Skip to content

Commit ad00e62

Browse files
Tetsuo Handaaxboe
authored andcommitted
io_uring/net: check socket is valid in io_bind()/io_listen()
We need to check that sock_from_file(req->file) != NULL. Reported-by: syzbot <syzbot+1e811482aa2c70afa9a0@syzkaller.appspotmail.com> Closes: https://syzkaller.appspot.com/bug?extid=1e811482aa2c70afa9a0 Fixes: 7481fd9 ("io_uring: Introduce IORING_OP_BIND") Fixes: ff140cc ("io_uring: Introduce IORING_OP_LISTEN") Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Link: https://lore.kernel.org/r/903da529-eaa3-43ef-ae41-d30f376c60cc@I-love.SAKURA.ne.jp [axboe: move assignment of sock to where the NULL check is] Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 943ad0b commit ad00e62

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

io_uring/net.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,9 +1747,14 @@ int io_bind(struct io_kiocb *req, unsigned int issue_flags)
17471747
{
17481748
struct io_bind *bind = io_kiocb_to_cmd(req, struct io_bind);
17491749
struct io_async_msghdr *io = req->async_data;
1750+
struct socket *sock;
17501751
int ret;
17511752

1752-
ret = __sys_bind_socket(sock_from_file(req->file), &io->addr, bind->addr_len);
1753+
sock = sock_from_file(req->file);
1754+
if (unlikely(!sock))
1755+
return -ENOTSOCK;
1756+
1757+
ret = __sys_bind_socket(sock, &io->addr, bind->addr_len);
17531758
if (ret < 0)
17541759
req_set_fail(req);
17551760
io_req_set_res(req, ret, 0);
@@ -1770,9 +1775,14 @@ int io_listen_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
17701775
int io_listen(struct io_kiocb *req, unsigned int issue_flags)
17711776
{
17721777
struct io_listen *listen = io_kiocb_to_cmd(req, struct io_listen);
1778+
struct socket *sock;
17731779
int ret;
17741780

1775-
ret = __sys_listen_socket(sock_from_file(req->file), listen->backlog);
1781+
sock = sock_from_file(req->file);
1782+
if (unlikely(!sock))
1783+
return -ENOTSOCK;
1784+
1785+
ret = __sys_listen_socket(sock, listen->backlog);
17761786
if (ret < 0)
17771787
req_set_fail(req);
17781788
io_req_set_res(req, ret, 0);

0 commit comments

Comments
 (0)