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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41876C4332F for ; Fri, 9 Dec 2022 11:48:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5AE3D851EE; Fri, 9 Dec 2022 12:48:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="K72OMgtU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 74B9C85230; Fri, 9 Dec 2022 12:48:26 +0100 (CET) Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 011B9851E7 for ; Fri, 9 Dec 2022 12:48:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=szymon.heidrich@gmail.com Received: by mail-lj1-x22a.google.com with SMTP id s10so4687914ljg.1 for ; Fri, 09 Dec 2022 03:48:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=PaPiFhtV/2JEYMndzkbDKyPOUDlTTwhTJ3FBM/kH5GU=; b=K72OMgtU0i53WyyofnAzzTyG+l+uoGFhhba6D5wDqUxo/K2O+B4ppL/Sg4qjmyToJG /wMq0ZIXwm345DL87EoryxXrdhS0fZy3tRSvm1gUbX/SWPa2O4wESixxgLANaN9qhFxT M8K7KQcrXhM/88woLg3ZjmZoCm0krslVwEPdSAmi84VxnHE5s8GtpmD60I8VYuQs5nSP cQ4pw4PJoV6nA33/7yB3CJ7UU5gMvjOtMZA8OHAZaIty1cGO5yNbs5Xez09zhHhbEu6M 0VzlQnayB54TKVYoGyKyVESMQamlzHPCqypv8smVwKxU+h8JiPltq1J1ax2nV31TY6WE Uecw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PaPiFhtV/2JEYMndzkbDKyPOUDlTTwhTJ3FBM/kH5GU=; b=xNI9y9GPjbMrJrKSlzi1k9RqHPhetVhRWw+RtM/zVg53FyRGP/hFmVdCnFDFM3sfD/ lRVygRvd+pqRRyl3Idu8zKyl5+SIIMSOip+SJAUG/87gaXaSY8hvwE/zU3mpIIMVOni0 CkCfXNrdjM5NiSlh1WwNzrJUHr3oZ+cNGk3F+9d88hSRo6Dfu+D6Mlu5ihpuPIbGluNJ 8kQHlN1SYu8je43hj80hOkQrnXZwvHnKJAFoghYhdblirTBl2nFdgV79voupRC2GDogg ViNf6aQBaqb9tsulINQDEAiPCB3Ms8ZGTxWjhsmJFCdO3dik+Z7gai7Wrqs+qaDbLnXw dZ8A== X-Gm-Message-State: ANoB5pkpxC62iNm7HELX+cAbmv1uuG3SXw9mKh3rBmTYUuP+0vXpMAd2 ZlTmwASEEkidCh/iv4wh9II= X-Google-Smtp-Source: AA0mqf5pZutfaqBgI6EKYp/sba4vdbeYuqUsCtjMk9wCROcrTkYuKoKAVOsDGXj6FEPVOhTNaIcsyg== X-Received: by 2002:a2e:9b4e:0:b0:279:e6fd:877c with SMTP id o14-20020a2e9b4e000000b00279e6fd877cmr1302656ljj.53.1670586503154; Fri, 09 Dec 2022 03:48:23 -0800 (PST) Received: from [192.168.50.20] (077222238151.warszawa.vectranet.pl. [77.222.238.151]) by smtp.gmail.com with ESMTPSA id u15-20020ac258cf000000b004b590c768edsm231290lfo.1.2022.12.09.03.48.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Dec 2022 03:48:22 -0800 (PST) Message-ID: <09dd3c14-135f-812b-b4e0-df62241a0937@gmail.com> Date: Fri, 9 Dec 2022 12:48:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v2] usb: gadget: rndis: Prevent InformationBufferOffset manipulation To: Marek Vasut , festevam@gmail.com, lukma@denx.de Cc: u-boot@lists.denx.de References: <58ee51c7-a318-7002-11eb-27aa79614e71@denx.de> <20221205092823.41742-1-szymon.heidrich@gmail.com> <43bcabe9-eb46-9099-eec9-2e846f2c3ddf@denx.de> Content-Language: en-US From: Szymon Heidrich In-Reply-To: <43bcabe9-eb46-9099-eec9-2e846f2c3ddf@denx.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 09/12/2022 02:56, Marek Vasut wrote: > On 12/5/22 10:28, Szymon Heidrich wrote: >> Prevent access to arbitrary memory locations in gen_ndis_set_resp >> via manipulation of buf->InformationBufferOffset. Original >> implementation permits manipulation of InformationBufferOffset to >> exploit OID_GEN_CURRENT_PACKET_FILTER to set arbitrary memory contents >> within a 32byte offset as the devices packet filter. The packet filter >> value may be next retrieved using gen_ndis_query_resp so it is possible >> to extract specific memory regions two bytes a time. >> >> The rndis_query_response was not modified as neither the buffer offset >> nor length passed to gen_ndis_query_resp is used. >> >> Signed-off-by: Szymon Heidrich >> --- >> V1 -> V2: Updated commit message >> >>   drivers/usb/gadget/rndis.c | 9 ++++++--- >>   1 file changed, 6 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c >> index 13c327ea38..3948f2cc9a 100644 >> --- a/drivers/usb/gadget/rndis.c >> +++ b/drivers/usb/gadget/rndis.c >> @@ -855,14 +855,17 @@ static int rndis_set_response(int configNr, rndis_set_msg_type *buf) >>       rndis_set_cmplt_type    *resp; >>       rndis_resp_t        *r; >>   +    BufLength = get_unaligned_le32(&buf->InformationBufferLength); >> +    BufOffset = get_unaligned_le32(&buf->InformationBufferOffset); >> +    if ((BufOffset > RNDIS_MAX_TOTAL_SIZE - 8) || >> +        (BufLength > RNDIS_MAX_TOTAL_SIZE - 8 - BufOffset)) >> +        return -EINVAL; >> + >>       r = rndis_add_response(configNr, sizeof(rndis_set_cmplt_type)); >>       if (!r) >>           return -ENOMEM; >>       resp = (rndis_set_cmplt_type *) r->buf; >>   -    BufLength = get_unaligned_le32(&buf->InformationBufferLength); >> -    BufOffset = get_unaligned_le32(&buf->InformationBufferOffset); >> - >>   #ifdef    VERBOSE >>       debug("%s: Length: %d\n", __func__, BufLength); >>       debug("%s: Offset: %d\n", __func__, BufOffset); > > Applied to usb/master, thanks Thank you very much for your time and review.