Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3522504pxf; Mon, 15 Mar 2021 11:26:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvJ8eW3/iEl2WOylkb1SOI+iAgtWAzSukQJ0dZI1nV2d0D+WqXUeJG0t6eD8d0m6LNspQT X-Received: by 2002:a17:906:8043:: with SMTP id x3mr24730300ejw.149.1615832767619; Mon, 15 Mar 2021 11:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832767; cv=none; d=google.com; s=arc-20160816; b=VRVNHXcZ13mSDzHqIKDULsI4WMsmLTzodHXrsYljXz02zNDacGVhzcu29DocoDZ0rQ NSPPqRWYM5iaGngj4kbos4tCyNC0enY4gjHZSibKaEq+nEkNdp55RC6G74SkXY5nDIZr /3LIOWJNex64peMgEdMFW/gcU8ZZcKwR80SqdeL24WAjqCRin2qFWxKN6k4nYEs38RF3 lLGCJkd2XQcAdk1DZFmyrZliRCqxaDPFjD8uWXxGlqz/0K9A1q/hMQqrhWFWBqYNd/HJ mYVCsKdVmC1cUlN9+Fb+hXcHBbSbbWrJEs6B/QqR/KSCKpMhPCl1oGbem4VmKNE9FZyj sAfQ== 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=ZYEc4uXdSjKlov3qtcg2MkCSexJ5IVKkMIfkfj9gpTE=; b=wU323J3Z0Om5ZnEoI/U7+XIwRtTJN9bIwcaKClErnDwnEDP4C6XdZladfHktFu1N65 l3jpckH6TqLvBvU4/a5qProq6X6Dmi+/KlYBPf4E44oXlpVQJSMLYR0EA8AgR8VANdDV utPpDNPgCE/85K7MdxPzSjGZhYYTKctYZoAXhU0HW08FU7apmNFsgMxsoTDItsrWwrpb rMKMNfbpRh4WjaZiq0WhmsemWbpGDWJIdajAh8BSjmKko2CRL7jbb1Y8LJS6qRA/1K3v AI2nLpX24MRtkevWUHv3lp2/a/47PQkpCgnXzaz50WVSPTpZwY3Fpv6My1LdPeidAlU+ pyBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bArr8pQ+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oz17si12128652ejb.205.2021.03.15.11.25.45; Mon, 15 Mar 2021 11:26:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bArr8pQ+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233523AbhCOO1C (ORCPT + 99 others); Mon, 15 Mar 2021 10:27:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:35610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233049AbhCOOAf (ORCPT ); Mon, 15 Mar 2021 10:00:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 544B864F29; Mon, 15 Mar 2021 14:00:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816818; bh=NLhKgzYXnBpYkUFUSvVlRwJLyAWpOa9ZgJaa+tXxM2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bArr8pQ+5q8b0sK6yl0vYj3xm3O8/O1qA+Y+2tMTgCS0hM5tDzLaBWwBqrsFw/7oD nMeurOxIDxSPl9Zty4MT4qSXjU2FV29I/et47w16LcVHFLvSXg20gcGqVZz3Kc69jP i71R5ejOPe1lxfnaawpVUEFkvABpWHsnMQNmlkxA= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter Subject: [PATCH 5.4 130/168] staging: rtl8188eu: fix potential memory corruption in rtw_check_beacon_data() Date: Mon, 15 Mar 2021 14:56:02 +0100 Message-Id: <20210315135554.616655632@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135550.333963635@linuxfoundation.org> References: <20210315135550.333963635@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Dan Carpenter commit d4ac640322b06095128a5c45ba4a1e80929fe7f3 upstream. The "ie_len" is a value in the 1-255 range that comes from the user. We have to cap it to ensure that it's not too large or it could lead to memory corruption. Fixes: 9a7fe54ddc3a ("staging: r8188eu: Add source files for new driver - part 1") Signed-off-by: Dan Carpenter Cc: stable Link: https://lore.kernel.org/r/YEHyQCrFZKTXyT7J@mwanda Signed-off-by: Greg Kroah-Hartman --- drivers/staging/rtl8188eu/core/rtw_ap.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/drivers/staging/rtl8188eu/core/rtw_ap.c +++ b/drivers/staging/rtl8188eu/core/rtw_ap.c @@ -784,6 +784,7 @@ int rtw_check_beacon_data(struct adapter /* SSID */ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SSID_IE_, &ie_len, (pbss_network->ie_length - _BEACON_IE_OFFSET_)); if (p && ie_len > 0) { + ie_len = min_t(int, ie_len, sizeof(pbss_network->ssid.ssid)); memset(&pbss_network->ssid, 0, sizeof(struct ndis_802_11_ssid)); memcpy(pbss_network->ssid.ssid, (p + 2), ie_len); pbss_network->ssid.ssid_length = ie_len; @@ -802,6 +803,7 @@ int rtw_check_beacon_data(struct adapter /* get supported rates */ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &ie_len, (pbss_network->ie_length - _BEACON_IE_OFFSET_)); if (p) { + ie_len = min_t(int, ie_len, NDIS_802_11_LENGTH_RATES_EX); memcpy(supportRate, p + 2, ie_len); supportRateNum = ie_len; } @@ -809,6 +811,8 @@ int rtw_check_beacon_data(struct adapter /* get ext_supported rates */ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ie_len, pbss_network->ie_length - _BEACON_IE_OFFSET_); if (p) { + ie_len = min_t(int, ie_len, + NDIS_802_11_LENGTH_RATES_EX - supportRateNum); memcpy(supportRate + supportRateNum, p + 2, ie_len); supportRateNum += ie_len; } @@ -922,6 +926,7 @@ int rtw_check_beacon_data(struct adapter pht_cap->mcs.rx_mask[0] = 0xff; pht_cap->mcs.rx_mask[1] = 0x0; + ie_len = min_t(int, ie_len, sizeof(pmlmepriv->htpriv.ht_cap)); memcpy(&pmlmepriv->htpriv.ht_cap, p + 2, ie_len); }