From patchwork Sat Oct 3 05:56:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11815069 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 351F86CB for ; Sat, 3 Oct 2020 05:56:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16F06206F8 for ; Sat, 3 Oct 2020 05:56:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="t5WOnAwL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725764AbgJCF46 (ORCPT ); Sat, 3 Oct 2020 01:56:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF46 (ORCPT ); Sat, 3 Oct 2020 01:56:58 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 783D7C0613D0 for ; Fri, 2 Oct 2020 22:56:58 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id kk9so2261112pjb.2 for ; Fri, 02 Oct 2020 22:56:58 -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=+yzZR2iVQ2ZdH/KMJFzmnk4qPWZEMSnlIB8x5f/rCn8=; b=t5WOnAwLYlQx3JWHuyTnYYLVsPf7HgoepbI1/nQKGEQvXW2FyH9NIgfkx7krnbYUD4 rQU2ZcBV+EmkdKKuRko8YBXw/dfKrcwuEAruf73zc0TaNNVKXXBbrksIECdqXz3HPbrk XwH/RhYdnfFIQwpz/FjVliYQg599vtN/PG82YxpW4fDbHeSVWU35EYgf7uLbqH8bMgxU gGjJghLCLO8WRoc3sOlDHZcdhWk3NugCwkeMMLgz/hrUdhZNpMmCNcAm1nNcPgza8sMV njgneig2OIwuKGOQ8ncewkIg/t6Ezc6kKeaSbnPrMxDYBUPd4yskQv5Pz6SsWE9In98/ DbMg== 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=+yzZR2iVQ2ZdH/KMJFzmnk4qPWZEMSnlIB8x5f/rCn8=; b=RDbb9+rYcWYtJ4KSRuCSHNNrSVAM8aK82Etmf6QaVmpAP6LnHVub4ol3+bJ4dp72ki BpstT9rRYu6esEoD9xS3EtQt3K3PogKHb4FFv2rjaxmbccV8DYT3EOXCH2jP9Jh6Fgpq /dfsj2GTPjyDzb2Z1CD7VDAiSvvd5hjK+y9/db2FYSrNP5pVNJEDkl7OpA22jRCrFQwo 5OUjaclXRWJVtY8kSRnCFs+VE98UUR1QkAoY4t5uFj48vzfMm1VLbeZIriF+90fGC+XG Rxtvk9FJclroXO2hSGMh4/H7Xu/9rJT65xKGJ7/643DlpBBeSifgWOPta+w0ifIK5wRz Rofw== X-Gm-Message-State: AOAM532HbGoRSEoUk+GYW65UfBO7Q1iOxlbIhe7m+qY0+2jEI0IdIiKl ey9i48BUS+wIac8f5uJA1tgP8V2VS/s2Ig== X-Google-Smtp-Source: ABdhPJy+0qCzeshqbE94sp6OiExupY1ikCrzg73yT5Codq7SN4HOjdMJs9UkHMb8GCdz5AgaBy/wWQ== X-Received: by 2002:a17:90a:203:: with SMTP id c3mr6022229pjc.149.1601704617720; Fri, 02 Oct 2020 22:56:57 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:56:57 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 05/12] xfs: Check for extent overflow when adding/removing dir entries Date: Sat, 3 Oct 2020 11:26:26 +0530 Message-Id: <20201003055633.9379-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-1-chandanrlinux@gmail.com> MIME-Version: 1.0 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. Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 13 +++++++++++++ fs/xfs/xfs_inode.c | 27 +++++++++++++++++++++++++++ fs/xfs/xfs_symlink.c | 5 +++++ 3 files changed, 45 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 5de2f07d0dd5..fd93fdc67ee4 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -57,6 +57,19 @@ 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 49624973eecc..f347b1911d9c 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1159,6 +1159,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 @@ -1375,6 +1380,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 @@ -2850,6 +2860,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. */ @@ -3210,6 +3225,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. */