Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1979769pxb; Fri, 5 Mar 2021 04:40:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+MkuL8oPVEk4KUgxxW9W7smk1zPuzOkSnzeQB0KNChRHNcj5MmYHbNi031+PltENIGkQD X-Received: by 2002:aa7:cb05:: with SMTP id s5mr9157714edt.19.1614948023959; Fri, 05 Mar 2021 04:40:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614948023; cv=none; d=google.com; s=arc-20160816; b=Vg3cKRK02MhCWovsMPXyg9CKlcDf5OnBn5l7jskKRGfts/hZgPbYZqss2WeedT7GUC OyBupJ/aRz0bRe7fGKhbWn0cjaX1MGpJwRZcd2jKEW9Bh87b52mFKO95xZzfKX+FkCC0 8HIKwiRzLJZj/I6ctYOzTFBYlGq5leRMcs3b8xRyOQVdmCyunS1IAuXpXUmW2hezEsDt nveNGUuR/7WT9GlPbwXRvv+SbSRKaabPMBKghdhNadOazz1ePZUYEDMzSN5mJ5rP3Zwv t9wgPeeuXBfAuJMpoH476CBaa7xCKGxViBwimkcHp0rkg2+MppAcifctpGGPvRGOyKm4 0ZwQ== 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=lEoVAGnz1MfiK2qgHkotUWhgWe4oahRuV+qF75tftv4=; b=kUgOTGfgAK+xNtoXdf8Qn7SSIJ1s0CigyyudNH0Rtp1E4gF+BEUM4qZePzAJWjx86Y fUrIfU5eGCHfrzTntFFcGZRbS80t0H8c9Z+0qRh0mR/AEEYDuK5/Okb5uU6mgLXBSf/+ pTny1BPSf7fRs2LTAkWtoPEu+PhOF4pc35zac8s4BZ/n5hZt76LQdmcrwhmiusSF7B2u 9AcsIGcruUOZRCjVHChWKmDEAWo6JWqmo4/cZQE/flblXM7h6/3NS1VZ2ZjFY6eYimdH g1CB79sJAEdLEJaGgmhP3KQ83d0FT+4jWDfR2Gt467o12ZfDFJRVlXYWzOohDCYX1+Ln xTgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KCj4p1XK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m12si1445147eds.183.2021.03.05.04.40.01; Fri, 05 Mar 2021 04:40:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KCj4p1XK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232926AbhCEMgt (ORCPT + 99 others); Fri, 5 Mar 2021 07:36:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:49210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232853AbhCEMgX (ORCPT ); Fri, 5 Mar 2021 07:36:23 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 716A865014; Fri, 5 Mar 2021 12:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614947783; bh=Mqw/Xi4CtknF9CnDt+xfZR2WJq/GQJJN7ERbesdt2Zo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KCj4p1XKqiB4kadLH0Q0mwmrvDT2pCoiMMf8RZrZ1y3E2S2ohtABaJBVFyhYjTcDz k+dAbARx8EIKGFjGODtrWXhnZRldhPEaUEsx00qv+oOb5aKYRbhKeb7iiIXURfhV08 f9jPQohVYiPzfTQNbsaw5yzY8NWOMXXjbBJliJhM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+36315852ece4132ec193@syzkaller.appspotmail.com, Randy Dunlap , Dave Kleikamp , jfs-discussion@lists.sourceforge.net, kernel test robot Subject: [PATCH 4.19 10/52] JFS: more checks for invalid superblock Date: Fri, 5 Mar 2021 13:21:41 +0100 Message-Id: <20210305120854.169806432@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305120853.659441428@linuxfoundation.org> References: <20210305120853.659441428@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Randy Dunlap commit 3bef198f1b17d1bb89260bad947ef084c0a2d1a6 upstream. syzbot is feeding invalid superblock data to JFS for mount testing. JFS does not check several of the fields -- just assumes that they are good since the JFS_MAGIC and version fields are good. In this case (syzbot reproducer), we have s_l2bsize == 0xda0c, pad == 0xf045, and s_state == 0x50, all of which are invalid IMO. Having s_l2bsize == 0xda0c causes this UBSAN warning: UBSAN: shift-out-of-bounds in fs/jfs/jfs_mount.c:373:25 shift exponent -9716 is negative s_l2bsize can be tested for correctness. pad can be tested for non-0 and punted. s_state can be tested for its valid values and punted. Do those 3 tests and if any of them fails, report the superblock as invalid/corrupt and let fsck handle it. With this patch, chkSuper() says this when JFS_DEBUG is enabled: jfs_mount: Mount Failure: superblock is corrupt! Mount JFS Failure: -22 jfs_mount failed w/return code = -22 The obvious problem with this method is that next week there could be another syzbot test that uses different fields for invalid values, this making this like a game of whack-a-mole. syzkaller link: https://syzkaller.appspot.com/bug?extid=36315852ece4132ec193 Reported-by: syzbot+36315852ece4132ec193@syzkaller.appspotmail.com Reported-by: kernel test robot # v2 Signed-off-by: Randy Dunlap Signed-off-by: Dave Kleikamp Cc: jfs-discussion@lists.sourceforge.net Signed-off-by: Greg Kroah-Hartman --- fs/jfs/jfs_filsys.h | 1 + fs/jfs/jfs_mount.c | 10 ++++++++++ 2 files changed, 11 insertions(+) --- a/fs/jfs/jfs_filsys.h +++ b/fs/jfs/jfs_filsys.h @@ -281,5 +281,6 @@ * fsck() must be run to repair */ #define FM_EXTENDFS 0x00000008 /* file system extendfs() in progress */ +#define FM_STATE_MAX 0x0000000f /* max value of s_state */ #endif /* _H_JFS_FILSYS */ --- a/fs/jfs/jfs_mount.c +++ b/fs/jfs/jfs_mount.c @@ -49,6 +49,7 @@ #include #include +#include #include "jfs_incore.h" #include "jfs_filsys.h" @@ -378,6 +379,15 @@ static int chkSuper(struct super_block * sbi->bsize = bsize; sbi->l2bsize = le16_to_cpu(j_sb->s_l2bsize); + /* check some fields for possible corruption */ + if (sbi->l2bsize != ilog2((u32)bsize) || + j_sb->pad != 0 || + le32_to_cpu(j_sb->s_state) > FM_STATE_MAX) { + rc = -EINVAL; + jfs_err("jfs_mount: Mount Failure: superblock is corrupt!"); + goto out; + } + /* * For now, ignore s_pbsize, l2bfactor. All I/O going through buffer * cache.