From patchwork Wed Oct 17 22:45:38 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: 10646317 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 9AF4B181D for ; Wed, 17 Oct 2018 22:45:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A71D288C7 for ; Wed, 17 Oct 2018 22:45:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DDBC288E4; Wed, 17 Oct 2018 22:45:46 +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 06046288C7 for ; Wed, 17 Oct 2018 22:45:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8F5B6B027F; Wed, 17 Oct 2018 18:45:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D3D046B0280; Wed, 17 Oct 2018 18:45:44 -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 C2C5B6B0281; Wed, 17 Oct 2018 18:45:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f70.google.com (mail-yw1-f70.google.com [209.85.161.70]) by kanga.kvack.org (Postfix) with ESMTP id 8CECB6B027F for ; Wed, 17 Oct 2018 18:45:44 -0400 (EDT) Received: by mail-yw1-f70.google.com with SMTP id c67-v6so17928612ywh.13 for ; Wed, 17 Oct 2018 15:45:44 -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=oYn3TF3+mIKEtXpyeaNeiH3yojLQ1PMr7+lfr4C14OshU4PjWZGIeWPpkNHqD4SDDV c2LuKE1dj2Y+leVq85KUaomef/wRwlsuqL1T6vyJmm4TqXfqzUUmi3yRJ8CE/IihOnk9 /9dY2DQ5T5f1fCn7QybYvDGnyTwoQeKyFbmKdPy+s8KlLGSURtwAd5qARQWtPkoVmgqr 5ipMEAxdzBfGGFWsEwjTjD7JUR/eLbKNf8U1YMs0QPv/06tHTrQlMTgKoyZswcHnltxz KoX8u82Nu2p0OL0U5XwB/rCO+hG4KZKeQR7w9GnVlvJc6HpsXk5II9ldQu68iheN1214 nutA== X-Gm-Message-State: ABuFfohh8ej/flCgGuxzIoSO3XJ0TmIpqsQBvxP8yI824BRlOKfAHTCS qnh5rN8oMtWCg/Yq/arb5b/DGg10JcGBp1s6HV6XvLcFworYnro2SFEBJ47IetxnjbETGrvczJJ aw9eS4vPq6FpqzT+sEHfVDyal5gAn1Fxjg9Z8edkWmeSbLZ3frmrEW+yI/OIyKndmgA== X-Received: by 2002:a81:2287:: with SMTP id i129-v6mr16999608ywi.74.1539816344259; Wed, 17 Oct 2018 15:45:44 -0700 (PDT) X-Google-Smtp-Source: ACcGV60txoGfbls91kIsw9PyLk7zH2iMvPrebi30e2xwYhyn+7hGSwDtD4CNNdEfB9uC32U5WtR5 X-Received: by 2002:a81:2287:: with SMTP id i129-v6mr16999589ywi.74.1539816343749; Wed, 17 Oct 2018 15:45:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539816343; cv=none; d=google.com; s=arc-20160816; b=z2tKg1vmrYeeyRcdNr2j8cooUlWMXF5/AdjEUEs4BlCP1m2S51VApVOdN9WnUNLBW5 1HjrOGnzwSer8jlqEsp+0z7nggOV/AJO7IuK/7IxCVdEe2HejlikZUnkk4oTt4joDvXH /4urYUh+X6/Dmg8CQLcQVHtH0lX9Jsj8iVf5yP5rn7CYtC14aJCtsNy95mV+7j+wr1SX 9csGHIBcqrWmi7lQUhY7FjV9UF6SsP3gwbVNq2vZyQtCRm8enDiUhHsLRIGxrU6SM8A1 x70c18hET3PFMliuQlVoTm8TPjpe8rtDX2NtrKyEpZ4ZImjGL8CyVkqqoXJtEK53dMw2 QgNw== 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=UKrNTsXVjM66Fi65mv3T/yDb8IcK8MwQZkXkxz/AtMcokk57CVaUUgoZDOM46JGXZh hRJ/yAvbePqVu9rSqSzKjwtMW/tEwomdwbYIL0DkulB/zJmlotsbMKMaaPxm+nrrOzOC OtUDPe+SiS1ThZ6GphQfzZcetocxZ47X8GlckUTFiGz6TSrpM6TL8DfFLYVt2LER3oV1 26/GH69Uzy2mIjPlCJ98BpEYjVzzMkLvwbdEMcnapjTZVbDdnQdJnWIZhWT2eViWg7DN YNHG/XwjW795O0lYUk9uV4SkaQIkHC5LgIBNA7wDFFkoSheQL8Wa786KD61H1D8fIW+g LCDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=nZSL7Dos; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from aserp2120.oracle.com (aserp2120.oracle.com. [141.146.126.78]) by mx.google.com with ESMTPS id x125-v6si3386613yba.408.2018.10.17.15.45.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 15:45:43 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) client-ip=141.146.126.78; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=nZSL7Dos; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 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 (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9HMiLH9048920; Wed, 17 Oct 2018 22:45:41 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=nZSL7Dos4JyHJSm01mcLftgKVKykwsGWd3+cEc1eg4k+OBYfJVnbfo+agYL7xCk6vvSB eB4bF7YgyZmSbJvPzL94iyNnJuO3IA9lUnpaJ3Y9pmkj0NxPxJMxbEq1GkhawoK+zb7/ 6iLGrZo2FRaxapmHn56RnDYsLkhRl/j/75Gyvio74EIEgJI//omlTZLtyURFV0avdAgL oTu8oNFNowFb1it/c/vJGBYdspFJvI6Ef7xWswBWOEeWuYk9ldAgtqgPDNvkQjuUVAIK ppU60URUixc55epMd7mURu+UsahTp8BzcX5LhaxcD0ZnW4NrW10eP9b44C9u8BXJZ46+ GA== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2n38nq9sv5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Oct 2018 22:45:41 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9HMjdc1010282 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Oct 2018 22:45:40 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9HMjdil015073; Wed, 17 Oct 2018 22:45:39 GMT Received: from localhost (/10.159.132.177) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 17 Oct 2018 15:45:39 -0700 Subject: [PATCH 12/29] 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: Wed, 17 Oct 2018 15:45:38 -0700 Message-ID: <153981633799.5568.10992236383232225210.stgit@magnolia> In-Reply-To: <153981625504.5568.2708520119290577378.stgit@magnolia> References: <153981625504.5568.2708520119290577378.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9049 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=850 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810170188 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);