Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4488463ivc; Tue, 3 Nov 2020 13:22:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9f/2o4mBnotd1Y0fB/DW3x1ZTC0OOy9NehdWMrKmWj25PU3gCY7Cbq64//ezrju30UxWQ X-Received: by 2002:a50:fb0d:: with SMTP id d13mr24091062edq.85.1604438527725; Tue, 03 Nov 2020 13:22:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604438527; cv=none; d=google.com; s=arc-20160816; b=uZHxtq6IP7rY/SyT0w4riAZFHS8UscrCK/GrC/E1+3U14HGE5Mwgi+7vDE7mOehNnw HifyYZDUp1605KKsuNMIARph7f5x3LfGbWBOLj+HJB/vbmrjS4G30c2e2079ZxwzCxK0 hA25UAa0d5sWqKTnaeXGGGVp/eh9u83WWTVIdYKjkTDXPuhkg4FBENjcMnN3lis531qp 639mP7k26d8G9Y4vkiT1W1KM9nvQK8V/ic0g6TyHzvYz8+fFHmGOvCowiNDj6VsaWWwM s6LBTMP7YtoNafheJNBsjtPiw3xmw7ZhwA1yucgNfnCoT6LiFPSuMDMrW35blualieT1 kIJw== 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=/GTYBr94CGW5ogzmxIPMGqBqAjsS52ANg1938aM7Siw=; b=XPtFr48ofjdMcRXU0F4HCYJvVENQeZBCnQTZNvJP3tZA2Cr+Tm870t+zC5Gk1DLNaZ w0bMY89f1nywzd1eNGrRYsfUcRgoHTXryUppzXcM5Oz18d4CdLFH02kTLeBBRAZ2p5Wo qTDXrce1tASHoCtG3z/Q/3AAnVp4R4yzyKgWjt30hIhYZos8PMkOHy2DQoWQLoTjxmNY Q0/xgJb6wu6A4EeAIruR1T5oNjspSqOuVeGcQbx6r0EESsF06acfnBkyly4AwScimquA NVYYvhrIUr0Kcx+kG1+MhcRJ/lMGyIiQkEEpe78XXfbrKnVk+IZs4sW2AOIX7NiYgIub GY0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DrjNICxJ; 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 d24si1417501edq.121.2020.11.03.13.21.44; Tue, 03 Nov 2020 13:22:07 -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=DrjNICxJ; 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 S2388757AbgKCVRG (ORCPT + 99 others); Tue, 3 Nov 2020 16:17:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:51664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388748AbgKCVKh (ORCPT ); Tue, 3 Nov 2020 16:10:37 -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 7B03E206B5; Tue, 3 Nov 2020 21:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437837; bh=vw2uco8VbAYvvg1ZPp5VtM0nQ/bOfZ0pJKl6LrYeppc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DrjNICxJEYV3wNeizAGyN8oWrFQ6n7m0JWG30yrKwv2l7m3sUD/gcKjkZ9Inu80Zw fAIwXNqIttccX0xxaCq7LWbQ2I4fzVyBv5PYDa/lAq2++7XSpzFo+Acq9V9jcRCySm YsNbsL6AwlMJM9OgpCOBxJ/qIgVzQRriv0fIdDGg= 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 4.14 052/125] gfs2: add validation checks for size of superblock Date: Tue, 3 Nov 2020 21:37:09 +0100 Message-Id: <20201103203204.533629797@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203156.372184213@linuxfoundation.org> References: <20201103203156.372184213@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 2de67588ac2d8..0b5c37ceb3ed3 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -161,15 +161,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