Skip to content

Commit a39c460

Browse files
Christoph Hellwigmartinetd
authored andcommitted
net/9p: validate fds in p9_fd_open
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 attempting a read or write, but a new warning added in linux-next upsets syzcaller. Fix this by just verifying the fds early on. Link: http://lkml.kernel.org/r/[email protected] Reported-by: [email protected] Signed-off-by: Christoph Hellwig <[email protected]> [Dominique: amend goto as per Doug Nazar's review] Signed-off-by: Dominique Martinet <[email protected]>
1 parent 11ba468 commit a39c460

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

net/9p/trans_fd.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -803,20 +803,28 @@ static int p9_fd_open(struct p9_client *client, int rfd, int wfd)
803803
return -ENOMEM;
804804

805805
ts->rd = fget(rfd);
806+
if (!ts->rd)
807+
goto out_free_ts;
808+
if (!(ts->rd->f_mode & FMODE_READ))
809+
goto out_put_rd;
806810
ts->wr = fget(wfd);
807-
if (!ts->rd || !ts->wr) {
808-
if (ts->rd)
809-
fput(ts->rd);
810-
if (ts->wr)
811-
fput(ts->wr);
812-
kfree(ts);
813-
return -EIO;
814-
}
811+
if (!ts->wr)
812+
goto out_put_rd;
813+
if (!(ts->wr->f_mode & FMODE_WRITE))
814+
goto out_put_wr;
815815

816816
client->trans = ts;
817817
client->status = Connected;
818818

819819
return 0;
820+
821+
out_put_wr:
822+
fput(ts->wr);
823+
out_put_rd:
824+
fput(ts->rd);
825+
out_free_ts:
826+
kfree(ts);
827+
return -EIO;
820828
}
821829

822830
static int p9_socket_open(struct p9_client *client, struct socket *csocket)

0 commit comments

Comments
 (0)