From patchwork Sun Oct 21 16:16:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10651061 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B53714E2 for ; Sun, 21 Oct 2018 16:16:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28C26287BE for ; Sun, 21 Oct 2018 16:16:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C35A287C2; Sun, 21 Oct 2018 16:16:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C6CB287BE for ; Sun, 21 Oct 2018 16:16:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76DEB6B0008; Sun, 21 Oct 2018 12:16:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 744C16B0271; Sun, 21 Oct 2018 12:16:33 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6361F6B0272; Sun, 21 Oct 2018 12:16:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f71.google.com (mail-yw1-f71.google.com [209.85.161.71]) by kanga.kvack.org (Postfix) with ESMTP id 309466B0008 for ; Sun, 21 Oct 2018 12:16:33 -0400 (EDT) Received: by mail-yw1-f71.google.com with SMTP id c67-v6so25778646ywh.13 for ; Sun, 21 Oct 2018 09:16:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=JKTdos3g9sr+caRIKtd3XTJY6SNyMhNBCwtE8oUJnVs=; b=ukymqy/ykonK0atl5AKpz4PmbaW3MQXNK4UTcNTPbXgIhe1MJtXxs469s41faPzRQT mkgDJ/1RrHo1Rn01UZfIO6J0PeNi0dTW7T1+1KtrUc+NId7SjTmf65WUL/QpTiyEktKs uGpxNjEjDRtxhHtlOguzttKI99FVl+aLjJqhyV6A+oVoW5A2JyfCqmeULIZn4qf5tYZm HocjGu8FONK5vSNGhee8saT6kproYznjv7xBgeeChx9Gv7wv2qi4BAOrCnLqwGyxmoOt Euu5z4jhvJEPyI4bQNP4dYuxZhW4XSLLGBIGFY1UTtPbEYLdaMwlKKoHarw31rTn0hil +z5Q== X-Gm-Message-State: ABuFfojnt0wc86h+SVjHRiG1xBFBzs0/5UMbNj03ktLmc0aogiBD5GX6 mEfgapa1aM7KKHmsZUchSLMoP116IhxpShB0JeR0qMHNwr/kt3VnIkIkkMRNx3UtTiTiKYAAn07 Wlm5HvtKfmqRdEPOamz6cSNxJbbLIMCto/gKYebRntB/+ND0pmuhd6pUBJmhV22SX2A== X-Received: by 2002:a25:6b4e:: with SMTP id o14-v6mr8560969ybm.158.1540138592942; Sun, 21 Oct 2018 09:16:32 -0700 (PDT) X-Google-Smtp-Source: ACcGV60LzOMEFDXl/Q5CmecgDWGKqn2LzAimRNd6FoUHzFxS5jnNpaDFMZ4CwLn3Eet8zj81Qv2Y X-Received: by 2002:a25:6b4e:: with SMTP id o14-v6mr8560935ybm.158.1540138592341; Sun, 21 Oct 2018 09:16:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540138592; cv=none; d=google.com; s=arc-20160816; b=gNDBRgAOIJVorNSUhVUVey264aS7dMR8Yx5HIfmFy5TFtmVRRopszgOvp+EHGr5Dk4 wp4KGqrLoQgZFrDiGc7o/81MGl+HDTiAv7gzyVKsSLQXTO1EKRCP1hAJ9hvqOu1tjqCk 7+ePHCazArCuhZDXmqy2uasT2DkpibUFQFNAW6omTb312S4BeVCjwWl7jDw0O+oe7QdG L6gD/58Pl1mauCpDqzCnTjRbnDzprokCF+xF9v1uzmqhGhnnsd9Yw2dDaSGBWDEh81FV sS6VPA/fZj9VM4bY5AyieEcwmFjwCeUbY3N3v0gfsBnNSyeJogcxod2eyDZ6vCZYVytl 4EXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=JKTdos3g9sr+caRIKtd3XTJY6SNyMhNBCwtE8oUJnVs=; b=mylW4snwitdflotZuCITAMzpW0It1LymFuiZcdlUi9UUCJHl+mYTyalsfzDcvsoF1d O+Gag8zzp47x2Ncf2Ju5qy04GdP6E4XqVKi4+HGyb5B/E+T8v/e5vhGOZe2KnvJTd1tV 4eox6nP1kCn2Clk/Ssx0FyxE1zrUDegqCJdYqV1R0MsQsfKCJuXzwhRTK+vIvJaNpsLR fCEcYpKNhwKZ6b2VY04XBSlPIFP5eMYi5krLx95gLts4+ZRK72zBQUfcXzZzyXYtyqa5 Nx1LhJAyTiWAexsABjBXd2uiWkturGsVRckncgP7vlbiqscVl2Jex2wVvJhUEoWvtREr kpzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=Q2DkFSC0; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2130.oracle.com (userp2130.oracle.com. [156.151.31.86]) by mx.google.com with ESMTPS id w6-v6si13273203ybl.150.2018.10.21.09.16.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Oct 2018 09:16:32 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) client-ip=156.151.31.86; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=Q2DkFSC0; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9LGEsJL154505; Sun, 21 Oct 2018 16:16:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=JKTdos3g9sr+caRIKtd3XTJY6SNyMhNBCwtE8oUJnVs=; b=Q2DkFSC0hVVLtFHZpR+NYqXPbdkwGDg/Tm0SAy7SQGYYAerjF3rwxSMbHBGk6f/+fmLg diVl5wWmoc6UWkzxYJcCIvHrsLSWW85B9HR7MbjL/ZqlKaDt4gjeAYLcKsYnsImJoA2a Nyy0+7t1hPmGfVaf1ymDHgbv/0P8Myj/GWTDr6pZsC+EKoGL6LUQXop+RMw4SL+NUE/S GHhjluXW8LJYlyV9/GSXx3Dk1kMbfy1buNJn+elYsELswpcRsmfqrPcBho1BIYVhdB4H 1o1jw1OQBqFdMrUS3etymkCQhJNbgsd0lRV71NucMpG6kKftH12mbIQ1P59PBB5B3mGr /A== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2n7ustu1t6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 21 Oct 2018 16:16:30 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9LGGTvU026218 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 21 Oct 2018 16:16:29 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9LGGSEZ021255; Sun, 21 Oct 2018 16:16:28 GMT Received: from localhost (/10.159.225.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 21 Oct 2018 09:16:28 -0700 Subject: [PATCH 12/28] vfs: remap helper should update destination inode metadata From: "Darrick J. Wong" To: david@fromorbit.com, darrick.wong@oracle.com Cc: sandeen@redhat.com, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, Amir Goldstein , linux-unionfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com Date: Sun, 21 Oct 2018 09:16:26 -0700 Message-ID: <154013858694.29026.18365355055791584652.stgit@magnolia> In-Reply-To: <154013850285.29026.16168387526580596209.stgit@magnolia> References: <154013850285.29026.16168387526580596209.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9053 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=867 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810210151 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Extend generic_remap_file_range_prep to handle inode metadata updates when remapping into a file. If the operation can possibly alter the file contents, we must update the ctime and mtime and remove security privileges, just like we do for regular file writes. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein --- fs/read_write.c | 19 +++++++++++++++++++ fs/xfs/xfs_reflink.c | 23 ----------------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index ebcbfc4f2907..b61bd3fc7154 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1820,6 +1820,25 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, if (ret) return ret; + /* If can't alter the file contents, we're done. */ + if (!(remap_flags & REMAP_FILE_DEDUP)) { + /* Update the timestamps, since we can alter file contents. */ + if (!(file_out->f_mode & FMODE_NOCMTIME)) { + ret = file_update_time(file_out); + if (ret) + return ret; + } + + /* + * Clear the security bits if the process is not being run by + * root. This keeps people from modifying setuid and setgid + * binaries. + */ + ret = file_remove_privs(file_out); + if (ret) + return ret; + } + return 1; } EXPORT_SYMBOL(generic_remap_file_range_prep); diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 29aab196ce7e..2d7dd8b28d7c 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1372,29 +1372,6 @@ xfs_reflink_remap_prep( truncate_inode_pages_range(&inode_out->i_data, pos_out, PAGE_ALIGN(pos_out + *len) - 1); - /* If we're altering the file contents... */ - if (!(remap_flags & REMAP_FILE_DEDUP)) { - /* - * ...update the timestamps (which will grab the ilock again - * from xfs_fs_dirty_inode, so we have to call it before we - * take the ilock). - */ - if (!(file_out->f_mode & FMODE_NOCMTIME)) { - ret = file_update_time(file_out); - if (ret) - goto out_unlock; - } - - /* - * ...clear the security bits if the process is not being run - * by root. This keeps people from modifying setuid and setgid - * binaries. - */ - ret = file_remove_privs(file_out); - if (ret) - goto out_unlock; - } - return 1; out_unlock: xfs_reflink_remap_unlock(file_in, file_out);