Skip to contentSkip to conversation

f2fs: avoid abnormal behavior on broken symlink

DISCUSSION Dan Carpenter 3 participants 9 messages Apr 20, 2015 – Apr 22, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello Jaegeuk Kim,

The patch feb7cbb079e6: "f2fs: avoid abnormal behavior on broken symlink" from Apr 15, 2015, leads to the following static checker warning:

	fs/f2fs/namei.c:304 f2fs_follow_link()
	warn: 'page' isn't an ERR_PTR

fs/f2fs/namei.c
299 static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd) 300 {
301 struct page *page;
302
303 page = page_follow_link_light(dentry, nd);
304 if (IS_ERR(page))

                           ^^^^

The code in page_follow_link_light() is a bit hard to follow but it returns NULL on error.

305 return page;
306
307 /* this is broken symlink case */
308 if (*nd_get_link(nd) == 0) {

   309                  kunmap(page);
                        ^^^^^^^^^^^^

Potential NULL deref.

   310                  page_cache_release(page);
   311                  return ERR_PTR(-ENOENT);
   312          }
   313          return page;
   314  }

regards,
dan carpenter

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF

maintainer
#1 lore raw

Hi Dan,

Thank you for letting me know.
I wrote a patch for this below.

Thanks,

Quoted 34 lines · Dan Carpenter

Hello Jaegeuk Kim,

The patch feb7cbb079e6: "f2fs: avoid abnormal behavior on broken symlink" from Apr 15, 2015, leads to the following static checker warning:

	fs/f2fs/namei.c:304 f2fs_follow_link()
	warn: 'page' isn't an ERR_PTR

fs/f2fs/namei.c
299 static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd)

   300  {
   301          struct page *page;
   302  
   303          page = page_follow_link_light(dentry, nd);
   304          if (IS_ERR(page))
                           ^^^^

The code in page_follow_link_light() is a bit hard to follow but it returns NULL on error.

   305                  return page;
   306  
   307          /* this is broken symlink case */
   308          if (*nd_get_link(nd) == 0) {
   309                  kunmap(page);
                        ^^^^^^^^^^^^

Potential NULL deref.

   310                  page_cache_release(page);
   311                  return ERR_PTR(-ENOENT);
   312          }
   313          return page;
   314  }
Quoted 4 lines

regards,
dan carpenter

From 52889398489d4edc0cb016ae24036b994e3d9ccd Mon Sep 17 00:00:00 2001

From: Jaegeuk Kim <[email protected]>
Date: Mon, 20 Apr 2015 16:30:14 -0700
Subject: [PATCH] f2fs: fix wrong error hanlder in f2fs_follow_link

The page_follow_link_light returns NULL and its error pointer was remained in nd->path.

---
 fs/f2fs/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/namei.c +2 -2
index 407dde3..678b6dd 100644
@@ -301,8 +301,8 @@ static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd)
 	struct page *page;
 
 	page = page_follow_link_light(dentry, nd);
-	if (IS_ERR(page))
-		return page;
+	if (!page)
+		return NULL;
 
 	/* this is broken symlink case */
 	if (*nd_get_link(nd) == 0) {
Signature · 8 lines
2.1.1

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
#2 lore raw

Hi all,

Quoted 7 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Wednesday, April 22, 2015 2:21 AM
To: Dan Carpenter
Cc: [email protected]
Subject: Re: [f2fs-dev] f2fs: avoid abnormal behavior on broken symlink

Quoted 27 lines

Hi Dan,

Thank you for letting me know.
I wrote a patch for this below.

Thanks,

Quoted 19 lines · Dan Carpenter

Hello Jaegeuk Kim,

The patch feb7cbb079e6: "f2fs: avoid abnormal behavior on broken symlink" from Apr 15, 2015, leads to the following static checker warning:

	fs/f2fs/namei.c:304 f2fs_follow_link()
	warn: 'page' isn't an ERR_PTR

fs/f2fs/namei.c
299 static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd)

   300  {
   301          struct page *page;
   302
   303          page = page_follow_link_light(dentry, nd);
   304          if (IS_ERR(page))
                           ^^^^

The code in page_follow_link_light() is a bit hard to follow but it returns NULL on error.

I try to find out the other callers' error handling method for page_follow_link_light, and it shows all of them use the "IS_ERR" one.

In page_follow_link_light I also can't find a path which will return a NULL value.

So, Dan, is that report from smatch not true? or I made a mistake? If so, please correct me.

Thanks,

Quoted 50 lines
Quoted 15 lines
   305                  return page;
   306
   307          /* this is broken symlink case */
   308          if (*nd_get_link(nd) == 0) {
   309                  kunmap(page);
                        ^^^^^^^^^^^^

Potential NULL deref.

   310                  page_cache_release(page);
   311                  return ERR_PTR(-ENOENT);
   312          }
   313          return page;
   314  }
