mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: youngjun <her0gyugyu@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Tejun Heo <tj@kernel.org>,
	linux-kernel@vger.kernel.org, youngjun <her0gyugyu@gmail.com>
Subject: [PATCH] fs: kernfs: fix possible null pointer dereferences
Date: Thu, 30 Apr 2020 04:20:46 -0700	[thread overview]
Message-ID: <20200430112046.53721-1-her0gyugyu@gmail.com> (raw)

kernfs_path_from_node_locked checks buf is NULL.
But, two cases below are not covered.

if(!kn_to)			<--- case1 (buf can be NULL)
	return strlcpy(buf, "(null)", buflen);

if(kn_from == kn_to)		<--- case2 (buf can be NULL)
	return strlcpy(buf, "/", buflen);

if (!buf)			<--- checked here.
	return -EINVAL;

buf NULL case needs to be checked first.

Signed-off-by: youngjun <her0gyugyu@gmail.com>
---
 fs/kernfs/dir.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 02fb5cc76e33..d802cfceddba 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -128,6 +128,9 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to,
 	size_t depth_from, depth_to, len = 0;
 	int i, j;
 
+	if (!buf)
+		return -EINVAL;
+
 	if (!kn_to)
 		return strlcpy(buf, "(null)", buflen);
 
@@ -137,9 +140,6 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to,
 	if (kn_from == kn_to)
 		return strlcpy(buf, "/", buflen);
 
-	if (!buf)
-		return -EINVAL;
-
 	common = kernfs_common_ancestor(kn_from, kn_to);
 	if (WARN_ON(!common))
 		return -EINVAL;
-- 
2.17.1


             reply	other threads:[~2020-04-30 11:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-30 11:20 youngjun [this message]
2020-05-06 12:44 ` Greg Kroah-Hartman

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=20200430112046.53721-1-her0gyugyu@gmail.com \
    --to=her0gyugyu@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /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®