Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3210716pxb; Mon, 9 Nov 2020 05:41:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJypKt2A7wiTWLLexzOtIcxrc6CASDf3ybFVniwqWUzYjLwT0gSQDwEjzcismrBC8wa1354V X-Received: by 2002:a17:906:3614:: with SMTP id q20mr14394837ejb.297.1604929288529; Mon, 09 Nov 2020 05:41:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929288; cv=none; d=google.com; s=arc-20160816; b=pCiELiN5LKZHVuUR7c7NwNP8zXzvNyCsnMownH9kNqkeq4GRnpiRsBZ15lZoB3VTPT eWQPULKN1gVTrVKiKuZQWmU4dPSxrY9HGIhzC6pMgBo0nFL/HfuXyGa7P76Y4YUYa9Vq IsDsWGeTm7tCH+Ij2gu4p8IcEQaVmlmm5lhl0QNHhdny12s4POMy9LMr0N/YyOc2SCsO hiy40+hayDKIHpIwNm+Eki4avPxxSf5y3cByqp/A52muZyxqdG4HbNeNkXnW0sNsYA81 L8i2Or9CA1bBUeJ8BfXbr1CqbK0eMWmEIGxfwb6LMN7/B3Vxiq2AbiMbroaducNT+4l2 NbRw== 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=3HugsCWS+bbKuXZnaM7kKupjpJoZMQu6G6K5koDbGqM=; b=Q5IZCLmI98uXlNG8W2ifvHfNhU+FZ4Mu4WNC8O90wxLM0/5dorOUBQRkePYlLNZ4s6 8lCYmSBO+vBJ9C3gSKkd3sYLZDgUZYAl1xUXJP1O0e+T6mqgOhRAvRk6Hu6A6aPWuB9e CMKpMg0SuW0i7P2XlcI+hz2BlnahlPdaN8qjEXJZXsCSOVEJuJ/8LrcCXfc9RDSQ5rlm wbqRhyCOliA3uNHSEujnq66gf3rhjQy+QuFVfUwbA5e7IU7XPnJggtVMrsaBd/FRA094 VdrhzxYBZX4/nsOZsHh4f9G4uLVBTBiigKX0sV/6s2Sh5uuvP0ALZQ6xvF9K+OR6XN1N OCZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bdqO8vJh; 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 l12si6958082ejx.101.2020.11.09.05.41.05; Mon, 09 Nov 2020 05:41:28 -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=bdqO8vJh; 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 S1730579AbgKINEC (ORCPT + 99 others); Mon, 9 Nov 2020 08:04:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:55548 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730040AbgKINBf (ORCPT ); Mon, 9 Nov 2020 08:01:35 -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 E48C520684; Mon, 9 Nov 2020 13:01:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604926894; bh=KkE9599z8X6ZModkrwGfEaS+5dmdtW0p7PPEl6w++O4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bdqO8vJhGHJWvLr8CmM/FRzDF5bkB97Z35LCu2pt3gDm7LurdfT/VeFJjzZePM8xU MaQMhkXTX2qiKrD26NAsyly1v242Sn65j2z+L+XeniQJ6yRjWa2w//m0i5fAJI+pcq Bobmg8SOcsKCyiEhSSIX9w5nAX5rDky1sTnP7VaU= 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.9 040/117] gfs2: add validation checks for size of superblock Date: Mon, 9 Nov 2020 13:54:26 +0100 Message-Id: <20201109125027.557743995@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@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 bb5ddaabc218b..0e6fa91f4c8f2 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -160,15 +160,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