mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 1/2] fs: fail gracefully in get_mounted_path/get_cdev_by_mountpath
Date: Mon,  8 May 2023 09:46:11 +0200	[thread overview]
Message-ID: <20230508074612.3313870-1-a.fatoum@pengutronix.de> (raw)

get_fsdevice_by_path will return NULL if no file system was mounted at
location. Returned pointer was dereferenced unconditionally, potentially
leading to null pointer dereference. Fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fs.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 65e4c661b9ce..368458cc54f8 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -240,6 +240,8 @@ struct cdev *get_cdev_by_mountpath(const char *path)
 	struct fs_device *fsdev;
 
 	fsdev = get_fsdevice_by_path(path);
+	if (!fsdev)
+		return NULL;
 
 	return fsdev->cdev;
 }
@@ -249,6 +251,8 @@ char *get_mounted_path(const char *path)
 	struct fs_device *fdev;
 
 	fdev = get_fsdevice_by_path(path);
+	if (!fdev)
+		return NULL;
 
 	return fdev->path;
 }
-- 
2.39.2




             reply	other threads:[~2023-05-08  7:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08  7:46 Ahmad Fatoum [this message]
2023-05-08  7:46 ` [PATCH master 2/2] block: refuse registering block devices with absurdly large blocks Ahmad Fatoum
2023-05-08 13:18 ` [PATCH master 1/2] fs: fail gracefully in get_mounted_path/get_cdev_by_mountpath Sascha Hauer

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=20230508074612.3313870-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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