Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp491646pxu; Thu, 3 Dec 2020 05:40:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwEegsv3AzjRvbDRNmllW+RUyBCUnhVdPehpCvkatw5YkyZ2G8Bi8rRfHRh8olcVBzAfr0m X-Received: by 2002:a17:906:cd06:: with SMTP id oz6mr2592495ejb.25.1607002839980; Thu, 03 Dec 2020 05:40:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607002839; cv=none; d=google.com; s=arc-20160816; b=XP5QcyFSzwSpYqU3+TUEwc7euwWnXNZurdasTy1Rz6mWbhFsdv/aWsH6QZ4R6sLwtt tssmt/AzAI23gYtDwRxZfyIqsSvQi5fmUmpVpHojoI5Yjf0RTKh0QgKoBDRke07sjQP/ eBWfpr2lRjJwAJh1SkdCoCqV/p4isXR/BZkd5kKbIzzQQouoOAD+xdlGk5n1/cTY3+MI oqwViiVKy/y+9NWvOr2DwCqG5LJCHY4XKmDmwAYvvlluut4kxRGfsyIoUci4AemSfbyO 8h0uYkU+GNc6p5csCHsx1YlifBPvw+w5Hd7T2UFLZlbmAHkeOY4S8WO5lYFur0prGn15 PP4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Uc65TheuzlP7MomAGoiql++yyjDi/NCJDOYxP5D6CaQ=; b=djTlItcfIaRxBJgLntibOvj6uEqE1TFNCkoFHn8zwSyG+gB9a21Gf2hyjv7j0zonRO jXuelYYphm4FuLcvPKD1n/5Mxn/jaVUcPM/GtZNr9ageEWL733zmV5VlKpNe7LStpFqG j6gBenIrwH3ViE2OYAIoMGSkEXkwmS9lXx8M0fzGs55MClVEa6NKHuJSA49chrH9uHWN /i3gQ8ml8hTnMUb8iaP8taCSaV/dxilCQAk8sfsc/S2OobP/Ucz7dVO0WXSM4nrgcEQC 8itDTRmsf9sUyYAV5bT6ePfaDwk9H9ClMVgL8uMqJMNB8PBxRRNVf7hnqU59LB46Yzsd ydZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b8si911953eds.509.2020.12.03.05.40.08; Thu, 03 Dec 2020 05:40:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436516AbgLCNaQ (ORCPT + 99 others); Thu, 3 Dec 2020 08:30:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:47782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436486AbgLCNaO (ORCPT ); Thu, 3 Dec 2020 08:30:14 -0500 From: Sasha Levin Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jens Axboe , Jakub Kicinski , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.9 17/39] tun: honor IOCB_NOWAIT flag Date: Thu, 3 Dec 2020 08:28:11 -0500 Message-Id: <20201203132834.930999-17-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201203132834.930999-1-sashal@kernel.org> References: <20201203132834.930999-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Axboe [ 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 Link: https://lore.kernel.org/r/e9451860-96cc-c7c7-47b8-fe42cadd5f4c@kernel.dk Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- 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 7959b5c2d11f1..b5f47d37ea1be 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1979,12 +1979,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; @@ -2203,10 +2206,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