From patchwork Wed May 13 06:56: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: 11545175 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 6C68081 for ; Wed, 13 May 2020 06:57:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53FF020718 for ; Wed, 13 May 2020 06:57:05 +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="Cpy9yo5p" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730057AbgEMG5E (ORCPT ); Wed, 13 May 2020 02:57:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726020AbgEMG5D (ORCPT ); Wed, 13 May 2020 02:57:03 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44102C061A0C; Tue, 12 May 2020 23:57:03 -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=e06V50DvlSAd0cjThq/uEzcBoN3nGl+GOyNKKGYH+cE=; b=Cpy9yo5pJaasmJZsjzEAZa0x5+ gwmF1NxkUhySvtE4qn/S4sEiFThHS+Kf2wfJsyUXCtdxOjhJCemsH620xTWSg9It1OkVL12ImlWuX sKjjRO3xKjeb0GaAtwvAWEGPTKomzP07xsg7XavQX6YYU4grcmeva7yxxz85nsKrKj29X2E8DX7e3 ictdHvmVK71ERYZqFi2ci5q7HgilydEoAZm07OF+vpNKp4fL1xZzDwVufvNMosdns1CGasPEH1L1f ce5m/KudHyk/nY6jDXg5+VanH9GKV8PDv0o+nBJPz0wpnnVJ/kikwdDRPdv0sckZoPjqirShS6lTf FvXD7b8w==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlK8-0003UW-S1; Wed, 13 May 2020 06:57:01 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:43 +0200 Message-Id: <20200513065656.2110441-2-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 1dc97f2d62013..c0b99ccd9a79f 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 Wed May 13 06:56:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545179 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 3286114B4 for ; Wed, 13 May 2020 06:57:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 110F620784 for ; Wed, 13 May 2020 06:57:09 +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="pLg5Kt6Q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729980AbgEMG5I (ORCPT ); Wed, 13 May 2020 02:57:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726020AbgEMG5G (ORCPT ); Wed, 13 May 2020 02:57:06 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EBFBC061A0C; Tue, 12 May 2020 23:57:06 -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=rXtaZ1o/KEZPUZSWEL2q4wXgiltZU/5g4tfpDlbXLdY=; b=pLg5Kt6QBe/gTDZYWUaFlA1FTD 24J+oa+KLkw0xpCmIUI1XPHhRyM6GL25rsb5CogQdpQ/OHd67+yePhl/Z7U5oAAzmexDEb6fjALrZ fRmjrmp/NCElzHmUC1zYFfNYIH7ihr4ZMaT+ZgEVARqiRLLuI2ccxAVOm0RCZqqUsMJ1qrfiJOGLB 6lWWEVb8ddKF1fJtiFL2R3HNCJAMG3chYWwjDFO07SwyVKJ15wmHtQr1/GsSC33lLEk4IxtEMCtdW IK9T69Y9wNRvXsaKBvVlDsd1fNeZycc366CvQVKfrvb1UrE4xOXusW6qIgfUz40D5RldTXv8OZWPt GktUnNbA==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKB-0003Uw-J1; Wed, 13 May 2020 06:57:04 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:44 +0200 Message-Id: <20200513065656.2110441-3-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 Wed May 13 06:56:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545183 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 D26F881 for ; Wed, 13 May 2020 06:57:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B8DAA2176D for ; Wed, 13 May 2020 06:57:11 +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="qw6git+s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726020AbgEMG5K (ORCPT ); Wed, 13 May 2020 02:57:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730102AbgEMG5J (ORCPT ); Wed, 13 May 2020 02:57:09 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02187C061A0C; Tue, 12 May 2020 23:57:09 -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=qw6git+sAifH6bMLJfZjlTewqv NLYeyPpqOsrNb12Q/x74J6RUbZnCfLNC5LdjTVEEFwfGJfKBB0Wm7PDyFPN1UNb3oQ27qwe4LfquV n9B70V72NPokt4O83Uk4pqSA3g44vBfAfEqvDwHCLmAlSqEzXTrlB9LChlwI7BuINURQxW8lfX4Si nYRfdu068mzXy9s69bisvyPSKvUAfHsSRRXeiTBp2od5dmj1i8DzcZQmqhaaSF197SUpha1/eWpKR TJPw8Khm8txu1ybGChXX7D23/VEj9UGeEJJSdSh/fgBSLwd2Sy76eelS8Sr2zC7kYO6qBaIh/H8r7 YlyNgQKw==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKE-0003VT-6N; Wed, 13 May 2020 06:57:06 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:45 +0200 Message-Id: <20200513065656.2110441-4-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 Wed May 13 06:56:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545187 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 17A5C14B4 for ; Wed, 13 May 2020 06:57:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0075C2176D for ; Wed, 13 May 2020 06:57:16 +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="utACUokS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729644AbgEMG5P (ORCPT ); Wed, 13 May 2020 02:57:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730139AbgEMG5L (ORCPT ); Wed, 13 May 2020 02:57:11 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AAE4C061A0C; Tue, 12 May 2020 23:57:11 -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=utACUokSRtyGsml0bWiLC/zofR rCtC1NSoIN/rv6qWqcjkAC7JNfbmNBVhx4oRYoWDNW8lvA0WYZuhg3mA/GUw06cfJEPOR0i5vxu29 CdlFrORESrlIUo33esqGMfp3V0lvVbOWxCv7ydrsKLJoMWd1xmnm2Xu22vhylDIKyPpejOFbpF/7I hrnPitCY0KveOwfZ0zqUfN2E04V7mTi8osl2LCNNLi+7xi/qn9Mv9RFXPBKKr6uTfSHgJ75UQs9hy HdO1kYYM9NSjYOc3o4euaNWVudcccPqLZHXhNa1R40ui5pJtzwHd55x9Hku2xw1x8l5odiq6oOyku kGzWqwhw==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKH-0003Vn-25; Wed, 13 May 2020 06:57:09 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:46 +0200 Message-Id: <20200513065656.2110441-5-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 Wed May 13 06:56:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545227 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 A08D814B4 for ; Wed, 13 May 2020 06:58:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 886412176D for ; Wed, 13 May 2020 06:58:07 +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="eWlybqD1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729931AbgEMG6G (ORCPT ); Wed, 13 May 2020 02:58:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730102AbgEMG5O (ORCPT ); Wed, 13 May 2020 02:57:14 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00F55C061A0C; Tue, 12 May 2020 23:57:14 -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=eWlybqD1KoTTOjAxPIZ2GmGWuc r0mVzo6v3VqIjQsb1BJnI2VjR76FE6lLwK8iPOkLkniP/nfrJ0HvsMbGVVwb9dxmOFJqw4rLzstig /AOO6BOIDBHii8SHUYx5IOVsShPqYwPBXLqTKTKBhFWohbuk1wq8vGYbjFt1N57z/Qy2lB5KQhtZo EBr/cuX/UaWaQgc1OmWk0ayffxDDRoMTObYde4/cIkEUoDzQO6pkUpiUZJvIJ7/G2keHRveErX+22 eHW8Spdj0zreRaHWSiScS5jdBaDJFGXKD6kB8Lbt08MtLXYAF/FdfIsVQqY80hDNZp/eNDpiNTtAs zXXZfWsg==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKJ-0003WJ-K9; Wed, 13 May 2020 06:57:12 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:47 +0200 Message-Id: <20200513065656.2110441-6-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 Wed May 13 06:56:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545219 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 E86E314B4 for ; Wed, 13 May 2020 06:57:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA36220718 for ; Wed, 13 May 2020 06:57: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="dL6Gnd5H" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730292AbgEMG5T (ORCPT ); Wed, 13 May 2020 02:57:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730258AbgEMG5Q (ORCPT ); Wed, 13 May 2020 02:57:16 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D07B7C061A0C; Tue, 12 May 2020 23:57: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=DRip+MGYeXnAm9ZgzN+DsTqmAXn6wgI0HX1AmvNIpA4=; b=dL6Gnd5H37HpOIBcYju2mxlVGw V17ie2vxjCEp7WAqanl4wpn7dkMw6/bDvpA8BYqOXr5riBIdn2X5KSSYRV5+Kxp6NDezCcBE+ULtQ idN121qEQGQ1FZVA0iOLGq0IOJThz4jm7shygeNyqHmATOkC3Wz3D08pWZa+6HkDgNZrd04SBv6Pb HEyFmHs41e27Ip+Cxx1oN2/87sE/aZCRRPDdZeke+S6jY7ShA8scWzhNYszhlDj3jYiI1Qi0ezsvV wbHE8XySZlJnS46cSw08Ll//aN9k/MBtZ5X//QRfWX0qLn8bOtLdzr9gsYQgyIuVBt77gAn7LAGl+ zhHoCmAw==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKM-0003XR-99; Wed, 13 May 2020 06:57:14 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:48 +0200 Message-Id: <20200513065656.2110441-7-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 979d9f977409a..59514051383e4 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -2582,7 +2582,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); @@ -2697,7 +2697,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 fd0a1e7e5959a..a59d4fadf27fe 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 Wed May 13 06:56:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545217 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 C93C081 for ; Wed, 13 May 2020 06:57:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A804A20784 for ; Wed, 13 May 2020 06:57:57 +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="ddmpe0Cn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730358AbgEMG5W (ORCPT ); Wed, 13 May 2020 02:57:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730310AbgEMG5T (ORCPT ); Wed, 13 May 2020 02:57:19 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DCD9C061A0C; Tue, 12 May 2020 23:57:19 -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=ddmpe0CnpS5hTGI3BvsktS/hjS +5N2t4yhisWNhSCpaQig9siB+HfCl1Yd/k+0mOW8gXepcJlQZt9ge4skfIu+IrRDoDIidW2QzZkpN vuloxdXC6+SFg9jbqWXt3lmYInuKOVrjpvTqI3/d/x+Jf90ccs1Cm5K5FtSx7ZVhxfUjaMazTwKhl Vh1ul/8U/6pCqz4Jg5r5HGPTmdkBIMs7dVLAP/fhFDrOiqLYvAgh3LPwYg5iu3x+QmFIXNNlH6GiV Ss32GP7NZOR4ZJvMuhGNGAewSvAZXihH5Yk/ZUUDdrUcObpvScwAEr/SOus5CyBV13zmwhsyWc3I4 oIc33EGg==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKO-0003YE-Rp; Wed, 13 May 2020 06:57:17 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:49 +0200 Message-Id: <20200513065656.2110441-8-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 Wed May 13 06:56:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545223 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 03C0281 for ; Wed, 13 May 2020 06:58:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E10CC2176D for ; Wed, 13 May 2020 06:58:03 +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="Xh7/wwtu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730521AbgEMG56 (ORCPT ); Wed, 13 May 2020 02:57:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729931AbgEMG5W (ORCPT ); Wed, 13 May 2020 02:57:22 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37FBAC061A0C; Tue, 12 May 2020 23:57:22 -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=Xh7/wwtuyk68AwJ/EwEpKp5/Qk MV/eZNBaS5bCbQfIFd+7BG10eiGPDOOWMTM8kBUW9AZ3fECXhFf9dPB3T4GZ4amq6DLcehidU1A4u GkLVYvwWrDoAq42G7BsRC6k6KNiTFga7eJHjhCJxTSGpGbonX7kx5LV0WeGANnAIwPe6BW4hPE1Bk zCPsgPoaXQ8B8r5dtpm26wnuFo/gGnH7GXwCnIM+sktKapjbeeJr7UK8GNWM0MwUnnZjTwWV0DGsM cr4KUe5U7yTLnTkq1RTouEHX7itJpGZS8sMonYVliSB6mD4LGniayNDG514P/M4QH3ECI89sfLDud ht9ziHKw==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKR-0003Yg-QK; Wed, 13 May 2020 06:57:20 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:50 +0200 Message-Id: <20200513065656.2110441-9-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 Wed May 13 06:56:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545191 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 48ADF14B4 for ; Wed, 13 May 2020 06:57:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30B4923127 for ; Wed, 13 May 2020 06:57:27 +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="kOKLaKSs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730426AbgEMG50 (ORCPT ); Wed, 13 May 2020 02:57:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730418AbgEMG5Y (ORCPT ); Wed, 13 May 2020 02:57:24 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD4F9C061A0C; Tue, 12 May 2020 23:57: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=axSbbRT9BzCYIqAhw6GFe8AhXOOBJWbdO6tNDMRT5zc=; b=kOKLaKSssLgrKqBnoHJ/JIjbTS mMgX3xXxkUKBcpmyvLDaG+ifAwDGRv7kAGVErjGZVph69mcEzu8Xd1yTpNA8vS0A68fclkbpdSCB5 R/fIAliwIclx3Y/t06x98HJpVn88maklIGYviruVcyYRbb8SvvsumtLFyF+3G0DqLGjG48DYczkvF hLwMEo8u97VD8d65xaCxrvUnSLrYK0EevpMojYbs+dnP25NuTEwP679LBevdUAbERFWXfZ5ISDnlp HA5Y1xy6SHfUYhFNVM3lrywemEbIEJRz0aW5X80W6fmOGLhRjtSegATkrbcuG1omJlVs3rpMn2mTk x3fRW1Hg==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKU-0003ZO-AD; Wed, 13 May 2020 06:57:22 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:51 +0200 Message-Id: <20200513065656.2110441-10-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 Wed May 13 06:56:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545195 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 7DB0F81 for ; Wed, 13 May 2020 06:57:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 633082176D for ; Wed, 13 May 2020 06:57: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="kgCEK11m" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730418AbgEMG5a (ORCPT ); Wed, 13 May 2020 02:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730473AbgEMG51 (ORCPT ); Wed, 13 May 2020 02:57:27 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CF4DC061A0C; Tue, 12 May 2020 23:57:27 -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=kgCEK11mX5oha5ZCaVeyrI15vP w0mhX7v/Z1M5YdhOfQPKiSdT9V3tqMpcd7pCKMnGU2ZCjX4N8McFXWgvFPkX094J9r6FuXlSW10oI vKKph5Ng1xaFxrzGfIL8csbOjUtOb9Z4Fk/EnutrQ5DGaXeJCscLWVNgvEWLu7EPxHB7GPpb7FP+2 RXjpq784rVPTrfgzyL8MiHgUKVSUagZubt4xei7JVO/a2hcXjlyYtElxrHD4H3MOZYqBsRExVjKEt iAl8EB8CH0R52mnpJKzrVUrhdYxPwjoygazTyLuKHZlUZhGGswkbAwwmJgv8JTgJUKQY9f3BkPNl5 GstJzwWg==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKX-0003Zb-19; Wed, 13 May 2020 06:57:25 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:52 +0200 Message-Id: <20200513065656.2110441-11-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 Wed May 13 06:56:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545213 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 9C2B214B4 for ; Wed, 13 May 2020 06:57:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8355E20718 for ; Wed, 13 May 2020 06:57: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="Ac7jfU+K" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731775AbgEMG5u (ORCPT ); Wed, 13 May 2020 02:57:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730521AbgEMG5a (ORCPT ); Wed, 13 May 2020 02:57:30 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6832C061A0C; Tue, 12 May 2020 23:57:30 -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=Ac7jfU+K7c05lQCCDEcvbMGyeX FBWUEVcR/Ep1f5njna/xn1Mv9c0/iztL5/Y5A0nRqtTCsarfQNklqMM4r2fSLJlhC7YD31t3zeo6Y b/oAEODYLg6MW9V4E9faNzSpnTnGtCnfy21ArDOUM3DIkMNGU2g7diAM+gGXCdGvNRbXpdEP/zccy Kz9pK6/YD6GoKHkY88LJN51YyCFf+F8v8DZXqUhX+oJbue4D8tFqry2Bpsx/GU8iZG5mzi4OubGM/ 5p0o/qFibgfyKNz44I2wnuMdG78Qr3L++T0fDteuQsOqyGz24jN52o8j/edMQ4KAs8UKiQOq3EwHo 5421umAw==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKZ-0003aM-JV; Wed, 13 May 2020 06:57:28 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:53 +0200 Message-Id: <20200513065656.2110441-12-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 Wed May 13 06:56:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545197 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 23A6481 for ; Wed, 13 May 2020 06:57:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B5D62176D for ; Wed, 13 May 2020 06:57: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="FmMhzH/2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730575AbgEMG5f (ORCPT ); Wed, 13 May 2020 02:57:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730537AbgEMG5c (ORCPT ); Wed, 13 May 2020 02:57:32 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCBA9C061A0C; Tue, 12 May 2020 23:57:32 -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=FmMhzH/2aSmLwOuRoLkk0nUEJ5 NaFBThyFh/dTRFR2ni66Wtd0FTF2Yw4tqUhjfYeXPmCXrQNKUeMjUkMxfxmMC21AVLIUiHF2WRAhs MOlwkoBeMkgWOwa4Qp+zMhx7b6MBjOw0teUPSonqU9qJMcPUdxnmNDHskKq/eh/UQai3toMnCmNy4 L5kpcVDockSjlyYAwPUatRDSLbkI4XBm37eMuevhlVe7rj1Yqz+qjIQeqSTNFjXJPX6kngvjUDq5x L6yytL85yL3qhtTs905janurHEn5wmprJo8XPpGvJar4LcAHUjDhSP/mkBcONRFS9NRMiOW7z82DM CzzwlqhQ==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKc-0003bE-Bh; Wed, 13 May 2020 06:57:30 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:54 +0200 Message-Id: <20200513065656.2110441-13-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 Wed May 13 06:56:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545205 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 B298F14B4 for ; Wed, 13 May 2020 06:57:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98F6E20718 for ; Wed, 13 May 2020 06:57: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="cpXTMSDK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729367AbgEMG5o (ORCPT ); Wed, 13 May 2020 02:57:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730562AbgEMG5f (ORCPT ); Wed, 13 May 2020 02:57:35 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 581F3C061A0E; Tue, 12 May 2020 23:57:35 -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=cpXTMSDKWMLl3JK6G5crB3c2nl YqhuG0LvrL66QAYJl0Ej/UuNVWyvqf+UMHx0Utl0xbe8nNUQP6UfWAn6oSwWkCOUyGMZjs//w/Mf1 MlNHLcdwplxhqdZcrWOcH+92soIe8UdfN538wz9RWMnFJSN4OEgkNwazs6jmfh5PIClXpCzsIAxrn rMm/ujzCCLsyvX2VuJGd1pJAhqSpDSErRJK8WRTsx0KyercPcEn533flMV3mTKXNvGBoPvlPYr3oV kScHJ4S0c/2gV7sObdOBF6JypkBT7bNUDnG7ntU+sfi/N8bL+wDoZMEc4AVyWgUW6jCIWRf+Z8HGW LK1Y8SZw==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKe-0003cG-Tw; Wed, 13 May 2020 06:57:33 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:55 +0200 Message-Id: <20200513065656.2110441-14-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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 Wed May 13 06:56:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11545201 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 B85F617EA for ; Wed, 13 May 2020 06:57:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A150C2312B for ; Wed, 13 May 2020 06:57:40 +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="XLxg3FNB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730718AbgEMG5j (ORCPT ); Wed, 13 May 2020 02:57:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729765AbgEMG5i (ORCPT ); Wed, 13 May 2020 02:57:38 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E78BC061A0C; Tue, 12 May 2020 23:57:38 -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=XLxg3FNB06sgO+Mvcd5lDJKwjP uoOZRG3bBXqQEfGfwdp3+GQhc7kJU+L1VQSJS73w0gINeO6zpXApIRVV0EWbU1LQloOBZnar/MIZi 7tWFQRfv7B2u6FBn6KjDeRtWL+y/cbliY7OwW2zuLl7wiEZyHy1y7rcoI79Kc5s6xSwYdF7wP3lih KU9xne6mBOLIL0J7wvzvvLy2hs+ddTZKuTlgUnx0d2fUBK/ejvI0cov4NL/m0+nKPm7rceaYr1fKU gTrfuSsmtdZLvSnMAUjZxbvyqDyQ113YAC7ee+WrNvftN0BuM5imo+ZBsl4pw6nK4ooBvoG9mD8Y1 y8rQkVdw==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYlKh-0003ch-MB; Wed, 13 May 2020 06:57:36 +0000 From: Christoph Hellwig To: Al Viro Cc: 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: Wed, 13 May 2020 08:56:56 +0200 Message-Id: <20200513065656.2110441-15-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513065656.2110441-1-hch@lst.de> References: <20200513065656.2110441-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);