Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1308089rwi; Thu, 13 Oct 2022 11:48:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7qNyXuTDeXWrbGIz8UrIctdpy6nblhURUA2yicxihNn16fWcNPdgQjtCUeoecjLIQ4QPf6 X-Received: by 2002:a05:6402:520d:b0:45a:31cb:f5bd with SMTP id s13-20020a056402520d00b0045a31cbf5bdmr1015938edd.119.1665686939525; Thu, 13 Oct 2022 11:48:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665686939; cv=none; d=google.com; s=arc-20160816; b=cJdC7AXC87bO21l47tjQKJc+W/5+lWbyRPFgt9XttxDV+sz6djfYnUSrwuXiXf7eAW ee5WaUDaPCW6yMmx20dvP5craUWkTfO2wNyQ2054Z7fYDNKOEcfhwAsshq1wVQa67t17 4CB+d7WxWvm/rwwv6hFg8oWZYdXPX8uLGzjWh70WipK1aoLuVgXhmqeM+rRP81dQ8f40 /oF6mnHNxkgSiBCM+9u3YD8xePWT6wCpx4+hja9tC5JSZRdOuOqTWYfxqduwN8T6ppf9 F2uPbABRcn8iKDRhedMC3eeT4iJfievApD4wfBwHZcqkxvvVodAPZXuCps+7cU/is15M KD9w== 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=rOBkAhKcePJSZfI0be+tPaBSsuf21vdCx3kTaKZI1w8=; b=HbzFn3+CzKcj0zyE4RPywn/Z48xbdiR//FLyP/YFWHUr6fKUdtFk9/FDYIZBzoLHQJ yz3pMCMo5VkBmDhz45Un25sVLpEXImWptmbecgiGiqLmhNLx8FUP2SzEVuJihVEeIf7I 3B5SOhFXVWnZjdGPypAk65C40c5DvOsVyRY2arlbQAukjSHU4qD64/F1157XZXyvuTHh FJI1quRmVbZ/lay1cgXgZ1W2RAzuf069WfS8ywCduyBplANm+Ws416v2Mkzc9VjdZ+2W thbNMmvcl5lFWJzxuGF5aJYn+xObqlDzR/Vj1RHGrgAwCbdDLmAOEqT+fj7tPJMcsDBX vWYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hVEkAv5R; 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 js4-20020a17090797c400b00778d193ca81si388359ejc.550.2022.10.13.11.48.32; Thu, 13 Oct 2022 11:48:59 -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=hVEkAv5R; 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 S230044AbiJMR4e (ORCPT + 99 others); Thu, 13 Oct 2022 13:56:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229777AbiJMR4K (ORCPT ); Thu, 13 Oct 2022 13:56:10 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E636152008; Thu, 13 Oct 2022 10:54:12 -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 9460EB8201E; Thu, 13 Oct 2022 17:54:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03467C433C1; Thu, 13 Oct 2022 17:54:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665683647; bh=F//YHv1bkUtABcaNo0CCRonpfHuEaxZGVHMrMkrR4lY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hVEkAv5RbtcEzUOnsrXp6OanYVPGI1+DPzEHa2nEXJT2XI1MlUT62Cpv3IDG7I8T1 To+5X74cT4mhCNUxNY3A6WZbqmAjSirA7gmwefvoCGlCRV5Z00p0iGqSeMTo+ScZaR yb8v9g8zV/NM77JuPddEcDUQsXKUSzUHuM/tOl4k= 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 5.4 18/38] nilfs2: fix NULL pointer dereference at nilfs_bmap_lookup_at_level() Date: Thu, 13 Oct 2022 19:52:19 +0200 Message-Id: <20221013175144.880820665@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175144.245431424@linuxfoundation.org> References: <20221013175144.245431424@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.1 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 @@ -451,6 +451,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 */