Quoted 4 lines

regards,
dan carpenter

From 52889398489d4edc0cb016ae24036b994e3d9ccd Mon Sep 17 00:00:00 2001

From: Jaegeuk Kim <[email protected]>
Date: Mon, 20 Apr 2015 16:30:14 -0700
Subject: [PATCH] f2fs: fix wrong error hanlder in f2fs_follow_link

The page_follow_link_light returns NULL and its error pointer was remained in nd->path.

---
 fs/f2fs/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/namei.c +2 -3
index 407dde3..678b6dd 100644
@@ -301,8 +301,8 @@ static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd)
 	struct page *page;
 
 	page = page_follow_link_light(dentry, nd);
-	if (IS_ERR(page))
-		return page;
+	if (!page)
+		return NULL;
 
 	/* this is broken symlink case */
 	if (*nd_get_link(nd) == 0) {
--

2.1.1

Quoted 10 lines

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF

maintainer
#3 lore raw

Hi Chao,

Quoted 37 lines · Chao Yu

Hi all,

Quoted 7 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Wednesday, April 22, 2015 2:21 AM
To: Dan Carpenter
Cc: [email protected]
Subject: Re: [f2fs-dev] f2fs: avoid abnormal behavior on broken symlink

Quoted 27 lines

Hi Dan,

Thank you for letting me know.
I wrote a patch for this below.

Thanks,

Quoted 19 lines · Dan Carpenter

Hello Jaegeuk Kim,

The patch feb7cbb079e6: "f2fs: avoid abnormal behavior on broken symlink" from Apr 15, 2015, leads to the following static checker warning:

	fs/f2fs/namei.c:304 f2fs_follow_link()
	warn: 'page' isn't an ERR_PTR

fs/f2fs/namei.c
299 static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd)

   300  {
   301          struct page *page;
   302
   303          page = page_follow_link_light(dentry, nd);
   304          if (IS_ERR(page))
                           ^^^^

The code in page_follow_link_light() is a bit hard to follow but it returns NULL on error.

Quoted 7 lines

I try to find out the other callers' error handling method for page_follow_link_light, and it shows all of them use the "IS_ERR" one.

In page_follow_link_light I also can't find a path which will return a NULL value.

So, Dan, is that report from smatch not true? or I made a mistake? If so, please correct me.

The page_getlink returns ERR_PTR(page) without setting *ppage. So, page_follow_link_light returns NULL and nd->saved_names[nd->depth] has error pointer by nd_set_link().

Thanks,

Quoted 53 lines

Thanks,

Quoted 50 lines
Quoted 15 lines
   305                  return page;
   306
   307          /* this is broken symlink case */
   308          if (*nd_get_link(nd) == 0) {
   309                  kunmap(page);
                        ^^^^^^^^^^^^

Potential NULL deref.

   310                  page_cache_release(page);
   311                  return ERR_PTR(-ENOENT);
   312          }
   313          return page;
   314  }
Quoted 4 lines

regards,
dan carpenter

From 52889398489d4edc0cb016ae24036b994e3d9ccd Mon Sep 17 00:00:00 2001

