Linux filesystem development
 help / color / mirror / Atom feed
* [PATCH] zonefs: handle integer overflow in zonefs_fname_to_fno
@ 2026-04-29 20:58 Johannes Thumshirn
  2026-04-29 22:41 ` Damien Le Moal
  2026-05-11 22:55 ` Damien Le Moal
  0 siblings, 2 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2026-04-29 20:58 UTC (permalink / raw)
  To: Damien Le Moal
  Cc: Naohiro Aota, linux-fsdevel, Alexey Dobriyan, 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.

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

Reported-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/zonefs/super.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
index 9b646cb5335d..c3b497707f82 100644
--- a/fs/zonefs/super.c
+++ b/fs/zonefs/super.c
@@ -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;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] zonefs: handle integer overflow in zonefs_fname_to_fno
  2026-04-29 20:58 [PATCH] zonefs: handle integer overflow in zonefs_fname_to_fno Johannes Thumshirn
@ 2026-04-29 22:41 ` Damien Le Moal
  2026-04-30 11:52   ` Johannes Thumshirn
  2026-05-11 22:55 ` Damien Le Moal
  1 sibling, 1 reply; 4+ messages in thread
From: Damien Le Moal @ 2026-04-29 22:41 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: Naohiro Aota, linux-fsdevel, Alexey Dobriyan

On 4/30/26 05:58, Johannes Thumshirn wrote:
> 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.
> 
> Reported-by: Alexey Dobriyan <adobriyan@gmail.com>
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

This needs a fixes tag I think.

> ---
>  fs/zonefs/super.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
> index 9b646cb5335d..c3b497707f82 100644
> --- a/fs/zonefs/super.c
> +++ b/fs/zonefs/super.c
> @@ -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;


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] zonefs: handle integer overflow in zonefs_fname_to_fno
  2026-04-29 22:41 ` Damien Le Moal
@ 2026-04-30 11:52   ` Johannes Thumshirn
  0 siblings, 0 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2026-04-30 11:52 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: Naohiro Aota, linux-fsdevel, Alexey Dobriyan

On 4/30/26 12:41 AM, Damien Le Moal wrote:
> On 4/30/26 05:58, Johannes Thumshirn wrote:
>> 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.
>>
>> Reported-by: Alexey Dobriyan <adobriyan@gmail.com>
>> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> 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?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] zonefs: handle integer overflow in zonefs_fname_to_fno
  2026-04-29 20:58 [PATCH] zonefs: handle integer overflow in zonefs_fname_to_fno Johannes Thumshirn
  2026-04-29 22:41 ` Damien Le Moal
@ 2026-05-11 22:55 ` Damien Le Moal
  1 sibling, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2026-05-11 22:55 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: Naohiro Aota, linux-fsdevel, Alexey Dobriyan

On 4/30/26 05:58, Johannes Thumshirn wrote:
> 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.
> 
> Reported-by: Alexey Dobriyan <adobriyan@gmail.com>
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

> ---
>  fs/zonefs/super.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
> index 9b646cb5335d..c3b497707f82 100644
> --- a/fs/zonefs/super.c
> +++ b/fs/zonefs/super.c
> @@ -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;

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

>  	}
>  
>  	return fno;


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-11 22:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-29 20:58 [PATCH] zonefs: handle integer overflow in zonefs_fname_to_fno Johannes Thumshirn
2026-04-29 22:41 ` Damien Le Moal
2026-04-30 11:52   ` Johannes Thumshirn
2026-05-11 22:55 ` Damien Le Moal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox