mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Zijun Hu <zijun_hu@icloud.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
	 David Howells <dhowells@redhat.com>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Zijun Hu <quic_zijuhu@quicinc.com>
Subject: Re: [PATCH 1/5] fs/filesystems: Fix potential unsigned integer underflow in fs_name()
Date: Fri, 11 Apr 2025 16:35:14 +0200	[thread overview]
Message-ID: <20250411-kaiman-bewahren-bef1f1baee8e@brauner> (raw)
In-Reply-To: <20250410-fix_fs-v1-1-7c14ccc8ebaa@quicinc.com>

On Thu, Apr 10, 2025 at 07:45:27PM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> fs_name() has @index as unsigned int, so there is underflow risk for
> operation '@index--'.
> 
> Fix by breaking the for loop when '@index == 0' which is also more proper
> than '@index <= 0' for unsigned integer comparison.
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---

This is honestly not worth the effort thinking about.
I'm going to propose that we remove this system call or at least switch
the default to N. Nobody uses this anymore I'm pretty sure.

>  fs/filesystems.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/filesystems.c b/fs/filesystems.c
> index 58b9067b2391ce814e580709b518b405e0f9cb8a..95e5256821a53494d88f496193305a2e50e04444 100644
> --- a/fs/filesystems.c
> +++ b/fs/filesystems.c
> @@ -156,15 +156,19 @@ static int fs_index(const char __user * __name)
>  static int fs_name(unsigned int index, char __user * buf)
>  {
>  	struct file_system_type * tmp;
> -	int len, res;
> +	int len, res = -EINVAL;
>  
>  	read_lock(&file_systems_lock);
> -	for (tmp = file_systems; tmp; tmp = tmp->next, index--)
> -		if (index <= 0 && try_module_get(tmp->owner))
> +	for (tmp = file_systems; tmp; tmp = tmp->next, index--) {
> +		if (index == 0) {
> +			if (try_module_get(tmp->owner))
> +				res = 0;
>  			break;
> +		}
> +	}
>  	read_unlock(&file_systems_lock);
> -	if (!tmp)
> -		return -EINVAL;
> +	if (res)
> +		return res;
>  
>  	/* OK, we got the reference, so we can safely block */
>  	len = strlen(tmp->name) + 1;
> 
> -- 
> 2.34.1
> 

  parent reply	other threads:[~2025-04-11 14:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10 11:45 [PATCH 0/5] fs: bug fixes Zijun Hu
2025-04-10 11:45 ` [PATCH 1/5] fs/filesystems: Fix potential unsigned integer underflow in fs_name() Zijun Hu
2025-04-11 14:34   ` (subset) " Christian Brauner
2025-04-11 14:35   ` Christian Brauner [this message]
2025-04-11 14:52     ` Zijun Hu
2025-04-10 11:45 ` [PATCH 2/5] fs/fs_parse: Fix macro fsparam_u32hex() definition Zijun Hu
2025-04-11 14:17   ` Christian Brauner
2025-04-11 14:25     ` Zijun Hu
2025-04-10 11:45 ` [PATCH 3/5] fs/fs_parse: Fix 3 issues for validate_constant_table() Zijun Hu
2025-04-11 14:37   ` Christian Brauner
2025-04-11 14:48     ` Zijun Hu
2025-04-14 12:39       ` Jan Kara
2025-04-10 11:45 ` [PATCH 4/5] fs/fs_parse: Correct comments of fs_validate_description() Zijun Hu
2025-04-11 14:20   ` (subset) " Christian Brauner
2025-04-10 11:45 ` [PATCH 5/5] fs/fs_context: Mark an unlikely if condition with unlikely() in vfs_parse_monolithic_sep() Zijun Hu
2025-04-11 14:24   ` (subset) " Christian Brauner
2025-04-11 15:34 ` [PATCH 1/5] fs/filesystems: Fix potential unsigned integer underflow in fs_name() David Howells
2025-04-11 16:06   ` Zijun Hu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250411-kaiman-bewahren-bef1f1baee8e@brauner \
    --to=brauner@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_zijuhu@quicinc.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zijun_hu@icloud.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®