Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2174425iof; Tue, 7 Jun 2022 22:11:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyQNfDOTthaxaIRzdUM465sWHimQWIWFeekx1vtkoUQjLg7VabofRVmPNCZuW63RS8mF+O X-Received: by 2002:a05:6a00:2310:b0:4fa:7eb1:e855 with SMTP id h16-20020a056a00231000b004fa7eb1e855mr33386272pfh.14.1654665084474; Tue, 07 Jun 2022 22:11:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654665084; cv=none; d=google.com; s=arc-20160816; b=DPGZrRSFL/tQdCdmTaUh2OvrnGIppH+J9nzm8+Lqe4Oy9Etgw/FxkGxG3YmNm8+e1h M8CRy93Q7oH+CCP2M4AQZx/PLqPknX9SahX6742tgveuH0jGmUXDhdZuV/MIvxoRm5g1 bqboAX61REEUzkrL+e+QAEJejIGQyt+EzJqg2MfMThD6d2f2SACGaoxq6uy/+X/qx6Qi zOS6UYaXG6j/tQso1Tp7VmO0HySlMWpLAJpNOQ6DJmn8AY8qDk0bH0tbuoQu0wtp+qAD hR+85JMeFgge9TGN7hNfXq6DAvBuINhB1/hUYq5UCHLKMv3hJXVj6zTBDmgUpMLzPRpH bODg== 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=IxBt8drNCZ6IsuHkiiiCrLXxjTqY1zqsb3gza28a1co=; b=JzFFJAi2N+oeSPXycVPNlEY7PSEfy0Q9KJY0hxU0o7js5oFhEgG4xP3XjETxsPimHt S4ahFm5d3vFqv9CGBA6uWydKTAoJXshBQJDOt1Vi0jDAnV/7SIA+4msunP+NrdNL44m/ ojZ5tt4ECJd7agf8UABc65+hDU1ClSRPSosQbe8S/JW3BEB33n99aIqU7YwCwforczrO i7KOeguPSnYqOcDry1BGIGdHgiXVJkgptLoATi6d218bhFFHyMwpTbz270D/BBBKSCWU qNyJwPqaJf+/tNnw7wHJIMZOfYc8NsfqkALCytAZLmmQvH8VdWklWlesGCLaGcHPnC+N tHHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NSScwCHZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q7-20020a056a00084700b0051c67ce537dsi915031pfk.337.2022.06.07.22.11.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:11:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NSScwCHZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8326829C105; Tue, 7 Jun 2022 21:41:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381226AbiFGVbt (ORCPT + 99 others); Tue, 7 Jun 2022 17:31:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356411AbiFGUe6 (ORCPT ); Tue, 7 Jun 2022 16:34:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DADC91EB431; Tue, 7 Jun 2022 11:37:47 -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 dfw.source.kernel.org (Postfix) with ESMTPS id C59D66157B; Tue, 7 Jun 2022 18:37:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC498C385A2; Tue, 7 Jun 2022 18:37:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654627066; bh=7GVSzPHphQc2+Ish2I4eyvamIhqbHAOrOfl/h31fIe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NSScwCHZyDQ6sBQsGROV1A7fYwMrQR9ARtuUj/cCCTygXGkUslAM/BYecMyXvOfO0 Qtf2pWNqwp7uqzhYvFPmM18mVsjugAykCvOlWBXSESHwosa1cPEweCFspMDGGGonrp xdGfWe/AY7HDICbGrII6p2X3gHsNCJYq66o9p6RE= 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.17 564/772] f2fs: fix to do sanity check on inline_dots inode Date: Tue, 7 Jun 2022 19:02:36 +0200 Message-Id: <20220607165005.575873327@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164948.980838585@linuxfoundation.org> References: <20220607164948.980838585@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 5f213f05556d..53273aec2627 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -460,6 +460,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