Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3355516pxf; Mon, 15 Mar 2021 07:51:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxR0w46yWtm4PAkRvLysoA7TAGt6vKJ6Zv1FpDkiIOhw2nj1E3Ah6BnzSG7jxeqlp1nmY3 X-Received: by 2002:a17:907:76c7:: with SMTP id kf7mr23572487ejc.470.1615819817122; Mon, 15 Mar 2021 07:50:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615819817; cv=none; d=google.com; s=arc-20160816; b=yrzlaPk++udzX+MPp55P+3m/KFXidycpVIGQYKTKdFsWkj3XRYMc1KCtjYCvpwxC/a mwmhP2Zn0oUkWHBILj/ziQaJ2CqjtvYCFCpULukZabx4Pwd7+ZBGKA+Hap9ATlmDxtXc lA2cd3wi0T/06t0OFAykAb+wMjMklcWce4VtqVjdcmUDeK4w8QTnxvsCTs+w4eMf2xvq SY1Xj77Pa/HzGk8IWMkHLTHdZU2arFC7PNK+COzAfwqXGW0unBtrePk9Ca+RIExA8ozD ljPoORXV/RAyUIBzYObKkMTsR6cIwMXX2Du7hENYBZv2Utcc7u+tbzxnyfjwmJDXDxs5 KRHw== 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=z1tbpbziH+FQW2wHWVpbJLG3+h/2/vDX/VUMKE7Mh+o=; b=gtrS2taIFb/b3yvquLiwT4CndGZ5nxale/VmsWGesQ0xyBfdNkK9y5OhJ78oZCedtR TSmhoLhoFhtpNBZHZWlVaJJcT2h3p9g89PV5F0ABZhzCfXeuxkWOyGtnhKjzx6oWJtL5 yXUYsxmVSXECoLM9v9LGH55Euoya1nB0gzVJw9atJLf/5Seztarif1D/+vIivD42cWwm x2xXhgCR6VocNxIS9Ofexy885WkKp7GoNce4u30frT9vN484sXo0T9I6YadQsqNR/jpb 5xl9DggZbXDISaZtGPw1+oXM7lVev5NPBI44iHvNxXxRu0wTwfV30sihDD4Mu9gIMutq cLdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DmKfVEVo; 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 n13si10796571ejs.39.2021.03.15.07.49.53; Mon, 15 Mar 2021 07:50:17 -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=DmKfVEVo; 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 S240499AbhCOOrt (ORCPT + 99 others); Mon, 15 Mar 2021 10:47:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:49156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233887AbhCOOCf (ORCPT ); Mon, 15 Mar 2021 10:02:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2099F64EEE; Mon, 15 Mar 2021 14:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816955; bh=9XsMaaOiAspY5eNbUTF64jnvZ7fk4hGIKdA/MsveCG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DmKfVEVoEW4znOnPDRLtXxLGspQw5zFMHgXVVZJslhzd2Jxq6769TgxvJPsba44VY V2KGoE3MDT44b26i4LYqoF9B34caJhw1pURh8RmTZT6OZPAuMSUSUXWaKp8SZofcaH /5br6o8uBNeWd+d6oykWyK04C/7jry480XUAQLF0= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lee Gibson Subject: [PATCH 5.11 226/306] staging: rtl8712: Fix possible buffer overflow in r8712_sitesurvey_cmd Date: Mon, 15 Mar 2021 14:54:49 +0100 Message-Id: <20210315135515.262567666@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@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: Lee Gibson commit b93c1e3981af19527beee1c10a2bef67a228c48c upstream. Function r8712_sitesurvey_cmd calls memcpy without checking the length. A user could control that length and trigger a buffer overflow. Fix by checking the length is within the maximum allowed size. Signed-off-by: Lee Gibson Link: https://lore.kernel.org/r/20210301132648.420296-1-leegib@gmail.com Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/staging/rtl8712/rtl871x_cmd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/staging/rtl8712/rtl871x_cmd.c +++ b/drivers/staging/rtl8712/rtl871x_cmd.c @@ -192,8 +192,10 @@ u8 r8712_sitesurvey_cmd(struct _adapter psurveyPara->ss_ssidlen = 0; memset(psurveyPara->ss_ssid, 0, IW_ESSID_MAX_SIZE + 1); if (pssid && pssid->SsidLength) { - memcpy(psurveyPara->ss_ssid, pssid->Ssid, pssid->SsidLength); - psurveyPara->ss_ssidlen = cpu_to_le32(pssid->SsidLength); + int len = min_t(int, pssid->SsidLength, IW_ESSID_MAX_SIZE); + + memcpy(psurveyPara->ss_ssid, pssid->Ssid, len); + psurveyPara->ss_ssidlen = cpu_to_le32(len); } set_fwstate(pmlmepriv, _FW_UNDER_SURVEY); r8712_enqueue_cmd(pcmdpriv, ph2c);