Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp478732rdb; Thu, 1 Feb 2024 14:27:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyRwHhp2WNTi8X/QXy7VaTODay73ludmLM0d6Abyw3o9JqLkO4wGOrnhz+rTfnXr4GnEau X-Received: by 2002:a05:6358:441e:b0:176:8472:800f with SMTP id z30-20020a056358441e00b001768472800fmr186462rwc.31.1706826467156; Thu, 01 Feb 2024 14:27:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706826467; cv=pass; d=google.com; s=arc-20160816; b=OX2APJp/VJSLmTDhC8IDRtaflSM+KqX/gP6LBJ6LXezfr0btBNEUEm/0aujIpUVmVW qlQo2jT68pZeEi0D7NVGtr7BJzHGemswHcZiqMLpMdY7eS7JYbO6qgwEKMFumxuFkhBD k6IjmayUi38r5g2fo6NOP2wVBxbLsz7vKr5NQW2k5JggXhJMii55WLnUku4nemX1LMHd 1lVvl+jsBHUf/OWEqgC3kO6cS3RGw5wMPOI5I4HrF7+uGfkfmHmcDnprG+H3NXa3IkPT cy9G2gLenrMWLxURy6Ig0YgLn58lOPslxTPx4gsyh3rdOdqGmQKt4PFD4xycJXGpWeqM MGHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=vL7SJZQiX7iBH2yVQNL2VeEYjvGEbCOoRew0Z3DhEek=; fh=mVNjMOiCQhX4FcMHKqfFSQQhpbBsu3aeN65hsD4PxPc=; b=wxa66OTvjei1XMVNEhj+XtiGlUnySpZ5eD3tfc+nLmUSW5v6k48nmFO4rkDSSDQAeg X0VEn6ypR1uT+Da+5MLzRR0EbEk3yg3JRApGA68w0a+IupaAC7bAs0NoNOtVJn20EKmf xxsjyP34qk9OgoxaboLWv1Z3ylCR+uotb6PwmX59jag27rUMvq4+HDqhc7dfSjazVebZ liZfPAYmp2SQJ3zl7a246YdPpJuhJJuVwsEHm7XBMIgE+dqNMpNzII7gKWFqji3G3t8+ iBMtfVns4EzZrxwPISZPRwmaJCNEzlJvnrADqlqDZ5/+o6rRcEn2mSHmk7+jhn3Q/DyK MP4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@canb.auug.org.au header.s=201702 header.b=pV8i93ih; arc=pass (i=1 spf=pass spfdomain=canb.auug.org.au dkim=pass dkdomain=canb.auug.org.au dmarc=pass fromdomain=canb.auug.org.au); spf=pass (google.com: domain of linux-kernel+bounces-48916-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48916-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canb.auug.org.au X-Forwarded-Encrypted: i=1; AJvYcCW3yoPFAvbjhhzEG/SzNrexJrD2Pu+2t2ZWQ0exGbovnlDJhCfhdWM6WSBq93/8/K1PnoQe54oLg5HB4V/TkrzlI/1T+i3tOT61TsooMQ== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e26-20020a630f1a000000b005c66e60900csi432673pgl.239.2024.02.01.14.27.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 14:27:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48916-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@canb.auug.org.au header.s=201702 header.b=pV8i93ih; arc=pass (i=1 spf=pass spfdomain=canb.auug.org.au dkim=pass dkdomain=canb.auug.org.au dmarc=pass fromdomain=canb.auug.org.au); spf=pass (google.com: domain of linux-kernel+bounces-48916-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48916-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canb.auug.org.au Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5B4E9B22933 for ; Thu, 1 Feb 2024 22:09:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B12BA3FB2E; Thu, 1 Feb 2024 22:09:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canb.auug.org.au header.i=@canb.auug.org.au header.b="pV8i93ih" Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90954405F8 for ; Thu, 1 Feb 2024 22:09:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=150.107.74.76 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706825353; cv=none; b=JPfnPjbM4bpxMm8cVBPDzGCsaCeGxeWyVFc5+TsUx5wQaBiQ/q886wch4PYgUlm2Bk3atTp3qFIWepU/tBS4iaLjhOQCHKFK4crtl3ewvINrLBfqMMI49XWkvEno69iuPnUtDLwFMEAOFSGHoqdcINO9AGdJw9KQFd3u6O6wcFg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706825353; c=relaxed/simple; bh=FNRWaapzIP96o6avBHUwnyDp2UuzJDEtzi68MNZb3XQ=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VgBfsnJHHqBHXDutJFgCG9GAMCoZ8n1JcHegsuYcmZPK3jFHz2W8poGDEP2tE5qJRUHji1iW9XzJZT03mltxb3O/yJufPFXflhzAy4G9i+tI08bZQ86XbGHL7HUjPs411HH35JQ/d8EyLd+jNw/4w3Z2Az76c0PllRPH00ohupc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canb.auug.org.au; spf=pass smtp.mailfrom=canb.auug.org.au; dkim=pass (2048-bit key) header.d=canb.auug.org.au header.i=@canb.auug.org.au header.b=pV8i93ih; arc=none smtp.client-ip=150.107.74.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canb.auug.org.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canb.auug.org.au DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canb.auug.org.au; s=201702; t=1706825346; bh=vL7SJZQiX7iBH2yVQNL2VeEYjvGEbCOoRew0Z3DhEek=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=pV8i93ihpBQWX/Jum97yQQApGrpd9muWbWh8gsRBKxPjOU8wbJEurgEQmCNAq6dly 5gsQW24igc680rGzBzMJAACXdSmnWO3JSBW2muSyo9rmKPL4tN1Gu79/OTFiYP8BAd 5OgNVBYpIrf+86i0kikm1mI6wSfIHV4YM16BzMCIoMf2V6ttz1R/u2noCQiXJx0C0b O/pmdpEi101tEWzsVCLpMVUPl6Jlo0Xpmpfkg2yN/TP7aJ78K2ysqU5xpN6AVYVi4z JF8eLmG/Uo2b2cuN0SydjhyGlPzHheSxPBD4V8EGhpjnhRjx29C3OkWB0OkMk1xMDI HrWFsbsEtuWfA== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4TQtNJ6PYTz4wcP; Fri, 2 Feb 2024 09:09:04 +1100 (AEDT) Date: Fri, 2 Feb 2024 09:09:03 +1100 From: Stephen Rothwell To: Marco Elver Cc: Andrew Morton , Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com Subject: Re: [PATCH -mm v2] stackdepot: fix -Wstringop-overflow warning Message-ID: <20240202090903.6ba062ac@canb.auug.org.au> In-Reply-To: <20240201090434.1762340-1-elver@google.com> References: <20240201090434.1762340-1-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/E5HTHIzNlHNnd_U1O+bvlVs"; protocol="application/pgp-signature"; micalg=pgp-sha256 --Sig_/E5HTHIzNlHNnd_U1O+bvlVs Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hi all, On Thu, 1 Feb 2024 10:04:30 +0100 Marco Elver wrote: > > Since 113a61863ecb ("Makefile: Enable -Wstringop-overflow globally") > string overflow checking is enabled by default. Within stackdepot, the > compiler (GCC 13.2.0) assumes that a multiplication overflow may be > possible and flex_array_size() can return SIZE_MAX (4294967295 on > 32-bit), resulting in this warning: >=20 > In function 'depot_alloc_stack', > inlined from 'stack_depot_save_flags' at lib/stackdepot.c:688:4: > arch/x86/include/asm/string_32.h:150:25: error: '__builtin_memcpy' speci= fied bound 4294967295 exceeds maximum object size 2147483647 [-Werror=3Dstr= ingop-overflow=3D] > 150 | #define memcpy(t, f, n) __builtin_memcpy(t, f, n) > | ^~~~~~~~~~~~~~~~~~~~~~~~~ > lib/stackdepot.c:459:9: note: in expansion of macro 'memcpy' > 459 | memcpy(stack->entries, entries, flex_array_size(stack, e= ntries, nr_entries)); > | ^~~~~~ > cc1: all warnings being treated as errors >=20 > This is due to depot_alloc_stack() accepting an 'int nr_entries' which > could be negative without deeper analysis of callers. >=20 > The call to depot_alloc_stack() from stack_depot_save_flags(), however, > only passes in its nr_entries which is unsigned int. Fix the warning by > switching depot_alloc_stack()'s nr_entries to also be unsigned. >=20 > Link: https://lore.kernel.org/all/20240201135747.18eca98e@canb.auug.org.a= u/ > Fixes: d869d3fb362c ("stackdepot: use variable size records for non-evict= able entries") > Reported-by: Stephen Rothwell > Signed-off-by: Marco Elver > --- > v2: > * Just switch 'nr_entries' to unsigned int which is already the case > elsewhere. > --- > lib/stackdepot.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > index 8f3b2c84ec2d..4a7055a63d9f 100644 > --- a/lib/stackdepot.c > +++ b/lib/stackdepot.c > @@ -420,7 +420,7 @@ static inline size_t depot_stack_record_size(struct s= tack_record *s, unsigned in > =20 > /* Allocates a new stack in a stack depot pool. */ > static struct stack_record * > -depot_alloc_stack(unsigned long *entries, int nr_entries, u32 hash, depo= t_flags_t flags, void **prealloc) > +depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 h= ash, depot_flags_t flags, void **prealloc) > { > struct stack_record *stack =3D NULL; > size_t record_size; > --=20 > 2.43.0.429.g432eaa2c6b-goog >=20 I have applied this patch to the merge of the mm tree today. --=20 Cheers, Stephen Rothwell --Sig_/E5HTHIzNlHNnd_U1O+bvlVs Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEENIC96giZ81tWdLgKAVBC80lX0GwFAmW8Fn8ACgkQAVBC80lX 0GwEdQf/QnOi4Qm8+1/IkO10QkmuLja/E9BrYs9hA8MrzNS5sUIvOr1HmQEvEP7Y CdpwEuMEITu9EgLXtwF9LqrddOg3WxHEsMpzwr4XSwJQk+zzyJV9OUMY0LV+OZw2 AT7P083oFYYMhfwvoTHTGMri7LQbB44JMqV+O4814bQCo63YCmDVxvZBc5xEiJT7 qdGhqra4nJpdURCQIpDEBFz49x/NQHsIAeUuqW1mGt963xX7BjfPd/8h7gZFM+PX rT0n8Nq1YALzqOXO+Q6sG06W2JURy7Pa0Asnc5TQITfD/zL1dV33YF0ljTOD1J8x qFy9tuJidBXQc4bTX6K7QRA5Mx5TxQ== =zrpL -----END PGP SIGNATURE----- --Sig_/E5HTHIzNlHNnd_U1O+bvlVs--