* [PATCH] f2fs: data: fix possible overflow in check_swap_activate()
@ 2023-10-25 20:20 ` Sergey Shtylyov
0 siblings, 0 replies; 6+ messages in thread
From: Sergey Shtylyov @ 2023-10-25 20:20 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu, linux-f2fs-devel; +Cc: linux-kernel
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...
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)
+ *span = 1 + highest_pblock - lowest_pblock;
+ else
+ *span = 0;
if (cur_lblock == 0)
cur_lblock = 1; /* force Empty message */
sis->max = cur_lblock;
--
2.26.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [f2fs-dev] [PATCH] f2fs: data: fix possible overflow in check_swap_activate()
@ 2023-10-25 20:20 ` Sergey Shtylyov
0 siblings, 0 replies; 6+ messages in thread
From: Sergey Shtylyov @ 2023-10-25 20:20 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu, linux-f2fs-devel; +Cc: linux-kernel
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...
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)
+ *span = 1 + highest_pblock - lowest_pblock;
+ else
+ *span = 0;
if (cur_lblock == 0)
cur_lblock = 1; /* force Empty message */
sis->max = cur_lblock;
--
2.26.3
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] f2fs: data: fix possible overflow in check_swap_activate()
2023-10-25 20:20 ` [f2fs-dev] " Sergey Shtylyov
@ 2023-11-07 15:29 ` Chao Yu
-1 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2023-11-07 15:29 UTC (permalink / raw)
To: Sergey Shtylyov, Jaegeuk Kim, linux-f2fs-devel; +Cc: linux-kernel
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;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: data: fix possible overflow in check_swap_activate()
@ 2023-11-07 15:29 ` Chao Yu
0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2023-11-07 15:29 UTC (permalink / raw)
To: Sergey Shtylyov, Jaegeuk Kim, linux-f2fs-devel; +Cc: linux-kernel
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;
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] f2fs: data: fix possible overflow in check_swap_activate()
2023-11-07 15:29 ` [f2fs-dev] " Chao Yu
@ 2023-12-10 21:14 ` Sergey Shtylyov
-1 siblings, 0 replies; 6+ messages in thread
From: Sergey Shtylyov @ 2023-12-10 21:14 UTC (permalink / raw)
To: Chao Yu, Jaegeuk Kim, linux-f2fs-devel; +Cc: linux-kernel
Hello!
Sorry for replying a month later than I should -- I got distracted by the
other Svace reports... It took a significant part of the weekend to swap this
stuff back in... :-/
On 11/7/23 6:29 PM, Chao Yu 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.
I don't know the code well enough but I got the impression that iff
we have a file containing a single page, we'd have one successful call
of add_swap_extent(). Am I missing something?
>> 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))
Well, Greg KH says we shouldn't use unlikely() unless we can prove
that it indeed improves things...
> 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;
MBR, Sergey
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: data: fix possible overflow in check_swap_activate()
@ 2023-12-10 21:14 ` Sergey Shtylyov
0 siblings, 0 replies; 6+ messages in thread
From: Sergey Shtylyov @ 2023-12-10 21:14 UTC (permalink / raw)
To: Chao Yu, Jaegeuk Kim, linux-f2fs-devel; +Cc: linux-kernel
Hello!
Sorry for replying a month later than I should -- I got distracted by the
other Svace reports... It took a significant part of the weekend to swap this
stuff back in... :-/
On 11/7/23 6:29 PM, Chao Yu 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.
I don't know the code well enough but I got the impression that iff
we have a file containing a single page, we'd have one successful call
of add_swap_extent(). Am I missing something?
>> 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))
Well, Greg KH says we shouldn't use unlikely() unless we can prove
that it indeed improves things...
> 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;
MBR, Sergey
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-12-10 21:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-25 20:20 [PATCH] f2fs: data: fix possible overflow in check_swap_activate() Sergey Shtylyov
2023-10-25 20:20 ` [f2fs-dev] " Sergey Shtylyov
2023-11-07 15:29 ` Chao Yu
2023-11-07 15:29 ` [f2fs-dev] " Chao Yu
2023-12-10 21:14 ` Sergey Shtylyov
2023-12-10 21:14 ` [f2fs-dev] " Sergey Shtylyov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.