From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCA70C433FE for ; Mon, 14 Feb 2022 09:33:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243518AbiBNJdp (ORCPT ); Mon, 14 Feb 2022 04:33:45 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243879AbiBNJdZ (ORCPT ); Mon, 14 Feb 2022 04:33:25 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F6C4AE59; Mon, 14 Feb 2022 01:31:57 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C3A1060F8F; Mon, 14 Feb 2022 09:31:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2385C36AE7; Mon, 14 Feb 2022 09:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831116; bh=2gge4O5EMd2sOxc5pLIMQF4jXVkp7Vr1+Gj3J7QqJiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZkXePqPYSf4ZIjuG/DT201PtpffdMMm9kaPbXwEeCpuM2fgd5evC/K5CdzkPESZPC +KlZ1nJFwFb+yky9z/9pBX2nf6zBXVayF5OwU0ZzKz+xQIR8EgBuiVUW3KznzGfQqB gbbjY2yyng0qqfV0IJqSparKOS7kBRUMXY+keLbE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Szymon Heidrich , stable@kernel.org Subject: [PATCH 4.14 36/44] usb: gadget: rndis: check size of RNDIS_MSG_SET command Date: Mon, 14 Feb 2022 10:25:59 +0100 Message-Id: <20220214092449.076117393@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092447.897544753@linuxfoundation.org> References: <20220214092447.897544753@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: stable@vger.kernel.org From: Greg Kroah-Hartman commit 38ea1eac7d88072bbffb630e2b3db83ca649b826 upstream. Check the size of the RNDIS_MSG_SET command given to us before attempting to respond to an invalid message size. Reported-by: Szymon Heidrich Cc: stable@kernel.org Tested-by: Szymon Heidrich Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/rndis.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/drivers/usb/gadget/function/rndis.c +++ b/drivers/usb/gadget/function/rndis.c @@ -640,14 +640,17 @@ static int rndis_set_response(struct rnd rndis_set_cmplt_type *resp; rndis_resp_t *r; + BufLength = le32_to_cpu(buf->InformationBufferLength); + BufOffset = le32_to_cpu(buf->InformationBufferOffset); + if ((BufLength > RNDIS_MAX_TOTAL_SIZE) || + (BufOffset + 8 >= RNDIS_MAX_TOTAL_SIZE)) + return -EINVAL; + r = rndis_add_response(params, sizeof(rndis_set_cmplt_type)); if (!r) return -ENOMEM; resp = (rndis_set_cmplt_type *)r->buf; - BufLength = le32_to_cpu(buf->InformationBufferLength); - BufOffset = le32_to_cpu(buf->InformationBufferOffset); - #ifdef VERBOSE_DEBUG pr_debug("%s: Length: %d\n", __func__, BufLength); pr_debug("%s: Offset: %d\n", __func__, BufOffset);