Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5041088pxb; Mon, 15 Feb 2021 08:03:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkN6y8yBHyMsmNmCKqDDhM8yMD3Fv1btMcq86lHRJl6cll89FwFabr+Sk3h9YBflckPYIS X-Received: by 2002:a05:651c:236:: with SMTP id z22mr4406267ljn.169.1613404998527; Mon, 15 Feb 2021 08:03:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613404998; cv=none; d=google.com; s=arc-20160816; b=lGnJe5KcDoQDgsJUts/umztmpDWYTukY0qfv15WtJWCn1zZ44d38O4XK04oia0rA4n cGB1AtTYnRWwsQzBhRalQN6sM6HQDVLht51JAZQ5VMRYI4jkfSCObY1Hb8cOb4L9SSNZ Ofw+hhdjMi9NNV2u/7Ay8/N/OrfoXsHIsM8zKwy0MoxHrs0hL5amRIS8X48+S7cQeOVd B29heIIOS1mjNA3Z9kVctnS7/79UKzvp8LPqyPe3B69UKG/+DJfb6qu4AI42F3VyCDst SgkeqHMh6UqWAewq3gKlgdD2RGZ26JvfI36UjlZ4TfM4tZDXAA1rP8PJnxOEB1hq52qo 7+4A== 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=gglHeoLJRxKpZCU5MyOw4tsqVayRkQ46dmA8JUFRdVc=; b=m3fMwUXEo4OC2iNWLwcvmkZ0rb/91Td1nkiklkRNZKA+WBOT4S9I+fKcLxOXA28G8u rWmlq7YSMPysm1G3KteL91eTs7EWaQxu5OILyOpwDh2s6kEfP4nQw2pDsA6TSxKll5/H RmTtwycr0RWs0X6o5/aPUTUiG2vqi1GyFtpSn2REhCCW+zfG+NdMoBOyln7e9zg1QC53 Jkxz4s5QDO3MvquKM2mmcCn8taahg9+qSOHdMqcDlTTMHpnZc7tOeFBii0jRLvc74uTq qxpUuX55s1R+NnEIX9bKNk08heErbfZ99qmZsIwSGgXhDCYJ+TYHjXtkLVdzuDYJh62P 9Zkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DxVzB8Bz; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id he44si11889248ejc.386.2021.02.15.08.02.51; Mon, 15 Feb 2021 08:03:18 -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=@linuxfoundation.org header.s=korg header.b=DxVzB8Bz; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232661AbhBOQCK (ORCPT + 99 others); Mon, 15 Feb 2021 11:02:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:46856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230494AbhBOPdE (ORCPT ); Mon, 15 Feb 2021 10:33:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 66DB764EB3; Mon, 15 Feb 2021 15:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403022; bh=QDBg45RFT+SOm/lag6l4rj0iybT9eBugjWUvyOd+7iY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DxVzB8Bz/zsHEqNuOK3si8c3LmxY/dgOcYNdH+z3K5g7qBT8sHkZdS01LpB+lbH3n VMNTLqqRE53iPLXDoKXjuxJgJCCmqGKhC44na1OGfZlYSpCnzHY4JHG5wftG1z3oDj PaBqu7eZffPvvjv724qwkyJ+h6ZrLi1q0RuO/Kuc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+c2a7e5c5211605a90865@syzkaller.appspotmail.com, Sabyrzhan Tasbolatov , Jakub Kicinski Subject: [PATCH 5.4 59/60] net/qrtr: restrict user-controlled length in qrtr_tun_write_iter() Date: Mon, 15 Feb 2021 16:27:47 +0100 Message-Id: <20210215152717.273523982@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152715.401453874@linuxfoundation.org> References: <20210215152715.401453874@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: Sabyrzhan Tasbolatov commit 2a80c15812372e554474b1dba0b1d8e467af295d upstream. syzbot found WARNING in qrtr_tun_write_iter [1] when write_iter length exceeds KMALLOC_MAX_SIZE causing order >= MAX_ORDER condition. Additionally, there is no check for 0 length write. [1] WARNING: mm/page_alloc.c:5011 [..] Call Trace: alloc_pages_current+0x18c/0x2a0 mm/mempolicy.c:2267 alloc_pages include/linux/gfp.h:547 [inline] kmalloc_order+0x2e/0xb0 mm/slab_common.c:837 kmalloc_order_trace+0x14/0x120 mm/slab_common.c:853 kmalloc include/linux/slab.h:557 [inline] kzalloc include/linux/slab.h:682 [inline] qrtr_tun_write_iter+0x8a/0x180 net/qrtr/tun.c:83 call_write_iter include/linux/fs.h:1901 [inline] Reported-by: syzbot+c2a7e5c5211605a90865@syzkaller.appspotmail.com Signed-off-by: Sabyrzhan Tasbolatov Link: https://lore.kernel.org/r/20210202092059.1361381-1-snovitoll@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/qrtr/tun.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/net/qrtr/tun.c +++ b/net/qrtr/tun.c @@ -80,6 +80,12 @@ static ssize_t qrtr_tun_write_iter(struc ssize_t ret; void *kbuf; + if (!len) + return -EINVAL; + + if (len > KMALLOC_MAX_SIZE) + return -ENOMEM; + kbuf = kzalloc(len, GFP_KERNEL); if (!kbuf) return -ENOMEM;