Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp883249pxb; Tue, 3 Nov 2020 15:28:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJynWAfvZaUIT/iMUHzymU8m9oGZxbE8dJ4hSF0HpkUEAImUqGYmTRg/WxV/ruDQNPCzLCNH X-Received: by 2002:a17:906:9414:: with SMTP id q20mr17988878ejx.384.1604446089439; Tue, 03 Nov 2020 15:28:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604446089; cv=none; d=google.com; s=arc-20160816; b=XAUztpNyuSLZs3mh0julKzGc6Y04epAJyNW5Fdk6eR1J2F5IRuoMydy5kEjPNuhxzr sWdCtBzOuAeOlSSiCBxAmhJsZXqCE8yjxUCBwJ8fov2WiaaBBAf5/eeO5POmhyNx10FM C01t4UD+xq0tDaRKdvtVa1D6r9uaDVgeYULHMmM9Buo65cb6uuJ4KVJ9QmCJGgOjj7N3 1atB5T91X8Sg64OMU3R4uuVwUTbutZSb7jeYJMDakK6oDqBGVK+ERRGBYkMiOVAOWoWX +jYOW9KQSHwyfjJVHDSabpj/OBbV1AL4Bwx8UyfkGV0vvgJbn2yXtyYleR3dNN/jLcv/ wrBw== 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=vHcXyHaqSZuQDRUEv3pyk0hZGBAyZDC7GOr3DnaMYoI=; b=GXwQwAePPW2z/rTUvaZMKk5J90PsPMkcVhIzsOnGYN8xOxv6cktOQJyG9WDNPX3+DP +C1ycgXw8nADzaZojfFG61m7fiwPZ+nbxuYPnSE9BiTiqFZAm/Mka2eO0vNUZJc5qVNh xt24+DRJ9z0D8ME1EkxuAUG/9sYoWvTWchIt1UUWGXK5Ly4taMnzq5ieqLjkKkcyzHK3 YFY4BNpm55xo32YeudkIUbGjMGdrj3Xm4pJq3lVoPwAgRQJTiQ/zQUcjvOJsQsIa8eSF JV3DW5e+3aoSxxxLSxXMmp2DLJVhFIUPM3VtwwpI6FXoTUZ+JddVxjji7mtFzn9vGyOI iJqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g9E43Rie; 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 g19si113875edy.65.2020.11.03.15.27.46; Tue, 03 Nov 2020 15:28:09 -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=g9E43Rie; 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 S2387758AbgKCVZE (ORCPT + 99 others); Tue, 3 Nov 2020 16:25:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:43136 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388043AbgKCVEx (ORCPT ); Tue, 3 Nov 2020 16:04:53 -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 B5E7020658; Tue, 3 Nov 2020 21:04:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437493; bh=2Ihjsjav/15kT4Ma5uN9/0jt2ugrjMecW97nyfe87/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g9E43RieS2FOHduznjkf/tnDreo1NSwJByMT7payHB13Y/eW0hUiEsCp53niUEi9T ALZkj+4t7xbKjpulebri43ge3w23PUaw5pAGWMwppO7SrdRHWwlWK1qzMiGRCbiNQ4 pdy+wQoKk+HXJYeJsFh46dojo7h5kygaDDntYqL0= 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.19 101/191] gfs2: add validation checks for size of superblock Date: Tue, 3 Nov 2020 21:36:33 +0100 Message-Id: <20201103203243.158645064@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@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 9448c8461e576..17001f4e9f845 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