Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp803072pxb; Tue, 3 Nov 2020 12:59:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJz8IQs4b8GfLm2JFdpoD8d0J2x35VlscNNVkV+ruIVVd+3Rl5ecdlcG7LPt/7C6/M2NH8Uo X-Received: by 2002:a50:950e:: with SMTP id u14mr23355765eda.260.1604437179187; Tue, 03 Nov 2020 12:59:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604437179; cv=none; d=google.com; s=arc-20160816; b=TzHrnw6rzenXcK79HCad+wV0EEHK7Fm/D0IWcgb6WajUDk5Yj9EMYYAKacg2nSyOhq fSQ1FbrmD08+ACu6WV9eP86ZbG6h6sbv5LdSMvPC285X0j3ekoYMAQlAyHcbHdMQkPnH xJBsIWvGzdkc6YLbZfPsfTLPYvrCDq83SDm12uA1HaCVCkFR/MHXKeUGj+yHcUCNiUGH n37hc9wb0X5e7+N7GYEWfgkuEomckvvjjkoMoLNb7B/N/ZxLGtW+58jIr7uj15zm72Uz 6qQSPwJ+NN85VXH0ete7zJwSeVXYZVdEF4sUryPpXBPM2CJBlrySjj2U/yvq7PB11DZy J65Q== 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=tGvf6DemsTL9wpsuubb9Oz9AzwQTGiRVtiQwuZxiNhs=; b=Ro9P2Z7+30JJGNTE3+SiBb9hOKqAEgmP8kJasVEkPzfYYm3gG6rKFM/HCzQV/6gdWt MB7TLMrVf94sQHBApUf2GpaRD+aZDToStGiBKD4QCTDzxWhK77gu6TKS+nttB1Cut+4U zlBjV6k1RQ8b2NjA8OHTRiE/+8LXmEAHZlxiHxihhcIQ51vK9o48+sthYx5v3UdW+G4K N638Tb9DH7WhgJAvaX4wJDheWb/7djMJJTOQ74E8t0z5Pu7a9w4y0KN4nHagAi+qjTKN t8P8o5Ipg/yIFrOt+04si8fV3tZroRh+5x3CBGbDWbuVYImKU1WBGTs587vOO11y1dGn TJIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v2Ux7fzL; 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=fail (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 a15si16686651edr.134.2020.11.03.12.59.16; Tue, 03 Nov 2020 12:59:39 -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=@kernel.org header.s=default header.b=v2Ux7fzL; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732074AbgKCUz4 (ORCPT + 99 others); Tue, 3 Nov 2020 15:55:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:57068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732087AbgKCUzy (ORCPT ); Tue, 3 Nov 2020 15:55:54 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AFC3A223AC; Tue, 3 Nov 2020 20:55:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436954; bh=EQVGEy6CkB7Wb8PJHdFwy+HAguGKKloyjSxavWVl7r8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v2Ux7fzLXK+zq7rNL0OEaqOhowyKryZYE+sQuU0aKZeEZuBEI5/uGGFAL1QUVABdr 0vuqxPELDq3l+KxQcgGAFn5J5I4nSjNn8wlwZVL0rvOtle554qHamoR1fS04f3DWid XgUZ7x4CVcFvyLI31KXwALGSrY0QUJTIPq3DndJY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+af90d47a37376844e731@syzkaller.appspotmail.com, Andrew Price , Anant Thazhemadam , Andreas Gruenbacher , Sasha Levin Subject: [PATCH 5.4 084/214] gfs2: add validation checks for size of superblock Date: Tue, 3 Nov 2020 21:35:32 +0100 Message-Id: <20201103203258.219187193@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@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: Anant Thazhemadam [ Upstream commit 0ddc5154b24c96f20e94d653b0a814438de6032b ] In gfs2_check_sb(), no validation checks are performed with regards to the size of the superblock. syzkaller detected a slab-out-of-bounds bug that was primarily caused because the block size for a superblock was set to zero. A valid size for a superblock is a power of 2 between 512 and PAGE_SIZE. Performing validation checks and ensuring that the size of the superblock is valid fixes this bug. Reported-by: syzbot+af90d47a37376844e731@syzkaller.appspotmail.com Tested-by: syzbot+af90d47a37376844e731@syzkaller.appspotmail.com Suggested-by: Andrew Price Signed-off-by: Anant Thazhemadam [Minor code reordering.] Signed-off-by: Andreas Gruenbacher Signed-off-by: Sasha Levin --- fs/gfs2/ops_fstype.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 338666a97fff6..29b27d769860c 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -169,15 +169,19 @@ static int gfs2_check_sb(struct gfs2_sbd *sdp, int silent) return -EINVAL; } - /* If format numbers match exactly, we're done. */ - - if (sb->sb_fs_format == GFS2_FORMAT_FS && - sb->sb_multihost_format == GFS2_FORMAT_MULTI) - return 0; + if (sb->sb_fs_format != GFS2_FORMAT_FS || + sb->sb_multihost_format != GFS2_FORMAT_MULTI) { + fs_warn(sdp, "Unknown on-disk format, unable to mount\n"); + return -EINVAL; + } - fs_warn(sdp, "Unknown on-disk format, unable to mount\n"); + if (sb->sb_bsize < 512 || sb->sb_bsize > PAGE_SIZE || + (sb->sb_bsize & (sb->sb_bsize - 1))) { + pr_warn("Invalid superblock size\n"); + return -EINVAL; + } - return -EINVAL; + return 0; } static void end_bio_io_page(struct bio *bio) -- 2.27.0