From patchwork Fri Jun 21 23:56:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11010831 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 B6A6C76 for ; Fri, 21 Jun 2019 23:57:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A49A428BAD for ; Fri, 21 Jun 2019 23:57:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98D3828BB1; Fri, 21 Jun 2019 23:57:15 +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 00ACC28BAD for ; Fri, 21 Jun 2019 23:57:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F004F8E0003; Fri, 21 Jun 2019 19:57:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EB1BF8E0001; Fri, 21 Jun 2019 19:57:13 -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 DA0458E0003; Fri, 21 Jun 2019 19:57:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f198.google.com (mail-yb1-f198.google.com [209.85.219.198]) by kanga.kvack.org (Postfix) with ESMTP id BAED38E0001 for ; Fri, 21 Jun 2019 19:57:13 -0400 (EDT) Received: by mail-yb1-f198.google.com with SMTP id l1so5443609ybj.18 for ; Fri, 21 Jun 2019 16:57:13 -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=twjcs7hmw0I/0y9CON1SwlujfVo0pxMu7JFwyONml5Y=; b=I3ikONdIc0QlsqS1XqzmlxUGRgvTjcE51o7ca3RFysMrzaS9wC7mYjYked7/VSb327 p17PY9cS+fK1/pINBMk3JwyBnP5gHaGmFNzpBuxcf4Y1nD/pVj152hzwxoldxqae0yVT gpcQb6XJRhQa9qOX2q7G1DNLtshGAr7R44Htmdxv8WmMyeaLQhQYnl145lkTO8THmXjL rOM0PRSZWHLuhufFxfB/9N8FHjCF1gaVhElEyDeCB9Rrk5wk1uDpabtMZTci+mIjHlAf qj4CXo5c8Ai9LnS6gMJ+cyAjMzNhAWAMgsZa9IRyha6k5cU1p+c99eFBsTWE1D4MvMZ6 M6PA== X-Gm-Message-State: APjAAAVCIDC8DEakGR4kZDuERLn8jVJ4fNqu3kOAQnxm5lrGEPZvaR0R nBJRT4GLj1qs1rwMD+vex0w3pIHVOSIEcDAOfBQQLVjPJDbjwqSlDdLEdXJhN+lQHnUR9VbpcqO j98M6iFwSIPJCu8dWbwAzR8EIj53dDSsJ4RUl5FHGMd1G8YY0U+OTKorN1f1guUKX5w== X-Received: by 2002:a25:e64f:: with SMTP id d76mr76250406ybh.473.1561161433419; Fri, 21 Jun 2019 16:57:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyzVdRdDhW2QWqxoUIaFTJLFsPBrzGYytJBtuJZ+rHzTm0OgSSAwm9xXdPFZ2asCK2F6COA X-Received: by 2002:a25:e64f:: with SMTP id d76mr76250390ybh.473.1561161432704; Fri, 21 Jun 2019 16:57:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561161432; cv=none; d=google.com; s=arc-20160816; b=trFYMKgNL3SUM9SnhGu6tQrnqlwZYTvxxUkURAsKyhiQPSusQsNdj6jrXrMNiYs6Ak GL+RWidKKzBwJXcLcUlj8F0W2gTu6mW6Ps1JMbbdFWAUHs7WH4ZW0o3HowWpYvY7rrrx a3CNgBFUFuauIWUEeb+cSB5ESVJarGu1kGcBw5+MZ6+2hU95JAmwRilDmeBniiFnecIz wxhgVgd7fgrOIpcHhIhJ0t8geAdKZcnaTZnAdzIovqWzhAEJKc8T+AtdaOOqppCRqLVX 3IvLrWrE5a+65Juopr22ZKS/Ey/njj/EJCVO0d8t8P9ehCvh4lU4/Edjy9y3jboUxQYt uNqw== 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=twjcs7hmw0I/0y9CON1SwlujfVo0pxMu7JFwyONml5Y=; b=efp7Ww7xaax+yaDGNyw1tGZTfqetuAPTCy4B4hSt3EzTe2x6n7G5lSGKhUHF3m1E34 xrQ11MtdqpMrrvbcJ4XVneRMoa0X7rDvvMBo5+KTz9lUaKMw2Ya7Y2zi+GlTJgFKUaEw JMnfjRZntM0i+TNsgljcXQ/DCPJ+S5ogHhfrQ6PJ7xkCoofZboSDzo/TjGriJHlmBcIM EAvv6+1lA6lUTA8ovhmHgDuUSIWIegmAz8Kdrwyq06vxQKiL0dJhcyk+O/ita1AD1blj RaxuYv37gT/3Vo3xtknHDkcXbG4I2fa/L59tZP2Ypmm/b7MgKwt1ATnbDn/SsV+6k7P/ NnFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=EN0d442h; 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 v15si1477885ybk.403.2019.06.21.16.57.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 16:57:12 -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=EN0d442h; 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.27/8.16.0.27) with SMTP id x5LNtT3B053502; Fri, 21 Jun 2019 23:57:05 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=twjcs7hmw0I/0y9CON1SwlujfVo0pxMu7JFwyONml5Y=; b=EN0d442hHQvSNNdl/RDvWSv64qxAaUqBJ+XWzb9wmHNittQOUUWson32FwnA5XsOJ7B1 iGsLJuG230CgcItr8GkMiTTOOQPd++pT+F2FFKTrjIIUW23zuCjPo4q9zWJSRjhtqh4y tHUs2KjIj99SfJcNC3WfbXVxr7c5JoLZ6M05US2Y9VlFyVrcg+sjXlOJohNfSt1B3GLs aTA1JLQMueHt86DwwYNKh4l87ElhhVid89sOr4rk8MXfz9FIGnNxYLjrMalcbFp/7Ylc 5dsT5NuF7PizftC8G7G17VjxcDrejTJ0B4mzo+6ilFAPLgyMkxYtyhCXIMImzP87l7n9 2g== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2t7809rswm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:05 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5LNtKFi168028; Fri, 21 Jun 2019 23:57:04 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 2t7rdy0612-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 21 Jun 2019 23:57:04 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.27/8.16.0.27) with SMTP id x5LNuhUw170079; Fri, 21 Jun 2019 23:57:04 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2t7rdy060u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:04 +0000 Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x5LNv2Il019145; Fri, 21 Jun 2019 23:57:02 GMT Received: from localhost (/10.159.131.214) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 21 Jun 2019 16:57:02 -0700 Subject: [PATCH 1/7] mm/fs: don't allow writes to immutable files From: "Darrick J. Wong" To: matthew.garrett@nebula.com, yuchao0@huawei.com, tytso@mit.edu, darrick.wong@oracle.com, ard.biesheuvel@linaro.org, josef@toxicpanda.com, clm@fb.com, adilger.kernel@dilger.ca, viro@zeniv.linux.org.uk, jack@suse.com, dsterba@suse.com, jaegeuk@kernel.org, jk@ozlabs.org Cc: reiserfs-devel@vger.kernel.org, linux-efi@vger.kernel.org, devel@lists.orangefs.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, linux-mtd@lists.infradead.org, ocfs2-devel@oss.oracle.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org Date: Fri, 21 Jun 2019 16:56:58 -0700 Message-ID: <156116141836.1664939.12249697737780481978.stgit@magnolia> In-Reply-To: <156116141046.1664939.11424021489724835645.stgit@magnolia> References: <156116141046.1664939.11424021489724835645.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9295 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=315 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906210182 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 The chattr manpage has this to say about immutable files: "A file with the 'i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file, most of the file's metadata can not be modified, and the file can not be opened in write mode." Once the flag is set, it is enforced for quite a few file operations, such as fallocate, fpunch, fzero, rm, touch, open, etc. However, we don't check for immutability when doing a write(), a PROT_WRITE mmap(), a truncate(), or a write to a previously established mmap. If a program has an open write fd to a file that the administrator subsequently marks immutable, the program still can change the file contents. Weird! The ability to write to an immutable file does not follow the manpage promise that immutable files cannot be modified. Worse yet it's inconsistent with the behavior of other syscalls which don't allow modifications of immutable files. Therefore, add the necessary checks to make the write, mmap, and truncate behavior consistent with what the manpage says and consistent with other syscalls on filesystems which support IMMUTABLE. Signed-off-by: Darrick J. Wong Reviewed-by: Jan Kara --- fs/attr.c | 13 ++++++------- mm/filemap.c | 3 +++ mm/memory.c | 3 +++ mm/mmap.c | 8 ++++++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index d22e8187477f..1fcfdcc5b367 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -233,19 +233,18 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de WARN_ON_ONCE(!inode_is_locked(inode)); - if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) { - if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) - return -EPERM; - } + if (IS_IMMUTABLE(inode)) + return -EPERM; + + if ((ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) && + IS_APPEND(inode)) + return -EPERM; /* * If utimes(2) and friends are called with times == NULL (or both * times are UTIME_NOW), then we need to check for write permission */ if (ia_valid & ATTR_TOUCH) { - if (IS_IMMUTABLE(inode)) - return -EPERM; - if (!inode_owner_or_capable(inode)) { error = inode_permission(inode, MAY_WRITE); if (error) diff --git a/mm/filemap.c b/mm/filemap.c index aac71aef4c61..dad85e10f5f8 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2935,6 +2935,9 @@ inline ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from) loff_t count; int ret; + if (IS_IMMUTABLE(inode)) + return -EPERM; + if (!iov_iter_count(from)) return 0; diff --git a/mm/memory.c b/mm/memory.c index ddf20bd0c317..4311cfdade90 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2235,6 +2235,9 @@ static vm_fault_t do_page_mkwrite(struct vm_fault *vmf) vmf->flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE; + if (vmf->vma->vm_file && IS_IMMUTABLE(file_inode(vmf->vma->vm_file))) + return VM_FAULT_SIGBUS; + ret = vmf->vma->vm_ops->page_mkwrite(vmf); /* Restore original flags so that caller is not surprised */ vmf->flags = old_flags; diff --git a/mm/mmap.c b/mm/mmap.c index 7e8c3e8ae75f..ac1e32205237 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1483,8 +1483,12 @@ unsigned long do_mmap(struct file *file, unsigned long addr, case MAP_SHARED_VALIDATE: if (flags & ~flags_mask) return -EOPNOTSUPP; - if ((prot&PROT_WRITE) && !(file->f_mode&FMODE_WRITE)) - return -EACCES; + if (prot & PROT_WRITE) { + if (!(file->f_mode & FMODE_WRITE)) + return -EACCES; + if (IS_IMMUTABLE(file_inode(file))) + return -EPERM; + } /* * Make sure we don't allow writing to an append-only From patchwork Fri Jun 21 23:57:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11010835 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 02EA36C5 for ; Fri, 21 Jun 2019 23:57:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E589428BAD for ; Fri, 21 Jun 2019 23:57:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D98B928BB1; Fri, 21 Jun 2019 23:57:24 +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 00F4128BAD for ; Fri, 21 Jun 2019 23:57:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2565B8E0005; Fri, 21 Jun 2019 19:57:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1E1D08E0001; Fri, 21 Jun 2019 19:57:23 -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 032458E0005; Fri, 21 Jun 2019 19:57:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) by kanga.kvack.org (Postfix) with ESMTP id CEF028E0001 for ; Fri, 21 Jun 2019 19:57:22 -0400 (EDT) Received: by mail-yb1-f199.google.com with SMTP id v6so7466543ybs.1 for ; Fri, 21 Jun 2019 16:57:22 -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=z/qDndmf6A+QcMxspoyUz/S1LymbRSh4kBuy/OOkZMU=; b=ERRZ66MIWOAJ1U83j6ooJUUoH42WF903hTgx7Y27sS4qpvAcuRnkhFQXFjjuH97C6v suKkGT8wQiEez16/6J9HXnwgmHTbv3ei4X9w5dUlwTaMKVoaXv2UJPRQIDtmTmJup83T 6hUfLXgIoyR7ionx8R8ziFemGJqDiSFff/GWXNoPs/mr8luWquoBgPdKa54ik8VRpX/X v9IhNFg8TxPckGmskm9dsddZVO9VBvCffdMYwn45ejKyzqZE3wmfVt+WZEwnFw9c0DFv /51YdOF+JTB75s7ONAWbm1WWn9uVovpYuHFZVTncqTKEFRHODigO5/e7nBeE5mShiJPn MDLQ== X-Gm-Message-State: APjAAAW1jkrJFvdEDZr8dSH7sa8WUVyjMPYUBjgyDii9vh/bB9puEcQc e1+V5fEoO68aVq31kQP9SNCK/8SDnyvNcuAdFw0eWMuvPZBAS5vPwXjjnqmA3hFX6hsSLSwek7e JqF/K1BiqO6ru1zyhLC6CmTGXeCdrdxqKJAPgQkbxNsq299yVwXAoDXKJJ+sgMHLewQ== X-Received: by 2002:a25:80ca:: with SMTP id c10mr65092516ybm.502.1561161442575; Fri, 21 Jun 2019 16:57:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqysHQXVLlEAhPv6+bF4bhUP2od08fXibrKRCH6Nz9Bc2A8dL6YYTmvg9yeEEkXWAsvYJ6KC X-Received: by 2002:a25:80ca:: with SMTP id c10mr65092502ybm.502.1561161441499; Fri, 21 Jun 2019 16:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561161441; cv=none; d=google.com; s=arc-20160816; b=m0UimUUc6ZxJ3QTtJ11OQNTxoCkEiTQBl+f07JmFtYjq7G0e91bDEzi1WT3gX9p/Do 9/v/MWpZBfa+6atKhQ2yU3mAoDVp0x+Wbt7iH2GmK4ZDtyk0I2t/0461KZCXJicEuotm 4bJ8HYwLRUi9GVJSMLfQ+WibufU8oKQde32nZMb80KAoDez7+2Zeg/nSGHLD5g3vlpsN uV07mOriQOex/QmF3qKVHcWJswGq60PLmnd2YJkLZg1wfpl+GAuRpyIINMv/a0CVKejC W7cZ5LURVbBvfyI1cPmDdIhZQ+c186ZJdYAhhiqt7To6dRHUIgYcQiLNKx8Yb9PQ4lkE UdUQ== 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=z/qDndmf6A+QcMxspoyUz/S1LymbRSh4kBuy/OOkZMU=; b=MGHzO/VRL6JAYV+j07NUi5hTQ3/xm1duFnfRZkI/qZPxfH15uOJ9xpN6eYxo4/4ZbP mNDShA7iCTAPggkTvhaDXxlmknkBIXCS9qFncGqQwu4Sjr/KBLQxGiEW7f6YvD6evDup dd633BF7uFDjAT+JdD0qIhYDonUbf5YPlWPTZE8sLfosVw0SHxmg3LCxp9z/ggJJMaK3 KMmnZtosFzmbCsdxU0ZKGMcvG6b1woOZt2nFA4RpRQ5ET5LmO/5JuZeZsssk8BEAaGTG s1wlDhHW2w28ItSpGl9weC9TBqZEkOio4Gj2XLlYfwxNMgCs+ld9JWRPLY8YiOjhgS+W Qd/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=wjkT0GQO; 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 d63si1377182ywa.68.2019.06.21.16.57.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 16:57:21 -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=wjkT0GQO; 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.27/8.16.0.27) with SMTP id x5LNtT3C053502; Fri, 21 Jun 2019 23:57:13 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=z/qDndmf6A+QcMxspoyUz/S1LymbRSh4kBuy/OOkZMU=; b=wjkT0GQOyhGZQVymw3iAWC4tCSljHbMaHfLwOMuDGL8p4btYWyTwsWtBEdQwGGINIwZo h9zBW/cgXXhMZ8oyGZjnW9NYmdB0nA3/EIc95B8S2hEfI7RVCeVpRHHiqV0MZZbBUk4d 2hLxOCGcFbZy1cJCUQcDfBHr4goqckvLXk68LVtc3iN4PAsokI9VnMV1Kduw7ojHGpCO t6oUEvGxTK8pCIDnMurzetCBjzV9DMGl1TyxzjEirA8mwBRdpKK72gDjjK2Oe+hHHOzL Yt0tAmTke1esEGQGWR33J1i4LB8hmomM7Sie9P1P+WLkg7KBJbOIeC+BaS+UWXzgGldC vg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2t7809rsww-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:13 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5LNuZJP036165; Fri, 21 Jun 2019 23:57:12 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 2t77yq6ubx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 21 Jun 2019 23:57:12 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.27/8.16.0.27) with SMTP id x5LNvCNA037024; Fri, 21 Jun 2019 23:57:12 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2t77yq6ubu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:12 +0000 Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x5LNvA1P019154; Fri, 21 Jun 2019 23:57:10 GMT Received: from localhost (/10.159.131.214) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 21 Jun 2019 16:57:09 -0700 Subject: [PATCH 2/7] vfs: flush and wait for io when setting the immutable flag via SETFLAGS From: "Darrick J. Wong" To: matthew.garrett@nebula.com, yuchao0@huawei.com, tytso@mit.edu, darrick.wong@oracle.com, ard.biesheuvel@linaro.org, josef@toxicpanda.com, clm@fb.com, adilger.kernel@dilger.ca, viro@zeniv.linux.org.uk, jack@suse.com, dsterba@suse.com, jaegeuk@kernel.org, jk@ozlabs.org Cc: reiserfs-devel@vger.kernel.org, linux-efi@vger.kernel.org, devel@lists.orangefs.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, linux-mtd@lists.infradead.org, ocfs2-devel@oss.oracle.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org Date: Fri, 21 Jun 2019 16:57:07 -0700 Message-ID: <156116142734.1664939.5074567130774423066.stgit@magnolia> In-Reply-To: <156116141046.1664939.11424021489724835645.stgit@magnolia> References: <156116141046.1664939.11424021489724835645.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9295 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906210182 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 When we're using FS_IOC_SETFLAGS to set the immutable flag on a file, we need to ensure that userspace can't continue to write the file after the file becomes immutable. To make that happen, we have to flush all the dirty pagecache pages to disk to ensure that we can fail a page fault on a mmap'd region, wait for pending directio to complete, and hope the caller locked out any new writes by holding the inode lock. Signed-off-by: Darrick J. Wong --- fs/btrfs/ioctl.c | 3 +++ fs/efivarfs/file.c | 5 +++++ fs/ext2/ioctl.c | 5 +++++ fs/ext4/ioctl.c | 3 +++ fs/f2fs/file.c | 3 +++ fs/hfsplus/ioctl.c | 3 +++ fs/nilfs2/ioctl.c | 3 +++ fs/ocfs2/ioctl.c | 3 +++ fs/orangefs/file.c | 11 ++++++++--- fs/orangefs/protocol.h | 3 +++ fs/reiserfs/ioctl.c | 3 +++ fs/ubifs/ioctl.c | 3 +++ include/linux/fs.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 93 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 7ddda5b4b6a6..f431813b2454 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -214,6 +214,9 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) fsflags = btrfs_mask_fsflags_for_type(inode, fsflags); old_fsflags = btrfs_inode_flags_to_fsflags(binode->flags); ret = vfs_ioc_setflags_check(inode, old_fsflags, fsflags); + if (ret) + goto out_unlock; + ret = vfs_ioc_setflags_flush_data(inode, fsflags); if (ret) goto out_unlock; diff --git a/fs/efivarfs/file.c b/fs/efivarfs/file.c index f4f6c1bec132..845016a67724 100644 --- a/fs/efivarfs/file.c +++ b/fs/efivarfs/file.c @@ -163,6 +163,11 @@ efivarfs_ioc_setxflags(struct file *file, void __user *arg) return error; inode_lock(inode); + error = vfs_ioc_setflags_flush_data(inode, flags); + if (error) { + inode_unlock(inode); + return error; + } inode_set_flags(inode, i_flags, S_IMMUTABLE); inode_unlock(inode); diff --git a/fs/ext2/ioctl.c b/fs/ext2/ioctl.c index 88b3b9720023..75f75619237c 100644 --- a/fs/ext2/ioctl.c +++ b/fs/ext2/ioctl.c @@ -65,6 +65,11 @@ long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) inode_unlock(inode); goto setflags_out; } + ret = vfs_ioc_setflags_flush_data(inode, flags); + if (ret) { + inode_unlock(inode); + goto setflags_out; + } flags = flags & EXT2_FL_USER_MODIFIABLE; flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE; diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index 6aa1df1918f7..a05341b94d98 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -290,6 +290,9 @@ static int ext4_ioctl_setflags(struct inode *inode, jflag = flags & EXT4_JOURNAL_DATA_FL; err = vfs_ioc_setflags_check(inode, oldflags, flags); + if (err) + goto flags_out; + err = vfs_ioc_setflags_flush_data(inode, flags); if (err) goto flags_out; diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 183ed1ac60e1..d3cf4bdb8738 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1681,6 +1681,9 @@ static int __f2fs_ioc_setflags(struct inode *inode, unsigned int flags) oldflags = fi->i_flags; err = vfs_ioc_setflags_check(inode, oldflags, flags); + if (err) + return err; + err = vfs_ioc_setflags_flush_data(inode, flags); if (err) return err; diff --git a/fs/hfsplus/ioctl.c b/fs/hfsplus/ioctl.c index 862a3c9481d7..f8295fa35237 100644 --- a/fs/hfsplus/ioctl.c +++ b/fs/hfsplus/ioctl.c @@ -104,6 +104,9 @@ static int hfsplus_ioctl_setflags(struct file *file, int __user *user_flags) inode_lock(inode); err = vfs_ioc_setflags_check(inode, oldflags, flags); + if (err) + goto out_unlock_inode; + err = vfs_ioc_setflags_flush_data(inode, flags); if (err) goto out_unlock_inode; diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c index 0632336d2515..a3c200ab9f60 100644 --- a/fs/nilfs2/ioctl.c +++ b/fs/nilfs2/ioctl.c @@ -149,6 +149,9 @@ static int nilfs_ioctl_setflags(struct inode *inode, struct file *filp, oldflags = NILFS_I(inode)->i_flags; ret = vfs_ioc_setflags_check(inode, oldflags, flags); + if (ret) + goto out; + ret = vfs_ioc_setflags_flush_data(inode, flags); if (ret) goto out; diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c index 467a2faf0305..e91ca0dad3d7 100644 --- a/fs/ocfs2/ioctl.c +++ b/fs/ocfs2/ioctl.c @@ -107,6 +107,9 @@ static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags, flags |= oldflags & ~mask; status = vfs_ioc_setflags_check(inode, oldflags, flags); + if (status) + goto bail_unlock; + status = vfs_ioc_setflags_flush_data(inode, flags); if (status) goto bail_unlock; diff --git a/fs/orangefs/file.c b/fs/orangefs/file.c index a35c17017210..fec5dfbc3dac 100644 --- a/fs/orangefs/file.c +++ b/fs/orangefs/file.c @@ -389,6 +389,8 @@ static long orangefs_ioctl(struct file *file, unsigned int cmd, unsigned long ar (unsigned long long)uval); return put_user(uval, (int __user *)arg); } else if (cmd == FS_IOC_SETFLAGS) { + struct inode *inode = file_inode(file); + ret = 0; if (get_user(uval, (int __user *)arg)) return -EFAULT; @@ -399,11 +401,14 @@ static long orangefs_ioctl(struct file *file, unsigned int cmd, unsigned long ar * the flags and then updates the flags with some new * settings. So, we ignore it in the following edit. bligon. */ - if ((uval & ~ORANGEFS_MIRROR_FL) & - (~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NOATIME_FL))) { + if ((uval & ~ORANGEFS_MIRROR_FL) & ~ORANGEFS_VFS_FL) { gossip_err("orangefs_ioctl: the FS_IOC_SETFLAGS only supports setting one of FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NOATIME_FL\n"); return -EINVAL; } + ret = vfs_ioc_setflags_flush_data(inode, + uval & ORANGEFS_VFS_FL); + if (ret) + goto out; val = uval; gossip_debug(GOSSIP_FILE_DEBUG, "orangefs_ioctl: FS_IOC_SETFLAGS: %llu\n", @@ -412,7 +417,7 @@ static long orangefs_ioctl(struct file *file, unsigned int cmd, unsigned long ar "user.pvfs2.meta_hint", &val, sizeof(val), 0); } - +out: return ret; } diff --git a/fs/orangefs/protocol.h b/fs/orangefs/protocol.h index d403cf29a99b..3dbe1c4534ce 100644 --- a/fs/orangefs/protocol.h +++ b/fs/orangefs/protocol.h @@ -129,6 +129,9 @@ static inline void ORANGEFS_khandle_from(struct orangefs_khandle *kh, #define ORANGEFS_IMMUTABLE_FL FS_IMMUTABLE_FL #define ORANGEFS_APPEND_FL FS_APPEND_FL #define ORANGEFS_NOATIME_FL FS_NOATIME_FL +#define ORANGEFS_VFS_FL (FS_IMMUTABLE_FL | \ + FS_APPEND_FL | \ + FS_NOATIME_FL) #define ORANGEFS_MIRROR_FL 0x01000000ULL #define ORANGEFS_FS_ID_NULL ((__s32)0) #define ORANGEFS_ATTR_SYS_UID (1 << 0) diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c index 92bcb1ecd994..50494f54392c 100644 --- a/fs/reiserfs/ioctl.c +++ b/fs/reiserfs/ioctl.c @@ -77,6 +77,9 @@ long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) err = vfs_ioc_setflags_check(inode, REISERFS_I(inode)->i_attrs, flags); + if (err) + goto setflags_out; + err = vfs_ioc_setflags_flush_data(inode, flags); if (err) goto setflags_out; if ((flags & REISERFS_NOTAIL_FL) && diff --git a/fs/ubifs/ioctl.c b/fs/ubifs/ioctl.c index bdea836fc38b..ff4a43314599 100644 --- a/fs/ubifs/ioctl.c +++ b/fs/ubifs/ioctl.c @@ -110,6 +110,9 @@ static int setflags(struct inode *inode, int flags) mutex_lock(&ui->ui_mutex); oldflags = ubifs2ioctl(ui->flags); err = vfs_ioc_setflags_check(inode, oldflags, flags); + if (err) + goto out_unlock; + err = vfs_ioc_setflags_flush_data(inode, flags); if (err) goto out_unlock; diff --git a/include/linux/fs.h b/include/linux/fs.h index 0c3ef24afe22..ed9a74cf5ef3 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3557,7 +3557,55 @@ static inline struct sock *io_uring_get_socket(struct file *file) int vfs_ioc_setflags_check(struct inode *inode, int oldflags, int flags); +/* + * Do we need to flush the file data before changing attributes? When we're + * setting the immutable flag we must stop all directio writes and flush the + * dirty pages so that we can fail the page fault on the next write attempt. + */ +static inline bool vfs_ioc_setflags_need_flush(struct inode *inode, int flags) +{ + if (S_ISREG(inode->i_mode) && !IS_IMMUTABLE(inode) && + (flags & FS_IMMUTABLE_FL)) + return true; + + return false; +} + +/* + * Flush file data before changing attributes. Caller must hold any locks + * required to prevent further writes to this file until we're done setting + * flags. + */ +static inline int inode_flush_data(struct inode *inode) +{ + inode_dio_wait(inode); + return filemap_write_and_wait(inode->i_mapping); +} + +/* + * Flush all pending IO and dirty mappings before setting S_IMMUTABLE on an + * inode via FS_IOC_SETFLAGS. If the flush fails we'll clear the flag before + * returning error. + * + * Note: the caller should be holding i_mutex, or else be sure that + * they have exclusive access to the inode structure. + */ +static inline int vfs_ioc_setflags_flush_data(struct inode *inode, int flags) +{ + int ret; + + if (!vfs_ioc_setflags_need_flush(inode, flags)) + return 0; + + inode_set_flags(inode, S_IMMUTABLE, S_IMMUTABLE); + ret = inode_flush_data(inode); + if (ret) + inode_set_flags(inode, 0, S_IMMUTABLE); + return ret; +} + int vfs_ioc_fssetxattr_check(struct inode *inode, const struct fsxattr *old_fa, struct fsxattr *fa); + #endif /* _LINUX_FS_H */ From patchwork Fri Jun 21 23:57:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11010839 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 D1FB376 for ; Fri, 21 Jun 2019 23:57:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0A6528BAD for ; Fri, 21 Jun 2019 23:57:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B43D528BB1; Fri, 21 Jun 2019 23:57:29 +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 0376928BAD for ; Fri, 21 Jun 2019 23:57:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00CF98E0006; Fri, 21 Jun 2019 19:57:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EFF748E0001; Fri, 21 Jun 2019 19:57:27 -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 D9F418E0006; Fri, 21 Jun 2019 19:57:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f69.google.com (mail-yw1-f69.google.com [209.85.161.69]) by kanga.kvack.org (Postfix) with ESMTP id B0D7B8E0001 for ; Fri, 21 Jun 2019 19:57:27 -0400 (EDT) Received: by mail-yw1-f69.google.com with SMTP id y205so8018053ywy.19 for ; Fri, 21 Jun 2019 16:57:27 -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=bO+sN6Te54B7Gm32yC/95CPAosLiG+rfFvZuf1HgzMU=; b=f3VOpJQEZ2hxmLrZxbREJYsg5D4NGS8PEtMOPCNq1x3iC4JRTiaQNIENZKFpxdOXIg oKpy664OlZSeyKV5/kq2alge4bQFHy+Co1aPShkRhjuzwymjMSDDr30Vrs3Dd8mFxsvl ljtNukvnx3EW+/doyd2HMwQII9j3X8d4CmYiXM3kuHPDlU2Kpfx9V1wgZrZi5r0yLXKX Ydi4evq7XqB4AnAsoBLNfdD0nTqX6VM+7iqjcZpPcrbAJkZ5g45E44P9mvJPx8jauoo1 +rTeKfKRU3Ije2OtXd6AfZsJHZnYqlmY9eRRqyP6hjpEQ0K4CjUClFE0+GZNtsCcaMw9 HoMQ== X-Gm-Message-State: APjAAAVHX1Ra3gmaisyRN6h/jXbScPh5ygonPRPC/n4TeGmjsfVM2MGv Cii7ueN1KBj9HdAlFcRhxBPZqeYI7FE3/s1GK/2KtIanetm0yXS+KfGouELutLtnTTLPOxNHbJG WixiOc0l51bguWQ6BG64ketU5lqRIhGyBzWnBWXQLEfw8deZROYftXFVgpJ0eVUqjMw== X-Received: by 2002:a25:be01:: with SMTP id h1mr25905935ybk.520.1561161447398; Fri, 21 Jun 2019 16:57:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcjTuXk91f1oprkRKKWCwMpxvUokdNJhNHe1Jl0SN2/zi9Re/8LA2/KKxNlfTAksVBr6y4 X-Received: by 2002:a25:be01:: with SMTP id h1mr25905924ybk.520.1561161446661; Fri, 21 Jun 2019 16:57:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561161446; cv=none; d=google.com; s=arc-20160816; b=uy2EClK6Qm4LWDTim8ECyDXLietQ3sPFTr1duXLpih9M9sRW0+ld2skwp0qd7KNqLH whA/zN3c5bTTuiHP45NeHd7J07pO6tzxxqlwzYNnRr5A/k44FwQdW/lCDFg1vXQ8E5Ue bU5qs2rr1j9jt63Nti+jsIP0Mejbvjz6PeBoYghwa4Am4d+MCLcjsyg9Vhf0wG8YGHvp Jh5MPP2Xyt/tb4xX5LwJONu4hs7V1OCH8u434p+qBCBOT5Ny2xzBYK+nStURHUwmDu7i 8dqEDeJnFbHMvu+NrtvB6q9hLXXNfnhVsDnxYnn1nZjir5dwd10ALbLVXnWfuO9Ohxcy qawA== 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=bO+sN6Te54B7Gm32yC/95CPAosLiG+rfFvZuf1HgzMU=; b=f6gzh9b2iLnVe3u32cDOyItmISoqTUtKA3fQy/pdgL8J9aRIybYuxA5y8awJbAiKVF /bwBHbconpzxeGO8wdBokA55MZwni8KPYoFew2KIVQNLdH1hZ0rwX6OfOoVvVTt3P+6Q R4BBt20A5Jh2XjxbrV52ZqLq9dPb50VPiNShEMLMA5bugNzQj9RVBiHLJ9Db4k9HewxF pSTjEfSck6vcZTVQlsMum5Wc1m4JDdW6rekLRc8ZbhjFKlbKrI0DDR2Tbq9ZI92HibBk ryJ0MpZUCroty6JyNMyH5oRclf8gjRY2h5CwGPeWsb4Z3lbB03vyTRB7dpVtnNNVEfRO odWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=iop0iBLc; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2120.oracle.com (userp2120.oracle.com. [156.151.31.85]) by mx.google.com with ESMTPS id r13si1365529ybp.145.2019.06.21.16.57.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 16:57:26 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 as permitted sender) client-ip=156.151.31.85; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=iop0iBLc; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 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 (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5LNsqBD059305; Fri, 21 Jun 2019 23:57:20 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=bO+sN6Te54B7Gm32yC/95CPAosLiG+rfFvZuf1HgzMU=; b=iop0iBLcfymdJCKdAp5ye36YRtYmpLaZtzpeCNIekVvk8BHvE0TvsQwZPTRe3GvBvnHB POhg9g6OZky6l9+XmlonbM47GDVpeHCNptPw1f0SGTFD69qudz5qj2jFjltpAPUFyq13 w3KNWu+wVs7ezxklCQg9TRG/odCOQBt/cLogJMrLkTERZiJDfOXSZr31CkR+QhJH0+68 gjtvuKs3csVg+Tg8WtXM+Uv0cSBNM7/LjpN7quqI1LB93qlLu9XwdmKKwOJl6wy5h1U7 wT8duhrMKfSo1Tj8wa37VlB+1nB222jRZXy16Cni/dLFHtFij5jp8ZgfZ5xzfhH5L5KN WQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2t7809rqv6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:20 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5LNu9VH042326; Fri, 21 Jun 2019 23:57:19 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3030.oracle.com with ESMTP id 2t77ypesfg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 21 Jun 2019 23:57:19 +0000 Received: from userp3030.oracle.com (userp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.27/8.16.0.27) with SMTP id x5LNvJbZ044395; Fri, 21 Jun 2019 23:57:19 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2t77ypesfc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:19 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x5LNvIgI031562; Fri, 21 Jun 2019 23:57:18 GMT Received: from localhost (/10.159.131.214) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 21 Jun 2019 23:57:17 +0000 Subject: [PATCH 3/7] vfs: flush and wait for io when setting the immutable flag via FSSETXATTR From: "Darrick J. Wong" To: matthew.garrett@nebula.com, yuchao0@huawei.com, tytso@mit.edu, darrick.wong@oracle.com, ard.biesheuvel@linaro.org, josef@toxicpanda.com, clm@fb.com, adilger.kernel@dilger.ca, viro@zeniv.linux.org.uk, jack@suse.com, dsterba@suse.com, jaegeuk@kernel.org, jk@ozlabs.org Cc: reiserfs-devel@vger.kernel.org, linux-efi@vger.kernel.org, devel@lists.orangefs.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, linux-mtd@lists.infradead.org, ocfs2-devel@oss.oracle.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org Date: Fri, 21 Jun 2019 16:57:15 -0700 Message-ID: <156116143526.1664939.6767366095685084430.stgit@magnolia> In-Reply-To: <156116141046.1664939.11424021489724835645.stgit@magnolia> References: <156116141046.1664939.11424021489724835645.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9295 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906210182 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 When we're using FS_IOC_FSSETXATTR to set the immutable flag on a file, we need to ensure that userspace can't continue to write the file after the file becomes immutable. To make that happen, we have to flush all the dirty pagecache pages to disk to ensure that we can fail a page fault on a mmap'd region, wait for pending directio to complete, and hope the caller locked out any new writes by holding the inode lock. Signed-off-by: Darrick J. Wong --- fs/btrfs/ioctl.c | 3 +++ fs/ext4/ioctl.c | 3 +++ fs/f2fs/file.c | 3 +++ fs/xfs/xfs_ioctl.c | 39 +++++++++++++++++++++++++++++++++------ include/linux/fs.h | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index f431813b2454..63a9281e6ce0 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -432,6 +432,9 @@ static int btrfs_ioctl_fssetxattr(struct file *file, void __user *arg) __btrfs_ioctl_fsgetxattr(binode, &old_fa); ret = vfs_ioc_fssetxattr_check(inode, &old_fa, &fa); + if (ret) + goto out_unlock; + ret = vfs_ioc_fssetxattr_flush_data(inode, &fa); if (ret) goto out_unlock; diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index a05341b94d98..6037585c1520 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -1115,6 +1115,9 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) inode_lock(inode); ext4_fsgetxattr(inode, &old_fa); err = vfs_ioc_fssetxattr_check(inode, &old_fa, &fa); + if (err) + goto out; + err = vfs_ioc_fssetxattr_flush_data(inode, &fa); if (err) goto out; flags = (ei->i_flags & ~EXT4_FL_XFLAG_VISIBLE) | diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index d3cf4bdb8738..97f4bb36540f 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2832,6 +2832,9 @@ static int f2fs_ioc_fssetxattr(struct file *filp, unsigned long arg) __f2fs_ioc_fsgetxattr(inode, &old_fa); err = vfs_ioc_fssetxattr_check(inode, &old_fa, &fa); + if (err) + goto out; + err = vfs_ioc_fssetxattr_flush_data(inode, &fa); if (err) goto out; flags = (fi->i_flags & ~F2FS_FL_XFLAG_VISIBLE) | diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index b494e7e881e3..88583b3e1e76 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -1014,6 +1014,28 @@ xfs_diflags_to_linux( #endif } +/* + * Lock the inode against file io and page faults, then flush all dirty pages + * and wait for writeback and direct IO operations to finish. Returns with + * the relevant inode lock flags set in @join_flags. Caller is responsible for + * unlocking even on error return. + */ +static int +xfs_ioctl_setattr_flush( + struct xfs_inode *ip, + int *join_flags) +{ + /* Already locked the inode from IO? Assume we're done. */ + if (((*join_flags) & (XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL)) == + (XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL)) + return 0; + + /* Lock and flush all mappings and IO in preparation for flag change */ + *join_flags = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL; + xfs_ilock(ip, *join_flags); + return inode_flush_data(VFS_I(ip)); +} + static int xfs_ioctl_setattr_xflags( struct xfs_trans *tp, @@ -1099,23 +1121,22 @@ xfs_ioctl_setattr_dax_invalidate( if (!(fa->fsx_xflags & FS_XFLAG_DAX) && !IS_DAX(inode)) return 0; - if (S_ISDIR(inode->i_mode)) + if (!S_ISREG(inode->i_mode)) return 0; - /* lock, flush and invalidate mapping in preparation for flag change */ - xfs_ilock(ip, XFS_MMAPLOCK_EXCL | XFS_IOLOCK_EXCL); - error = filemap_write_and_wait(inode->i_mapping); + error = xfs_ioctl_setattr_flush(ip, join_flags); if (error) goto out_unlock; error = invalidate_inode_pages2(inode->i_mapping); if (error) goto out_unlock; - *join_flags = XFS_MMAPLOCK_EXCL | XFS_IOLOCK_EXCL; return 0; out_unlock: - xfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_IOLOCK_EXCL); + if (*join_flags) + xfs_iunlock(ip, *join_flags); + *join_flags = 0; return error; } @@ -1337,6 +1358,12 @@ xfs_ioctl_setattr( if (code) goto error_free_dquots; + if (!join_flags && vfs_ioc_fssetxattr_need_flush(VFS_I(ip), fa)) { + code = xfs_ioctl_setattr_flush(ip, &join_flags); + if (code) + goto error_free_dquots; + } + tp = xfs_ioctl_setattr_get_trans(ip, join_flags); if (IS_ERR(tp)) { code = PTR_ERR(tp); diff --git a/include/linux/fs.h b/include/linux/fs.h index ed9a74cf5ef3..b4553d01e254 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3607,5 +3607,42 @@ static inline int vfs_ioc_setflags_flush_data(struct inode *inode, int flags) int vfs_ioc_fssetxattr_check(struct inode *inode, const struct fsxattr *old_fa, struct fsxattr *fa); +/* + * Do we need to flush the file data before changing attributes? When we're + * setting the immutable flag we must stop all directio writes and flush the + * dirty pages so that we can fail the page fault on the next write attempt. + */ +static inline bool vfs_ioc_fssetxattr_need_flush(struct inode *inode, + struct fsxattr *fa) +{ + if (S_ISREG(inode->i_mode) && !IS_IMMUTABLE(inode) && + (fa->fsx_xflags & FS_XFLAG_IMMUTABLE)) + return true; + + return false; +} + +/* + * Flush all pending IO and dirty mappings before setting S_IMMUTABLE on an + * inode via FS_IOC_SETXATTR. If the flush fails we'll clear the flag before + * returning error. + * + * Note: the caller should be holding i_mutex, or else be sure that + * they have exclusive access to the inode structure. + */ +static inline int vfs_ioc_fssetxattr_flush_data(struct inode *inode, + struct fsxattr *fa) +{ + int ret; + + if (!vfs_ioc_fssetxattr_need_flush(inode, fa)) + return 0; + + inode_set_flags(inode, S_IMMUTABLE, S_IMMUTABLE); + ret = inode_flush_data(inode); + if (ret) + inode_set_flags(inode, 0, S_IMMUTABLE); + return ret; +} #endif /* _LINUX_FS_H */ From patchwork Fri Jun 21 23:57:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11010851 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 7F1A3186E for ; Fri, 21 Jun 2019 23:57:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E21A2870D for ; Fri, 21 Jun 2019 23:57:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6271928B81; Fri, 21 Jun 2019 23:57:39 +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 E036828BAD for ; Fri, 21 Jun 2019 23:57:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D1028E0007; Fri, 21 Jun 2019 19:57:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 081368E0001; Fri, 21 Jun 2019 19:57:38 -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 E8A5A8E0007; Fri, 21 Jun 2019 19:57:37 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by kanga.kvack.org (Postfix) with ESMTP id C41268E0001 for ; Fri, 21 Jun 2019 19:57:37 -0400 (EDT) Received: by mail-qt1-f197.google.com with SMTP id r57so9726312qtj.21 for ; Fri, 21 Jun 2019 16:57:37 -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=H3uevlbLebMWG9Gcus8tT+xdX29l/sejQz3Gcj6GgOM=; b=uXf1PHFoDG6C3Wmll+z0JkSjjKxV5qRwqS9Rv8VvRgY0Edn7wwfDNamcjU+i2akqPm tAMy8Sl84hrLxdMFkKcZlI+taBLH0BxloPnEM0JsoSeeIJ1UF7OCP5gnI5pJaomd5Ow5 FWcgoGlnJSVIlLTIeGCuSXfa7yJo9ubzm79hfZxzH+vekmBlquYCSmuxjGUj7inpBfeD R1o0ZP/rGJxUFbpHRUikdDBAlLJD9Xa7r0w2t1mjZZq/FgXd6HLvE431nFrAlbC663gB MpOYIYSg7v6xmyrmXXacFwGlnARKUuykrT6Jo0uPhkDkKS9bI4+TVn3D4xfN/sEbfa9o j0UA== X-Gm-Message-State: APjAAAXFfakY5IQ67uqBI+qb9ygm5Pmqsc/+FHZK0RWs5U6JIFue8/EK LCOrbsBYqY5cuAd6vS1/gk5O2KSfbA8hDv0sdystLK+Az2U4FH8J/PufycIKvYPn+vYFkD2Dxi8 PcjJeFgMJem1BPwcCv22DpieuYQvMOPnw7CBOSWMSftKZ7hN7CTvKxfIU6syBnc2VEA== X-Received: by 2002:ac8:25b1:: with SMTP id e46mr100087950qte.36.1561161457545; Fri, 21 Jun 2019 16:57:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBv7yUkM895IrvLBAMklAszoGRYyy3Kd0i31Y9CqYEMdLWWw2kgUyMQ1IE8dxMj3xF5C51 X-Received: by 2002:ac8:25b1:: with SMTP id e46mr100087912qte.36.1561161456910; Fri, 21 Jun 2019 16:57:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561161456; cv=none; d=google.com; s=arc-20160816; b=rucDzxeZ/eV8Fl7K9FG3w9Xfmk3AKZ6ONj5vX4rmuKSyg46gmKEHjxGmfHggEmGuR0 cZQXydLlzuWuH57PcX1YcIsd4wXjZ2WF+/1CtEFPpOSSQi8tVwQhHK/cvSqz2jICPYAy Wz9LB4f8AD7gPYVkSrY/awrG+5bDzyGuQHyTfoSDDElXtdaiw7qrKXMlYsSeqgZ+KiIX ObEurkZHcQzjsGoIkxdoTeHMNH7YR6wUD3LIKBXsQ6EMiuQJ+utDhxOu0X90sZNqcGUO kZA6PHo1N4flTlCyWPdj3iDjAWTCDJPfVjoHeY5LOvTwNm+SzG/FL7/m4avoqbtsID4a eyGg== 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=H3uevlbLebMWG9Gcus8tT+xdX29l/sejQz3Gcj6GgOM=; b=aVRkRjIYh/Xe9H5AJdrh5hy9xLyBqTroNdbW/2XtosgGqT5tkB3Sia384C4hpet58N +8JHEG/U96gAUkscz3G5X6lMhnMIedd+kebD0nBCpr6hgku+mho+Wk5QhE9/YiuCYKv6 rTYtOPkG93hrmc2JAk1/cBMAfaFec+IwN2R2obWX2Vj1qwfmtWV12eVuvLUa42kfA8fX /3QZJjWFfFXgmXBxE2cxQOVRKDIWusbElQzw8I9XGH+2JHcNAAmyx7yPzoUp6Hxrql7r LCwh1LvklvTqwF0dHxlJ0mS3WXhj63olkiXJULIc4iOjqHjp2R2FRYkxKMEsCu+cYK6D LbRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=OcnqzjPS; 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 e48si2721536qta.238.2019.06.21.16.57.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 16:57:36 -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=OcnqzjPS; 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.27/8.16.0.27) with SMTP id x5LNsvRV052754; Fri, 21 Jun 2019 23:57:29 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=H3uevlbLebMWG9Gcus8tT+xdX29l/sejQz3Gcj6GgOM=; b=OcnqzjPSKPtrxCRWYar6ofhsldYVF9c+tkfBHXonTVfuZMYUnfzwd+pZBE075w5zCRmi ZvsUfy3kAcVu/YedEjN9R/6USufYjacFfPaKsIdUv80jaVBQnD/OAu6lBasg+yQiEqjP eKuWczOltqaQsSQOKOYn/WyUhF9mG4q9hlyIS5IHkJIYG9MP/Y+1AJ1FU73ge2OLZkP1 hZaOIE2TRbrQFAunY0/VNR5vRAiBxDfmhK6deScIzINNLh1gycqSUk/W9IUPYABlnujp Ix4fU3tFgbn/QJ+lm60ma+H/Asm2thRj0sXAL9MfISyk+U6RhkB3o0SFsco43PF8crSz hg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2t7809rsx8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:29 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5LNvQ7S171581; Fri, 21 Jun 2019 23:57:28 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 2t7rdy064m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 21 Jun 2019 23:57:28 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.27/8.16.0.27) with SMTP id x5LNvS47171635; Fri, 21 Jun 2019 23:57:28 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 2t7rdy064f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:28 +0000 Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x5LNvPo2020773; Fri, 21 Jun 2019 23:57:26 GMT Received: from localhost (/10.159.131.214) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 21 Jun 2019 16:57:25 -0700 Subject: [PATCH 4/7] vfs: don't allow most setxattr to immutable files From: "Darrick J. Wong" To: matthew.garrett@nebula.com, yuchao0@huawei.com, tytso@mit.edu, darrick.wong@oracle.com, ard.biesheuvel@linaro.org, josef@toxicpanda.com, clm@fb.com, adilger.kernel@dilger.ca, viro@zeniv.linux.org.uk, jack@suse.com, dsterba@suse.com, jaegeuk@kernel.org, jk@ozlabs.org Cc: reiserfs-devel@vger.kernel.org, linux-efi@vger.kernel.org, devel@lists.orangefs.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, linux-mtd@lists.infradead.org, ocfs2-devel@oss.oracle.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org Date: Fri, 21 Jun 2019 16:57:23 -0700 Message-ID: <156116144305.1664939.3544724373475771930.stgit@magnolia> In-Reply-To: <156116141046.1664939.11424021489724835645.stgit@magnolia> References: <156116141046.1664939.11424021489724835645.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9295 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=885 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906210182 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 The chattr manpage has this to say about immutable files: "A file with the 'i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file, most of the file's metadata can not be modified, and the file can not be opened in write mode." However, we don't actually check the immutable flag in the setattr code, which means that we can update inode flags and project ids and extent size hints on supposedly immutable files. Therefore, reject setflags and fssetxattr calls on an immutable file if the file is immutable and will remain that way. Signed-off-by: Darrick J. Wong --- fs/inode.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index 6374ad2ef25b..220caefc31f7 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2204,6 +2204,14 @@ int vfs_ioc_setflags_check(struct inode *inode, int oldflags, int flags) !capable(CAP_LINUX_IMMUTABLE)) return -EPERM; + /* + * We aren't allowed to change any other flags if the immutable flag is + * already set and is not being unset. + */ + if ((oldflags & FS_IMMUTABLE_FL) && (flags & FS_IMMUTABLE_FL) && + oldflags != flags) + return -EPERM; + return 0; } EXPORT_SYMBOL(vfs_ioc_setflags_check); @@ -2246,6 +2254,25 @@ int vfs_ioc_fssetxattr_check(struct inode *inode, const struct fsxattr *old_fa, !S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) return -EINVAL; + /* + * We aren't allowed to change any fields if the immutable flag is + * already set and is not being unset. + */ + if ((old_fa->fsx_xflags & FS_XFLAG_IMMUTABLE) && + (fa->fsx_xflags & FS_XFLAG_IMMUTABLE)) { + if (old_fa->fsx_xflags != fa->fsx_xflags) + return -EPERM; + if (old_fa->fsx_projid != fa->fsx_projid) + return -EPERM; + if ((fa->fsx_xflags & (FS_XFLAG_EXTSIZE | + FS_XFLAG_EXTSZINHERIT)) && + old_fa->fsx_extsize != fa->fsx_extsize) + return -EPERM; + if ((old_fa->fsx_xflags & FS_XFLAG_COWEXTSIZE) && + old_fa->fsx_cowextsize != fa->fsx_cowextsize) + return -EPERM; + } + /* Extent size hints of zero turn off the flags. */ if (fa->fsx_extsize == 0) fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT); From patchwork Fri Jun 21 23:57:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11010857 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 7A7BF76 for ; Fri, 21 Jun 2019 23:57:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 698732870D for ; Fri, 21 Jun 2019 23:57:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D4D928BAD; Fri, 21 Jun 2019 23:57:45 +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 D99222870D for ; Fri, 21 Jun 2019 23:57:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00BCD8E0008; Fri, 21 Jun 2019 19:57:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ED8578E0001; Fri, 21 Jun 2019 19:57:43 -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 D78C98E0008; Fri, 21 Jun 2019 19:57:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) by kanga.kvack.org (Postfix) with ESMTP id B5CDA8E0001 for ; Fri, 21 Jun 2019 19:57:43 -0400 (EDT) Received: by mail-yb1-f199.google.com with SMTP id g7so7387934ybf.10 for ; Fri, 21 Jun 2019 16:57:43 -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=GoNZ4aRxdLiu9VXKzoYqQXkZ8KvvgodmwFDB7EyF+mY=; b=WdT1TyGejTQIElffG1W9LQkBmfB+j7fy7C0HqLPqleYziW+B2avepGmM0RHDa9AzAe L26VkeXQtzriFNClzuSG37GzSKFXIt1HuvorO99YaCqv+1gLaRWxkFCVcnKhC/0F9Vyc aMMI6a4GB8+CRiRaP5AROq3ReX3r6I5AsKiNNZ1UH8ga1dfLt4pSyjQX+EANSkLNNMae AnJyDguklC4G4ns1eGlUYW0xyFtyhPghvJD1GDN/SzHQN6xWo7y0eFBdFzoSHs6a86fo eEzikbOCzleOLAIRF0/RM8mb1i6X5eI92PaS4PsySN90iRPpxtSm/eVAjza/Pf2HUYOc ZtRA== X-Gm-Message-State: APjAAAXFfxUPHp1imGtbvpfTrSk10JJXGS4Gzv8CPMXGWC4c+az2Rz+6 JcP+cOHeRoJ7a24K3VVzED3pZJc4F0QxVqZizP30W3CAbJgIfBKYm7LobnyW3D2Afy+i/+6rOy+ YTb1OOvHYHOvFWdDpAdoRXTdio/a95qI7FGR+uG8YcM4aDzhuK2tkk7vUAvXJ8C0a2g== X-Received: by 2002:a81:1d13:: with SMTP id d19mr72313005ywd.490.1561161463506; Fri, 21 Jun 2019 16:57:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyv1NCR0nIHV/lefrJWpoiARPBToYPfOUjQ03mWknQJUpVoUiKqv3jzgy3Qyl8UK8ttY/Nz X-Received: by 2002:a81:1d13:: with SMTP id d19mr72312987ywd.490.1561161462858; Fri, 21 Jun 2019 16:57:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561161462; cv=none; d=google.com; s=arc-20160816; b=cFu147DOcQebpJ4f2ZLClqk/6m90gYipdixdsKre765u4wlpoC7X60nEbrUruBv3uy V+8HKggfqcA7N8+BZgJ9YdPpiujyXlqL2ZkXhlDUFXp363hDAPxyfcKqxNM6xW5vQIG9 o2iTTpHo1uFrD0MENY4CiZcy7ILyov8nLIJnlUB4cKHJCRXh4kAyA+n6jUwecLN45Snj mLZFbX3E1YGHuSOqYmbAkCmbpZOW2fZ3gtlYuKK1H/san4fHxlNYlaDQF+ZFzYDodUzC +MjP1zCoSuy0VTBYKe86ZF/epThu2lvivEws3R5o8jCOOQG+h6m1puupTfpoYTg1bW6n AwYQ== 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=GoNZ4aRxdLiu9VXKzoYqQXkZ8KvvgodmwFDB7EyF+mY=; b=LPSB5KksRpp6eifo7H5D7i+DxWckYcGVlZQ4rzYLxffoYku1LKgHvVHS86jNMANxOK FlnHTAYHUJ1Eju30z9UJ0jrUaYynCCP7NXaaBQR22VIgSvbZXHcLvAHXAngAaZ87jGai SPfge28XC3pExiqy22527qI3cXjloxhIg7Edd5MaWusc/LDUaUdA+cXDWf8RfKPLNrqZ I8tARHH4TPhpb3VTVyL+hvB/e8fEV1YhHqRGlkdDAj314LGIYa3CCVwsulcEuokzPyNZ mQ8zUBcSIur0relMTusVELPoouNgedPSmBEqquUAWOFMaD7s+f/AEgXm56BK007upi3O cciQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=3Y+kdV0F; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2120.oracle.com (userp2120.oracle.com. [156.151.31.85]) by mx.google.com with ESMTPS id u203si1524995ywu.163.2019.06.21.16.57.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 16:57:42 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 as permitted sender) client-ip=156.151.31.85; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=3Y+kdV0F; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 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 (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5LNsBti058928; Fri, 21 Jun 2019 23:57:35 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=GoNZ4aRxdLiu9VXKzoYqQXkZ8KvvgodmwFDB7EyF+mY=; b=3Y+kdV0FiS+tW5au38wMNPWuEC6sxrct9Yc3CK79Ps2gZr3sIwaz7QELL0qPbY+1qF0J lIgZ3Rgp/6bzk8/RdtUIyrGMt6hJJUyiio72dubmoyXK970/MtSrct7KLItSYck8385+ gKeU/c7adOZBK3y2sgrIhX1NQ2QUEREBJcpWjYVK3mpxNTKe+RrqHXtk3j2LQpRyu9ev J5Mq7oRWE8vTr2OVMFaXnwNKLinN0hH9bh7T21sbTPqWk7ma1VEZDWKSBR6072dcrO+W iKut11/kS8KO+ACrX7Sf61/83yFgeGnY7W/5dTFnHodoCvrlli7/kfhPMyPix5QSOhrZ Bw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2t7809rqvg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:35 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5LNu8OR042309; Fri, 21 Jun 2019 23:57:35 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3030.oracle.com with ESMTP id 2t77ypeshd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 21 Jun 2019 23:57:35 +0000 Received: from userp3030.oracle.com (userp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.27/8.16.0.27) with SMTP id x5LNvYK4044889; Fri, 21 Jun 2019 23:57:34 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2t77ypesh2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:34 +0000 Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x5LNvXDf031731; Fri, 21 Jun 2019 23:57:33 GMT Received: from localhost (/10.159.131.214) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 21 Jun 2019 16:57:33 -0700 Subject: [PATCH 5/7] xfs: refactor setflags to use setattr code directly From: "Darrick J. Wong" To: matthew.garrett@nebula.com, yuchao0@huawei.com, tytso@mit.edu, darrick.wong@oracle.com, ard.biesheuvel@linaro.org, josef@toxicpanda.com, clm@fb.com, adilger.kernel@dilger.ca, viro@zeniv.linux.org.uk, jack@suse.com, dsterba@suse.com, jaegeuk@kernel.org, jk@ozlabs.org Cc: reiserfs-devel@vger.kernel.org, linux-efi@vger.kernel.org, devel@lists.orangefs.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, linux-mtd@lists.infradead.org, ocfs2-devel@oss.oracle.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org Date: Fri, 21 Jun 2019 16:57:30 -0700 Message-ID: <156116145090.1664939.13744166286109265130.stgit@magnolia> In-Reply-To: <156116141046.1664939.11424021489724835645.stgit@magnolia> References: <156116141046.1664939.11424021489724835645.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9295 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906210182 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 Refactor the SETFLAGS implementation to use the SETXATTR code directly instead of partially constructing a struct fsxattr and calling bits and pieces of the setxattr code. This reduces code size and becomes necessary in the next patch to maintain the behavior of allowing userspace to set immutable on an immutable file so long as nothing /else/ about the attributes change. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_ioctl.c | 40 +++------------------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 88583b3e1e76..7b19ba2956ad 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -1491,11 +1491,8 @@ xfs_ioc_setxflags( struct file *filp, void __user *arg) { - struct xfs_trans *tp; struct fsxattr fa; - struct fsxattr old_fa; unsigned int flags; - int join_flags = 0; int error; if (copy_from_user(&flags, arg, sizeof(flags))) @@ -1506,44 +1503,13 @@ xfs_ioc_setxflags( FS_SYNC_FL)) return -EOPNOTSUPP; - fa.fsx_xflags = xfs_merge_ioc_xflags(flags, xfs_ip2xflags(ip)); + __xfs_ioc_fsgetxattr(ip, false, &fa); + fa.fsx_xflags = xfs_merge_ioc_xflags(flags, fa.fsx_xflags); error = mnt_want_write_file(filp); if (error) return error; - - /* - * Changing DAX config may require inode locking for mapping - * invalidation. These need to be held all the way to transaction commit - * or cancel time, so need to be passed through to - * xfs_ioctl_setattr_get_trans() so it can apply them to the join call - * appropriately. - */ - error = xfs_ioctl_setattr_dax_invalidate(ip, &fa, &join_flags); - if (error) - goto out_drop_write; - - tp = xfs_ioctl_setattr_get_trans(ip, join_flags); - if (IS_ERR(tp)) { - error = PTR_ERR(tp); - goto out_drop_write; - } - - __xfs_ioc_fsgetxattr(ip, false, &old_fa); - error = vfs_ioc_fssetxattr_check(VFS_I(ip), &old_fa, &fa); - if (error) { - xfs_trans_cancel(tp); - goto out_drop_write; - } - - error = xfs_ioctl_setattr_xflags(tp, ip, &fa); - if (error) { - xfs_trans_cancel(tp); - goto out_drop_write; - } - - error = xfs_trans_commit(tp); -out_drop_write: + error = xfs_ioctl_setattr(ip, &fa); mnt_drop_write_file(filp); return error; } From patchwork Fri Jun 21 23:57:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11010863 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 25C6C76 for ; Fri, 21 Jun 2019 23:57:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 168232870D for ; Fri, 21 Jun 2019 23:57:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A45C28BAD; Fri, 21 Jun 2019 23:57:54 +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 7B4B12870D for ; Fri, 21 Jun 2019 23:57:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95D828E0009; Fri, 21 Jun 2019 19:57:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 90B298E0001; Fri, 21 Jun 2019 19:57:52 -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 7AC838E0009; Fri, 21 Jun 2019 19:57:52 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id 5AC0D8E0001 for ; Fri, 21 Jun 2019 19:57:52 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id t196so9427304qke.0 for ; Fri, 21 Jun 2019 16:57:52 -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=w6B62XWgEySnIWZsve79cF+lTRasJpmyyQueK4g93UE=; b=CDfYKQpq3i0ezsem/EYQLz7FXErdd1OpKMrBql+MXS8AFvwWlYZ9U7Nf33WiMdo+TY m+En868vDuiIVvm8zAo3vknX6SJ34RNNth0Cr1twks4jSDiZMv5teFKgJf70Bkktyspj nh7WHg6bBPAW36QRsIh+eqHsYJRAcZXfNZL2rR+b8fGnd72uwJNMOL3GvZ7os5HxsYi5 kDT266btpqSB77zMgmRLtULRMFTK9Hh+Le2Dn+kkVAmdZhf9yjp6okR6xLxChdhfff/i joAcclZL9IhOzTy6nd7TeLOuH20PDvSn/2eCWhOnS1aahK99HxSPoXD0Upa8Yv1El5Ox u0Lg== X-Gm-Message-State: APjAAAVFvNF6JhELZLKuq2C2R3q19gsmiNcsts+kC+ArA9MldIincvI3 gYksw6sk4mQyerE6VzeFinSELJglZYvDBk99SIQwUz0yUe4SEIzJcvyKEB+OeycrgeQ09A+nJx5 0SfPwmnaxLWGfAdrcBkRJThGmVxj83Qe9Ku2HmkgS+eY+PQjN7UyK6kD8/Boi0/ToLg== X-Received: by 2002:ac8:3078:: with SMTP id g53mr116526699qte.126.1561161472109; Fri, 21 Jun 2019 16:57:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3MowAHoFazKtTmViHcdR/KY4zYtjKxvL1TJEj4Lx6nf19xg1WPgUDqvYLE38Lz7f9cG55 X-Received: by 2002:ac8:3078:: with SMTP id g53mr116526678qte.126.1561161471604; Fri, 21 Jun 2019 16:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561161471; cv=none; d=google.com; s=arc-20160816; b=jp/ztVTVTWkQXlM+mH7gjnrmoswfVCaBFRpHT2VabyR2NptGUMiAXWZncXU2m4XtWH cfTA5jmMu93jDPypIsUf7cmvdUcoH+xOOnww25tWj6cMROuBRLvVVHw4/GkEHvcdG8yt ApsXPPep9dFA6tRR9vs/3n6dTWFChBIlfYXWPdHOFOiJGqD53MRr911H0fj6hClpNSeV +TAnEgYrCHU/rW+h1q5K5tnFDzlAl5CjUHYCmGhZmEOVgVeU2e5dUMcR4yiNrmtz9c8H zq5Cnhzc+xGtTvNSK+Fy9QorvIjSbCm2I26Yghx0TXqVsVgCZiO1usBWzsSLKzFtWHl1 hPGQ== 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=w6B62XWgEySnIWZsve79cF+lTRasJpmyyQueK4g93UE=; b=BmCD1SxMnic8ne4Jf4acOJY6MdGkad1cq4qlHqqY4ijqogup0+Qw9sc2rLrDXW/VYX WTCdWXe/i1dMRd6FEzpCh6jK6kSwdSLj2ZoM5M0mfNrWPyI2j2sc0YBpJS/Cl37b5G+H tKUwhnl8xpB49CRXV6fJTAHBJT4zMKsaVagoSTuDYkmYxb+HybYUUZygujvIRgszhAPd 8K/plrj6fAhamTmLS+ZVPiYsAd9yoGxjVYr6eI1jqiWIj3LKMTNeGUxdoi7cxqdUvyCe Uw0RcSntY1MnxIIGj8HcvPM+RrGbOBK6KGXOEWavkdJy1S/AQHKMBWv38ATJo+L0igA0 TMkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=LCPK7AWC; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2120.oracle.com (userp2120.oracle.com. [156.151.31.85]) by mx.google.com with ESMTPS id y57si2990660qvh.13.2019.06.21.16.57.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 16:57:51 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 as permitted sender) client-ip=156.151.31.85; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=LCPK7AWC; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 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 (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5LNuMtI060602; Fri, 21 Jun 2019 23:57:44 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=w6B62XWgEySnIWZsve79cF+lTRasJpmyyQueK4g93UE=; b=LCPK7AWCsGBI+RqAzXGFgNPkRiXblgkq9WSLzaq9Z5PAnvNp/X/wTP3QFBjyDnp8Bgll L3vmL6Xq68Xv+Yf0N1PngmAjU64QyoIR07RPDYMd1ftuds6jFGEtNEZHw9W/Y3ze8Szf EU7883mLnIRViAC3o8bFq1u+W+6Zgwly1DzWCMBrnmxPgfRYeEdOB2PYCDEvh2T8mX82 ma/K8Md7Uepq4zO72Jn1QXSWCa+54A4BmVUS1lIDC0gbWvA6b71iVR01TRGSHLg2vO41 axO4hlGWZmk4yOHrsvTiApeDqICstAnZjwOptSjUH2isRmYV5KhT+PO+naU0f5eOU+zO hA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2t7809rqw6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:44 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5LNuYZh036128; Fri, 21 Jun 2019 23:57:43 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 2t77yq6ug3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 21 Jun 2019 23:57:43 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.27/8.16.0.27) with SMTP id x5LNvhDq037856; Fri, 21 Jun 2019 23:57:43 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2t77yq6ufw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:43 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x5LNvfqC020811; Fri, 21 Jun 2019 23:57:41 GMT Received: from localhost (/10.159.131.214) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 21 Jun 2019 16:57:41 -0700 Subject: [PATCH 6/7] xfs: clean up xfs_merge_ioc_xflags From: "Darrick J. Wong" To: matthew.garrett@nebula.com, yuchao0@huawei.com, tytso@mit.edu, darrick.wong@oracle.com, ard.biesheuvel@linaro.org, josef@toxicpanda.com, clm@fb.com, adilger.kernel@dilger.ca, viro@zeniv.linux.org.uk, jack@suse.com, dsterba@suse.com, jaegeuk@kernel.org, jk@ozlabs.org Cc: reiserfs-devel@vger.kernel.org, linux-efi@vger.kernel.org, devel@lists.orangefs.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, linux-mtd@lists.infradead.org, ocfs2-devel@oss.oracle.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org Date: Fri, 21 Jun 2019 16:57:38 -0700 Message-ID: <156116145859.1664939.13167913873080632498.stgit@magnolia> In-Reply-To: <156116141046.1664939.11424021489724835645.stgit@magnolia> References: <156116141046.1664939.11424021489724835645.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9295 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=612 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906210182 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 Clean up the calling convention since we're editing the fsxattr struct anyway. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_ioctl.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 7b19ba2956ad..a67bc9afdd0b 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -829,35 +829,31 @@ xfs_ioc_ag_geometry( * Linux extended inode flags interface. */ -STATIC unsigned int +static inline void xfs_merge_ioc_xflags( - unsigned int flags, - unsigned int start) + struct fsxattr *fa, + unsigned int flags) { - unsigned int xflags = start; - if (flags & FS_IMMUTABLE_FL) - xflags |= FS_XFLAG_IMMUTABLE; + fa->fsx_xflags |= FS_XFLAG_IMMUTABLE; else - xflags &= ~FS_XFLAG_IMMUTABLE; + fa->fsx_xflags &= ~FS_XFLAG_IMMUTABLE; if (flags & FS_APPEND_FL) - xflags |= FS_XFLAG_APPEND; + fa->fsx_xflags |= FS_XFLAG_APPEND; else - xflags &= ~FS_XFLAG_APPEND; + fa->fsx_xflags &= ~FS_XFLAG_APPEND; if (flags & FS_SYNC_FL) - xflags |= FS_XFLAG_SYNC; + fa->fsx_xflags |= FS_XFLAG_SYNC; else - xflags &= ~FS_XFLAG_SYNC; + fa->fsx_xflags &= ~FS_XFLAG_SYNC; if (flags & FS_NOATIME_FL) - xflags |= FS_XFLAG_NOATIME; + fa->fsx_xflags |= FS_XFLAG_NOATIME; else - xflags &= ~FS_XFLAG_NOATIME; + fa->fsx_xflags &= ~FS_XFLAG_NOATIME; if (flags & FS_NODUMP_FL) - xflags |= FS_XFLAG_NODUMP; + fa->fsx_xflags |= FS_XFLAG_NODUMP; else - xflags &= ~FS_XFLAG_NODUMP; - - return xflags; + fa->fsx_xflags &= ~FS_XFLAG_NODUMP; } STATIC unsigned int @@ -1504,7 +1500,7 @@ xfs_ioc_setxflags( return -EOPNOTSUPP; __xfs_ioc_fsgetxattr(ip, false, &fa); - fa.fsx_xflags = xfs_merge_ioc_xflags(flags, fa.fsx_xflags); + xfs_merge_ioc_xflags(&fa, flags); error = mnt_want_write_file(filp); if (error) From patchwork Fri Jun 21 23:57:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11010875 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 C3A9A186E for ; Fri, 21 Jun 2019 23:58:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0B6A2870D for ; Fri, 21 Jun 2019 23:58:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9416728BB4; Fri, 21 Jun 2019 23:58:02 +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 016D728B81 for ; Fri, 21 Jun 2019 23:58:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEE8F8E000A; Fri, 21 Jun 2019 19:58:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D780B8E0001; Fri, 21 Jun 2019 19:58:00 -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 C18A48E000A; Fri, 21 Jun 2019 19:58:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f72.google.com (mail-yw1-f72.google.com [209.85.161.72]) by kanga.kvack.org (Postfix) with ESMTP id 9E7658E0001 for ; Fri, 21 Jun 2019 19:58:00 -0400 (EDT) Received: by mail-yw1-f72.google.com with SMTP id w127so8028805ywe.6 for ; Fri, 21 Jun 2019 16:58:00 -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=rwZuzZLu2QSuxM1deZeCZnnfsOeZtWtWWa3iVLz4Y0o=; b=UBxPV/TPDjajH2rhDxXOBx5pfkSAJUjizHcIfVVSEUJfocq0GPx5tS4iJPr3MO0lg3 KViVQVd7sQgfGbjBtTItc+gOl952vwetTVxSCTrcpAPTadUCBmlEpvtYwOiNnJwn4OdI SMWX+rX3II2V8b1nIT2QWmi093DeJJrpjFH2pftKiezvR60A1IKQmOunATh882ksZrz8 gzLZc7rUS6NLLMA08GpRTOZaM+/rCMFvTPTtvNu8WQW4mlMlGDIgYKJaO+cHu3i0ANJh d33a25/tEjdBS8E+uxdfVZsT6+SP20ylxly2megWryrlzxgQkpyjqrohUSlDeFUBsmnh +YCw== X-Gm-Message-State: APjAAAVlrxUt44TRSP/9UKUpVhHmjCsVg+19pR0Q4o3F8PShiBmdg28B erFYT3EFUmb6lnY40mZVF+NIEfVu5aIkxqqOa1IUYYICgSat0YyfGZp8wKud74LE78dRMz7NcqO vJmmG76Pkr2PN+H+EcMWGZD1WuJnrutTGg7rqeUbvQBb5XtSL3lILCJF33cphbmOFsQ== X-Received: by 2002:a25:e405:: with SMTP id b5mr7436691ybh.330.1561161480392; Fri, 21 Jun 2019 16:58:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHi0EAHtyvlY5LBWepYCtcbb4RFUgN7Ma0GYibx5lePSb1pnDFnALLZnTehu5eDEEzeBZ5 X-Received: by 2002:a25:e405:: with SMTP id b5mr7436673ybh.330.1561161479765; Fri, 21 Jun 2019 16:57:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561161479; cv=none; d=google.com; s=arc-20160816; b=bp68dM6HIbQ5GMrtG6dx72dQbQ4csOXX8IYL8wHmtEUWGQVkTR3StpU3B+8FjScKJ+ jaf56Dw/zvvsRn4SH2+XaS3LQRAh1S6tVctoGA43yRZANYBnts91UMEFpcNyBqL/Jhjy LJdSO0Ava52hhC9VF2MxH5H/dRUkJ+4YYfvdIVvS0AoExFo2ye4Gep1xmIbLZaGmIev/ OWYh92uLn+0nFwjP+veCvFm+OqwcS0p1mT2Z4w06KuY8VVHbybhh9K9AL6ee4J8DeG3F 9RRg4qw2WqvqtjPMZWor/t1LDwfgnsNAyHCJ2DXaD3dsrOJ5+65BjgMwUGEytxnq5FRY JOgA== 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=rwZuzZLu2QSuxM1deZeCZnnfsOeZtWtWWa3iVLz4Y0o=; b=Pz9juVQ5NsGjXwjfydENFUAOXkzp2EwI0BOVXiScJNR6dgQgYaPhx6btQi27i+3bF2 PMg2LbDHiLXXniCEYrda3vnFmImB3qz9OLTmmxa7wpZHMS2hNN/UA0PsW3jixcaRzjZG D4lzIUaG03VTcpH6YFl0cYpmbYZBsFKxM6tOWmMLzTusH9UYYc7cewC/mXdLpRZ3e6Fy 91DZxVcX/IR1b8XfXuJhJwVog5LDKBM+j7hJvePfQqjRYhkEpyNpUnGXYFvKBaJ8wac/ fapA3/vNTBHiP+ze7guQYEi0whg2GDrPQmvPRSrX33lsKpPyV1OI3oDOy3cEgniNIdO+ UwWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=j4pMav0S; 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 9si1562616ybq.246.2019.06.21.16.57.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 16:57:59 -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=j4pMav0S; 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.27/8.16.0.27) with SMTP id x5LNt22Y052769; Fri, 21 Jun 2019 23:57:53 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=rwZuzZLu2QSuxM1deZeCZnnfsOeZtWtWWa3iVLz4Y0o=; b=j4pMav0SW7e9IFJcTpCLcn4neiQwevtJo2J+lHllOH0GrPdCMsB8iQfSOQ1NgxlBqbVT OICMIQi3C2UlR7VmtDc28J0RWQyGpW/svba+WkpNuDwnYYbtGkzIR9onweaaZ42Hjd4v 7+6DtESjx18TSxlVMjfOZTOLmVoXhIFnHLJx/ZuAg0EjP7ntcN5y53Ydpo+wlR3McVro P/X2vkBxkiaF5hh8rtBC9Y3IHL9TJQU9hmFMqtuN/6D9K20cct8ZF1rNphEDE4665jhl j72tS2nlAV7F8v5YLxysiYVfhqU1R1I/qPp3EaMXTsfzZ3rfbLk0QJO1ozCXzn3jkiUu FA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2t7809rsyd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:53 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5LNvFfg108897; Fri, 21 Jun 2019 23:57:52 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3020.oracle.com with ESMTP id 2t77ypetb6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 21 Jun 2019 23:57:52 +0000 Received: from userp3020.oracle.com (userp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.27/8.16.0.27) with SMTP id x5LNvq84109606; Fri, 21 Jun 2019 23:57:52 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 2t77ypetb3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 23:57:52 +0000 Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x5LNvocq020839; Fri, 21 Jun 2019 23:57:50 GMT Received: from localhost (/10.159.131.214) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 21 Jun 2019 16:57:49 -0700 Subject: [PATCH 7/7] vfs: don't allow writes to swap files From: "Darrick J. Wong" To: matthew.garrett@nebula.com, yuchao0@huawei.com, tytso@mit.edu, darrick.wong@oracle.com, ard.biesheuvel@linaro.org, josef@toxicpanda.com, clm@fb.com, adilger.kernel@dilger.ca, viro@zeniv.linux.org.uk, jack@suse.com, dsterba@suse.com, jaegeuk@kernel.org, jk@ozlabs.org Cc: reiserfs-devel@vger.kernel.org, linux-efi@vger.kernel.org, devel@lists.orangefs.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, linux-mtd@lists.infradead.org, ocfs2-devel@oss.oracle.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org Date: Fri, 21 Jun 2019 16:57:46 -0700 Message-ID: <156116146628.1664939.13724544486987830540.stgit@magnolia> In-Reply-To: <156116141046.1664939.11424021489724835645.stgit@magnolia> References: <156116141046.1664939.11424021489724835645.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9295 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=969 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906210182 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 Don't let userspace write to an active swap file because the kernel effectively has a long term lease on the storage and things could get seriously corrupted if we let this happen. Signed-off-by: Darrick J. Wong --- fs/attr.c | 3 +++ mm/filemap.c | 3 +++ mm/memory.c | 4 +++- mm/mmap.c | 2 ++ mm/swapfile.c | 15 +++++++++++++-- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index 1fcfdcc5b367..42f4d4fb0631 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -236,6 +236,9 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de if (IS_IMMUTABLE(inode)) return -EPERM; + if (IS_SWAPFILE(inode)) + return -ETXTBSY; + if ((ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) && IS_APPEND(inode)) return -EPERM; diff --git a/mm/filemap.c b/mm/filemap.c index dad85e10f5f8..fd80bc20e30a 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2938,6 +2938,9 @@ inline ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from) if (IS_IMMUTABLE(inode)) return -EPERM; + if (IS_SWAPFILE(inode)) + return -ETXTBSY; + if (!iov_iter_count(from)) return 0; diff --git a/mm/memory.c b/mm/memory.c index 4311cfdade90..c04c6a689995 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2235,7 +2235,9 @@ static vm_fault_t do_page_mkwrite(struct vm_fault *vmf) vmf->flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE; - if (vmf->vma->vm_file && IS_IMMUTABLE(file_inode(vmf->vma->vm_file))) + if (vmf->vma->vm_file && + (IS_IMMUTABLE(file_inode(vmf->vma->vm_file)) || + IS_SWAPFILE(file_inode(vmf->vma->vm_file)))) return VM_FAULT_SIGBUS; ret = vmf->vma->vm_ops->page_mkwrite(vmf); diff --git a/mm/mmap.c b/mm/mmap.c index ac1e32205237..031807339869 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1488,6 +1488,8 @@ unsigned long do_mmap(struct file *file, unsigned long addr, return -EACCES; if (IS_IMMUTABLE(file_inode(file))) return -EPERM; + if (IS_SWAPFILE(file_inode(file))) + return -ETXTBSY; } /* diff --git a/mm/swapfile.c b/mm/swapfile.c index 596ac98051c5..390859785558 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3165,6 +3165,19 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) if (error) goto bad_swap; + /* + * Flush any pending IO and dirty mappings before we start using this + * swap file. + */ + if (S_ISREG(inode->i_mode)) { + inode->i_flags |= S_SWAPFILE; + error = inode_flush_data(inode); + if (error) { + inode->i_flags &= ~S_SWAPFILE; + goto bad_swap; + } + } + mutex_lock(&swapon_mutex); prio = -1; if (swap_flags & SWAP_FLAG_PREFER) @@ -3185,8 +3198,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) atomic_inc(&proc_poll_event); wake_up_interruptible(&proc_poll_wait); - if (S_ISREG(inode->i_mode)) - inode->i_flags |= S_SWAPFILE; error = 0; goto out; bad_swap: