lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <202404191458.17308A48D4@keescook>
Date: Fri, 19 Apr 2024 15:06:39 -0700
From: Kees Cook <keescook@...omium.org>
To: Matthew Wilcox <willy@...radead.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
	Ingo Molnar <mingo@...hat.com>,
	Peter Zijlstra <peterz@...radead.org>,
	Juri Lelli <juri.lelli@...hat.com>,
	Vincent Guittot <vincent.guittot@...aro.org>,
	Dietmar Eggemann <dietmar.eggemann@....com>,
	Steven Rostedt <rostedt@...dmis.org>,
	Ben Segall <bsegall@...gle.com>, Mel Gorman <mgorman@...e.de>,
	Daniel Bristot de Oliveira <bristot@...hat.com>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 00/19] Enable -Wshadow=local for kernel/sched

On Wed, Apr 17, 2024 at 01:52:28AM +0100, Matthew Wilcox wrote:
> On Tue, Apr 16, 2024 at 05:29:02PM -0700, Linus Torvalds wrote:
> > On Tue, 16 Apr 2024 at 14:15, Kees Cook <keescook@...omium.org> wrote:
> > >
> > > I was looking at -Wshadow=local again, and remembered this series. It
> > > sounded like things were close, but a tweak was needed. What would be
> > > next to get this working?
> > 
> > So what is the solution to
> > 
> >     #define MAX(a,b) ({ \
> >         typeof(a) __a = (a); \
> >         typeof(b) __b = (b); \
> >         __a > __b ? __a : __b; \
> >     })
> 
> #define __MAX(a, __a, b, __b) ({	\
> 	typeof(a) __a = (a);		\
> 	typeof(b) __b = (b);		\
> 	__a > __b ? __a : __b;		\
> })
> 
> #define MAX(a, b)	__MAX(a, UNIQUE_ID(a), b, UNIQUE_ID(b))

Yup, this is what we've had for a long time now. See
include/linux/minmax.h

> At least, I think that was the plan.  This was two years ago and I've
> mostly forgotten.
> 
> >     int test(int a, int b, int c)
> >     {
> >         return MAX(a, MAX(b,c));
> >     }
> > 
> > where -Wshadow=all causes insane warnings that are bogus garbage?
> > 
> > Honestly, Willy's patch-series is a hack to avoid this kind of very
> > natural nested macro pattern.
> > 
> > But it's a horrible hack, and it does it by making the code actively worse.
> > 
> > Here's the deal: if we can't handle somethng like the above without
> > warning, -Wshadow isn't getting enabled.
> > 
> > Because we don't write worse code because of bad warnings.
> > 
> > IOW, what is the sane way to just say "this variable can shadow the
> > use site, and it's fine"?
> > 
> > Without that kind of out, I don't think -Wshadow=local is workable.

This isn't a hill I want to die on, but it's just another case where
we've fought bugs more than once that would have stood out immediately
if we had -Wshadow=local enabled, but there is basically only 1 user. In
my bug-fighting calculus, it makes sense to deal with fixing the 1 user
so we can gain the coverage everywhere else.

But there are much worse bug sources, so if Willy's series isn't
workable, I'll drop this again for now. :)

-Kees


-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