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,