Linux-XFS Archive on lore.kernel.org
 help / color / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Kees Cook <keescook@chromium.org>,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	linux-xfs <linux-xfs@vger.kernel.org>
Subject: Re: [PATCH] xfs: Replace one-element arrays with flexible-array members
Date: Sat, 23 May 2020 19:25:55 -0700
Message-ID: <20200524022555.GA252930@magnolia> (raw)
In-Reply-To: <20200523202149.GI29907@embeddedor>

Please always cc linux-xfs when you're changing fs/xfs code.

*Especially* when it involves changes to ondisk structures.

On Sat, May 23, 2020 at 03:21:50PM -0500, Gustavo A. R. Silva wrote:
> On Fri, May 22, 2020 at 04:06:38PM -0700, Kees Cook wrote:
> > On Fri, May 22, 2020 at 04:55:42PM -0500, Gustavo A. R. Silva wrote:
> > > The current codebase makes use of one-element arrays in the following
> > > form:
> > > 
> > > struct something {
> > >     int length;
> > >     u8 data[1];
> > > };
> > > 
> > > struct something *instance;
> > > 
> > > instance = kmalloc(sizeof(*instance) + size, GFP_KERNEL);
> > > instance->length = size;
> > > memcpy(instance->data, source, size);
> > > 
> > > but the preferred mechanism to declare variable-length types such as
> > > these ones is a flexible array member[1][2], introduced in C99:
> > > 
> > > struct foo {
> > >         int stuff;
> > >         struct boo array[];
> > > };
> > > 
> > > By making use of the mechanism above, we will get a compiler warning
> > > in case the flexible array does not occur last in the structure, which
> > > will help us prevent some kind of undefined behavior bugs from being
> > > inadvertently introduced[3] to the codebase from now on. So, replace
> > > the one-element array with a flexible-array member.
> > > 
> > > This issue was found with the help of Coccinelle and audited
> > > _manually_.
> > > 
> > > [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
> > > [2] https://github.com/KSPP/linux/issues/21
> > > [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")
> > > 
> > > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> > > ---
> > >  fs/xfs/libxfs/xfs_log_format.h | 12 ++++++------
> > >  fs/xfs/xfs_extfree_item.c      | 18 +++++++++---------
> > >  fs/xfs/xfs_ondisk.h            |  8 ++++----
> > >  3 files changed, 19 insertions(+), 19 deletions(-)
> > > 

<snip>

> > > diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h
> > > index 5f04d8a5ab2a9..ceba638fd99ce 100644
> > > --- a/fs/xfs/xfs_ondisk.h
> > > +++ b/fs/xfs/xfs_ondisk.h
> > > @@ -113,10 +113,10 @@ xfs_check_ondisk_structs(void)
> > >  	/* log structures */
> > >  	XFS_CHECK_STRUCT_SIZE(struct xfs_buf_log_format,	88);
> > >  	XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat,		24);
> > > -	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_32,	28);
> > > -	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_64,	32);
> > > -	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_32,	28);
> > > -	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_64,	32);
> > > +	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_32,	16);
> > > +	XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_64,	16);
> > > +	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_32,	16);
> > > +	XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_64,	16);

Seeing as you're changing ondisk structure size checks, I gotta ask:
You /did/ run fstests before and after to make sure that the log
recovery tests still work, right?

--D

> > >  	XFS_CHECK_STRUCT_SIZE(struct xfs_extent_32,		12);
> > >  	XFS_CHECK_STRUCT_SIZE(struct xfs_extent_64,		16);
> > >  	XFS_CHECK_STRUCT_SIZE(struct xfs_log_dinode,		176);
> > > -- 
> > > 2.26.2
> > > 
> > 
> > -- 
> > Kees Cook

       reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200522215542.GA18898@embeddedor>
     [not found] ` <202005221606.A1647A0@keescook>
     [not found]   ` <20200523202149.GI29907@embeddedor>
2020-05-24  2:25     ` Darrick J. Wong [this message]
2020-05-24 23:23       ` Dave Chinner
2020-05-25 18:41         ` 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=20200524022555.GA252930@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=gustavo@embeddedor.com \
    --cc=gustavoars@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-xfs@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

Linux-XFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-xfs/0 linux-xfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-xfs linux-xfs/ https://lore.kernel.org/linux-xfs \
		linux-xfs@vger.kernel.org
	public-inbox-index linux-xfs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-xfs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git