* [f2fs-dev] [PATCH] f2fs: file: add checks to f2fs_ioc_flush_device()
@ 2024-08-01 7:17 Roman Smirnov
2024-08-13 3:50 ` Chao Yu
0 siblings, 1 reply; 2+ messages in thread
From: Roman Smirnov @ 2024-08-01 7:17 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu
Cc: Sergey Shtylyov, lvc-project, linux-kernel, Karina Yankevich,
linux-f2fs-devel, Roman Smirnov
If invalid data is copied from user space and if GET_SEGNO()
returns NULL_SEGNO an overflow is possible.
Add checks for invalid values.
Found by Linux Verification Center (linuxtesting.org) with Svace.
Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
---
fs/f2fs/file.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 168f08507004..1b9c4fee9db1 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3093,6 +3093,9 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)
start_segno = dev_start_segno;
end_segno = min(start_segno + range.segments, dev_end_segno);
+ if (start_segno > F2FS_MAX_SEGMENT - range.segments || end_segno == NULL_SEGNO)
+ return -EINVAL;
+
while (start_segno < end_segno) {
if (!f2fs_down_write_trylock(&sbi->gc_lock)) {
ret = -EBUSY;
--
2.43.0
_______________________________________________
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] 2+ messages in thread* Re: [f2fs-dev] [PATCH] f2fs: file: add checks to f2fs_ioc_flush_device()
2024-08-01 7:17 [f2fs-dev] [PATCH] f2fs: file: add checks to f2fs_ioc_flush_device() Roman Smirnov
@ 2024-08-13 3:50 ` Chao Yu
0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2024-08-13 3:50 UTC (permalink / raw)
To: Roman Smirnov, Jaegeuk Kim
Cc: lvc-project, Sergey Shtylyov, linux-kernel, Karina Yankevich,
linux-f2fs-devel
On 2024/8/1 15:17, Roman Smirnov wrote:
> If invalid data is copied from user space and if GET_SEGNO()
> returns NULL_SEGNO an overflow is possible.
Can you explain in which condition that FDEV(range.dev_num).start_blk or
FDEV(range.dev_num).end_blk will be invalid?
> > Add checks for invalid values.
>
> Found by Linux Verification Center (linuxtesting.org) with Svace.
>
> Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
> ---
> fs/f2fs/file.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 168f08507004..1b9c4fee9db1 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -3093,6 +3093,9 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)
> start_segno = dev_start_segno;
> end_segno = min(start_segno + range.segments, dev_end_segno);
>
> + if (start_segno > F2FS_MAX_SEGMENT - range.segments || end_segno == NULL_SEGNO)
> + return -EINVAL;
It missed to call mnt_drop_write_file() before return.
Thanks,
> +
> while (start_segno < end_segno) {
> if (!f2fs_down_write_trylock(&sbi->gc_lock)) {
> ret = -EBUSY;
_______________________________________________
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] 2+ messages in thread
end of thread, other threads:[~2024-08-13 3:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-01 7:17 [f2fs-dev] [PATCH] f2fs: file: add checks to f2fs_ioc_flush_device() Roman Smirnov
2024-08-13 3:50 ` Chao Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).