Re: [PATCH 1/3] ipc/sem.c: remove sem_base, embed struct sem
From: Kees Cook
Date: Mon May 15 2017 - 18:16:06 EST
On Mon, May 15, 2017 at 1:08 PM, Andrew Morton
<akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Mon, 15 May 2017 19:19:10 +0200 Manfred Spraul <manfred@xxxxxxxxxxxxxxxx> wrote:
>
>> sma->sem_base is initialized with
>> sma->sem_base = (struct sem *) &sma[1];
>>
>> The current code has four problems:
>> - There is an unnecessary pointer dereference - sem_base is not needed.
>> - Alignment for struct sem only works by chance.
>> - The current code causes false positive for static code analysis.
>> - This is a cast between different non-void types, which the future
>> randstruct GCC plugin warns on.
>>
>> And, as bonus, the code size gets smaller:
>>
>> Before:
>> 0 .text 00003770
>> After:
>> 0 .text 0000374e
>
>
> This clashes with Kees's patch, below. Does it have the same effect?
This is a better clean up than what I've got. I haven't had a chance
to verify this is sufficient for randstruct (I think it is), but I'll
check and send any another needed fixes separately.
-Kees
--
Kees Cook
Pixel Security