Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1677822pxu; Sun, 6 Dec 2020 03:45:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpV9cmxiDIHulBtKH96OPKoeud4UsYGuORqII2w8K0m0pFRxxaK8cIgh7zQY3KbXyOsQ+X X-Received: by 2002:a17:906:e082:: with SMTP id gh2mr14239278ejb.406.1607255151650; Sun, 06 Dec 2020 03:45:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607255151; cv=none; d=google.com; s=arc-20160816; b=kbM2oZOStT49WP1XCZUVfDVJFQq3vJzPMyRYpMcygAuFt4HoPZfsb1MTSnIzFRmtkw jDfnW7utkErq2kpqnHZlH1w56b4+lqGFa1ASqb0ou8h5y8CxSfJr+v0qQEpOz2sJnaVQ iaz3ltV5/8yZ9w3TBvIJ9Zif0qh94kNlUvHOrfXARNJGnanJPVAlA/2SzDhQYkeGfl3P MoJSQCofa1TvyhM9zUFCMSZeAzK73RUyPnROJ4OfmMwWh1p2CZbcmlXOI+lPAoKBoMH5 pNM3dAax+fbNecPWhq0u0DoP0tQd4kZojPOTGHTCZDZ1k5PL7NwTKdPUvO9LGGrY2hTV hLYA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=QD0avDLH66kbcHYOtoJptWzy0CtBBLtyLJdTvEx3RiA=; b=zlE8aHHqoCVxIHHd5bo8XADpQlpBlk8VKfKCWoMtZ/xZB11k+E0QZEm9CrkPii+QXm JuoMBM76bFC94URs9zkBVLFeL+h1h38UH8Kv8BuGx7bdcyuzD5Ku3KFKUzoFYlzgfhpd asjn/Sqo93IUkYymyq2eWCblc5HoHnGrDtSut+UPNmRLaybgJz8q3tRdn2uAx5eXGfG5 djdX9/MpwMnGTCaF2Fo4mGYbXpGdwXba47R4RpK5GpU/seL8gNRBaeT7yokuPsfv0GGs nvifkCocipzgcB3L6jVi4vl76QiMOGIBtu8GkDAl3+I1jaQhLxo+0nTbq4shx8nv3rdD U3mw== 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i11si8082816edb.323.2020.12.06.03.45.29; Sun, 06 Dec 2020 03:45:51 -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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728692AbgLFLlA (ORCPT + 99 others); Sun, 6 Dec 2020 06:41:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:36754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728237AbgLFLjx (ORCPT ); Sun, 6 Dec 2020 06:39:53 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jens Axboe , Jakub Kicinski Subject: [PATCH 4.14 05/20] tun: honor IOCB_NOWAIT flag Date: Sun, 6 Dec 2020 12:17:08 +0100 Message-Id: <20201206111555.813046793@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201206111555.569713359@linuxfoundation.org> References: <20201206111555.569713359@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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: Greg Kroah-Hartman --- drivers/net/tun.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1601,12 +1601,15 @@ static ssize_t tun_chr_write_iter(struct struct tun_struct *tun = tun_get(file); struct tun_file *tfile = file->private_data; 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; @@ -1789,10 +1792,15 @@ static ssize_t tun_chr_read_iter(struct 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;