Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2893325pxb; Mon, 18 Apr 2022 10:26:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyiP4/A9cCIUAZ1mg1Aq7a6qTpRtLdPrnrSO0NYWL0u/7gxr/nYrteJiAvck5ifzPGM9j6 X-Received: by 2002:a63:7543:0:b0:39d:2965:de66 with SMTP id f3-20020a637543000000b0039d2965de66mr10861934pgn.269.1650302796330; Mon, 18 Apr 2022 10:26:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650302796; cv=none; d=google.com; s=arc-20160816; b=Min+aQpfD2mqYGdRthjHKJxrJdzT8aPPDKM3q6ZLvAQ6Wvhli5toeRemB9iuKoboo1 QkN+GXhhdc8q0X/CanSJB0G3D5kdvXhrlBFJmxnJo5fA0kSn39i0KWhWzA74CuIa5Vr6 EjyccSVxeKVePxNyX74jPC1Z1EKE2t6M81uQHEidnVbwFCK7n2SR2tbcxo5teqdUHMDT Nx2zlzFMqN1aTbR2k3zGcQQAYJAoNsxBvqMFeJ7uMh+xD6dWoR2bEpea3juTmLgfLlf2 xpw/+1qn7ZPF1zRCxtU2+Zo+7HFUgoMMYpu1BgQqvu6BRFZ0D6K5fA0iB5vOprxqGlI+ c6ig== 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=tt0045kNBIOGtAj5wInubDsr+dtGMD5fXPchNRMt9N8=; b=Q3wIhiNurNnVW98LIJjCV+Gpyz8FdfGpRGIYzftvgUD4UizooPhLF0hojYdjuJXPtq Bw7qr1l4tfQE4F+V490ZLIOgpx9ds1gpDrh7VE13Vg38KoPJp5+jwFnmHExsvbDDz9ok UYqg2HQqOYOwLR5A6wvZwVvcZ4cXyyFs7oJeuXgCLU2/Glp4kLMSXD0myqgts3bgTJt7 KWaFCk2qqRTw9SNY6Ljp1AfCE959sIkUXDu7j86zNBfIveoNzMaZbY/2nh1TjUv/kB9/ J8ZR41YgXTDp5zDLxrEByPakJQj+Fya3K258GsLP+iTXa5Vd4yg9vecLCBZ8ADcZR6Il FM+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y3smYUyh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q3-20020a63ae03000000b0039ce0b6491asi9905281pgf.702.2022.04.18.10.26.19; Mon, 18 Apr 2022 10:26:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y3smYUyh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S238933AbiDRMfx (ORCPT + 99 others); Mon, 18 Apr 2022 08:35:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239979AbiDRM3L (ORCPT ); Mon, 18 Apr 2022 08:29:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CFCC201BE; Mon, 18 Apr 2022 05:23:00 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id ECF33B80EC1; Mon, 18 Apr 2022 12:22:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 487A8C385A7; Mon, 18 Apr 2022 12:22:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650284577; bh=Bcm/L4B9jJWb+jV5TvnT5U/PTAjme2W/RGdOOBuZDt8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y3smYUyhasuUWXbEhS+aDzjeD+LDNRozqty4rPrqrzOqsUXvBpWet0iKKBn0g+WtY xMGA7MLYEFlMoQwpDs22RdH8znNuMVHOvDZch/do/cf226Zyy2pcINcW9D1SpBZm20 ncingRStMIvohrdnfPaVwhjAONjQIZ0s0eF+MPw8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marcin Kozlowski , "David S. Miller" , Sasha Levin Subject: [PATCH 5.17 159/219] net: usb: aqc111: Fix out-of-bounds accesses in RX fixup Date: Mon, 18 Apr 2022 14:12:08 +0200 Message-Id: <20220418121211.334656665@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121203.462784814@linuxfoundation.org> References: <20220418121203.462784814@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marcin Kozlowski [ Upstream commit afb8e246527536848b9b4025b40e613edf776a9d ] aqc111_rx_fixup() contains several out-of-bounds accesses that can be triggered by a malicious (or defective) USB device, in particular: - The metadata array (desc_offset..desc_offset+2*pkt_count) can be out of bounds, causing OOB reads and (on big-endian systems) OOB endianness flips. - A packet can overlap the metadata array, causing a later OOB endianness flip to corrupt data used by a cloned SKB that has already been handed off into the network stack. - A packet SKB can be constructed whose tail is far beyond its end, causing out-of-bounds heap data to be considered part of the SKB's data. Found doing variant analysis. Tested it with another driver (ax88179_178a), since I don't have a aqc111 device to test it, but the code looks very similar. Signed-off-by: Marcin Kozlowski Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/usb/aqc111.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index ea06d10e1c21..ca409d450a29 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -1102,10 +1102,15 @@ static int aqc111_rx_fixup(struct usbnet *dev, struct sk_buff *skb) if (start_of_descs != desc_offset) goto err; - /* self check desc_offset from header*/ - if (desc_offset >= skb_len) + /* self check desc_offset from header and make sure that the + * bounds of the metadata array are inside the SKB + */ + if (pkt_count * 2 + desc_offset >= skb_len) goto err; + /* Packets must not overlap the metadata array */ + skb_trim(skb, desc_offset); + if (pkt_count == 0) goto err; -- 2.35.1