Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2569777imu; Thu, 29 Nov 2018 07:03:23 -0800 (PST) X-Google-Smtp-Source: AFSGD/UaLA7WjwY7ws8DPm1wtmwwaGt/hXBm56fyNBRtyYJLIK7SDndJW0d2J6vGNT5yZ3WX3liz X-Received: by 2002:a63:5a57:: with SMTP id k23mr1514470pgm.5.1543503803274; Thu, 29 Nov 2018 07:03:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543503803; cv=none; d=google.com; s=arc-20160816; b=YSEwto1SXzjHS2hl4XxC1h+9dkLBkv8iFLfSw8voOeGclR//fktJaWk00xT3H3n+3j 2j4fCVkWbn57YiBBOFBAhcLygUDez31SsGC5eCAbevkbQshaGrRRDd5JfbF8oI57bqdm Asj/Tm6Tzw33DABE8CVXe8moq23x/89VZWLgaRxIpocIaYXQw/x0KuUCfGDft6V+R//a q9oUp/mMtchDkCU1kkvluh+T6xuNXcsPJ9MoxYZVNkJitJkWhFJaBcBt+ukk1RXzdd1m 4G32c3Ry4qnSGd9O7qHs/HnsYZ/lrP/tvwlPYAPC5jtsjA+A4VAoCw5PacWE3MZW8XNR 0mLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FnMsyQWTTvi5LYa5aV8v8KFpAcaNd8kRkcRRaaHsd80=; b=ih+yst5IuWMQeg56CjMkx/KDVbRFJHb5Lz49PFm7nvWB0rCh8MN9pcv36f7vPtArWO iuHPouYTkoJwr3KOel0AsQl15L2S1SvDRGEbwpYBz9mpP9Auo5JmIAJG6lYikpijgPf4 VBkx3QKq0ucVVIvzwMDGXX/QwrHb5cm12STwChX9XjeMcsPUPyJPrHi4MDvpzIQ/Ycd1 IM4mDXRmNFCARvF4NhGCwSdPKLxTgGTD3N6sCcnldZq0LC17OSI2CTGV7xEzFHBV5+TH Z/1DnZZu0eT7YsjMEUmFM+JK2XichDOF9NaKryda3QEQI9b4DdmacpQbxe3qj2dSxDk0 9E7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=klbOWp1w; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9si2173959pff.126.2018.11.29.07.02.57; Thu, 29 Nov 2018 07:03:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=klbOWp1w; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730769AbeK3CHK (ORCPT + 99 others); Thu, 29 Nov 2018 21:07:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:45842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729761AbeK3BXf (ORCPT ); Thu, 29 Nov 2018 20:23:35 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 3B0E0208E7; Thu, 29 Nov 2018 14:18:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501084; bh=ICTylHP/XZIiWhY7b/M9Evh6H8xIdUeCXumnl4B1Nxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=klbOWp1w71GrTxzOO1SlPRcV41VRpTzraJF46Ieyf8LDF66XKQU6yEt0MHvdGHfUU ZHtzgaeDFeuwd92GlsiBABDeS77aHZqUI1b4tZBWxb/mTBSNIzJ7dZHlK2HpX8Zydx ZD3ZObT2yy8mAO+F3PdSUYq18s91KtpkyPqnQnbI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tetsuo Handa , syzbot , Andrew Morton , Tigran Aivazian , Matthew Wilcox , Linus Torvalds Subject: [PATCH 4.4 06/86] bfs: add sanity check at bfs_fill_super() Date: Thu, 29 Nov 2018 15:11:31 +0100 Message-Id: <20181129140110.438088150@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140109.832117862@linuxfoundation.org> References: <20181129140109.832117862@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tetsuo Handa commit 9f2df09a33aa2c76ce6385d382693f98d7f2f07e upstream. syzbot is reporting too large memory allocation at bfs_fill_super() [1]. Since file system image is corrupted such that bfs_sb->s_start == 0, bfs_fill_super() is trying to allocate 8MB of continuous memory. Fix this by adding a sanity check on bfs_sb->s_start, __GFP_NOWARN and printf(). [1] https://syzkaller.appspot.com/bug?id=16a87c236b951351374a84c8a32f40edbc034e96 Link: http://lkml.kernel.org/r/1525862104-3407-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp Signed-off-by: Tetsuo Handa Reported-by: syzbot Reviewed-by: Andrew Morton Cc: Tigran Aivazian Cc: Matthew Wilcox Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/bfs/inode.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/fs/bfs/inode.c +++ b/fs/bfs/inode.c @@ -350,7 +350,8 @@ static int bfs_fill_super(struct super_b s->s_magic = BFS_MAGIC; - if (le32_to_cpu(bfs_sb->s_start) > le32_to_cpu(bfs_sb->s_end)) { + if (le32_to_cpu(bfs_sb->s_start) > le32_to_cpu(bfs_sb->s_end) || + le32_to_cpu(bfs_sb->s_start) < BFS_BSIZE) { printf("Superblock is corrupted\n"); goto out1; } @@ -359,9 +360,11 @@ static int bfs_fill_super(struct super_b sizeof(struct bfs_inode) + BFS_ROOT_INO - 1; imap_len = (info->si_lasti / 8) + 1; - info->si_imap = kzalloc(imap_len, GFP_KERNEL); - if (!info->si_imap) + info->si_imap = kzalloc(imap_len, GFP_KERNEL | __GFP_NOWARN); + if (!info->si_imap) { + printf("Cannot allocate %u bytes\n", imap_len); goto out1; + } for (i = 0; i < BFS_ROOT_INO; i++) set_bit(i, info->si_imap);