From: Jaegeuk Kim <[email protected]>
Date: Mon, 20 Apr 2015 16:30:14 -0700
Subject: [PATCH] f2fs: fix wrong error hanlder in f2fs_follow_link

The page_follow_link_light returns NULL and its error pointer was remained in nd->path.

---
 fs/f2fs/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/namei.c +2 -3
index 407dde3..678b6dd 100644
@@ -301,8 +301,8 @@ static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd)
 	struct page *page;
 
 	page = page_follow_link_light(dentry, nd);
-	if (IS_ERR(page))
-		return page;
+	if (!page)
+		return NULL;
 
 	/* this is broken symlink case */
 	if (*nd_get_link(nd) == 0) {
--

2.1.1

Quoted 10 lines
Quoted 10 lines

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF

#4 lore raw

Hi Jaegeuk,

Quoted 50 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Wednesday, April 22, 2015 3:49 PM
To: Chao Yu
Cc: 'Dan Carpenter'; [email protected]
Subject: Re: [f2fs-dev] f2fs: avoid abnormal behavior on broken symlink

Hi Chao,

Quoted 40 lines · Chao Yu

Hi all,

Quoted 7 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Wednesday, April 22, 2015 2:21 AM
To: Dan Carpenter
Cc: [email protected]
Subject: Re: [f2fs-dev] f2fs: avoid abnormal behavior on broken symlink

Quoted 27 lines

Hi Dan,

Thank you for letting me know.
I wrote a patch for this below.

Thanks,

Quoted 19 lines · Dan Carpenter

Hello Jaegeuk Kim,

The patch feb7cbb079e6: "f2fs: avoid abnormal behavior on broken symlink" from Apr 15, 2015, leads to the following static checker warning:

	fs/f2fs/namei.c:304 f2fs_follow_link()
	warn: 'page' isn't an ERR_PTR

fs/f2fs/namei.c
299 static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd)

   300  {
   301          struct page *page;
   302
   303          page = page_follow_link_light(dentry, nd);
   304          if (IS_ERR(page))
                           ^^^^

The code in page_follow_link_light() is a bit hard to follow but it returns NULL on error.

I try to find out the other callers' error handling method for page_follow_link_light, and it shows all of them use the "IS_ERR" one.

Quoted 8 lines
Quoted 4 lines

In page_follow_link_light I also can't find a path which will return a NULL value.

So, Dan, is that report from smatch not true? or I made a mistake? If so, please correct me.

The page_getlink returns ERR_PTR(page) without setting *ppage. So, page_follow_link_light returns NULL and nd->saved_names[nd->depth] has error pointer by nd_set_link().

Yes, I can see it in last linux-next repo. But in commit 093ee96e7e37 ("new ->follow_link() and ->put_link() calling conventions"), it has been refactored by Al Viro in his tree. You can see it in following link:

https://git.kernel.org/cgit/linux/kernel/git/viro/vfs.git/commit/?h=link_path_walk&id=093ee96e7e3770b7188ed8aec18378309da3fe79

If this commit is been merged into mainline, our patch could be a wrong fixing.

So how about keeping this patch and wait?

Thanks,

Quoted 57 lines

Thanks,

Quoted 35 lines

Thanks,

Quoted 32 lines
Quoted 15 lines
   305                  return page;
   306
   307          /* this is broken symlink case */
   308          if (*nd_get_link(nd) == 0) {
   309                  kunmap(page);
                        ^^^^^^^^^^^^

Potential NULL deref.

   310                  page_cache_release(page);
   311                  return ERR_PTR(-ENOENT);
   312          }
   313          return page;
   314  }
Quoted 4 lines

regards,
dan carpenter

From 52889398489d4edc0cb016ae24036b994e3d9ccd Mon Sep 17 00:00:00 2001

From: Jaegeuk Kim <[email protected]>
Date: Mon, 20 Apr 2015 16:30:14 -0700
Subject: [PATCH] f2fs: fix wrong error hanlder in f2fs_follow_link

The page_follow_link_light returns NULL and its error pointer was remained in nd->path.

---
 fs/f2fs/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 5 lines

