From patchwork Thu May 28 05:40:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574699 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1DE9114C0 for ; Thu, 28 May 2020 05:40:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E045920899 for ; Thu, 28 May 2020 05:40:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="WE4SAKBG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727092AbgE1Fkw (ORCPT ); Thu, 28 May 2020 01:40:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbgE1Fkw (ORCPT ); Thu, 28 May 2020 01:40:52 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03CE8C05BD1E; Wed, 27 May 2020 22:40:52 -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=P7QNZHLDU9SPyDwV+b1BobdLyPS2Aa8qPobGkmYeBSo=; b=WE4SAKBGOw/Eof/y9Xx+vXK5oA UVDxfHwdd33ocqUYDbHO6tLOm1/gOuEBIuh4873sJ1BN53m5aqQlQnM4x4+Uk5+T3Q9kdpXiq1P7s STKwqNMqLcGlp3YwupkSOuZsd3chuaWpDC1NUId7wPDDMIhlAAIw0TtP2upxC5ydzuTkSWmiCnlVB rP1wpD7cmDySRWgOhsx46L6+Z5EhJs6KVrIlyw6lKmHGAsgqSWeWGwND//V/D2WkCyZmWBoqxqhe3 pIiYx2sBBLgKk0FjFdRm1mMjnt6oJNurAP5KUSM+0RTu2Z4UmDq3rXcrbPCIRZViJq+8NhkW+uUpF iAOMSI0A==; 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 1jeBHc-0002JI-Ay; Thu, 28 May 2020 05:40:48 +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 01/14] cachefiles: switch to kernel_write Date: Thu, 28 May 2020 07:40:30 +0200 Message-Id: <20200528054043.621510-2-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: __kernel_write doesn't take a sb_writers references, which we need here. Signed-off-by: Christoph Hellwig Reviewed-by: David Howells --- fs/cachefiles/rdwr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c index e7726f5f1241c..3080cda9e8245 100644 --- a/fs/cachefiles/rdwr.c +++ b/fs/cachefiles/rdwr.c @@ -937,7 +937,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page) } data = kmap(page); - ret = __kernel_write(file, data, len, &pos); + ret = kernel_write(file, data, len, &pos); kunmap(page); fput(file); if (ret != len) From patchwork Thu May 28 05:40:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574701 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F56A14C0 for ; Thu, 28 May 2020 05:40:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16E2D2089D for ; Thu, 28 May 2020 05:40:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Xa/oTOAh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727878AbgE1Fkz (ORCPT ); Thu, 28 May 2020 01:40:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725984AbgE1Fky (ORCPT ); Thu, 28 May 2020 01:40:54 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E1E7C05BD1E; Wed, 27 May 2020 22:40:54 -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=IeHy1UWBjGCugKPZsL/McSR8vAod70zeUAWlcMoC1+A=; b=Xa/oTOAhhpZ8du9OaOuGoXzKBa JBqSCM9urQjq5Mvj/UHs52DmSBe5PCEOAHm2kTv4BwJ9QDtVwXJXxjS1Aw1EoCu8OfEkkLj7vyXHw kyEGjhj5ox9glYGjcUXxIIYPcDCELAHGI+MMv97q1X9OadIon81Cyk/Ogm7uEQ6uQCnTJIQMWkLSz Z6b7YFbiwwGRF0h7SUMA6Ymh9rGD6sNNbe34Mx3nundu0YA1voT3xjxnPegj+ZnzC6cufrawnlHkf B9OfEFdFcYwPM5amrzYVL5gg3+gvZx+EulLBiXnHTlKmvuCH1cVy4n/ij4tzlCAv7t630KlzMitQw n0FrmPZg==; 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 1jeBHf-0002Ji-3L; Thu, 28 May 2020 05:40:51 +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 02/14] autofs: switch to kernel_write Date: Thu, 28 May 2020 07:40:31 +0200 Message-Id: <20200528054043.621510-3-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: While pipes don't really need sb_writers projection, __kernel_write is an interface better kept private, and the additional rw_verify_area does not hurt here. Signed-off-by: Christoph Hellwig Acked-by: Ian Kent --- fs/autofs/waitq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/autofs/waitq.c b/fs/autofs/waitq.c index b04c528b19d34..74c886f7c51cb 100644 --- a/fs/autofs/waitq.c +++ b/fs/autofs/waitq.c @@ -53,7 +53,7 @@ static int autofs_write(struct autofs_sb_info *sbi, mutex_lock(&sbi->pipe_mutex); while (bytes) { - wr = __kernel_write(file, data, bytes, &file->f_pos); + wr = kernel_write(file, data, bytes, &file->f_pos); if (wr <= 0) break; data += wr; From patchwork Thu May 28 05:40:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574749 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 338FB913 for ; Thu, 28 May 2020 05:42:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 128792089D for ; Thu, 28 May 2020 05:42:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="cMukcwnT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727902AbgE1Fk6 (ORCPT ); Thu, 28 May 2020 01:40:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727897AbgE1Fk5 (ORCPT ); Thu, 28 May 2020 01:40:57 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA771C05BD1E; Wed, 27 May 2020 22:40:56 -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=4NVlnvH2L/cYRkCm5hQ2+fmz61uNYxGY9AD8xRJmRwA=; b=cMukcwnTJJsoPTbpZu69MUgPA9 mEzSBxgPmva8SNLYcW9HoysLjqA7xebO+hTM+RinEFuPKfU0XMu/1+/v27sxyAZU69y3U4LpQmJl3 vDgEobIMWfrosZbXls3iOODZ9g5+7UUX8EYUk9LMH9kMGRX0U0gt4d6iIiQJZTsYMGWwyC8WlW/Hi pfK1QZoQ409C9knIfsil37oPoVFDM+aIwtfg0Q8k7rsY5kqIOpWYDxCPQBekUt7SQ2s8QuBOfgWSV bYlZXFeJ47HR7e7ha2FKUAPWLSF6yR+CvQCeTYPL2lm6i8iCW5JqtWPZrqfMqeLqkuoorp02juEC/ TQQXYKrQ==; 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 1jeBHh-0002KI-Og; Thu, 28 May 2020 05:40:54 +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 03/14] bpfilter: switch to kernel_write Date: Thu, 28 May 2020 07:40:32 +0200 Message-Id: <20200528054043.621510-4-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: While pipes don't really need sb_writers projection, __kernel_write is an interface better kept private, and the additional rw_verify_area does not hurt here. Signed-off-by: Christoph Hellwig --- net/bpfilter/bpfilter_kern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bpfilter/bpfilter_kern.c b/net/bpfilter/bpfilter_kern.c index c0f0990f30b60..1905e01c3aa9a 100644 --- a/net/bpfilter/bpfilter_kern.c +++ b/net/bpfilter/bpfilter_kern.c @@ -50,7 +50,7 @@ static int __bpfilter_process_sockopt(struct sock *sk, int optname, req.len = optlen; if (!bpfilter_ops.info.pid) goto out; - n = __kernel_write(bpfilter_ops.info.pipe_to_umh, &req, sizeof(req), + n = kernel_write(bpfilter_ops.info.pipe_to_umh, &req, sizeof(req), &pos); if (n != sizeof(req)) { pr_err("write fail %zd\n", n); From patchwork Thu May 28 05:40:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574747 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 91822159A for ; Thu, 28 May 2020 05:41:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7164A2089D for ; Thu, 28 May 2020 05:41:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="S5cqbOTD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727924AbgE1FlA (ORCPT ); Thu, 28 May 2020 01:41:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727915AbgE1Fk7 (ORCPT ); Thu, 28 May 2020 01:40:59 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B5FEC05BD1E; Wed, 27 May 2020 22:40:59 -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=OfbCGpVq2bSVaxzX21SAbOgZUqmrr254Kbi/uKi31mE=; b=S5cqbOTDRp5dleW5ZVjmCZMgnu 1SwnwIkimBF14ZxVRjVGNMMIKvyBjK79Sc9tkggRt3QluIug/5YhnLZotNXsMFGM/yd47DUmZdCQ3 eKobcr/s0EIDpuAWd4YckaRcgRyoHNpNvoDCSSrl9B/ruy1JFxIxh3lGosjOTTcwVUTzY9FkUJGS5 FkEavwas4oZ+yPQqpdWT03zfKRBzkbmZqdGKpHjm703RKnnX+NsJARtOwYhY54NHs1BJeXd6rX0Da nznZy7SudQgQrhLjIKOzbA5zF+V/xPX6pighYz9SCdA+ba4TiF5vyMpupj7e1uQB1lulWHPsKNCDH Gb+xIt5A==; 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 1jeBHk-0002Ka-87; Thu, 28 May 2020 05:40:56 +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 04/14] fs: unexport __kernel_write Date: Thu, 28 May 2020 07:40:33 +0200 Message-Id: <20200528054043.621510-5-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: This is a very special interface that skips sb_writes protection, and not used by modules anymore. Signed-off-by: Christoph Hellwig --- fs/read_write.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/read_write.c b/fs/read_write.c index bbfa9b12b15eb..2c601d853ff3d 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -522,7 +522,6 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t inc_syscw(current); return ret; } -EXPORT_SYMBOL(__kernel_write); ssize_t kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos) From patchwork Thu May 28 05:40:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574743 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CB8C913 for ; Thu, 28 May 2020 05:41:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B7C220899 for ; Thu, 28 May 2020 05:41:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="S/CrKoO/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727953AbgE1FlD (ORCPT ); Thu, 28 May 2020 01:41:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727915AbgE1FlC (ORCPT ); Thu, 28 May 2020 01:41:02 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69203C05BD1E; Wed, 27 May 2020 22:41:02 -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: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=LiemweaQJNNyLn4dfMO7A8hjFLXFG2PuwhKLysUSths=; b=S/CrKoO/MT3Iqbd1YKRizIUS0R DKbDK7u6VpKvmNdzazhqnFNkTQWvB3FyElBeT6N25dj3I8v3mfyZXncOgP8HzuPsokYwrMZYo7v5X U71Cprine01rYaUb+GDDZLuUm6LWu4GppHHaWg+vs+6OxsnSyPAk3KZKMd/W+rB01dbmexgpJlvIl Ut8HPk1TeWocsVaPPyKiDmXvPE7TF5Gakt3UAXai4tNXAQVRn7aiW+/NtxVbW37q0nuS+bQx3Ies9 9PkIryvAyF+7xMmmyofehXl0Lwc+On3bx4cEzD5pEe6vMCWqAan0YuE9EOKvFdYlmWIyshzFcoXcX sPPr8rRA==; 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 1jeBHn-0002L8-2y; Thu, 28 May 2020 05:40:59 +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 05/14] fs: check FMODE_WRITE in __kernel_write Date: Thu, 28 May 2020 07:40:34 +0200 Message-Id: <20200528054043.621510-6-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: We still need to check if the fѕ is open write, even for the low-level helper. Signed-off-by: Christoph Hellwig --- fs/read_write.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/read_write.c b/fs/read_write.c index 2c601d853ff3d..76be155ad9824 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -505,6 +505,8 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t const char __user *p; ssize_t ret; + if (!(file->f_mode & FMODE_WRITE)) + return -EBADF; if (!(file->f_mode & FMODE_CAN_WRITE)) return -EINVAL; From patchwork Thu May 28 05:40:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574741 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C36A14C0 for ; Thu, 28 May 2020 05:41:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E44312089D for ; Thu, 28 May 2020 05:41:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="MBskP1WL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728040AbgE1Flt (ORCPT ); Thu, 28 May 2020 01:41:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727969AbgE1FlE (ORCPT ); Thu, 28 May 2020 01:41:04 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B64E1C05BD1E; Wed, 27 May 2020 22:41:04 -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=+27B/kWY77txgcnCnO/se59OKQEtJSQNrCBAd6cQiEo=; b=MBskP1WLILJANaiMEi9+Sw+O5o Lko+o6u6aLxDSAifn3VBNdes3EeBP5/dic2rPhvpsrFnKlMSAjOzxP69KD78stpbKm6iycCS5ya87 RIcDKXVJ+Tf2Pu4JzPGl1jhMc/GU+2xeboXot9hBEr7BsTC3QKZami0qgNfjft5/W4i/Lns5IWBh2 a2d6x7uZ/30UE92J+D0hXR0CDDsJlHpsMnS7N+OfK/xTrbTVY6oGg9m19ppP6M04U8sSB+9f+zz+c VJtV1Gc1OGF2W4gZO9NXQJgOZ+6o4Vba85oPia4Qive++ceIWyxkt9gvQDtLQZmWSUVH06QKvvKIc RDaQNlWw==; 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 1jeBHp-0002MO-Qj; Thu, 28 May 2020 05:41:02 +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 06/14] fs: remove the call_{read,write}_iter functions Date: Thu, 28 May 2020 07:40:35 +0200 Message-Id: <20200528054043.621510-7-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: Just open coding the methods calls is a lot easier to follow. Signed-off-by: Christoph Hellwig --- drivers/block/loop.c | 4 ++-- drivers/target/target_core_file.c | 4 ++-- fs/aio.c | 4 ++-- fs/io_uring.c | 4 ++-- fs/read_write.c | 12 ++++++------ fs/splice.c | 2 +- include/linux/fs.h | 12 ------------ 7 files changed, 15 insertions(+), 27 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index da693e6a834e5..ad167050a4ec4 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -572,9 +572,9 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, kthread_associate_blkcg(cmd->css); if (rw == WRITE) - ret = call_write_iter(file, &cmd->iocb, &iter); + ret = file->f_op->write_iter(&cmd->iocb, &iter); else - ret = call_read_iter(file, &cmd->iocb, &iter); + ret = file->f_op->read_iter(&cmd->iocb, &iter); lo_rw_aio_do_completion(cmd); kthread_associate_blkcg(NULL); diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c index 7143d03f0e027..79f0707877917 100644 --- a/drivers/target/target_core_file.c +++ b/drivers/target/target_core_file.c @@ -303,9 +303,9 @@ fd_execute_rw_aio(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents, aio_cmd->iocb.ki_flags |= IOCB_DSYNC; if (is_write) - ret = call_write_iter(file, &aio_cmd->iocb, &iter); + ret = file->f_op->write_iter(&aio_cmd->iocb, &iter); else - ret = call_read_iter(file, &aio_cmd->iocb, &iter); + ret = file->f_op->read_iter(&aio_cmd->iocb, &iter); kfree(bvec); diff --git a/fs/aio.c b/fs/aio.c index 5f3d3d8149287..1ccc0efdc357d 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1540,7 +1540,7 @@ static int aio_read(struct kiocb *req, const struct iocb *iocb, return ret; ret = rw_verify_area(READ, file, &req->ki_pos, iov_iter_count(&iter)); if (!ret) - aio_rw_done(req, call_read_iter(file, req, &iter)); + aio_rw_done(req, file->f_op->read_iter(req, &iter)); kfree(iovec); return ret; } @@ -1580,7 +1580,7 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb, __sb_writers_release(file_inode(file)->i_sb, SB_FREEZE_WRITE); } req->ki_flags |= IOCB_WRITE; - aio_rw_done(req, call_write_iter(file, req, &iter)); + aio_rw_done(req, file->f_op->write_iter(req, &iter)); } kfree(iovec); return ret; diff --git a/fs/io_uring.c b/fs/io_uring.c index bb25e3997d418..f4b808231af0b 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -2579,7 +2579,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock) ssize_t ret2; if (req->file->f_op->read_iter) - ret2 = call_read_iter(req->file, kiocb, &iter); + ret2 = req->file->f_op->read_iter(kiocb, &iter); else ret2 = loop_rw_iter(READ, req->file, kiocb, &iter); @@ -2694,7 +2694,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock) current->signal->rlim[RLIMIT_FSIZE].rlim_cur = req->fsize; if (req->file->f_op->write_iter) - ret2 = call_write_iter(req->file, kiocb, &iter); + ret2 = req->file->f_op->write_iter(kiocb, &iter); else ret2 = loop_rw_iter(WRITE, req->file, kiocb, &iter); diff --git a/fs/read_write.c b/fs/read_write.c index 76be155ad9824..f0768313ea010 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -412,7 +412,7 @@ static ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, lo kiocb.ki_pos = (ppos ? *ppos : 0); iov_iter_init(&iter, READ, &iov, 1, len); - ret = call_read_iter(filp, &kiocb, &iter); + ret = filp->f_op->read_iter(&kiocb, &iter); BUG_ON(ret == -EIOCBQUEUED); if (ppos) *ppos = kiocb.ki_pos; @@ -481,7 +481,7 @@ static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t kiocb.ki_pos = (ppos ? *ppos : 0); iov_iter_init(&iter, WRITE, &iov, 1, len); - ret = call_write_iter(filp, &kiocb, &iter); + ret = filp->f_op->write_iter(&kiocb, &iter); BUG_ON(ret == -EIOCBQUEUED); if (ret > 0 && ppos) *ppos = kiocb.ki_pos; @@ -690,9 +690,9 @@ static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter, kiocb.ki_pos = (ppos ? *ppos : 0); if (type == READ) - ret = call_read_iter(filp, &kiocb, iter); + ret = filp->f_op->read_iter(&kiocb, iter); else - ret = call_write_iter(filp, &kiocb, iter); + ret = filp->f_op->write_iter(&kiocb, iter); BUG_ON(ret == -EIOCBQUEUED); if (ppos) *ppos = kiocb.ki_pos; @@ -961,7 +961,7 @@ ssize_t vfs_iocb_iter_read(struct file *file, struct kiocb *iocb, if (ret < 0) return ret; - ret = call_read_iter(file, iocb, iter); + ret = file->f_op->read_iter(iocb, iter); out: if (ret >= 0) fsnotify_access(file); @@ -1025,7 +1025,7 @@ ssize_t vfs_iocb_iter_write(struct file *file, struct kiocb *iocb, if (ret < 0) return ret; - ret = call_write_iter(file, iocb, iter); + ret = file->f_op->write_iter(iocb, iter); if (ret > 0) fsnotify_modify(file); diff --git a/fs/splice.c b/fs/splice.c index 4e53efbd621db..3382d5f0610dd 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -310,7 +310,7 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos, i_head = to.head; init_sync_kiocb(&kiocb, in); kiocb.ki_pos = *ppos; - ret = call_read_iter(in, &kiocb, &to); + ret = in->f_op->read_iter(&kiocb, &to); if (ret > 0) { *ppos = kiocb.ki_pos; file_accessed(in); diff --git a/include/linux/fs.h b/include/linux/fs.h index 45cc10cdf6ddd..21f126957c2cf 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1895,18 +1895,6 @@ struct inode_operations { int (*set_acl)(struct inode *, struct posix_acl *, int); } ____cacheline_aligned; -static inline ssize_t call_read_iter(struct file *file, struct kiocb *kio, - struct iov_iter *iter) -{ - return file->f_op->read_iter(kio, iter); -} - -static inline ssize_t call_write_iter(struct file *file, struct kiocb *kio, - struct iov_iter *iter) -{ - return file->f_op->write_iter(kio, iter); -} - static inline int call_mmap(struct file *file, struct vm_area_struct *vma) { return file->f_op->mmap(file, vma); From patchwork Thu May 28 05:40:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574735 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D412913 for ; Thu, 28 May 2020 05:41:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2540F2089D for ; Thu, 28 May 2020 05:41:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Mol6D5Y6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728000AbgE1FlJ (ORCPT ); Thu, 28 May 2020 01:41:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727987AbgE1FlH (ORCPT ); Thu, 28 May 2020 01:41:07 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DAB0C05BD1E; Wed, 27 May 2020 22:41:07 -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=KaeJEwRFrws3Sr3qqEXI33NXZ5dPCgwGDFfFGJ19P54=; b=Mol6D5Y6R1D9e/F+LW7O82xptB MXB9jwA/QH+Hy8SHPKIE9AY9NCg51MAr4nUECczMrcFA59wgSqI56QKnTwMKW8xnVPTIvWueF3Vjj wUjh9xIDDhLot3gscNRfjixZC3vxMYAXKIYdFh2na+jSY2GxnKgpVrj5s0hDa0x8x2/zYfI3y3C5D 9tG6RDPUNrJN50tE6EuOyTdH7CpXpQuolVZVJkyGt3GRsQBsVAQqfsgNcbnPrwZKWOB4LR/EdllWc HLmPUy75V5oNVKaiRQ8gc15+2dI5tvYkt/SivPutaMVICY8GnP5Z+EHB8elXuF2qm9HZIWk5WlReh 5mZSaSMA==; 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 1jeBHs-0002Nk-G0; Thu, 28 May 2020 05:41:04 +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 07/14] fs: implement kernel_write using __kernel_write Date: Thu, 28 May 2020 07:40:36 +0200 Message-Id: <20200528054043.621510-8-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: Consolidate the two in-kernel write helpers to make upcoming changes easier. The only difference are the missing call to rw_verify_area in kernel_write, and an access_ok check that doesn't make sense for kernel buffers to start with. Signed-off-by: Christoph Hellwig --- fs/read_write.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index f0768313ea010..abb84391cfbc5 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -499,6 +499,7 @@ static ssize_t __vfs_write(struct file *file, const char __user *p, return -EINVAL; } +/* caller is responsible for file_start_write/file_end_write */ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos) { mm_segment_t old_fs; @@ -528,16 +529,16 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t ssize_t kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos) { - mm_segment_t old_fs; - ssize_t res; + ssize_t ret; - old_fs = get_fs(); - set_fs(KERNEL_DS); - /* The cast to a user pointer is valid due to the set_fs() */ - res = vfs_write(file, (__force const char __user *)buf, count, pos); - set_fs(old_fs); + ret = rw_verify_area(WRITE, file, pos, count); + if (ret) + return ret; - return res; + file_start_write(file); + ret = __kernel_write(file, buf, count, pos); + file_end_write(file); + return ret; } EXPORT_SYMBOL(kernel_write); From patchwork Thu May 28 05:40:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574733 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47DFC14C0 for ; Thu, 28 May 2020 05:41:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FDC42089D for ; Thu, 28 May 2020 05:41:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="acJn3my9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728015AbgE1FlK (ORCPT ); Thu, 28 May 2020 01:41:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728007AbgE1FlK (ORCPT ); Thu, 28 May 2020 01:41:10 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E3B1C05BD1E; Wed, 27 May 2020 22:41:10 -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=AZrEO4uOUGmTKGyBg+hBxvz5LOpc/mMjva1AqdoZkhw=; b=acJn3my92W68iGQuJv65iNtVDP wEJXlE9AXQT0Lzi7DuU07lKSfx8dyBXZwvcWiJ/q0kqyZDSOEoC37PGTiJ+BZUL9t3UopY5XE4Mng A+GKs5GOB/rJf+b9cZaGhfIu5QsSfXA017LuvvojCGWU8FHDFSphfE++7hK51+DTq1p9822sukmmp 2tsUZnvr0DJhneypHKf0c7SVhB1BXOauU28NJJ1ULOTSuv+ryU+Qe+L5AA+zT0q/djgrrTOetz7jJ hgw0Ie/4+0DW95olcevSRWNPinBWorHERWAg6WrG0uYFRNpWIxMXGhcBEEuPYekHzUMzfsewxjHG6 gmsReeUQ==; 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 1jeBHv-0002Ok-2c; Thu, 28 May 2020 05:41:07 +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 08/14] fs: remove __vfs_write Date: Thu, 28 May 2020 07:40:37 +0200 Message-Id: <20200528054043.621510-9-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: Fold it into the two callers. Signed-off-by: Christoph Hellwig --- fs/read_write.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index abb84391cfbc5..3bcb084f160de 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -488,17 +488,6 @@ static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t return ret; } -static ssize_t __vfs_write(struct file *file, const char __user *p, - size_t count, loff_t *pos) -{ - if (file->f_op->write) - return file->f_op->write(file, p, count, pos); - else if (file->f_op->write_iter) - return new_sync_write(file, p, count, pos); - else - return -EINVAL; -} - /* caller is responsible for file_start_write/file_end_write */ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos) { @@ -516,7 +505,12 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t p = (__force const char __user *)buf; if (count > MAX_RW_COUNT) count = MAX_RW_COUNT; - ret = __vfs_write(file, p, count, pos); + if (file->f_op->write) + ret = file->f_op->write(file, p, count, pos); + else if (file->f_op->write_iter) + ret = new_sync_write(file, p, count, pos); + else + ret = -EINVAL; set_fs(old_fs); if (ret > 0) { fsnotify_modify(file); @@ -554,19 +548,23 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_ return -EFAULT; ret = rw_verify_area(WRITE, file, pos, count); - if (!ret) { - if (count > MAX_RW_COUNT) - count = MAX_RW_COUNT; - file_start_write(file); - ret = __vfs_write(file, buf, count, pos); - if (ret > 0) { - fsnotify_modify(file); - add_wchar(current, ret); - } - inc_syscw(current); - file_end_write(file); + if (ret) + return ret; + if (count > MAX_RW_COUNT) + count = MAX_RW_COUNT; + file_start_write(file); + if (file->f_op->write) + ret = file->f_op->write(file, buf, count, pos); + else if (file->f_op->write_iter) + ret = new_sync_write(file, buf, count, pos); + else + ret = -EINVAL; + if (ret > 0) { + fsnotify_modify(file); + add_wchar(current, ret); } - + inc_syscw(current); + file_end_write(file); return ret; } From patchwork Thu May 28 05:40:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574711 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE2D7913 for ; Thu, 28 May 2020 05:41:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97C572089D for ; Thu, 28 May 2020 05:41:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="dkuzcaFO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728044AbgE1FlP (ORCPT ); Thu, 28 May 2020 01:41:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728040AbgE1FlN (ORCPT ); Thu, 28 May 2020 01:41:13 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E08B9C05BD1E; Wed, 27 May 2020 22:41:12 -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=axSbbRT9BzCYIqAhw6GFe8AhXOOBJWbdO6tNDMRT5zc=; b=dkuzcaFOGVWl7HLb4dvVTdVQFD YxsLjpcAD4ZLLeZkr9HS7wVdkRoGwwN04Pc90TeEZU/fT+xPc3rp3NN6Ww3DHSzAIEw+gGcGjWygn KJsabZNsS3f7dC7N14Pe1PgFQmTxCscp/n2Jl3BY+Zfr0a4xgvXwKeAJFIJ+rO+DPVzlGAjJYJfL+ wibZiuqpZPw92s02a79SOqAiFh/X6vlyy0ea638oUv4pKrhOdJplMKWlYGjeHYNT4szyI0t9ZOt49 hPcPGcIdkRXV/nTTyN4gYNDYrxl2TgvAlmWNaVmqp3w71R2iDy8WDCb6n8rEmtbPtFmQ50IOjgyfv 0BLNNvxw==; 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 1jeBHx-0002Ow-Uc; Thu, 28 May 2020 05:41:10 +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 09/14] fs: don't change the address limit for ->write_iter in __kernel_write Date: Thu, 28 May 2020 07:40:38 +0200 Message-Id: <20200528054043.621510-10-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: If we write to a file that implements ->write_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 ->write with a changed address limit if available. Signed-off-by: Christoph Hellwig --- fs/read_write.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 3bcb084f160de..8cfca5f8fc3ce 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -489,10 +489,9 @@ static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t } /* caller is responsible for file_start_write/file_end_write */ -ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos) +ssize_t __kernel_write(struct file *file, const void *buf, size_t count, + loff_t *pos) { - mm_segment_t old_fs; - const char __user *p; ssize_t ret; if (!(file->f_mode & FMODE_WRITE)) @@ -500,18 +499,29 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t if (!(file->f_mode & FMODE_CAN_WRITE)) return -EINVAL; - old_fs = get_fs(); - set_fs(KERNEL_DS); - p = (__force const char __user *)buf; if (count > MAX_RW_COUNT) count = MAX_RW_COUNT; - if (file->f_op->write) - ret = file->f_op->write(file, p, count, pos); - else if (file->f_op->write_iter) - ret = new_sync_write(file, p, count, pos); - else + if (file->f_op->write_iter) { + struct kvec iov = { .iov_base = (void *)buf, .iov_len = count }; + struct kiocb kiocb; + struct iov_iter iter; + + init_sync_kiocb(&kiocb, file); + kiocb.ki_pos = *pos; + iov_iter_kvec(&iter, WRITE, &iov, 1, count); + ret = file->f_op->write_iter(&kiocb, &iter); + if (ret > 0) + *pos = kiocb.ki_pos; + } else if (file->f_op->write) { + mm_segment_t old_fs = get_fs(); + + set_fs(KERNEL_DS); + ret = file->f_op->write(file, (__force const char __user *)buf, + count, pos); + set_fs(old_fs); + } else { ret = -EINVAL; - set_fs(old_fs); + } if (ret > 0) { fsnotify_modify(file); add_wchar(current, ret); From patchwork Thu May 28 05:40:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574727 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C979913 for ; Thu, 28 May 2020 05:41:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E84912089D for ; Thu, 28 May 2020 05:41:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="M7xMSmzt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728073AbgE1FlT (ORCPT ); Thu, 28 May 2020 01:41:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728069AbgE1FlQ (ORCPT ); Thu, 28 May 2020 01:41:16 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78C73C05BD1E; Wed, 27 May 2020 22:41:16 -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=9a0yuZ9jbeWWLZ6wdj7/oXrc5yC9mMpHwfG04VNOeCA=; b=M7xMSmztFHAzOggW+dpxqIqIlt NzGNtVdU1jRI3uxrrEAZRnXY0N0IqqarK715bHKSTxJFuwD1+HcwaX5Ia/QqyzlRWtXIyIvCZ6dIw LGmT4rLbNVboHYpbsvj6LzHQ8JZcQt5SX/asuSYp9mi5o+Rf3vwclhtm0aqfQnDdi/nR2K+x4EnwG EmxDyzUWEl7lKKIpjlulk9ZLOlbalGHBh0pBOGqITNC6J33UJeVdFNG5xbgeRPcVbkzViBTve/24/ Y01dRqMlSw83VubX4LK0x1UqEsRNHOyDTAT2mSevyKfyJhGdLa0SCZaDVAv/S5SCiQFu+5RN3t+fR JnYST7MA==; 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 1jeBI0-0002PW-Mw; Thu, 28 May 2020 05:41:13 +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 10/14] fs: add a __kernel_read helper Date: Thu, 28 May 2020 07:40:39 +0200 Message-Id: <20200528054043.621510-11-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: This is the counterpart to __kernel_write, and skip the rw_verify_area call compared to kernel_read. Signed-off-by: Christoph Hellwig --- fs/read_write.c | 21 +++++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 22 insertions(+) diff --git a/fs/read_write.c b/fs/read_write.c index 8cfca5f8fc3ce..bd12af8a895c8 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -430,6 +430,27 @@ ssize_t __vfs_read(struct file *file, char __user *buf, size_t count, return -EINVAL; } +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)) + return -EINVAL; + + if (count > MAX_RW_COUNT) + count = MAX_RW_COUNT; + set_fs(KERNEL_DS); + ret = __vfs_read(file, (void __user *)buf, count, pos); + set_fs(old_fs); + if (ret > 0) { + fsnotify_access(file); + add_rchar(current, ret); + } + inc_syscr(current); + return ret; +} + ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) { mm_segment_t old_fs; diff --git a/include/linux/fs.h b/include/linux/fs.h index 21f126957c2cf..6441aaa25f8f2 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3011,6 +3011,7 @@ extern int kernel_read_file_from_path_initns(const char *, void **, loff_t *, lo extern int kernel_read_file_from_fd(int, void **, loff_t *, loff_t, enum kernel_read_file_id); extern ssize_t kernel_read(struct file *, void *, size_t, loff_t *); +ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos); extern ssize_t kernel_write(struct file *, const void *, size_t, loff_t *); extern ssize_t __kernel_write(struct file *, const void *, size_t, loff_t *); extern struct file * open_exec(const char *); From patchwork Thu May 28 05:40:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574729 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 871D7159A for ; Thu, 28 May 2020 05:41:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 665FA2089D for ; Thu, 28 May 2020 05:41:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Sly8RB2C" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728153AbgE1Fli (ORCPT ); Thu, 28 May 2020 01:41:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728040AbgE1FlS (ORCPT ); Thu, 28 May 2020 01:41:18 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90EC7C08C5C2; Wed, 27 May 2020 22:41:18 -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=v2d8pva8LsFTXWqDIrLlQ4NNcDJbw9ZGB5N3mHruM2Q=; b=Sly8RB2C62rL3Ag/ASebOALXhx jsuXC/klqC7pOqgzkf/1FnDCemkL8CJ+lOg3UTElUUlsu9+DZ105kBNCHmi+9z0Ta/66886wFbboz l7cRNTN6XYxRap49QE9qL0m7mfcweYdrhtbur4ZVe8uphe8UNliBog+pZxXlUHfN6u3eaS52CjD79 Jw3HmMizeh4AfoIP9whoapShinlg6Nkm3V0ALzdCPd1D0DJShVbS/oiyoWWswaMQ+V7VEO7EesKii 0gmtiASmBpMtbs6ccT1OWSAcIdicHs9kNujJoQ7qL8XZ8FSzweMvmqkaQed43j7l05cBGEGl5Ld5h 79rnpqIg==; 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 1jeBI3-0002Qp-M1; Thu, 28 May 2020 05:41:16 +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 11/14] integrity/ima: switch to using __kernel_read Date: Thu, 28 May 2020 07:40:40 +0200 Message-Id: <20200528054043.621510-12-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: __kernel_read has a bunch of additional sanity checks, and this moves the set_fs out of non-core code. Signed-off-by: Christoph Hellwig --- security/integrity/iint.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/security/integrity/iint.c b/security/integrity/iint.c index e12c4900510f6..1d20003243c3f 100644 --- a/security/integrity/iint.c +++ b/security/integrity/iint.c @@ -188,19 +188,7 @@ DEFINE_LSM(integrity) = { int integrity_kernel_read(struct file *file, loff_t offset, void *addr, unsigned long count) { - mm_segment_t old_fs; - char __user *buf = (char __user *)addr; - ssize_t ret; - - if (!(file->f_mode & FMODE_READ)) - return -EBADF; - - old_fs = get_fs(); - set_fs(KERNEL_DS); - ret = __vfs_read(file, buf, count, &offset); - set_fs(old_fs); - - return ret; + return __kernel_read(file, addr, count, &offset); } /* From patchwork Thu May 28 05:40:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574721 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D7DDC913 for ; Thu, 28 May 2020 05:41:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B26DF21475 for ; Thu, 28 May 2020 05:41:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Zn6qhVBM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727032AbgE1FlW (ORCPT ); Thu, 28 May 2020 01:41:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728069AbgE1FlV (ORCPT ); Thu, 28 May 2020 01:41:21 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77084C05BD1E; Wed, 27 May 2020 22:41:21 -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=RKgk8zViaf8A5u7/beCuCOI0498LURgV/aa2JhdiYjs=; b=Zn6qhVBMpAn77GXpcuKN/iHPMA RbRTTRBammj4MrsO8AhNVVSuA0xsSJSsIlU8dOckiWeZ2FXN1+ty9K4+RR90K6u33N8xrKChrqQkb PwSsuITP+jEHA2q84Lxc3Uc3SGlPHG2HSK+fvMsnSPRXMyO+lGTf0rZxtCr54e8LTXDCJEIPdDL39 6Nmg4vnARVXBh55dKoyPG5OEzrZRfZIUf5xncLNpj9SlvCp1eGWhS9jySc1peFI7eOVwkUZwdhSbD ui3LQbBjdHrJ3zEYg7ikFoVUuPOiZsz8+5NO3ug/7J/qII85sH2qNsEfBw0lXznhEentn4RdTEnwy un2XVTVQ==; 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 1jeBI6-0002RT-Hj; Thu, 28 May 2020 05:41:18 +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 12/14] fs: implement kernel_read using __kernel_read Date: Thu, 28 May 2020 07:40:41 +0200 Message-Id: <20200528054043.621510-13-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: Consolidate the two in-kernel read helpers to make upcoming changes easier. The only difference are the missing call to rw_verify_area in kernel_read, and an access_ok check that doesn't make sense for kernel buffers to start with. Signed-off-by: Christoph Hellwig --- fs/read_write.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index bd12af8a895c8..4e19152a7efe0 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -453,15 +453,12 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) { - mm_segment_t old_fs; - ssize_t result; + ssize_t ret; - old_fs = get_fs(); - set_fs(KERNEL_DS); - /* The cast to a user pointer is valid due to the set_fs() */ - result = vfs_read(file, (void __user *)buf, count, pos); - set_fs(old_fs); - return result; + ret = rw_verify_area(READ, file, pos, count); + if (ret) + return ret; + return __kernel_read(file, buf, count, pos); } EXPORT_SYMBOL(kernel_read); From patchwork Thu May 28 05:40:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574719 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7DA9F913 for ; Thu, 28 May 2020 05:41:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67F072089D for ; Thu, 28 May 2020 05:41:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="PcSzIc+T" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728111AbgE1FlY (ORCPT ); Thu, 28 May 2020 01:41:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728108AbgE1FlY (ORCPT ); Thu, 28 May 2020 01:41:24 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 248B2C05BD1E; Wed, 27 May 2020 22:41:24 -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=xX/ohJ/Nsd6gFnpTn5enX4QPRDFfh56M5/PiEzwOvXs=; b=PcSzIc+Td50qildKcaFkhaU0B0 PL/j3K+OQRp/G1qQYo+9Z1IUipoQ9iaoHj2ZJzWlzaG++PgucJ23N9hQAyecKYpppEr0OUBBE+5jg UxgWeUeIpb8Q6boe1meyAAvAmd9JGZyRVsGOS1T4yX6FHesIFh7Kgxn4HeUZqmrVwyCRfR7i1RQx4 id/lGWsKgCKJcCLE1mRdMu+nRCK96XVliVwGADucw5CA/rDweMzXEAGQgoebD2hY7OWONDeYtA517 y24Nr0I4GHA1PmPCRzO5vXtj6U5zfx3E3eGb79RQacTHQp67ezga3Vk8Wglf8Whf9tVc6l9PQCjX0 GoWpepzg==; 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 1jeBI9-0002SH-6j; Thu, 28 May 2020 05:41:21 +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 13/14] fs: remove __vfs_read Date: Thu, 28 May 2020 07:40:42 +0200 Message-Id: <20200528054043.621510-14-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: Fold it into the two callers. Signed-off-by: Christoph Hellwig --- fs/read_write.c | 43 +++++++++++++++++++++---------------------- include/linux/fs.h | 1 - 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 4e19152a7efe0..46ddfce17e839 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -419,17 +419,6 @@ static ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, lo return ret; } -ssize_t __vfs_read(struct file *file, char __user *buf, size_t count, - loff_t *pos) -{ - if (file->f_op->read) - return file->f_op->read(file, buf, count, pos); - else if (file->f_op->read_iter) - return new_sync_read(file, buf, count, pos); - else - return -EINVAL; -} - ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) { mm_segment_t old_fs = get_fs(); @@ -441,7 +430,12 @@ 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); - ret = __vfs_read(file, (void __user *)buf, count, pos); + if (file->f_op->read) + 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 + ret = -EINVAL; set_fs(old_fs); if (ret > 0) { fsnotify_access(file); @@ -474,17 +468,22 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) return -EFAULT; ret = rw_verify_area(READ, file, pos, count); - if (!ret) { - if (count > MAX_RW_COUNT) - count = MAX_RW_COUNT; - ret = __vfs_read(file, buf, count, pos); - if (ret > 0) { - fsnotify_access(file); - add_rchar(current, ret); - } - inc_syscr(current); - } + if (ret) + return ret; + if (count > MAX_RW_COUNT) + count = MAX_RW_COUNT; + if (file->f_op->read) + ret = file->f_op->read(file, buf, count, pos); + else if (file->f_op->read_iter) + ret = new_sync_read(file, buf, count, pos); + else + ret = -EINVAL; + if (ret > 0) { + fsnotify_access(file); + add_rchar(current, ret); + } + inc_syscr(current); return ret; } diff --git a/include/linux/fs.h b/include/linux/fs.h index 6441aaa25f8f2..4c10a07a36178 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1905,7 +1905,6 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, struct iovec *fast_pointer, struct iovec **ret_pointer); -extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *); extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *); extern ssize_t vfs_readv(struct file *, const struct iovec __user *, From patchwork Thu May 28 05:40:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11574723 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F6A2159A for ; Thu, 28 May 2020 05:41:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC5C520899 for ; Thu, 28 May 2020 05:41:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="taesqRkS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728143AbgE1Flc (ORCPT ); Thu, 28 May 2020 01:41:32 -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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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);