From patchwork Tue Dec 6 01:58:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 30053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2573709wrr; Mon, 5 Dec 2022 17:37:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf7jUHMK+Vs65D3T2R28F7YLDQHSeueQo3fZMwP4kqiAbib3XGCQfk/Rql09YkIY6U/e4Q4L X-Received: by 2002:a63:5863:0:b0:478:1020:b1e2 with SMTP id i35-20020a635863000000b004781020b1e2mr36686455pgm.510.1670290662632; Mon, 05 Dec 2022 17:37:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670290662; cv=none; d=google.com; s=arc-20160816; b=Mmd5GdnXMr4JuLZ0BNLgHflz53RoW/D5QaRm1GI5v92M2e7HrLknpHPMdDrLuIwXc8 bP1UJkF5zqzkbTdf2uQeAFuoFhrYvEI35vicmuvmIRgyXWPWhkUmZbsO+dkX6EUNmqBc 72WH91mzQi0Brow8pVWJiwvfrPa+2U7SIyU2wVdnbOLrOJJXgGi1zpdWZuTE4C1LAXob hd5YkpiPuQx/dLSEL2xkBBhEtHOOFOYgaehGDmiAhuAfEsRXnfXGjaHBbDhgrUpS3CAA qSothI9CPdT7aYHEQsWOwXat2jq2+o1t9oX8cyyuU5rOvVn6sAE8iqGNifZKEeC32/wW cAlA== 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; bh=sa1IZ1Z6NTAKGEAKcKX1V9jD+UEaQC8oLXYo3L6Y9qw=; b=Z0XmgERlc3xiun2uG69x4MV2A08O7rRwcGMoT57u5vHmw94XXAdrAhuAR/+dbL9Jnk 3ZBZxXWAq4lIej8mD1D48vtM5T1By1mQP1K0661kYQq0B1b5hWOQCNh67kBG2wWI88yt +st1AdXiZomEQtdqFCs1ylg+Aet4SeuS3PVnHlS9NkvDZLT9Hp0puRrlZwyCqx3J4oCE U5ExlEPyjwYpyBDU6MTHiA7EuAzVDXMYiBZFJDWtjsX0piGoga1nOoYfPwj20OrjXehZ V/ATJMiUXE3CN9bHsi0IP2Rpo/v4NQkce2P57ekUIq/fpaTSK7DnREp88cjeINOWcutx a1ow== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o124-20020a62cd82000000b005771086c184si3064899pfg.51.2022.12.05.17.37.29; Mon, 05 Dec 2022 17:37:42 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233235AbiLFBhS (ORCPT + 99 others); Mon, 5 Dec 2022 20:37:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232553AbiLFBhP (ORCPT ); Mon, 5 Dec 2022 20:37:15 -0500 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EB17201BD; Mon, 5 Dec 2022 17:37:14 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4NR31d2Lxzz4f3lHK; Tue, 6 Dec 2022 09:37:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgDH69jFnI5jZpTsBg--.65169S5; Tue, 06 Dec 2022 09:37:11 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin , syzbot+4d99a966fd74bdeeec36@syzkaller.appspotmail.com Subject: [PATCH -next 1/6] ext4: fix WARNING in ext4_expand_extra_isize_ea Date: Tue, 6 Dec 2022 09:58:01 +0800 Message-Id: <20221206015806.3420321-2-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221206015806.3420321-1-yebin@huaweicloud.com> References: <20221206015806.3420321-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDH69jFnI5jZpTsBg--.65169S5 X-Coremail-Antispam: 1UD129KBjvJXoWxGrW3JFy5KrWkJr4rZr4kXrb_yoWrtr4xpw 4fA347Cr48XFyDCF4xAr1Utw1DWwn5CF4UJry7Wrn7ZFy7Xw1xKas8Kr4fXFy8trW8J342 qF1DJ34rKw15GaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjxUzl1vUUUUU X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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?1751426701832086781?= X-GMAIL-MSGID: =?utf-8?q?1751426701832086781?= From: Ye Bin Syzbot found the following issue: ------------[ cut here ]------------ WARNING: CPU: 1 PID: 3631 at mm/page_alloc.c:5534 __alloc_pages+0x30a/0x560 mm/page_alloc.c:5534 Modules linked in: CPU: 1 PID: 3631 Comm: syz-executor261 Not tainted 6.1.0-rc6-syzkaller-00308-g644e9524388a #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022 RIP: 0010:__alloc_pages+0x30a/0x560 mm/page_alloc.c:5534 RSP: 0018:ffffc90003ccf080 EFLAGS: 00010246 RAX: ffffc90003ccf0e0 RBX: 000000000000000c RCX: 0000000000000000 RDX: 0000000000000028 RSI: 0000000000000000 RDI: ffffc90003ccf108 RBP: ffffc90003ccf198 R08: dffffc0000000000 R09: ffffc90003ccf0e0 R10: fffff52000799e21 R11: 1ffff92000799e1c R12: 0000000000040c40 R13: 1ffff92000799e18 R14: dffffc0000000000 R15: 1ffff92000799e14 FS: 0000555555c10300(0000) GS:ffff8880b9900000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007ffc36f70000 CR3: 00000000744ad000 CR4: 00000000003506e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: __alloc_pages_node include/linux/gfp.h:223 [inline] alloc_pages_node include/linux/gfp.h:246 [inline] __kmalloc_large_node+0x8a/0x1a0 mm/slab_common.c:1096 __do_kmalloc_node mm/slab_common.c:943 [inline] __kmalloc+0xfe/0x1a0 mm/slab_common.c:968 kmalloc include/linux/slab.h:558 [inline] ext4_xattr_move_to_block fs/ext4/xattr.c:2558 [inline] ext4_xattr_make_inode_space fs/ext4/xattr.c:2673 [inline] ext4_expand_extra_isize_ea+0xe3f/0x1cd0 fs/ext4/xattr.c:2765 __ext4_expand_extra_isize+0x2b8/0x3f0 fs/ext4/inode.c:5857 ext4_try_to_expand_extra_isize fs/ext4/inode.c:5900 [inline] __ext4_mark_inode_dirty+0x51a/0x670 fs/ext4/inode.c:5978 ext4_inline_data_truncate+0x548/0xd00 fs/ext4/inline.c:2021 ext4_truncate+0x341/0xeb0 fs/ext4/inode.c:4221 ext4_process_orphan+0x1aa/0x2d0 fs/ext4/orphan.c:339 ext4_orphan_cleanup+0xb60/0x1340 fs/ext4/orphan.c:474 __ext4_fill_super fs/ext4/super.c:5515 [inline] ext4_fill_super+0x80ed/0x8610 fs/ext4/super.c:5643 get_tree_bdev+0x400/0x620 fs/super.c:1324 vfs_get_tree+0x88/0x270 fs/super.c:1531 do_new_mount+0x289/0xad0 fs/namespace.c:3040 do_mount fs/namespace.c:3383 [inline] __do_sys_mount fs/namespace.c:3591 [inline] __se_sys_mount+0x2d3/0x3c0 fs/namespace.c:3568 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd Reason is allocate 16M memory by kmalloc, but MAX_ORDER is 11, kmalloc can allocate maxium size memory is 4M. XATTR_SIZE_MAX is currently 64k, but EXT4_XATTR_SIZE_MAX is '(1 << 24)', so 'ext4_xattr_check_entries()' regards this length as legal. Then trigger warning in 'ext4_xattr_move_to_block()'. To solve above issue, according to Jan Kara's suggestion use kvmalloc() to allocate memory in ext4_xattr_move_to_block(). Reported-by: syzbot+4d99a966fd74bdeeec36@syzkaller.appspotmail.com Fixes: 54dd0e0a1b25 ("ext4: add extra checks to ext4_xattr_block_get()") Signed-off-by: Ye Bin --- fs/ext4/xattr.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h index 824faf0b15a8..444ee46838c3 100644 --- a/fs/ext4/xattr.h +++ b/fs/ext4/xattr.h @@ -71,15 +71,10 @@ struct ext4_xattr_entry { #define IFIRST(hdr) ((struct ext4_xattr_entry *)((hdr)+1)) /* - * XATTR_SIZE_MAX is currently 64k, but for the purposes of checking - * for file system consistency errors, we use a somewhat bigger value. - * This allows XATTR_SIZE_MAX to grow in the future, but by using this - * instead of INT_MAX for certain consistency checks, we don't need to - * worry about arithmetic overflows. (Actually XATTR_SIZE_MAX is - * defined in include/uapi/linux/limits.h, so changing it is going - * not going to be trivial....) + * Use XATTR_SIZE_MAX to checking for file system consistency errors. Extended + * attribute length exceed XATTR_SIZE_MAX is ilegal. */ -#define EXT4_XATTR_SIZE_MAX (1 << 24) +#define EXT4_XATTR_SIZE_MAX XATTR_SIZE_MAX /* * The minimum size of EA value when you start storing it in an external inode From patchwork Tue Dec 6 01:58:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 30054 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2574172wrr; Mon, 5 Dec 2022 17:38:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf6jsqMaoLmgV50lMe1F724WJfK9aTGkaASuyLk2Us8cTItOzfekbepY+Hmlow3V5jYTNaNe X-Received: by 2002:aa7:952a:0:b0:577:1b6:ee7b with SMTP id c10-20020aa7952a000000b0057701b6ee7bmr6323274pfp.5.1670290735900; Mon, 05 Dec 2022 17:38:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670290735; cv=none; d=google.com; s=arc-20160816; b=VQjPLL+eY8CpC2551dpYN3Jf3iz7PTgD0ByutTExnQxPcbQqRZ+kUAuw3JWuBdYMLk n7UiDcS5F86bG+8yCQ8UCJ1zAQiUCLFJJkDrX50StXiYxLLQhZhhT788Q+AWlV2XmcWI ke47RBegKwQNjBYTEh+sJIzPcBH8BYKbLInJni7irCKi99pVJPet7WJ50W7XjgBqtapc cgtf6LARTf2DZFhnfP4dDzygsm/VEs8WT9H99GguRP+Jz1pAljZtZndFw1q655i3fWue +Hohkpts21kp/2bsqMuovplHP61zEMNzIXxa4UJggtb2ciJLLeN+R104S/5P/9tngnLW YJ/g== 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; bh=mmnSImcqyNJM2t5iC42i31MNxLmJoXcP4RLRvb8sjVY=; b=LoYqGdFTdzCYAXvZ4r+m17D8WG8cMyxM8H6A/wRGfvoG7qf2zugyS1STx6y4Pslnx6 RLMMPmQZOkaZTDJu0IHY6k9gtDFRmEte+Rwo+mHbcnRdR7zpQ1lXB9QZOBqQQ1w/O83F srWLOjwSoxuMppVF1VBPcRWmdSXdC9oPCJvWzpPDVduy5mJiSE3xSdmBIO4rbpB97p5J Dn9ERYmSvySkJkrAXpb38EkXOsr16MvyrJGo0SMHXHybu5Oel7XzIqswxYMzktBA8sWz jZlpVehRwVknUphde+aiGB8bHm0YMZk94t0yrQMyZeRmPGetbuFA1osVsxHmiOJz6K4V NY2A== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l64-20020a638843000000b00477076948efsi13925343pgd.799.2022.12.05.17.38.41; Mon, 05 Dec 2022 17:38:55 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233354AbiLFBhW (ORCPT + 99 others); Mon, 5 Dec 2022 20:37:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232849AbiLFBhP (ORCPT ); Mon, 5 Dec 2022 20:37:15 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9479D205F4; Mon, 5 Dec 2022 17:37:14 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NR31d0YVSz4f3v56; Tue, 6 Dec 2022 09:37:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgDH69jFnI5jZpTsBg--.65169S6; Tue, 06 Dec 2022 09:37:12 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin Subject: [PATCH -next 2/6] ext4: add primary check extended attribute inode in ext4_xattr_check_entries() Date: Tue, 6 Dec 2022 09:58:02 +0800 Message-Id: <20221206015806.3420321-3-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221206015806.3420321-1-yebin@huaweicloud.com> References: <20221206015806.3420321-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDH69jFnI5jZpTsBg--.65169S6 X-Coremail-Antispam: 1UD129KBjvJXoWxGF13CFykKry7Cw45ur1kGrg_yoW5ZF4rpa 13Jr98Gr4UJFyDWrySyw1UZwnIga1xGFWjvFyxKw1FyF17Xrn7tFyFqF90kF1jyrWkGw1j qa98tr1Uua13u3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjxU2_MaUUUUU X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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?1751426778528868674?= X-GMAIL-MSGID: =?utf-8?q?1751426778528868674?= From: Ye Bin Add primary check for extended attribute inode, only do hash check when read ea_inode's data in ext4_xattr_inode_get(). Signed-off-by: Ye Bin --- fs/ext4/xattr.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 718ef3987f94..eed001eee3ec 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -83,6 +83,9 @@ static __le32 ext4_xattr_hash_entry(char *name, size_t name_len, __le32 *value, size_t value_count); static void ext4_xattr_rehash(struct ext4_xattr_header *); +static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino, + u32 ea_inode_hash, struct inode **ea_inode); + static const struct xattr_handler * const ext4_xattr_handler_map[] = { [EXT4_XATTR_INDEX_USER] = &ext4_xattr_user_handler, #ifdef CONFIG_EXT4_FS_POSIX_ACL @@ -181,9 +184,32 @@ ext4_xattr_handler(int name_index) return handler; } +static inline int ext4_xattr_check_extra_inode(struct inode *inode, + struct ext4_xattr_entry *entry) +{ + int err; + struct inode *ea_inode; + + err = ext4_xattr_inode_iget(inode, le32_to_cpu(entry->e_value_inum), + le32_to_cpu(entry->e_hash), &ea_inode); + if (err) + return err; + + if (i_size_read(ea_inode) != le32_to_cpu(entry->e_value_size)) { + ext4_warning_inode(ea_inode, + "ea_inode file size=%llu entry size=%u", + i_size_read(ea_inode), + le32_to_cpu(entry->e_value_size)); + err = -EFSCORRUPTED; + } + iput(ea_inode); + + return err; +} + static int -ext4_xattr_check_entries(struct ext4_xattr_entry *entry, void *end, - void *value_start) +ext4_xattr_check_entries(struct inode *inode, struct ext4_xattr_entry *entry, + void *end, void *value_start) { struct ext4_xattr_entry *e = entry; @@ -221,6 +247,10 @@ ext4_xattr_check_entries(struct ext4_xattr_entry *entry, void *end, size > end - value || EXT4_XATTR_SIZE(size) > end - value) return -EFSCORRUPTED; + } else if (entry->e_value_inum) { + int err = ext4_xattr_check_extra_inode(inode, entry); + if (err) + return err; } entry = EXT4_XATTR_NEXT(entry); } @@ -243,8 +273,8 @@ __ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh, error = -EFSBADCRC; if (!ext4_xattr_block_csum_verify(inode, bh)) goto errout; - error = ext4_xattr_check_entries(BFIRST(bh), bh->b_data + bh->b_size, - bh->b_data); + error = ext4_xattr_check_entries(inode, BFIRST(bh), + bh->b_data + bh->b_size, bh->b_data); errout: if (error) __ext4_error_inode(inode, function, line, 0, -error, @@ -268,7 +298,8 @@ __xattr_check_inode(struct inode *inode, struct ext4_xattr_ibody_header *header, if (end - (void *)header < sizeof(*header) + sizeof(u32) || (header->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC))) goto errout; - error = ext4_xattr_check_entries(IFIRST(header), end, IFIRST(header)); + error = ext4_xattr_check_entries(inode, IFIRST(header), end, + IFIRST(header)); errout: if (error) __ext4_error_inode(inode, function, line, 0, -error, From patchwork Tue Dec 6 01:58:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 30055 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2574176wrr; Mon, 5 Dec 2022 17:38:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf5P6DUNgLGEqUXLE/8hAGLACH3OOFgvZ3U6N/twLel4WZK4KADNU0ZOjAtiUDwLjyd/czTn X-Received: by 2002:aa7:84c7:0:b0:574:9b8d:1873 with SMTP id x7-20020aa784c7000000b005749b8d1873mr55115478pfn.75.1670290737317; Mon, 05 Dec 2022 17:38:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670290737; cv=none; d=google.com; s=arc-20160816; b=Me4WGRjA7f5ozrJUoHD8+wJPwjhzE/aeTJldMtvhzVqcDSLns/9xXqWYWLMuer/Tqs 5edUwnwt9XdvUIN045XlAH5v2bI6PUuMfXD1WbKrMnHQMQgyZ5t+gv851+0Za8GTbRkb iYVnfeBYOnxrlwjCenVAV6s4152jqGlmbkm8PSNC8aXJPZ8JJtNKnxzVK59Rw1aNSqBE SDlC4ZFL++w2KqrxLqKuZ574f/K5bGFOljFVhmSyx15U8jgbceREgP0Kd1SEw0c+CRuf voWabTdFUEOJ/Pu0jNfUQ3I9T6TboBSm9kX7xAF6nLFt99++bkthZh6HtT/ys8nLIZCq E38g== 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; bh=DSX1WjQ8Quf+KccQohdscxRUHHsDLF/PEoEJ9yNslMQ=; b=SgWuHpcjQNceNg7RY5ocbM26GqP7rQcD7hvnOF9IYaV8oK2sFxB14chfuz2sXdzoPE boQL3IycnNPdsG8TyYico8H8hmKJZv3o17mhYSHwnvxteJjrBpHKRUvCD19pYwo925kZ mm/T/VvRNjQtAKVu8R228UDlCCx1+9u/oCa9R2s+8nswS0BJ5FKMxvipvvVq+bSziIf2 GQreOi16wvuPEwd/YeyR8tnhCtPMEVqc6lhrLosfXHj3HdmrtqhgdRMkNedN5aYVBAYd rS8e9mN5UsqKqpg5h/yhzplYgCFWEdnnbI4vIfoH5lYFHnRQqRQLWUe9H6My69IIPlsC IArA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o7-20020a17090aac0700b002193428c920si18429784pjq.144.2022.12.05.17.38.43; Mon, 05 Dec 2022 17:38:57 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233453AbiLFBh0 (ORCPT + 99 others); Mon, 5 Dec 2022 20:37:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232919AbiLFBhP (ORCPT ); Mon, 5 Dec 2022 20:37:15 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD56420BCE; Mon, 5 Dec 2022 17:37:14 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NR31d2fYlz4f3v57; Tue, 6 Dec 2022 09:37:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgDH69jFnI5jZpTsBg--.65169S7; Tue, 06 Dec 2022 09:37:12 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin Subject: [PATCH -next 3/6] ext4: remove unnessary size check in ext4_xattr_inode_get() Date: Tue, 6 Dec 2022 09:58:03 +0800 Message-Id: <20221206015806.3420321-4-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221206015806.3420321-1-yebin@huaweicloud.com> References: <20221206015806.3420321-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDH69jFnI5jZpTsBg--.65169S7 X-Coremail-Antispam: 1UD129KBjvdXoW7Jw4rXF1fZw15GrWfur4xXrb_yoW3trXEya 4qqr4UGr43Xr1xWrWDAF1ay3ZYy3W8Gr1fuF4kJFy7Z3WaqayvvrWDXrWUZr13Ww4rt3Z8 Z34DJrW7GFyFgjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbV8YFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r1rM2 8IrcIa0xkI8VCY1x0267AKxVW8JVW5JwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK 021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx 0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWU JVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJV W8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF 1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6x IIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvE x4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvj DU0xZFpf9x07jnyCJUUUUU= X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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?1751426780195997971?= X-GMAIL-MSGID: =?utf-8?q?1751426780195997971?= From: Ye Bin As previous patch add check in ext4_xattr_check_entries(), before call ext4_xattr_inode_get() will already do xattr entries check. Signed-off-by: Ye Bin --- fs/ext4/xattr.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index eed001eee3ec..75287422c36c 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -525,14 +525,6 @@ ext4_xattr_inode_get(struct inode *inode, struct ext4_xattr_entry *entry, goto out; } - if (i_size_read(ea_inode) != size) { - ext4_warning_inode(ea_inode, - "ea_inode file size=%llu entry size=%zu", - i_size_read(ea_inode), size); - err = -EFSCORRUPTED; - goto out; - } - err = ext4_xattr_inode_read(ea_inode, buffer, size); if (err) goto out; From patchwork Tue Dec 6 01:58:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 30056 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2574177wrr; Mon, 5 Dec 2022 17:38:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf4CKViw88549peItbxOn+QvBAyv/6wUR1JNiyMusPt+iMwol2vyLB92gOmvkcDTrYlMTt5W X-Received: by 2002:a63:470e:0:b0:440:69bc:c972 with SMTP id u14-20020a63470e000000b0044069bcc972mr57387024pga.86.1670290737372; Mon, 05 Dec 2022 17:38:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670290737; cv=none; d=google.com; s=arc-20160816; b=MIFO+JzQRm/rWhO3hxwCfTVZ/T6fXteQoEdP3A98xIJ1+4UQVTKN37fI5puRL9oEFO Sw52FHfRqwLc6Auc0glLus26YbvGSo9EgqbGa/HYy5emXKdA9tAObFv3ilz0qelF8T+l xE3ZAaeJThS4Dn1g513b+qGx+kArJ1egCBpjFcSSo/7I0ywS52x/7XlngOVoH8fOFsWS 8iQ7x96HhGcYm7Vb0mIfAX4g3+NaoJWTzqUlJzNh7Wz2wqX0GeWwj19/gxKFoyS8kZsT CuggSc1n1R8NY6vntoYKP03VwqAbDlTjwoSH+xoRk7rX8TMPNf6gUPhl2S/aTekW6sCY fz8g== 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; bh=TWpKIgkwmAGa3zPrX3g2HE1BSt8x45EBVm09+iXEYVc=; b=Lnr62On/Mli5XHthPQ03YhblA84T/2OV61xIDWvlkBWOlLHtdFk8CggHmUE4byn4m2 eQ30IUgnvo1QxT+qbNCy/3IH14VfwVqOsSFvWqwnrU5sNdjn0YhHOnJ8rA84yc6quG3n w4qalGxJjrc+5UOJsfvrzTTgRup0i5d2py4caQSbfNyRoniYLtjyK3OoZApHiYAKu9fT ZdtbjUbODQ/6wvr87j9nT83ZkuCuE2bX8MP1BFen7P4NQC5F2S67rNZKkGFyeMo9ZYvu Npt9zpCo3jE1Zadlb6I469pfsby186mPxQ6hPn4YjBA6jxDffEJw3s2A02sQ3+Ucl9+A Xdhg== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u62-20020a638541000000b00478b6aa0363si5089256pgd.218.2022.12.05.17.38.43; Mon, 05 Dec 2022 17:38:57 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233467AbiLFBh2 (ORCPT + 99 others); Mon, 5 Dec 2022 20:37:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232976AbiLFBhQ (ORCPT ); Mon, 5 Dec 2022 20:37:16 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 369CE20BD7; Mon, 5 Dec 2022 17:37:15 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NR31d52zlz4f3k62; Tue, 6 Dec 2022 09:37:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgDH69jFnI5jZpTsBg--.65169S8; Tue, 06 Dec 2022 09:37:12 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin Subject: [PATCH -next 4/6] ext4: allocate extended attribute value in vmalloc area Date: Tue, 6 Dec 2022 09:58:04 +0800 Message-Id: <20221206015806.3420321-5-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221206015806.3420321-1-yebin@huaweicloud.com> References: <20221206015806.3420321-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDH69jFnI5jZpTsBg--.65169S8 X-Coremail-Antispam: 1UD129KBjvJXoW7ArW3JF1fWFWxury7KryUWrg_yoW8JFyfpa 95K340kr43Wry7urWxCF4xZ3sFg3ZFgr47Gay3Xw40vFy5Xwn2gFyYyFWYvF15ZFWftw4v qF1Dtr18Za13t3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIx AIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI 42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWI evJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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?1751426780174721291?= X-GMAIL-MSGID: =?utf-8?q?1751426780174721291?= From: Ye Bin Now, extended attribute value maxium length is 64K. The memory requested here does not need continuous physical addresses, so it is appropriate to use kvmalloc to request memory. At the same time, it can also cope with the situation that the extension attribute will become longer in the future. Signed-off-by: Ye Bin --- fs/ext4/xattr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 75287422c36c..efa623658c12 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -2579,7 +2579,7 @@ 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 = kmalloc(value_size, 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) { error = -ENOMEM; @@ -2631,7 +2631,7 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode, error = 0; out: kfree(b_entry_name); - kfree(buffer); + kvfree(buffer); if (is) brelse(is->iloc.bh); if (bs) From patchwork Tue Dec 6 01:58:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 30058 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2574712wrr; Mon, 5 Dec 2022 17:40:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf79mtNpvk3KkIruecBW+nWis1qFUrI4k+TYWStogF69WI9WInCT//bs+xErW+rCOsPdm8Di X-Received: by 2002:a63:f80a:0:b0:478:427a:85f0 with SMTP id n10-20020a63f80a000000b00478427a85f0mr28059783pgh.124.1670290825036; Mon, 05 Dec 2022 17:40:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670290825; cv=none; d=google.com; s=arc-20160816; b=f88nRA0GubRfuNIynWRI0VuPDS3ld/zHUb4Ut4ZD+8C+tJjakT9hfAqJ+rzBrMVewK wVcpwW3CFWQpR3p2O8iVRKlb2e5FbI5M/IUZ8Uvyjy19ZKA3sxof4XOZW7+mUnfkVPy1 vUcE/WSsebm67WGtTXnxnsCXRvLhxjx6n5LwxCMQ+MuCCU4mQmGsWGOsBWAS5yqW4E+V lKz0SOlKcStEiavZ1V/FL9g47QT9Hmyt/s6qNmiHqh/xv1xfQeFi2mhzI80AcM+mzNSz 545Rj8bWpTRZe7GHcBgM+GFqc47MdY3kcc9lAxMedDRYlctpSs+dZcft1XuqMU3rgmU5 r/Sw== 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; bh=rNdbnqwtC9MchPAUQ3da+rSUEy8ZwqEhXtr/R5+G4sQ=; b=iv3ntHHYaccPOn8dqI9El2EM37Utxi7duee/CPE2rvUgYz478aeEeup5tsTiA8o09W hn0CH6n4UxZpXyI654Tcy0QjGHsh8Jz8M7KoZUfInCXxAjNvPOQNPJVy/8wQvmI6vkSW WH3JvTPRUHmw2Wl3Lil+eq/3972iCnTOkfpbEluwiajlQQ41g0CF8v59Kgbz4IKtpA0a 26pDoaLElOjhmpNOtq3bm6m70EgLz+RI/VwuJIlg16ZvNe4M/Li2m3NZxyTiSA5P5Ami Zakf18gHdhNB7EV3dXjEg3W6wX1NosOPUkVtxGH0jzRPcmm8Ftrau7dIDjYLIVuOakyn rgTA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j71-20020a638b4a000000b0047865b303a5si15986564pge.762.2022.12.05.17.40.11; Mon, 05 Dec 2022 17:40:25 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233517AbiLFBhg (ORCPT + 99 others); Mon, 5 Dec 2022 20:37:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233086AbiLFBhQ (ORCPT ); Mon, 5 Dec 2022 20:37:16 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80B472019E; Mon, 5 Dec 2022 17:37:15 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NR31d6zLhz4f3v5K; Tue, 6 Dec 2022 09:37:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgDH69jFnI5jZpTsBg--.65169S9; Tue, 06 Dec 2022 09:37:13 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin Subject: [PATCH -next 5/6] ext4: rename xattr_find_entry() and __xattr_check_inode() Date: Tue, 6 Dec 2022 09:58:05 +0800 Message-Id: <20221206015806.3420321-6-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221206015806.3420321-1-yebin@huaweicloud.com> References: <20221206015806.3420321-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDH69jFnI5jZpTsBg--.65169S9 X-Coremail-Antispam: 1UD129KBjvJXoWxJFyfJFy3GrWfGFyDCw18Grg_yoWrKFyUpF yUJa4DJw48JryUur40yr17Zw1ag3W7Gay7ZayxC3WSyF1kXwn7tFyFkFn8CFyUWr4kWw4a qF43K348u3WSk3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI 42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWI evJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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?1751426872062666900?= X-GMAIL-MSGID: =?utf-8?q?1751426872062666900?= From: Ye Bin xattr_find_entry() and __xattr_check_inode() is in EXT4 xattr module. so add 'ext4' prefix to unify name style. Signed-off-by: Ye Bin --- fs/ext4/xattr.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index efa623658c12..003fe1f2d6a8 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -290,7 +290,7 @@ __ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh, static int -__xattr_check_inode(struct inode *inode, struct ext4_xattr_ibody_header *header, +__ext4_xattr_check_inode(struct inode *inode, struct ext4_xattr_ibody_header *header, void *end, const char *function, unsigned int line) { int error = -EFSCORRUPTED; @@ -307,11 +307,11 @@ __xattr_check_inode(struct inode *inode, struct ext4_xattr_ibody_header *header, return error; } -#define xattr_check_inode(inode, header, end) \ - __xattr_check_inode((inode), (header), (end), __func__, __LINE__) +#define ext4_xattr_check_inode(inode, header, end) \ + __ext4_xattr_check_inode((inode), (header), (end), __func__, __LINE__) static int -xattr_find_entry(struct inode *inode, struct ext4_xattr_entry **pentry, +ext4_xattr_find_entry(struct inode *inode, struct ext4_xattr_entry **pentry, void *end, int name_index, const char *name, int sorted) { struct ext4_xattr_entry *entry, *next; @@ -577,7 +577,7 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name, ext4_xattr_block_cache_insert(ea_block_cache, bh); entry = BFIRST(bh); end = bh->b_data + bh->b_size; - error = xattr_find_entry(inode, &entry, end, name_index, name, 1); + error = ext4_xattr_find_entry(inode, &entry, end, name_index, name, 1); if (error) goto cleanup; size = le32_to_cpu(entry->e_value_size); @@ -628,11 +628,11 @@ ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name, raw_inode = ext4_raw_inode(&iloc); header = IHDR(inode, raw_inode); end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; - error = xattr_check_inode(inode, header, end); + error = ext4_xattr_check_inode(inode, header, end); if (error) goto cleanup; entry = IFIRST(header); - error = xattr_find_entry(inode, &entry, end, name_index, name, 0); + error = ext4_xattr_find_entry(inode, &entry, end, name_index, name, 0); if (error) goto cleanup; size = le32_to_cpu(entry->e_value_size); @@ -773,7 +773,7 @@ ext4_xattr_ibody_list(struct dentry *dentry, char *buffer, size_t buffer_size) raw_inode = ext4_raw_inode(&iloc); header = IHDR(inode, raw_inode); end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; - error = xattr_check_inode(inode, header, end); + error = ext4_xattr_check_inode(inode, header, end); if (error) goto cleanup; error = ext4_xattr_list_entries(dentry, IFIRST(header), @@ -859,7 +859,7 @@ int ext4_get_inode_usage(struct inode *inode, qsize_t *usage) raw_inode = ext4_raw_inode(&iloc); header = IHDR(inode, raw_inode); end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; - ret = xattr_check_inode(inode, header, end); + ret = ext4_xattr_check_inode(inode, header, end); if (ret) goto out; @@ -1862,7 +1862,7 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i, bs->s.first = BFIRST(bs->bh); bs->s.end = bs->bh->b_data + bs->bh->b_size; bs->s.here = bs->s.first; - error = xattr_find_entry(inode, &bs->s.here, bs->s.end, + error = ext4_xattr_find_entry(inode, &bs->s.here, bs->s.end, i->name_index, i->name, 1); if (error && error != -ENODATA) return error; @@ -2222,11 +2222,11 @@ int ext4_xattr_ibody_find(struct inode *inode, struct ext4_xattr_info *i, is->s.here = is->s.first; is->s.end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; if (ext4_test_inode_state(inode, EXT4_STATE_XATTR)) { - error = xattr_check_inode(inode, header, is->s.end); + error = ext4_xattr_check_inode(inode, header, is->s.end); if (error) return error; /* Find the named attribute. */ - error = xattr_find_entry(inode, &is->s.here, is->s.end, + error = ext4_xattr_find_entry(inode, &is->s.here, is->s.end, i->name_index, i->name, 0); if (error && error != -ENODATA) return error; @@ -2742,7 +2742,7 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize, min_offs = end - base; total_ino = sizeof(struct ext4_xattr_ibody_header) + sizeof(u32); - error = xattr_check_inode(inode, header, end); + error = ext4_xattr_check_inode(inode, header, end); if (error) goto cleanup; From patchwork Tue Dec 6 01:58:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 30057 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2574428wrr; Mon, 5 Dec 2022 17:39:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf4O/EKEwZlThT2fYC7extLgvaM5VgjxwqCOo1tYvgoTuuTOsjQrAXdmSIkcQQfbSmc29rzC X-Received: by 2002:a17:90a:7885:b0:217:e32e:e931 with SMTP id x5-20020a17090a788500b00217e32ee931mr97255249pjk.146.1670290780020; Mon, 05 Dec 2022 17:39:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670290780; cv=none; d=google.com; s=arc-20160816; b=rRD7lBtNjxblS76gtPu5b6M63AG/vJTaUtkZsVxoTm0YrwsqjcnztrqCIK/tKe2HIj UGHLFRNHKTqHf5+2ScdbcqiO3Ty+Vf1fITQfkB7TjPkmYT5P5H7jk2FVG5RkmcydR/sT lCWtPJLFRPSbdbooPXVQzXjBh+tZAHttmbmVOkEhpUfStiFrccaHdRXptkqyswJ1u/Rr 7qITSpHSiF1j6Y5IAGLioNGZd3KxhfylRUycGiwk3UXwewGevWZnvBKuvh3W0IZNkW8t 3f/XQkaLL4Da/vWM1oDhJxiwKYbWc6Ighb0zWDht4bb5v4anvK7B7I2oFnbWWv7d6gCJ 4azA== 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; bh=uhpIKDvikoeHqoW/TYvGeKHzbukhjBbmcPvqqBvLL9M=; b=pB0Ags4pbkvEQZ9N3WHZaU/TmDxmGaXz4ZMfLKMeMyXBE5yAFCChz02WchS11fXOy6 U0JpPXdDC604MCuj63UV/T1B/CZBwbTIx+NQMrzi88ODjBKaFMXI7CuV82lAA3Y/vczf qcZAiqHZG0s2cv4WRtpJIXMwYfkbMAquRNYMPm046RW3CF9nx01QiEp4FkkLTKHyGpJp VsPVGbk0vI8nF8jzmsZx5Dd90iW9w0ZbXrs3zFjRF26OlRHc4eOITJfjCcj4YcJ9fuyP dWBUx3RnBwFfhJ457980xp2v+h6kf73iWL33O5HkAI6Tb8DSxdBAuYGDZtEANrfYxPSA Rbww== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e64-20020a636943000000b00478a53c6715si6635027pgc.289.2022.12.05.17.39.26; Mon, 05 Dec 2022 17:39:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233497AbiLFBhc (ORCPT + 99 others); Mon, 5 Dec 2022 20:37:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233008AbiLFBhQ (ORCPT ); Mon, 5 Dec 2022 20:37:16 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C512B201BD; Mon, 5 Dec 2022 17:37:15 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NR31f2C1Kz4f3k6S; Tue, 6 Dec 2022 09:37:10 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgDH69jFnI5jZpTsBg--.65169S10; Tue, 06 Dec 2022 09:37:13 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin Subject: [PATCH -next 6/6] ext4: fix inode leak in 'ext4_xattr_inode_create()' Date: Tue, 6 Dec 2022 09:58:06 +0800 Message-Id: <20221206015806.3420321-7-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221206015806.3420321-1-yebin@huaweicloud.com> References: <20221206015806.3420321-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDH69jFnI5jZpTsBg--.65169S10 X-Coremail-Antispam: 1UD129KBjvJXoW7Aw4ftr4kJr4DAF13Xw17trb_yoW8Gry7pr sxJr18Kr4UuFyqg3yrKFs7Z3srKasrGr4UXFyUKw1rAF98Xasaqa45KF4rAF1UJr4ktw1F qF4UCrWFvw13A3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI 42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWI evJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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?1751426824846801776?= X-GMAIL-MSGID: =?utf-8?q?1751426824846801776?= From: Ye Bin There is issue as follows when do setxattr with inject fault: [localhost]#fsck.ext4 -fn /dev/sda e2fsck 1.46.6-rc1 (12-Sep-2022) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Unattached zero-length inode 15. Clear? no Unattached inode 15 Connect to /lost+found? no Pass 5: Checking group summary information /dev/sda: ********** WARNING: Filesystem still has errors ********** /dev/sda: 15/655360 files (0.0% non-contiguous), 66755/2621440 blocks Above issue occur in 'ext4_xattr_inode_create()', if 'ext4_mark_inode_dirty()' failed need to drop inode's i_nlink. Or will lead to inode leak. Signed-off-by: Ye Bin Reviewed-by: Jan Kara --- fs/ext4/xattr.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 003fe1f2d6a8..734f787ae7ed 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -1464,6 +1464,9 @@ static struct inode *ext4_xattr_inode_create(handle_t *handle, if (!err) err = ext4_inode_attach_jinode(ea_inode); if (err) { + if (ext4_xattr_inode_dec_ref(handle, ea_inode)) + ext4_warning_inode(ea_inode, + "cleanup dec ref error %d", err); iput(ea_inode); return ERR_PTR(err); }