From patchwork Tue Jul 7 17:47:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649495 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 8FDC513BD for ; Tue, 7 Jul 2020 17:49:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73E8C2073E for ; Tue, 7 Jul 2020 17:49:43 +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="ffwwwsSz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728863AbgGGRtj (ORCPT ); Tue, 7 Jul 2020 13:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728392AbgGGRsP (ORCPT ); Tue, 7 Jul 2020 13:48:15 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEB69C08C5E1; Tue, 7 Jul 2020 10:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=fw2+4gebTcJUXyNcS2c+cOqcMRuf3D2bJUNwgAt6wzg=; b=ffwwwsSzRkfiu1zSF/dykwvPc6 8DlX3s1/JsA5j+3ZxaN35I3y8UKbSNZta7qy8O6/AntqKCbHZIkytU4xodFLn8rJqYTu3mjCszaaX //pvzQoXhFoyBDgozgYfCfERfE5V2s9+8M6jxIl3s6kgpfocqAPUaJdD0fMQ+rZ+KS0WL0pDDhvmS X9V0jFPiI9sLSbhBnyol3t8nh7VsUpyBbZOchGcqWp+sWoOADUX9KGSa0US5n3MUiHiQOqZs0M7CF WF9x1+06iPAv8evXC6xKzWPanD+2FxIggtGftp3sijUSmihNue7qJi9e/uvm4YhtaqVIMhTfByosQ Tq+rfLtw==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhN-0003Gz-4o; Tue, 07 Jul 2020 17:48:05 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Howells Subject: [PATCH 01/23] cachefiles: switch to kernel_write Date: Tue, 7 Jul 2020 19:47:39 +0200 Message-Id: <20200707174801.4162712-2-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org __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 e7726f5f1241c2..3080cda9e82457 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 Tue Jul 7 17:47:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649497 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 24A4B912 for ; Tue, 7 Jul 2020 17:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 023DC20708 for ; Tue, 7 Jul 2020 17:49:44 +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="lMLi+aGs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728326AbgGGRsN (ORCPT ); Tue, 7 Jul 2020 13:48:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727777AbgGGRsM (ORCPT ); Tue, 7 Jul 2020 13:48:12 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE3C0C061755; Tue, 7 Jul 2020 10:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=jzV+T85fyIY/sAf/kMztKfiAVfq1VzZmIi5LCeoOypo=; b=lMLi+aGsrNxCY3Oj8Qva9lGg5l txPcbqJfSTYYP9op3LwyT+uR9tdwA92AaslaNjSEXtheBTxptT0qQI+CmjCI2b8JoTFh86SVTFBmI IL/TNqehK0nLGW86csDnn3Zfix6xoKKsU7e1tWtJpucMjZMy6gYLvXf5/AQ0vzZvya/8Lflj7RSGT gOUxHayKLqkhrBZo0IAdTKYmUYf7I2nOdhL2lsbZKlvloIXvmugAO0gC70qeURHk9DNnuB2sGQEPQ LUUVMelXKCAQeYGbsHhfJpIHUKFwcrOSGonjuj7Guqd39Mn0g44B9Yf0u9jGrnRlyOjZ/Rs3C9byD /5xaGPWg==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhO-0003H9-7X; Tue, 07 Jul 2020 17:48:06 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Ian Kent Subject: [PATCH 02/23] autofs: switch to kernel_write Date: Tue, 7 Jul 2020 19:47:40 +0200 Message-Id: <20200707174801.4162712-3-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 b04c528b19d342..74c886f7c51cbe 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 Tue Jul 7 17:47:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649489 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 ABB5413BD for ; Tue, 7 Jul 2020 17:49:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9413520738 for ; Tue, 7 Jul 2020 17:49:25 +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="UTUPIlR6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728804AbgGGRtS (ORCPT ); Tue, 7 Jul 2020 13:49:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728471AbgGGRsR (ORCPT ); Tue, 7 Jul 2020 13:48:17 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14197C061755; Tue, 7 Jul 2020 10:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=PIZcUHBXRzg4FA/EeFx1uXo9md1v0NkQLsX0zI2zg6M=; b=UTUPIlR6WQ9gbpj9oAyWWz2BsR P3RItcDIDoSx/mQl8E1LH3rfmfp9B6H7lcjkM6v0K7aSTu9gFSw09qAy6wMGwNKVTu3yty1qMeGNq 34uLpX2d/UnJPXWo98PJq3nlXgcC1v/iXyEdOtoyGhVC65sOH60b5WnRj2w/9v9VeqHyGK6X7FmeA 5BzQPRU6hktMA4PqUub5DFadHMy/9rmmrBrAUxzyEb+koA5inbSF/5kKZtiJvdNzufjCvODircTS7 NH2kxFOvOSleSJDPU3MalGwkjMoTbW2lSm1RKDdeUwjEibm+7WXlhdgjLEPsN271ZvYT4qBtsse78 pEU9tPSg==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhP-0003HI-AY; Tue, 07 Jul 2020 17:48:07 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 03/23] bpfilter: switch to kernel_write Date: Tue, 7 Jul 2020 19:47:41 +0200 Message-Id: <20200707174801.4162712-4-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 c0f0990f30b604..1905e01c3aa9a7 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 Tue Jul 7 17:47:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649463 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 F0DBA912 for ; Tue, 7 Jul 2020 17:48:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE3242073E for ; Tue, 7 Jul 2020 17:48: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="gUdNvtLu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728466AbgGGRsQ (ORCPT ); Tue, 7 Jul 2020 13:48:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728379AbgGGRsO (ORCPT ); Tue, 7 Jul 2020 13:48:14 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DF51C08C5DC; Tue, 7 Jul 2020 10:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=Bo298b9PL3Uu2rIZ3OmLGqOnn53VokHDlRvRjRJg3qI=; b=gUdNvtLu1LXksfHJwAE/PEGff/ IRsFpXTeIDn0OZgGTZfQLo/BfWKWKGB59MRTKJJ90h/3ou01eixHX+he8bGDRA++03Bo+K5I1uzGu lkNR2gHQ74B0o35kSpZRF8LV7wnjMBtvF0ts/annAWLDl5TOD4GWmknlujQnFOA9zpvXDJyf9GWWu NV8z22SZ8Myr75iZpxurF2xzxlxlshIYZl1QnU5dpgOH0rsI9j0Wc4I16NUqtYTUTwAV/lJ5v+6Ia AAYQ04+5d8u3MlwAALUVKuhrygUFDe2Q74m3gFKfhkNmI/yFcqpHKDc1d+0Vw/5ZrC9DkIbyE5ztX /IYoyAdg==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhQ-0003HP-Bm; Tue, 07 Jul 2020 17:48:08 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 04/23] fs: unexport __kernel_write Date: Tue, 7 Jul 2020 19:47:42 +0200 Message-Id: <20200707174801.4162712-5-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 bbfa9b12b15eb7..2c601d853ff3d8 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 Tue Jul 7 17:47:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649491 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 209B1912 for ; Tue, 7 Jul 2020 17:49:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE60B20675 for ; Tue, 7 Jul 2020 17:49:28 +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="X75j3alJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728834AbgGGRt1 (ORCPT ); Tue, 7 Jul 2020 13:49:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728404AbgGGRsP (ORCPT ); Tue, 7 Jul 2020 13:48:15 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3667C061755; Tue, 7 Jul 2020 10:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=Ruv3QkeH3yf1ddYt00bBWdUvSXa4YUB7wJ/k+J42Rps=; b=X75j3alJTwTh4rHPd55B93+/Ks ZDooFPCkgJDSFe7kTvl8S0qHXjcPmrmVbG4kE5dWn1aBg5XcL6O2bt8sjQ+Y0LyjxwLL8OYuXVJEE QJg4Jx9j4QBGZsgyNooR7TZverM3Wp6pGQqw0F+eU0Yzn0ze1RrSnrO2yEuzgQy+yUO1hUjt2IlNy LEif7xEfDnBwEFUvbESNgImccJHWXdjllpjiyDHeEoJfJScVp1c4r82NLoB4A6Aa5gi+kqigR6nAm TIQgpDqDmndI3RL3N8pn5i3la1sn/13TK6GpesmHTrlecc2SAf58SHpV/4uupE4zcwuBY6ipMIRTQ P6nfKkKQ==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhR-0003Ha-E1; Tue, 07 Jul 2020 17:48:09 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 05/23] fs: check FMODE_WRITE in __kernel_write Date: Tue, 7 Jul 2020 19:47:43 +0200 Message-Id: <20200707174801.4162712-6-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add a WARN_ON_ONCE if the file isn't actually open for write. This matches the check done in vfs_write, but actually warn warns as a kernel user calling write on a file not opened for writing is a pretty obvious programming error. 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 2c601d853ff3d8..8f9fc05990ae8b 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 (WARN_ON_ONCE(!(file->f_mode & FMODE_WRITE))) + return -EBADF; if (!(file->f_mode & FMODE_CAN_WRITE)) return -EINVAL; From patchwork Tue Jul 7 17:47:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649493 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 0C6AA912 for ; Tue, 7 Jul 2020 17:49:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E662E20786 for ; Tue, 7 Jul 2020 17:49: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="FedC0yES" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728505AbgGGRt1 (ORCPT ); Tue, 7 Jul 2020 13:49:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728440AbgGGRsQ (ORCPT ); Tue, 7 Jul 2020 13:48:16 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8347C08C5DC; Tue, 7 Jul 2020 10:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=Hlt6C7VzRXUPvzt04ubxLGUKBtxCCqCnw0SDgIXm7hw=; b=FedC0yESTcWwLvcjowIvzYO5kq 8Yla9CQhhoM/P0NsCRc27TI/uwOMB4Zu/E/moc4ndCkdSL7NkZRiZMhNHYrIC5HR0iFKw+/WysYlI yZKTU4iq0Np4TKJJZDx8/A0D8+hrnzF+IVbTcB7rw9YU/aVnsKslNf0hm1+6xDktO2bLaOsdc4xhk 6keJC5+QACVIp2qX070sCpAyFI0oF6XVXLkh/QuNi0zDp6m+WrKDhNMqhg4NFP9GFON81Kjc3yvDI Si1EG5LTZeEpStd9gD/5Y2Oj0TeN8zngapPPA0yjHU2vsIEebH/UdlL3HVwENCxTE9DtEbr7R06Se FIxz2vBA==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhS-0003Hj-Fn; Tue, 07 Jul 2020 17:48:10 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 06/23] fs: implement kernel_write using __kernel_write Date: Tue, 7 Jul 2020 19:47:44 +0200 Message-Id: <20200707174801.4162712-7-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 8f9fc05990ae8b..5110cd1e6e2771 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 Tue Jul 7 17:47:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649487 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 DEC6213BD for ; Tue, 7 Jul 2020 17:49:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C64AE20708 for ; Tue, 7 Jul 2020 17:49:18 +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="j5SmmtFF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728796AbgGGRtR (ORCPT ); Tue, 7 Jul 2020 13:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728485AbgGGRsR (ORCPT ); Tue, 7 Jul 2020 13:48:17 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41C68C08C5DC; Tue, 7 Jul 2020 10:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=dVcUaNs/nJl21S9DI4MlGzuWbjmDqO4Jqbdos/3DXPs=; b=j5SmmtFFNxcF6I1KUTCPlm4nu3 Byl9VICfCeLVlKYfFWNDEWX3pJuS+O/12xgfG+YmlFdk08s7TIRi7srlPnTPHEDjXYF2YJAR2YsGj UjVmIyN2hwf0+HGna8Nvn8hE6ajtOYzLI75+wlyghuBfQAOZcnDcEs6YdnuqnX7f6y+FqfJtYLtvk GBQGOWWYLIHOwtF3XdUzCNAUZPg3oc9WnXdCNC+lbE3nk1xgU+w69wGjoRxIz+grj/fy+lfHjVUds mkgFAt8sRTunhakcyI/d+DdjqEFcmN0pKqwupa2RJZ3K21EgELbquobG3SskkMfH/gVzAekj1t8Zh 4Ji+Vgxg==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhT-0003Ht-J7; Tue, 07 Jul 2020 17:48:11 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 07/23] fs: remove __vfs_write Date: Tue, 7 Jul 2020 19:47:45 +0200 Message-Id: <20200707174801.4162712-8-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 5110cd1e6e2771..96e8e354f99b45 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 Tue Jul 7 17:47:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649483 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 4F4E1912 for ; Tue, 7 Jul 2020 17:49:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3740B2075B for ; Tue, 7 Jul 2020 17:49:13 +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="s2k/Uysz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728514AbgGGRsY (ORCPT ); Tue, 7 Jul 2020 13:48:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728493AbgGGRsT (ORCPT ); Tue, 7 Jul 2020 13:48:19 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E734C08C5E1; Tue, 7 Jul 2020 10:48:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=pE9BZ+cY4E02xMmAEaREea9Ma9ZDLW8TJAoArZaeVmc=; b=s2k/Uysz/zKiqGbsJ2zZX4Ej3w JMSxVE2ZhZdssp0Q+a4+jMLac7zyRsREMAAiccZx6Fu4UhEOr9VG60Qbxnv8NB/zp6Io3SB4X7Iz9 3mz0m3ME2vPiRq8UyANleuBUUWya45shpTiLZ/y/viAtkIl9s83u+YPGcp5gdfD89fIGOUiyTFMor Ble0ko/pyOMWwRL+l1+cxqPJ1uMxS1XR5kLdJIvUzfQNbJjrSaw06+m9DPSvAdG/RkuUX1RDg11wO wGe5VwCQSv9SbE57mAVXbEMxoZbHZz3AEE19JMwPDMX90eT+dI3SIXo4bm041CtMFWGIs3Gs+6+N2 gUS8199A==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhU-0003IC-M5; Tue, 07 Jul 2020 17:48:12 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 08/23] fs: don't change the address limit for ->write_iter in __kernel_write Date: Tue, 7 Jul 2020 19:47:46 +0200 Message-Id: <20200707174801.4162712-9-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 96e8e354f99b45..bd46c959799e97 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 (WARN_ON_ONCE(!(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 Tue Jul 7 17:47:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649465 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 1EB55912 for ; Tue, 7 Jul 2020 17:48:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0541C2075B for ; Tue, 7 Jul 2020 17:48: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="SGBT2hXu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728603AbgGGRs0 (ORCPT ); Tue, 7 Jul 2020 13:48:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728573AbgGGRsZ (ORCPT ); Tue, 7 Jul 2020 13:48:25 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA906C061755; Tue, 7 Jul 2020 10:48:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=8oAca2Sh96a0lCcV3gNnPlvoMT0ySVT+lMAbT/xWciU=; b=SGBT2hXuirr0IaFti3lia9tSRU VweNIjq3OrAr2hK/vno0vV+HxxOmSpcmqkNEbPWnvWFYBR1Hr9srSkkQnOHCv4NViyNQtXY3DeDi8 SzPd1dWGgRq1ZgN0uoWxPQMt69bZXzMnxdgpkTV6a1n8KmzCjdFPHNSovZBeantiOow4m6xcubRT/ Frd//4rP24Zf9GPiJo+yqR4k0bGEsBgw9J+d5QKNSPUJLJ/L1xoNykfvJIofZNqn8zAhZIrQNygjV o5dgGljCjpSRBn+hbyV5ijuqsyaCDIsNv3YY9VyBDxWieholZd9mVfoBAPxZ7C3SV4UBv/iEiySD1 8z20ql8A==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhV-0003IQ-Rs; Tue, 07 Jul 2020 17:48:14 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 09/23] fs: add a __kernel_read helper Date: Tue, 7 Jul 2020 19:47:47 +0200 Message-Id: <20200707174801.4162712-10-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 | 23 +++++++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 24 insertions(+) diff --git a/fs/read_write.c b/fs/read_write.c index bd46c959799e97..cc8e0b4f3cd697 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -430,6 +430,29 @@ 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 (WARN_ON_ONCE(!(file->f_mode & FMODE_READ))) + return -EINVAL; + 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 3f881a892ea746..22cbe7b2e91994 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3033,6 +3033,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 Tue Jul 7 17:47:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649481 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 B8F6A912 for ; Tue, 7 Jul 2020 17:49:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 993202075B for ; Tue, 7 Jul 2020 17:49:10 +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="qmF5VmcK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728528AbgGGRsY (ORCPT ); Tue, 7 Jul 2020 13:48:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728379AbgGGRsW (ORCPT ); Tue, 7 Jul 2020 13:48:22 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F1D5C061755; Tue, 7 Jul 2020 10:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=EBziasLTB9yyj8vVMRpUDtYmmAnu214zH16u+u17qnY=; b=qmF5VmcKBpsDHE6C4O1/fcyX4d K/B1cdCEwDZbGcw/Ll9YvyVe96JKpOrEqbAVaBR+bi7XaraAOMfKE4nMwJ0VUXUiAs+QLB/Iz/T53 7VS2mIp4AYuUB1GKS8oqE06rEjDJAChOYNs0HYjIuqRDyjLzeU3cMNIy3lC78Wm1he3HgXwo4bOea BvxXoM7wbZuVumkOguZul7s2Cg9EmeKsCGqX3laVk86D68UM7oPDu9yTRLZ/ObzDIIs/GjCDjiXpK 94Dimp2sIiy1OEDMnwWD9EpGnmFUrnIXk2e1mvbUZCZ9MFB01hGPnPjCx5Ug67KzwvTN8w/rb/Y5t yJRxDikQ==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhX-0003Ie-6h; Tue, 07 Jul 2020 17:48:15 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 10/23] integrity/ima: switch to using __kernel_read Date: Tue, 7 Jul 2020 19:47:48 +0200 Message-Id: <20200707174801.4162712-11-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org __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 e12c4900510f60..1d20003243c3fb 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 Tue Jul 7 17:47:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649485 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 7710D912 for ; Tue, 7 Jul 2020 17:49:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D04E207FB for ; Tue, 7 Jul 2020 17:49: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="mFGEGHx2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728776AbgGGRtN (ORCPT ); Tue, 7 Jul 2020 13:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728513AbgGGRsY (ORCPT ); Tue, 7 Jul 2020 13:48:24 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3DACC061755; Tue, 7 Jul 2020 10:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=rF/h+g2aRvM7O684xTgcwq5WjNPNPSLZJBoCztHySj0=; b=mFGEGHx2eqHf2GAe5IHSpAddv6 AbSrUPzSK75vbu/Zf7WkR6KQ1V4imkhSYcjovGcKVS8O07Yz3yjudqmrdLUJ21wAFNmjLcw0hEO3N VMSRsA61DPftGVp/9S9C0EaTIKdwfsv1kMbr8iJiEB02gFiU3jVeVimem1xvDUJmjc1j+I2AmoWzC H6Yq+UfIr+T0Pms73rNbaQiL50zuj1mp1Iig3W/+4ZWiQWlH4O6s7Ixz5vaSRN2gBPe1ez8xLJZSl MTCfQNc/igRpR1qvppp/9dHeCy5Kn6o/NWJ/xeKRhQH0UakZouzv3kF48NfaYcKsvKCplzRqMIrUO 72NIfuxw==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhY-0003Iq-Ee; Tue, 07 Jul 2020 17:48:16 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 11/23] fs: implement kernel_read using __kernel_read Date: Tue, 7 Jul 2020 19:47:49 +0200 Message-Id: <20200707174801.4162712-12-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 cc8e0b4f3cd697..a0a0b5d1d9249c 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -455,15 +455,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 Tue Jul 7 17:47:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649467 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 6DC22912 for ; Tue, 7 Jul 2020 17:48:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5508F207CD for ; Tue, 7 Jul 2020 17:48:34 +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="NYUTT3Q3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728652AbgGGRsd (ORCPT ); Tue, 7 Jul 2020 13:48:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728618AbgGGRs2 (ORCPT ); Tue, 7 Jul 2020 13:48:28 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE250C061755; Tue, 7 Jul 2020 10:48:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=0zhvBQZ7oT4xAzbMT5Iv8nd7tiG+K7QhKCHlApRhAsY=; b=NYUTT3Q3TYJ65LWaHXnHK3GGCi +hL5B/Oxyhpp/cR+DeLE3AgJThhijYDTKEINGRCm2f4Tm0J6rZMaJa8UdUzaiJxVADKELaPqMa34G szzHXVB6cosXWblvjxtek4s+fBDpAPi7hgs4f0a3tsY+boNHPX3+Bjz2dQR7X84HSlBYhco3JhnAD vOqPCwqVLj5IIze+LjraZGlQb1PqR18R3FIUGwJ56pTL0aiNHUNjIT+WiXdEA+W9+oPlXPputDbLi ak6HW97lYXNZF8XVnTQUevLkfJcgJSjJFD9sAS2/kFLelFEU/2Sc5lXI/vCPn5VfcMF9PAYVCLCfH X/XvbIgg==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhZ-0003J0-S1; Tue, 07 Jul 2020 17:48:18 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 12/23] fs: remove __vfs_read Date: Tue, 7 Jul 2020 19:47:50 +0200 Message-Id: <20200707174801.4162712-13-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 a0a0b5d1d9249c..6a2170eaee64f9 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(); @@ -443,7 +432,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); @@ -476,17 +470,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 22cbe7b2e91994..0c0ec76b600b50 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1917,7 +1917,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 Tue Jul 7 17:47:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649479 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 8508B912 for ; Tue, 7 Jul 2020 17:49:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B95A20708 for ; Tue, 7 Jul 2020 17:49: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="sUyc/Xx9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728760AbgGGRtE (ORCPT ); Tue, 7 Jul 2020 13:49:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728591AbgGGRsZ (ORCPT ); Tue, 7 Jul 2020 13:48:25 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98F94C08C5DC; Tue, 7 Jul 2020 10:48:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=RHUcUsvFM01nbSipjJ9wbpJn0M6zNebEekts07Aqyyk=; b=sUyc/Xx90PACCH/5DMtZ5TmMZF lf7i9vm7s2YVB029wP+OgA2KCC+Qw7Lf31pfH2K3vrZWSfjxhtQdsrg1rW2m81uboYTsHJwRBK2aG 2//EkgTY8c8wClX0IUYqIeXub4iRTj3g8hJoeLljo7KkIuwPNV57zniiXS/WxM3iFxKwbNkR7Dxjh 561nEWJp9QQkRQO85+7SIn0QHoklx+snhRz/FxWBQJJBSDphpm9GQNcmDAr2/kMfg0mskDSMB9fiD LK0S3u5DBA3IMYhz0MMrC9KATKwT49OhLV1gplFcfDm2y6+bE9WF+OzdQJElG+gIh3w2/I+hQN6wr cHqe8f+Q==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhb-0003JN-Fg; Tue, 07 Jul 2020 17:48:19 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 13/23] fs: don't change the address limit for ->read_iter in __kernel_read Date: Tue, 7 Jul 2020 19:47:51 +0200 Message-Id: <20200707174801.4162712-14-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org If we read to a file that implements ->read_iter there is no need to change the address limit if we send a kvec down. Signed-off-by: Christoph Hellwig --- fs/read_write.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 6a2170eaee64f9..8bec4418543994 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 (WARN_ON_ONCE(!(file->f_mode & FMODE_READ))) @@ -431,14 +430,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) { + 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 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 { ret = -EINVAL; - set_fs(old_fs); + } if (ret > 0) { fsnotify_access(file); add_rchar(current, ret); @@ -520,7 +530,14 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, if (count > MAX_RW_COUNT) count = MAX_RW_COUNT; - if (file->f_op->write_iter) { + 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 if (file->f_op->write_iter) { struct kvec iov = { .iov_base = (void *)buf, .iov_len = count }; struct kiocb kiocb; struct iov_iter iter; @@ -531,13 +548,6 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t 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; } From patchwork Tue Jul 7 17:47:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649477 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 DF97D912 for ; Tue, 7 Jul 2020 17:49:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C657620708 for ; Tue, 7 Jul 2020 17:49: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="k1S6jrk3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728647AbgGGRsc (ORCPT ); Tue, 7 Jul 2020 13:48:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728630AbgGGRs2 (ORCPT ); Tue, 7 Jul 2020 13:48:28 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7062C08C5DC; Tue, 7 Jul 2020 10:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=mmoVUcobkO+dCnZgQ7fZY0lcjXQ10mtOvDim8BHPO/s=; b=k1S6jrk3gGfBlEejCf+NgE87yK UUGnXPbrF7WMcZid7t7hAk40jb9mTh1morboQIwh+YMRUeoxZbUopHlcJll4ANNsBMflzyQ2S4ptk aAnzgP9feaBOYRk5ECAMsf8HzB59quqD5sDKL4bbRtNU8CBboxJPJ4eFkEEYi2jV7jBGHdYIvkry4 iIC3KVKfNEFw+SsAvchK1wKO5eEtqan7RKy4VqRiVf+va1lbGxgsBTD6SFIyqfb2zSqzWRd4Pv5MW Je6372XNnpg75i9Na62igg8gBTXm5k2Pc+yRbCBOQQW6B3+TSFwuPiBWrmjWZCaqIMUbmy+pKYFFi KMrnFM2Q==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhc-0003Jn-Pb; Tue, 07 Jul 2020 17:48:21 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 14/23] seq_file: add seq_read_iter Date: Tue, 7 Jul 2020 19:47:52 +0200 Message-Id: <20200707174801.4162712-15-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org iov_iter based variant for reading a seq_file. seq_read is reimplemented on top of the iter variant. Signed-off-by: Christoph Hellwig --- fs/seq_file.c | 45 ++++++++++++++++++++++++++++------------ include/linux/seq_file.h | 1 + 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index 4e6239f33c066a..4c00cd222adcdc 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -146,7 +147,28 @@ static int traverse(struct seq_file *m, loff_t offset) */ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) { - struct seq_file *m = file->private_data; + struct iovec iov = { .iov_base = buf, .iov_len = size}; + struct kiocb kiocb; + struct iov_iter iter; + ssize_t ret; + + init_sync_kiocb(&kiocb, file); + iov_iter_init(&iter, READ, &iov, 1, size); + + kiocb.ki_pos = *ppos; + ret = seq_read_iter(&kiocb, &iter); + *ppos = kiocb.ki_pos; + return ret; +} +EXPORT_SYMBOL(seq_read); + +/* + * Ready-made ->f_op->read_iter() + */ +ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter) +{ + struct seq_file *m = iocb->ki_filp->private_data; + size_t size = iov_iter_count(iter); size_t copied = 0; size_t n; void *p; @@ -158,14 +180,14 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) * if request is to read from zero offset, reset iterator to first * record as it might have been already advanced by previous requests */ - if (*ppos == 0) { + if (iocb->ki_pos == 0) { m->index = 0; m->count = 0; } - /* Don't assume *ppos is where we left it */ - if (unlikely(*ppos != m->read_pos)) { - while ((err = traverse(m, *ppos)) == -EAGAIN) + /* Don't assume ki_pos is where we left it */ + if (unlikely(iocb->ki_pos != m->read_pos)) { + while ((err = traverse(m, iocb->ki_pos)) == -EAGAIN) ; if (err) { /* With prejudice... */ @@ -174,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) m->count = 0; goto Done; } else { - m->read_pos = *ppos; + m->read_pos = iocb->ki_pos; } } @@ -187,13 +209,11 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) /* if not empty - flush it first */ if (m->count) { n = min(m->count, size); - err = copy_to_user(buf, m->buf + m->from, n); - if (err) + if (copy_to_iter(m->buf + m->from, n, iter) != n) goto Efault; m->count -= n; m->from += n; size -= n; - buf += n; copied += n; if (!size) goto Done; @@ -254,8 +274,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) } m->op->stop(m, p); n = min(m->count, size); - err = copy_to_user(buf, m->buf, n); - if (err) + if (copy_to_iter(m->buf, n, iter) != n) goto Efault; copied += n; m->count -= n; @@ -264,7 +283,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) if (!copied) copied = err; else { - *ppos += copied; + iocb->ki_pos += copied; m->read_pos += copied; } mutex_unlock(&m->lock); @@ -276,7 +295,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) err = -EFAULT; goto Done; } -EXPORT_SYMBOL(seq_read); +EXPORT_SYMBOL(seq_read_iter); /** * seq_lseek - ->llseek() method for sequential files. diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index 813614d4b71fbc..b83b3ae3c877f3 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -107,6 +107,7 @@ void seq_pad(struct seq_file *m, char c); char *mangle_path(char *s, const char *p, const char *esc); int seq_open(struct file *, const struct seq_operations *); ssize_t seq_read(struct file *, char __user *, size_t, loff_t *); +ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter); loff_t seq_lseek(struct file *, loff_t, int); int seq_release(struct inode *, struct file *); int seq_write(struct seq_file *seq, const void *data, size_t len); From patchwork Tue Jul 7 17:47:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649475 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 D8308912 for ; Tue, 7 Jul 2020 17:49:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BDE862073E for ; Tue, 7 Jul 2020 17:49: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="VnhHfBod" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728711AbgGGRs6 (ORCPT ); Tue, 7 Jul 2020 13:48:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728661AbgGGRse (ORCPT ); Tue, 7 Jul 2020 13:48:34 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45A5CC061755; Tue, 7 Jul 2020 10:48:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=5UdxRZXTOhVUtxH21tqgR494MAXE+7aifhN/sMLl3wo=; b=VnhHfBod7FY+/0HQLHZOiY+Dsc waw2TdL0ExD9660hDrFgJc9uRgTQLe07nQZrOQfHpupePKLqoGOLfSakm0VrB8ootaEVdH80w6VwG cIu9Sp985pOpd8JAwDEID1xnj9HoWxyhHmFGgeLJhlYfAVV18za403POJvLs57cXtiv7uGaruDp6m T0rWal21LEl68ttv09A5vHzfn/1yoEjG1f/5UXLO5usD098OtPZK0fTO40EUum9w89s6QjekmS2u1 UCMnffQx4ONN4lXhdhvvCd7Z34aMmEvVWXfbwzSHggxKi8QrGj//dkLlIzTETWEpm4b7p0P0Gpi/y NSY8+y8w==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhi-0003Kv-IY; Tue, 07 Jul 2020 17:48:27 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 16/23] proc: remove a level of indentation in proc_get_inode Date: Tue, 7 Jul 2020 19:47:54 +0200 Message-Id: <20200707174801.4162712-17-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Just return early on inode allocation failure. Signed-off-by: Christoph Hellwig --- fs/proc/inode.c | 72 +++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/fs/proc/inode.c b/fs/proc/inode.c index 28d6105e908e4c..016b1302cbabc0 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -619,42 +619,44 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de) { struct inode *inode = new_inode(sb); - if (inode) { - inode->i_ino = de->low_ino; - inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); - PROC_I(inode)->pde = de; - - if (is_empty_pde(de)) { - make_empty_dir_inode(inode); - return inode; - } - if (de->mode) { - inode->i_mode = de->mode; - inode->i_uid = de->uid; - inode->i_gid = de->gid; - } - if (de->size) - inode->i_size = de->size; - if (de->nlink) - set_nlink(inode, de->nlink); - - if (S_ISREG(inode->i_mode)) { - inode->i_op = de->proc_iops; - inode->i_fop = &proc_reg_file_ops; + if (!inode) { + pde_put(de); + return NULL; + } + + inode->i_ino = de->low_ino; + inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); + PROC_I(inode)->pde = de; + if (is_empty_pde(de)) { + make_empty_dir_inode(inode); + return inode; + } + + if (de->mode) { + inode->i_mode = de->mode; + inode->i_uid = de->uid; + inode->i_gid = de->gid; + } + if (de->size) + inode->i_size = de->size; + if (de->nlink) + set_nlink(inode, de->nlink); + + if (S_ISREG(inode->i_mode)) { + inode->i_op = de->proc_iops; + inode->i_fop = &proc_reg_file_ops; #ifdef CONFIG_COMPAT - if (!de->proc_ops->proc_compat_ioctl) { - inode->i_fop = &proc_reg_file_ops_no_compat; - } + if (!de->proc_ops->proc_compat_ioctl) + inode->i_fop = &proc_reg_file_ops_no_compat; #endif - } else if (S_ISDIR(inode->i_mode)) { - inode->i_op = de->proc_iops; - inode->i_fop = de->proc_dir_ops; - } else if (S_ISLNK(inode->i_mode)) { - inode->i_op = de->proc_iops; - inode->i_fop = NULL; - } else - BUG(); - } else - pde_put(de); + } else if (S_ISDIR(inode->i_mode)) { + inode->i_op = de->proc_iops; + inode->i_fop = de->proc_dir_ops; + } else if (S_ISLNK(inode->i_mode)) { + inode->i_op = de->proc_iops; + inode->i_fop = NULL; + } else { + BUG(); + } return inode; } From patchwork Tue Jul 7 17:47:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649469 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 22CB813BD for ; Tue, 7 Jul 2020 17:48:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B259207DF for ; Tue, 7 Jul 2020 17:48:41 +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="lCeLmb3s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728706AbgGGRsi (ORCPT ); Tue, 7 Jul 2020 13:48:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728677AbgGGRsg (ORCPT ); Tue, 7 Jul 2020 13:48:36 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33535C061755; Tue, 7 Jul 2020 10:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=NA8lGOC4BC4BRu8ev38I4oygB9glKOvDb9c92iDVn1E=; b=lCeLmb3suH99pmI4X62B5drqwA skczlsEs84laHHAjzSZxxIU1lj5lkgaZnsQufQV5oNCs7YmlGFZSbWS/9NXYYCc7i+Y1TdwMyKHxd DAJ4gI9vYovb+nxyuo1L5n8DNSlkJdQCYuimkIe3Tukah4QcodtAywbWWrd7rp1wOezvaWKDeMVSB fSGQoGUvGk0kPFIusTE0bHnu7+v7xSkfEHzTVOL7FKcE/vHTSTI9ogb1z9f4uq7BIsq/aNDV4PrSg dVxeQEI4W4gKTGUzZQ2HPklSAIeK8I3UfZBX5qkkpX7Dr8LUGXei+nIEdfVH5L+JTnfwQIg1tXViv 9NIbfKwA==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhk-0003LU-0Y; Tue, 07 Jul 2020 17:48:28 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 17/23] proc: cleanup the compat vs no compat file ops Date: Tue, 7 Jul 2020 19:47:55 +0200 Message-Id: <20200707174801.4162712-18-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Instead of providing a special no-compat version provide a special compat version for operations with ->compat_ioctl. Signed-off-by: Christoph Hellwig --- fs/proc/inode.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/proc/inode.c b/fs/proc/inode.c index 016b1302cbabc0..93dd2045737504 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -572,9 +572,6 @@ static const struct file_operations proc_reg_file_ops = { .write = proc_reg_write, .poll = proc_reg_poll, .unlocked_ioctl = proc_reg_unlocked_ioctl, -#ifdef CONFIG_COMPAT - .compat_ioctl = proc_reg_compat_ioctl, -#endif .mmap = proc_reg_mmap, .get_unmapped_area = proc_reg_get_unmapped_area, .open = proc_reg_open, @@ -582,12 +579,13 @@ static const struct file_operations proc_reg_file_ops = { }; #ifdef CONFIG_COMPAT -static const struct file_operations proc_reg_file_ops_no_compat = { +static const struct file_operations proc_reg_file_ops_compat = { .llseek = proc_reg_llseek, .read = proc_reg_read, .write = proc_reg_write, .poll = proc_reg_poll, .unlocked_ioctl = proc_reg_unlocked_ioctl, + .compat_ioctl = proc_reg_compat_ioctl, .mmap = proc_reg_mmap, .get_unmapped_area = proc_reg_get_unmapped_area, .open = proc_reg_open, @@ -646,8 +644,8 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de) inode->i_op = de->proc_iops; inode->i_fop = &proc_reg_file_ops; #ifdef CONFIG_COMPAT - if (!de->proc_ops->proc_compat_ioctl) - inode->i_fop = &proc_reg_file_ops_no_compat; + if (de->proc_ops->proc_compat_ioctl) + inode->i_fop = &proc_reg_file_ops_compat; #endif } else if (S_ISDIR(inode->i_mode)) { inode->i_op = de->proc_iops; From patchwork Tue Jul 7 17:47:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649473 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 23345912 for ; Tue, 7 Jul 2020 17:48:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0ABD32075B for ; Tue, 7 Jul 2020 17:48: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="lVbi0VKH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728693AbgGGRsh (ORCPT ); Tue, 7 Jul 2020 13:48:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728688AbgGGRsh (ORCPT ); Tue, 7 Jul 2020 13:48:37 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7443C061755; Tue, 7 Jul 2020 10:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=EnavTkgxyxgyyAtAribcKqVL9aBK4q+saHxSi5sRM4k=; b=lVbi0VKHr3xM2aqKT0GJByTECH UOBgMbcnBwcyRtMA+Wm2nyda/T5ij03HR5gomWIbj4jlPkhjOaRmFahHja+A59HgzRD+Z+tttb5p1 PXAKQ6RwngSMUuLzRvTWq5JYxaOEK5Talu7PQhO4Jx23WW6b1li8pPXgXXuMobmQYcoqibvegiQsz 3zV99vFFyfxLcam10qK36w/WATF105PWlc/2VkLNmtjxpRNaYCkwgJx6jIZrxiRgzmGZZVbR4GHs+ XzgZIlEPzHwuHkx4O+z/r2W/6A6eFMOX3iWJy2mLiNcMQ68AVjM+vnZv50zwvz+oF3KQIuZpCJKox D1c4lyTg==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhl-0003M6-UG; Tue, 07 Jul 2020 17:48:30 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 18/23] proc: add a read_iter method to proc proc_ops Date: Tue, 7 Jul 2020 19:47:56 +0200 Message-Id: <20200707174801.4162712-19-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This will allow proc files to implement iter read semantics. Signed-off-by: Christoph Hellwig --- fs/proc/inode.c | 53 ++++++++++++++++++++++++++++++++++++++--- include/linux/proc_fs.h | 1 + 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/fs/proc/inode.c b/fs/proc/inode.c index 93dd2045737504..58c075e2a452d6 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -297,6 +297,21 @@ static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence) return rv; } +static ssize_t proc_reg_read_iter(struct kiocb *iocb, struct iov_iter *iter) +{ + struct proc_dir_entry *pde = PDE(file_inode(iocb->ki_filp)); + ssize_t ret; + + if (pde_is_permanent(pde)) + return pde->proc_ops->proc_read_iter(iocb, iter); + + if (!use_pde(pde)) + return -EIO; + ret = pde->proc_ops->proc_read_iter(iocb, iter); + unuse_pde(pde); + return ret; +} + static ssize_t pde_read(struct proc_dir_entry *pde, struct file *file, char __user *buf, size_t count, loff_t *ppos) { typeof_member(struct proc_ops, proc_read) read; @@ -578,6 +593,18 @@ static const struct file_operations proc_reg_file_ops = { .release = proc_reg_release, }; +static const struct file_operations proc_iter_file_ops = { + .llseek = proc_reg_llseek, + .read_iter = proc_reg_read_iter, + .write = proc_reg_write, + .poll = proc_reg_poll, + .unlocked_ioctl = proc_reg_unlocked_ioctl, + .mmap = proc_reg_mmap, + .get_unmapped_area = proc_reg_get_unmapped_area, + .open = proc_reg_open, + .release = proc_reg_release, +}; + #ifdef CONFIG_COMPAT static const struct file_operations proc_reg_file_ops_compat = { .llseek = proc_reg_llseek, @@ -591,6 +618,19 @@ static const struct file_operations proc_reg_file_ops_compat = { .open = proc_reg_open, .release = proc_reg_release, }; + +static const struct file_operations proc_iter_file_ops_compat = { + .llseek = proc_reg_llseek, + .read_iter = proc_reg_read_iter, + .write = proc_reg_write, + .poll = proc_reg_poll, + .unlocked_ioctl = proc_reg_unlocked_ioctl, + .compat_ioctl = proc_reg_compat_ioctl, + .mmap = proc_reg_mmap, + .get_unmapped_area = proc_reg_get_unmapped_area, + .open = proc_reg_open, + .release = proc_reg_release, +}; #endif static void proc_put_link(void *p) @@ -642,10 +682,17 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de) if (S_ISREG(inode->i_mode)) { inode->i_op = de->proc_iops; - inode->i_fop = &proc_reg_file_ops; + if (de->proc_ops->proc_read_iter) + inode->i_fop = &proc_iter_file_ops; + else + inode->i_fop = &proc_reg_file_ops; #ifdef CONFIG_COMPAT - if (de->proc_ops->proc_compat_ioctl) - inode->i_fop = &proc_reg_file_ops_compat; + if (de->proc_ops->proc_compat_ioctl) { + if (de->proc_ops->proc_read_iter) + inode->i_fop = &proc_iter_file_ops_compat; + else + inode->i_fop = &proc_reg_file_ops_compat; + } #endif } else if (S_ISDIR(inode->i_mode)) { inode->i_op = de->proc_iops; diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h index d1eed1b4365172..97b3f5f06db9d8 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h @@ -30,6 +30,7 @@ struct proc_ops { unsigned int proc_flags; int (*proc_open)(struct inode *, struct file *); ssize_t (*proc_read)(struct file *, char __user *, size_t, loff_t *); + ssize_t (*proc_read_iter)(struct kiocb *, struct iov_iter *); ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *); loff_t (*proc_lseek)(struct file *, loff_t, int); int (*proc_release)(struct inode *, struct file *); From patchwork Tue Jul 7 17:47:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649471 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 47FEC912 for ; Tue, 7 Jul 2020 17:48:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B4F002075B for ; Tue, 7 Jul 2020 17:48:51 +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="YE9wsut0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728721AbgGGRsn (ORCPT ); Tue, 7 Jul 2020 13:48:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728711AbgGGRsl (ORCPT ); Tue, 7 Jul 2020 13:48:41 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EE17C08C5DC; Tue, 7 Jul 2020 10:48:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=SBnmWcIvkgH41xrAa+D50IWWk6VENwdtw9aK4PGxf2k=; b=YE9wsut0ndRLWz4P2kXZwSn9t9 7/bnldFB+rQ8lM90/IP/iHlOCddFTusiqajP0LSpM3cvxYEySjnBoH8oD+i2d/S/0/kvhaFwFSMUL pYkJXkLEkQB95RYYRF4F9GXPvY10DQx8+IoIKCDR06hQRnGe4hyeRYuOh7IRmz19OSMhTGHtxADx4 YOXut41FM/+Oi7d0lgtckdRc+N8S2YxwZ7DkcqIuFHqLcHRU7kmJOSL6rOSTRRRazO5hy3mzVYC7/ YdGCIvW2gSE0YLAZZLU8FjoYevuF0G77b2DcXbhkrrnc/Qujc1qNSjm92dR5UZUpabSCYjObpzmDW q6rLBb7A==; Received: from [2001:4bb8:18c:3b3b:a49f:8154:a2b7:8b6c] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrhn-0003MV-MS; Tue, 07 Jul 2020 17:48:32 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 19/23] proc: switch over direct seq_read method calls to seq_read_iter Date: Tue, 7 Jul 2020 19:47:57 +0200 Message-Id: <20200707174801.4162712-20-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Switch over all instances used directly as methods using these sed expressions: sed -i -e 's/\.proc_read\(\s*=\s*\)seq_read/\.proc_read_iter\1seq_read_iter/g' Signed-off-by: Christoph Hellwig --- arch/alpha/kernel/srm_env.c | 2 +- arch/arm/mm/alignment.c | 2 +- arch/powerpc/kernel/rtas-proc.c | 10 +++++----- arch/powerpc/mm/numa.c | 2 +- arch/powerpc/platforms/pseries/lpar.c | 4 ++-- arch/powerpc/platforms/pseries/lparcfg.c | 2 +- arch/sh/mm/alignment.c | 2 +- arch/sparc/kernel/led.c | 2 +- arch/um/kernel/exitcode.c | 2 +- arch/um/kernel/process.c | 2 +- arch/x86/kernel/cpu/mtrr/if.c | 2 +- arch/x86/platform/uv/tlb_uv.c | 2 +- drivers/acpi/battery.c | 2 +- drivers/acpi/proc.c | 2 +- drivers/hwmon/dell-smm-hwmon.c | 2 +- drivers/ide/ide-proc.c | 2 +- drivers/input/input.c | 4 ++-- drivers/macintosh/via-pmu.c | 2 +- drivers/md/md.c | 2 +- drivers/misc/sgi-gru/gruprocfs.c | 6 +++--- drivers/net/wireless/intel/ipw2x00/libipw_module.c | 2 +- .../net/wireless/intersil/hostap/hostap_download.c | 2 +- drivers/parisc/led.c | 2 +- drivers/platform/x86/thinkpad_acpi.c | 2 +- drivers/platform/x86/toshiba_acpi.c | 8 ++++---- drivers/pnp/pnpbios/proc.c | 2 +- drivers/s390/block/dasd_proc.c | 2 +- drivers/s390/cio/blacklist.c | 2 +- drivers/scsi/scsi_devinfo.c | 2 +- drivers/scsi/scsi_proc.c | 4 ++-- drivers/scsi/sg.c | 4 ++-- .../staging/rtl8192u/ieee80211/ieee80211_module.c | 2 +- drivers/usb/gadget/function/rndis.c | 2 +- drivers/video/fbdev/via/viafbdev.c | 14 +++++++------- fs/cifs/cifs_debug.c | 14 +++++++------- fs/cifs/dfs_cache.c | 2 +- fs/fscache/object-list.c | 2 +- fs/jbd2/journal.c | 2 +- fs/jfs/jfs_debug.c | 2 +- fs/nfsd/nfsctl.c | 2 +- fs/nfsd/stats.c | 2 +- fs/proc/cpuinfo.c | 2 +- fs/proc/generic.c | 4 ++-- fs/proc/proc_net.c | 4 ++-- fs/proc/stat.c | 2 +- include/linux/seq_file.h | 2 +- ipc/util.c | 2 +- kernel/irq/proc.c | 6 +++--- kernel/kallsyms.c | 2 +- kernel/latencytop.c | 2 +- kernel/locking/lockdep_proc.c | 2 +- kernel/module.c | 2 +- kernel/profile.c | 2 +- kernel/sched/psi.c | 6 +++--- lib/dynamic_debug.c | 2 +- mm/slab_common.c | 2 +- mm/swapfile.c | 2 +- net/atm/mpoa_proc.c | 2 +- net/core/pktgen.c | 6 +++--- net/ipv4/netfilter/ipt_CLUSTERIP.c | 2 +- net/ipv4/route.c | 4 ++-- net/netfilter/xt_recent.c | 2 +- net/sunrpc/cache.c | 2 +- net/sunrpc/stats.c | 2 +- sound/core/info.c | 2 +- 65 files changed, 99 insertions(+), 99 deletions(-) diff --git a/arch/alpha/kernel/srm_env.c b/arch/alpha/kernel/srm_env.c index 528d2be5818298..8ad9c100ef7612 100644 --- a/arch/alpha/kernel/srm_env.c +++ b/arch/alpha/kernel/srm_env.c @@ -121,7 +121,7 @@ static ssize_t srm_env_proc_write(struct file *file, const char __user *buffer, static const struct proc_ops srm_env_proc_ops = { .proc_open = srm_env_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = srm_env_proc_write, diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c index 81a627e6e1c599..412cab88402acd 100644 --- a/arch/arm/mm/alignment.c +++ b/arch/arm/mm/alignment.c @@ -164,7 +164,7 @@ static ssize_t alignment_proc_write(struct file *file, const char __user *buffer static const struct proc_ops alignment_proc_ops = { .proc_open = alignment_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = alignment_proc_write, diff --git a/arch/powerpc/kernel/rtas-proc.c b/arch/powerpc/kernel/rtas-proc.c index 2d33f342a29307..3aace56aacc1df 100644 --- a/arch/powerpc/kernel/rtas-proc.c +++ b/arch/powerpc/kernel/rtas-proc.c @@ -161,7 +161,7 @@ static int poweron_open(struct inode *inode, struct file *file) static const struct proc_ops ppc_rtas_poweron_proc_ops = { .proc_open = poweron_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = ppc_rtas_poweron_write, .proc_release = single_release, @@ -174,7 +174,7 @@ static int progress_open(struct inode *inode, struct file *file) static const struct proc_ops ppc_rtas_progress_proc_ops = { .proc_open = progress_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = ppc_rtas_progress_write, .proc_release = single_release, @@ -187,7 +187,7 @@ static int clock_open(struct inode *inode, struct file *file) static const struct proc_ops ppc_rtas_clock_proc_ops = { .proc_open = clock_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = ppc_rtas_clock_write, .proc_release = single_release, @@ -200,7 +200,7 @@ static int tone_freq_open(struct inode *inode, struct file *file) static const struct proc_ops ppc_rtas_tone_freq_proc_ops = { .proc_open = tone_freq_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = ppc_rtas_tone_freq_write, .proc_release = single_release, @@ -213,7 +213,7 @@ static int tone_volume_open(struct inode *inode, struct file *file) static const struct proc_ops ppc_rtas_tone_volume_proc_ops = { .proc_open = tone_volume_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = ppc_rtas_tone_volume_write, .proc_release = single_release, diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c index 9fcf2d19583004..2f3aef6c0b513b 100644 --- a/arch/powerpc/mm/numa.c +++ b/arch/powerpc/mm/numa.c @@ -1672,7 +1672,7 @@ static ssize_t topology_write(struct file *file, const char __user *buf, } static const struct proc_ops topology_proc_ops = { - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = topology_write, .proc_open = topology_open, .proc_release = single_release, diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c index fd26f3d21d7b4b..2b13a67d60e206 100644 --- a/arch/powerpc/platforms/pseries/lpar.c +++ b/arch/powerpc/platforms/pseries/lpar.c @@ -584,7 +584,7 @@ static int vcpudispatch_stats_open(struct inode *inode, struct file *file) static const struct proc_ops vcpudispatch_stats_proc_ops = { .proc_open = vcpudispatch_stats_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = vcpudispatch_stats_write, .proc_lseek = seq_lseek, .proc_release = single_release, @@ -628,7 +628,7 @@ static int vcpudispatch_stats_freq_open(struct inode *inode, struct file *file) static const struct proc_ops vcpudispatch_stats_freq_proc_ops = { .proc_open = vcpudispatch_stats_freq_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = vcpudispatch_stats_freq_write, .proc_lseek = seq_lseek, .proc_release = single_release, diff --git a/arch/powerpc/platforms/pseries/lparcfg.c b/arch/powerpc/platforms/pseries/lparcfg.c index b8d28ab881789d..35eb0e4b8fd31a 100644 --- a/arch/powerpc/platforms/pseries/lparcfg.c +++ b/arch/powerpc/platforms/pseries/lparcfg.c @@ -699,7 +699,7 @@ static int lparcfg_open(struct inode *inode, struct file *file) } static const struct proc_ops lparcfg_proc_ops = { - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = lparcfg_write, .proc_open = lparcfg_open, .proc_release = single_release, diff --git a/arch/sh/mm/alignment.c b/arch/sh/mm/alignment.c index fb517b82a87b10..66115241ad93a4 100644 --- a/arch/sh/mm/alignment.c +++ b/arch/sh/mm/alignment.c @@ -154,7 +154,7 @@ static ssize_t alignment_proc_write(struct file *file, static const struct proc_ops alignment_proc_ops = { .proc_open = alignment_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = alignment_proc_write, diff --git a/arch/sparc/kernel/led.c b/arch/sparc/kernel/led.c index bd48575172c323..a0b893d216c443 100644 --- a/arch/sparc/kernel/led.c +++ b/arch/sparc/kernel/led.c @@ -106,7 +106,7 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer, static const struct proc_ops led_proc_ops = { .proc_open = led_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = led_proc_write, diff --git a/arch/um/kernel/exitcode.c b/arch/um/kernel/exitcode.c index 43edc2aa57e4fb..95184d271a47cf 100644 --- a/arch/um/kernel/exitcode.c +++ b/arch/um/kernel/exitcode.c @@ -57,7 +57,7 @@ static ssize_t exitcode_proc_write(struct file *file, static const struct proc_ops exitcode_proc_ops = { .proc_open = exitcode_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = exitcode_proc_write, diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c index e3a2cf92a3738b..f3e4bd48f6d5b6 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -312,7 +312,7 @@ static ssize_t sysemu_proc_write(struct file *file, const char __user *buf, static const struct proc_ops sysemu_proc_ops = { .proc_open = sysemu_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = sysemu_proc_write, diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c index a5c506f6da7fa1..f5743b5ecaf232 100644 --- a/arch/x86/kernel/cpu/mtrr/if.c +++ b/arch/x86/kernel/cpu/mtrr/if.c @@ -398,7 +398,7 @@ static int mtrr_open(struct inode *inode, struct file *file) static const struct proc_ops mtrr_proc_ops = { .proc_open = mtrr_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = mtrr_write, .proc_ioctl = mtrr_ioctl, diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c index 0ac96ca304c7b5..cd6ee86283e6e1 100644 --- a/arch/x86/platform/uv/tlb_uv.c +++ b/arch/x86/platform/uv/tlb_uv.c @@ -1670,7 +1670,7 @@ static int tunables_open(struct inode *inode, struct file *file) static const struct proc_ops uv_ptc_proc_ops = { .proc_open = ptc_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = ptc_proc_write, .proc_lseek = seq_lseek, .proc_release = seq_release, diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 366c389175d844..c8e5972ad6c952 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -1204,7 +1204,7 @@ static int acpi_battery_alarm_proc_open(struct inode *inode, struct file *file) static const struct proc_ops acpi_battery_alarm_proc_ops = { .proc_open = acpi_battery_alarm_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = acpi_battery_write_alarm, .proc_lseek = seq_lseek, .proc_release = single_release, diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c index 7892980b3ce4d3..774da498c77265 100644 --- a/drivers/acpi/proc.c +++ b/drivers/acpi/proc.c @@ -136,7 +136,7 @@ acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file) static const struct proc_ops acpi_system_wakeup_device_proc_ops = { .proc_open = acpi_system_wakeup_device_open_fs, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = acpi_system_write_wakeup_device, .proc_lseek = seq_lseek, .proc_release = single_release, diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 16be012a95ed84..29ac388429620f 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -597,7 +597,7 @@ static int i8k_open_fs(struct inode *inode, struct file *file) static const struct proc_ops i8k_proc_ops = { .proc_open = i8k_open_fs, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_ioctl = i8k_ioctl, diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c index 8ea282a3a19f0d..a0b56737152fb5 100644 --- a/drivers/ide/ide-proc.c +++ b/drivers/ide/ide-proc.c @@ -383,7 +383,7 @@ static ssize_t ide_settings_proc_write(struct file *file, const char __user *buf static const struct proc_ops ide_settings_proc_ops = { .proc_open = ide_settings_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = ide_settings_proc_write, diff --git a/drivers/input/input.c b/drivers/input/input.c index 3cfd2c18eebd9d..c8180d7f92d576 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -1220,7 +1220,7 @@ static int input_proc_devices_open(struct inode *inode, struct file *file) static const struct proc_ops input_devices_proc_ops = { .proc_open = input_proc_devices_open, .proc_poll = input_proc_devices_poll, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release, }; @@ -1282,7 +1282,7 @@ static int input_proc_handlers_open(struct inode *inode, struct file *file) static const struct proc_ops input_handlers_proc_ops = { .proc_open = input_proc_handlers_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release, }; diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c index 73e6ae88fafd4e..9415eddb419402 100644 --- a/drivers/macintosh/via-pmu.c +++ b/drivers/macintosh/via-pmu.c @@ -973,7 +973,7 @@ static ssize_t pmu_options_proc_write(struct file *file, static const struct proc_ops pmu_options_proc_ops = { .proc_open = pmu_options_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = pmu_options_proc_write, diff --git a/drivers/md/md.c b/drivers/md/md.c index f567f536b529bd..0bae6c1523cec6 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -8301,7 +8301,7 @@ static __poll_t mdstat_poll(struct file *filp, poll_table *wait) static const struct proc_ops mdstat_proc_ops = { .proc_open = md_seq_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release, .proc_poll = mdstat_poll, diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c index 97b8b38ab47dfd..fc9498ec797762 100644 --- a/drivers/misc/sgi-gru/gruprocfs.c +++ b/drivers/misc/sgi-gru/gruprocfs.c @@ -257,7 +257,7 @@ static int options_open(struct inode *inode, struct file *file) /* *INDENT-OFF* */ static const struct proc_ops statistics_proc_ops = { .proc_open = statistics_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = statistics_write, .proc_lseek = seq_lseek, .proc_release = single_release, @@ -265,7 +265,7 @@ static const struct proc_ops statistics_proc_ops = { static const struct proc_ops mcs_statistics_proc_ops = { .proc_open = mcs_statistics_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = mcs_statistics_write, .proc_lseek = seq_lseek, .proc_release = single_release, @@ -273,7 +273,7 @@ static const struct proc_ops mcs_statistics_proc_ops = { static const struct proc_ops options_proc_ops = { .proc_open = options_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = options_write, .proc_lseek = seq_lseek, .proc_release = single_release, diff --git a/drivers/net/wireless/intel/ipw2x00/libipw_module.c b/drivers/net/wireless/intel/ipw2x00/libipw_module.c index 43bab92a4148f2..1929db6921d7e0 100644 --- a/drivers/net/wireless/intel/ipw2x00/libipw_module.c +++ b/drivers/net/wireless/intel/ipw2x00/libipw_module.c @@ -242,7 +242,7 @@ static ssize_t debug_level_proc_write(struct file *file, static const struct proc_ops debug_level_proc_ops = { .proc_open = debug_level_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = debug_level_proc_write, diff --git a/drivers/net/wireless/intersil/hostap/hostap_download.c b/drivers/net/wireless/intersil/hostap/hostap_download.c index 7c6a5a6d1d45d8..8980fd57b2eda4 100644 --- a/drivers/net/wireless/intersil/hostap/hostap_download.c +++ b/drivers/net/wireless/intersil/hostap/hostap_download.c @@ -234,7 +234,7 @@ static int prism2_download_aux_dump_proc_open(struct inode *inode, struct file * static const struct proc_ops prism2_download_aux_dump_proc_ops = { .proc_open = prism2_download_aux_dump_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release_private, }; diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c index 36c6613f7a36b7..d75df3977926b3 100644 --- a/drivers/parisc/led.c +++ b/drivers/parisc/led.c @@ -232,7 +232,7 @@ static ssize_t led_proc_write(struct file *file, const char __user *buf, static const struct proc_ops led_proc_ops = { .proc_open = led_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = led_proc_write, diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index ff7f0a4f247563..f571d6254e7c34 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -901,7 +901,7 @@ static ssize_t dispatch_proc_write(struct file *file, static const struct proc_ops dispatch_proc_ops = { .proc_open = dispatch_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = dispatch_proc_write, diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 1ddab5a6dead6d..770477bb407d49 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -1428,7 +1428,7 @@ static ssize_t lcd_proc_write(struct file *file, const char __user *buf, static const struct proc_ops lcd_proc_ops = { .proc_open = lcd_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = lcd_proc_write, @@ -1534,7 +1534,7 @@ static ssize_t video_proc_write(struct file *file, const char __user *buf, static const struct proc_ops video_proc_ops = { .proc_open = video_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = video_proc_write, @@ -1611,7 +1611,7 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf, static const struct proc_ops fan_proc_ops = { .proc_open = fan_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = fan_proc_write, @@ -1655,7 +1655,7 @@ static ssize_t keys_proc_write(struct file *file, const char __user *buf, static const struct proc_ops keys_proc_ops = { .proc_open = keys_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = keys_proc_write, diff --git a/drivers/pnp/pnpbios/proc.c b/drivers/pnp/pnpbios/proc.c index a806830e3a407f..10d0181c4430ab 100644 --- a/drivers/pnp/pnpbios/proc.c +++ b/drivers/pnp/pnpbios/proc.c @@ -212,7 +212,7 @@ static ssize_t pnpbios_proc_write(struct file *file, const char __user *buf, static const struct proc_ops pnpbios_proc_ops = { .proc_open = pnpbios_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = pnpbios_proc_write, diff --git a/drivers/s390/block/dasd_proc.c b/drivers/s390/block/dasd_proc.c index 62a859ea67f893..278f0dccc85ff1 100644 --- a/drivers/s390/block/dasd_proc.c +++ b/drivers/s390/block/dasd_proc.c @@ -322,7 +322,7 @@ static ssize_t dasd_stats_proc_write(struct file *file, static const struct proc_ops dasd_stats_proc_ops = { .proc_open = dasd_stats_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = dasd_stats_proc_write, diff --git a/drivers/s390/cio/blacklist.c b/drivers/s390/cio/blacklist.c index 4dd2eb63485699..05f58c453b060c 100644 --- a/drivers/s390/cio/blacklist.c +++ b/drivers/s390/cio/blacklist.c @@ -401,7 +401,7 @@ cio_ignore_proc_open(struct inode *inode, struct file *file) static const struct proc_ops cio_ignore_proc_ops = { .proc_open = cio_ignore_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release_private, .proc_write = cio_ignore_write, diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c index eed31021e7885c..87fb440ddfc5d8 100644 --- a/drivers/scsi/scsi_devinfo.c +++ b/drivers/scsi/scsi_devinfo.c @@ -738,7 +738,7 @@ static ssize_t proc_scsi_devinfo_write(struct file *file, static const struct proc_ops scsi_devinfo_proc_ops = { .proc_open = proc_scsi_devinfo_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = proc_scsi_devinfo_write, .proc_lseek = seq_lseek, .proc_release = seq_release, diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c index d6982d3557396b..81601a9e79c4db 100644 --- a/drivers/scsi/scsi_proc.c +++ b/drivers/scsi/scsi_proc.c @@ -86,7 +86,7 @@ static int proc_scsi_host_open(struct inode *inode, struct file *file) static const struct proc_ops proc_scsi_ops = { .proc_open = proc_scsi_host_open, .proc_release = single_release, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = proc_scsi_host_write }; @@ -438,7 +438,7 @@ static int proc_scsi_open(struct inode *inode, struct file *file) static const struct proc_ops scsi_scsi_proc_ops = { .proc_open = proc_scsi_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = proc_scsi_write, .proc_lseek = seq_lseek, .proc_release = seq_release, diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 20472aaaf630a4..c5d482190066bc 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -2328,7 +2328,7 @@ static ssize_t sg_proc_write_adio(struct file *filp, const char __user *buffer, size_t count, loff_t *off); static const struct proc_ops adio_proc_ops = { .proc_open = sg_proc_single_open_adio, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = sg_proc_write_adio, .proc_release = single_release, @@ -2339,7 +2339,7 @@ static ssize_t sg_proc_write_dressz(struct file *filp, const char __user *buffer, size_t count, loff_t *off); static const struct proc_ops dressz_proc_ops = { .proc_open = sg_proc_single_open_dressz, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = sg_proc_write_dressz, .proc_release = single_release, diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c index a5a1b14f5a40c5..e198779db6fc2e 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c @@ -265,7 +265,7 @@ static int open_debug_level(struct inode *inode, struct file *file) static const struct proc_ops debug_level_proc_ops = { .proc_open = open_debug_level, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = write_debug_level, .proc_release = single_release, diff --git a/drivers/usb/gadget/function/rndis.c b/drivers/usb/gadget/function/rndis.c index 64de9f1b874c55..562781b95101d3 100644 --- a/drivers/usb/gadget/function/rndis.c +++ b/drivers/usb/gadget/function/rndis.c @@ -1166,7 +1166,7 @@ static int rndis_proc_open(struct inode *inode, struct file *file) static const struct proc_ops rndis_proc_ops = { .proc_open = rndis_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = rndis_proc_write, diff --git a/drivers/video/fbdev/via/viafbdev.c b/drivers/video/fbdev/via/viafbdev.c index 22deb340a0484f..6cf91191de7f15 100644 --- a/drivers/video/fbdev/via/viafbdev.c +++ b/drivers/video/fbdev/via/viafbdev.c @@ -1175,7 +1175,7 @@ static ssize_t viafb_dvp0_proc_write(struct file *file, static const struct proc_ops viafb_dvp0_proc_ops = { .proc_open = viafb_dvp0_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = viafb_dvp0_proc_write, @@ -1239,7 +1239,7 @@ static ssize_t viafb_dvp1_proc_write(struct file *file, static const struct proc_ops viafb_dvp1_proc_ops = { .proc_open = viafb_dvp1_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = viafb_dvp1_proc_write, @@ -1273,7 +1273,7 @@ static ssize_t viafb_dfph_proc_write(struct file *file, static const struct proc_ops viafb_dfph_proc_ops = { .proc_open = viafb_dfph_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = viafb_dfph_proc_write, @@ -1307,7 +1307,7 @@ static ssize_t viafb_dfpl_proc_write(struct file *file, static const struct proc_ops viafb_dfpl_proc_ops = { .proc_open = viafb_dfpl_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = viafb_dfpl_proc_write, @@ -1442,7 +1442,7 @@ static ssize_t viafb_vt1636_proc_write(struct file *file, static const struct proc_ops viafb_vt1636_proc_ops = { .proc_open = viafb_vt1636_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = viafb_vt1636_proc_write, @@ -1519,7 +1519,7 @@ static ssize_t viafb_iga1_odev_proc_write(struct file *file, static const struct proc_ops viafb_iga1_odev_proc_ops = { .proc_open = viafb_iga1_odev_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = viafb_iga1_odev_proc_write, @@ -1558,7 +1558,7 @@ static ssize_t viafb_iga2_odev_proc_write(struct file *file, static const struct proc_ops viafb_iga2_odev_proc_ops = { .proc_open = viafb_iga2_odev_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = viafb_iga2_odev_proc_write, diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c index 53588d7517b4d0..877763996fa987 100644 --- a/fs/cifs/cifs_debug.c +++ b/fs/cifs/cifs_debug.c @@ -619,7 +619,7 @@ static int cifs_stats_proc_open(struct inode *inode, struct file *file) static const struct proc_ops cifs_stats_proc_ops = { .proc_open = cifs_stats_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = cifs_stats_proc_write, @@ -648,7 +648,7 @@ static int name##_open(struct inode *inode, struct file *file) \ \ static const struct proc_ops cifs_##name##_proc_fops = { \ .proc_open = name##_open, \ - .proc_read = seq_read, \ + .proc_read_iter = seq_read_iter, \ .proc_lseek = seq_lseek, \ .proc_release = single_release, \ .proc_write = name##_write, \ @@ -782,7 +782,7 @@ static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer, static const struct proc_ops cifsFYI_proc_ops = { .proc_open = cifsFYI_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = cifsFYI_proc_write, @@ -813,7 +813,7 @@ static ssize_t cifs_linux_ext_proc_write(struct file *file, static const struct proc_ops cifs_linux_ext_proc_ops = { .proc_open = cifs_linux_ext_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = cifs_linux_ext_proc_write, @@ -844,7 +844,7 @@ static ssize_t cifs_lookup_cache_proc_write(struct file *file, static const struct proc_ops cifs_lookup_cache_proc_ops = { .proc_open = cifs_lookup_cache_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = cifs_lookup_cache_proc_write, @@ -875,7 +875,7 @@ static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer, static const struct proc_ops traceSMB_proc_ops = { .proc_open = traceSMB_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = traceSMB_proc_write, @@ -986,7 +986,7 @@ static ssize_t cifs_security_flags_proc_write(struct file *file, static const struct proc_ops cifs_security_flags_proc_ops = { .proc_open = cifs_security_flags_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = cifs_security_flags_proc_write, diff --git a/fs/cifs/dfs_cache.c b/fs/cifs/dfs_cache.c index df81c718d2faec..a4fe155fc92a7a 100644 --- a/fs/cifs/dfs_cache.c +++ b/fs/cifs/dfs_cache.c @@ -214,7 +214,7 @@ static int dfscache_proc_open(struct inode *inode, struct file *file) const struct proc_ops dfscache_proc_ops = { .proc_open = dfscache_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = dfscache_proc_write, diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c index e106a1a1600d82..fab5a4197f50c3 100644 --- a/fs/fscache/object-list.c +++ b/fs/fscache/object-list.c @@ -408,7 +408,7 @@ static int fscache_objlist_release(struct inode *inode, struct file *file) const struct proc_ops fscache_objlist_proc_ops = { .proc_open = fscache_objlist_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = fscache_objlist_release, }; diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index e4944436e733d0..db661b953c4378 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -1080,7 +1080,7 @@ static int jbd2_seq_info_release(struct inode *inode, struct file *file) static const struct proc_ops jbd2_info_proc_ops = { .proc_open = jbd2_seq_info_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = jbd2_seq_info_release, }; diff --git a/fs/jfs/jfs_debug.c b/fs/jfs/jfs_debug.c index 44b62b3c322e9a..235df6bac1d71a 100644 --- a/fs/jfs/jfs_debug.c +++ b/fs/jfs/jfs_debug.c @@ -45,7 +45,7 @@ static ssize_t jfs_loglevel_proc_write(struct file *file, static const struct proc_ops jfs_loglevel_proc_ops = { .proc_open = jfs_loglevel_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = jfs_loglevel_proc_write, diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index 583ede369fd7cd..c6f2faa759d1fb 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -159,7 +159,7 @@ static int exports_proc_open(struct inode *inode, struct file *file) static const struct proc_ops exports_proc_ops = { .proc_open = exports_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release, }; diff --git a/fs/nfsd/stats.c b/fs/nfsd/stats.c index b1bc582b0493e4..1076f87715ad88 100644 --- a/fs/nfsd/stats.c +++ b/fs/nfsd/stats.c @@ -86,7 +86,7 @@ static int nfsd_proc_open(struct inode *inode, struct file *file) static const struct proc_ops nfsd_proc_ops = { .proc_open = nfsd_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, }; diff --git a/fs/proc/cpuinfo.c b/fs/proc/cpuinfo.c index d0989a443c77df..419760fd77bdd8 100644 --- a/fs/proc/cpuinfo.c +++ b/fs/proc/cpuinfo.c @@ -19,7 +19,7 @@ static int cpuinfo_open(struct inode *inode, struct file *file) static const struct proc_ops cpuinfo_proc_ops = { .proc_flags = PROC_ENTRY_PERMANENT, .proc_open = cpuinfo_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release, }; diff --git a/fs/proc/generic.c b/fs/proc/generic.c index 2f9fa179194d72..4323b28db5643a 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -590,7 +590,7 @@ static int proc_seq_release(struct inode *inode, struct file *file) static const struct proc_ops proc_seq_ops = { /* not permanent -- can call into arbitrary seq_operations */ .proc_open = proc_seq_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = proc_seq_release, }; @@ -621,7 +621,7 @@ static int proc_single_open(struct inode *inode, struct file *file) static const struct proc_ops proc_single_ops = { /* not permanent -- can call into arbitrary ->single_show */ .proc_open = proc_single_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, }; diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c index dba63b2429f05f..8274f4fc4d4338 100644 --- a/fs/proc/proc_net.c +++ b/fs/proc/proc_net.c @@ -92,7 +92,7 @@ static int seq_release_net(struct inode *ino, struct file *f) static const struct proc_ops proc_net_seq_ops = { .proc_open = seq_open_net, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = proc_simple_write, .proc_lseek = seq_lseek, .proc_release = seq_release_net, @@ -204,7 +204,7 @@ static int single_release_net(struct inode *ino, struct file *f) static const struct proc_ops proc_net_single_ops = { .proc_open = single_open_net, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = proc_simple_write, .proc_lseek = seq_lseek, .proc_release = single_release_net, diff --git a/fs/proc/stat.c b/fs/proc/stat.c index 46b3293015fe61..4695b6de315129 100644 --- a/fs/proc/stat.c +++ b/fs/proc/stat.c @@ -226,7 +226,7 @@ static int stat_open(struct inode *inode, struct file *file) static const struct proc_ops stat_proc_ops = { .proc_flags = PROC_ENTRY_PERMANENT, .proc_open = stat_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, }; diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index 0c9e9c8607e788..04f342179f5572 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -187,7 +187,7 @@ static int __name ## _open(struct inode *inode, struct file *file) \ \ static const struct proc_ops __name ## _proc_ops = { \ .proc_open = __name ## _open, \ - .proc_read = seq_read, \ + .proc_read_iter = seq_read_iter, \ .proc_lseek = seq_lseek, \ .proc_release = single_release, \ } diff --git a/ipc/util.c b/ipc/util.c index cfa0045e748d55..189c835108afc8 100644 --- a/ipc/util.c +++ b/ipc/util.c @@ -887,7 +887,7 @@ static int sysvipc_proc_release(struct inode *inode, struct file *file) static const struct proc_ops sysvipc_proc_ops = { .proc_flags = PROC_ENTRY_PERMANENT, .proc_open = sysvipc_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = sysvipc_proc_release, }; diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c index 32c071d7bc0338..6c541898f614c4 100644 --- a/kernel/irq/proc.c +++ b/kernel/irq/proc.c @@ -200,7 +200,7 @@ static int irq_affinity_list_proc_open(struct inode *inode, struct file *file) static const struct proc_ops irq_affinity_proc_ops = { .proc_open = irq_affinity_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = irq_affinity_proc_write, @@ -208,7 +208,7 @@ static const struct proc_ops irq_affinity_proc_ops = { static const struct proc_ops irq_affinity_list_proc_ops = { .proc_open = irq_affinity_list_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = irq_affinity_list_proc_write, @@ -270,7 +270,7 @@ static int default_affinity_open(struct inode *inode, struct file *file) static const struct proc_ops default_affinity_proc_ops = { .proc_open = default_affinity_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = default_affinity_write, diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 16c8c605f4b0fa..90facda3b723ab 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -699,7 +699,7 @@ const char *kdb_walk_kallsyms(loff_t *pos) static const struct proc_ops kallsyms_proc_ops = { .proc_open = kallsyms_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release_private, }; diff --git a/kernel/latencytop.c b/kernel/latencytop.c index 166d7bf49666b0..543c7f552c45ce 100644 --- a/kernel/latencytop.c +++ b/kernel/latencytop.c @@ -257,7 +257,7 @@ static int lstats_open(struct inode *inode, struct file *filp) static const struct proc_ops lstats_proc_ops = { .proc_open = lstats_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = lstats_write, .proc_lseek = seq_lseek, .proc_release = single_release, diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c index 5525cd3ba0c83c..60c725f53c26d7 100644 --- a/kernel/locking/lockdep_proc.c +++ b/kernel/locking/lockdep_proc.c @@ -669,7 +669,7 @@ static int lock_stat_release(struct inode *inode, struct file *file) static const struct proc_ops lock_stat_proc_ops = { .proc_open = lock_stat_open, .proc_write = lock_stat_write, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = lock_stat_release, }; diff --git a/kernel/module.c b/kernel/module.c index bee1c25ca5c5ec..ed5a99d520b40c 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -4388,7 +4388,7 @@ static int modules_open(struct inode *inode, struct file *file) static const struct proc_ops modules_proc_ops = { .proc_flags = PROC_ENTRY_PERMANENT, .proc_open = modules_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release, }; diff --git a/kernel/profile.c b/kernel/profile.c index 6f69a4195d5630..101090397235ae 100644 --- a/kernel/profile.c +++ b/kernel/profile.c @@ -444,7 +444,7 @@ static ssize_t prof_cpu_mask_proc_write(struct file *file, static const struct proc_ops prof_cpu_mask_proc_ops = { .proc_open = prof_cpu_mask_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, .proc_write = prof_cpu_mask_proc_write, diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 8f45cdb6463b88..6795170140a031 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -1305,7 +1305,7 @@ static int psi_fop_release(struct inode *inode, struct file *file) static const struct proc_ops psi_io_proc_ops = { .proc_open = psi_io_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = psi_io_write, .proc_poll = psi_fop_poll, @@ -1314,7 +1314,7 @@ static const struct proc_ops psi_io_proc_ops = { static const struct proc_ops psi_memory_proc_ops = { .proc_open = psi_memory_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = psi_memory_write, .proc_poll = psi_fop_poll, @@ -1323,7 +1323,7 @@ static const struct proc_ops psi_memory_proc_ops = { static const struct proc_ops psi_cpu_proc_ops = { .proc_open = psi_cpu_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = psi_cpu_write, .proc_poll = psi_fop_poll, diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 76750e73dcaf9d..2317d29e16def9 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -878,7 +878,7 @@ static const struct file_operations ddebug_proc_fops = { static const struct proc_ops proc_fops = { .proc_open = ddebug_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release_private, .proc_write = ddebug_proc_write diff --git a/mm/slab_common.c b/mm/slab_common.c index 37d48a56431d04..5cf40d2d721c0b 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1584,7 +1584,7 @@ static int slabinfo_open(struct inode *inode, struct file *file) static const struct proc_ops slabinfo_proc_ops = { .proc_flags = PROC_ENTRY_PERMANENT, .proc_open = slabinfo_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = slabinfo_write, .proc_lseek = seq_lseek, .proc_release = seq_release, diff --git a/mm/swapfile.c b/mm/swapfile.c index 987276c557d1f1..2e50f52a14c7c2 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2835,7 +2835,7 @@ static int swaps_open(struct inode *inode, struct file *file) static const struct proc_ops swaps_proc_ops = { .proc_flags = PROC_ENTRY_PERMANENT, .proc_open = swaps_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release, .proc_poll = swaps_poll, diff --git a/net/atm/mpoa_proc.c b/net/atm/mpoa_proc.c index 829db9eba0cb95..fe8f822c7750a6 100644 --- a/net/atm/mpoa_proc.c +++ b/net/atm/mpoa_proc.c @@ -55,7 +55,7 @@ static int parse_qos(const char *buff); static const struct proc_ops mpc_proc_ops = { .proc_open = proc_mpc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = proc_mpc_write, .proc_release = seq_release, diff --git a/net/core/pktgen.c b/net/core/pktgen.c index b53b6d38c4dff8..200b976202d0d1 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -537,7 +537,7 @@ static int pgctrl_open(struct inode *inode, struct file *file) static const struct proc_ops pktgen_proc_ops = { .proc_open = pgctrl_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = pgctrl_write, .proc_release = single_release, @@ -1709,7 +1709,7 @@ static int pktgen_if_open(struct inode *inode, struct file *file) static const struct proc_ops pktgen_if_proc_ops = { .proc_open = pktgen_if_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = pktgen_if_write, .proc_release = single_release, @@ -1846,7 +1846,7 @@ static int pktgen_thread_open(struct inode *inode, struct file *file) static const struct proc_ops pktgen_thread_proc_ops = { .proc_open = pktgen_thread_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_write = pktgen_thread_write, .proc_release = single_release, diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c index f8755a4ae9d4bd..67472389c9c395 100644 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c @@ -806,7 +806,7 @@ static ssize_t clusterip_proc_write(struct file *file, const char __user *input, static const struct proc_ops clusterip_proc_ops = { .proc_open = clusterip_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = clusterip_proc_write, .proc_lseek = seq_lseek, .proc_release = clusterip_proc_release, diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 1d7076b78e630b..4d5f26478f1001 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -239,7 +239,7 @@ static int rt_cache_seq_open(struct inode *inode, struct file *file) static const struct proc_ops rt_cache_proc_ops = { .proc_open = rt_cache_seq_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release, }; @@ -330,7 +330,7 @@ static int rt_cpu_seq_open(struct inode *inode, struct file *file) static const struct proc_ops rt_cpu_proc_ops = { .proc_open = rt_cpu_seq_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = seq_release, }; diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c index 19bef176145eb9..f9cc00f7486058 100644 --- a/net/netfilter/xt_recent.c +++ b/net/netfilter/xt_recent.c @@ -618,7 +618,7 @@ recent_mt_proc_write(struct file *file, const char __user *input, static const struct proc_ops recent_mt_proc_ops = { .proc_open = recent_seq_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_write = recent_mt_proc_write, .proc_release = seq_release_private, .proc_lseek = seq_lseek, diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index e5c01697c3f1d6..3671c464e0d30f 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -1623,7 +1623,7 @@ static int content_release_procfs(struct inode *inode, struct file *filp) static const struct proc_ops content_proc_ops = { .proc_open = content_open_procfs, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = content_release_procfs, }; diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c index c964b48eaabae4..95b56f0e5a01e8 100644 --- a/net/sunrpc/stats.c +++ b/net/sunrpc/stats.c @@ -71,7 +71,7 @@ static int rpc_proc_open(struct inode *inode, struct file *file) static const struct proc_ops rpc_proc_ops = { .proc_open = rpc_proc_open, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, .proc_lseek = seq_lseek, .proc_release = single_release, }; diff --git a/sound/core/info.c b/sound/core/info.c index 8c6bc5241df50c..6e2a35a37b5e6b 100644 --- a/sound/core/info.c +++ b/sound/core/info.c @@ -426,7 +426,7 @@ static const struct proc_ops snd_info_text_entry_ops = .proc_release = snd_info_text_entry_release, .proc_write = snd_info_text_entry_write, .proc_lseek = seq_lseek, - .proc_read = seq_read, + .proc_read_iter = seq_read_iter, }; static struct snd_info_entry *create_subdir(struct module *mod, From patchwork Tue Jul 7 17:47:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649503 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 35EAE739 for ; Tue, 7 Jul 2020 17:50:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CF8520708 for ; Tue, 7 Jul 2020 17:50:55 +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="NXWqDN2A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728609AbgGGRuw (ORCPT ); Tue, 7 Jul 2020 13:50:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728211AbgGGRuv (ORCPT ); Tue, 7 Jul 2020 13:50:51 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD305C061755; Tue, 7 Jul 2020 10:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=Gjf3jqi0HzNFMllJJU/tVW22QOLJhqX9EJ96/owdJdI=; b=NXWqDN2A5HtMNjnFrALW/SebK9 k0Z5VbnOzXDzHivfIJycC5fNs8GERyChMxWkMqV7uRw69cXmuUeSQvYXYDzJgCWtSr036ltGDy0qg Ho5U80t623stEQ2MbU7Ibmb48hhIxlnor+0au18e1Blemli0PLqwue0GeBPDSjVIENi1OzCAknizk +Z5Cn64DpiAO3ukLRYa/tVQVUjj17GbIvut4wwXlKTK8GsRnGSXiPFAqD/r1KPMr90KDc34E4c6Ag 5VAfIeVFuopG3RQYBo+CRNBoWvXOdl7tFJQ2jQrOcKX/3OIaN55D6B9p4uoHf2pPVfw45sHJu46If MWmfWdLg==; Received: from 213-225-32-40.nat.highway.a1.net ([213.225.32.40] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrjx-0003fY-4U; Tue, 07 Jul 2020 17:50:45 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 20/23] sysctl: Convert to iter interfaces Date: Tue, 7 Jul 2020 19:47:58 +0200 Message-Id: <20200707174801.4162712-21-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: "Matthew Wilcox (Oracle)" Using the read_iter/write_iter interfaces allows for in-kernel users to set sysctls without using set_fs(). Also, the buffer is a string, so give it the real type of 'char *', not void *. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig --- fs/proc/proc_sysctl.c | 44 ++++++++++++++++++-------------------- include/linux/bpf-cgroup.h | 2 +- kernel/bpf/cgroup.c | 2 +- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 6c1166ccdaea57..9f6b9c3e3fdaf5 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -540,13 +541,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry, return err; } -static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, - size_t count, loff_t *ppos, int write) +static ssize_t proc_sys_call_handler(struct kiocb *iocb, struct iov_iter *iter, + int write) { - struct inode *inode = file_inode(filp); + struct inode *inode = file_inode(iocb->ki_filp); struct ctl_table_header *head = grab_header(inode); struct ctl_table *table = PROC_I(inode)->sysctl_entry; - void *kbuf; + size_t count = iov_iter_count(iter); + char *kbuf; ssize_t error; if (IS_ERR(head)) @@ -569,32 +571,30 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, error = -ENOMEM; if (count >= KMALLOC_MAX_SIZE) goto out; + kbuf = kzalloc(count + 1, GFP_KERNEL); + if (!kbuf) + goto out; if (write) { - kbuf = memdup_user_nul(ubuf, count); - if (IS_ERR(kbuf)) { - error = PTR_ERR(kbuf); - goto out; - } - } else { - kbuf = kzalloc(count, GFP_KERNEL); - if (!kbuf) + error = -EFAULT; + if (!copy_from_iter_full(kbuf, count, iter)) goto out; + kbuf[count] = '\0'; } error = BPF_CGROUP_RUN_PROG_SYSCTL(head, table, write, &kbuf, &count, - ppos); + &iocb->ki_pos); if (error) goto out_free_buf; /* careful: calling conventions are nasty here */ - error = table->proc_handler(table, write, kbuf, &count, ppos); + error = table->proc_handler(table, write, kbuf, &count, &iocb->ki_pos); if (error) goto out_free_buf; if (!write) { error = -EFAULT; - if (copy_to_user(ubuf, kbuf, count)) + if (copy_to_iter(kbuf, count, iter) < count) goto out_free_buf; } @@ -607,16 +607,14 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, return error; } -static ssize_t proc_sys_read(struct file *filp, char __user *buf, - size_t count, loff_t *ppos) +static ssize_t proc_sys_read(struct kiocb *iocb, struct iov_iter *iter) { - return proc_sys_call_handler(filp, (void __user *)buf, count, ppos, 0); + return proc_sys_call_handler(iocb, iter, 0); } -static ssize_t proc_sys_write(struct file *filp, const char __user *buf, - size_t count, loff_t *ppos) +static ssize_t proc_sys_write(struct kiocb *iocb, struct iov_iter *iter) { - return proc_sys_call_handler(filp, (void __user *)buf, count, ppos, 1); + return proc_sys_call_handler(iocb, iter, 1); } static int proc_sys_open(struct inode *inode, struct file *filp) @@ -853,8 +851,8 @@ static int proc_sys_getattr(const struct path *path, struct kstat *stat, static const struct file_operations proc_sys_file_operations = { .open = proc_sys_open, .poll = proc_sys_poll, - .read = proc_sys_read, - .write = proc_sys_write, + .read_iter = proc_sys_read, + .write_iter = proc_sys_write, .llseek = default_llseek, }; diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h index c66c545e161a60..f81d3b3752f919 100644 --- a/include/linux/bpf-cgroup.h +++ b/include/linux/bpf-cgroup.h @@ -132,7 +132,7 @@ int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor, int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head, struct ctl_table *table, int write, - void **buf, size_t *pcount, loff_t *ppos, + char **buf, size_t *pcount, loff_t *ppos, enum bpf_attach_type type); int __cgroup_bpf_run_filter_setsockopt(struct sock *sock, int *level, diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index ac53102e244a7a..81dcf15990ebe1 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -1202,7 +1202,7 @@ const struct bpf_verifier_ops cg_dev_verifier_ops = { */ int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head, struct ctl_table *table, int write, - void **buf, size_t *pcount, loff_t *ppos, + char **buf, size_t *pcount, loff_t *ppos, enum bpf_attach_type type) { struct bpf_sysctl_kern ctx = { From patchwork Tue Jul 7 17:47:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649505 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 28523912 for ; Tue, 7 Jul 2020 17:53:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1089720720 for ; Tue, 7 Jul 2020 17:53:08 +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="f3wQLBn5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728453AbgGGRxE (ORCPT ); Tue, 7 Jul 2020 13:53:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728265AbgGGRxE (ORCPT ); Tue, 7 Jul 2020 13:53:04 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32E2DC061755; Tue, 7 Jul 2020 10:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=ikLDu9Sqnofb7uotDosNOhH64p/v3I5ZekNTOjjncWE=; b=f3wQLBn5jEdVdwA61niHFtDcYq HurwCJPCNykfmI4pqa6SJPG4Y4l9kfx3UO1Qq3gGPsYxFiGZp+RrLUkJt+jr4f2cSiAIhlmneDKHu JVvWx+XVrdW1hg+FqBX4Ak1SbFyq6EtYIfbMUaoI5z3K+0Ys0aqt3YwXcyMVdlimSAvUVCZS3mbKh G6mVv5H1r+aCwp31mA3uf1VrvNE9UucIZBQIF+a7wkof/Fd2NhJQGCEDe9bXgygNz5wVBp+6XwgSP myrSeWKwwtNAe9RazV3T34Lv2GgED2tQnBY+3efFSpAi08gdmS1bU0UbFCJfJtKN2oDBJubIWePzZ +2l+3h/A==; Received: from 213-225-32-40.nat.highway.a1.net ([213.225.32.40] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrm5-0003kX-Pj; Tue, 07 Jul 2020 17:52:58 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 21/23] fs: don't allow kernel reads and writes without iter ops Date: Tue, 7 Jul 2020 19:47:59 +0200 Message-Id: <20200707174801.4162712-22-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Don't allow calling ->read or ->write with set_fs as a preparation for killing off set_fs. While I've not triggered any of these cases in my setups as all the usual suspect (file systems, pipes, sockets, block devices, system character devices) use the iter ops this is almost going to be guaranteed to eventuall break something, so print a detailed error message helping to debug such cases. The fix will be to switch the affected driver to use the iter ops. Signed-off-by: Christoph Hellwig --- fs/read_write.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 8bec4418543994..11c55547cfc9d6 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -419,6 +419,13 @@ static ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, lo return ret; } +static void warn_unsupported(struct file *file, const char *op) +{ + pr_warn_ratelimited( + "kernel %s not supported for file %pD4 (pid: %d comm: %.20s)\n", + op, file, current->pid, current->comm); +} + ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) { ssize_t ret; @@ -430,13 +437,7 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) if (count > MAX_RW_COUNT) count = MAX_RW_COUNT; - 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); - set_fs(old_fs); - } else if (file->f_op->read_iter) { + if (file->f_op->read_iter) { struct kvec iov = { .iov_base = buf, .iov_len = count }; struct kiocb kiocb; struct iov_iter iter; @@ -447,6 +448,8 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) ret = file->f_op->read_iter(&kiocb, &iter); *pos = kiocb.ki_pos; } else { + if (file->f_op->read) + warn_unsupported(file, "read"); ret = -EINVAL; } if (ret > 0) { @@ -530,14 +533,7 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, if (count > MAX_RW_COUNT) count = MAX_RW_COUNT; - 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 if (file->f_op->write_iter) { + if (file->f_op->write_iter) { struct kvec iov = { .iov_base = (void *)buf, .iov_len = count }; struct kiocb kiocb; struct iov_iter iter; @@ -549,6 +545,8 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, if (ret > 0) *pos = kiocb.ki_pos; } else { + if (file->f_op->write) + warn_unsupported(file, "write"); ret = -EINVAL; } if (ret > 0) { From patchwork Tue Jul 7 17:48:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649507 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 EDE62739 for ; Tue, 7 Jul 2020 17:55:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9E6C20708 for ; Tue, 7 Jul 2020 17:55:18 +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="eqsE5JcL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728183AbgGGRzQ (ORCPT ); Tue, 7 Jul 2020 13:55:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727777AbgGGRzQ (ORCPT ); Tue, 7 Jul 2020 13:55:16 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4354C061755; Tue, 7 Jul 2020 10:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=q7opg098sB7NQjpFJjg41tCJlS6oGLAGY2Zu0zCKTg0=; b=eqsE5JcLdYrnGsK4rDITE4o5xd oA2AGhSV05YPHOBDx4NoH2mSeQDVvhRysjiVHEIkWivoOtBDTiYiJ18dn7zBcAW0kC7WyI7qdBxtl ZCaoToQtUFYpJ4li2dnNqt6jCQx/NxujbJdRnNJs32mK5o8WUq1OJsyEtmih4Z+BJPmzYc3UjIYPk kMFr51G5H9ZHWD8M1sMn/8ht//mY8hQS+9IJZH6DHdIxGHPOCDrNHKzTaZhHnEl4Mm+mU4dqsWZwb JSlXIwv7x+h6qIdJJbWDmWtw/9edtmmF1Ax4mOwRv40KvbBsoGOmM6KvIjBaFlCId+gBpay1/Hix8 xi1fFNeg==; Received: from 213-225-32-40.nat.highway.a1.net ([213.225.32.40] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsroC-0003tJ-KQ; Tue, 07 Jul 2020 17:55:09 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 22/23] fs: default to generic_file_splice_read for files having ->read_iter Date: Tue, 7 Jul 2020 19:48:00 +0200 Message-Id: <20200707174801.4162712-23-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org If a file implements the ->read_iter method, the iter based splice read works and is always preferred over the ->read based one. Use it by default in do_splice_to and remove all the direct assignment of generic_file_splice_read to file_operations. Signed-off-by: Christoph Hellwig --- fs/adfs/file.c | 1 - fs/affs/file.c | 1 - fs/afs/file.c | 1 - fs/bfs/file.c | 1 - fs/block_dev.c | 1 - fs/btrfs/file.c | 1 - fs/ceph/file.c | 1 - fs/cifs/cifsfs.c | 6 ------ fs/coda/file.c | 1 - fs/cramfs/inode.c | 1 - fs/ecryptfs/file.c | 1 - fs/exfat/file.c | 1 - fs/ext2/file.c | 1 - fs/ext4/file.c | 1 - fs/f2fs/file.c | 1 - fs/fat/file.c | 1 - fs/fuse/file.c | 1 - fs/gfs2/file.c | 2 -- fs/hfs/inode.c | 1 - fs/hfsplus/inode.c | 1 - fs/hostfs/hostfs_kern.c | 1 - fs/hpfs/file.c | 1 - fs/jffs2/file.c | 1 - fs/jfs/file.c | 1 - fs/minix/file.c | 1 - fs/nfs/file.c | 1 - fs/nfs/nfs4file.c | 1 - fs/nilfs2/file.c | 1 - fs/ntfs/file.c | 1 - fs/ocfs2/file.c | 2 -- fs/omfs/file.c | 1 - fs/ramfs/file-mmu.c | 1 - fs/ramfs/file-nommu.c | 1 - fs/read_write.c | 1 - fs/reiserfs/file.c | 1 - fs/romfs/mmap-nommu.c | 1 - fs/splice.c | 2 ++ fs/sysv/file.c | 1 - fs/ubifs/file.c | 1 - fs/udf/file.c | 1 - fs/ufs/file.c | 1 - fs/vboxsf/file.c | 1 - fs/xfs/xfs_file.c | 1 - fs/zonefs/super.c | 1 - mm/shmem.c | 1 - 45 files changed, 2 insertions(+), 51 deletions(-) diff --git a/fs/adfs/file.c b/fs/adfs/file.c index 754afb14a6ff74..b089b91c1870ae 100644 --- a/fs/adfs/file.c +++ b/fs/adfs/file.c @@ -28,7 +28,6 @@ const struct file_operations adfs_file_operations = { .mmap = generic_file_mmap, .fsync = generic_file_fsync, .write_iter = generic_file_write_iter, - .splice_read = generic_file_splice_read, }; const struct inode_operations adfs_file_inode_operations = { diff --git a/fs/affs/file.c b/fs/affs/file.c index a85817f54483f7..7d51cc2e3dabfa 100644 --- a/fs/affs/file.c +++ b/fs/affs/file.c @@ -975,7 +975,6 @@ const struct file_operations affs_file_operations = { .open = affs_file_open, .release = affs_file_release, .fsync = affs_file_fsync, - .splice_read = generic_file_splice_read, }; const struct inode_operations affs_file_inode_operations = { diff --git a/fs/afs/file.c b/fs/afs/file.c index 6f6ed1605cfe30..2476f10383fbdd 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c @@ -32,7 +32,6 @@ const struct file_operations afs_file_operations = { .read_iter = generic_file_read_iter, .write_iter = afs_file_write, .mmap = afs_file_mmap, - .splice_read = generic_file_splice_read, .fsync = afs_fsync, .lock = afs_lock, .flock = afs_flock, diff --git a/fs/bfs/file.c b/fs/bfs/file.c index 0dceefc54b48ab..39088cc7492308 100644 --- a/fs/bfs/file.c +++ b/fs/bfs/file.c @@ -27,7 +27,6 @@ const struct file_operations bfs_file_operations = { .read_iter = generic_file_read_iter, .write_iter = generic_file_write_iter, .mmap = generic_file_mmap, - .splice_read = generic_file_splice_read, }; static int bfs_move_block(unsigned long from, unsigned long to, diff --git a/fs/block_dev.c b/fs/block_dev.c index 0ae656e022fd57..0aa66a6075eb11 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -2160,7 +2160,6 @@ const struct file_operations def_blk_fops = { #ifdef CONFIG_COMPAT .compat_ioctl = compat_blkdev_ioctl, #endif - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = blkdev_fallocate, }; diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 2520605afc256e..322cc65902d107 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -3507,7 +3507,6 @@ static int btrfs_file_open(struct inode *inode, struct file *filp) const struct file_operations btrfs_file_operations = { .llseek = btrfs_file_llseek, .read_iter = generic_file_read_iter, - .splice_read = generic_file_splice_read, .write_iter = btrfs_file_write_iter, .mmap = btrfs_file_mmap, .open = btrfs_file_open, diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 160644ddaeed70..e28c27751e6b3b 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -2507,7 +2507,6 @@ const struct file_operations ceph_file_fops = { .fsync = ceph_fsync, .lock = ceph_lock, .flock = ceph_flock, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .unlocked_ioctl = ceph_ioctl, .compat_ioctl = compat_ptr_ioctl, diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 0fb99d25e8a8a0..74da1dfe08c6fa 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -1235,7 +1235,6 @@ const struct file_operations cifs_file_ops = { .fsync = cifs_fsync, .flush = cifs_flush, .mmap = cifs_file_mmap, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, @@ -1255,7 +1254,6 @@ const struct file_operations cifs_file_strict_ops = { .fsync = cifs_strict_fsync, .flush = cifs_flush, .mmap = cifs_file_strict_mmap, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, @@ -1275,7 +1273,6 @@ const struct file_operations cifs_file_direct_ops = { .fsync = cifs_fsync, .flush = cifs_flush, .mmap = cifs_file_mmap, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, @@ -1293,7 +1290,6 @@ const struct file_operations cifs_file_nobrl_ops = { .fsync = cifs_fsync, .flush = cifs_flush, .mmap = cifs_file_mmap, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, @@ -1311,7 +1307,6 @@ const struct file_operations cifs_file_strict_nobrl_ops = { .fsync = cifs_strict_fsync, .flush = cifs_flush, .mmap = cifs_file_strict_mmap, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, @@ -1329,7 +1324,6 @@ const struct file_operations cifs_file_direct_nobrl_ops = { .fsync = cifs_fsync, .flush = cifs_flush, .mmap = cifs_file_mmap, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, diff --git a/fs/coda/file.c b/fs/coda/file.c index 128d63df5bfb62..8dd438f2c09fe2 100644 --- a/fs/coda/file.c +++ b/fs/coda/file.c @@ -301,5 +301,4 @@ const struct file_operations coda_file_operations = { .open = coda_open, .release = coda_release, .fsync = coda_fsync, - .splice_read = generic_file_splice_read, }; diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c index 912308600d393d..0645c1af27c07d 100644 --- a/fs/cramfs/inode.c +++ b/fs/cramfs/inode.c @@ -485,7 +485,6 @@ static unsigned int cramfs_physmem_mmap_capabilities(struct file *file) static const struct file_operations cramfs_physmem_fops = { .llseek = generic_file_llseek, .read_iter = generic_file_read_iter, - .splice_read = generic_file_splice_read, .mmap = cramfs_physmem_mmap, #ifndef CONFIG_MMU .get_unmapped_area = cramfs_physmem_get_unmapped_area, diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index 5fb45d865ce511..03210a02fe6c00 100644 --- a/fs/ecryptfs/file.c +++ b/fs/ecryptfs/file.c @@ -420,5 +420,4 @@ const struct file_operations ecryptfs_main_fops = { .release = ecryptfs_release, .fsync = ecryptfs_fsync, .fasync = ecryptfs_fasync, - .splice_read = generic_file_splice_read, }; diff --git a/fs/exfat/file.c b/fs/exfat/file.c index 3b7fea465fd41e..8fe5df8a9ccbca 100644 --- a/fs/exfat/file.c +++ b/fs/exfat/file.c @@ -369,7 +369,6 @@ const struct file_operations exfat_file_operations = { .write_iter = generic_file_write_iter, .mmap = generic_file_mmap, .fsync = exfat_file_fsync, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, }; diff --git a/fs/ext2/file.c b/fs/ext2/file.c index 60378ddf1424b0..1c0828e0198440 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c @@ -191,7 +191,6 @@ const struct file_operations ext2_file_operations = { .release = ext2_release_file, .fsync = ext2_fsync, .get_unmapped_area = thp_get_unmapped_area, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, }; diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 2a01e31a032c4c..f5dc9a4e0937d1 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -896,7 +896,6 @@ const struct file_operations ext4_file_operations = { .release = ext4_release_file, .fsync = ext4_sync_file, .get_unmapped_area = thp_get_unmapped_area, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ext4_fallocate, }; diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 3268f8dd59bbaf..6b34caf13b5668 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4033,6 +4033,5 @@ const struct file_operations f2fs_file_operations = { #ifdef CONFIG_COMPAT .compat_ioctl = f2fs_compat_ioctl, #endif - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, }; diff --git a/fs/fat/file.c b/fs/fat/file.c index 42134c58c87e19..e7a0342ccfe1f0 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c @@ -208,7 +208,6 @@ const struct file_operations fat_file_operations = { .unlocked_ioctl = fat_generic_ioctl, .compat_ioctl = compat_ptr_ioctl, .fsync = fat_file_fsync, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = fat_fallocate, }; diff --git a/fs/fuse/file.c b/fs/fuse/file.c index e573b0cd2737dc..a404e147bb2cf7 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -3382,7 +3382,6 @@ static const struct file_operations fuse_file_operations = { .fsync = fuse_fsync, .lock = fuse_file_lock, .flock = fuse_file_flock, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .unlocked_ioctl = fuse_file_ioctl, .compat_ioctl = fuse_file_compat_ioctl, diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index fe305e4bfd3734..d23babc0c292b8 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -1323,7 +1323,6 @@ const struct file_operations gfs2_file_fops = { .fsync = gfs2_fsync, .lock = gfs2_lock, .flock = gfs2_flock, - .splice_read = generic_file_splice_read, .splice_write = gfs2_file_splice_write, .setlease = simple_nosetlease, .fallocate = gfs2_fallocate, @@ -1354,7 +1353,6 @@ const struct file_operations gfs2_file_fops_nolock = { .open = gfs2_open, .release = gfs2_release, .fsync = gfs2_fsync, - .splice_read = generic_file_splice_read, .splice_write = gfs2_file_splice_write, .setlease = generic_setlease, .fallocate = gfs2_fallocate, diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index 2f224b98ee94a6..6181d3818e17c0 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c @@ -682,7 +682,6 @@ static const struct file_operations hfs_file_operations = { .read_iter = generic_file_read_iter, .write_iter = generic_file_write_iter, .mmap = generic_file_mmap, - .splice_read = generic_file_splice_read, .fsync = hfs_file_fsync, .open = hfs_file_open, .release = hfs_file_release, diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c index e3da9e96b83578..7bd61ba08fbc9e 100644 --- a/fs/hfsplus/inode.c +++ b/fs/hfsplus/inode.c @@ -358,7 +358,6 @@ static const struct file_operations hfsplus_file_operations = { .read_iter = generic_file_read_iter, .write_iter = generic_file_write_iter, .mmap = generic_file_mmap, - .splice_read = generic_file_splice_read, .fsync = hfsplus_file_fsync, .open = hfsplus_file_open, .release = hfsplus_file_release, diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c index c070c0d8e3e977..c6453e3768294c 100644 --- a/fs/hostfs/hostfs_kern.c +++ b/fs/hostfs/hostfs_kern.c @@ -379,7 +379,6 @@ static int hostfs_fsync(struct file *file, loff_t start, loff_t end, static const struct file_operations hostfs_file_fops = { .llseek = generic_file_llseek, - .splice_read = generic_file_splice_read, .read_iter = generic_file_read_iter, .write_iter = generic_file_write_iter, .mmap = generic_file_mmap, diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c index 077c25128eb741..53951f29f25e50 100644 --- a/fs/hpfs/file.c +++ b/fs/hpfs/file.c @@ -213,7 +213,6 @@ const struct file_operations hpfs_file_ops = .mmap = generic_file_mmap, .release = hpfs_file_release, .fsync = hpfs_file_fsync, - .splice_read = generic_file_splice_read, .unlocked_ioctl = hpfs_ioctl, .compat_ioctl = compat_ptr_ioctl, }; diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c index f8fb89b10227ce..6e986a99669779 100644 --- a/fs/jffs2/file.c +++ b/fs/jffs2/file.c @@ -56,7 +56,6 @@ const struct file_operations jffs2_file_operations = .unlocked_ioctl=jffs2_ioctl, .mmap = generic_file_readonly_mmap, .fsync = jffs2_fsync, - .splice_read = generic_file_splice_read, }; /* jffs2_file_inode_operations */ diff --git a/fs/jfs/file.c b/fs/jfs/file.c index 930d2701f2062b..fb209673943697 100644 --- a/fs/jfs/file.c +++ b/fs/jfs/file.c @@ -141,7 +141,6 @@ const struct file_operations jfs_file_operations = { .read_iter = generic_file_read_iter, .write_iter = generic_file_write_iter, .mmap = generic_file_mmap, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fsync = jfs_fsync, .release = jfs_release, diff --git a/fs/minix/file.c b/fs/minix/file.c index c50b0a20fcd9c1..e787789b43fa95 100644 --- a/fs/minix/file.c +++ b/fs/minix/file.c @@ -19,7 +19,6 @@ const struct file_operations minix_file_operations = { .write_iter = generic_file_write_iter, .mmap = generic_file_mmap, .fsync = generic_file_fsync, - .splice_read = generic_file_splice_read, }; static int minix_setattr(struct dentry *dentry, struct iattr *attr) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index ccd6c1637b270b..8ba06f6c3ec5af 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -851,7 +851,6 @@ const struct file_operations nfs_file_operations = { .fsync = nfs_file_fsync, .lock = nfs_lock, .flock = nfs_flock, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .check_flags = nfs_check_flags, .setlease = simple_nosetlease, diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index 8e5d6223ddd359..3e3793cb217ec1 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -415,7 +415,6 @@ const struct file_operations nfs4_file_operations = { .fsync = nfs_file_fsync, .lock = nfs_lock, .flock = nfs_flock, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .check_flags = nfs_check_flags, .setlease = simple_nosetlease, diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c index 64bc81363c6cc0..cb3269c52dabc7 100644 --- a/fs/nilfs2/file.c +++ b/fs/nilfs2/file.c @@ -140,7 +140,6 @@ const struct file_operations nilfs_file_operations = { .open = generic_file_open, /* .release = nilfs_release_file, */ .fsync = nilfs_sync_file, - .splice_read = generic_file_splice_read, }; const struct inode_operations nilfs_file_inode_operations = { diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c index f42967b738eb67..8c1759e9185dd7 100644 --- a/fs/ntfs/file.c +++ b/fs/ntfs/file.c @@ -2012,7 +2012,6 @@ const struct file_operations ntfs_file_ops = { #endif /* NTFS_RW */ .mmap = generic_file_mmap, .open = ntfs_file_open, - .splice_read = generic_file_splice_read, }; const struct inode_operations ntfs_file_inode_ops = { diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 85979e2214b39d..86069cae29047e 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -2671,7 +2671,6 @@ const struct file_operations ocfs2_fops = { #endif .lock = ocfs2_lock, .flock = ocfs2_flock, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ocfs2_fallocate, .remap_file_range = ocfs2_remap_file_range, @@ -2717,7 +2716,6 @@ const struct file_operations ocfs2_fops_no_plocks = { .compat_ioctl = ocfs2_compat_ioctl, #endif .flock = ocfs2_flock, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ocfs2_fallocate, .remap_file_range = ocfs2_remap_file_range, diff --git a/fs/omfs/file.c b/fs/omfs/file.c index d7b5f09d298c9d..0dddc6c644c10c 100644 --- a/fs/omfs/file.c +++ b/fs/omfs/file.c @@ -340,7 +340,6 @@ const struct file_operations omfs_file_operations = { .write_iter = generic_file_write_iter, .mmap = generic_file_mmap, .fsync = generic_file_fsync, - .splice_read = generic_file_splice_read, }; static int omfs_setattr(struct dentry *dentry, struct iattr *attr) diff --git a/fs/ramfs/file-mmu.c b/fs/ramfs/file-mmu.c index 12af0490322f9d..d1e76267e9c323 100644 --- a/fs/ramfs/file-mmu.c +++ b/fs/ramfs/file-mmu.c @@ -43,7 +43,6 @@ const struct file_operations ramfs_file_operations = { .write_iter = generic_file_write_iter, .mmap = generic_file_mmap, .fsync = noop_fsync, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = generic_file_llseek, .get_unmapped_area = ramfs_mmu_get_unmapped_area, diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c index 41469545495608..9336086e60fefd 100644 --- a/fs/ramfs/file-nommu.c +++ b/fs/ramfs/file-nommu.c @@ -43,7 +43,6 @@ const struct file_operations ramfs_file_operations = { .read_iter = generic_file_read_iter, .write_iter = generic_file_write_iter, .fsync = noop_fsync, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = generic_file_llseek, }; diff --git a/fs/read_write.c b/fs/read_write.c index 11c55547cfc9d6..8d8113ae8561e6 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -29,7 +29,6 @@ const struct file_operations generic_ro_fops = { .llseek = generic_file_llseek, .read_iter = generic_file_read_iter, .mmap = generic_file_readonly_mmap, - .splice_read = generic_file_splice_read, }; EXPORT_SYMBOL(generic_ro_fops); diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c index 0b641ae694f123..4f71c3aca2b8c1 100644 --- a/fs/reiserfs/file.c +++ b/fs/reiserfs/file.c @@ -247,7 +247,6 @@ const struct file_operations reiserfs_file_operations = { .fsync = reiserfs_sync_file, .read_iter = generic_file_read_iter, .write_iter = generic_file_write_iter, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = generic_file_llseek, }; diff --git a/fs/romfs/mmap-nommu.c b/fs/romfs/mmap-nommu.c index 2c4a23113fb5f2..f37e27fa0c1084 100644 --- a/fs/romfs/mmap-nommu.c +++ b/fs/romfs/mmap-nommu.c @@ -78,7 +78,6 @@ static unsigned romfs_mmap_capabilities(struct file *file) const struct file_operations romfs_ro_fops = { .llseek = generic_file_llseek, .read_iter = generic_file_read_iter, - .splice_read = generic_file_splice_read, .mmap = romfs_mmap, .get_unmapped_area = romfs_get_unmapped_area, .mmap_capabilities = romfs_mmap_capabilities, diff --git a/fs/splice.c b/fs/splice.c index d7c8a7c4db07ff..52485158023778 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -868,6 +868,8 @@ static long do_splice_to(struct file *in, loff_t *ppos, if (in->f_op->splice_read) return in->f_op->splice_read(in, ppos, pipe, len, flags); + if (in->f_op->read_iter) + return generic_file_splice_read(in, ppos, pipe, len, flags); return default_file_splice_read(in, ppos, pipe, len, flags); } diff --git a/fs/sysv/file.c b/fs/sysv/file.c index 45fc79a18594f1..d023922c0e44c7 100644 --- a/fs/sysv/file.c +++ b/fs/sysv/file.c @@ -26,7 +26,6 @@ const struct file_operations sysv_file_operations = { .write_iter = generic_file_write_iter, .mmap = generic_file_mmap, .fsync = generic_file_fsync, - .splice_read = generic_file_splice_read, }; static int sysv_setattr(struct dentry *dentry, struct iattr *attr) diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 49fe062ce45ec2..a3af46b3950811 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c @@ -1668,7 +1668,6 @@ const struct file_operations ubifs_file_operations = { .mmap = ubifs_file_mmap, .fsync = ubifs_fsync, .unlocked_ioctl = ubifs_ioctl, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .open = fscrypt_file_open, #ifdef CONFIG_COMPAT diff --git a/fs/udf/file.c b/fs/udf/file.c index 628941a6b79afb..6c796ef2bd8331 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c @@ -250,7 +250,6 @@ const struct file_operations udf_file_operations = { .write_iter = udf_file_write_iter, .release = udf_release_file, .fsync = generic_file_fsync, - .splice_read = generic_file_splice_read, .llseek = generic_file_llseek, }; diff --git a/fs/ufs/file.c b/fs/ufs/file.c index 7e087581be7e0c..7a6dbb32d22cb6 100644 --- a/fs/ufs/file.c +++ b/fs/ufs/file.c @@ -41,5 +41,4 @@ const struct file_operations ufs_file_operations = { .mmap = generic_file_mmap, .open = generic_file_open, .fsync = generic_file_fsync, - .splice_read = generic_file_splice_read, }; diff --git a/fs/vboxsf/file.c b/fs/vboxsf/file.c index c4ab5996d97a83..30671e1226dbed 100644 --- a/fs/vboxsf/file.c +++ b/fs/vboxsf/file.c @@ -200,7 +200,6 @@ const struct file_operations vboxsf_reg_fops = { .open = vboxsf_file_open, .release = vboxsf_file_release, .fsync = noop_fsync, - .splice_read = generic_file_splice_read, }; const struct inode_operations vboxsf_reg_iops = { diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 00db81eac80d6c..964bc733e765a4 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1297,7 +1297,6 @@ const struct file_operations xfs_file_operations = { .llseek = xfs_file_llseek, .read_iter = xfs_file_read_iter, .write_iter = xfs_file_write_iter, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .iopoll = iomap_dio_iopoll, .unlocked_ioctl = xfs_file_ioctl, diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c index 07bc42d62673ce..d9f5fbeb55062e 100644 --- a/fs/zonefs/super.c +++ b/fs/zonefs/super.c @@ -869,7 +869,6 @@ static const struct file_operations zonefs_file_operations = { .llseek = zonefs_file_llseek, .read_iter = zonefs_file_read_iter, .write_iter = zonefs_file_write_iter, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .iopoll = iomap_dio_iopoll, }; diff --git a/mm/shmem.c b/mm/shmem.c index a0dbe62f8042e7..f019ff50084403 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3756,7 +3756,6 @@ static const struct file_operations shmem_file_operations = { .read_iter = shmem_file_read_iter, .write_iter = generic_file_write_iter, .fsync = noop_fsync, - .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = shmem_fallocate, #endif From patchwork Tue Jul 7 17:48:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 11649509 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 AD721739 for ; Tue, 7 Jul 2020 17:57:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D5292075B for ; Tue, 7 Jul 2020 17:57:30 +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="qEUvpwxL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728607AbgGGR51 (ORCPT ); Tue, 7 Jul 2020 13:57:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728036AbgGGR51 (ORCPT ); Tue, 7 Jul 2020 13:57:27 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53F92C061755; Tue, 7 Jul 2020 10:57:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=Weuro944qoHsBvfyYbAkCMwQQQFAVhE01qJV6uQvAx8=; b=qEUvpwxLV9Ae+jesGCTc8ddeVN jGipuy3RunNhHETYZHOmVHp5QJdHPMfa4ANtLhcKnGmjgJCvdZ66O6kxxuuxgtTEaAFIxgb7F2PHT sbugZOIJv06LBO6lUw6NEwFsTuejwARoWEo2q+u6t+q+nmJ+pig5LXrTBj0Vr2KjeqViACGMZbUpj 9iIgKq64i99ET+EkzHUOcChRV77Uw0JHFVhLNuJnsyn1aAeBT5Tudzb55y0K5hbY0rspbagi7BAGb 2zk/jttD7JQxE6OhHw4IBKglDFZ1g0QpQZWkYtav2MIUxjqixFt9+l70ZAxGtz1gA7l6jyHH1nF2z mXiUX7RQ==; Received: from 213-225-32-40.nat.highway.a1.net ([213.225.32.40] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsrqJ-0003xp-LF; Tue, 07 Jul 2020 17:57:20 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds , Stephen Rothwell Cc: Luis Chamberlain , Matthew Wilcox , Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 23/23] fs: don't allow splice read/write without explicit ops Date: Tue, 7 Jul 2020 19:48:01 +0200 Message-Id: <20200707174801.4162712-24-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707174801.4162712-1-hch@lst.de> References: <20200707174801.4162712-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Don't allow calling ->read or ->write with set_fs as a preparation for killing off set_fs. While I've not triggered any of these cases in my setups as all the usual suspect (file systems, pipes, sockets, block devices, system character devices) use the iter ops this is almost going to be guaranteed to eventuall break something, so print a detailed error message helping to debug such cases. The fix will be to switch the affected driver to use the iter ops. Signed-off-by: Christoph Hellwig --- fs/read_write.c | 2 +- fs/splice.c | 121 ++++----------------------------------------- include/linux/fs.h | 2 - 3 files changed, 10 insertions(+), 115 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 8d8113ae8561e6..c33182f97d1ef0 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1077,7 +1077,7 @@ ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos, } EXPORT_SYMBOL(vfs_iter_write); -ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, +static ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, unsigned long vlen, loff_t *pos, rwf_t flags) { struct iovec iovstack[UIO_FASTIOV]; diff --git a/fs/splice.c b/fs/splice.c index 52485158023778..3ceaaf3b8c122c 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -342,89 +342,6 @@ const struct pipe_buf_operations nosteal_pipe_buf_ops = { }; EXPORT_SYMBOL(nosteal_pipe_buf_ops); -static ssize_t kernel_readv(struct file *file, const struct kvec *vec, - unsigned long vlen, loff_t offset) -{ - mm_segment_t old_fs; - loff_t pos = offset; - ssize_t res; - - old_fs = get_fs(); - set_fs(KERNEL_DS); - /* The cast to a user pointer is valid due to the set_fs() */ - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos, 0); - set_fs(old_fs); - - return res; -} - -static ssize_t default_file_splice_read(struct file *in, loff_t *ppos, - struct pipe_inode_info *pipe, size_t len, - unsigned int flags) -{ - struct kvec *vec, __vec[PIPE_DEF_BUFFERS]; - struct iov_iter to; - struct page **pages; - unsigned int nr_pages; - unsigned int mask; - size_t offset, base, copied = 0; - ssize_t res; - int i; - - if (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) - return -EAGAIN; - - /* - * Try to keep page boundaries matching to source pagecache ones - - * it probably won't be much help, but... - */ - offset = *ppos & ~PAGE_MASK; - - iov_iter_pipe(&to, READ, pipe, len + offset); - - res = iov_iter_get_pages_alloc(&to, &pages, len + offset, &base); - if (res <= 0) - return -ENOMEM; - - nr_pages = DIV_ROUND_UP(res + base, PAGE_SIZE); - - vec = __vec; - if (nr_pages > PIPE_DEF_BUFFERS) { - vec = kmalloc_array(nr_pages, sizeof(struct kvec), GFP_KERNEL); - if (unlikely(!vec)) { - res = -ENOMEM; - goto out; - } - } - - mask = pipe->ring_size - 1; - pipe->bufs[to.head & mask].offset = offset; - pipe->bufs[to.head & mask].len -= offset; - - for (i = 0; i < nr_pages; i++) { - size_t this_len = min_t(size_t, len, PAGE_SIZE - offset); - vec[i].iov_base = page_address(pages[i]) + offset; - vec[i].iov_len = this_len; - len -= this_len; - offset = 0; - } - - res = kernel_readv(in, vec, nr_pages, *ppos); - if (res > 0) { - copied = res; - *ppos += res; - } - - if (vec != __vec) - kfree(vec); -out: - for (i = 0; i < nr_pages; i++) - put_page(pages[i]); - kvfree(pages); - iov_iter_advance(&to, copied); /* truncates and discards */ - return res; -} - /* * Send 'sd->len' bytes to socket from 'sd->file' at position 'sd->pos' * using sendpage(). Return the number of bytes sent. @@ -788,33 +705,6 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, EXPORT_SYMBOL(iter_file_splice_write); -static int write_pipe_buf(struct pipe_inode_info *pipe, struct pipe_buffer *buf, - struct splice_desc *sd) -{ - int ret; - void *data; - loff_t tmp = sd->pos; - - data = kmap(buf->page); - ret = __kernel_write(sd->u.file, data + buf->offset, sd->len, &tmp); - kunmap(buf->page); - - return ret; -} - -static ssize_t default_file_splice_write(struct pipe_inode_info *pipe, - struct file *out, loff_t *ppos, - size_t len, unsigned int flags) -{ - ssize_t ret; - - ret = splice_from_pipe(pipe, out, ppos, len, flags, write_pipe_buf); - if (ret > 0) - *ppos += ret; - - return ret; -} - /** * generic_splice_sendpage - splice data from a pipe to a socket * @pipe: pipe to splice from @@ -844,7 +734,10 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, { if (out->f_op->splice_write) return out->f_op->splice_write(pipe, out, ppos, len, flags); - return default_file_splice_write(pipe, out, ppos, len, flags); + pr_warn_ratelimited( + "splice write not supported for file %pD4 (pid: %d comm: %.20s)\n", + out, current->pid, current->comm); + return -EINVAL; } /* @@ -870,7 +763,11 @@ static long do_splice_to(struct file *in, loff_t *ppos, return in->f_op->splice_read(in, ppos, pipe, len, flags); if (in->f_op->read_iter) return generic_file_splice_read(in, ppos, pipe, len, flags); - return default_file_splice_read(in, ppos, pipe, len, flags); + + pr_warn_ratelimited( + "splice read not supported for file %pD4 (pid: %d comm: %.20s)\n", + in, current->pid, current->comm); + return -EINVAL; } /** diff --git a/include/linux/fs.h b/include/linux/fs.h index 0c0ec76b600b50..fac6aead402a98 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1919,8 +1919,6 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, 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 *, - unsigned long, loff_t *, rwf_t); extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *, loff_t, size_t, unsigned int); extern ssize_t generic_copy_file_range(struct file *file_in, loff_t pos_in,