Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2195070iof; Tue, 7 Jun 2022 22:50:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1XC5QZAumA0s7pwjVkAlj/mPIKSRz2kSgOQuMHEZFYIlzCdmBHYB7Ub7UI4LugWXl2ROW X-Received: by 2002:a17:903:408c:b0:163:e526:4397 with SMTP id z12-20020a170903408c00b00163e5264397mr31904544plc.80.1654667449845; Tue, 07 Jun 2022 22:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667449; cv=none; d=google.com; s=arc-20160816; b=a7CgJWcvmKnfm14cGWVhpOktNT/v/s0psyO4hzjoTl1IIfjUmqhvzCOpKb7WHW8j5N XkUwhMWLofMtK58GvvxOtKRv5Qt3qw9v+hpctieZH+G43bhfHtIBeLwZJyYrZPJo8Tr1 8xdt5n4ZhjcCcB4gn7hi2ex/xg4vs9fwbB1+W+oAyPlf7ElpjDhQaB+S2gTz/T1QhZVK cN5FymjXIrdB8BaqPJp4aGNfwFrRaD6N+KUCFBuA1GmA4N/YOJPVEGtH+Juq+fv1miOg qj7Kuug0rpdjdVg/WqtptCZYxJPkPRZU/KMtTGKgQI2BP4sutM6zE8OOmnuX8g9HeGQu 38ag== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gORuV6S7klQ7Jd3VnBo6RMR70E0VL/0qD3n8MEEIfsQ=; b=NO05LcpJ34UKH9DbTNN+eHgQQ7siwbIjJZ1oK9HoqPz/eNJucKAJ8Qz0JAl5VXg1QT A4mln/CTcoq5kaDkdfH/SzONhkDcvjJENHKMvkvQwJc5kJutKf4WgqVn4rZRwUjZXc+l ExkkXZtftVW0sNjnhsko6JbsBMh0ywW8WE5a0AaXGIFrugKdBJbhxwf/rEXwOH4KSdol olsyQV3UFRCB08ACPAlbmBrfhl/vIrn/bwRfPKhJsyag3PkDQdAziQsJlIwKVlvyw8BK V29g6gw6hoixJ50TIGdFNIZgL39Y45OYEiZUs2HQP5KX0L68cLajULScYpuLiCzwpLlr 3Oaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M3f+Yylx; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j19-20020a635953000000b003aa7f30fcaasi27394227pgm.516.2022.06.07.22.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:50:49 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M3f+Yylx; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1A18C4A6B9A; Tue, 7 Jun 2022 22:17:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381074AbiFHAOz (ORCPT + 99 others); Tue, 7 Jun 2022 20:14:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356690AbiFGWGy (ORCPT ); Tue, 7 Jun 2022 18:06:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDAF7252C2C; Tue, 7 Jun 2022 12:15:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8C908B822C0; Tue, 7 Jun 2022 19:15:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC007C385A2; Tue, 7 Jun 2022 19:15:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629348; bh=AFmrO0annGer79QB+xtRaRH2XRcecd0xN8/ccZeQdG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M3f+YylxH7DsLQfDyLdr6NuiB+JNxafZeeXSLfGcgJWSmvCeqFDY1nLPv6hya/H8v H92ISD/OgU79NkuFFLpWXGGZ75B8ZNHPf2T2ZYEAgeKJdZJha3OutP6GutouT0E4PF wNez1j8GMf6w9rPyrKR1sBxluOC2nqHawcUr/pzs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenqing Liu , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.18 659/879] f2fs: fix to do sanity check on inline_dots inode Date: Tue, 7 Jun 2022 19:02:57 +0200 Message-Id: <20220607165021.975926404@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Chao Yu [ Upstream commit 12662d19467b391b5b509ac5e9ab4f583c6dde16 ] As Wenqing reported in bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215765 It will cause a kernel panic with steps: - mkdir mnt - mount tmp40.img mnt - ls mnt folio_mark_dirty+0x33/0x50 f2fs_add_regular_entry+0x541/0xad0 [f2fs] f2fs_add_dentry+0x6c/0xb0 [f2fs] f2fs_do_add_link+0x182/0x230 [f2fs] __recover_dot_dentries+0x2d6/0x470 [f2fs] f2fs_lookup+0x5af/0x6a0 [f2fs] __lookup_slow+0xac/0x200 lookup_slow+0x45/0x70 walk_component+0x16c/0x250 path_lookupat+0x8b/0x1f0 filename_lookup+0xef/0x250 user_path_at_empty+0x46/0x70 vfs_statx+0x98/0x190 __do_sys_newlstat+0x41/0x90 __x64_sys_newlstat+0x1a/0x30 do_syscall_64+0x37/0xb0 entry_SYSCALL_64_after_hwframe+0x44/0xae The root cause is for special file: e.g. character, block, fifo or socket file, f2fs doesn't assign address space operations pointer array for mapping->a_ops field, so, in a fuzzed image, if inline_dots flag was tagged in special file, during lookup(), when f2fs runs into __recover_dot_dentries(), it will cause NULL pointer access once f2fs_add_regular_entry() calls a_ops->set_dirty_page(). Fixes: 510022a85839 ("f2fs: add F2FS_INLINE_DOTS to recover missing dot dentries") Reported-by: Wenqing Liu Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/namei.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index 5ed79b29999f..fffafd2aa438 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -461,6 +461,13 @@ static int __recover_dot_dentries(struct inode *dir, nid_t pino) return 0; } + if (!S_ISDIR(dir->i_mode)) { + f2fs_err(sbi, "inconsistent inode status, skip recovering inline_dots inode (ino:%lu, i_mode:%u, pino:%u)", + dir->i_ino, dir->i_mode, pino); + set_sbi_flag(sbi, SBI_NEED_FSCK); + return -ENOTDIR; + } + err = f2fs_dquot_initialize(dir); if (err) return err; -- 2.35.1