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 80C49C433DF for ; Mon, 12 Oct 2020 09:30:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2091B2087D for ; Mon, 12 Oct 2020 09:30:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a7kleH+l" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729405AbgJLJaT (ORCPT ); Mon, 12 Oct 2020 05:30:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729379AbgJLJaT (ORCPT ); Mon, 12 Oct 2020 05:30:19 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57930C0613CE for ; Mon, 12 Oct 2020 02:30:19 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id y1so4724291plp.6 for ; Mon, 12 Oct 2020 02:30:19 -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=bksEJ9nyOOSWN6jraeYLFwuNzpd3eKCyXw3XOFq/P88=; b=a7kleH+lkTB8ZkE0Ofx5hOZEBO7cNcGj4uQSvVmwN/3oAhXUIcUt8AVGBEjb9Mytj7 XRgS/fvZH/jl9gFyDq1ZUDkhmrQRGW2IQkFXOOkM6OEZRYsSuq7RgDhIw0u40ingpnrj NriXVx2yfoL58qnxThNiHmnvrzWingyWMdM+8/0Whn08JYS5/b8MqlQzUBAuOxYHzeMd 9KrBbfBfVdXI6EV55PB2KJ/P6lXjQHyMFYPdtTdBZNprIWktWsqy9GT4geG1yleTjCM2 v4Sg+jzX+LZK9z4SQg4Nb8GtPPRjmXT59zRFq0HxdSF6y7vMIcGMqfa4pyc5z/g+65Hm IWQA== 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=bksEJ9nyOOSWN6jraeYLFwuNzpd3eKCyXw3XOFq/P88=; b=GTh52Y4kHofrcZle+Z3YMK75zT+NXDl6Gk1aSP0026MdyVDhN1JTZK/UlnK9Iz46G4 aAoNcLi9jROT2hZ4sAu0fRBIdSHgP5+GcB9DlDFhSGvYn9KvJBLkRwx+Ow1f07jIIjJu 4OF9y0x7DooYGMiuWu0NcpkvpfNEptfkM/rsoGYFyUXvY1fTMjust7/fihy5qtqNMMY/ 6NevqHQ+ZGpo0cP0B2HPOr76mK9kYYtpPFndd3FptHgwmIP+t/VqVGZ+H9DJNPTD11iE GvceQbxyjxt5SOT3wmIDIJe2bcMekENaX8BijZuQHB485gtU9hgBVFUk265VhoCp/BTt ySNw== X-Gm-Message-State: AOAM531uT3t9lbllmuroQqsBIg19p/inKcO4gpL9KkozIshcCy8z5hV8 iT/pH8ofNLN3k//EmL0E+LdRvRFuS40= X-Google-Smtp-Source: ABdhPJxW1Ow2moyKw4/JngWtLs8NmtTcNxMHMMMsDylOJNcpEma0SSv5fu6hlZa5D+ZNYELTDyCxTA== X-Received: by 2002:a17:902:c40b:b029:d3:def2:d90f with SMTP id k11-20020a170902c40bb02900d3def2d90fmr22192058plk.29.1602495018302; Mon, 12 Oct 2020 02:30:18 -0700 (PDT) Received: from localhost.localdomain ([122.172.180.109]) by smtp.gmail.com with ESMTPSA id z142sm19451985pfc.179.2020.10.12.02.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 02:30:17 -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 V6 05/11] xfs: Check for extent overflow when adding/removing dir entries Date: Mon, 12 Oct 2020 14:59:32 +0530 Message-Id: <20201012092938.50946-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012092938.50946-1-chandanrlinux@gmail.com> References: <20201012092938.50946-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 2bfbcf28b1bd..5b41ffaf04d7 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1177,6 +1177,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 @@ -1393,6 +1398,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