Skip to contentSkip to conversation

orangefs: fix out-of-bounds fsid access

PATCH RESEND In review Arnd Bergmann 5 participants 6 messages Apr 8, 2024 – Apr 9, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 orangefs: fix out-of-bounds fsid access

From: Arnd Bergmann <[email protected]>

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

In file included from fs/orangefs/super.c:8:
include/linux/fortify-string.h:592:4: error: call to '__read_overflow2_field' declared with 'warning' attribute: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]

                        __read_overflow2_field(q_size_field, size);

Change the memcpy() to an individual assignment of the two fields, which helps both the compiler and human readers understand better what it does.

---
Resending to VFS maintainers, I sent this a couple of times to the orangefs maintainers but never got a reply

---
 fs/orangefs/super.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/orangefs/super.c +4 -1
index fb4d09c2f531..152478295766 100644
@@ -201,7 +201,10 @@ 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 = (__kernel_fsid_t) {{
+		ORANGEFS_SB(sb)->fs_id,
+		ORANGEFS_SB(sb)->id,
+	}};
 	buf->f_bsize = new_op->downcall.resp.statfs.block_size;
 	buf->f_namelen = ORANGEFS_NAME_MAX;
 
Signature · 1 line
2.39.2
reviewer
#1 lore raw
Quoted 34 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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

In file included from fs/orangefs/super.c:8:
include/linux/fortify-string.h:592:4: error: call to '__read_overflow2_field' declared with 'warning' attribute: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]

                        __read_overflow2_field(q_size_field, size);

Change the memcpy() to an individual assignment of the two fields, which helps both the compiler and human readers understand better what it does.

---
Resending to VFS maintainers, I sent this a couple of times to the orangefs maintainers but never got a reply

---
 fs/orangefs/super.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/orangefs/super.c +0 -0
index fb4d09c2f531..152478295766 100644

fs/orangefs/super.c static int orangefs_statfs(struct dentry *dentry, struct kstatfs *buf) · line 207

Quoted 8 lines
fs/orangefs/super.c +4 -1
@@ -201,7 +201,10 @@ 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 = (__kernel_fsid_t) {{
+		ORANGEFS_SB(sb)->fs_id,
+		ORANGEFS_SB(sb)->id,
+	}};

Frankly, this initializer is hard to understand for me. Why not simple:

	buf->f_fsid[0] = ORANGEFS_SB(sb)->fs_id;
	buf->f_fsid[1] = ORANGEFS_SB(sb)->id;

								Honza
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
Quoted 5 lines · Jan Kara

Frankly, this initializer is hard to understand for me. Why not simple:

        buf->f_fsid[0] = ORANGEFS_SB(sb)->fs_id;
        buf->f_fsid[1] = ORANGEFS_SB(sb)->id;

+1 for this idea, seems easier to read for me.

Quoted 4 lines

Honza
--
Jan Kara <[email protected]>
SUSE Labs, CR

#3 lore raw
Quoted 8 lines · Justin Stitt
Quoted 5 lines · Jan Kara

Frankly, this initializer is hard to understand for me. Why not simple:

        buf->f_fsid[0] = ORANGEFS_SB(sb)->fs_id;
        buf->f_fsid[1] = ORANGEFS_SB(sb)->id;

+1 for this idea, seems easier to read for me.

Yes, good idea, I'll send this as v2 after my next round of build testing.

Arnd

maintainer
#4 lore raw

I applied Arnd's patch on top of Linux 6.9-rc3 and ran through xfstests with no issue.

Also, instead of Arnd's patch, I used Jan's idea:

+
+ buf->f_fsid.val[0] = ORANGEFS_SB(sb)->fs_id;
+ buf->f_fsid.val[1] = ORANGEFS_SB(sb)->id;
+

And ran that through as well, no issue.

Sorry for missing the earlier patch.

-Mike

Quoted 15 lines · Arnd Bergmann
Quoted 8 lines · Justin Stitt
Quoted 5 lines · Jan Kara

Frankly, this initializer is hard to understand for me. Why not simple:

        buf->f_fsid[0] = ORANGEFS_SB(sb)->fs_id;
        buf->f_fsid[1] = ORANGEFS_SB(sb)->id;

+1 for this idea, seems easier to read for me.

Yes, good idea, I'll send this as v2 after my next round of build testing.

Arnd

#5 lore raw
Quoted 10 lines · Mike Marshall

I applied Arnd's patch on top of Linux 6.9-rc3 and ran through xfstests with no issue.

Also, instead of Arnd's patch, I used Jan's idea:

(quoted diff) +4 -0
+
+       buf->f_fsid.val[0] = ORANGEFS_SB(sb)->fs_id;
+       buf->f_fsid.val[1] = ORANGEFS_SB(sb)->id;
+
Quoted 3 lines

And ran that through as well, no issue.

Sorry for missing the earlier patch.

Thanks!

I was about to send the updated patch and can skip that now.

Arnd