Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp916450pxx; Tue, 27 Oct 2020 03:56:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy12IoPdV/11YYTHtJVYL539QXS1Zez9aF2DEd7OjzRQymme73FpnkKljp8hrJCtpz/IczJ X-Received: by 2002:a17:906:c186:: with SMTP id g6mr1653006ejz.465.1603796195848; Tue, 27 Oct 2020 03:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603796195; cv=none; d=google.com; s=arc-20160816; b=mi4P7iKWJKn9LV5ZRxhTslb1mE9eXWpIY8/Ugdavb9urgFJw6JPkexqtl0OAwUVsZx s4U268AR5J2nOCTEz3kAUtPE5Bqt3J58QSufV7MZwNT50vhJM7mOjjpRqXmUmZVqt/QT KJytB8f9aShJtch7dx3KFJfqZKuDN7m0qCy+b9NGDKqi9iOXuvijIU0xycbUTxK8ylRX h1UELPlI6kKfe5vdgHSJ2BMuhwd+MGHVCu+K/ugDD0CUdXOZMSffobTCOw5To4or9+tZ EtbgyoG3wwHpRTqxWVjq1inG6TtFyYIBozD1KK7pd8ohpAQfnJjdIfYPtALEVw0lm9YT khEQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mtt4DkUUINqiVil4c98Sft5ZjR5pVmFl/emp15/0cmA=; b=QwhH6W2+YLQVMbcVamLQcphZlpI6T/QMY8qtBLb2J2wkF0Yor/bFq3X8YuljVaCNXV 2tuxUYebOxo3rP18OseWEXiGuHtA+twJyrt/VuGRAc2uJqUoerbp7+duL5JS4x/NmYrC tpwSh9VKBW8vkP8OpubxZjbaF4JbRO2A0kqGHYdOGwONBa6QRm5r092YqKPOP6dC51ph /Kpc1fky4M1FiFYD76No3WENqLsB5PKQbLBy9aXZ1ANT+B862XNqX+F9oDhOHuHKr39s a/l6lhHVzDejG86sruzXi58aTBoJUWFGYC4RRq8mFCcbFSgi93YiRoMO9hu25C67Uf/X b/EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fbLEZhHl; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d7si712075ejk.598.2020.10.27.03.56.13; Tue, 27 Oct 2020 03:56:35 -0700 (PDT) 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=fbLEZhHl; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725808AbgJ0AAa (ORCPT + 99 others); Mon, 26 Oct 2020 20:00:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:36770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436533AbgJZX4k (ORCPT ); Mon, 26 Oct 2020 19:56:40 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3D2CD221FC; Mon, 26 Oct 2020 23:56:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756600; bh=0spco8h1lS/S/iKhR4bKFBCHd2OccrFkIlHrFA5ketE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fbLEZhHlK+u56KAn4/gYwrevSGB67G9ZIwcHWa8k1qeNNZh/jHt6neSZeuzTXsQRO osGLD2e7ZBhjCofEm+G4B+gY1TH0Jpmffg4Z9bjswGWPhAQIQvYoYElPdiGjLydnJQ MTZuxn8QL/69N5iEfIu9pbHOy9sX/tnnI/oh86cY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anant Thazhemadam , syzbot+af90d47a37376844e731@syzkaller.appspotmail.com, Andrew Price , Andreas Gruenbacher , Sasha Levin , cluster-devel@redhat.com Subject: [PATCH AUTOSEL 5.4 69/80] gfs2: add validation checks for size of superblock Date: Mon, 26 Oct 2020 19:55:05 -0400 Message-Id: <20201026235516.1025100-69-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026235516.1025100-1-sashal@kernel.org> References: <20201026235516.1025100-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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.25.1