From patchwork Tue Apr 26 17:43:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12827659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50CD1C433F5 for ; Tue, 26 Apr 2022 17:44:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBEAE6B0089; Tue, 26 Apr 2022 13:44:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E43596B008A; Tue, 26 Apr 2022 13:44:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE49A6B0092; Tue, 26 Apr 2022 13:44:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 9F85F6B008A for ; Tue, 26 Apr 2022 13:44:14 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8429B2619B for ; Tue, 26 Apr 2022 17:44:14 +0000 (UTC) X-FDA: 79399754028.26.D1A0B53 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf21.hostedemail.com (Postfix) with ESMTP id 103401C0052 for ; Tue, 26 Apr 2022 17:44:10 +0000 (UTC) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 23QGQTdQ024678 for ; Tue, 26 Apr 2022 10:44:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=H1gaP7rmwRkzgL1zpgAy7/OkhOf1XEN09A0i6oOpXGo=; b=TaF5a1rhf6dMGoL27gH9Ot05WWSLx8kTwjXIjHwikOTmRLbJT1tvguQqL121Pv/d39j2 kxq/M90b8V+U7BhxPnIybKpDKR+s7BPs68ulpOttJGOIZUvZ9dgh7kOn4awBHU82f7WC xserZ7G3AQr7hkKOBOhIpamM0+0MP7nTMtY= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3fn1ge03h8-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 26 Apr 2022 10:44:12 -0700 Received: from twshared6486.05.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 26 Apr 2022 10:44:12 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id B06AAE2D4867; Tue, 26 Apr 2022 10:43:40 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , Subject: [RFC PATCH v1 10/18] xfs: Enable async write file modification handling. Date: Tue, 26 Apr 2022 10:43:27 -0700 Message-ID: <20220426174335.4004987-11-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220426174335.4004987-1-shr@fb.com> References: <20220426174335.4004987-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: x6hPjKyyTt4LKwrhxm2bmgAqmz8bRdeA X-Proofpoint-GUID: x6hPjKyyTt4LKwrhxm2bmgAqmz8bRdeA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-26_05,2022-04-26_02,2022-02-23_01 X-Rspamd-Queue-Id: 103401C0052 X-Stat-Signature: 444f3sctanh4nn38n8fn47jareukk18r X-Rspam-User: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=TaF5a1rh; spf=none (imf21.hostedemail.com: domain of "prvs=5115329de3=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=5115329de3=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com X-Rspamd-Server: rspam09 X-HE-Tag: 1650995050-950772 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: This modifies xfs write checks to return -EAGAIN if the request either requires to remove privileges or needs to update the file modification time. This is required for async buffered writes, so the request gets handled in the io worker. Signed-off-by: Stefan Roesch --- fs/xfs/xfs_file.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 5bddb1e9e0b3..6f9da1059e8b 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -299,6 +299,43 @@ xfs_file_read_iter( return ret; } +static int xfs_file_modified(struct file *file, int flags) +{ + int ret; + struct dentry *dentry = file_dentry(file); + struct inode *inode = file_inode(file); + struct timespec64 now = current_time(inode); + + /* + * Clear the security bits if the process is not being run by root. + * This keeps people from modifying setuid and setgid binaries. + */ + ret = need_file_remove_privs(inode, dentry); + if (ret < 0) { + return ret; + } else if (ret > 0) { + if (flags & IOCB_NOWAIT) + return -EAGAIN; + + ret = do_file_remove_privs(file, inode, dentry, ret); + if (ret) + return ret; + } + + ret = need_file_update_time(inode, file, &now); + if (ret <= 0) + return ret; + if (flags & IOCB_NOWAIT) { + if (IS_PENDING_TIME(inode)) + return 0; + + inode->i_flags |= S_PENDING_TIME; + return -EAGAIN; + } + + return do_file_update_time(inode, file, &now, ret); +} + /* * Common pre-write limit and setup checks. * @@ -410,7 +447,7 @@ xfs_file_write_checks( spin_unlock(&ip->i_flags_lock); out: - return file_modified(file); + return xfs_file_modified(file, iocb->ki_flags); } static int