Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1679235pxu; Sun, 6 Dec 2020 03:49:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJz15eYk3zAeBK9jq6Z/DM6c0+mDW9Mh+9ztM8GuN1H5PkgIRz5NvXqpJsVED+netib9jQSW X-Received: by 2002:a17:906:fc3:: with SMTP id c3mr922998ejk.474.1607255361611; Sun, 06 Dec 2020 03:49:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607255361; cv=none; d=google.com; s=arc-20160816; b=CMzEoinbi5oYZcQ/uOesdlF18ZJT+x+IZd87lLNORxeED038j1uWil5MH8/wBK1M5w wZlRvnemoeGFQICr05DEMccl+8P0HhJ30vGE6lsG92KdYwer2wpQD91af9brjHn3sFPY w35dlAjBG8Maqye1tRdE0NM0KZRCiU/vozrK++R2LKI/zZYHZf86xcynJOOEa4UESwPx VMptkS0eAZ9jk30PJo643XBLcgnPzaItapU3OgfVy/tCJ3bht8CbHDnrDQaf0RFbbZQE fB+XOZ8pe027WIAYVe4YSU8dE2D+sSHig+JliuDvXwqhwVvSjE/ahKHPNqvPnzdMs/v8 qzXQ== 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=z7fjj5MCsd01Xy3cTFHcJMDJkp08gTru4SBBJQJmptw=; b=j1LG3grPPCvGxyJa7IJlW46HkBpKHqvAbat9yglSoE35+3Hd0b6wpRkVKwJoHUCw8k Y9fkSU48z0WeFj1e9RlbLiVN2Tz4G+NKpyl/8tEBoHAamUCkuXbsfwq03jpkS7+1vuCC Fj8aoGi09Rf309nWE1vWZoYnSeOYywsJbY0X3JDdwzhK/nEx/7u+aR/iXqqHSHMiQVGL WYxws8DrkJlXd5/BpuAlwmR12yGhqH3gkq+5LAjMxIWgpNxbEU2BWAJ/k5yhA2TLMUv/ siAy99IAhtLQcs76cYT181zB0qfJmA4P6ljRAVy4Y5jTZEi1YGzwVnauTPGZ6y+QcuIY jzYg== 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 qp17si5052597ejb.516.2020.12.06.03.48.58; Sun, 06 Dec 2020 03:49:21 -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 S1728236AbgLFLqf (ORCPT + 99 others); Sun, 6 Dec 2020 06:46:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:44588 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729459AbgLFLpL (ORCPT ); Sun, 6 Dec 2020 06:45:11 -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 5.9 11/46] tun: honor IOCB_NOWAIT flag Date: Sun, 6 Dec 2020 12:17:19 +0100 Message-Id: <20201206111557.005207131@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201206111556.455533723@linuxfoundation.org> References: <20201206111556.455533723@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 @@ -1979,12 +1979,15 @@ static ssize_t tun_chr_write_iter(struct 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 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;