linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: "'Gustavo A. R. Silva'" <gustavoars@kernel.org>,
	"J. Bruce Fields" <bfields@fieldses.org>,
	Chuck Lever <chuck.lever@oracle.com>
Cc: "linux-nfs@vger.kernel.org" <linux-nfs@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-hardening@vger.kernel.org"
	<linux-hardening@vger.kernel.org>
Subject: RE: [PATCH][next] UAPI: nfsfh.h: Replace one-element array with flexible-array member
Date: Thu, 25 Mar 2021 13:45:16 +0000	[thread overview]
Message-ID: <629154ce566b4c9c9b7f4124b3260fc3@AcuMS.aculab.com> (raw)
In-Reply-To: <20210323224858.GA293698@embeddedor>

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.
You might need to use a named anonymous structure for the
four __u8 fields and create two different structures that
include the extra field on the end.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2021-03-25 13:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23 22:48 [PATCH][next] UAPI: nfsfh.h: Replace one-element array with flexible-array member Gustavo A. R. Silva
2021-03-25 13:45 ` David Laight [this message]
2021-03-25 13:18   ` Gustavo A. R. Silva
2021-03-25 15:29     ` David Laight
2021-03-25 21:12       ` Gustavo A. R. Silva
2021-03-26  8:17         ` David Laight
2021-03-26 14:10           ` Gustavo A. R. Silva
2021-03-29 14:57 ` Chuck Lever
2021-03-29 14:51   ` Gustavo A. R. Silva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=629154ce566b4c9c9b7f4124b3260fc3@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=gustavoars@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).