mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roman Smirnov <r.smirnov@omp.ru>
To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>
Cc: Roman Smirnov <r.smirnov@omp.ru>,
	<linux-f2fs-devel@lists.sourceforge.net>,
	<linux-kernel@vger.kernel.org>,
	Sergey Shtylyov <s.shtylyov@omp.ru>,
	Karina Yankevich <k.yankevich@omp.ru>,
	<lvc-project@linuxtesting.org>
Subject: [PATCH] f2fs: file: add checks to f2fs_ioc_flush_device()
Date: Thu, 1 Aug 2024 10:17:07 +0300	[thread overview]
Message-ID: <20240801071707.8296-1-r.smirnov@omp.ru> (raw)

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


             reply	other threads:[~2024-08-01  7:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-01  7:17 Roman Smirnov [this message]
2024-08-13  3:50 ` Chao Yu

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=20240801071707.8296-1-r.smirnov@omp.ru \
    --to=r.smirnov@omp.ru \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=k.yankevich@omp.ru \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.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®