From nobody Tue Sep 16 13:47:27 2025 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 9E76DC53210 for ; Tue, 3 Jan 2023 01:45:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232287AbjACBpN (ORCPT ); Mon, 2 Jan 2023 20:45:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236540AbjACBpC (ORCPT ); Mon, 2 Jan 2023 20:45:02 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B123C62EE for ; Mon, 2 Jan 2023 17:45:01 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id o31-20020a17090a0a2200b00223fedffb30so29630031pjo.3 for ; Mon, 02 Jan 2023 17:45:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lxndJAPqkkg+7Ix0bR4//3QWQHh62xysWAMqysIRogg=; b=OA9Ef4d7WAhxk3cq8MrSUCkpcHlzZH+HT+d01d/QTtdnSonZ77AoCruMSuanMHugrn jl58RqjaIt0JWQTOB4sKnOn7DJLfWU5rPX6UHsz63hrE5SseDFK+oNb0mR/v4kgVVYTM quJA+9nHYuVz4qNR7p5zQl3wENJWYe+mgyoZsbJP9YQ1SXQ+JaUd7UpmQExG4o7bsiCg +F5vpkzxahtdpc5rPPMiWriCxPqfQ4T9cRQ47j9WNlGnjk+dxn5+BH8ug6db8DsGbW3H nHPKCqO5VkHLEKkFgxlzjL8DT8CqyQvgCvdQ/EtJEEa1kO+nh591uZ7L7CnhA1XQW84s I+ng== 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 :subject:date:message-id:reply-to; bh=lxndJAPqkkg+7Ix0bR4//3QWQHh62xysWAMqysIRogg=; b=8B7x9qs25BfGp4XG9yBVZUHjMlvlq9aI7k65FJpDIVxy7aoNTXlf7u0tdlMRqfJbC3 2jIcdPDj14fjZjwEkp/KY5fIUoSxxDqVabirUu/HKdslJwFjuSAz/t8B+cgk64bYLEzE tPORdLDbC0egGwk4rGqyb232xo2aqHnqEpgiMWxkMtSZcNiJGd2iTbkmghv442dRpDZU xJjuEGMokRoctZ/Qo/O/wSIQUMur3HY/YU6DvjU4+1FwAVO6H+9stlJIOmGkF6ICXyc6 KWKAdQqQmdswwZ+sDLL3jOxgwu6mxSixJj90J6rqDyHH9Vd4+dtOj5o+clSdatjM4aFM nSfQ== X-Gm-Message-State: AFqh2ko4EqFd2NzR5N3g/fjdsSCMao9lk+Paa10AdGafRHZlY9On3Ca+ yZNiXf0QP3yU0/e/fYfRcMRtxw== X-Google-Smtp-Source: AMrXdXu6ms8jwa7l3akSlsQVzB56U6hlL47LPcdCgIQm0acDZRRCDScYKInsFoEtDPDalygWO6EJ2A== X-Received: by 2002:a17:902:c948:b0:188:a6ea:279f with SMTP id i8-20020a170902c94800b00188a6ea279fmr60269041pla.12.1672710301260; Mon, 02 Jan 2023 17:45:01 -0800 (PST) Received: from niej-dt-7B47.. (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id f15-20020a170902ab8f00b001769206a766sm20588895plr.307.2023.01.02.17.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 17:45:00 -0800 (PST) From: Jun Nie To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tudor.ambarus@linaro.org Subject: [PATCH v2 1/2] ext4: optimize ea_inode block expansion Date: Tue, 3 Jan 2023 09:45:16 +0800 Message-Id: <20230103014517.495275-2-jun.nie@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230103014517.495275-1-jun.nie@linaro.org> References: <20230103014517.495275-1-jun.nie@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Copy ea data from inode entry when expanding ea block if possible. Then remove the ea entry if expansion success. Thus memcpy to a temporary buffer may be avoided. If the expansion fails, we do not need to recovery the removed ea entry neither in this way. Signed-off-by: Jun Nie --- fs/ext4/xattr.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 7decaaf27e82..235a517d9c17 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -2551,9 +2551,8 @@ static int ext4_xattr_move_to_block(handle_t *handle,= struct inode *inode, =20 is =3D kzalloc(sizeof(struct ext4_xattr_ibody_find), GFP_NOFS); bs =3D kzalloc(sizeof(struct ext4_xattr_block_find), GFP_NOFS); - buffer =3D kvmalloc(value_size, GFP_NOFS); b_entry_name =3D kmalloc(entry->e_name_len + 1, GFP_NOFS); - if (!is || !bs || !buffer || !b_entry_name) { + if (!is || !bs || !b_entry_name) { error =3D -ENOMEM; goto out; } @@ -2565,12 +2564,18 @@ static int ext4_xattr_move_to_block(handle_t *handl= e, struct inode *inode, =20 /* Save the entry name and the entry value */ if (entry->e_value_inum) { + buffer =3D kvmalloc(value_size, GFP_NOFS); + if (!buffer) { + error =3D -ENOMEM; + goto out; + } + error =3D ext4_xattr_inode_get(inode, entry, buffer, value_size); if (error) goto out; } else { size_t value_offs =3D le16_to_cpu(entry->e_value_offs); - memcpy(buffer, (void *)IFIRST(header) + value_offs, value_size); + buffer =3D (void *)IFIRST(header) + value_offs; } =20 memcpy(b_entry_name, entry->e_name, entry->e_name_len); @@ -2585,25 +2590,26 @@ static int ext4_xattr_move_to_block(handle_t *handl= e, struct inode *inode, if (error) goto out; =20 - /* Remove the chosen entry from the inode */ - error =3D ext4_xattr_ibody_set(handle, inode, &i, is); - if (error) - goto out; - i.value =3D buffer; i.value_len =3D value_size; error =3D ext4_xattr_block_find(inode, &i, bs); if (error) goto out; =20 - /* Add entry which was removed from the inode into the block */ + /* Move ea entry from the inode into the block */ error =3D ext4_xattr_block_set(handle, inode, &i, bs); if (error) goto out; - error =3D 0; + + /* Remove the chosen entry from the inode */ + i.value =3D NULL; + i.value_len =3D 0; + error =3D ext4_xattr_ibody_set(handle, inode, &i, is); + out: kfree(b_entry_name); - kvfree(buffer); + if (entry->e_value_inum && buffer) + kvfree(buffer); if (is) brelse(is->iloc.bh); if (bs) --=20 2.34.1 From nobody Tue Sep 16 13:47:27 2025 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 EAA17C53210 for ; Tue, 3 Jan 2023 01:45:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236505AbjACBpQ (ORCPT ); Mon, 2 Jan 2023 20:45:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236323AbjACBpH (ORCPT ); Mon, 2 Jan 2023 20:45:07 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 283DD627F for ; Mon, 2 Jan 2023 17:45:07 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id jl4so24818727plb.8 for ; Mon, 02 Jan 2023 17:45:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pHFNPClZL6YqqHgH05AOCgftoZUseEmSrgezOmi2yxk=; b=O8xlIsglgdhduJo7+bHnIGvWYXQKrSsJOgHp4hqykudZgbPYD6sxab2YtDecPhe5ZZ z71fr2qP20MdKzggYU1OjqwHfnIJvKMDEH5uSYiZj3H9xMni/yxQhq2wDNwNsuTMdTni yrFzz7N0iLXSRnRlOiNqjrPASvWyEp9DnJ7DjLi+h4OR0sca6ACpauSN884KUHrSJOC2 Q2TnCuYgoO2EZLnd60QVwr+GyfVJJUTNA8SlA/6+ysEFV4IQpqOeeKlx67MZrTstBpzL qr+djEBY08eU1tO0guKoya9+UA6d+xuTqABpBZ5Kkk95ZS5ZaX9erG8Fcr77jTEZckmN GRpg== 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 :subject:date:message-id:reply-to; bh=pHFNPClZL6YqqHgH05AOCgftoZUseEmSrgezOmi2yxk=; b=szdoDxNc9P2kNY8GZO4tyDKY2T8YzpUZf+1Lhi650q+KG34/wUyvJLdmfJ7ofjlsH5 SUiWXZ1GfQYkIyJHBbt+63N51Gdcw+qIFYr/IDQl3uDK1VIFg1rNkxFaXT8sjA3cYvkF ogULCsQQ+Wg/zXUFHKw9J+3VSRWFuhyppW3EekT4dx4W5iwX7xFwy17uujh+vQbJ5NVI uDe3Q/gHZeYakxLuQUWxMYxRNuz38WeeHaR5a3V4HZz1ITSq+IVG4n+JtM2RQVCuUa0M VjZUs2vTD34P7E9e9J/K0LNvPF2kCEWopGlE5HkUPiAlRjD4IRn5sUSdmt+eL/ci7UvT RRdw== X-Gm-Message-State: AFqh2kqALsKeEUw7cXFf+LQfrI4POhRp7ZyieAZHCn2iVXRm1Nq82k0b 7PXu9M9uaLCWEdkZEa2AwHqrjw== X-Google-Smtp-Source: AMrXdXuCB+HjiuEKN3LL/KtS1LyAdfDKnaHcNh0fjGf9u6qf+6of2IgCpsKc3N7jkuSwHU4etbw15g== X-Received: by 2002:a17:902:cf41:b0:192:82d4:f9b2 with SMTP id e1-20020a170902cf4100b0019282d4f9b2mr28859244plg.7.1672710306715; Mon, 02 Jan 2023 17:45:06 -0800 (PST) Received: from niej-dt-7B47.. (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id f15-20020a170902ab8f00b001769206a766sm20588895plr.307.2023.01.02.17.45.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 17:45:06 -0800 (PST) From: Jun Nie To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tudor.ambarus@linaro.org Subject: [PATCH v2 2/2] ext4: refuse to create ea block when umounted Date: Tue, 3 Jan 2023 09:45:17 +0800 Message-Id: <20230103014517.495275-3-jun.nie@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230103014517.495275-1-jun.nie@linaro.org> References: <20230103014517.495275-1-jun.nie@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The ea block expansion need to access s_root while it is already set as NULL when umount is triggered. Refuse this request to avoid panic. Reported-by: syzbot+2dacb8f015bf1420155f@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?id=3D3613786cb88c93aa1c6a279b1df6a7= b201347d08 Signed-off-by: Jun Nie --- fs/ext4/xattr.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 235a517d9c17..b350510b798c 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -1422,6 +1422,13 @@ static struct inode *ext4_xattr_inode_create(handle_= t *handle, uid_t owner[2] =3D { i_uid_read(inode), i_gid_read(inode) }; int err; =20 + if (inode->i_sb->s_root =3D=3D NULL) { + ext4_warning(inode->i_sb, + "refuse to create EA inode when umounting"); + WARN_ON(1); + return ERR_PTR(-EINVAL); + } + /* * Let the next inode be the goal, so we try and allocate the EA inode * in the same group, or nearby one. --=20 2.34.1