Re: [ 16/85] use clamp_t in UNAME26 fix

From: Fengguang Wu
Date: Sat Oct 27 2012 - 13:04:44 EST


On Sat, Oct 27, 2012 at 05:11:58PM +0100, Ben Hutchings wrote:
> On Thu, 2012-10-25 at 17:05 -0700, Greg Kroah-Hartman wrote:
> > 3.6-stable review patch. If anyone has any objections, please let me know.
> >
> > ------------------
> >
> > From: Kees Cook <keescook@xxxxxxxxxxxx>
> >
> > commit 31fd84b95eb211d5db460a1dda85e004800a7b52 upstream.
> >
> > The min/max call needed to have explicit types on some architectures
> > (e.g. mn10300). Use clamp_t instead to avoid the warning:
> >
> > kernel/sys.c: In function 'override_release':
> > kernel/sys.c:1287:10: warning: comparison of distinct pointer types lacks a cast [enabled by default]
>
> While this change makes the code more readable, I think the bug is
> really in the type definitions for those architectures:
>
> [...]
> > - copy = min(sizeof(buf), max_t(size_t, 1, len));
> > + copy = clamp_t(size_t, len, 1, sizeof(buf));
> [...]
>
> 1. sizeof(buf) yields a value of type size_t, by definition.
> 2. max_t(size_t, 1, len) yields a value of type size_t.
> 3. Therefore min(sizeof(buf), max_t(size_t, 1, len)) is valid.
>
> The only way I see to get this warning is to define size_t wrongly, so
> that (1) is not true.

Agreed. mn10300 and cris seem to have problems with size_t.
Here is a related issue:

Re: [next:akpm 155/157] drivers/char/random.c:827:3: warning: format '%zd' expects argument of type 'signed size_t', but argument 7 has type 'size_t'
https://lkml.org/lkml/2012/10/23/792

Thanks,
Fengguang
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/