Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1146711ybl; Wed, 8 Jan 2020 11:51:16 -0800 (PST) X-Google-Smtp-Source: APXvYqy0E3vInNZOYNZ5TByXSaPBmKhcTYC061mq7VnnMej4rhOjVxJOyT/iiAc4jmJH/UlkNoRf X-Received: by 2002:a05:6808:53:: with SMTP id v19mr188459oic.169.1578513076751; Wed, 08 Jan 2020 11:51:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578513076; cv=none; d=google.com; s=arc-20160816; b=SbD7cQih7HhogdX4sj/Czw9Dpc3F+v6u6bOx6QlZHtwLBtYlzyywBcgZspNrww+Qyi LLsmjq5WttKhWMG4zfqSuGat7WvhAr0ASK0XAlYrU1VCB/XIDiDzKmYfdKQi4pp3TpWy VUWLRqudLe0ElLdqSr2u/Cb0qpkn8eUu5++cHOg4fArUR4fdr277fNDRLFF0G6uqVwcM wCG0XxntSdL6OtdeMIFGFlMJ5/fzifK66MdYICItnVnaiUpqjyn2wqqfK8RMvYKYn0kV HSpMl20SRjmfhqGDTc3SG5goP5JuIm7Y4h5WmMDkSR6QSXX5/GX8L4UwJCoLeBzv22gg Gxgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=o6tdD7jeqIZo5y8ZKdnI3buWN0/yjWfvsAlcLhODuBk=; b=oPN3Tpz+4M4lRoHXvq7G/Y+BiknEnBDfJKsZoCuv0P4a8e3TMItZ8ORQ670YNeeU2Y Ahc/3rL+70sFyU8GAwS00oJR4vzVWLGq+WhX5xRY747TSuA//Pqdy8aRpiHnou2SzWQG 92w3fZ6QwQHGMHqGCn2h3UW/VCmHOJu1GQF+5MyVKl9NwcJ6kT9Jniq//CCSfj3G1rUw opN5qdJJ6EV852cPo6Tu8tIed/rQqrXiEZiwU6wHwJuBJHmdgE8jmHaNjcfnvH2+i5L7 /heMg1Op0hyx8Dchx7HnhnTxSCGAr5n6hbAPZCwmsQG39vw5d8SAk/k4bvMZQPfv9UYG zPKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y140si2317205oia.49.2020.01.08.11.51.05; Wed, 08 Jan 2020 11:51:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728307AbgAHTr6 (ORCPT + 99 others); Wed, 8 Jan 2020 14:47:58 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:43768 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730455AbgAHTqE (ORCPT ); Wed, 8 Jan 2020 14:46:04 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ipHHD-0006oh-VZ; Wed, 08 Jan 2020 19:46:00 +0000 Received: from ben by deadeye with local (Exim 4.93) (envelope-from ) id 1ipHHD-007dpR-I5; Wed, 08 Jan 2020 19:45:59 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "huangwen" , "Ganapathi Bhat" , "Kalle Valo" Date: Wed, 08 Jan 2020 19:44:00 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 62/63] mwifiex: fix possible heap overflow in mwifiex_process_country_ie() In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.81-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Ganapathi Bhat commit 3d94a4a8373bf5f45cf5f939e88b8354dbf2311b upstream. mwifiex_process_country_ie() function parse elements of bss descriptor in beacon packet. When processing WLAN_EID_COUNTRY element, there is no upper limit check for country_ie_len before calling memcpy. The destination buffer domain_info->triplet is an array of length MWIFIEX_MAX_TRIPLET_802_11D(83). The remote attacker can build a fake AP with the same ssid as real AP, and send malicous beacon packet with long WLAN_EID_COUNTRY elemen (country_ie_len > 83). Attacker can force STA connect to fake AP on a different channel. When the victim STA connects to fake AP, will trigger the heap buffer overflow. Fix this by checking for length and if found invalid, don not connect to the AP. This fix addresses CVE-2019-14895. Reported-by: huangwen Signed-off-by: Ganapathi Bhat Signed-off-by: Kalle Valo [bwh: Backported to 3.16: - Use wiphy_dbg() instead of mwifiex_dbg() - Adjust filename] Signed-off-by: Ben Hutchings --- drivers/net/wireless/mwifiex/sta_ioctl.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/drivers/net/wireless/mwifiex/sta_ioctl.c +++ b/drivers/net/wireless/mwifiex/sta_ioctl.c @@ -223,6 +223,14 @@ static int mwifiex_process_country_ie(st "11D: skip setting domain info in FW\n"); return 0; } + + if (country_ie_len > + (IEEE80211_COUNTRY_STRING_LEN + MWIFIEX_MAX_TRIPLET_802_11D)) { + wiphy_dbg(priv->wdev->wiphy, + "11D: country_ie_len overflow!, deauth AP\n"); + return -EINVAL; + } + memcpy(priv->adapter->country_code, &country_ie[2], 2); domain_info->country_code[0] = country_ie[2]; @@ -266,8 +274,9 @@ int mwifiex_bss_start(struct mwifiex_pri priv->scan_block = false; if (bss) { - if (adapter->region_code == 0x00) - mwifiex_process_country_ie(priv, bss); + if (adapter->region_code == 0x00 && + mwifiex_process_country_ie(priv, bss)) + return -EINVAL; /* Allocate and fill new bss descriptor */ bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),