fs/f2fs/namei.c static void *f2fs_follow_link(struct dentry *dentry, struct nameidata

Quoted 5 lines
fs/f2fs/namei.c +0 -0
index 407dde3..678b6dd 100644
@@ -301,8 +301,8 @@ static void *f2fs_follow_link(struct dentry *dentry, struct nameidata

*nd)

Quoted 13 lines
Quoted 13 lines
fs/f2fs/namei.c +2 -3
 	struct page *page;
 
 	page = page_follow_link_light(dentry, nd);
-	if (IS_ERR(page))
-		return page;
+	if (!page)
+		return NULL;
 
 	/* this is broken symlink case */
 	if (*nd_get_link(nd) == 0) {
--

2.1.1

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF

maintainer
#5 lore raw

Hi Chao,

Quoted 61 lines · Chao Yu

Hi Jaegeuk,

Quoted 50 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Wednesday, April 22, 2015 3:49 PM
To: Chao Yu
Cc: 'Dan Carpenter'; [email protected]
Subject: Re: [f2fs-dev] f2fs: avoid abnormal behavior on broken symlink

Hi Chao,

Quoted 40 lines · Chao Yu

Hi all,

Quoted 7 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Wednesday, April 22, 2015 2:21 AM
To: Dan Carpenter
Cc: [email protected]
Subject: Re: [f2fs-dev] f2fs: avoid abnormal behavior on broken symlink

Quoted 27 lines

Hi Dan,

Thank you for letting me know.
I wrote a patch for this below.

Thanks,

Quoted 19 lines · Dan Carpenter

Hello Jaegeuk Kim,

The patch feb7cbb079e6: "f2fs: avoid abnormal behavior on broken symlink" from Apr 15, 2015, leads to the following static checker warning:

	fs/f2fs/namei.c:304 f2fs_follow_link()
	warn: 'page' isn't an ERR_PTR

fs/f2fs/namei.c
299 static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd)

   300  {
   301          struct page *page;
   302
   303          page = page_follow_link_light(dentry, nd);
   304          if (IS_ERR(page))
                           ^^^^

The code in page_follow_link_light() is a bit hard to follow but it returns NULL on error.

I try to find out the other callers' error handling method for page_follow_link_light, and it shows all of them use the "IS_ERR" one.

Quoted 8 lines
Quoted 4 lines

In page_follow_link_light I also can't find a path which will return a NULL value.

So, Dan, is that report from smatch not true? or I made a mistake? If so, please correct me.

The page_getlink returns ERR_PTR(page) without setting *ppage. So, page_follow_link_light returns NULL and nd->saved_names[nd->depth] has error pointer by nd_set_link().

Quoted 7 lines

Yes, I can see it in last linux-next repo. But in commit 093ee96e7e37 ("new ->follow_link() and ->put_link() calling conventions"), it has been refactored by Al Viro in his tree. You can see it in following link:

https://git.kernel.org/cgit/linux/kernel/git/viro/vfs.git/commit/?h=link_path_walk&id=093ee96e7e3770b7188ed8aec18378309da3fe79

If this commit is been merged into mainline, our patch could be a wrong fixing.

AFAICT, that is not merged yet, which means Al needs to change f2fs_follow_link, since f2fs was merged already.

Quoted 2 lines

So how about keeping this patch and wait?

Sure. At least, I think that can be merged after rc1.

Thanks,

Quoted 60 lines

Thanks,

Quoted 57 lines

Thanks,

Quoted 35 lines

Thanks,

Quoted 32 lines
Quoted 15 lines
   305                  return page;
   306
   307          /* this is broken symlink case */
   308          if (*nd_get_link(nd) == 0) {
   309                  kunmap(page);
                        ^^^^^^^^^^^^

Potential NULL deref.

   310                  page_cache_release(page);
   311                  return ERR_PTR(-ENOENT);
   312          }
   313          return page;
   314  }
Quoted 4 lines

regards,
dan carpenter

From 52889398489d4edc0cb016ae24036b994e3d9ccd Mon Sep 17 00:00:00 2001

From: Jaegeuk Kim <[email protected]>
Date: Mon, 20 Apr 2015 16:30:14 -0700
Subject: [PATCH] f2fs: fix wrong error hanlder in f2fs_follow_link

The page_follow_link_light returns NULL and its error pointer was remained in nd->path.

---
 fs/f2fs/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 5 lines

fs/f2fs/namei.c static void *f2fs_follow_link(struct dentry *dentry, struct nameidata

Quoted 5 lines
fs/f2fs/namei.c +0 -0
index 407dde3..678b6dd 100644
@@ -301,8 +301,8 @@ static void *f2fs_follow_link(struct dentry *dentry, struct nameidata

*nd)

Quoted 13 lines
Quoted 13 lines
fs/f2fs/namei.c +2 -3
 	struct page *page;
 
 	page = page_follow_link_light(dentry, nd);
-	if (IS_ERR(page))
-		return page;
+	if (!page)
+		return NULL;
 
 	/* this is broken symlink case */
 	if (*nd_get_link(nd) == 0) {
--

2.1.1

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF

#6 lore raw
In reply to Chao Yu
Quoted 11 lines · Chao Yu
Quoted 10 lines
Quoted 10 lines

fs/f2fs/namei.c
299 static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd)

   300  {
   301          struct page *page;
   302
   303          page = page_follow_link_light(dentry, nd);
   304          if (IS_ERR(page))
                           ^^^^

The code in page_follow_link_light() is a bit hard to follow but it returns NULL on error.

Quoted 7 lines

I try to find out the other callers' error handling method for page_follow_link_light, and it shows all of them use the "IS_ERR" one.

In page_follow_link_light I also can't find a path which will return a NULL value.

So, Dan, is that report from smatch not true? or I made a mistake? If so, please correct me.

Smatch is correct, it returns NULL on error. However, I agree that it looks like it is supposed to return an ERR_PTR. Every caller seems to expect that.

I suspect the right fix is to change page_follow_link_light(). But I don't know this code very well so I just sent the bug report instead of fixing it myself. :)

regards,
dan carpenter

fs/namei.c +6 -1
index ffab2e0..5ca251e 100644
@@ -4473,7 +4473,12 @@ EXPORT_SYMBOL(page_readlink);
 void *page_follow_link_light(struct dentry *dentry, struct nameidata *nd)
 {
 	struct page *page = NULL;
-	nd_set_link(nd, page_getlink(dentry, &page));
+	char *link;
+
+	link = page_getlink(dentry, &page);
+	if (IS_ERR(link))
+		return link;
+	nd_set_link(nd, link);
 	return page;
 }
 EXPORT_SYMBOL(page_follow_link_light);

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF

maintainer
#7 lore raw
Quoted 15 lines · Dan Carpenter
Quoted 14 lines · Chao Yu
Quoted 10 lines
Quoted 10 lines

fs/f2fs/namei.c
299 static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd)

   300  {
   301          struct page *page;
   302
   303          page = page_follow_link_light(dentry, nd);
   304          if (IS_ERR(page))
                           ^^^^

The code in page_follow_link_light() is a bit hard to follow but it returns NULL on error.

I try to find out the other callers' error handling method for page_follow_link_light, and it shows all of them use the "IS_ERR" one.

Quoted 8 lines
Quoted 4 lines

In page_follow_link_light I also can't find a path which will return a NULL value.

So, Dan, is that report from smatch not true? or I made a mistake? If so, please correct me.

Smatch is correct, it returns NULL on error. However, I agree that it looks like it is supposed to return an ERR_PTR. Every caller seems to expect that.

Well, at least, it seems vfs handles the error correctly. The page_follow_link_light is used only by several filesystems.

And, follow_link is called by:

1. fs/namei.c <<follow_link>>
-> No problem. It checks the error with nd->saved_names.

2. fs/namei.c <<generic_readlink>>
-> No problem. The error is checked by readlink_copy.

Whatever it is expected or not, the fact is that there is no bug in vfs. So at this moment, IMO, it needs to fix f2fs_follow_link by adding IS_ERR_OR_NULL() to avoid all the cases (including the backporting effort).

As Chao mentioned, it seems that Al is going to fix that with new convention, though. :)

Thanks,

Quoted 16 lines

I suspect the right fix is to change page_follow_link_light(). But I don't know this code very well so I just sent the bug report instead of fixing it myself. :)

regards,
dan carpenter

fs/namei.c +0 -0
index ffab2e0..5ca251e 100644
@@ -4473,7 +4473,12 @@ EXPORT_SYMBOL(page_readlink);
 void *page_follow_link_light(struct dentry *dentry, struct nameidata *nd)
 {
 	struct page *page = NULL;

fs/namei.c EXPORT_SYMBOL(page_readlink); · line 4484

Quoted 10 lines
fs/namei.c +6 -1
-	nd_set_link(nd, page_getlink(dentry, &page));
+	char *link;
+
+	link = page_getlink(dentry, &page);
+	if (IS_ERR(link))
+		return link;
+	nd_set_link(nd, link);
 	return page;
 }
 EXPORT_SYMBOL(page_follow_link_light);

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF

#8 lore raw
Quoted 28 lines · Jaegeuk Kim
Quoted 15 lines · Dan Carpenter
Quoted 14 lines · Chao Yu
Quoted 10 lines
Quoted 10 lines

fs/f2fs/namei.c
299 static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd)

   300  {
   301          struct page *page;
   302
   303          page = page_follow_link_light(dentry, nd);
   304          if (IS_ERR(page))
                           ^^^^

The code in page_follow_link_light() is a bit hard to follow but it returns NULL on error.

I try to find out the other callers' error handling method for page_follow_link_light, and it shows all of them use the "IS_ERR" one.

Quoted 8 lines
Quoted 4 lines

In page_follow_link_light I also can't find a path which will return a NULL value.

So, Dan, is that report from smatch not true? or I made a mistake? If so, please correct me.

Smatch is correct, it returns NULL on error. However, I agree that it looks like it is supposed to return an ERR_PTR. Every caller seems to expect that.

Well, at least, it seems vfs handles the error correctly. The page_follow_link_light is used only by several filesystems.

Quoted 7 lines

And, follow_link is called by:

1. fs/namei.c <<follow_link>>
-> No problem. It checks the error with nd->saved_names.

2. fs/namei.c <<generic_readlink>>
-> No problem. The error is checked by readlink_copy.

You're right. My patch was wrong because it doesn't set nd->saved_names. But wow, though! So convoluted!

  4423  /*
  4424   * A helper for ->readlink().  This should be used *ONLY* for symlinks that
  4425   * have ->follow_link() touching nd only in nd_set_link().  Using (or not
  4426   * using) it for any given inode is up to filesystem.
  4427   */
  4428  int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)
  4429  {
  4430          struct nameidata nd;
  4431          void *cookie;
  4432          int res;
  4433  
  4434          nd.depth = 0;
  4435          cookie = dentry->d_inode->i_op->follow_link(dentry, &nd);
  4436          if (IS_ERR(cookie))
  4437                  return PTR_ERR(cookie);

Even though we don't return here, the rest of the function is a no-op.

  4438  
  4439          res = readlink_copy(buffer, buflen, nd_get_link(&nd));
  4440          if (dentry->d_inode->i_op->put_link)
  4441                  dentry->d_inode->i_op->put_link(dentry, &nd, cookie);
  4442          return res;
  4443  }
  4444  EXPORT_SYMBOL(generic_readlink);
Quoted 5 lines

Whatever it is expected or not, the fact is that there is no bug in vfs. So at this moment, IMO, it needs to fix f2fs_follow_link by adding IS_ERR_OR_NULL() to avoid all the cases (including the backporting effort).

I guess that works... The follow_link() functions often seem to return NULL on sucess. But the page_follow_link_light() only returns NULL on error. It's very strange.

regards,
dan carpenter

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF