Re: [PATCH] kernel.h: Skip single-eval logic on literals in min()/max()

From: Kees Cook
Date: Thu Mar 08 2018 - 20:46:56 EST


On Thu, Mar 8, 2018 at 5:35 PM, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> I don't want to weaken the type enforcement, and I _thought_ you had
> done that __builtin_types_compatible_p() to keep it in place.

I thought so too (that originally came from Josh), but on removal, I
was surprised that the checking was retained. :)

> But if that's not why you did it, then why was it there at all? If the
> type warning shows through even if it's in the other expression, then
> just a
>
>
> #define __min(t1, t2, x, y) \
> __builtin_choose_expr( \
> __builtin_constant_p(x) & \
> __builtin_constant_p(y), \
> (t1)(x) < (t2)(y) ? (t1)(x) : (t2)(y), \
> __single_eval_min(t1, t2, \
> ...
>
> would seem to be sufficient?
>
> Because logically, the only thing that matters is that x and y don't
> have any side effects and can be evaluated twice, and
> "__builtin_constant_p()" is already a much stronger version of that.
>
> Hmm? The __builtin_types_compatible_p() just doesn't seem to matter
> for the only thing I thought it was there for.

Yup, agreed. I'll drop it.

-Kees

--
Kees Cook
Pixel Security