From patchwork Tue Jan 3 01:45:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 38236 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4391195wrt; Mon, 2 Jan 2023 17:47:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXswtoYEHhIkbaw9LQ6z9dvEWYo09uVFpMvG4ikg/quOcRYEc3LVvAm5Be0wA33aei2Kg4tX X-Received: by 2002:aa7:df06:0:b0:48e:64a6:8149 with SMTP id c6-20020aa7df06000000b0048e64a68149mr4704194edy.32.1672710429312; Mon, 02 Jan 2023 17:47:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672710429; cv=none; d=google.com; s=arc-20160816; b=jZJYKe6TlHEQBILNtoxtLwzV9z7S36+j4+gsGVBgZaVtarVqJanBfLLLGGlGUvnQo8 e2p9+X3hXrLsRWkLc9S2uxMalOUwhVEC3TD4RZ2ieAwLRRy/1KnDdSS0PVBkbmQb6xkL abEGDiN5/uWIhvcB8bKdQOcKJTD2jM9/QUyOtQYKlpl3B1Y3SyjiFDAbZ5QWl5DY32rn GpM5o316u6kG7W9h53Ze2+Bqvyp6px2odDsuCPSu54qegk4oIp8rh8bcrrxyffne9uMM WWXhSNzQCVHvrJ2ouEc1HdqtNWbIr9I7baHQhxkGkYhLI4V3atHrOHRV/KHbNZwTybhx scBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lxndJAPqkkg+7Ix0bR4//3QWQHh62xysWAMqysIRogg=; b=qYJTdl8ZT/tD0f5RXlJXW43PACQLsJo/RvgCCIzk0l33lviFJOeTMtvlG512QpCAsu cQ9sNCMppx+u4+2W/fNONCorQHBlWby12PwtbvUz8D3/rgs9KMVhGOdDHL5tM0DRQpjO oNGCJsJ8ROkQFIWKK52XYsHfNziwMwQ2DMHYm02KOBQEMt8ScD4joDOt+VzeODj5TLrZ 6rvXlWZ0B90bzCDYeWYNY3wAm+MWcm/ao+ElMEBsSrqJ07r0i8Kt6MVj7HpUdlPF1bNn TBSopkLW+VAsanTvvg0LhDz3+obccl53y63eJRZaVUwnRbf4GA05+O+aznfkO7JPnyxy eUQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OA9Ef4d7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020a056402279400b00484d2a31c84si21409594ede.473.2023.01.02.17.46.46; Mon, 02 Jan 2023 17:47:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OA9Ef4d7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236368AbjACBpL (ORCPT + 99 others); Mon, 2 Jan 2023 20:45:11 -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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753964011407358352?= X-GMAIL-MSGID: =?utf-8?q?1753964011407358352?= 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, is = kzalloc(sizeof(struct ext4_xattr_ibody_find), GFP_NOFS); bs = kzalloc(sizeof(struct ext4_xattr_block_find), GFP_NOFS); - buffer = kvmalloc(value_size, GFP_NOFS); b_entry_name = kmalloc(entry->e_name_len + 1, GFP_NOFS); - if (!is || !bs || !buffer || !b_entry_name) { + if (!is || !bs || !b_entry_name) { error = -ENOMEM; goto out; } @@ -2565,12 +2564,18 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode, /* Save the entry name and the entry value */ if (entry->e_value_inum) { + buffer = kvmalloc(value_size, GFP_NOFS); + if (!buffer) { + error = -ENOMEM; + goto out; + } + error = ext4_xattr_inode_get(inode, entry, buffer, value_size); if (error) goto out; } else { size_t value_offs = le16_to_cpu(entry->e_value_offs); - memcpy(buffer, (void *)IFIRST(header) + value_offs, value_size); + buffer = (void *)IFIRST(header) + value_offs; } memcpy(b_entry_name, entry->e_name, entry->e_name_len); @@ -2585,25 +2590,26 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode, if (error) goto out; - /* Remove the chosen entry from the inode */ - error = ext4_xattr_ibody_set(handle, inode, &i, is); - if (error) - goto out; - i.value = buffer; i.value_len = value_size; error = ext4_xattr_block_find(inode, &i, bs); if (error) goto out; - /* Add entry which was removed from the inode into the block */ + /* Move ea entry from the inode into the block */ error = ext4_xattr_block_set(handle, inode, &i, bs); if (error) goto out; - error = 0; + + /* Remove the chosen entry from the inode */ + i.value = NULL; + i.value_len = 0; + error = 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) From patchwork Tue Jan 3 01:45:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 38237 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4391230wrt; Mon, 2 Jan 2023 17:47:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXsApfZbtm/+hSWamTj+yELZnEZjo9hLMe65FyGoTLKFoAg+FM6sakSEMEaT01qgSzOek0+9 X-Received: by 2002:a17:907:214d:b0:837:4378:dbd6 with SMTP id rk13-20020a170907214d00b008374378dbd6mr38245122ejb.22.1672710438047; Mon, 02 Jan 2023 17:47:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672710438; cv=none; d=google.com; s=arc-20160816; b=UtFxoPrKBViLkyWXVgRqB817Uehjli4Ehlng+dABjb5YBIIgU+HjFLkNCl1Ypq5zqh Vi/E6Z6fZTOlirjrCls78pXi+8eCFXwEQrUKNFX6BIeIDwNaUBvowdwsTP68YTXHbtr8 /jIw8oq094a4WUWzZnEtHqIuWHK+pLrJUqbBNYvibHg+fBv21gMINDQ8R7Hl9OtO5jNc uMhwT3lahkYDeqHW123g7p+AsMUGnPAAgeHMHYKirjNxawGNJSUchuAYp07cl50ck+bX y7NQr0vrjGFEPP2ChZ3Dhm3fmFhtISe8/F/ZNeFV1yfYjg3WpEqQJPB85tj0NMpbF8VI qCfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pHFNPClZL6YqqHgH05AOCgftoZUseEmSrgezOmi2yxk=; b=QrvC88dZKgPn1AF7u3xOJ2R0za8auiuhx9wrtWJFdsteey0H0TySvdUOcRv6mQ1LE7 Z0GgOLiu0z0F8vlcUimYpvwYdpZkZ17cJ4r2iHA3k8OS2C0OFs3QgTUWX2gC2scbS0iu cQG8r0hQFjiFKMbxv8pzprW87voTtHK+tGoA7AlMKjT/Fzqz6/i2Ysxg8eGQcIjIaJ3W wDB42LYfcyxSOs+mnzfmsJA2SRf5cJV8woqW2eMjAScsFNHqe/ZnNIB9Ebk3vvVh7T6m 8h7nOGCatKdbiibpTG5/YcUhjTu8xZZDRkL1XWIW3kdS7qH1JxQz6DakAfo+1hRQ57PF wFuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O8xlIsgl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ww7-20020a170907084700b0084cbf555299si6833461ejb.954.2023.01.02.17.46.55; Mon, 02 Jan 2023 17:47:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O8xlIsgl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236513AbjACBpP (ORCPT + 99 others); Mon, 2 Jan 2023 20:45:15 -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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753964020426415394?= X-GMAIL-MSGID: =?utf-8?q?1753964020426415394?= 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=3613786cb88c93aa1c6a279b1df6a7b201347d08 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] = { i_uid_read(inode), i_gid_read(inode) }; int err; + if (inode->i_sb->s_root == 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.