All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] autofs4: Do not potentially dereference NULL pointer returned by fget() in autofs_dev_ioctl_setpipefd()
@ 2010-12-18 21:43 Jesper Juhl
  2010-12-28  2:36 ` Ian Kent
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Jesper Juhl @ 2010-12-18 21:43 UTC (permalink / raw)
  To: autofs; +Cc: linux-kernel, Ian Kent

Hi,

In fs/autofs4/dev-ioctl.c::autofs_dev_ioctl_setpipefd() we call fget(), 
which may return NULL, but we do not explicitly test for that NULL return 
so we may end up dereferencing a NULL pointer - bad.

When I originally submitted this patch I had chosen EBUSY as the return 
value to use if this happens. Ian Kent was kind enough to explain why that 
would most likely be wrong and why EBADF should most likely be used 
instead. This version of the patch uses EBADF.


Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 dev-ioctl.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
index eff9a41..a650d7e 100644
--- a/fs/autofs4/dev-ioctl.c
+++ b/fs/autofs4/dev-ioctl.c
@@ -372,6 +372,10 @@ static int autofs_dev_ioctl_setpipefd(struct file *fp,
 		return -EBUSY;
 	} else {
 		struct file *pipe = fget(pipefd);
+		if (!pipe) {
+			err = -EBADF;
+			goto out;
+		}
 		if (!pipe->f_op || !pipe->f_op->write) {
 			err = -EPIPE;
 			fput(pipe);



-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.

^ permalink raw reply related	[flat|nested] 9+ messages in thread
* [PATCH][RFC] autofs4: Do not potentially dereference null pointer returned by fget() in autofs_dev_ioctl_setpipefd()
@ 2010-12-12 23:02 Jesper Juhl
  2010-12-15  3:03 ` [autofs] " Ian Kent
  0 siblings, 1 reply; 9+ messages in thread
From: Jesper Juhl @ 2010-12-12 23:02 UTC (permalink / raw)
  To: autofs; +Cc: linux-kernel, Ian Kent

Hi,

In fs/autofs4/dev-ioctl.c::autofs_dev_ioctl_setpipefd() we call fget(), 
which may return NULL, but we do not explicitly test for that NULL return 
so we may end up dereferencing a NULL pointer - bad.

A comment in fget() says "File object ref couldn't be taken" when that 
function returns NULL, so I guess EBUSY is the proper error to return from 
autofs_dev_ioctl_setpipefd() when this happens, but I'm far from sure 
about this, so I'd like some feedback before this patch is merged.


Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 dev-ioctl.c |    4 ++++
 1 file changed, 4 insertions(+)

 compile tested only.

diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
index eff9a41..ab551ee 100644
--- a/fs/autofs4/dev-ioctl.c
+++ b/fs/autofs4/dev-ioctl.c
@@ -372,6 +372,10 @@ static int autofs_dev_ioctl_setpipefd(struct file *fp,
 		return -EBUSY;
 	} else {
 		struct file *pipe = fget(pipefd);
+		if (!pipe) {
+			err = -EBUSY;
+			goto out;
+		}
 		if (!pipe->f_op || !pipe->f_op->write) {
 			err = -EPIPE;
 			fput(pipe);



-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.

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

end of thread, other threads:[~2011-01-25  1:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-18 21:43 [PATCH] autofs4: Do not potentially dereference NULL pointer returned by fget() in autofs_dev_ioctl_setpipefd() Jesper Juhl
2010-12-28  2:36 ` Ian Kent
2011-01-02 12:52 ` Autofs SMBFS no write in files Issa
2011-01-05 16:38   ` Carter, Joel
2011-01-05 18:53     ` Issa
2011-01-24 19:51 ` [PATCH] autofs4: Do not potentially dereference NULL pointer returned by fget() in autofs_dev_ioctl_setpipefd() Jesper Juhl
2011-01-24 20:03   ` Jesper Juhl
2011-01-25  1:55     ` Ian Kent
  -- strict thread matches above, loose matches on Subject: below --
2010-12-12 23:02 [PATCH][RFC] autofs4: Do not potentially dereference null " Jesper Juhl
2010-12-15  3:03 ` [autofs] " Ian Kent
2010-12-17 12:07   ` Jesper Juhl
2010-12-28 18:51     ` Autofs SMBFS no write in files Issa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.