Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5076661pxb; Mon, 15 Feb 2021 08:54:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJybLuh2BArTA+u8DAgAfH6cyA017Wvdr81gsH6w8C7mDMotFrQLmt6FonDCOyDmYkj1q9Lt X-Received: by 2002:aa7:dd49:: with SMTP id o9mr16495980edw.14.1613408074560; Mon, 15 Feb 2021 08:54:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613408074; cv=none; d=google.com; s=arc-20160816; b=NIxhscjJxAfAkicQ0s6Yt8DJ747E1DCTuwQgDu0LED7CwnP2bdUyCsGXwskLJYfeLO A8W9f65vDnjneXP095XtOwFMajEmZ5Z0FQ1gJ9RhW/n/+Q0pwcWe8k3hzbIeNXawr2xd piCDHgNiQtMEzIHEMVZOXscdtEpo/ym6UcZ/5s6lzKqmSbS8btAEHj9A7U3zrVLOSJHu 3tMkn2aA9vXYFVLlJXWG1aMjpEzX6g9uEvJE32/GSVuHSyRU8ZaT4yMZVv0WiLd5LIjy lglAAxPXP5rNXbFCgXNagMNka6YKeCrAbp/9oM0uUeUlcPo5l9gFAVznMciDxymlrgRR jZzg== 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=ZtKQ6QIElEhyJHWugB4fEMtT2S9pTvgyyS4z4iel6RBACB88mEu1tM2cAYiY5hAhwQ qvTl8/eTnzz9/VLTaY07DoCKvZ1nzQr9egCuLbmT4ZWobuZekqJm7PkfaYfRPYHfHkAk ZYroyNGpHz034IzvWJt8HvZgm+8ApZcFVwLhqKdMNLqYn6utEVChha7zjMCQsYCrSvMs cPJbH3E9Z9Ur7yk9Jti5tlrTQQdZMLdbDQDxwhZZfwX2L63ioBXyvPsJ1wrbBCboo0ma yBYQ82t5ljiO7squcDzqD306IzxBj8NDwb517EcWohQ2swCsrqTXU6yE5zPkjMq28F8z 9URA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OdJ5CmdD; 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 e6si5813350edv.313.2021.02.15.08.54.11; Mon, 15 Feb 2021 08:54:34 -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=OdJ5CmdD; 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 S231565AbhBOQve (ORCPT + 99 others); Mon, 15 Feb 2021 11:51:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:49600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229993AbhBOPlu (ORCPT ); Mon, 15 Feb 2021 10:41:50 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D153664DC3; Mon, 15 Feb 2021 15:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403297; bh=QDBg45RFT+SOm/lag6l4rj0iybT9eBugjWUvyOd+7iY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OdJ5CmdDE4Yr8z2NXlaezPe8kJmQOHTbjHJqSGml3/+W/aAoQCu7JRBmgxHuPCsPs oKABefMKV0jteew6B2w86JyxuKnfZ50ptHbUD4FRFqdiKdxFznYArxuVpt+nYBLj60 NBxg3moB11mjIHNBhwUnaMj63vzZT206H06ABdC0= 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.10 102/104] net/qrtr: restrict user-controlled length in qrtr_tun_write_iter() Date: Mon, 15 Feb 2021 16:27:55 +0100 Message-Id: <20210215152722.761368789@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152719.459796636@linuxfoundation.org> References: <20210215152719.459796636@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;