lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 25 Mar 2021 08:18:18 -0500
From:   "Gustavo A. R. Silva" <gustavo@...eddedor.com>
To:     David Laight <David.Laight@...LAB.COM>,
        "'Gustavo A. R. Silva'" <gustavoars@...nel.org>,
        "J. Bruce Fields" <bfields@...ldses.org>,
        Chuck Lever <chuck.lever@...cle.com>
Cc:     "linux-nfs@...r.kernel.org" <linux-nfs@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "linux-hardening@...r.kernel.org" <linux-hardening@...r.kernel.org>
Subject: Re: [PATCH][next] UAPI: nfsfh.h: Replace one-element array with
 flexible-array member



On 3/25/21 08:45, David Laight wrote:
> From: Gustavo A. R. Silva
>> Sent: 23 March 2021 22:49
>>
>> There is a regular need in the kernel to provide a way to declare having
>> a dynamically sized set of trailing elements in a structure. Kernel code
>> should always use “flexible array members”[1] for these cases. The older
>> style of one-element or zero-length arrays should no longer be used[2].
>>
>> Use an anonymous union with a couple of anonymous structs in order to
>> keep userspace unchanged:
>>
>> $ pahole -C nfs_fhbase_new fs/nfsd/nfsfh.o
>> struct nfs_fhbase_new {
>>         union {
>>                 struct {
>>                         __u8       fb_version_aux;       /*     0     1 */
>>                         __u8       fb_auth_type_aux;     /*     1     1 */
>>                         __u8       fb_fsid_type_aux;     /*     2     1 */
>>                         __u8       fb_fileid_type_aux;   /*     3     1 */
>>                         __u32      fb_auth[1];           /*     4     4 */
>>                 };                                       /*     0     8 */
>>                 struct {
>>                         __u8       fb_version;           /*     0     1 */
>>                         __u8       fb_auth_type;         /*     1     1 */
>>                         __u8       fb_fsid_type;         /*     2     1 */
>>                         __u8       fb_fileid_type;       /*     3     1 */
>>                         __u32      fb_auth_flex[0];      /*     4     0 */
>>                 };                                       /*     0     4 */
>>         };                                               /*     0     8 */
>>
>>         /* size: 8, cachelines: 1, members: 1 */
>>         /* last cacheline: 8 bytes */
>> };
> 
> Could you use the simpler:
>> struct nfs_fhbase_new {
>>          __u8       fb_version;
>>          __u8       fb_auth_type;
>>          __u8       fb_fsid_type;
>>          __u8       fb_fileid_type;
>>          union {
>>                 __u32      fb_auth[1];
>>                 __u32      fb_auth_flex[0];
>>          };
>> };
> 
> Although I'm not certain flexible arrays are supported
> as the last element of a union.

Nope; this is not allowed: https://godbolt.org/z/14vd4o8na

--
Gustavo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