mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Su Hui <suhui@nfschina.com>
To: jack@suse.cz, amir73il@gmail.com, repnop@google.com
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org, Su Hui <suhui@nfschina.com>
Subject: [PATCH] fanotify: avoid possible NULL dereference
Date: Tue,  8 Aug 2023 17:18:50 +0800	[thread overview]
Message-ID: <20230808091849.505809-1-suhui@nfschina.com> (raw)

smatch error:
fs/notify/fanotify/fanotify_user.c:462 copy_fid_info_to_user():
we previously assumed 'fh' could be null (see line 421)

Fixes: afc894c784c8 ("fanotify: Store fanotify handles differently")
Signed-off-by: Su Hui <suhui@nfschina.com>
---
 fs/notify/fanotify/fanotify_user.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index f69c451018e3..5a5487ae2460 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -459,12 +459,13 @@ static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh,
 	if (WARN_ON_ONCE(len < sizeof(handle)))
 		return -EFAULT;
 
-	handle.handle_type = fh->type;
 	handle.handle_bytes = fh_len;
 
 	/* Mangle handle_type for bad file_handle */
 	if (!fh_len)
 		handle.handle_type = FILEID_INVALID;
+	else
+		handle.handle_type = fh->type;
 
 	if (copy_to_user(buf, &handle, sizeof(handle)))
 		return -EFAULT;
-- 
2.30.2


             reply	other threads:[~2023-08-09  1:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-08  9:18 Su Hui [this message]
2023-08-10 17:58 ` Amir Goldstein
2024-01-02 13:47   ` Jan Kara

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=20230808091849.505809-1-suhui@nfschina.com \
    --to=suhui@nfschina.com \
    --cc=amir73il@gmail.com \
    --cc=jack@suse.cz \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=repnop@google.com \
    /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®