Skip to content

Commit e0c47a5

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 fe6402e commit e0c47a5

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

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

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

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

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

0 commit comments

Comments
 (0)