Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2681346pxb; Thu, 11 Feb 2021 20:51:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhgwKYTY+bw3mcY2IPH6C8A3Q9ZNZZ8UyIr6tQR96o/kCu4HezCKIlwQpJlO1uakT1tqt6 X-Received: by 2002:a05:6402:10c3:: with SMTP id p3mr1481569edu.67.1613105461382; Thu, 11 Feb 2021 20:51:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613105461; cv=none; d=google.com; s=arc-20160816; b=Mkbri4myt2TLbvs7sLqWoY4OyHEmfc60LPdKJpsHByDuT4fTP58VWDOwobVnp7225H 8T57++G7M5EyPPuus9Y+GWxje0nKtC1GCENHrJeCyfCXeTc8cV3SRCOKrop0yOXJx+DG +pP7aOQuq61Hj54RR33hJz9sN3vL79B/Ft9Pg4jE/mlWDrRifJaYiCy2yNyky2i3JJY1 bdM1R78yqnyfU3N91s2XbfGwAaBBwaRzPwzfrHJG7LLh1Xh3uZ/UPCTefAun0mq6ymnh 1phDuR4/9dptCc673jhgPf2Qc/+pe5I3Bdb49CykR+C52t8Mtf0p6QnMZOD117R1nreK KlIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gf/FNE2g9dFP9p3d4PnxWCRqpKSooOmCgY06BBUWQtQ=; b=dIynyzHa3l1C96XuaJeiXY+sSYdpry72zJy6fAVmJZppVLwNc/U31RTOTlXlsxpK/4 uWbSfkqR2TyYZjbEqh4D72mSUP04x8go9cVXzIUzjY3UAhxvWvxKT/Cr+7mLbXq9hubY wNIhXuO4/JyfT9JW9Ph/IwQukqOM/Wz76vET9Mknlah8tclY+1nop6Xjr22eFuve2H52 oAXjG9qwTaLCvnq82C/q6MpVT81iC+sp+HWi4eiw/UpbCp4H+KjNnak2f2pencggTxtc IyZ4Hj5aISY5ygeLj+AfiP9tR7v7upCsW1f7b+xc+H2HwpXdUUeCE4cy0C7RcAczV32l rSMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=D1dJ9Pxb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n20si5392125ejj.318.2021.02.11.20.50.38; Thu, 11 Feb 2021 20:51:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=D1dJ9Pxb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229864AbhBLEq5 (ORCPT + 99 others); Thu, 11 Feb 2021 23:46:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229744AbhBLEqG (ORCPT ); Thu, 11 Feb 2021 23:46:06 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0459FC061794 for ; Thu, 11 Feb 2021 20:44:57 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id t2so4681072pjq.2 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=Cw592wsI+mwC2/diEcax+XaceN26KBPmvSoFDe5qRDkg6loaCMSRzyytNm/SUd4vq/ uZ8EbmUfeOPC+iqPZ55Njr+hJbuQVeOXSTMG8xxIuWvf7OIvTMk97/aciuw8FyOWZfZY 7mCo3dnzFOE9o+xU8ZQQB7ApjYtrXHTQZirO0NIRbaPpIJB1BTDw2UaZ5H49CS4tidAF W604Bim3v5uFNIAnluqqz2GB9nqx5kK06bNhg/A4ksWp5jrWvjoVZcEnZx3L8U3NWjn4 dKJkkfdfGzFuaV3yu02nvf/T4inEEJFti8JVntJ0ap2MAMmA1un93ZVV7q8QYtqCQf6g fa/A== X-Gm-Message-State: AOAM530UXUSB8QZECfMSWP8F1MDaRrzFQiLcuIwPQOjxuKyZpZ6wPb1l NVXdZ6t6cJEYBUCOFgpTJiHXaw== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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)) -- 2.30.0.478.g8a0d178c01-goog