mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Aldo Ariel Panzardo <qwe.aldo@gmail.com>,
	Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	 stable@vger.kernel.org
Subject: Re: [PATCH v2] nilfs2: validate segment number in nilfs_sufile_get_suinfo()
Date: Wed, 16 Sep 2026 12:06:16 -0700	[thread overview]
Message-ID: <8eef80c6c8d21e863c5a3721b1ae681fc4ccf54f.camel@dubeyko.com> (raw)
In-Reply-To: <20260915195223.3331909-1-qwe.aldo@gmail.com>

On Tue, 2026-09-15 at 16:52 -0300, Aldo Ariel Panzardo wrote:
> nilfs_sufile_get_suinfo() subtracts the caller-provided segment
> number
> from the total number of segments without first checking its range.
> If
> the requested number is greater than the total, the unsigned
> subtraction
> wraps and the function may process segment numbers outside the
> filesystem.
> 
> Cache the total while holding the metadata semaphore and return no
> entries
> when the starting segment number is at or beyond the end.
> 
> Fixes: 6c98cd4ecb0a ("nilfs2: segment usage file")
> Cc: stable@vger.kernel.org
> Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
> ---
>  fs/nilfs2/sufile.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c
> index eceedca026..573646c5f7 100644
> --- a/fs/nilfs2/sufile.c
> +++ b/fs/nilfs2/sufile.c
> @@ -870,10 +870,14 @@ ssize_t nilfs_sufile_get_suinfo(struct inode
> *sufile, __u64 segnum, void *buf,
>  
>  	down_read(&NILFS_MDT(sufile)->mi_sem);
>  
> +	nsegs = nilfs_sufile_get_nsegments(sufile);
> +	if (segnum >= nsegs) {
> +		ret = 0;
> +		goto out;
> +	}
> +
>  	segusages_per_block =
> nilfs_sufile_segment_usages_per_block(sufile);
> -	nsegs = min_t(unsigned long,
> -		      nilfs_sufile_get_nsegments(sufile) - segnum,
> -		      nsi);
> +	nsegs = min_t(unsigned long, nsegs - segnum, nsi);
>  	for (i = 0; i < nsegs; i += n, segnum += n) {
>  		n = min_t(unsigned long,
>  			  segusages_per_block -

Looks good to me.

Reviewed-by: Viacheslav Dubeyko <slava@dubeyko.com>

Thanks,
Slava.

  reply	other threads:[~2026-09-16 19:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <MSG-ID-sufile-v1>
2026-09-15 19:51 ` [PATCH] " Aldo Ariel Panzardo
2026-09-15 19:52 ` [PATCH v2] " Aldo Ariel Panzardo
2026-09-16 19:06   ` Viacheslav Dubeyko [this message]
2026-09-17 15:46     ` Ryusuke Konishi
2026-09-17 16:05       ` Ryusuke Konishi
2026-09-17 19:35         ` Viacheslav Dubeyko

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=8eef80c6c8d21e863c5a3721b1ae681fc4ccf54f.camel@dubeyko.com \
    --to=slava@dubeyko.com \
    --cc=konishi.ryusuke@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nilfs@vger.kernel.org \
    --cc=qwe.aldo@gmail.com \
    --cc=stable@vger.kernel.org \
    /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®