From: Chao Yu <chao@kernel.org>
To: Sergey Shtylyov <s.shtylyov@omp.ru>,
Jaegeuk Kim <jaegeuk@kernel.org>,
linux-f2fs-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] f2fs: data: fix possible overflow in check_swap_activate()
Date: Tue, 7 Nov 2023 23:29:53 +0800 [thread overview]
Message-ID: <e2167506-2b0a-a0f5-c0e9-0e8b6139c69e@kernel.org> (raw)
In-Reply-To: <20231025202019.5228-1-s.shtylyov@omp.ru>
Hi Sergey,
Thanks for the patch.
On 2023/10/26 4:20, Sergey Shtylyov wrote:
> In check_swap_activate(), if the *while* loop exits early (0- or 1-page
> long swap file), an overflow happens while calculating the value of the
> span parameter as the lowest_pblock variable ends up being greater than
> the highest_pblock variable. Let's set *span to 0 in this case...
What do you think of returning -EINVAL for such case? I assume this is a
corner case.
>
> Found by Linux Verification Center (linuxtesting.org) with the SVACE static
> analysis tool.
>
> Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
> ---
> This patch is against the 'master' branch of Jaegeuk Kim's F2FS repo...
>
> fs/f2fs/data.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 916e317ac925..342cb0d5056d 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -4047,7 +4047,10 @@ static int check_swap_activate(struct swap_info_struct *sis,
> cur_lblock += nr_pblocks;
> }
> ret = nr_extents;
> - *span = 1 + highest_pblock - lowest_pblock;
> + if (lowest_pblock <= highest_pblock)
if (unlikely(higest_pblock < lowest_pblock))
return -EINVAL;
*span = 1 + highest_pblock - lowest_pblock;
Thanks,
> + *span = 1 + highest_pblock - lowest_pblock;
> + else
> + *span = 0;
> if (cur_lblock == 0)
> cur_lblock = 1; /* force Empty message */
> sis->max = cur_lblock;
next prev parent reply other threads:[~2023-11-07 15:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-25 20:20 Sergey Shtylyov
2023-11-07 15:29 ` Chao Yu [this message]
2023-12-10 21:14 ` Sergey Shtylyov
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=e2167506-2b0a-a0f5-c0e9-0e8b6139c69e@kernel.org \
--to=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=s.shtylyov@omp.ru \
/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®