[PATCH] linux: Clear mode_t padding bits (BZ#25623)

Andreas Schwab schwab@suse.de
Wed Mar 4 09:08:00 GMT 2020


On Mär 03 2020, Adhemerval Zanella wrote:

> On 03/03/2020 18:51, Florian Weimer wrote:
>> * Adhemerval Zanella:
>> 
>>> diff --git a/sysdeps/unix/sysv/linux/msgctl.c b/sysdeps/unix/sysv/linux/msgctl.c
>>> index 27879e76cd..48801a3fba 100644
>>> --- a/sysdeps/unix/sysv/linux/msgctl.c
>>> +++ b/sysdeps/unix/sysv/linux/msgctl.c
>> 
>>> +#else
>>> +	  /* Old Linux kernel versions might not clear the mode padding.  */
>>> +	  if (sizeof ((struct msqid_ds){0}.msg_perm.mode
>>> +	      != sizeof ((struct __old_ipc_perm){0}.mode)))
>>> +	    buf->msg_perm.mode &= 0xFFFF;
>>> +#endif
>> 
>> The condition always evaluates to true becaduse the first sizeof is
>> applied to the result of the != operator.
>
> Sigh, indeed (I should have verified if x86_64 resulting code would be
> constant). Is is ok with the suppose fix (below)?
>
>           if (sizeof ((struct msqid_ds){0}.msg_perm.mode)
>               != sizeof ((struct __old_ipc_perm){0}.mode))
>             buf->msg_perm.mode &= 0xFFFF;

I don't think __old_ipc_perm is the right type to check since that is
for use by the !__IPC_64 syscall.  What we really need to check here
is __kernel_mode_t vs. mode_t.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



More information about the Libc-alpha mailing list