[PATCH] netfs: Fix gcc-12 warning by embedding vfs inode in netfs_i_context

Kees Cook keescook at chromium.org
Thu May 19 07:05:49 PDT 2022


On Thu, May 19, 2022 at 02:44:28PM +0100, David Howells wrote:
> While randstruct was satisfied with using an open-coded "void *" offset
> cast for the netfs_i_context <-> inode casting, __builtin_object_size() as
> used by FORTIFY_SOURCE was not as easily fooled.  This was causing the
> following complaint[1] from gcc v12:
> 
> In file included from ./include/linux/string.h:253,
>                  from ./include/linux/ceph/ceph_debug.h:7,
>                  from fs/ceph/inode.c:2:
> In function 'fortify_memset_chk',
>     inlined from 'netfs_i_context_init' at ./include/linux/netfs.h:326:2,
>     inlined from 'ceph_alloc_inode' at fs/ceph/inode.c:463:2:
> ./include/linux/fortify-string.h:242:25: warning: call to '__write_overflow_field' declared with attribute warning:
> detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning]
>   242 |                         __write_overflow_field(p_size_field, size);
>       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Fix this by embedding a struct inode into struct netfs_i_context (which
> should perhaps be renamed to struct netfs_inode).  The struct inode
> vfs_inode fields are then removed from the 9p, afs, ceph and cifs inode
> structs and vfs_inode is then simply changed to "nic.inode" in those
> filesystems.
> 
> Most of the changes were done with:
> 
>   perl -p -i -e 's/vfs_inode/nic.inode/'g \
> 	`git grep -l 'vfs_inode' -- fs/{9p,afs,ceph,cifs}/*.[ch]`
> 
> Kees suggested doing it with a pair structure[2] and a special declarator
> to insert that into the network filesystem's inode wrapper[3], but I think
> it's cleaner to embed it - and then it doesn't matter if struct
> randomisation reorders things.
> 
> Fixes: bc899ee1c898 ("netfs: Add a netfs inode context")
> Reported-by: Jeff Layton <jlayton at kernel.org>
> Signed-off-by: David Howells <dhowells at redhat.com>
> cc: Kees Cook <keescook at chromium.org>
> cc: Jonathan Corbet <corbet at lwn.net>
> cc: Eric Van Hensbergen <ericvh at gmail.com>
> cc: Latchesar Ionkov <lucho at ionkov.net>
> cc: Dominique Martinet <asmadeus at codewreck.org>
> cc: Christian Schoenebeck <linux_oss at crudebyte.com>
> cc: Marc Dionne <marc.dionne at auristor.com>
> cc: Xiubo Li <xiubli at redhat.com>
> cc: Ilya Dryomov <idryomov at gmail.com>
> cc: Steve French <smfrench at gmail.com>
> cc: William Kucharski <william.kucharski at oracle.com>
> cc: "Matthew Wilcox (Oracle)" <willy at infradead.org>
> cc: linux-doc at vger.kernel.org
> cc: v9fs-developer at lists.sourceforge.net
> cc: linux-afs at lists.infradead.org
> cc: ceph-devel at vger.kernel.org
> cc: linux-cifs at vger.kernel.org
> cc: samba-technical at lists.samba.org
> cc: linux-fsdevek at vger.kernel.org
> cc: linux-hardening at vger.kernel.org
> Link: https://lore.kernel.org/r/d2ad3a3d7bdd794c6efb562d2f2b655fb67756b9.camel@kernel.org/ [1]
> Link: https://lore.kernel.org/r/20220517210230.864239-1-keescook@chromium.org/ [2]
> Link: https://lore.kernel.org/r/20220518202212.2322058-1-keescook@chromium.org/ [3]

Works for me! :) Thanks for building the alternative.

Reviewed-by: Kees Cook <keescook at chromium.org>

-Kees

-- 
Kees Cook



More information about the linux-afs mailing list