All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>, Jakub Kicinski <kuba@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 4.19 08/14] tun: honor IOCB_NOWAIT flag
Date: Thu,  3 Dec 2020 08:30:04 -0500	[thread overview]
Message-ID: <20201203133010.931600-8-sashal@kernel.org> (raw)
In-Reply-To: <20201203133010.931600-1-sashal@kernel.org>

From: Jens Axboe <axboe@kernel.dk>

[ Upstream commit 5aac0390a63b8718237a61dd0d24a29201d1c94a ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/tun.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index d84a09172ddbf..fe0e02e11f294 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1988,12 +1988,15 @@ static ssize_t tun_chr_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	struct tun_file *tfile = file->private_data;
 	struct tun_struct *tun = tun_get(tfile);
 	ssize_t result;
+	int noblock = 0;
 
 	if (!tun)
 		return -EBADFD;
 
-	result = tun_get_user(tun, tfile, NULL, from,
-			      file->f_flags & O_NONBLOCK, false);
+	if ((file->f_flags & O_NONBLOCK) || (iocb->ki_flags & IOCB_NOWAIT))
+		noblock = 1;
+
+	result = tun_get_user(tun, tfile, NULL, from, noblock, false);
 
 	tun_put(tun);
 	return result;
@@ -2214,10 +2217,15 @@ static ssize_t tun_chr_read_iter(struct kiocb *iocb, struct iov_iter *to)
 	struct tun_file *tfile = file->private_data;
 	struct tun_struct *tun = tun_get(tfile);
 	ssize_t len = iov_iter_count(to), ret;
+	int noblock = 0;
 
 	if (!tun)
 		return -EBADFD;
-	ret = tun_do_read(tun, tfile, to, file->f_flags & O_NONBLOCK, NULL);
+
+	if ((file->f_flags & O_NONBLOCK) || (iocb->ki_flags & IOCB_NOWAIT))
+		noblock = 1;
+
+	ret = tun_do_read(tun, tfile, to, noblock, NULL);
 	ret = min_t(ssize_t, ret, len);
 	if (ret > 0)
 		iocb->ki_pos = ret;
-- 
2.27.0


  parent reply	other threads:[~2020-12-03 13:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03 13:29 [PATCH AUTOSEL 4.19 01/14] iwlwifi: pcie: limit memory read spin time Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 4.19 02/14] arm64: dts: rockchip: Assign a fixed index to mmc devices on rk3399 boards Sasha Levin
2020-12-03 13:29   ` Sasha Levin
2020-12-03 13:29   ` Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 4.19 03/14] iwlwifi: mvm: fix kernel panic in case of assert during CSA Sasha Levin
2020-12-03 13:30 ` [PATCH AUTOSEL 4.19 04/14] powerpc: Drop -me200 addition to build flags Sasha Levin
2020-12-03 13:30   ` Sasha Levin
2020-12-03 13:30 ` [PATCH AUTOSEL 4.19 05/14] ARC: stack unwinding: don't assume non-current task is sleeping Sasha Levin
2020-12-03 13:30   ` Sasha Levin
2020-12-03 13:30 ` [PATCH AUTOSEL 4.19 06/14] scsi: ufs: Make sure clk scaling happens only when HBA is runtime ACTIVE Sasha Levin
2020-12-03 13:30   ` Sasha Levin
2020-12-03 13:30   ` Sasha Levin
2020-12-03 13:30 ` [PATCH AUTOSEL 4.19 07/14] usbnet: ipheth: fix connectivity with iOS 14 Sasha Levin
2020-12-03 13:30 ` Sasha Levin [this message]
2020-12-03 13:30 ` [PATCH AUTOSEL 4.19 09/14] irqchip/gic-v3-its: Unconditionally save/restore the ITS state on suspend Sasha Levin
2020-12-03 13:30 ` [PATCH AUTOSEL 4.19 10/14] soc: fsl: dpio: Get the cpumask through cpumask_of(cpu) Sasha Levin
2020-12-03 13:30   ` Sasha Levin
2020-12-03 13:30   ` Sasha Levin
2020-12-03 13:30 ` [PATCH AUTOSEL 4.19 11/14] platform/x86: thinkpad_acpi: Do not report SW_TABLET_MODE on Yoga 11e Sasha Levin
2020-12-03 13:30 ` [PATCH AUTOSEL 4.19 12/14] platform/x86: thinkpad_acpi: Add BAT1 is primary battery quirk for Thinkpad Yoga 11e 4th gen Sasha Levin
2020-12-03 13:30 ` [PATCH AUTOSEL 4.19 13/14] platform/x86: acer-wmi: add automatic keyboard background light toggle key as KEY_LIGHTS_TOGGLE Sasha Levin
2020-12-03 13:30 ` [PATCH AUTOSEL 4.19 14/14] platform/x86: intel-vbtn: Support for tablet mode on HP Pavilion 13 x360 PC Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201203133010.931600-8-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.