Skip to contentSkip to conversation

xfs: don't walk off the end of a directory data block

PATCH In review Chandan Babu R 2 participants 5 messages May 27, 2024 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 xfs: don't walk off the end of a directory data block

[CC-ing linux-xfs mailing list]

Quoted 5 lines · lei lu

Add a check to make sure xfs_dir2_data_unused and xfs_dir2_data_entry don't stray beyond valid memory region.

Also adding the missing RVB from Darrick,

Quoted 29 lines
---
 fs/xfs/libxfs/xfs_dir2_data.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/xfs/libxfs/xfs_dir2_data.c +7 -0
index dbcf58979a59..08c18e0c1baa 100644
@@ -178,6 +178,9 @@ __xfs_dir3_data_check(
 		struct xfs_dir2_data_unused	*dup = bp->b_addr + offset;
 		struct xfs_dir2_data_entry	*dep = bp->b_addr + offset;
 
+		if (offset + sizeof(*dup) > end)
+			return __this_address;
+
 		/*
 		 * If it's unused, look for the space in the bestfree table.
 		 * If we find it, account for that, else make sure it
@@ -210,6 +213,10 @@ __xfs_dir3_data_check(
 			lastfree = 1;
 			continue;
 		}
+
+		if (offset + sizeof(*dep) > end)
+			return __this_address;
+
 		/*
 		 * It's a real entry.  Validate the fields.
 		 * If this is a block directory then make sure it's
Signature · 1 line
Chandan
#2 lore raw
Quoted 6 lines · Chandan Babu R

[CC-ing linux-xfs mailing list]

Quoted 2 lines · lei lu

Add a check to make sure xfs_dir2_data_unused and xfs_dir2_data_entry don't stray beyond valid memory region.

How was this found? What symptoms did it have? i.e. How do we know if we've tripped over the same problem on an older LTS/distro kernel and need to backport it?

Quoted 6 lines
Quoted 2 lines

Also adding the missing RVB from Darrick,

That's not really normal process - adding third party tags like this are kinda frowned upon because there's no actual public record of Darrick saying this.

i.e. patches send privately should really be reposted to the public list by the submitter and everyone then adds their rvb/acks, etc on list themselves.

Quoted 22 lines
Quoted 22 lines
---
 fs/xfs/libxfs/xfs_dir2_data.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/xfs/libxfs/xfs_dir2_data.c +3 -0
index dbcf58979a59..08c18e0c1baa 100644
@@ -178,6 +178,9 @@ __xfs_dir3_data_check(
 		struct xfs_dir2_data_unused	*dup = bp->b_addr + offset;
 		struct xfs_dir2_data_entry	*dep = bp->b_addr + offset;
 
+		if (offset + sizeof(*dup) > end)
+			return __this_address;
+
 		/*
 		 * If it's unused, look for the space in the bestfree table.
 		 * If we find it, account for that, else make sure it
@@ -210,6 +213,10 @@ __xfs_dir3_data_check(
 			lastfree = 1;
 			continue;
Quoted 8 lines

fs/xfs/libxfs/xfs_dir2_data.c __xfs_dir3_data_check( · line 222

Quoted 8 lines
fs/xfs/libxfs/xfs_dir2_data.c +4 -0
 		}
+
+		if (offset + sizeof(*dep) > end)
+			return __this_address;
+
 		/*
 		 * It's a real entry.  Validate the fields.
 		 * If this is a block directory then make sure it's

Nothing wrong with the code change, though.

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#3 lore raw
Quoted 15 lines · Dave Chinner
Quoted 6 lines · Chandan Babu R

[CC-ing linux-xfs mailing list]

Quoted 2 lines · lei lu

Add a check to make sure xfs_dir2_data_unused and xfs_dir2_data_entry don't stray beyond valid memory region.

How was this found? What symptoms did it have? i.e. How do we know if we've tripped over the same problem on an older LTS/distro kernel and need to backport it?

Quoted 3 lines
Quoted 2 lines
Quoted 7 lines
Quoted 3 lines

Also adding the missing RVB from Darrick,

That's not really normal process - adding third party tags like this are kinda frowned upon because there's no actual public record of Darrick saying this.

Ok. The patch was posted on [email protected] with me on CC. Hence, I had decided to forward the patch to linux-xfs for any reviews from the wider audience.

Quoted 5 lines

i.e. patches send privately should really be reposted to the public list by the submitter and everyone then adds their rvb/acks, etc on list themselves.

Sorry, I didn't know about the last part i.e. rvbs need to be added once again after reposting the patch.

Quoted 33 lines
Quoted 22 lines
Quoted 22 lines
---
 fs/xfs/libxfs/xfs_dir2_data.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/xfs/libxfs/xfs_dir2_data.c +3 -0
index dbcf58979a59..08c18e0c1baa 100644
@@ -178,6 +178,9 @@ __xfs_dir3_data_check(
 		struct xfs_dir2_data_unused	*dup = bp->b_addr + offset;
 		struct xfs_dir2_data_entry	*dep = bp->b_addr + offset;
 
+		if (offset + sizeof(*dup) > end)
+			return __this_address;
+
 		/*
 		 * If it's unused, look for the space in the bestfree table.
 		 * If we find it, account for that, else make sure it
@@ -210,6 +213,10 @@ __xfs_dir3_data_check(
 			lastfree = 1;
 			continue;
Quoted 8 lines

fs/xfs/libxfs/xfs_dir2_data.c __xfs_dir3_data_check( · line 222

Quoted 8 lines
fs/xfs/libxfs/xfs_dir2_data.c +4 -0
 		}
+
+		if (offset + sizeof(*dep) > end)
+			return __this_address;
+
 		/*
 		 * It's a real entry.  Validate the fields.
 		 * If this is a block directory then make sure it's

Nothing wrong with the code change, though.

Signature · 1 line
Chandan
#4 lore raw
Quoted 20 lines · Chandan Babu R
Quoted 19 lines · Dave Chinner
Quoted 6 lines · Chandan Babu R

[CC-ing linux-xfs mailing list]

Quoted 2 lines · lei lu

Add a check to make sure xfs_dir2_data_unused and xfs_dir2_data_entry don't stray beyond valid memory region.

How was this found? What symptoms did it have? i.e. How do we know if we've tripped over the same problem on an older LTS/distro kernel and need to backport it?

Quoted 6 lines
Quoted 2 lines

Also adding the missing RVB from Darrick,

Quoted 7 lines
Quoted 3 lines

That's not really normal process - adding third party tags like this are kinda frowned upon because there's no actual public record of Darrick saying this.

Ok. The patch was posted on [email protected] with me on CC. Hence, I had decided to forward the patch to linux-xfs for any reviews from the wider audience.

Ugh. More "security process" madness. Please at least tell us what context you are forwarding issues from so we aren't left guessing at what happened prior to the mailing list post...

Regardless, this issue is no different to any number of syzkaller bugs that have been reported over the past few years. [email protected] should be reserved for real security problems, not for reporting issues found by filesystem image fuzzers that require root permissions before the kernel can be exposed to them.

Quoted 7 lines
Quoted 4 lines

i.e. patches send privately should really be reposted to the public list by the submitter and everyone then adds their rvb/acks, etc on list themselves.

Sorry, I didn't know about the last part i.e. rvbs need to be added once again after reposting the patch.

I'm more concerned more about having an open, verifiable process. sobs and rvbs that stem from private discussions have no actual value because they are not verifiable via the archives of the public discussion on the issue.

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#5 lore raw
Quoted 33 lines · Dave Chinner
Quoted 20 lines · Chandan Babu R
Quoted 19 lines · Dave Chinner
Quoted 6 lines · Chandan Babu R

[CC-ing linux-xfs mailing list]

Quoted 2 lines · lei lu

Add a check to make sure xfs_dir2_data_unused and xfs_dir2_data_entry don't stray beyond valid memory region.

How was this found? What symptoms did it have? i.e. How do we know if we've tripped over the same problem on an older LTS/distro kernel and need to backport it?

Quoted 6 lines
Quoted 2 lines

Also adding the missing RVB from Darrick,

Quoted 7 lines
Quoted 3 lines

That's not really normal process - adding third party tags like this are kinda frowned upon because there's no actual public record of Darrick saying this.

Ok. The patch was posted on [email protected] with me on CC. Hence, I had decided to forward the patch to linux-xfs for any reviews from the wider audience.

Ugh. More "security process" madness. Please at least tell us what context you are forwarding issues from so we aren't left guessing at what happened prior to the mailing list post...

Quoted 6 lines

Regardless, this issue is no different to any number of syzkaller bugs that have been reported over the past few years. [email protected] should be reserved for real security problems, not for reporting issues found by filesystem image fuzzers that require root permissions before the kernel can be exposed to them.

Yes, I agree. Hence, I decided on forwarding the patch to linux-xfs mailing list. However, I now realize that I should have asked the patch author to post the patch on the mailing list. I am sorry about that.

Quoted 12 lines
Quoted 7 lines
Quoted 4 lines

i.e. patches send privately should really be reposted to the public list by the submitter and everyone then adds their rvb/acks, etc on list themselves.

Sorry, I didn't know about the last part i.e. rvbs need to be added once again after reposting the patch.

I'm more concerned more about having an open, verifiable process. sobs and rvbs that stem from private discussions have no actual value because they are not verifiable via the archives of the public discussion on the issue.

Signature · 1 line
Chandan