From patchwork Wed May 25 11:17:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12861016 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 ED34EC43217 for ; Wed, 25 May 2022 11:17:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233019AbiEYLRk (ORCPT ); Wed, 25 May 2022 07:17:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233808AbiEYLRj (ORCPT ); Wed, 25 May 2022 07:17:39 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BD9A6FA1D; Wed, 25 May 2022 04:17:36 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id bg25so12265096wmb.4; Wed, 25 May 2022 04:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2qWgwOMIZoZnoqcx4izZwNBl2nOWFWpcJl0NLoI3n8I=; b=AxzS0DUqbBsKXgkc1qHfc14RnK86er5uXvG+I1R3AvGenFiuZ49NYv3W1I6FN3+qQY 3uh4io3EIncMnmbl8vs0whGNz8UMKtVhIQ7f9hyxIDtJF+1A7Yb0QObjL1YNwd+D7CsM fjbSyYIFSer4oXEq3J2sU8ECI+d2tt7bbDp5wAMv7c1R22kFTCjNLxWKfDK7iMfjs3XC eaqxqkyl0TZHfM09rOs5c8fcZYVrGsaSZDa+Uh087apJp3/2f3qm5//Q/gXuzcfJgK4q ew/LdMVRNlhZy7rPSvwUsjDQ+sRjttOnGDU7Z8O744F3nlf27rxmSk/fgMioT4UoBbRD uDwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2qWgwOMIZoZnoqcx4izZwNBl2nOWFWpcJl0NLoI3n8I=; b=S9p0uAhuY7EQfzQA/CHBci3lLuxHGHr1rTocsls6rpoIDeQe8CBrPpPq+E2ruEgW30 CLHCyno4EXDM7TFBXtWO1q4CBi5a3NTiPH0R7L8IXZNwXSZcrGfG21vqlhcLoEcNXxhy BFYGFRQe3pyLhFfUIzPqN8jpNqj6y71eoI7aPqG3XJEVmNdv0JQcqR6O8Ib/I+1nLgeW 4evIphYsR3+hiXbzUQW0HsPYIYr1HrVRH904hjq45cUAjoQ0QW3h/wBCNAy7GjjCrnyB us7fQq88YjeVP68GP7PY+0bstu/clfyHE6VJQmzUoYYJpZVOmRPzl7Xd0RWPCYK5Q6w0 EEDw== X-Gm-Message-State: AOAM530/HtFE/hJqPmoFcbfcFSDDUxmJGZdfoG+bL1OducqmasFxhTdn i/9ELMJO71YXkrZvdHiaYxI= X-Google-Smtp-Source: ABdhPJz7dE2sbVIYT7ZPTv9s7MHnpNRFZj1WPPTH+YG5h59Xfv0QYhIKOErQkH97nOCbUipWwQl7ng== X-Received: by 2002:a7b:c928:0:b0:397:65f3:67b6 with SMTP id h8-20020a7bc928000000b0039765f367b6mr4224736wml.45.1653477454574; Wed, 25 May 2022 04:17:34 -0700 (PDT) Received: from localhost.localdomain ([5.29.19.200]) by smtp.gmail.com with ESMTPSA id e12-20020a056000178c00b0020c5253d8besm2059904wrg.10.2022.05.25.04.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 04:17:34 -0700 (PDT) From: Amir Goldstein To: Dave Chinner , "Darrick J . Wong" Cc: Luis Chamberlain , Theodore Ts'o , Adam Manzanares , Tyler Hicks , linux-xfs@vger.kernel.org, fstests@vger.kernel.org, Christoph Hellwig Subject: [PATH 5.10 1/4] xfs: detect overflows in bmbt records Date: Wed, 25 May 2022 14:17:12 +0300 Message-Id: <20220525111715.2769700-2-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525111715.2769700-1-amir73il@gmail.com> References: <20220525111715.2769700-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: "Darrick J. Wong" commit acf104c2331c1ba2a667e65dd36139d1555b1432 upstream. Detect file block mappings with a blockcount that's either so large that integer overflows occur or are zero, because neither are valid in the filesystem. Worse yet, attempting directory modifications causes the iext code to trip over the bmbt key handling and takes the filesystem down. We can fix most of this by preventing the bad metadata from entering the incore structures in the first place. Found by setting blockcount=0 in a directory data fork mapping and watching the fireworks. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Amir Goldstein --- fs/xfs/libxfs/xfs_bmap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index d9a692484eae..de9c27ef68d8 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -6229,6 +6229,11 @@ xfs_bmap_validate_extent( xfs_fsblock_t endfsb; bool isrt; + if (irec->br_startblock + irec->br_blockcount <= irec->br_startblock) + return __this_address; + if (irec->br_startoff + irec->br_blockcount <= irec->br_startoff) + return __this_address; + isrt = XFS_IS_REALTIME_INODE(ip); endfsb = irec->br_startblock + irec->br_blockcount - 1; if (isrt && whichfork == XFS_DATA_FORK) { From patchwork Wed May 25 11:17:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12861015 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 0E557C433EF for ; Wed, 25 May 2022 11:17:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233717AbiEYLRj (ORCPT ); Wed, 25 May 2022 07:17:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233019AbiEYLRi (ORCPT ); Wed, 25 May 2022 07:17:38 -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 8326F8CCC5; Wed, 25 May 2022 04:17:37 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 67-20020a1c1946000000b00397382b44f4so3141416wmz.2; Wed, 25 May 2022 04:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LuV2WNWBzFzDFM9UzO8H2iJ9QFWj2tDa1lgS6fde0JU=; b=f7KxPQr4TkBQZfu/0UrPf81FTwY8ufQ8HzRDFb0sUZhCYJ3GHx4Bm6Fcr1QzDtTt17 mxGQ7QGK60fyop8LCIEZzCR+APCME2I4uEQag17zo8N5mC7hd1NO4AH4+BxeyQ/lVz9m TpAPZLJi8UgiS2kG2gQ3OR/cwiDxXUCST7eXYnaEO/L5K83EuobvNjdi8L+j7b7zbIXA YIsYGnw0s8wRab9vYHk78DTwcgWi1Kq4ZQhE1s00qETQMANf0+ZCZiF58DLW+gi3TnoE HuyN3UIl8WY0G5kKjDnuLJHnmnKz66E+GlJOZH7JAV6+PAC9nyyuBFfw1oXQXMEUlv1P I7jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LuV2WNWBzFzDFM9UzO8H2iJ9QFWj2tDa1lgS6fde0JU=; b=wGek6YPwEli08Y8S66rX0lkNdEY4fafI+aboBBEZ5fmqdInqpU0PNnrfG41BNL+8s1 4UfIu+5BY2r24gthmscnwlcsLny54vidNVPqqogmt8CSqTvPKN988txbXCAEXHzpHEDH s4KF+xcJUxmFRq99A0H57eSS3fQMh6uzy5APFZku32S2Vxr2J3a0Xio+wJvKdtmFcT2A hlIy640pk5la+977tH2SSDjm6TbxUsnmvaHAG1BI2WtkcVJ/tcAMm7ucywQ31HIJTp8V Cn1iWlYuDTtFhfg04Z5lAuVaOBuar8R+00pxsMuRR3Bn5Qktpo87HqJScYbFg8qCs6th BX3g== X-Gm-Message-State: AOAM533p0xSlzfDnkNQ7kRyjEBrCCavOWiHdFFf9uRmX9ogCUe27v83s R6cdxrz4jY+GyALxOJaF0pM= X-Google-Smtp-Source: ABdhPJyLZd6EpS1uB3O4EjN+11yEkNK6du/ru/pBqVcHqv6YGlNxh3hvhtW2EwhAD3Q0czl5kvq1fA== X-Received: by 2002:a05:600c:3ba4:b0:397:47b2:588d with SMTP id n36-20020a05600c3ba400b0039747b2588dmr7827185wms.64.1653477456137; Wed, 25 May 2022 04:17:36 -0700 (PDT) Received: from localhost.localdomain ([5.29.19.200]) by smtp.gmail.com with ESMTPSA id e12-20020a056000178c00b0020c5253d8besm2059904wrg.10.2022.05.25.04.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 04:17:35 -0700 (PDT) From: Amir Goldstein To: Dave Chinner , "Darrick J . Wong" Cc: Luis Chamberlain , Theodore Ts'o , Adam Manzanares , Tyler Hicks , linux-xfs@vger.kernel.org, fstests@vger.kernel.org, Kaixu Xia Subject: [PATH 5.10 2/4] xfs: show the proper user quota options Date: Wed, 25 May 2022 14:17:13 +0300 Message-Id: <20220525111715.2769700-3-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525111715.2769700-1-amir73il@gmail.com> References: <20220525111715.2769700-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Kaixu Xia commit 237d7887ae723af7d978e8b9a385fdff416f357b upstream. The quota option 'usrquota' should be shown if both the XFS_UQUOTA_ACCT and XFS_UQUOTA_ENFD flags are set. The option 'uqnoenforce' should be shown when only the XFS_UQUOTA_ACCT flag is set. The current code logic seems wrong, Fix it and show proper options. Signed-off-by: Kaixu Xia Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Amir Goldstein --- fs/xfs/xfs_super.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index e3e229e52512..5ebd6cdc44a7 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -199,10 +199,12 @@ xfs_fs_show_options( seq_printf(m, ",swidth=%d", (int)XFS_FSB_TO_BB(mp, mp->m_swidth)); - if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD)) - seq_puts(m, ",usrquota"); - else if (mp->m_qflags & XFS_UQUOTA_ACCT) - seq_puts(m, ",uqnoenforce"); + if (mp->m_qflags & XFS_UQUOTA_ACCT) { + if (mp->m_qflags & XFS_UQUOTA_ENFD) + seq_puts(m, ",usrquota"); + else + seq_puts(m, ",uqnoenforce"); + } if (mp->m_qflags & XFS_PQUOTA_ACCT) { if (mp->m_qflags & XFS_PQUOTA_ENFD) From patchwork Wed May 25 11:17:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12861017 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 6B360C433F5 for ; Wed, 25 May 2022 11:17:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233808AbiEYLRk (ORCPT ); Wed, 25 May 2022 07:17:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235257AbiEYLRk (ORCPT ); Wed, 25 May 2022 07:17:40 -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 3384DBF57; Wed, 25 May 2022 04:17:39 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id m32-20020a05600c3b2000b0039756bb41f2so3138759wms.3; Wed, 25 May 2022 04:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GX4MGgyF/rjjoLGNo+9vAqeePSGvpBNozK+r4g9/A+k=; b=dlw0Mg6gf3WNt8D6bhTQyID0LYoJJu+FAy8sfn/2lG1PC0eQ+HbwP1ZdGeFD4PbuMA twUcX5S6riP5FUAwDKCviI2RecKNaZZ3FWBW/mQOxVa1P+ceTTaVY7ihIS7+spQtL1Sg k8PdsWHzdk7pNvrRo/ykfDK7RgRIQ8D4FfxcDUp3PM5HKIldzZD3PrtugAgxc/ADngwa oSxvxhNhPm844QrmW9Xww46yI3/le5LHCxgeobuc9eOgFcf6IfJcKdHEKC/AEHVX0KRq AsAz3QtSb9wocwzYGry5S8FbVNH5BVs/1wNGCURAVG+EZ9YecdKN6C4Rsj3EZb+vOohq rq0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GX4MGgyF/rjjoLGNo+9vAqeePSGvpBNozK+r4g9/A+k=; b=xm8yQaoN+tsk5ZbTNcMiKd95Ul6+r+Df+9lJCp5s2JOpCP5xcz3Gaht5CSVuyj+LxU bcTBgH85+KsLaQ1lTT65NZGIlgSyRVEY6HTUmwyCREkOW4A/jEXEZkDypA5kFWdB4P2H urfZxC4F6Yizm1NVbZNhb0+QIoFnw3Hb5tsE2bxpIIrxmjEpauzAZ9H6NMZput0Shj8f lGLPIDp4h48oWnc1tQ+Ysok2aEKFSGSkzpsefKJ4g4yiWvmndx3ahF/bg0xUuX1uEpnp 62KEgRQGAWgJt5yVZ5cmNuxai9jo4Ixt8evZp7qYhEXne9v7ucBmuADydTmgTRF+/2a9 wf+g== X-Gm-Message-State: AOAM532E7k0BdkIlR62/WCBdX3Wu+Ot4khm1reLSZp5wmw0m8wF6dyMA KfHXoT5Tl4h/ASN98eFYuVQ= X-Google-Smtp-Source: ABdhPJyC68W7SAjRUxetk9N2SwY3o8lg1eXakzy/Ukr/JkU2bUbF2Dq2GKbLiOjTb1iBspIP/jgvTw== X-Received: by 2002:a05:600c:2904:b0:397:3673:83d1 with SMTP id i4-20020a05600c290400b00397367383d1mr7569254wmd.122.1653477457781; Wed, 25 May 2022 04:17:37 -0700 (PDT) Received: from localhost.localdomain ([5.29.19.200]) by smtp.gmail.com with ESMTPSA id e12-20020a056000178c00b0020c5253d8besm2059904wrg.10.2022.05.25.04.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 04:17:37 -0700 (PDT) From: Amir Goldstein To: Dave Chinner , "Darrick J . Wong" Cc: Luis Chamberlain , Theodore Ts'o , Adam Manzanares , Tyler Hicks , linux-xfs@vger.kernel.org, fstests@vger.kernel.org, zlang@redhat.com, Dave Chinner Subject: [PATH 5.10 3/4] xfs: fix the forward progress assertion in xfs_iwalk_run_callbacks Date: Wed, 25 May 2022 14:17:14 +0300 Message-Id: <20220525111715.2769700-4-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525111715.2769700-1-amir73il@gmail.com> References: <20220525111715.2769700-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: "Darrick J. Wong" commit a5336d6bb2d02d0e9d4d3c8be04b80b8b68d56c8 upstream. In commit 27c14b5daa82 we started tracking the last inode seen during an inode walk to avoid infinite loops if a corrupt inobt record happens to have a lower ir_startino than the record preceeding it. Unfortunately, the assertion trips over the case where there are completely empty inobt records (which can happen quite easily on 64k page filesystems) because we advance the tracking cursor without actually putting the empty record into the processing buffer. Fix the assert to allow for this case. Reported-by: zlang@redhat.com Fixes: 27c14b5daa82 ("xfs: ensure inobt record walks always make forward progress") Signed-off-by: Darrick J. Wong Reviewed-by: Zorro Lang Reviewed-by: Dave Chinner Signed-off-by: Amir Goldstein --- fs/xfs/xfs_iwalk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/xfs/xfs_iwalk.c b/fs/xfs/xfs_iwalk.c index 2a45138831e3..eae3aff9bc97 100644 --- a/fs/xfs/xfs_iwalk.c +++ b/fs/xfs/xfs_iwalk.c @@ -363,7 +363,7 @@ xfs_iwalk_run_callbacks( /* Delete cursor but remember the last record we cached... */ xfs_iwalk_del_inobt(tp, curpp, agi_bpp, 0); irec = &iwag->recs[iwag->nr_recs - 1]; - ASSERT(next_agino == irec->ir_startino + XFS_INODES_PER_CHUNK); + ASSERT(next_agino >= irec->ir_startino + XFS_INODES_PER_CHUNK); error = xfs_iwalk_ag_recs(iwag); if (error) From patchwork Wed May 25 11:17:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12861018 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 9C507C433FE for ; Wed, 25 May 2022 11:17:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233321AbiEYLRn (ORCPT ); Wed, 25 May 2022 07:17:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229962AbiEYLRm (ORCPT ); Wed, 25 May 2022 07:17:42 -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 E5FFFBF57; Wed, 25 May 2022 04:17:40 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id s28so29517665wrb.7; Wed, 25 May 2022 04:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JLC0ja767iUSkq7vhFyAS50rOOoNLE8fxflV1RxjsDw=; b=B+8Uuiwetwr3EOaHPsTSCuyBeUtYD3wotxWuLsZ/8+ouP/h7TN1hOBCFUI94i8Y2ds Axl10hnC52K54iu3cuDniX7s3r2m82CfSFemaB3+r71i8RO+u5Yki0iwRbmNPK/qJMga 5PkhP5tJukVPGeelnyl5Se+lwISg/hmCxKQH+kmtV3kArjiI51As8Gd7g51uTSNkRB+O WP5pDCjYwEXJsJ09/d8Zircnz7kSr5LpOQahAVOuVtUauj7BSOGeiFfsP2rXADzlg8Hn waHBBj1XeqkMxwnxU1ReLyUKV33NW+o0MKOGE96U9IEsX/jh6DX1Eg3q8Ydxr0khkzko GqlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JLC0ja767iUSkq7vhFyAS50rOOoNLE8fxflV1RxjsDw=; b=I4lgmPzxjrRRvjzODQ+uinrTd7tDPp2FllL5SIlk0kovrf2VxSPeSyNhiZ+6a8gsS7 dX/Kjiz1oUgbOU/Kec881jP4uTVIxoJNMW9Ws/P5hEbOhE6FG7ZFPse6UGNM0HQrem1y ghij8E7bDcJvI4qSYG2sPJeg5/RFiI6EUQ2Y6gCsayD5/CehP+ilIPu4IxO7y9Q+/1p4 5EmuH2wfzC2PwvRbF6dYqKEsn/UQ09eazQSrwkYzw5O8VkM/hghh3BTMLfodRMk6Txrs MbG8dM4RkNKWVX8VjDUI0EFQau1oMV0PSZ559CAzsET2wGCjEXxCmEYcBGWi0Cr6D642 jKMw== X-Gm-Message-State: AOAM531YUUq9DY+ug8Jh4zBJrnSRXTWEJkRhSuAcf81gesPyW9gJBfLK GQBfcKXjukRrWo9NNRD1U32pFM8d2xjBJA== X-Google-Smtp-Source: ABdhPJyRsykgXShW1kfR8nTS4vulfeVnDHcE4JVzPJOnlSdvecXYC0KCPSKqL7CBMDcxapjIkwehZA== X-Received: by 2002:adf:f582:0:b0:210:f0:24ac with SMTP id f2-20020adff582000000b0021000f024acmr1647830wro.444.1653477459408; Wed, 25 May 2022 04:17:39 -0700 (PDT) Received: from localhost.localdomain ([5.29.19.200]) by smtp.gmail.com with ESMTPSA id e12-20020a056000178c00b0020c5253d8besm2059904wrg.10.2022.05.25.04.17.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 04:17:38 -0700 (PDT) From: Amir Goldstein To: Dave Chinner , "Darrick J . Wong" Cc: Luis Chamberlain , Theodore Ts'o , Adam Manzanares , Tyler Hicks , linux-xfs@vger.kernel.org, fstests@vger.kernel.org, wenli xie , Brian Foster Subject: [PATH 5.10 4/4] xfs: fix an ABBA deadlock in xfs_rename Date: Wed, 25 May 2022 14:17:15 +0300 Message-Id: <20220525111715.2769700-5-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525111715.2769700-1-amir73il@gmail.com> References: <20220525111715.2769700-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: "Darrick J. Wong" commit 6da1b4b1ab36d80a3994fd4811c8381de10af604 upstream. When overlayfs is running on top of xfs and the user unlinks a file in the overlay, overlayfs will create a whiteout inode and ask xfs to "rename" the whiteout file atop the one being unlinked. If the file being unlinked loses its one nlink, we then have to put the inode on the unlinked list. This requires us to grab the AGI buffer of the whiteout inode to take it off the unlinked list (which is where whiteouts are created) and to grab the AGI buffer of the file being deleted. If the whiteout was created in a higher numbered AG than the file being deleted, we'll lock the AGIs in the wrong order and deadlock. Therefore, grab all the AGI locks we think we'll need ahead of time, and in order of increasing AG number per the locking rules. Reported-by: wenli xie Fixes: 93597ae8dac0 ("xfs: Fix deadlock between AGI and AGF when target_ip exists in xfs_rename()") Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster Signed-off-by: Amir Goldstein --- fs/xfs/libxfs/xfs_dir2.h | 2 -- fs/xfs/libxfs/xfs_dir2_sf.c | 2 +- fs/xfs/xfs_inode.c | 42 ++++++++++++++++++++++--------------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index e55378640b05..d03e6098ded9 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h @@ -47,8 +47,6 @@ extern int xfs_dir_lookup(struct xfs_trans *tp, struct xfs_inode *dp, extern int xfs_dir_removename(struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_name *name, xfs_ino_t ino, xfs_extlen_t tot); -extern bool xfs_dir2_sf_replace_needblock(struct xfs_inode *dp, - xfs_ino_t inum); extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_name *name, xfs_ino_t inum, xfs_extlen_t tot); diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 2463b5d73447..8c4f76bba88b 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -1018,7 +1018,7 @@ xfs_dir2_sf_removename( /* * Check whether the sf dir replace operation need more blocks. */ -bool +static bool xfs_dir2_sf_replace_needblock( struct xfs_inode *dp, xfs_ino_t inum) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 2bfbcf28b1bd..e958b1c74561 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -3152,7 +3152,7 @@ xfs_rename( struct xfs_trans *tp; struct xfs_inode *wip = NULL; /* whiteout inode */ struct xfs_inode *inodes[__XFS_SORT_INODES]; - struct xfs_buf *agibp; + int i; int num_inodes = __XFS_SORT_INODES; bool new_parent = (src_dp != target_dp); bool src_is_directory = S_ISDIR(VFS_I(src_ip)->i_mode); @@ -3265,6 +3265,30 @@ xfs_rename( } } + /* + * Lock the AGI buffers we need to handle bumping the nlink of the + * whiteout inode off the unlinked list and to handle dropping the + * nlink of the target inode. Per locking order rules, do this in + * increasing AG order and before directory block allocation tries to + * grab AGFs because we grab AGIs before AGFs. + * + * The (vfs) caller must ensure that if src is a directory then + * target_ip is either null or an empty directory. + */ + for (i = 0; i < num_inodes && inodes[i] != NULL; i++) { + if (inodes[i] == wip || + (inodes[i] == target_ip && + (VFS_I(target_ip)->i_nlink == 1 || src_is_directory))) { + struct xfs_buf *bp; + xfs_agnumber_t agno; + + agno = XFS_INO_TO_AGNO(mp, inodes[i]->i_ino); + error = xfs_read_agi(mp, tp, agno, &bp); + if (error) + goto out_trans_cancel; + } + } + /* * Directory entry creation below may acquire the AGF. Remove * the whiteout from the unlinked list first to preserve correct @@ -3317,22 +3341,6 @@ xfs_rename( * In case there is already an entry with the same * name at the destination directory, remove it first. */ - - /* - * Check whether the replace operation will need to allocate - * blocks. This happens when the shortform directory lacks - * space and we have to convert it to a block format directory. - * When more blocks are necessary, we must lock the AGI first - * to preserve locking order (AGI -> AGF). - */ - if (xfs_dir2_sf_replace_needblock(target_dp, src_ip->i_ino)) { - error = xfs_read_agi(mp, tp, - XFS_INO_TO_AGNO(mp, target_ip->i_ino), - &agibp); - if (error) - goto out_trans_cancel; - } - error = xfs_dir_replace(tp, target_dp, target_name, src_ip->i_ino, spaceres); if (error)