mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Jeff Layton <jlayton@kernel.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	Miklos Szeredi <miklos@szeredi.hu>, Ian Kent <raven@themaw.net>,
	Josef Bacik <josef@toxicpanda.com>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/3] fs: don't let statmount return empty strings
Date: Mon, 11 Nov 2024 18:44:03 +0100	[thread overview]
Message-ID: <20241111174403.qm7eqdl5pxwjhb3h@quack3> (raw)
In-Reply-To: <20241111-statmount-v4-1-2eaf35d07a80@kernel.org>

On Mon 11-11-24 10:09:55, Jeff Layton wrote:
> When one of the statmount_string() handlers doesn't emit anything to
> seq, the kernel currently sets the corresponding flag and emits an empty
> string.
> 
> Given that statmount() returns a mask of accessible fields, just leave
> the bit unset in this case, and skip any NULL termination. If nothing
> was emitted to the seq, then the EOVERFLOW and EAGAIN cases aren't
> applicable and the function can just return immediately.
> 
> Signed-off-by: Jeff Layton <jlayton@kernel.org>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/namespace.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/namespace.c b/fs/namespace.c
> index ba77ce1c6788dfe461814b5826fcbb3aab68fad4..28ad153b1fb6f49653c0a85d12da457c4650a87e 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -5046,22 +5046,23 @@ static int statmount_string(struct kstatmount *s, u64 flag)
>  	size_t kbufsize;
>  	struct seq_file *seq = &s->seq;
>  	struct statmount *sm = &s->sm;
> +	u32 start = seq->count;
>  
>  	switch (flag) {
>  	case STATMOUNT_FS_TYPE:
> -		sm->fs_type = seq->count;
> +		sm->fs_type = start;
>  		ret = statmount_fs_type(s, seq);
>  		break;
>  	case STATMOUNT_MNT_ROOT:
> -		sm->mnt_root = seq->count;
> +		sm->mnt_root = start;
>  		ret = statmount_mnt_root(s, seq);
>  		break;
>  	case STATMOUNT_MNT_POINT:
> -		sm->mnt_point = seq->count;
> +		sm->mnt_point = start;
>  		ret = statmount_mnt_point(s, seq);
>  		break;
>  	case STATMOUNT_MNT_OPTS:
> -		sm->mnt_opts = seq->count;
> +		sm->mnt_opts = start;
>  		ret = statmount_mnt_opts(s, seq);
>  		break;
>  	default:
> @@ -5069,6 +5070,12 @@ static int statmount_string(struct kstatmount *s, u64 flag)
>  		return -EINVAL;
>  	}
>  
> +	/*
> +	 * If nothing was emitted, return to avoid setting the flag
> +	 * and terminating the buffer.
> +	 */
> +	if (seq->count == start)
> +		return ret;
>  	if (unlikely(check_add_overflow(sizeof(*sm), seq->count, &kbufsize)))
>  		return -EOVERFLOW;
>  	if (kbufsize >= s->bufsize)
> 
> -- 
> 2.47.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2024-11-11 17:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-11 15:09 [PATCH v4 0/3] fs: allow statmount to fetch the fs_subtype and sb_source Jeff Layton
2024-11-11 15:09 ` [PATCH v4 1/3] fs: don't let statmount return empty strings Jeff Layton
2024-11-11 17:44   ` Jan Kara [this message]
2024-11-11 15:09 ` [PATCH v4 2/3] fs: add the ability for statmount() to report the fs_subtype Jeff Layton
2024-11-11 15:09 ` [PATCH v4 3/3] fs: add the ability for statmount() to report the sb_source Jeff Layton
2024-11-12 10:32 ` [PATCH v4 0/3] fs: allow statmount to fetch the fs_subtype and sb_source Miklos Szeredi
2024-11-12 11:12   ` Jeff Layton
2024-11-12 13:39 ` Christian Brauner
2024-11-13 11:27   ` Karel Zak
2024-11-13 13:08     ` Miklos Szeredi
2024-11-13 13:45     ` Jeff Layton
2024-11-13 15:18       ` Jan Kara
2024-11-13 15:49         ` Miklos Szeredi
2024-11-13 16:00           ` Jan Kara
2024-11-14  1:45         ` Ian Kent
2024-11-14 11:56           ` Jan Kara
2024-11-14 13:20             ` Miklos Szeredi
2024-11-17 23:29             ` Ian Kent
2024-11-18  9:07               ` Jan Kara
2024-11-14  1:51         ` Ian Kent
2024-11-14 11:29       ` Christian Brauner
2024-11-14 12:29         ` Jeff Layton
2024-11-14 13:16           ` Miklos Szeredi
2024-11-14 14:48             ` Christian Brauner
2024-11-14 14:51               ` Jeff Layton
2024-11-14 15:09                 ` Christian Brauner

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=20241111174403.qm7eqdl5pxwjhb3h@quack3 \
    --to=jack@suse.cz \
    --cc=brauner@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=raven@themaw.net \
    --cc=viro@zeniv.linux.org.uk \
    /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®