Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6817374rwi; Mon, 24 Oct 2022 06:31:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6sE1VLo3q2g4oBIhQ6uT99k0DwGjMJisr6+gJcC8ueub3vo+4TnzSUPyWGW7HMB8HNVLnN X-Received: by 2002:a17:907:9627:b0:78d:a7d8:9407 with SMTP id gb39-20020a170907962700b0078da7d89407mr27422416ejc.675.1666618300048; Mon, 24 Oct 2022 06:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618300; cv=none; d=google.com; s=arc-20160816; b=0ugEQR13Vi7i87uKp5xohClnak8F9UohytJi7YvCfjNFeaiX0Yoy1++FPYInpqqBYX E/vo5asiz1kvxa3GjZCAAOVulsSfx0g2F0tyeCVGdk3Ugyxs7P6RK1Qs82vVrWK/QW46 aDP0EKAym7aJvsxPd2B+cQj3BW/ZvyyesOebTj5LkWkShIIeo2VmHVl5c194rak99Mvi CV89aWEo2ADwwGdmtaQoPj9DHW9/XZf/B3/xfBWX/tun+oM8r/XF/ten3XhIp7xKS9dY dc94l159hAKHhEckKKY+8ofaK/hsmGWW/z9r1Obpn5a+CrMHemlGeNHXha8JDp8dGT00 CM4Q== 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=rxnKb43PVueR95OuJku2w86yxCaPJHaugoFRDHBApWM=; b=SR3QC3etSsaODcA3FHvbZ4pt/x/nAXIkxviK0D2q7cLq3+QltuOAUpH13j2X+Rve9y QMVqAVYPXubhNnD1/K6EV4Cw3ZNNuRL2Uxa+9ig/bdWrKgpi7HQxyjGC1+N8JVpk0Exh l8cEJ2aSDV3MouWfsghpBNH0DEQwl+XBN6gN/KDErqEtfWVMB1BOrSzYsR+b2EQwvxuW Trfu1tFKvYUE4+TdhQ6wLOllJIfH56s86Bpe0ZsyLj8CgQzVNlUm04fnca7YO9MMxdKP 0AIDMjs6Jk4bfS3CzvSAjbfr0nIFjGDqVVVvjigZ97GcOy9fv0p/m067OnW9EubUT0dR RSdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=U9KyiCYv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b21-20020a056402139500b00448d387c327si24108740edv.181.2022.10.24.06.31.13; Mon, 24 Oct 2022 06:31:40 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=U9KyiCYv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232835AbiJXMMB (ORCPT + 99 others); Mon, 24 Oct 2022 08:12:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232828AbiJXMLH (ORCPT ); Mon, 24 Oct 2022 08:11:07 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B88915719; Mon, 24 Oct 2022 04:53:39 -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 sin.source.kernel.org (Postfix) with ESMTPS id D1DABCE131D; Mon, 24 Oct 2022 11:39:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFB08C433D6; Mon, 24 Oct 2022 11:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611564; bh=5bSnUp5dX34XQ99c1SQZmiSSKHcGvqw4nlmJQKpbDSk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U9KyiCYvhD6GAybrMCFQy8ylSj92w9vnEYUCu8UF4u3ArmuAy54zyYMKNI167izD4 DV7inK/hjI7vPD60U+IyQY4zGAwxQVyZbHSmC8LIkdrSGIdZWuKxtER1+8LmY+rMHh RT+QTxy2Mru7MfKJqnFweXM3MGt2MhPD3gPqKGqM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ryusuke Konishi , syzbot+2b32eb36c1a825b7a74c@syzkaller.appspotmail.com, Tetsuo Handa , Andrew Morton Subject: [PATCH 4.9 027/159] nilfs2: fix NULL pointer dereference at nilfs_bmap_lookup_at_level() Date: Mon, 24 Oct 2022 13:29:41 +0200 Message-Id: <20221024112950.397696339@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Ryusuke Konishi commit 21a87d88c2253350e115029f14fe2a10a7e6c856 upstream. If the i_mode field in inode of metadata files is corrupted on disk, it can cause the initialization of bmap structure, which should have been called from nilfs_read_inode_common(), not to be called. This causes a lockdep warning followed by a NULL pointer dereference at nilfs_bmap_lookup_at_level(). This patch fixes these issues by adding a missing sanitiy check for the i_mode field of metadata file's inode. Link: https://lkml.kernel.org/r/20221002030804.29978-1-konishi.ryusuke@gmail.com Signed-off-by: Ryusuke Konishi Reported-by: syzbot+2b32eb36c1a825b7a74c@syzkaller.appspotmail.com Reported-by: Tetsuo Handa Tested-by: Ryusuke Konishi Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/nilfs2/inode.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c @@ -455,6 +455,8 @@ int nilfs_read_inode_common(struct inode inode->i_atime.tv_nsec = le32_to_cpu(raw_inode->i_mtime_nsec); inode->i_ctime.tv_nsec = le32_to_cpu(raw_inode->i_ctime_nsec); inode->i_mtime.tv_nsec = le32_to_cpu(raw_inode->i_mtime_nsec); + if (nilfs_is_metadata_file_inode(inode) && !S_ISREG(inode->i_mode)) + return -EIO; /* this inode is for metadata and corrupted */ if (inode->i_nlink == 0) return -ESTALE; /* this inode is deleted */