Skip to content

Commit edd9097

Browse files
Christoph Hellwiggregkh
authored andcommitted
net/9p: validate fds in p9_fd_open
[ Upstream commit a39c460 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent efde0dd commit edd9097

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
@@ -815,20 +815,28 @@ static int p9_fd_open(struct p9_client *client, int rfd, int wfd)
815815
return -ENOMEM;
816816

817817
ts->rd = fget(rfd);
818+
if (!ts->rd)
819+
goto out_free_ts;
820+
if (!(ts->rd->f_mode & FMODE_READ))
821+
goto out_put_rd;
818822
ts->wr = fget(wfd);
819-
if (!ts->rd || !ts->wr) {
820-
if (ts->rd)
821-
fput(ts->rd);
822-
if (ts->wr)
823-
fput(ts->wr);
824-
kfree(ts);
825-
return -EIO;
826-
}
823+
if (!ts->wr)
824+
goto out_put_rd;
825+
if (!(ts->wr->f_mode & FMODE_WRITE))
826+
goto out_put_wr;
827827

828828
client->trans = ts;
829829
client->status = Connected;
830830

831831
return 0;
832+
833+
out_put_wr:
834+
fput(ts->wr);
835+
out_put_rd:
836+
fput(ts->rd);
837+
out_free_ts:
838+
kfree(ts);
839+
return -EIO;
832840
}
833841

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

0 commit comments

Comments
 (0)