Skip to contentSkip to conversation

exfat: Fix use after free in exfat_load_upcase_table()

PATCH New Markus Elfring 4 participants 8 messages Jun 8, 2020 – Jun 10, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw
Quoted 2 lines

This code calls brelse(bh) and then dereferences "bh" on the next line resulting in a possible use after free.

There is an unfortunate function call sequence.

Quoted 1 line

The brelse() should just be moved down a line.

How do you think about a wording variant like the following?

Thus move a call of the function “brelse” one line down.

Would you like to omit a word from the patch subject so that a typo will be avoided there?

Regards,
Markus

#1 lore raw
Quoted 8 lines · Markus Elfring
Quoted 2 lines

This code calls brelse(bh) and then dereferences "bh" on the next line resulting in a possible use after free.

There is an unfortunate function call sequence.

Quoted 1 line

The brelse() should just be moved down a line.

Quoted 7 lines

How do you think about a wording variant like the following?

Thus move a call of the function “brelse” one line down.

Would you like to omit a word from the patch subject so that a typo will be avoided there?

Markus, please go away. This comment is entirely unhelpful.

#2 lore raw
Quoted 11 lines
Quoted 9 lines
Quoted 1 line

The brelse() should just be moved down a line.

How do you think about a wording variant like the following?

Thus move a call of the function “brelse” one line down.

Would you like to omit a word from the patch subject so that a typo will be avoided there?

Markus, please go away. This comment is entirely unhelpful.

I hope that other contributors can get also more positive impressions (as it happened before).

Regards,
Markus

#3 lore raw
In reply to Markus Elfring
Quoted 8 lines · Markus Elfring
Quoted 2 lines

This code calls brelse(bh) and then dereferences "bh" on the next line resulting in a possible use after free.

There is an unfortunate function call sequence.

Quoted 1 line

The brelse() should just be moved down a line.

Quoted 7 lines

How do you think about a wording variant like the following?

Thus move a call of the function “brelse” one line down.

Would you like to omit a word from the patch subject so that a typo will be avoided there?

Hi,

This is the semi-friendly patch-bot of Greg Kroah-Hartman.

Markus, you seem to have sent a nonsensical or otherwise pointless review comment to a patch submission on a Linux kernel developer mailing list. I strongly suggest that you not do this anymore. Please do not bother developers who are actively working to produce patches and features with comments that, in the end, are a waste of time.

Patch submitter, please ignore Markus's suggestion; you do not need to follow it at all. The person/bot/AI that sent it is being ignored by almost all Linux kernel maintainers for having a persistent pattern of behavior of producing distracting and pointless commentary, and inability to adapt to feedback. Please feel free to also ignore emails from them.

thanks,

greg k-h's patch email bot

#4 lore raw

Re: exfat: Improving exception handling in two functions

In reply to Markus Elfring

Hello,

I have taken another look at pointer usage after calls of the function “brelse”. My source code analysis approach pointed implementation details like the following out for further software development considerations.
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/fs/exfat/namei.c?id=3d155ae4358baf4831609c2f9cd09396a2b8badf#n1078

…

		epold = exfat_get_dentry(sb, p_dir, oldentry + 1, &old_bh,
			&sector_old);
		epnew = exfat_get_dentry(sb, p_dir, newentry + 1, &new_bh,
			&sector_new);
		if (!epold || !epnew)
			return -EIO;

…

I suggest to split such an error check.
How do you think about to release a buffer head object for the desired exception handling if one of these function calls succeeded?

Would you like to adjust such code in the functions “exfat_rename_file” and “exfat_move_file”?

Regards,
Markus

#5 lore raw

PATCH 1/1 exfat: call brelse() on error path

If the second exfat_get_dentry() call fails then we need to release "old_bh" before returning.

---
 fs/exfat/namei.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/exfat/namei.c +5 -1
index 5b0f35329d63e..fda92c824ff11 100644
@@ -1077,10 +1077,14 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
 
 		epold = exfat_get_dentry(sb, p_dir, oldentry + 1, &old_bh,
 			&sector_old);
+		if (!epold)
+			return -EIO;
 		epnew = exfat_get_dentry(sb, p_dir, newentry + 1, &new_bh,
 			&sector_new);
-		if (!epold || !epnew)
+		if (!epnew) {
+			brelse(old_bh);
 			return -EIO;
+		}
 
 		memcpy(epnew, epold, DENTRY_SIZE);
 		exfat_update_bh(sb, new_bh, sync);
Signature · 1 line
2.26.2
#6 lore raw

Re: exfat: Improving exception handling in two functions

In reply to Markus Elfring
Quoted 2 lines

My source code analysis approach pointed implementation details like the following out for further software development considerations.

The clarification of corresponding collateral evolution will be continued with the update suggestion “exfat: call brelse() on error path”.
https://lore.kernel.org/linux-fsdevel/20200610095934.GA35167@mwanda/
https://lore.kernel.org/patchwork/patch/1254515/

Regards,
Markus

#7 lore raw

Re: exfat: Improving exception handling in two functions

In reply to Markus Elfring
Quoted 20 lines · Markus Elfring

Hello,

I have taken another look at pointer usage after calls of the function “brelse”. My source code analysis approach pointed implementation details like the following out for further software development considerations.
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/fs/exfat/namei.c?id=155ae4358baf4831609c2f9cd09396a2b8badf#n1078

…

		epold = exfat_get_dentry(sb, p_dir, oldentry + 1, &old_bh,
			&sector_old);
		epnew = exfat_get_dentry(sb, p_dir, newentry + 1, &new_bh,
			&sector_new);
		if (!epold || !epnew)
			return -EIO;

…

I suggest to split such an error check.
How do you think about to release a buffer head object for the desired exception handling if one of these function calls succeeded?

Quoted 5 lines

Would you like to adjust such code in the functions “exfat_rename_file” and “exfat_move_file”?

Regards,
Markus

Hi,

This is the semi-friendly patch-bot of Greg Kroah-Hartman.

Markus, you seem to have sent a nonsensical or otherwise pointless review comment to a patch submission on a Linux kernel developer mailing list. I strongly suggest that you not do this anymore. Please do not bother developers who are actively working to produce patches and features with comments that, in the end, are a waste of time.

Patch submitter, please ignore Markus's suggestion; you do not need to follow it at all. The person/bot/AI that sent it is being ignored by almost all Linux kernel maintainers for having a persistent pattern of behavior of producing distracting and pointless commentary, and inability to adapt to feedback. Please feel free to also ignore emails from them.

thanks,

greg k-h's patch email bot