linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] xfs: Replace one-element arrays with flexible-array members
       [not found]   ` <20200523202149.GI29907@embeddedor>
@ 2020-05-24  2:25     ` Darrick J. Wong
  2020-05-24 23:23       ` Dave Chinner
  0 siblings, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2020-05-24  2:25 UTC (permalink / raw)
  To: Gustavo A. R. Silva; +Cc: Kees Cook, Gustavo A. R. Silva, linux-xfs

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] xfs: Replace one-element arrays with flexible-array members
  2020-05-24  2:25     ` [PATCH] xfs: Replace one-element arrays with flexible-array members Darrick J. Wong
@ 2020-05-24 23:23       ` Dave Chinner
  2020-05-25 18:41         ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Chinner @ 2020-05-24 23:23 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: Gustavo A. R. Silva, Kees Cook, Gustavo A. R. Silva, linux-xfs

On Sat, May 23, 2020 at 07:25:55PM -0700, Darrick J. Wong wrote:
> Please always cc linux-xfs when you're changing fs/xfs code.
> 
> *Especially* when it involves changes to ondisk structures.

I can't find this patch in lkml or -fsdevel on lore.kernel.org, so I
have no idea where this patch even came from. Which means I can't
even check what the structure change is because it wasn't quoted in
full.

So, NACK on this until the entire patch is resent to linux-xfs and
run through all the shutdown and error recovery tests in fstests....

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] xfs: Replace one-element arrays with flexible-array members
  2020-05-24 23:23       ` Dave Chinner
@ 2020-05-25 18:41         ` Gustavo A. R. Silva
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2020-05-25 18:41 UTC (permalink / raw)
  To: Dave Chinner; +Cc: Darrick J. Wong, Kees Cook, Gustavo A. R. Silva, linux-xfs

Hi all,

On Mon, May 25, 2020 at 09:23:15AM +1000, Dave Chinner wrote:
> On Sat, May 23, 2020 at 07:25:55PM -0700, Darrick J. Wong wrote:
> > Please always cc linux-xfs when you're changing fs/xfs code.
> > 
> > *Especially* when it involves changes to ondisk structures.
> 
> I can't find this patch in lkml or -fsdevel on lore.kernel.org, so I
> have no idea where this patch even came from. Which means I can't
> even check what the structure change is because it wasn't quoted in
> full.
> 

Yeah, there was a bug in one of my scripts that was messing up with
some email addresses. I just fixed it up.

> So, NACK on this until the entire patch is resent to linux-xfs and
> run through all the shutdown and error recovery tests in fstests....
> 

I've added the patch[1] to my testing/xfs branch. I'll wait for
Kernel test robot <lkp@intel.com> to help me test it.

Thanks
--
Gustavo

[1] https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?h=testing/xfs


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-25 18:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200522215542.GA18898@embeddedor>
     [not found] ` <202005221606.A1647A0@keescook>
     [not found]   ` <20200523202149.GI29907@embeddedor>
2020-05-24  2:25     ` [PATCH] xfs: Replace one-element arrays with flexible-array members Darrick J. Wong
2020-05-24 23:23       ` Dave Chinner
2020-05-25 18:41         ` Gustavo A. R. Silva

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).