From patchwork Mon Aug 22 16:27:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12950920 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6BF7C28D13 for ; Mon, 22 Aug 2022 16:28:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237029AbiHVQ2W (ORCPT ); Mon, 22 Aug 2022 12:28:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237012AbiHVQ2P (ORCPT ); Mon, 22 Aug 2022 12:28:15 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5487101; Mon, 22 Aug 2022 09:28:12 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id k18-20020a05600c0b5200b003a5dab49d0bso6309525wmr.3; Mon, 22 Aug 2022 09:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=uYrJzm2OiQQN3lvK2knCDJ6v9s4sNITV4hwedxG7cpk=; b=MMI5G096K+Nm3DQo5LfM8EdSA3O5ZEWa02aVVjpnyxNTKjZC+LWjzuSN+544ZtN8Hg IdIAAL7dIoYlkhCxbeE2ORfGBbvIuiYAr7PUOAdCBK4j8w6BdkNEEuzsaQ9nN+1cy/39 hnObl6kGzFspijB50haBeOFgl/lJdm1IswjnqQUsFHBxf/ZPdrvOvMvTlLMmwF3lWny5 QgrQppjQVuxgMUL0ocLY8nJt/U2h0dS2QfOrziuG8CWGEC02FqIk5+orJQv2dydK6SYy EZCAcNHb76rxgIqIAQuqWgO+2YhTM3G/jdKtlV01KGG3K31KqYNYzBy85rjI47Hiy1MV ZHFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=uYrJzm2OiQQN3lvK2knCDJ6v9s4sNITV4hwedxG7cpk=; b=Q43dj6YX0uO64y02QT+lkdWChLITy8PeRLsTq/oLtbwPJkvbdPmmcfByzhJ2R1esEX 9/VoPdIusiYXOmX5RHELENPtIEw9J7RWFj+/EuroBKc+OdTgHWaVXZS7T5hgEqmw+P7a tVap2FKWY9yYlmOl1Kf0umkwPalwyS8iODsZuGFiV76QVweXGiAF6ENWQlx7PeTWC7d1 5mIWRpOFXAU6i1nooO4OfXBsABDwXgEg+Rc2R5AJqd1jLQnm01JFfWEtGAC2/BuLV+1F RcrMsj8nydao3ikP62ylMoHhQAOb8AZ2+8Jg0ZLxP/lBo8jyz/gl8FPgppsnjIA9Kfu0 KOAw== X-Gm-Message-State: ACgBeo3Os5QV9lofRGKtYvzpzAS1CTCnY6YBNLTgLcYfk2A7zXFLWXqM UoPL95S7TRasXqv2osoEumeqUV+MGW4= X-Google-Smtp-Source: AA6agR4pSeIjIJoEOKEgWtyeLUD4TD4gkUlyGdsvPkupt0L9VwMQOsyRTw7w02OGV3M6Qfv1ORhNPg== X-Received: by 2002:a05:600c:a02:b0:39c:97cc:82e3 with SMTP id z2-20020a05600c0a0200b0039c97cc82e3mr15934147wmp.97.1661185691178; Mon, 22 Aug 2022 09:28:11 -0700 (PDT) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id z13-20020a5d44cd000000b00222ed7ea203sm11749229wrr.100.2022.08.22.09.28.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 09:28:10 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Leah Rumancik , Chandan Babu R , linux-xfs@vger.kernel.org, fstests@vger.kernel.org, Dan Carpenter Subject: [PATCH 5.10 CANDIDATE 1/6] xfs: prevent a WARN_ONCE() in xfs_ioc_attr_list() Date: Mon, 22 Aug 2022 19:27:57 +0300 Message-Id: <20220822162802.1661512-2-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822162802.1661512-1-amir73il@gmail.com> References: <20220822162802.1661512-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Dan Carpenter commit 6ed6356b07714e0198be3bc3ecccc8b40a212de4 upstream. The "bufsize" comes from the root user. If "bufsize" is negative then, because of type promotion, neither of the validation checks at the start of the function are able to catch it: if (bufsize < sizeof(struct xfs_attrlist) || bufsize > XFS_XATTR_LIST_MAX) return -EINVAL; This means "bufsize" will trigger (WARN_ON_ONCE(size > INT_MAX)) in kvmalloc_node(). Fix this by changing the type from int to size_t. Signed-off-by: Dan Carpenter Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Amir Goldstein --- fs/xfs/xfs_ioctl.c | 2 +- fs/xfs/xfs_ioctl.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 646735aad45d..d973350d5946 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -371,7 +371,7 @@ int xfs_ioc_attr_list( struct xfs_inode *dp, void __user *ubuf, - int bufsize, + size_t bufsize, int flags, struct xfs_attrlist_cursor __user *ucursor) { diff --git a/fs/xfs/xfs_ioctl.h b/fs/xfs/xfs_ioctl.h index bab6a5a92407..416e20de66e7 100644 --- a/fs/xfs/xfs_ioctl.h +++ b/fs/xfs/xfs_ioctl.h @@ -38,8 +38,9 @@ xfs_readlink_by_handle( int xfs_ioc_attrmulti_one(struct file *parfilp, struct inode *inode, uint32_t opcode, void __user *uname, void __user *value, uint32_t *len, uint32_t flags); -int xfs_ioc_attr_list(struct xfs_inode *dp, void __user *ubuf, int bufsize, - int flags, struct xfs_attrlist_cursor __user *ucursor); +int xfs_ioc_attr_list(struct xfs_inode *dp, void __user *ubuf, + size_t bufsize, int flags, + struct xfs_attrlist_cursor __user *ucursor); extern struct dentry * xfs_handle_to_dentry( From patchwork Mon Aug 22 16:27:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12950921 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FFB4C32772 for ; Mon, 22 Aug 2022 16:28:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237016AbiHVQ2X (ORCPT ); Mon, 22 Aug 2022 12:28:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237014AbiHVQ2P (ORCPT ); Mon, 22 Aug 2022 12:28:15 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF9E92A2; Mon, 22 Aug 2022 09:28:13 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id k18-20020a05600c0b5200b003a5dab49d0bso6309559wmr.3; Mon, 22 Aug 2022 09:28:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=59bI0yR2jhIr7DA55+u7TB6jQiSVDZFeMCHEmKcrfqs=; b=AHjq2nTcmkrdEHKSt1IjuUkA4AkTGYH/M53d9Cjo6tX8x12+YMTcfni1wU7w6VKxMJ TGRLnYjDNze0BI/XPAR3s13GK+74QEHNUuzQH11WqHmQ7yJGfMEM/gWYEVrXZQH6dMPZ F4eJelGT5N5LkuXvTmp/rDeE84xOCCal+6RwHAdoYbenw8XxnlLfzowi6xU0+sNx/C7r wMi04hlkvSHM/FV5JLi/9xy8B2VZ+f8XdDZ+eybSxCxiSyvRA2+Td/NMQwaK3Tetv0Qt gBI5IgPmIHHbvKg5Jwmi+JsyRL7sdzQDKGCSeJM2NVRkVq63dZj2Pg/bZ0b/GE8dNmUa GrTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=59bI0yR2jhIr7DA55+u7TB6jQiSVDZFeMCHEmKcrfqs=; b=Fh/C3ON5rn+WqCbQuK6t7yI4y7aE2lksk6IUZxY21mznCmDat71uSSoilMtL6kF+jE yXQbtLnXA/E9tkGtzilURX5wGuBp+U1WXFWTT75dWyXYXJUnPEjRxvcjskgVL7v2A5HJ kL5FFCAVIlg/S7T+J6eVTzCUY+g54eY2Dcj78bWcwt7n2t76UF/lzsjPMQ5mlDHf4PxN P0NFnApiBzWd4B1pWd8YhG75QAxN58sni41CI28GkfAXyHvIcYVztCaFg2nLJWS/LWXm ile1rPxZqRD21KUNU+CLZd7r0JZlcNzzChHH8dEq1alBZwOz8LEEWPf5ci+gciu1QQS9 pKOQ== X-Gm-Message-State: ACgBeo0Or5cdZQRpZ9pfW7CYvpIiScBW/Uj66Kt8mPkUh7IT6yQdV+ae m+y5Hjp/zHFv2cQoBwoFGps= X-Google-Smtp-Source: AA6agR7HtIgZumh2Bal7Job0hNfZhRdT5pqSBvP0JFX+cnUYafm10CcVXENgjOP5fkfdlL06Ps9PEA== X-Received: by 2002:a1c:a187:0:b0:3a5:e055:715b with SMTP id k129-20020a1ca187000000b003a5e055715bmr12975931wme.171.1661185692443; Mon, 22 Aug 2022 09:28:12 -0700 (PDT) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id z13-20020a5d44cd000000b00222ed7ea203sm11749229wrr.100.2022.08.22.09.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 09:28:12 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Leah Rumancik , Chandan Babu R , linux-xfs@vger.kernel.org, fstests@vger.kernel.org, Allison Henderson , Catherine Hoang Subject: [PATCH 5.10 CANDIDATE 2/6] xfs: reject crazy array sizes being fed to XFS_IOC_GETBMAP* Date: Mon, 22 Aug 2022 19:27:58 +0300 Message-Id: <20220822162802.1661512-3-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822162802.1661512-1-amir73il@gmail.com> References: <20220822162802.1661512-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: "Darrick J. Wong" commit 29d650f7e3ab55283b89c9f5883d0c256ce478b5 upstream. Syzbot tripped over the following complaint from the kernel: WARNING: CPU: 2 PID: 15402 at mm/util.c:597 kvmalloc_node+0x11e/0x125 mm/util.c:597 While trying to run XFS_IOC_GETBMAP against the following structure: struct getbmap fubar = { .bmv_count = 0x22dae649, }; Obviously, this is a crazy huge value since the next thing that the ioctl would do is allocate 37GB of memory. This is enough to make kvmalloc mad, but isn't large enough to trip the validation functions. In other words, I'm fussing with checks that were **already sufficient** because that's easier than dealing with 644 internal bug reports. Yes, that's right, six hundred and forty-four. Signed-off-by: Darrick J. Wong Reviewed-by: Allison Henderson Reviewed-by: Catherine Hoang Signed-off-by: Amir Goldstein --- fs/xfs/xfs_ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index d973350d5946..103fa8381e7d 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -1689,7 +1689,7 @@ xfs_ioc_getbmap( if (bmx.bmv_count < 2) return -EINVAL; - if (bmx.bmv_count > ULONG_MAX / recsize) + if (bmx.bmv_count >= INT_MAX / recsize) return -ENOMEM; buf = kvzalloc(bmx.bmv_count * sizeof(*buf), GFP_KERNEL); From patchwork Mon Aug 22 16:27:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12950922 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1760C38142 for ; Mon, 22 Aug 2022 16:28:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237038AbiHVQ21 (ORCPT ); Mon, 22 Aug 2022 12:28:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237018AbiHVQ2Q (ORCPT ); Mon, 22 Aug 2022 12:28:16 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61B153BD; Mon, 22 Aug 2022 09:28:15 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id z14-20020a7bc7ce000000b003a5db0388a8so5962921wmk.1; Mon, 22 Aug 2022 09:28:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=a+j0v/WuqVSvmnAdOqE+a9Tv3zr3uqGMUrJc5B6a3zo=; b=LfdcU9IBxGkjrrjwLSi7lxXGlGltjfU+W7MKJgIPsMbwqZtPamOCPkesFy/nH1tu0N j0ry+kx3p07ZZ8Ucv87n3n/hzkBdJTp2dLx4BSSGDJxUj4sVTjcLNiV4VGnoOGU9qZfY BnB/GjAz3lb51kKmkv4BL2/lnq4aQlX57MxY9I1zyVq+EOf8yAcpeIaUKt1GH+Wt3bau aQn+AWiJ4YbssfsRyPXNG4jmhnmtPTOEykJGhOFSW3i9BkaWf98wqZZiHmP13Va/nLSZ AW/7yZJoaBdsHBCkS91MdKUTxkMeAiM1xqcTH56NJjmGiBgCU4d9Jj+i/dNuSG2PiLmY IRLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=a+j0v/WuqVSvmnAdOqE+a9Tv3zr3uqGMUrJc5B6a3zo=; b=uV+z0bTrg/zzbwzFv3DPzH59GP4tsxSUNlNGNKDzCUqvdZEEY4ui2/g8g+HFJQw9yn svoH1OJFrHEDDk8D+TnbiTwf2gBLzbFnAJI6kOooHetlptP1bmybrqZg+YeX5X4oCaFG S0VBHTgqx+pwfslAIcHBYWxpoby7OCHsfnpF27+SyCYqrsByjA1Sovl8rGOp5Ycf89bO 31HKpmMUt1NfNJtvB5ILevduvye3rQsFfAQo1Uec0Z3XUGMjVnlzcwINZpsZ9G+EOB90 bivmkvdbUho6oINGtM27NsMNlSzcXJQE9Bb8/llDBEs/NNpvtwj6BO+k272uTKGBx5Tb yqgg== X-Gm-Message-State: ACgBeo2NMjR6sEWveFTQjdMekUB9G0pl8fBl9oseumAbwBNSmLJS3vgB oPC0L/RTuQb/d4YuFgmzEo0= X-Google-Smtp-Source: AA6agR4Whc6w79g7yLsWxqc4WRqLK3I3an3DkvppBty0t1EBhHndZ/efNRRo6XcGHnY8Uqn2m47n4A== X-Received: by 2002:a05:600c:4e0f:b0:3a5:e065:9b50 with SMTP id b15-20020a05600c4e0f00b003a5e0659b50mr16045699wmq.35.1661185693785; Mon, 22 Aug 2022 09:28:13 -0700 (PDT) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id z13-20020a5d44cd000000b00222ed7ea203sm11749229wrr.100.2022.08.22.09.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 09:28:13 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Leah Rumancik , Chandan Babu R , linux-xfs@vger.kernel.org, fstests@vger.kernel.org, Christoph Hellwig , Chaitanya Kulkarni , Jens Axboe Subject: [PATCH 5.10 CANDIDATE 3/6] fs: remove __sync_filesystem Date: Mon, 22 Aug 2022 19:27:59 +0300 Message-Id: <20220822162802.1661512-4-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822162802.1661512-1-amir73il@gmail.com> References: <20220822162802.1661512-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Christoph Hellwig commit 9a208ba5c9afa62c7b1e9c6f5e783066e84e2d3c upstream. [backported for dependency] There is no clear benefit in having this helper vs just open coding it. Signed-off-by: Christoph Hellwig Reviewed-by: Chaitanya Kulkarni Link: https://lore.kernel.org/r/20211019062530.2174626-2-hch@lst.de Signed-off-by: Jens Axboe Signed-off-by: Amir Goldstein --- fs/sync.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/fs/sync.c b/fs/sync.c index 1373a610dc78..0d6cdc507cb9 100644 --- a/fs/sync.c +++ b/fs/sync.c @@ -21,25 +21,6 @@ #define VALID_FLAGS (SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE| \ SYNC_FILE_RANGE_WAIT_AFTER) -/* - * Do the filesystem syncing work. For simple filesystems - * writeback_inodes_sb(sb) just dirties buffers with inodes so we have to - * submit IO for these buffers via __sync_blockdev(). This also speeds up the - * wait == 1 case since in that case write_inode() functions do - * sync_dirty_buffer() and thus effectively write one block at a time. - */ -static int __sync_filesystem(struct super_block *sb, int wait) -{ - if (wait) - sync_inodes_sb(sb); - else - writeback_inodes_sb(sb, WB_REASON_SYNC); - - if (sb->s_op->sync_fs) - sb->s_op->sync_fs(sb, wait); - return __sync_blockdev(sb->s_bdev, wait); -} - /* * Write out and wait upon all dirty data associated with this * superblock. Filesystem data as well as the underlying block @@ -61,10 +42,25 @@ int sync_filesystem(struct super_block *sb) if (sb_rdonly(sb)) return 0; - ret = __sync_filesystem(sb, 0); + /* + * Do the filesystem syncing work. For simple filesystems + * writeback_inodes_sb(sb) just dirties buffers with inodes so we have + * to submit I/O for these buffers via __sync_blockdev(). This also + * speeds up the wait == 1 case since in that case write_inode() + * methods call sync_dirty_buffer() and thus effectively write one block + * at a time. + */ + writeback_inodes_sb(sb, WB_REASON_SYNC); + if (sb->s_op->sync_fs) + sb->s_op->sync_fs(sb, 0); + ret = __sync_blockdev(sb->s_bdev, 0); if (ret < 0) return ret; - return __sync_filesystem(sb, 1); + + sync_inodes_sb(sb); + if (sb->s_op->sync_fs) + sb->s_op->sync_fs(sb, 1); + return __sync_blockdev(sb->s_bdev, 1); } EXPORT_SYMBOL(sync_filesystem); From patchwork Mon Aug 22 16:28:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12950923 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39547C32789 for ; Mon, 22 Aug 2022 16:28:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237022AbiHVQ20 (ORCPT ); Mon, 22 Aug 2022 12:28:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237025AbiHVQ2R (ORCPT ); Mon, 22 Aug 2022 12:28:17 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0A18E9A; Mon, 22 Aug 2022 09:28:16 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id r16so13892507wrm.6; Mon, 22 Aug 2022 09:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=q/FI4CYR+WYkVFva7q03Gliz+K3Jnhdatwd2qEAi2Ao=; b=G3inXztuNs6ypVb1NVRJ8CdJzgxlJMB2mRdjf/EmS7SLOcBfZZSwgTQZCmJbgTNkaX hICVtUk24z0oaPZA5lX694qFK+hczNmto+DIyVyH1FCqVKn58UXG5zOl8yAfGGrEAGbv XFpRJXq94KZIq6z5Yg0YLVsuCZXOnn7mK4+s5fxXVzvOBysKXRZuNppg2MTL494NJP3W u0yrVjwQV9omEoidB+VkOw+lT/Er7EjPCL3kB2pUZx3mEh9bdrMsxtoMtCt05Wybwq3J TADNsUcSu+TTPN10efrEYENviAkiAuRfDGphnZcxgDdhkoaZVhJCGJldQlXogtYA4q5g BVJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=q/FI4CYR+WYkVFva7q03Gliz+K3Jnhdatwd2qEAi2Ao=; b=P84oBuMPl56zVCj1NEsQ5/QIIiB+GzyrHDXKZkpxsEtGBo53k/cOHLCMpLhaI+wh3C yukaG0zdJUTwmgeT3AKAgy0ANt6Do1AA4xKSoHTBzMM6QUseokyXs6fbnFqAms8islmi P7lR1CwfMRVvQP8TVlLKSHkzFHLgdV8DLpOzuY08FNxHUOtRqBz7VxmuskhEMcdSmrkr +5D9ktWCZlhl+PAHoasGOFg7SAdxmAdO5AppSF50ItxVZWl6g6zESGPJqwMDZGOg/lO2 fBLLujfkll55gA08yCK4YJbFGjrChY8NuPV60aaOTL1kCEJT/6G+rimgtSlDFQOzJv2e yrTw== X-Gm-Message-State: ACgBeo0lD7iGfSJbA3CR3VCLXuk0KLWYc8Im0PC8BfS84dhXZ6XLm3EN MG4V34+4rZBRH3Orc4B16/7hwv9yfYc= X-Google-Smtp-Source: AA6agR71bmi0TjYMckHqvLWSKbz2NnuUh3hXSzUQvPkWeISOW+fgYfweZ0BAeqRWH/n2t/4MMpP+0Q== X-Received: by 2002:a05:6000:1881:b0:222:c899:cac6 with SMTP id a1-20020a056000188100b00222c899cac6mr10738712wri.283.1661185695155; Mon, 22 Aug 2022 09:28:15 -0700 (PDT) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id z13-20020a5d44cd000000b00222ed7ea203sm11749229wrr.100.2022.08.22.09.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 09:28:14 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Leah Rumancik , Chandan Babu R , linux-xfs@vger.kernel.org, fstests@vger.kernel.org, Jan Kara , Christoph Hellwig , Christian Brauner Subject: [PATCH 5.10 CANDIDATE 4/6] vfs: make sync_filesystem return errors from ->sync_fs Date: Mon, 22 Aug 2022 19:28:00 +0300 Message-Id: <20220822162802.1661512-5-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822162802.1661512-1-amir73il@gmail.com> References: <20220822162802.1661512-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: "Darrick J. Wong" commit 5679897eb104cec9e99609c3f045a0c20603da4c upstream. [backport to 5.10 only differs in __sync_blockdev helper] Strangely, sync_filesystem ignores the return code from the ->sync_fs call, which means that syscalls like syncfs(2) never see the error. This doesn't seem right, so fix that. Signed-off-by: Darrick J. Wong Reviewed-by: Jan Kara Reviewed-by: Christoph Hellwig Acked-by: Christian Brauner Signed-off-by: Amir Goldstein --- fs/sync.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/fs/sync.c b/fs/sync.c index 0d6cdc507cb9..79180e58d862 100644 --- a/fs/sync.c +++ b/fs/sync.c @@ -28,7 +28,7 @@ */ int sync_filesystem(struct super_block *sb) { - int ret; + int ret = 0; /* * We need to be protected against the filesystem going from @@ -51,15 +51,21 @@ int sync_filesystem(struct super_block *sb) * at a time. */ writeback_inodes_sb(sb, WB_REASON_SYNC); - if (sb->s_op->sync_fs) - sb->s_op->sync_fs(sb, 0); + if (sb->s_op->sync_fs) { + ret = sb->s_op->sync_fs(sb, 0); + if (ret) + return ret; + } ret = __sync_blockdev(sb->s_bdev, 0); - if (ret < 0) + if (ret) return ret; sync_inodes_sb(sb); - if (sb->s_op->sync_fs) - sb->s_op->sync_fs(sb, 1); + if (sb->s_op->sync_fs) { + ret = sb->s_op->sync_fs(sb, 1); + if (ret) + return ret; + } return __sync_blockdev(sb->s_bdev, 1); } EXPORT_SYMBOL(sync_filesystem); From patchwork Mon Aug 22 16:28:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12950924 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73346C28D13 for ; Mon, 22 Aug 2022 16:28:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237043AbiHVQ22 (ORCPT ); Mon, 22 Aug 2022 12:28:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbiHVQ2U (ORCPT ); Mon, 22 Aug 2022 12:28:20 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E242A101B; Mon, 22 Aug 2022 09:28:17 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id s23so5869976wmj.4; Mon, 22 Aug 2022 09:28:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=kGcIKdRqU7mZG6oIgZsRqaH70DPckvwa8kwcbO1drxw=; b=l0aZG6wTUMBkbnd7w1hVXuyfQoLvTw+N/JmqIbM5j8GUonXHWvqPx0N5Z/OPEQNRlP vdk28fAttlIvfCM/sd8fTpCdwzigReIi//LJyRbrbQnTnBU3tAdGRSjifaa/2umqK5Ek pv92NAZQMZ6nO7dszPW2ZsSFmXog4LlFCM8p8PnX1YyZjXVCr7Mghwxn3LADL8jlrIAV Oiq+ZyA8fcFVCxkIC1XjSF+BkMCh3+jpZ/xBYQ6ZSSp9cURx5XL/Dg0PHTkIrOBBXWWT qKqk8UJ+ySCevsVlkLvgxn0NS058wP0Z6PFc53IZkKJhhCQU8jMarzGsnVI3D5gVdlR/ rWrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=kGcIKdRqU7mZG6oIgZsRqaH70DPckvwa8kwcbO1drxw=; b=Se4qMcQsOtCpQnIhD9cjZ0P6xUWzd74esS02VE7hItV3vVUPnUEMqX/8psuAGsObWo SW424HSdkHAUlQxxRzCgCQj9iJuO2qwjC+KaC6TxK6u3calUd+Tbt9Ijcs8PQ83HcGSI vth4XHXY8WZ79SrLIB62AvvH9qwMPzI14rsSpukXWETkxz4xUsOA6NsfRLQvVYJFhTlv CSMJZlDLdEGUkIN3flW8IMvMY4RFyTCSyYY3Zrq103hCmN4e17jipESPNRG7jmxKIbFd acokemjMj8WxpAoQzh2tIiIXzZVCfaev+qmVjlljnDesXSsQ73lp9ooWr5GEGBBMYvfX 6y+Q== X-Gm-Message-State: ACgBeo3OwDMQa+y3LIxx23zN6749900KWf8Do8MWRPgPKXmjgpw9wNrE eDnQ7oHtflwIVQwLPLKwthyFH9N5e1A= X-Google-Smtp-Source: AA6agR7RnNyN4Cc5TG8Zep3PZvoiGb3HVbsfeYnTET1CF9QADJPBfbmNYghDgdNPDzIDCDE/uDVBpw== X-Received: by 2002:a05:600c:384f:b0:3a6:603c:4338 with SMTP id s15-20020a05600c384f00b003a6603c4338mr4493016wmr.192.1661185696458; Mon, 22 Aug 2022 09:28:16 -0700 (PDT) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id z13-20020a5d44cd000000b00222ed7ea203sm11749229wrr.100.2022.08.22.09.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 09:28:16 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Leah Rumancik , Chandan Babu R , linux-xfs@vger.kernel.org, fstests@vger.kernel.org, Jan Kara , Christoph Hellwig , Christian Brauner Subject: [PATCH 5.10 CANDIDATE 5/6] xfs: return errors in xfs_fs_sync_fs Date: Mon, 22 Aug 2022 19:28:01 +0300 Message-Id: <20220822162802.1661512-6-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822162802.1661512-1-amir73il@gmail.com> References: <20220822162802.1661512-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: "Darrick J. Wong" commit 2d86293c70750e4331e9616aded33ab6b47c299d upstream. Now that the VFS will do something with the return values from ->sync_fs, make ours pass on error codes. Signed-off-by: Darrick J. Wong Reviewed-by: Jan Kara Reviewed-by: Christoph Hellwig Acked-by: Christian Brauner Signed-off-by: Amir Goldstein --- fs/xfs/xfs_super.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 6323974d6b3e..ff686cb16c7b 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -757,6 +757,7 @@ xfs_fs_sync_fs( int wait) { struct xfs_mount *mp = XFS_M(sb); + int error; /* * Doing anything during the async pass would be counterproductive. @@ -764,7 +765,10 @@ xfs_fs_sync_fs( if (!wait) return 0; - xfs_log_force(mp, XFS_LOG_SYNC); + error = xfs_log_force(mp, XFS_LOG_SYNC); + if (error) + return error; + if (laptop_mode) { /* * The disk must be active because we're syncing. From patchwork Mon Aug 22 16:28:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12950925 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAF46C32772 for ; Mon, 22 Aug 2022 16:28:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229524AbiHVQ23 (ORCPT ); Mon, 22 Aug 2022 12:28:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237027AbiHVQ2V (ORCPT ); Mon, 22 Aug 2022 12:28:21 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4208F2BD9; Mon, 22 Aug 2022 09:28:19 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id n4so13878228wrp.10; Mon, 22 Aug 2022 09:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=6pDOFEVfy1K9q+BjZ7R38iS5s9eH+edv8BSk6OFu1xM=; b=bKaQQ17Lfw5igPYj6dV9/QXA4Ds6wJYo+Gqf7YVzZh6f1N4pHbLGMCEILyJ6wKiRTb NRe5aGzRb7t8ue88Leeds+/k5Mqd+iEptB7v32/y5sbrKz799UczXz+EzKRwnte16ogE blWjELKSP0DU+dgCmLTN/e+5zqLjnDZ0971p2ttTHRgNGv1huLmBjmRJ3ro0UeyrhNZE 8GC0hlOt0w0LJltpSa1bqGek8u2dHRfhWcSeLUt2Uv+5jHkoHQEoWt3unwfmci1Whc8v o8IQ39WEonSLnvAGHYGp17P/FNxVBba9x8e3+MTwh5UyV56LMezHpeyvdDqO84WCQuve ba3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=6pDOFEVfy1K9q+BjZ7R38iS5s9eH+edv8BSk6OFu1xM=; b=mfBbW57clRH8NsDu9A/k0sx50Ju2LYL8QrAPCAPTjZrn8wh7H1L6GPZPv2V3Kyc7bv 1lxv0NpK8AOBWJnH8B63KScu92u2sPKDOwwTEf70Wh/eV0ZetL73kv5s6uGAQd0RbziW 9OhmkHD5JMi7DK4DDTisD0Hco3fghdOEGMt8DmmPvmH77NQuFOfN63xwniBtqqlikJtk 1GBodhbtKeIPnToVU7GCEzphq7sWh2TOEFghsYB/TPWu52XQtDqTal84SJQrqptwllfy 0UGwIrSNxr49puPBDHgRQ3i6E4/1x7tcAS2m68I7+rHhxUceylAXLE5jXP1SaDMCGqCN 9rlA== X-Gm-Message-State: ACgBeo280yRClksoSSNnEQr6OJ6S41/1AGilHsM/Zr/juQiAnEuAI4LP BBxGVdeCTZWj0oYNsy9RC7Q= X-Google-Smtp-Source: AA6agR520VIAwvFoMJou/rhDZvXvNam1uJMzbEH4KqdX8iMcJ+sZYwS78dIsUOB+SjLkoCOQDLb9Ag== X-Received: by 2002:adf:f2ca:0:b0:225:4800:d201 with SMTP id d10-20020adff2ca000000b002254800d201mr3833968wrp.187.1661185697691; Mon, 22 Aug 2022 09:28:17 -0700 (PDT) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id z13-20020a5d44cd000000b00222ed7ea203sm11749229wrr.100.2022.08.22.09.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 09:28:17 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Leah Rumancik , Chandan Babu R , linux-xfs@vger.kernel.org, fstests@vger.kernel.org, Dave Chinner Subject: [PATCH 5.10 CANDIDATE 6/6] xfs: only bother with sync_filesystem during readonly remount Date: Mon, 22 Aug 2022 19:28:02 +0300 Message-Id: <20220822162802.1661512-7-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822162802.1661512-1-amir73il@gmail.com> References: <20220822162802.1661512-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: "Darrick J. Wong" commit b97cca3ba9098522e5a1c3388764ead42640c1a5 upstream. In commit 02b9984d6408, we pushed a sync_filesystem() call from the VFS into xfs_fs_remount. The only time that we ever need to push dirty file data or metadata to disk for a remount is if we're remounting the filesystem read only, so this really could be moved to xfs_remount_ro. Once we've moved the call site, actually check the return value from sync_filesystem. Fixes: 02b9984d6408 ("fs: push sync_filesystem() down to the file system's remount_fs()") Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Amir Goldstein --- fs/xfs/xfs_super.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index ff686cb16c7b..434c87cc9fbf 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1720,6 +1720,11 @@ xfs_remount_ro( }; int error; + /* Flush all the dirty data to disk. */ + error = sync_filesystem(mp->m_super); + if (error) + return error; + /* * Cancel background eofb scanning so it cannot race with the final * log force+buftarg wait and deadlock the remount. @@ -1790,8 +1795,6 @@ xfs_fc_reconfigure( if (error) return error; - sync_filesystem(mp->m_super); - /* inode32 -> inode64 */ if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && !(new_mp->m_flags & XFS_MOUNT_SMALL_INUMS)) {