linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/9p: validate fds in p9_fd_open
@ 2020-07-10  8:57 Christoph Hellwig
  2020-07-10 11:12 ` Dominique Martinet
  2020-07-10 22:56 ` Doug Nazar
  0 siblings, 2 replies; 11+ messages in thread
From: Christoph Hellwig @ 2020-07-10  8:57 UTC (permalink / raw)
  To: ericvh, lucho, asmadeus
  Cc: v9fs-developer, netdev, linux-kernel, syzbot+e6f77e16ff68b2434a2c

p9_fd_open just fgets file descriptors passed in from userspace, but
doesn't verify that they are valid for read or writing.  This gets
cought down in the VFS when actually attemping a read or write, but a
new warning added in linux-next upsets syzcaller.

Fix this by just verifying the fds early on.

Reported-by: syzbot+e6f77e16ff68b2434a2c@syzkaller.appspotmail.com
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 net/9p/trans_fd.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
index 13cd683a658ab6..1cd8ea0e493617 100644
--- a/net/9p/trans_fd.c
+++ b/net/9p/trans_fd.c
@@ -803,20 +803,28 @@ static int p9_fd_open(struct p9_client *client, int rfd, int wfd)
 		return -ENOMEM;
 
 	ts->rd = fget(rfd);
+	if (!ts->rd)
+		goto out_free_ts;
+	if (!(ts->rd->f_mode & FMODE_READ))
+		goto out_put_wr;
 	ts->wr = fget(wfd);
-	if (!ts->rd || !ts->wr) {
-		if (ts->rd)
-			fput(ts->rd);
-		if (ts->wr)
-			fput(ts->wr);
-		kfree(ts);
-		return -EIO;
-	}
+	if (!ts->wr)
+		goto out_put_rd;
+	if (!(ts->wr->f_mode & FMODE_WRITE))
+		goto out_put_wr;
 
 	client->trans = ts;
 	client->status = Connected;
 
 	return 0;
+
+out_put_wr:
+	fput(ts->wr);
+out_put_rd:
+	fput(ts->rd);
+out_free_ts:
+	kfree(ts);
+	return -EIO;
 }
 
 static int p9_socket_open(struct p9_client *client, struct socket *csocket)
-- 
2.26.2


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

end of thread, other threads:[~2020-07-16 20:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-10  8:57 [PATCH] net/9p: validate fds in p9_fd_open Christoph Hellwig
2020-07-10 11:12 ` Dominique Martinet
2020-07-10 22:56 ` Doug Nazar
2020-07-11 10:49   ` Dominique Martinet
2020-07-13  7:38     ` Christoph Hellwig
2020-07-15  7:37     ` Christoph Hellwig
2020-07-15 13:47       ` Dominique Martinet
2020-07-15 18:19         ` Christoph Hellwig
2020-07-15 21:24         ` David Miller
2020-07-16  7:58           ` Dominique Martinet
2020-07-16 20:13             ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).