zonefs: handle integer overflow in zonefs_fname_to_fno
Subsystems (2)
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
@@ -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
Damien Le Moal
maintainerQuoted 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.Reported-by Alexey Dobriyan <[email protected]>Signed-off-by Johannes Thumshirn <[email protected]>
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@@ -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
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.Reported-by Alexey Dobriyan <[email protected]>Signed-off-by Johannes Thumshirn <[email protected]>This needs a fixes tag I think.
That would then be:
Can you add it when applying or should I resend?
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.Reported-by Alexey Dobriyan <[email protected]>Signed-off-by Johannes Thumshirn <[email protected]>
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@@ -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