Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp776709rdb; Fri, 8 Sep 2023 16:42:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF0G1b5ziN/6AemqT3uCvAprMSZxNN+nsK21+VsuUI+7fTJGihwUD2WUElMH+QsTvpq1LlM X-Received: by 2002:a17:90b:ec5:b0:26d:4d1c:5395 with SMTP id gz5-20020a17090b0ec500b0026d4d1c5395mr9050195pjb.18.1694216554690; Fri, 08 Sep 2023 16:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694216554; cv=none; d=google.com; s=arc-20160816; b=b7GfZ6tHjJUdqw2vidWS2iycp760W8sc+pkrHssS4LyJ9voNl8ASWKuFd4X5LaY8Gr Qu6dmhGdWG5dRAKhhTIX+xD7bnkzF68L1mr+en0TfVocx0Yfiybz6wcFqwoCzv6fbEGp mb9OY1/Ru2L1bCyMdz1PqkpS3YH2IWuNse2eD9V8rHvdSsE09K+ySP7E9iF4QlS9ls1y w1/x+qTFREYCgV95o4iU3YjLSxMYqTzzQzFi0tClS6l3vBMBSrhCY8WeEnmaa5b3TrP1 o7b/WW5LJ47vtYctAZ/ql43tXFBWQ+AgPamO62KntsfxgRtdZ0q9gbb/gnuLhoGSz/hz 5twg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=PQQCzIcQzKZ8gCy9/YOy22vWaOQGGG4cGUxmxyznMXg=; fh=t69//+pSSfow9S0g86Ze6Lg5bbGhpHiHvtLjEwGwlJw=; b=IsYgiu2IIgeF475t9XCf39Z3pQYZ/R7ys77/JBdJR0fI3hjiRUeN+fDEAsXCyCAieM Du+lZcFs7L/TypnVQSrUVLdlotsfptvPDvUftzgA8JrqPEyJb0dgTTXMJgVlckHxqZmH Nly21GPrv8W605DI99miNqEUS2cQJvs/HZvAq0h62zM/yi0TBwkHrtyo7kFD04wgzJPP Zu4BWNzfmfGbyk02Z7STGXcBBxLGokU7Vc92E9LSEaPUKYIfRg4HumYQtu+R4RHKSwqU Pe/AmiTDAESZRl2iwFAFMaVAiBXHGCGsBTu1vPC7h1Q59it+EwvAM/93jjhkc7qlEb0s MOMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JbjvLvSp; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mu7-20020a17090b388700b00268414272d1si2279924pjb.156.2023.09.08.16.42.27; Fri, 08 Sep 2023 16:42:34 -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=@chromium.org header.s=google header.b=JbjvLvSp; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242931AbjIHKnT (ORCPT + 45 others); Fri, 8 Sep 2023 06:43:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234527AbjIHKnT (ORCPT ); Fri, 8 Sep 2023 06:43:19 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 234A71BEA for ; Fri, 8 Sep 2023 03:43:15 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1c0bae4da38so13568905ad.0 for ; Fri, 08 Sep 2023 03:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694169794; x=1694774594; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PQQCzIcQzKZ8gCy9/YOy22vWaOQGGG4cGUxmxyznMXg=; b=JbjvLvSp2NaMyRfITtj2eVN2gl4MFeF5cXMu6v0Uh3ibn8EpvfvrfxjUSsw6rt2xdh bCEKi0Zlz64VuLjKrE8Y29JaOtpuwl+PxAQcSM9Y7oi4LrUdvsYQcSajB4/fdHoa0MuX zYmIKe52+3XhIqmWkSAqmfkS9kjK3aCqKdZoI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694169794; x=1694774594; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PQQCzIcQzKZ8gCy9/YOy22vWaOQGGG4cGUxmxyznMXg=; b=TeYGVbCIAslLcn04H+zcFm7vCaYaYU+8xsSaW9x/RW7uhc4vtqDyrP4pb1s4GvcHpT DtSa33P1H79UCmqVgR36OlF/z3CKiCwC1J7iu92/wq39x6eRm+XYjFCTjR4OPfuN9NqV jjD/QyMjE1xS8KfgNbMoB+D94ZByGczhVL9T4NUGwJoQLqSSDiQ7WDISzWZrHBGQn+9M s9JwsZYATbtMBg7hbNvAb/uHQnJrey0TcNsFyG+j/qWJdNcXLsmtuU7kFV0KZalYBZIF 23AwkgRgAr++qQWzQwTyEodMB80iUgfuvzdybFR8YUzfVf7WEhHlU0+RaQ7or1K67Bqu 23gA== X-Gm-Message-State: AOJu0YwO1z+3JPK9XAvBv/ULA/H4VDnj/Tg/N2ovNzudx65B1yQHjg4L RS3L/xdNCoHzj34fKnz3Cccsn4j+rqnVwvpWN40= X-Received: by 2002:a17:902:c942:b0:1c1:d5d1:a364 with SMTP id i2-20020a170902c94200b001c1d5d1a364mr2372755pla.33.1694169794463; Fri, 08 Sep 2023 03:43:14 -0700 (PDT) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:cfe5:1210:6170:87ad]) by smtp.gmail.com with ESMTPSA id x18-20020a170902ec9200b001bbd1562e75sm1287154plg.55.2023.09.08.03.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 03:43:14 -0700 (PDT) From: Pin-yen Lin To: linux-wireless@vger.kernel.org Cc: Pin-yen Lin , Brian Norris , Kalle Valo , Polaris Pi , Matthew Wang , linux-kernel@vger.kernel.org Subject: [PATCH v3] wifi: mwifiex: Fix oob check condition in mwifiex_process_rx_packet Date: Fri, 8 Sep 2023 18:41:12 +0800 Message-ID: <20230908104308.1546501-1-treapking@chromium.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 Only skip the code path trying to access the rfc1042 headers when the buffer is too small, so the driver can still process packets without rfc1042 headers. Fixes: 119585281617 ("wifi: mwifiex: Fix OOB and integer underflow when rx packets") Signed-off-by: Pin-yen Lin --- Changes in v3: - Really apply the sizeof call fix as it was missed in the previous patch Changes in v2: - Fix sizeof call (sizeof(rx_pkt_hdr) --> sizeof(*rx_pkt_hdr)) drivers/net/wireless/marvell/mwifiex/sta_rx.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/sta_rx.c b/drivers/net/wireless/marvell/mwifiex/sta_rx.c index 65420ad67416..257737137cd7 100644 --- a/drivers/net/wireless/marvell/mwifiex/sta_rx.c +++ b/drivers/net/wireless/marvell/mwifiex/sta_rx.c @@ -86,7 +86,8 @@ int mwifiex_process_rx_packet(struct mwifiex_private *priv, rx_pkt_len = le16_to_cpu(local_rx_pd->rx_pkt_length); rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_off; - if (sizeof(*rx_pkt_hdr) + rx_pkt_off > skb->len) { + if (sizeof(rx_pkt_hdr->eth803_hdr) + sizeof(rfc1042_header) + + rx_pkt_off > skb->len) { mwifiex_dbg(priv->adapter, ERROR, "wrong rx packet offset: len=%d, rx_pkt_off=%d\n", skb->len, rx_pkt_off); @@ -95,12 +96,13 @@ int mwifiex_process_rx_packet(struct mwifiex_private *priv, return -1; } - if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header, - sizeof(bridge_tunnel_header))) || - (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header, - sizeof(rfc1042_header)) && - ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP && - ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX)) { + if (sizeof(*rx_pkt_hdr) + rx_pkt_off <= skb->len && + ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header, + sizeof(bridge_tunnel_header))) || + (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header, + sizeof(rfc1042_header)) && + ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP && + ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX))) { /* * Replace the 803 header and rfc1042 header (llc/snap) with an * EthernetII header, keep the src/dst and snap_type -- 2.42.0.283.g2d96d420d3-goog