mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix opening empty path
@ 2021-05-07 10:56 Sascha Hauer
  2021-05-07 10:56 ` [PATCH 1/3] fs: check for empty name in getname() Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2021-05-07 10:56 UTC (permalink / raw)
  To: Barebox List; +Cc: Neeraj Pal

barebox currently crashes when an empty path is passed to open().
This can be provoked with doing a 'nfs foo ""' on the command line. This
series fixes the issue.

Sascha Hauer (3):
  fs: check for empty name in getname()
  fs: check for valid name in filename_lookup()
  fs: check getname() return value in open()

 fs/fs.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] fs: check for empty name in getname()
  2021-05-07 10:56 [PATCH 0/3] Fix opening empty path Sascha Hauer
@ 2021-05-07 10:56 ` Sascha Hauer
  2021-05-07 10:56 ` [PATCH 2/3] fs: check for valid name in filename_lookup() Sascha Hauer
  2021-05-07 10:56 ` [PATCH 3/3] fs: check getname() return value in open() Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2021-05-07 10:56 UTC (permalink / raw)
  To: Barebox List; +Cc: Neeraj Pal

getname() should return an error for an empty path. While at it, change
getname() to return an error pointer.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 6de5a3b59e..09fccf9c28 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1866,14 +1866,17 @@ static struct filename *getname(const char *filename)
 {
 	struct filename *result;
 
+	if (!*filename)
+		return ERR_PTR(-ENOENT);
+
 	result = malloc(sizeof(*result));
 	if (!result)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	result->name = strdup(filename);
 	if (!result->name) {
 		free(result);
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 	}
 
 	result->refcnt = 1;
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] fs: check for valid name in filename_lookup()
  2021-05-07 10:56 [PATCH 0/3] Fix opening empty path Sascha Hauer
  2021-05-07 10:56 ` [PATCH 1/3] fs: check for empty name in getname() Sascha Hauer
@ 2021-05-07 10:56 ` Sascha Hauer
  2021-05-07 10:56 ` [PATCH 3/3] fs: check getname() return value in open() Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2021-05-07 10:56 UTC (permalink / raw)
  To: Barebox List; +Cc: Neeraj Pal

The getname() return value is passed to filename_lookup() without
checking the return value, so this must be done in filename_lookup().

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 09fccf9c28..2eaf7eaa37 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2189,6 +2189,9 @@ static int filename_lookup(int dfd, struct filename *name, unsigned flags,
 	struct nameidata nd;
 	const char *s;
 
+	if (IS_ERR(name))
+		return PTR_ERR(name);
+
 	set_nameidata(&nd, dfd, name);
 
 	s = path_init(&nd, flags);
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] fs: check getname() return value in open()
  2021-05-07 10:56 [PATCH 0/3] Fix opening empty path Sascha Hauer
  2021-05-07 10:56 ` [PATCH 1/3] fs: check for empty name in getname() Sascha Hauer
  2021-05-07 10:56 ` [PATCH 2/3] fs: check for valid name in filename_lookup() Sascha Hauer
@ 2021-05-07 10:56 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2021-05-07 10:56 UTC (permalink / raw)
  To: Barebox List; +Cc: Neeraj Pal

getname() can return an error when for example the input path is an
empty string. Check the getname() return value in open() before
further using it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/fs.c b/fs/fs.c
index 2eaf7eaa37..f4baba81e7 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2368,8 +2368,14 @@ int open(const char *pathname, int flags, ...)
 	struct dentry *dentry = NULL;
 	struct nameidata nd;
 	const char *s;
+	struct filename *filename;
+
+	filename = getname(pathname);
+	if (IS_ERR(filename))
+		return PTR_ERR(filename);
+
+	set_nameidata(&nd, AT_FDCWD, filename);
 
-	set_nameidata(&nd, AT_FDCWD, getname(pathname));
 	s = path_init(&nd, LOOKUP_FOLLOW);
 
 	while (1) {
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-07 10:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 10:56 [PATCH 0/3] Fix opening empty path Sascha Hauer
2021-05-07 10:56 ` [PATCH 1/3] fs: check for empty name in getname() Sascha Hauer
2021-05-07 10:56 ` [PATCH 2/3] fs: check for valid name in filename_lookup() Sascha Hauer
2021-05-07 10:56 ` [PATCH 3/3] fs: check getname() return value in open() Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox