From patchwork Wed Dec 7 07:40:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 30663 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp32081wrr; Tue, 6 Dec 2022 23:21:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf57n6q6UmGPcltYCb+SRfpnchv7X/ONODL0To1LIIqGHsPoWuNirEHxaoBlV/7iAYW19v16 X-Received: by 2002:a17:903:22ca:b0:189:cca6:3971 with SMTP id y10-20020a17090322ca00b00189cca63971mr17177704plg.89.1670397707234; Tue, 06 Dec 2022 23:21:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670397707; cv=none; d=google.com; s=arc-20160816; b=tmoGW+pDX4mZRCq/k8NBY3PHNX2GwG6u9sWIF635ePwh5QTS2rZ5lcvkAis8cjFbc4 jgfq2VlLHwK2srEgEi8p19lQfrTT8XeuhKGQLxoTLncvV/ODKfpjrBKLB5gYHd6zqJtH 5/RhE41htvIPLxaSpWpxOQRvxG0k+QKPSf75itUMRQytmSWB+G5wzPvM0eKiU0UXZhep KNldFGStqGU65e1TDf029Q3J9hA1C12Xi414IrMAQsPK8+MQsZrncP/bC08zIa0IO+Nj l5OWZCs2FG7SeM7pTOQ+BSxHBH9V5Ma17bTr1vUB+EeMgwVwd+C+3RZQknN72yQvtuId lnxw== 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=6mYSqDmerZ1pBrvDeIzrlGck47rtiTjHQzpgNsGZkgk=; b=D6TdhNn0dwxUGCfyH0jamN/THgh2FqoeKFqVvTdujpab+T3UOyStEXnwRwWwNxkPnd DJ0GWFKuUMoK3rPHOSPRmt+RTSWfZweBIyxxn3r7oGPcAeURrMz0eIHXWMaZrW55ep0u mV2R1Hs/Z6zOMyjbQx/ceWBbYu88OOwJclAIAanS/e4b3LveJNK9LFIFBMX0LEgn31wA 9HmkpdAx58Wnaczb+UN7Behc4F8JlfJUQqNVT411P1xLPbZXvDYcBlU4WD1/rcXa9RCN jbk+ic383znlfRNse2+DHhXyhS/MA7PQUQDITofDN3fYtb5Ko51exZwQJq4XNHC76ES7 jkYw== 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 oa14-20020a17090b1bce00b0020593d282desi797652pjb.12.2022.12.06.23.21.34; Tue, 06 Dec 2022 23:21:47 -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 S229779AbiLGHUF (ORCPT + 99 others); Wed, 7 Dec 2022 02:20:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbiLGHT4 (ORCPT ); Wed, 7 Dec 2022 02:19:56 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4594F2183C; Tue, 6 Dec 2022 23:19:55 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NRpZY0CBsz4f3k6P; Wed, 7 Dec 2022 15:19:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBniteWPpBj6qE0Bw--.52253S5; Wed, 07 Dec 2022 15:19:52 +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 v2 1/6] ext4: fix WARNING in ext4_expand_extra_isize_ea Date: Wed, 7 Dec 2022 15:40:38 +0800 Message-Id: <20221207074043.1286731-2-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221207074043.1286731-1-yebin@huaweicloud.com> References: <20221207074043.1286731-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBniteWPpBj6qE0Bw--.52253S5 X-Coremail-Antispam: 1UD129KBjvJXoWxGrW3JFy5KrWkJr4rZr4kXrb_yoWrKry8pw 43A347Cr48XF9rCF4xAr1Utwn8Wwn5CF4UJryxWr1kZFy3Jw1xKa98Kr4SqFyxtrW8Jry2 qFn8J34rKw15GaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV 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=0.3 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,SPF_HELO_NONE,SPF_NONE autolearn=no 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?1751538946080476227?= X-GMAIL-MSGID: =?utf-8?q?1751538946080476227?= 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, change EXT4_XATTR_SIZE_MAX from '(1 << 24)' to XATTR_SIZE_MAX. As VFS limit extended attribute maxium size to XATTR_SIZE_MAX. So we can assume that there will be no extended attribute with a length greater than XATTR_SIZE_MAX. 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..c71e582b1007 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 illegal. */ -#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 Wed Dec 7 07:40:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 30665 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp32373wrr; Tue, 6 Dec 2022 23:22:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf7MoLRzyhxfkoP7PlnA0ayb4K2ihGZEbwGXZMFFIC/yQd67AqGxqaCNdhEIhU+ZZdA5y9jb X-Received: by 2002:a17:902:848d:b0:185:378d:7c18 with SMTP id c13-20020a170902848d00b00185378d7c18mr82388331plo.21.1670397758941; Tue, 06 Dec 2022 23:22:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670397758; cv=none; d=google.com; s=arc-20160816; b=mNDJbvz6C/+upX0anvuasN3+Rc/TwS1OiTBjlkIUYIddenuHMFht7wDCZANvWLdmk9 9B4ALxmH6N6Bb5ruhZKi3GY5X/DooaHgo9e45fCq9Uj/vwTv5C2nIkgmHulHj9cnoWZ3 KrGFJfeybPxkruOHoGvt9ppR8ZOGvcOB8VDDtxAB9QLctlu3dQ0HzJVOtUawG40afU7h fu6wAt48Ms2ssrRcLqQ1uMOUkd2JHpLWNHmxNRh1puWI+oyfqciUQ0Ar3X1IYxgxRQkM IBx5FTJ8QX9Vln1jbkD0HcLNt+Ztk/FUbxWSXn8Pz5tGqhaTEyVk6oOFMh2HpsX3v5qA tgLg== 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=toiNhTWmkWpLhy5mOjVgoE1yT8DeJVHk6AxMQSuO1LxPRDitfb8IjSva85naIYWfdk DF/ogHugSm88sKi1AroxgVjw9OYy9GQNajPrfuexnM+kakELmGEZqw0h+jtOt2vs7COP FD0ib9Yei/H8aXLwJpIXk0Zdn3/2fszGDROGoucyjv+4EQ2JHDV7nCn0G3f4fWZj4B40 iWR3l8vr6KVP5Ep3gpc6DylqbTNJ7O+hcLRQRHwrpE9bjeCsLBHCaNBjuPy428dKgghV ZcfDibzNhkPwi6HfRT4xWzRuTcle8sJ8C9H+Ib9krq3GIpNnI7znC2yod2k8GRFtVJdn hgzA== 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 d10-20020a170902f14a00b001889ad3ed98si17372933plb.462.2022.12.06.23.22.26; Tue, 06 Dec 2022 23:22:38 -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 S229740AbiLGHUP (ORCPT + 99 others); Wed, 7 Dec 2022 02:20:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229732AbiLGHT4 (ORCPT ); Wed, 7 Dec 2022 02:19:56 -0500 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6869631FA9; Tue, 6 Dec 2022 23:19:55 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4NRpZY60v8z4f3mSd; Wed, 7 Dec 2022 15:19:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBniteWPpBj6qE0Bw--.52253S6; Wed, 07 Dec 2022 15:19:52 +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 v2 2/6] ext4: add primary check extended attribute inode in ext4_xattr_check_entries() Date: Wed, 7 Dec 2022 15:40:39 +0800 Message-Id: <20221207074043.1286731-3-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221207074043.1286731-1-yebin@huaweicloud.com> References: <20221207074043.1286731-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBniteWPpBj6qE0Bw--.52253S6 X-Coremail-Antispam: 1UD129KBjvJXoWxGF13CFykKry7Cw45ur1kGrg_yoW5ZF4rpa 13Jr98Gr4UJFyDWrySyw1UZwnIga1xGFWjvFyxKw1FyF17Xrn7tFyFqF90kF1jyrWkGw1j qa98tr1Uua13u3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV 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=0.3 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,SPF_HELO_NONE,SPF_NONE autolearn=no 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?1751539000244242573?= X-GMAIL-MSGID: =?utf-8?q?1751539000244242573?= 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 Wed Dec 7 07:40:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 30659 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp31866wrr; Tue, 6 Dec 2022 23:21:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf4PZWPRc1oX23oyqoTB2z80G9Sifk8WWhGjsdFHoISuToLG7xZeqZ27HjsvPAivRT62XHgf X-Received: by 2002:a17:90b:681:b0:213:ff80:1828 with SMTP id m1-20020a17090b068100b00213ff801828mr104488778pjz.31.1670397668998; Tue, 06 Dec 2022 23:21:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670397668; cv=none; d=google.com; s=arc-20160816; b=zhhNZdXYquOU7NeEfa4v61/4kkdrkkBbpmgfNWXZidSxx1fV76tHtd6X8z01ZbBAlw u3qHa89bEH/GE2Uai7BtGDNLQpxNcZye5jl6HWgOSR9WSrs0z/tuHI0JoBr5EbovWK8u K88ucrvJJCosbVyCuVc/zwCeo3xckuispZ+t3JU+s4IrH2lR9g86UTGrmlW10B50vfHf zYGv/xr6u6wDT3wXMeb7Btxo04/1nRAX2ij5jv9FqyignqoTiElJwh/j3ulmcKAHvcoz neoarX/tgm775G5NHvHnSQ3C07vP/1bG3vigN2b3hLw1WVSSZDX7wNNe1vnOvHsgqjh5 YItQ== 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=pKrXr6OGQ0B2N4fquoeRKH7cNJngRspBD2SbWyTdF8vgg9Ov59KP8YhapuavKU9Fbg PAKN/8wnu96BAS24q7/nsCEoNkr2W6s7mH0c9gr+2t5zwCu23WJmgC0FrUlgJyR6wrPT 49Wfdg41rou7QWDNbDYmLFKBTlN1a36OIxb+jkbUQOnRGBZi/H8rHAgL7cDlptMQfFk3 KaDOLVCRzaHyq2LSaBIAYKPGU1AspUppU4TjLzrE8lbf9VSMYe3zg70HlWAQxOXLPD6A itr2QQGkHvmubPMJA/Q0ndGfyrIsL6M5TlQXnZDoOZu5DlQHy6cnK8XSr77gZM+LVQE2 F0DQ== 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 v8-20020a17090a898800b002190292b597si731186pjn.26.2022.12.06.23.20.56; Tue, 06 Dec 2022 23:21:08 -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 S229744AbiLGHT6 (ORCPT + 99 others); Wed, 7 Dec 2022 02:19:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbiLGHT4 (ORCPT ); Wed, 7 Dec 2022 02:19:56 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49EC631EEE; Tue, 6 Dec 2022 23:19:55 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NRpZY49dDz4f3vf8; Wed, 7 Dec 2022 15:19:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBniteWPpBj6qE0Bw--.52253S7; Wed, 07 Dec 2022 15:19:52 +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 v2 3/6] ext4: remove unnessary size check in ext4_xattr_inode_get() Date: Wed, 7 Dec 2022 15:40:40 +0800 Message-Id: <20221207074043.1286731-4-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221207074043.1286731-1-yebin@huaweicloud.com> References: <20221207074043.1286731-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBniteWPpBj6qE0Bw--.52253S7 X-Coremail-Antispam: 1UD129KBjvdXoW7Jw4rXF1fZw15GrWfur4xXrb_yoW3trXEya 4qqr4UGr43Xr1xWrWDAF1ay3ZYy3W8Gr1fuF4kJFy7Z3WaqayvvrWDXrWUZr13Ww4rt3Z8 Z34DJrW7GFyFgjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbV8YFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r1rM2 8IrcIa0xkI8VCY1x0267AKxVW8JVW5JwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK 021l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r 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=0.3 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,SPF_HELO_NONE,SPF_NONE autolearn=no 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?1751538906528606206?= X-GMAIL-MSGID: =?utf-8?q?1751538906528606206?= 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 Wed Dec 7 07:40:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 30664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp32355wrr; Tue, 6 Dec 2022 23:22:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf6+ow+XI/CBz+rqSfW6oVc9ZsuYd63988QlfKQKokpoMR1Q0xsKXgmLBTN7bBzpaAdXNCPo X-Received: by 2002:a17:902:c386:b0:189:fae5:e938 with SMTP id g6-20020a170902c38600b00189fae5e938mr389923plg.54.1670397756435; Tue, 06 Dec 2022 23:22:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670397756; cv=none; d=google.com; s=arc-20160816; b=GJ/LouOJKyAeRHhJT3bSkhRz0p8LUwmgTuxaP35qV5sh+k/Erdy/Iqifu9eGeMfkG5 UtBrmU7xxwImh8oq7t6KhC03ES1nsVxpxA3bJ5R12bFOTJWoyYgkJC+H6bNyhtq9J1fk qur8NbA26U8/oAuyk0cT+PRoiYQ5o4uZxpmHYKHNYEOBpAyXxuL1GoI9PE6SWrdxodD8 QvaifiKI5fCO4K9ksFuFqAn5AGzrlplJv9+su8rujqWNe+SkYG7y7v98sUSTMYHLM8TB 6qTePcHxcIo2SQ4MveiSoe9RCldWGE4BdRNRlTmhhlHta/18hePuje1P1FIoR4hVlHE7 XKxA== 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=ONtWTKMORvYdzAjC8+0X6rztiOCNwF3ARriV3w+NUMM=; b=lFKS59oRl1sMNfqPnJ7xamKKqdUzPKqlXLDGRnylwkM0zQ1DPM7VFhTSCnFeap5X/7 BxTw2fp07/ZsNO13lEqQoxOE3Tdrp/95lr2m/sgxDFi+9oHjqZ74iNOHrm9WcKG+iYrs iLQJ2STdtCFsWxxSg8GHHfCEAqzJasXIHuxAlAzlHnOiQBnVWCemdEtS8pr1rIfUYhvE mVDJ4O7EmPzzqc11x7YBQSonxve2i6zcT+9Nv0bHjYoGPLc5qTjgI/BKD1IR1eilT+KT rSuMuPiwd0OwwM/QcbHzEuYhyp/p/4qRn5U6GrIoKaPp68ob9P3UZispnkWJs89i1vjD BMuA== 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 d18-20020a056a00199200b00541c0da3083si21269107pfl.302.2022.12.06.23.22.23; Tue, 06 Dec 2022 23:22:36 -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 S229790AbiLGHUM (ORCPT + 99 others); Wed, 7 Dec 2022 02:20:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbiLGHT4 (ORCPT ); Wed, 7 Dec 2022 02:19:56 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90E333204A; Tue, 6 Dec 2022 23:19:55 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NRpZY6TMvz4f3k6c; Wed, 7 Dec 2022 15:19:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBniteWPpBj6qE0Bw--.52253S8; Wed, 07 Dec 2022 15:19:52 +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 v2 4/6] ext4: allocate extended attribute value in vmalloc area Date: Wed, 7 Dec 2022 15:40:41 +0800 Message-Id: <20221207074043.1286731-5-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221207074043.1286731-1-yebin@huaweicloud.com> References: <20221207074043.1286731-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBniteWPpBj6qE0Bw--.52253S8 X-Coremail-Antispam: 1UD129KBjvJXoW7ArW3JF1DJr18Kw4kZry3XFb_yoW8JFy3pa 95K340kr43Wry7urWxCF4xZ3sFg3ZrKr4UGay3Xw40vFy5Xwn2gFy5tFWYvF1UZFWxtw4v qF1Dtr18Za13t3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 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=0.3 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,SPF_HELO_NONE,SPF_NONE autolearn=no 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?1751538997992668129?= X-GMAIL-MSGID: =?utf-8?q?1751538997992668129?= 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 extended attribute will become longer in the future. Signed-off-by: Ye Bin Reviewed-by: Jan Kara --- 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 Wed Dec 7 07:40:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 30666 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp32604wrr; Tue, 6 Dec 2022 23:23:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf4J0Ol9blNpMxGQd+mT3XhyrNjILepINQjqyW2UKzqcUZKrWVNrq2I121b+gicBu5UB5kQJ X-Received: by 2002:a62:e908:0:b0:574:53f4:c4d6 with SMTP id j8-20020a62e908000000b0057453f4c4d6mr67933647pfh.81.1670397795722; Tue, 06 Dec 2022 23:23:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670397795; cv=none; d=google.com; s=arc-20160816; b=M+G0yJwNLEFYks2AVdAvuoQygU247GA9iQXpTMADv/v0XvYRBkFFoV0FNr4+RWArul G9RNCTtB62rkLYV7L2MNlfc64lBHMB5CBaXeEPTholekDd6gJ2dI09b3x0j2S/NWDmCB j60rZWqE/ITMh2FrDVHlP14/WK++khfeoSQAPw+llAOA5psArsop86GZElaJBMJcsJxF kkeb/S1IY7WmkIMt7tBpLzWXutVBmogELRUGgFLj+pHguIwBe0lIpMExOjN8hi42WBir KesQiiwXCJ/ofgoM7ksMqhq73zGkk5r9Ujf4fotGYPjbIPIu6775GcgQOnPgZ7nRv8F0 BWaA== 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=BlT3kliXVaiM+KyHojK8xcd98ctQGqbpRPikJiwYpH8=; b=pAb4gpagTX/wffNStIcSgnhunzEV5T7mv9D1E3s7JakNQK4p5iBT0BX0DsmtXPlC/R 3GYZBoDr9zELwYGyU20V3mQXdSFiHKGjQVhp6hxzoovxN/1+EWePW2O563Eun1V+/DyH TOt8TudXTkFqkK0aTLo5rVyNh0tsiAL0ssI4ch1HlNwJyGx11gBCgvXtUkRxp6uQNJgY qJgksSY5y0TuQ9u1Q0f0GTPyRmMV5zsFii9rLGvzm4JdQRRcgan6w64wnNYscY8rarLD aWiXdfs4eYUt2z1U11C5xO71g0leDnkszgjr3/qtkSYDp+fcRCCDMddXB/dmBEug1CjW HmNA== 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 x84-20020a633157000000b00463fc72dae9si20496422pgx.144.2022.12.06.23.23.02; Tue, 06 Dec 2022 23:23:15 -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 S229606AbiLGHUV (ORCPT + 99 others); Wed, 7 Dec 2022 02:20:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbiLGHT5 (ORCPT ); Wed, 7 Dec 2022 02:19:57 -0500 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF40F32057; Tue, 6 Dec 2022 23:19:55 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4NRpZZ5LM9z4f3sC7; Wed, 7 Dec 2022 15:19:50 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBniteWPpBj6qE0Bw--.52253S9; Wed, 07 Dec 2022 15:19:53 +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 v2 5/6] ext4: rename xattr_find_entry() and __xattr_check_inode() Date: Wed, 7 Dec 2022 15:40:42 +0800 Message-Id: <20221207074043.1286731-6-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221207074043.1286731-1-yebin@huaweicloud.com> References: <20221207074043.1286731-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBniteWPpBj6qE0Bw--.52253S9 X-Coremail-Antispam: 1UD129KBjvJXoW3GrW3AFW3JFyUXw13JF4kCrg_yoW7GFWkpF yUJa4DJr48JryUur40yr17Zw1ag3W7Gay7ZayxC3WSyF1DXwn7tFyFkFn5CFyUur4kWw42 qF43K348u3WSk3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 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=0.3 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,SPF_HELO_NONE,SPF_NONE autolearn=no 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?1751539038778551901?= X-GMAIL-MSGID: =?utf-8?q?1751539038778551901?= 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 Reviewed-by: Jan Kara --- fs/ext4/xattr.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index efa623658c12..5c0476ff62c8 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -290,8 +290,9 @@ __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, - void *end, const char *function, unsigned int line) +__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,12 +308,12 @@ __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, - void *end, int name_index, const char *name, int sorted) +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; size_t name_len; @@ -577,7 +578,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 +629,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 +774,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 +860,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,8 +1863,8 @@ 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, - i->name_index, i->name, 1); + error = ext4_xattr_find_entry(inode, &bs->s.here, bs->s.end, + i->name_index, i->name, 1); if (error && error != -ENODATA) return error; bs->s.not_found = error; @@ -2222,12 +2223,12 @@ 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, - i->name_index, i->name, 0); + error = ext4_xattr_find_entry(inode, &is->s.here, is->s.end, + i->name_index, i->name, 0); if (error && error != -ENODATA) return error; is->s.not_found = error; @@ -2742,7 +2743,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 Wed Dec 7 07:40:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 30661 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp32041wrr; Tue, 6 Dec 2022 23:21:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf5xs+f6me8CmQqjI0jfyNF/+AosVohQXU2L3+Yg+m4nVKYogr1TMb2Zrl7/yX7/hSubN5lr X-Received: by 2002:a05:6a00:408b:b0:56b:ca57:ba8c with SMTP id bw11-20020a056a00408b00b0056bca57ba8cmr73567970pfb.43.1670397700029; Tue, 06 Dec 2022 23:21:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670397700; cv=none; d=google.com; s=arc-20160816; b=easYJMWGwsm9x463sUMynHxaYrAKSVh/HxmLJ4/ry+ecFOFnJPiCX4QyUGLYggTtED CiMj4sNtvmUJjAO10Q487aQq3apGl+tX0gNs1okunX8yUyoyXywAeAFJXdftOJNwPBNE MSKd5uz/n7XJN7MCwDZXnK7K0+7D3dEv7IegWw/sNy4vrvmaow1mbAkdp5xkNtHkDdp2 3g9A1CxLG1ZGtzohM7QH8w5PMDkjDP6TQOFh9zMzBw6qQjU4JSL3ZCydGK0ssoGRWGpY /uISszK/O6N97JJlAvkpz7CVQxJRyZ08h+SKuqVwk2y1wVRk9OiZKdKsZAMSpaKINMdf jRvQ== 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=GswiN5Fl9SB7/VSGPBVAu0XsNrjw7kTuIUeaNxhiB5g=; b=xsAT24dzhT2UhKqdAHonvyz7Vh1SIjUMUSpPAncnLN/EDlbaPBv2dVeRm1ylTBzMzL Yy8NQvMz1Pn/m+02JXkbZ2K836MgkyDKFG4GxIgEVGMITkhqCTf73sW9eOzzKK2yQYy2 ljfgLsaKbrcdFNV6K/8KtJsLOeYqMc7PLMwUCCfWuPEgTktlQoRvnP8dHxbztwjZoadx XQ+H7cjjt8WP0CAPJVAKL7hOUkOuA+XpOFQkwwx2BR9qG/VqG/K9cBSIYHaaV/pm7U27 CpxE0/JSP9KE1w66T7VNgMiJ7D7cVdtUZxFXh6n1/HzK4WmEjE4hA9kHwl5dECZQiaXN NMpQ== 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 l10-20020a170902e2ca00b00189c8b6e603si10295982plc.583.2022.12.06.23.21.26; Tue, 06 Dec 2022 23:21: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 S229785AbiLGHUI (ORCPT + 99 others); Wed, 7 Dec 2022 02:20:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbiLGHT4 (ORCPT ); Wed, 7 Dec 2022 02:19:56 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00E1432058; Tue, 6 Dec 2022 23:19:55 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NRpZZ3MZRz4f3vfW; Wed, 7 Dec 2022 15:19:50 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBniteWPpBj6qE0Bw--.52253S10; Wed, 07 Dec 2022 15:19:53 +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 v2 6/6] ext4: fix inode leak in 'ext4_xattr_inode_create()' Date: Wed, 7 Dec 2022 15:40:43 +0800 Message-Id: <20221207074043.1286731-7-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221207074043.1286731-1-yebin@huaweicloud.com> References: <20221207074043.1286731-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBniteWPpBj6qE0Bw--.52253S10 X-Coremail-Antispam: 1UD129KBjvJXoW7Aw4ftr4kJr4DAF13Xw17trb_yoW8Gry7pr sxJr18Kr48uFyqg3yFyFs7Z3srKasrGr4UJFWUKw1rAF98Wasaqa45Kr4rAF1UJr4ktw1F qF1UCrWFvr45AaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 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=0.3 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,SPF_HELO_NONE,SPF_NONE autolearn=no 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?1751538938407798183?= X-GMAIL-MSGID: =?utf-8?q?1751538938407798183?= 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 5c0476ff62c8..6c19d01ba261 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -1465,6 +1465,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); }