From patchwork Tue Oct 16 03:19: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: 10642875 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 871E317D2 for ; Tue, 16 Oct 2018 03:19:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC7DF29ABC for ; Tue, 16 Oct 2018 03:19:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE3DD299BC; Tue, 16 Oct 2018 03:19:36 +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 67BBC299BC for ; Tue, 16 Oct 2018 03:19:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F18D6B0279; Mon, 15 Oct 2018 23:19:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3A2A26B027A; Mon, 15 Oct 2018 23:19:35 -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 269BA6B027B; Mon, 15 Oct 2018 23:19:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id DC2B36B0279 for ; Mon, 15 Oct 2018 23:19:34 -0400 (EDT) Received: by mail-pl1-f197.google.com with SMTP id f59-v6so17185626plb.5 for ; Mon, 15 Oct 2018 20:19:34 -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=2Mwz+Jm1Vv6DSly8RfSjLjmTysY9FOE+4U51VEcOuGA=; b=i2pii+QHhOuDVy/oESSaAf/3sh/EOH99YOyLoh3ZR9GkzRHlcblss4ZVvqk85lrM7G 2aeIMxYunWxO0v1EA/rwOoxzqGe/w5IHQXY1BUay/f18XbuIkHx+bhmibMu6uwqrAYEM f4APEGHO2g12eFDhL9yrqgkXoVgTlHSvel99I/1MmOi9xYEtuYwMc1mtdoCVhbzDemKS 8Lb0t+maYIRh2yNXj561SmnTnLtAI/fGNYDhe8rifJ3FpaAGFpnyJTPEbq+3GvHWFMp6 9fho37llu5W2bgk4M4jb879IFBrdneyiZ5r0NC6Tr/PSzfmJ3dvnmDmXq8Ykk5fC8PmR 2NbQ== X-Gm-Message-State: ABuFfoj7VwRz5W3w6Yfb0QByDyqv/8dnWVhcrE6Fd8rCoiHI/WZKuE8N +PIPohCazVl6NqDKSgc0aycOrs8Kt8fvanEc2dTf1UmqnMhVmYdZXvzOFSgV1ePpDCy+W6bnTI/ DOfcymt9hXN/wfTqUahkbhXEI06XpM5ycDhbrrMgrpHNCcEev4RDgcZBQCk1qCAI9hg== X-Received: by 2002:a17:902:9a07:: with SMTP id v7-v6mr19147657plp.14.1539659974253; Mon, 15 Oct 2018 20:19:34 -0700 (PDT) X-Google-Smtp-Source: ACcGV630UFWCi0iXyB7vi/vmICsu24UDCmtJz/WxUjhQsM/GqeW3oS9evCVJ/gnj8pC2+r9tcyMQ X-Received: by 2002:a17:902:9a07:: with SMTP id v7-v6mr19147625plp.14.1539659973417; Mon, 15 Oct 2018 20:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659973; cv=none; d=google.com; s=arc-20160816; b=M+pOq+K2NQZZ4ZqfA/qsUQvrX57Hn11d3+pLzMex51F/xQ2Zh8DpopFJnftrQuy6L+ ZzptF1MsH9ersGMjSA9FpHxTCqdgDjnOSptdNas/0sj6rwozqCxWFPuOS6WG5B46w+y9 8XYYBcYYUvxs1R1x5i/WKSzX+H5CLLw6lLocAv2s9xkihV5+IdLPag967PpaoePDynEE FD6MQtoH6wD8MgsQLtBCVeZXVfXAUCvWdmWNWGaEQ048+9C3E1djuZY6Mzr3ZKywf7oH K2SAgHryC5OTgrJlM4k0+Zyr60PJfZQEgKnLZGt5cDNjHDIjJ3UTD7xd5a4lUOuYrnkH eonQ== 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=2Mwz+Jm1Vv6DSly8RfSjLjmTysY9FOE+4U51VEcOuGA=; b=bZ+f4GPk9FrR3ceItmgXsUAzBnI3FaOd7V7WIS3oDcttZUbdN7D0TZD3Z2yWWKYygw GJqPpy5MIwUMRRl9lLuyPt/gk3+MCebcvLZYLtkCm/h5LQLH0sr80T9OOpGvn+QBDntI tDZXj0MZqsFE8QZg1uBSvjrE3ANvN/ukEiOArfHCmcOKuKX0TJ0mqtItqel4PuIJIJ4i eDqZo7Dlar3qJLHqLAXS5YwPJMr6+2NEe/kdLjDoU0Fl0RrcYJxYRbwUv3kh6/2FZg33 QvsrTw6gU5xJ0iO+gRt1vR4IorfjrFfOFhFdadxZbRTrJeh9vml7M5zc36U2wVH8Zt/a hDLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=QyfeosX1; 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 l91-v6si12934147plb.315.2018.10.15.20.19.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:19:33 -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=QyfeosX1; 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 w9G3JMpO060270; Tue, 16 Oct 2018 03:19:31 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=2Mwz+Jm1Vv6DSly8RfSjLjmTysY9FOE+4U51VEcOuGA=; b=QyfeosX11lkm+R6FJaSex5a7QxpympeeUy+dEEs9LKcGmvkOjbmr5b5J42Y4L8kKr8jP MWHQFqrh7+0Btd+SC4wQED5K+Z7Qao9bJJuFGTprbpx7sofYa7z8KCZXd+7Ij4P7EK7K Cf8tB5t/gAlpy1jcqWV+QKaLlLUtV1HRm9m+rcUt90RHgqeIcq3QMawvy3a2XTE4v0UE Oo3BAZ/uV/C3sUdMJ0/03DTL9bkT0Klnm3D4tD8cmX79Rf3eoAVBfw6w+O18hAEHE40G 5qhtdTc/xjY9MDG3MQXzblfJtk8pVlt2ZitpFkBAoaLtI84yG1vMR1/rdJltfHCrfRYQ /w== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2n38npwvev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:30 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3JTuR003181 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:29 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3JSGX007232; Tue, 16 Oct 2018 03:19:28 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:19:28 -0700 Subject: [PATCH 13/26] vfs: create generic_remap_file_range_touch to update 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: Mon, 15 Oct 2018 20:19:26 -0700 Message-ID: <153965996673.3607.133184523000924340.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=853 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 Create a new VFS helper 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. Wire up ocfs2 to ensure consistent behavior. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein --- fs/read_write.c | 28 ++++++++++++++++++++++++++++ fs/xfs/xfs_reflink.c | 23 ----------------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index ebcbfc4f2907..3f6392f1d5d4 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1737,6 +1737,30 @@ static int generic_remap_check_len(struct inode *inode_in, return 0; } +/* Update inode timestamps and remove security privileges when remapping. */ +static int generic_remap_file_range_target(struct file *file, + unsigned int remap_flags) +{ + int ret; + + /* If can't alter the file contents, we're done. */ + if (remap_flags & REMAP_FILE_DEDUP) + return 0; + + /* Update the timestamps, since we can alter file contents. */ + if (!(file->f_mode & FMODE_NOCMTIME)) { + ret = file_update_time(file); + 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. + */ + return file_remove_privs(file); +} + /* * Check that the two inodes are eligible for cloning, the ranges make * sense, and then flush all dirty data. Caller must ensure that the @@ -1820,6 +1844,10 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, if (ret) return ret; + ret = generic_remap_file_range_target(file_out, remap_flags); + 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);