From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F21EC433E1 for ; Thu, 20 Aug 2020 05:44:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F37F2075E for ; Thu, 20 Aug 2020 05:44:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="t4K5bR1A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbgHTFoV (ORCPT ); Thu, 20 Aug 2020 01:44:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726745AbgHTFoV (ORCPT ); Thu, 20 Aug 2020 01:44:21 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 439ABC061757 for ; Wed, 19 Aug 2020 22:44:21 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id y10so417133plr.11 for ; Wed, 19 Aug 2020 22:44:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9rX+/WpEhbK1jNNfavW4BofCGrwob0yBeBWvyb4SHVU=; b=t4K5bR1Aspq4Mpvf0C1J3vU5QJspI/eC6EZpUlE4sTyBwwP/Q3fkPb2iGcvxDoW+kS exiGPqwZXuDNAlYY0gGwMR0Crqs25RqbubEidTof/WuW5fSFcxpnbakHulblOsCiChXp DH2gWPvpDtN+ZiLPwSmP/RnEU81tddA4XzBfWB0+WCuWG740q87tIxNEFpDR2AF9QH0O kZSjtnb0WI7D56jGHl2Mt81m+KsVkNWZ9x13LnaJuTQiWycwDUGT75+Ofr17H2X0Yoxb 1hUOfyHf/wnSmPXWSd6/jVjo+AeVupI4GSszIKLsWr7HMZnyeY0ndkBBOJWIQ9/3veFb 4Qww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9rX+/WpEhbK1jNNfavW4BofCGrwob0yBeBWvyb4SHVU=; b=UhEy/huyH6ObLOylb7scnLPYqz8HWxa7VCS0Qbjtcy+JshHkDZnO41dFa6HSl3fW+y JgNLoJsoq0/OPKWD2jRyuhPhe6kl1KzhRvW/w8FHqSCd3HrU6jPmxwJiacOaeq6MHj9J tYERh7xNy+ZxGOTTW3XKjL3Rz+sPeRwb1hAekDhOt21MVdy/SM+qc0s+YT0u4KSDd6DI WPLSDzcJEgw0FI8CuzU4BDtx0yjtMbNIR6QBxy2N8hkpM0fu4n3tQ2mTsspmSZ35NpLK v+FszBmdpziuKOoxvaGpidfVzDiNpvSgyoAcSlx1+Cjs1x/LsyykISsc5wqXcuJuRHuM r6mw== X-Gm-Message-State: AOAM532fWK8bdBPS9xuivvg8fQNzkoYxH6OpXeESrNglEjdXqvQVKuSj eCmeRev8VYk6eiS6tKdwVodQRm1jhnU= X-Google-Smtp-Source: ABdhPJzYUgw/fAqLjzwHZDwNpEoOH8sl7gvD5z7aPqjJ4/X6Esb6uoLpFRx720dGgNFDxzcId+BqSQ== X-Received: by 2002:a17:90a:a792:: with SMTP id f18mr1208493pjq.65.1597902260522; Wed, 19 Aug 2020 22:44:20 -0700 (PDT) Received: from localhost.localdomain ([122.171.166.150]) by smtp.gmail.com with ESMTPSA id l4sm1044034pgk.74.2020.08.19.22.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 22:44:19 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V3 05/10] xfs: Check for extent overflow when adding/removing dir entries Date: Thu, 20 Aug 2020 11:13:44 +0530 Message-Id: <20200820054349.5525-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820054349.5525-1-chandanrlinux@gmail.com> References: <20200820054349.5525-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Directory entry addition/removal can cause the following, 1. Data block can be added/removed. A new extent can cause extent count to increase by 1. 2. Free disk block can be added/removed. Same behaviour as described above for Data block. 3. Dabtree blocks. XFS_DA_NODE_MAXDEPTH blocks can be added. Each of these can be new extents. Hence extent count can increase by XFS_DA_NODE_MAXDEPTH. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 12 ++++++++++++ fs/xfs/xfs_inode.c | 27 +++++++++++++++++++++++++++ fs/xfs/xfs_symlink.c | 5 +++++ 3 files changed, 44 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index aae8e6e80b71..f686c7418d2b 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -54,6 +54,18 @@ struct xfs_ifork { */ #define XFS_IEXT_ATTR_MANIP_CNT(rmt_blks) \ (XFS_DA_NODE_MAXDEPTH + max(1, rmt_blks)) +/* + * Directory entry addition/removal can cause the following, + * 1. Data block can be added/removed. + * A new extent can cause extent count to increase by 1. + * 2. Free disk block can be added/removed. + * Same behaviour as described above for Data block. + * 3. Dabtree blocks. + * XFS_DA_NODE_MAXDEPTH blocks can be added. Each of these can be new + * extents. Hence extent count can increase by XFS_DA_NODE_MAXDEPTH. + */ +#define XFS_IEXT_DIR_MANIP_CNT(mp) \ + ((XFS_DA_NODE_MAXDEPTH + 1 + 1) * (mp)->m_dir_geo->fsbcount) /* * Fork handling. diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 407d6299606d..8d195b6ef326 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1175,6 +1175,11 @@ xfs_create( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * A newly created regular or special file just has one directory * entry pointing to them, but a directory also the "." entry @@ -1391,6 +1396,11 @@ xfs_link( xfs_trans_ijoin(tp, sip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, tdp, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(tdp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto error_return; + /* * If we are using project inheritance, we only allow hard link * creation in our tree when the project IDs are the same; else @@ -2861,6 +2871,11 @@ xfs_remove( xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * If we're removing a directory perform some additional validation. */ @@ -3221,6 +3236,18 @@ xfs_rename( if (wip) xfs_trans_ijoin(tp, wip, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(src_dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + + if (target_ip == NULL) { + error = xfs_iext_count_may_overflow(target_dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + } + /* * If we are using project inheritance, we only allow renames * into our tree when the project IDs are the same; else the diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 8e88a7ca387e..581a4032a817 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -220,6 +220,11 @@ xfs_symlink( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * Allocate an inode for the symlink. */ -- 2.28.0