Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2527233imu; Thu, 29 Nov 2018 06:26:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/VQefLrSZapsLL1kXN6dh6NllayeTzqirDlDWS/GiBRZZb5ZOZAOIu3zY7C+XufOTGefo2C X-Received: by 2002:a63:e20a:: with SMTP id q10mr226527pgh.206.1543501569014; Thu, 29 Nov 2018 06:26:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501568; cv=none; d=google.com; s=arc-20160816; b=w1vsqKb/p3SMMddej6j5+awcKiNhS5XeWggHKXXXnSASgFUNszQNV8cW+mJZ8gPll9 G4SpJz8hX8UgrHlfuGizoB8URegMN1KEkiEw5j1ANNG5NkF4ydbg8L4B/UooT1YDOwUA TYQ29oyyeXtvCxFN1sAXNNPwnaEnN1u9QKKRDvYVyApPAMtNqL+4sJqbOL8UzzeG09DZ xEfSRIMrPeGZ1bbIBwiHQ1QKfdCqqn2j0ejOD4cd6Sa1FB7Hkj6k7rSKgEypa0wrYKvL ueP0FwFj3HgiMPTawMBA3Xa5fGf+n9ikee+rHQAxn/kMcwjgmt0Gj5XlrBF34xqmcYx2 RozQ== 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=aY9N95/zlSE2P5+POf2IwoANsW/5+iLT1BMFVSbwJOM=; b=sq7pCoFRWuJ0lKpCVRp54WJUwguhRlsy2rHZjT+njONpZXDUJzYCI49aP6L0Uphfbx mthaDS+UlYVvgy1lVn3mHtJfx073DPmdeoBiUDMLGrAqLMa8vaCCKR69RRxiuUm1BYch 0O3Ut6swjA+8kQPfYwWIXjtc/j02cB/HmRPdYGAovws1f67IL54kxDliRy1bTZXljaRd E5Z8HK/hQXuM6uzt2ZEtKUgt0lPnMVgN8qBZTrRCtNTTZLysw3NHRWTV1l/MvbTk1WdB 3fzBaLigjwKAXTzAeguuPytxARGtl40TanAlN3+arWIYSqaoXgn5gRar9UVOVizhRByJ BQFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=toMSd9nB; 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 u6si2520534pfb.92.2018.11.29.06.25.42; Thu, 29 Nov 2018 06:26:08 -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=toMSd9nB; 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 S1732836AbeK3Bad (ORCPT + 99 others); Thu, 29 Nov 2018 20:30:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:57642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731565AbeK3Bad (ORCPT ); Thu, 29 Nov 2018 20:30:33 -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 07DD22146D; Thu, 29 Nov 2018 14:25:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501501; bh=cweXbTBHDAExAan8BXB3GKzno8wACnnjsw2pALUFt7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=toMSd9nBneusnpQp4fi4bHk8rJTEHfwKEftgiISQAlSHrNbriQevgXBQO9JsM9qIZ 6x69Crevp97FlD1mMCc9N+zsRrU4dhVX4lv2qRwecSeNYI1Tz8LaigeMB4wAt0wNl+ A05YYzwN6KqwjhaEwtSB10dJOY6mx/vrZ8MOlVYw= 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.14 024/100] bfs: add sanity check at bfs_fill_super() Date: Thu, 29 Nov 2018 15:11:54 +0100 Message-Id: <20181129140100.827972866@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140058.768942700@linuxfoundation.org> References: <20181129140058.768942700@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.14-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);