[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202308141416.89AC5C2@keescook>
Date: Mon, 14 Aug 2023 14:21:02 -0700
From: Kees Cook <keescook@...omium.org>
To: David Laight <David.Laight@...lab.com>
Cc: "'linux-kernel@...r.kernel.org'" <linux-kernel@...r.kernel.org>,
'Andy Shevchenko' <andriy.shevchenko@...ux.intel.com>,
'Andrew Morton' <akpm@...ux-foundation.org>,
"'Matthew Wilcox (Oracle)'" <willy@...radead.org>,
'Christoph Hellwig' <hch@...radead.org>,
"'Jason A. Donenfeld'" <Jason@...c4.com>,
Linus Torvalds <torvalds@...ux-foundation.org>
Subject: Re: [PATCH next v3 0/5] minmax: Relax type checks in min() and max().
On Fri, Aug 04, 2023 at 10:50:59AM +0000, David Laight wrote:
> [...]
> I also suspect that many of the min_t(u16, ...) are actually wrong.
> For example copy_data() in printk_ringbuffer.c contains:
> data_size = min_t(u16, buf_size, len);
> Here buf_size is 'unsigned int' and len 'u16', pass a 64k buffer
> (can you prove that doesn't happen?) and no data is returned.
Stars aligning... this exact bug (as you saw in the other thread[1]) got
hit. And in the analysis, I came to the same conclusion: min_t() is a
serious foot-gun, and we should be able to make min() Just Work in the
most common situations.
It seems like the existing type_max/type_min macros could be used to
figure out that the args are safe to appropriately automatically cast,
etc. e.g. type_max(u16) <= type_max(unsigned int) && type_min(u16) >=
type_min(unsigned int) ...
-Kees
[1] https://lore.kernel.org/all/20230811054528.never.165-kees@kernel.org/
--
Kees Cook
Powered by blists - more mailing lists