Re: [PATCH RESEND] KEYS: fix parsing invalid pkey info string
From: Linus Torvalds
Date: Mon Dec 17 2018 - 14:07:10 EST
On Mon, Dec 17, 2018 at 10:49 AM Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> So the *simplest* fix would seem to be to literally remove all those
> "= -1" for the Opt_err initialization. Making the code smaller,
> simpler, and fixing the bug in the process.
Something like this
git grep -l 'Opt_err = -1' | xargs sed -i 's/Opt_err = -1/Opt_err/'
would do it, but I also notice that
security/integrity/ima/ima_policy.c then has some truly funky code
that plays around with the enum numbers , ie
#define pt(token) policy_tokens[token + Opt_err].pattern
which actually depends on the ordering of policy_tokens[], and depends
on the exact values, ie it literally (and quite insanely) sets Opt_err
to -1, and then Opt_measure to 1, and leaves 0 unused. That code
seriously makes no sense at all, and is fundamentally broken.
It would be better to use
#define pt(token) policy_tokens[token - Opt_measure].pattern
instead, but even then you should have a huge comment about how the
policy_tokens[] array absolutely has to be properly ordered.
Honestly, for being about "security", all of this code seems to be
doing some really questionable things with all those Opt_xyz enums.
Linus