Skip to contentSkip to conversation

zonefs: handle integer overflow in zonefs_fname_to_fno

PATCH Applied Johannes Thumshirn 2 participants 4 messages Apr 29 – May 11

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

PATCH 1/1 zonefs: handle integer overflow in zonefs_fname_to_fno

In zonefs the file name in one of the two directories corresponds to the zone number.

Here Alexey reported a possible integer overflow in zonefs_fname_to_fno(), where the parsing of the zone number from the file name can overflow the 'long' data type.

Add a check for integer overflows and if the fno 'long' did overflow return -ENOENT.

---
 fs/zonefs/super.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/zonefs/super.c +5 -1
index 9b646cb5335d..c3b497707f82 100644
@@ -610,11 +610,15 @@ static long zonefs_fname_to_fno(const struct qstr *fname)
 		return c - '0';
 
 	for (i = 0, rname = name + len - 1; i < len; i++, rname--) {
+		long digit;
+
 		c = *rname;
 		if (!isdigit(c))
 			return -ENOENT;
-		fno += (c - '0') * shift;
+		digit = (c - '0') * shift;
 		shift *= 10;
+		if (check_add_overflow(fno, digit, &fno))
+			return -ENOENT;
 	}
 
 	return fno;
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 7 lines · Johannes Thumshirn

In zonefs the file name in one of the two directories corresponds to the zone number.

Here Alexey reported a possible integer overflow in zonefs_fname_to_fno(), where the parsing of the zone number from the file name can overflow the 'long' data type.

Quoted 5 lines

Add a check for integer overflows and if the fno 'long' did overflow return -ENOENT.

This needs a fixes tag I think.

Quoted 25 lines
---
 fs/zonefs/super.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/zonefs/super.c +5 -1
index 9b646cb5335d..c3b497707f82 100644
@@ -610,11 +610,15 @@ static long zonefs_fname_to_fno(const struct qstr *fname)
 		return c - '0';
 
 	for (i = 0, rname = name + len - 1; i < len; i++, rname--) {
+		long digit;
+
 		c = *rname;
 		if (!isdigit(c))
 			return -ENOENT;
-		fno += (c - '0') * shift;
+		digit = (c - '0') * shift;
 		shift *= 10;
+		if (check_add_overflow(fno, digit, &fno))
+			return -ENOENT;
 	}
 
 	return fno;
Signature · 2 lines
Damien Le Moal
Western Digital Research
#2 lore raw
Quoted 8 lines · Damien Le Moal
Quoted 7 lines · Johannes Thumshirn

In zonefs the file name in one of the two directories corresponds to the zone number.

Here Alexey reported a possible integer overflow in zonefs_fname_to_fno(), where the parsing of the zone number from the file name can overflow the 'long' data type.

Quoted 6 lines
Quoted 5 lines

Add a check for integer overflows and if the fno 'long' did overflow return -ENOENT.

This needs a fixes tag I think.

That would then be:

Fixes d207794ababe ("zonefs: Dynamically create file inodes when needed")

Can you add it when applying or should I resend?

maintainer Applied
#3 lore raw
In reply to Johannes Thumshirn
Quoted 7 lines · Johannes Thumshirn

In zonefs the file name in one of the two directories corresponds to the zone number.

Here Alexey reported a possible integer overflow in zonefs_fname_to_fno(), where the parsing of the zone number from the file name can overflow the 'long' data type.

Quoted 5 lines

Add a check for integer overflows and if the fno 'long' did overflow return -ENOENT.

Applied to for-7.1-fixes, with the Fixes tag added.

Quoted 12 lines
---
 fs/zonefs/super.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/zonefs/super.c +0 -0
index 9b646cb5335d..c3b497707f82 100644
@@ -610,11 +610,15 @@ static long zonefs_fname_to_fno(const struct qstr *fname)
 		return c - '0';
 
 	for (i = 0, rname = name + len - 1; i < len; i++, rname--) {

fs/zonefs/super.c static long zonefs_fname_to_fno(const struct qstr *fname) · line 621

Quoted 10 lines
fs/zonefs/super.c +5 -1
+		long digit;
+
 		c = *rname;
 		if (!isdigit(c))
 			return -ENOENT;
-		fno += (c - '0') * shift;
+		digit = (c - '0') * shift;
 		shift *= 10;
+		if (check_add_overflow(fno, digit, &fno))
+			return -ENOENT;

Note: I moved this hunk one line up, keeping "shift *= 10;" as the last line of the loop.

Quoted 3 lines
fs/zonefs/super.c +0 -0
 	}
 
 	return fno;
Signature · 2 lines
Damien Le Moal
Western Digital Research