orangefs: fix out-of-bounds fsid access
authorMike Marshall <hubcap@omnibond.com>
Wed, 1 May 2024 20:20:36 +0000 (16:20 -0400)
committerMike Marshall <hubcap@omnibond.com>
Mon, 6 May 2024 14:10:36 +0000 (10:10 -0400)
Arnd Bergmann sent a patch to fsdevel, he says:

"orangefs_statfs() copies two consecutive fields of the superblock into
the statfs structure, which triggers a warning from the string fortification
helpers"

Jan Kara suggested an alternate way to do the patch to make it more readable.

I ran both ideas through xfstests and both seem fine. This patch
is based on Jan Kara's suggestion.

Signed-off-by: Mike Marshall <hubcap@omnibond.com>
fs/orangefs/super.c

index 34849b4a3243ca5a2d27114d8a6f5f0a6074d329..907765673765c88e660482b95d6fa6b348add32e 100644 (file)
@@ -201,7 +201,8 @@ static int orangefs_statfs(struct dentry *dentry, struct kstatfs *buf)
                     (long)new_op->downcall.resp.statfs.files_avail);
 
        buf->f_type = sb->s_magic;
-       memcpy(&buf->f_fsid, &ORANGEFS_SB(sb)->fs_id, sizeof(buf->f_fsid));
+       buf->f_fsid.val[0] = ORANGEFS_SB(sb)->fs_id;
+       buf->f_fsid.val[1] = ORANGEFS_SB(sb)->id;
        buf->f_bsize = new_op->downcall.resp.statfs.block_size;
        buf->f_namelen = ORANGEFS_NAME_MAX;