Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4785660rwb; Tue, 8 Aug 2023 13:57:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWvKlr/T1xtUga00XKfhL+R6lOts3yThOrYppgED8WscjfunRwcTQXXHQDinN5FQdZuc6L X-Received: by 2002:a17:906:194:b0:969:93f2:259a with SMTP id 20-20020a170906019400b0096993f2259amr545691ejb.73.1691528234919; Tue, 08 Aug 2023 13:57:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691528234; cv=none; d=google.com; s=arc-20160816; b=a9rZ+csutNua2V6S5CtAejj5tAGPjbfN3g+e6AZSSJOihuIVBjjoU/p3phQm2UPc/j gR5sAgm4khVuMJP6r5PQaEs/cyvIRM4wLOgm44MXep6Te87yM1lwUxlWMgygP+IxAuqQ +CvjpDUGZCMLdoaALnJGNxhrDNSdQX3SX9JD3LlXPgr6WizGsdn3v+nEq8r9lk/CetNr KBj6Qb8nPpcicC9rODo/73N0Wm/ZX0KBDJEM3oARLPFIZ92Cf7SSwd248a7IXKIojoRT WfAqcCs1QEx5PE/w3PEA1UJ1oDOzMM5bT/DpIlTIx2DHuTjIi//B+nY24IFf6LXY1xkQ TJ6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=8YfCtcbe4WPmkqSYcWXFF4mhHo97h/r2CF3qRV1YvRU=; fh=esV5KwhE4fmE0YmvRBqEk3mIjIR8MSdylhtUYtHBudo=; b=FLxA0PP72sWMyg9n6Rq66Xo4PDAl86FLP5yAhvys+d88xqcLvPQtp6geGOx+i4ey2O 9Nj1GOQAHVXGLf5WFCin6xqf/mJFbVR+oIFId59AacxD8CFQwmuf2+Cdk2WRl5slRDPd Mn9ialih3GP05CYaWjvw8hcMdiWQK663M8NBdFEPMb+/78KmH9EGjDN3JYUF1wn6U99G WMy1c1pYJoSoKn6tkCaJVTjersPPaBVyrF+4Fg7QYD8FPWghn4jBrVq98a0axoaQdt5V 13WlEazBfWcz13mqwomTtCOmfaGnVaKwfGKckJL+wsFafQnm+RgZNgTLPn2/Zg2WTInz De9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=YvtWi+TJ; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w8-20020a1709060a0800b0099b6a172f27si6391042ejf.611.2023.08.08.13.56.11; Tue, 08 Aug 2023 13:57:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=@sipsolutions.net header.s=mail header.b=YvtWi+TJ; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234180AbjHHUse (ORCPT + 56 others); Tue, 8 Aug 2023 16:48:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234131AbjHHUsR (ORCPT ); Tue, 8 Aug 2023 16:48:17 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:242:246e::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC75E157AF for ; Tue, 8 Aug 2023 09:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=MIME-Version:Content-Transfer-Encoding: Content-Type:References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=8YfCtcbe4WPmkqSYcWXFF4mhHo97h/r2CF3qRV1YvRU=; t=1691512828; x=1692722428; b=YvtWi+TJjW+x9rkOogJe1YVR6/Jup94JukC42D5s/ZMz71I 1WhSKZDbVfYWE5yV4HiA6jRk6HVDCfHkySMy/jOp+ZxQ8M7DZVFAjkLR9Y4bgi4oe5nW0v8DFq2SC xjsKEUtW7bsEzrMszAZ+SaepN9VGzr3G89+JEXixeYDDfZgjkAKy0mpfE7Jw+93BhlOguV90U4fHo KpcJV815o/mr+BOL4DnWCl9heErEmrC7EaBROYt2y1juPbLAv6FJliDCoa/M/ZyWGM8CTtSTijkKE NTHDDdiGS/yxJLTvQ5QEeEKrtlyV7g6S1mxPVqvU/q9GQOwYnzCf7mPHottHLXLQ==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1qTKNL-00CZrr-22; Tue, 08 Aug 2023 12:55:43 +0200 Message-ID: <6ccf4549011f0efa67523d1c171b23694122ec6c.camel@sipsolutions.net> Subject: Re: [PATCH] wifi: ath12k: Fix buffer overflow when scanning with extraie From: Johannes Berg To: Wen Gong , ath12k@lists.infradead.org Cc: linux-wireless@vger.kernel.org Date: Tue, 08 Aug 2023 12:55:42 +0200 In-Reply-To: <20230807030806.9345-1-quic_wgong@quicinc.com> References: <20230807030806.9345-1-quic_wgong@quicinc.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-malware-bazaar: not-scanned X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED 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-wireless@vger.kernel.org Hi, Since I'm covering for Kalle right now ... On Sun, 2023-08-06 at 23:08 -0400, Wen Gong wrote: > If cfg80211 is providing extraie's for a scanning process then ath12k wil= l > copy that over to the firmware. The extraie.len is a 32 bit value in stru= ct > element_info and describes the amount of bytes for the vendor information > elements. >=20 > The WMI_TLV packet is having a special WMI_TAG_ARRAY_BYTE section. This > section can have a (payload) length up to 65535 bytes because the > WMI_TLV_LEN can store up to 16 bits. The code was missing such a check an= d > could have created a scan request which cannot be parsed correctly by the > firmware. >=20 > But the bigger problem was the allocation of the buffer. It has to align > the TLV sections by 4 bytes. But the code was using an u8 to store the > newly calculated length of this section (with alignment). And the new > calculated length was then used to allocate the skbuff. But the actual co= de > to copy in the data is using the extraie.len and not the calculated > "aligned" length. >=20 > The length of extraie with IEEE80211_HW_SINGLE_SCAN_ON_ALL_BANDS enabled > was 264 bytes during tests with a wifi card. But it only allocated 8 > bytes (264 bytes % 256) for it. As consequence, the code to memcpy the > extraie into the skb was then just overwriting data after skb->end. Thing= s > like shinfo were therefore corrupted. This could usually be seen by a cra= sh > in skb_zcopy_clear which tried to call a ubuf_info callback (using a bogu= s > address). I feel these are two separate issues. Having a large enough TLV that the firmware cannot parse it is highly unlikely to happen, and not really an issue here. Please split this into two patches, and fix *just* the buffer overflow in a patch titled "Fix buffer overflow". I believe simply changing the variable type is sufficient for this, as the code is otherwise equivalent. That's a patch I'd take to wireless at this stage (rc5), but probably not the entire bigger change. johannes