Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp157814ybm; Wed, 27 May 2020 22:44:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfs62t7dVJ5ViVY7OSjMEvCoJwNf+fTPrkhO8WgXm1ZONEiOdqm+ZbMTyPyRzgXrDMlNqQ X-Received: by 2002:a17:906:cd06:: with SMTP id oz6mr1580351ejb.434.1590644647606; Wed, 27 May 2020 22:44:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590644647; cv=none; d=google.com; s=arc-20160816; b=NY6yxUozNniRRkJywcviUKeIXdrdl5+8ofhj+C6yNozBPLnM/UT6OoFIdTdKcipQjl sTcmJzxUmUPn23JXFnWLfGShOszm1i2NgugA3DCN/IR1j13FY4prJCmyopMpier2g+Jb mYyHdcb3irH/pgTnfR/+7y8nk/w+QjKgzyoNSHHv87c6nfyq/CMyTh/3SF5EMY8QdYi7 Y8PJlZNdJ1hab3+/yJwkaeKANcFsbh/0VyiFAQ/rZzes1wfHZ5hqmcxBttsDUUwK0684 HC9tfsbRjSRJT+h+Sf4xTKFT+gQYBl0ACBkYYzxqJliaS+zXQFVSJEUiniw66VfC3ZpE ZSbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5X3G8p2gpeq1mWhpOrbRnLoYssjgaGtuSsqN+ape3Fw=; b=YkGHA0ZAvqUwnXhseEtnqstLBMIyEvmvD2es4MkUW2ec3ZyPHa19DtX7pq7W4XDvHy oICkf4B2NrxgFx5/kPEZInqfsuwch1fz7gugIpfhPq33huv6GSvAFiBY8I63TSqlsuTf 1St0bk2OwiH9q5inwryqZQY0UHAVaRUp7sxU7fRtqmy0lFMYoZnfF+obKNBLoR5oJU+A 6gvEiMzOg9Gbeqv1p9wRwkmhSpB+sLYAG7EPiFnDGFZChHLpsxsn/3MxYpfS4s7Ma9JT PeYZVH3w1ASQnpJNAEz6e3sc5H3+Qv8aU9bz2quqWBg99x7sCWcFJJ+t/V7QiZRnhxiU MN6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=taesqRkS; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a6si3126176edu.275.2020.05.27.22.43.44; Wed, 27 May 2020 22:44:07 -0700 (PDT) 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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=taesqRkS; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728145AbgE1Fld (ORCPT + 99 others); Thu, 28 May 2020 01:41:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727105AbgE1Fl1 (ORCPT ); Thu, 28 May 2020 01:41:27 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F17EFC05BD1E; Wed, 27 May 2020 22:41:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=5X3G8p2gpeq1mWhpOrbRnLoYssjgaGtuSsqN+ape3Fw=; b=taesqRkSyAIu/2pRL+KOySjFhB TtDF0spTbSsTcQcYEPzf2Xmk+u9SrWaeiUz7FKdnwI3eDaBkdhFATqSDy0i/tUSaWJbuVXaA81uFB L5LMUM5VHRtiu+OmIVREgnc/f9BqnApHYE8W/M6wh296l/FsUV3pq5V7nkguM+uzMBgkvJ4+SDK4e FX/KWuchAoMHUAePKpzWoNFOkusxGaycL3QI4w3QBVf4nAk5u7qZ4C58iQzb0UfuU4I5/aMKJ4TTu qVqApMY1QvyibhhK6mE2aApD4C36fsXbEQbqFryR7NghXc/f2aowUTV0GCuZjZtOAWYlW02c+hGSK q7BiKACg==; Received: from p4fdb1ad2.dip0.t-ipconnect.de ([79.219.26.210] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jeBIB-0002St-VR; Thu, 28 May 2020 05:41:24 +0000 From: Christoph Hellwig To: Al Viro Cc: Linus Torvalds , Ian Kent , David Howells , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, netfilter-devel@vger.kernel.org Subject: [PATCH 14/14] fs: don't change the address limit for ->read_iter in __kernel_read Date: Thu, 28 May 2020 07:40:43 +0200 Message-Id: <20200528054043.621510-15-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200528054043.621510-1-hch@lst.de> References: <20200528054043.621510-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If we read to a file that implements ->read_iter there is no need to change the address limit if we send a kvec down. Implement that case, and prefer it over using plain ->read with a changed address limit if available. Signed-off-by: Christoph Hellwig --- fs/read_write.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 46ddfce17e839..c93acbd8bf5a3 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -421,7 +421,6 @@ static ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, lo ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) { - mm_segment_t old_fs = get_fs(); ssize_t ret; if (!(file->f_mode & FMODE_CAN_READ)) @@ -429,14 +428,25 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) if (count > MAX_RW_COUNT) count = MAX_RW_COUNT; - set_fs(KERNEL_DS); - if (file->f_op->read) + if (file->f_op->read_iter) { + struct kvec iov = { .iov_base = buf, .iov_len = count }; + struct kiocb kiocb; + struct iov_iter iter; + + init_sync_kiocb(&kiocb, file); + kiocb.ki_pos = *pos; + iov_iter_kvec(&iter, READ, &iov, 1, count); + ret = file->f_op->read_iter(&kiocb, &iter); + *pos = kiocb.ki_pos; + } else if (file->f_op->read) { + mm_segment_t old_fs = get_fs(); + + set_fs(KERNEL_DS); ret = file->f_op->read(file, (void __user *)buf, count, pos); - else if (file->f_op->read_iter) - ret = new_sync_read(file, (void __user *)buf, count, pos); - else + set_fs(old_fs); + } else { ret = -EINVAL; - set_fs(old_fs); + } if (ret > 0) { fsnotify_access(file); add_rchar(current, ret); -- 2.26.2