From patchwork Fri Feb 12 04:44:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Boichat X-Patchwork-Id: 12084731 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F36CC433E6 for ; Fri, 12 Feb 2021 04:45:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D45BE64E6C for ; Fri, 12 Feb 2021 04:45:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbhBLEp1 (ORCPT ); Thu, 11 Feb 2021 23:45:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbhBLEpZ (ORCPT ); Thu, 11 Feb 2021 23:45:25 -0500 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EC8BC0613D6 for ; Thu, 11 Feb 2021 20:44:45 -0800 (PST) Received: by mail-pg1-x535.google.com with SMTP id j5so5438515pgb.11 for ; Thu, 11 Feb 2021 20:44:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Uwr/8PJUNMrs1DNHiVxSJVanvT/KDCxxvdzqAMfX/20=; b=jDPV6GnSoh0tUu9SL3pV6ZNkNlrVV4nNS5weOpmxNEER4+qGUF4kuWbxGzf7zUe4Q6 0fNbc8n6aPmawRsXKF60jjdrAlO3PQ6/lKXdvfCYNb1N+gAjmCFqexp/zw0kQUWuFKmo tsPTSYVURrDD1QkSKI9JBQAqmySDiCWcOQCeI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Uwr/8PJUNMrs1DNHiVxSJVanvT/KDCxxvdzqAMfX/20=; b=HagFaD67ZHokr6kiMsElOOFrBSmVaF5wwKnvMvcHplVL2h0O6Ameh1saJ1pptylRmf JQUfh3A6v44GkWRXEGdgU4ZnNpEwGGcb5r50vHZ6eYr1Djo7y8Pqbh6cYdyA46Jbi88y Om0MVsEcS78xsxrf5qkOH6VBiOHBbhQgkEaDh6HwkjuXu8sLYndgPzgjB8YBSh6znhMb zKC8qX76EqqSz6wxQwbPMvs4PpENu6gd/Eb9wAffcRFXxApnTm7ZKtrI5YH6Q0RudCck tnf1TCVUIlGmHJpzNNkLKf3Z0QzobNf2OoLUAVSOgQMMRL0yiEH2PxcZ74zwPh7cB71d zpWA== X-Gm-Message-State: AOAM533XtPVHdHT1NROj/TXEKG62/IuO9V/Y+caqBBhB/IiaujHkBnd6 WzD17PHjdKmN65RaDH8B4BgKlQ== X-Google-Smtp-Source: ABdhPJzVzB2K3BQRHbHlI8qUm7OdSQAl5fNCAIJBHSDbPKSvTVB19WkYz5J5ZvETG1Vuz0V/f25kmg== X-Received: by 2002:a63:1965:: with SMTP id 37mr1468628pgz.349.1613105084885; Thu, 11 Feb 2021 20:44:44 -0800 (PST) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:a453:d6cd:41b9:5925]) by smtp.gmail.com with ESMTPSA id 25sm7298904pfh.199.2021.02.11.20.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 20:44:44 -0800 (PST) From: Nicolas Boichat To: "Darrick J . Wong" Cc: Alexander Viro , Ian Lance Taylor , Luis Lozano , Greg KH , Dave Chinner , Nicolas Boichat , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/6] fs: Add flag to file_system_type to indicate content is generated Date: Fri, 12 Feb 2021 12:44:00 +0800 Message-Id: <20210212124354.1.I7084a6235fbcc522b674a6b1db64e4aff8170485@changeid> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog In-Reply-To: <20210212044405.4120619-1-drinkcat@chromium.org> References: <20210212044405.4120619-1-drinkcat@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Filesystems such as procfs and sysfs generate their content at runtime. This implies the file sizes do not usually match the amount of data that can be read from the file, and that seeking may not work as intended. This will be useful to disallow copy_file_range with input files from such filesystems. Signed-off-by: Nicolas Boichat --- I first thought of adding a new field to struct file_operations, but that doesn't quite scale as every single file creation operation would need to be modified. include/linux/fs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 3482146b11b0..5bd58b928e94 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2335,6 +2335,7 @@ struct file_system_type { #define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */ #define FS_THP_SUPPORT 8192 /* Remove once all fs converted */ #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */ +#define FS_GENERATED_CONTENT 65536 /* FS contains generated content */ int (*init_fs_context)(struct fs_context *); const struct fs_parameter_spec *parameters; struct dentry *(*mount) (struct file_system_type *, int, From patchwork Fri Feb 12 04:44:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Boichat X-Patchwork-Id: 12084735 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 388D8C433E9 for ; Fri, 12 Feb 2021 04:45:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CBEA64E6B for ; Fri, 12 Feb 2021 04:45:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229733AbhBLEpl (ORCPT ); Thu, 11 Feb 2021 23:45:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbhBLEp2 (ORCPT ); Thu, 11 Feb 2021 23:45:28 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75052C061788 for ; Thu, 11 Feb 2021 20:44:48 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id o7so5465373pgl.1 for ; Thu, 11 Feb 2021 20:44:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kOCq94xjVzI4ceYxRuWCABPovXysMtiBjdG9BO6ZZlk=; b=YFLT2F+J3RvMBDSiUHuypueB0DK/XGg7G87wgW+rPVjaHKPEEMXI6pHivuc83P91bE kMLIh6M0HtmB+EqZNhXx8eoQnJCEoy1eUXnUxMxjpVTr74I6Q4FoQDJQkOySytnwuLdy R55uL0VGEYvuO4NVzPP+pMQ1ef5edLP85FnNk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kOCq94xjVzI4ceYxRuWCABPovXysMtiBjdG9BO6ZZlk=; b=YdwUtZfmFl9ohAhkLAAILtat330qiLDhGkUJ1bysHSZzUWbh1htLaD3U00oGOSngv6 ATRr0+j9x0N3zGZLwOduJljeZZicuLORrIsEWCDEWQZGmDsrxv+EnLeDyBt3KVcCDlyw uMVOjtARSXjO/DQyIQyigGiJU4MXwt2fQx3M3l5qPZyuLagWLxKbhClwJZrQ2A2bqOOj 4kYWwUkKGankww1xEUo2Zz0lLaj+jTRWXBki6jUS+66teG2e4/K9MSJ8MghKcLo3RrpS oKHnK4pLyZ/5PLAI7CeU+lnNwiJ9+5Ach0mRPjUhYezeaysXOUdPecYpppK0VGRYWAfX Xa8A== X-Gm-Message-State: AOAM531dhA0vMfk8QA+6IGuFQ82VEDioYuRKE2a3yGrDiJFAheShvrbz kBq8j7RlWNyom1R7rp98QSSnkw== X-Google-Smtp-Source: ABdhPJyDqCSgz7B7i5HFEOaYVmF8gpNgKK8UqSgtygiJmq1OSOo2Gge9hjbzPGZv5mCs18fovQKXMg== X-Received: by 2002:a62:43:0:b029:1cd:2de2:5a24 with SMTP id 64-20020a6200430000b02901cd2de25a24mr1403879pfa.27.1613105088055; Thu, 11 Feb 2021 20:44:48 -0800 (PST) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:a453:d6cd:41b9:5925]) by smtp.gmail.com with ESMTPSA id 25sm7298904pfh.199.2021.02.11.20.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 20:44:47 -0800 (PST) From: Nicolas Boichat To: "Darrick J . Wong" Cc: Alexander Viro , Ian Lance Taylor , Luis Lozano , Greg KH , Dave Chinner , Nicolas Boichat , Alexey Dobriyan , Alexey Gladkov , Christian Brauner , "Eric W. Biederman" , Kees Cook , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/6] proc: Add FS_GENERATED_CONTENT to filesystem flags Date: Fri, 12 Feb 2021 12:44:01 +0800 Message-Id: <20210212124354.2.I89f693bbe7011553bfac5fedd88d2fc7398be61b@changeid> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog In-Reply-To: <20210212044405.4120619-1-drinkcat@chromium.org> References: <20210212044405.4120619-1-drinkcat@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org procfs content is generated at runtime. Signed-off-by: Nicolas Boichat --- fs/proc/root.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/proc/root.c b/fs/proc/root.c index c7e3b1350ef8..7ed715a0f807 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -282,7 +282,7 @@ static struct file_system_type proc_fs_type = { .init_fs_context = proc_init_fs_context, .parameters = proc_fs_parameters, .kill_sb = proc_kill_sb, - .fs_flags = FS_USERNS_MOUNT | FS_DISALLOW_NOTIFY_PERM, + .fs_flags = FS_USERNS_MOUNT | FS_DISALLOW_NOTIFY_PERM | FS_GENERATED_CONTENT, }; void __init proc_root_init(void) From patchwork Fri Feb 12 04:44:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Boichat X-Patchwork-Id: 12084737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68354C433DB for ; Fri, 12 Feb 2021 04:46:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 251D264DCD for ; Fri, 12 Feb 2021 04:46:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbhBLEqK (ORCPT ); Thu, 11 Feb 2021 23:46:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229758AbhBLEqG (ORCPT ); Thu, 11 Feb 2021 23:46:06 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05746C061797 for ; Thu, 11 Feb 2021 20:44:57 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id e9so4495869plh.3 for ; Thu, 11 Feb 2021 20:44:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gf/FNE2g9dFP9p3d4PnxWCRqpKSooOmCgY06BBUWQtQ=; b=D1dJ9Pxbb6GQULURKHNuG77hzlfdpyFwDfIJR/kdcgaKOm7QeDaVsVh7BxWEKBMFBQ TUh8hYE6LSrIJiTUxYE1NFvVpRrVqU65AVZVLxKlVm/Jyec+M8CIhJ/j354uZZVbTf34 E4dy5KCHzyiapdvYwXs32ylZGzOeG5skr/tNo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gf/FNE2g9dFP9p3d4PnxWCRqpKSooOmCgY06BBUWQtQ=; b=VbbWYRN3Y0ff7GCy5w2n5nWa7CAlMSphHP45naAvXMYt1wBX1jkgXszJiCY/NHk0I8 AJJBiWs7X8XkhEiu+8r1EXYmnsb9hq905U0PA3X7Icwla3SobMbnfSi+oCg/xB33aEJD HuP8adM2U98yqqUYsxjceazCiL/UE5gpukqt31xv5Uz9/fbkulvkz7/sZ7lugRvB7NRx EN7kIURNIXjw4yedlXiGuLBM8lGjEyNnn8B2iL4HHGp8MM1YvMfFuCZipdXzi/4i2g1b dIdWaGqb1s6DVAre4sTXDaVGt/bWHcthqurRODTWNBrDdqFK3xNqyDudxht6SrwvHlg9 Pm8w== X-Gm-Message-State: AOAM533MQIo78a0jyiucVpvuz43C7o/fUPR7oVaLUf24ZUDr1zSBbz6S 24txDHytoncbtKIu9ycR2YC1cw== X-Google-Smtp-Source: ABdhPJytZbcYqZrhtmpGfcJw/baVcFRWjDI0lVpoG2xuV81ph0vrPS4VW5luUG9QLhZoW8KGx2d7Lw== X-Received: by 2002:a17:90a:9310:: with SMTP id p16mr1102823pjo.211.1613105096610; Thu, 11 Feb 2021 20:44:56 -0800 (PST) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:a453:d6cd:41b9:5925]) by smtp.gmail.com with ESMTPSA id 25sm7298904pfh.199.2021.02.11.20.44.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 20:44:56 -0800 (PST) From: Nicolas Boichat To: "Darrick J . Wong" Cc: Alexander Viro , Ian Lance Taylor , Luis Lozano , Greg KH , Dave Chinner , Nicolas Boichat , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] vfs: Disallow copy_file_range on generated file systems Date: Fri, 12 Feb 2021 12:44:05 +0800 Message-Id: <20210212124354.6.Idc9c3110d708aa0df9d8fe5a6246524dc8469dae@changeid> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog In-Reply-To: <20210212044405.4120619-1-drinkcat@chromium.org> References: <20210212044405.4120619-1-drinkcat@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org copy_file_range (which calls generic_copy_file_checks) uses the inode file size to adjust the copy count parameter. This breaks with special filesystems like procfs/sysfs/debugfs/tracefs, where the file size appears to be zero, but content is actually returned when a read operation is performed. Other issues would also happen on partial writes, as the function would attempt to seek in the input file. Use the newly introduced FS_GENERATED_CONTENT filesystem flag to return -EOPNOTSUPP: applications can then retry with a more usual read/write based file copy (the fallback code is usually already present to handle older kernels). Signed-off-by: Nicolas Boichat --- fs/read_write.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/read_write.c b/fs/read_write.c index 0029ff2b0ca8..80322e89fb0a 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1485,6 +1485,9 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, if (flags != 0) return -EINVAL; + if (file_inode(file_in)->i_sb->s_type->fs_flags & FS_GENERATED_CONTENT) + return -EOPNOTSUPP; + ret = generic_copy_file_checks(file_in, pos_in, file_out, pos_out, &len, flags); if (unlikely(ret))