Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp277795ybi; Wed, 29 May 2019 21:13:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRbtrTAxqUnFR7aLBS6FiKuqBmUQ/sOARVh+OAwoRGWdGmwneY9W0xZBRjtvOi/fXthQvH X-Received: by 2002:a63:2b96:: with SMTP id r144mr1946183pgr.314.1559189627406; Wed, 29 May 2019 21:13:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559189627; cv=none; d=google.com; s=arc-20160816; b=fSbECWovb/GHYsrviIQx3P+XEW0t3JHvRvchtO+WCIGsW3DZo6v7skzPXJLk/n3KFZ Z1OGFuPKmH+l+EqgoBICYKpYSGhqV+SQyEhdzXf8gBPOLNEQYjjXXhjTrgkBzaW5p+Y8 70Aol0PUHubReuI7peS6LXXdMzTYu0DsHxVuSshFaR4DVRhbmZYm6qyl7XpJI1yg/DEs 20V8AWmbPpfn0wWGcWiumytoVe3UulAv0g/1tHCUY0vzQRzUbcxHKTFQvsuAAUwmWBAR iXyv/ZSZK/GGBYSqhUtB4lHVFh+5ZUmcUEXtVeLtwbUZaoGfcv0CZBMHJdQFB/TV0RQB dnqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OygpRiO4e8Ew5fVjZUZc1FxElI9lTK+9ETtV3mc5XUw=; b=jA/qH1gtL3RH3KfLE/YBHbdIdn6ApKglJejh/+PsP/Oktmxya9brRgwckG6T7afVjY xZo8bbDY7ZmgioS8B05/BDOQodaciz4cutK368yhAxqwpMdC2xSJq60szmiSJ31XM7LQ beWnONPmm+92l4EuBxlMrC28m6t2EipDhYOVLQh5O/w0w+vizv5W74YHgRtea+XGAJ/N KaVlLZVoScYAHKjr2c/zn3P/ioOSM1pU8S4BUgeOodU2mP45LZFhpFiJbMb4pF7tAnPW YYzVckvT7zGqHig8I5vofXrJFJhCH9XeipRj7ZOSGuAS4bEcWztYZckBQUsxxv/DsGLV EG4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oCxRkyKq; 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 l75si1967766pje.36.2019.05.29.21.13.31; Wed, 29 May 2019 21:13:47 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=oCxRkyKq; 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 S1729927AbfE3EL3 (ORCPT + 99 others); Thu, 30 May 2019 00:11:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:43788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729878AbfE3DQt (ORCPT ); Wed, 29 May 2019 23:16:49 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0F72324636; Thu, 30 May 2019 03:16:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186208; bh=m1S/o7bBWJfYKmlK40ba7fNUGV6C3viDPdMO7iZvriU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oCxRkyKqQiqDircj7LsyrjllqLBjif5t9BqxAUeGyu+EctIWr1Imvzdck56EzjNNM YMakhqw6RVI2XBJAlVbR2HUh/G4fCYnLn5nUTTWD5ampLLWjatotXmNFsXSmTfGnEb 28huTibOkXUFxHXvsvmrhyrhaExHdmG5Przq3b8E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aditya Pakki , Kalle Valo , Sasha Levin Subject: [PATCH 4.19 097/276] rsi: Fix NULL pointer dereference in kmalloc Date: Wed, 29 May 2019 20:04:15 -0700 Message-Id: <20190530030532.206413780@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit d5414c2355b20ea8201156d2e874265f1cb0d775 ] kmalloc can fail in rsi_register_rates_channels but memcpy still attempts to write to channels. The patch replaces these calls with kmemdup and passes the error upstream. Signed-off-by: Aditya Pakki Signed-off-by: Kalle Valo Signed-off-by: Sasha Levin --- drivers/net/wireless/rsi/rsi_91x_mac80211.c | 30 ++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/rsi/rsi_91x_mac80211.c b/drivers/net/wireless/rsi/rsi_91x_mac80211.c index 4e510cbe0a89f..be59d66585d6d 100644 --- a/drivers/net/wireless/rsi/rsi_91x_mac80211.c +++ b/drivers/net/wireless/rsi/rsi_91x_mac80211.c @@ -188,27 +188,27 @@ bool rsi_is_cipher_wep(struct rsi_common *common) * @adapter: Pointer to the adapter structure. * @band: Operating band to be set. * - * Return: None. + * Return: int - 0 on success, negative error on failure. */ -static void rsi_register_rates_channels(struct rsi_hw *adapter, int band) +static int rsi_register_rates_channels(struct rsi_hw *adapter, int band) { struct ieee80211_supported_band *sbands = &adapter->sbands[band]; void *channels = NULL; if (band == NL80211_BAND_2GHZ) { - channels = kmalloc(sizeof(rsi_2ghz_channels), GFP_KERNEL); - memcpy(channels, - rsi_2ghz_channels, - sizeof(rsi_2ghz_channels)); + channels = kmemdup(rsi_2ghz_channels, sizeof(rsi_2ghz_channels), + GFP_KERNEL); + if (!channels) + return -ENOMEM; sbands->band = NL80211_BAND_2GHZ; sbands->n_channels = ARRAY_SIZE(rsi_2ghz_channels); sbands->bitrates = rsi_rates; sbands->n_bitrates = ARRAY_SIZE(rsi_rates); } else { - channels = kmalloc(sizeof(rsi_5ghz_channels), GFP_KERNEL); - memcpy(channels, - rsi_5ghz_channels, - sizeof(rsi_5ghz_channels)); + channels = kmemdup(rsi_5ghz_channels, sizeof(rsi_5ghz_channels), + GFP_KERNEL); + if (!channels) + return -ENOMEM; sbands->band = NL80211_BAND_5GHZ; sbands->n_channels = ARRAY_SIZE(rsi_5ghz_channels); sbands->bitrates = &rsi_rates[4]; @@ -227,6 +227,7 @@ static void rsi_register_rates_channels(struct rsi_hw *adapter, int band) sbands->ht_cap.mcs.rx_mask[0] = 0xff; sbands->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; /* sbands->ht_cap.mcs.rx_highest = 0x82; */ + return 0; } /** @@ -1985,11 +1986,16 @@ int rsi_mac80211_attach(struct rsi_common *common) wiphy->available_antennas_rx = 1; wiphy->available_antennas_tx = 1; - rsi_register_rates_channels(adapter, NL80211_BAND_2GHZ); + status = rsi_register_rates_channels(adapter, NL80211_BAND_2GHZ); + if (status) + return status; wiphy->bands[NL80211_BAND_2GHZ] = &adapter->sbands[NL80211_BAND_2GHZ]; if (common->num_supp_bands > 1) { - rsi_register_rates_channels(adapter, NL80211_BAND_5GHZ); + status = rsi_register_rates_channels(adapter, + NL80211_BAND_5GHZ); + if (status) + return status; wiphy->bands[NL80211_BAND_5GHZ] = &adapter->sbands[NL80211_BAND_5GHZ]; } -- 2.20.1