Skip to content

Commit 5aac039

Browse files
axboekuba-moo
authored andcommitted
tun: honor IOCB_NOWAIT flag
tun only checks the file O_NONBLOCK flag, but it should also be checking the iocb IOCB_NOWAIT flag. Any fops using ->read/write_iter() should check both, otherwise it breaks users that correctly expect O_NONBLOCK semantics if IOCB_NOWAIT is set. Signed-off-by: Jens Axboe <axboe@kernel.dk> Link: https://lore.kernel.org/r/e9451860-96cc-c7c7-47b8-fe42cadd5f4c@kernel.dk Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent c5dab09 commit 5aac039

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

drivers/net/tun.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,12 +1961,15 @@ static ssize_t tun_chr_write_iter(struct kiocb *iocb, struct iov_iter *from)
19611961
struct tun_file *tfile = file->private_data;
19621962
struct tun_struct *tun = tun_get(tfile);
19631963
ssize_t result;
1964+
int noblock = 0;
19641965

19651966
if (!tun)
19661967
return -EBADFD;
19671968

1968-
result = tun_get_user(tun, tfile, NULL, from,
1969-
file->f_flags & O_NONBLOCK, false);
1969+
if ((file->f_flags & O_NONBLOCK) || (iocb->ki_flags & IOCB_NOWAIT))
1970+
noblock = 1;
1971+
1972+
result = tun_get_user(tun, tfile, NULL, from, noblock, false);
19701973

19711974
tun_put(tun);
19721975
return result;
@@ -2185,10 +2188,15 @@ static ssize_t tun_chr_read_iter(struct kiocb *iocb, struct iov_iter *to)
21852188
struct tun_file *tfile = file->private_data;
21862189
struct tun_struct *tun = tun_get(tfile);
21872190
ssize_t len = iov_iter_count(to), ret;
2191+
int noblock = 0;
21882192

21892193
if (!tun)
21902194
return -EBADFD;
2191-
ret = tun_do_read(tun, tfile, to, file->f_flags & O_NONBLOCK, NULL);
2195+
2196+
if ((file->f_flags & O_NONBLOCK) || (iocb->ki_flags & IOCB_NOWAIT))
2197+
noblock = 1;
2198+
2199+
ret = tun_do_read(tun, tfile, to, noblock, NULL);
21922200
ret = min_t(ssize_t, ret, len);
21932201
if (ret > 0)
21942202
iocb->ki_pos = ret;

0 commit comments

Comments
 (0)