Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4029719pxb; Mon, 21 Feb 2022 10:27:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7LLvsPn098Z2cGEyGVMdSuLuB3vu727RLvUPtTKqXQW2DQnSzpy2jnKGdJ9sknOHSs7uW X-Received: by 2002:a05:6a00:2389:b0:4c9:f19c:1e52 with SMTP id f9-20020a056a00238900b004c9f19c1e52mr21473060pfc.35.1645468070989; Mon, 21 Feb 2022 10:27:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645468070; cv=none; d=google.com; s=arc-20160816; b=TiZksNIhY98fMP3vcFW3fwpOHeEq35LP9EKkIOIn+B568jw++Gj/337sGqzV6AGAC7 gbjpilMcWueP5k9PXISaCnCFLB6uL62XSIQH/xDxR3I1GLmnR6gM0xlys8IFsgJuDrTu KhPBvkQj0mazZUd9RwWQmVeATFvsl4ASObC+dv2qTYVKeYBENRS/7qQQFE9pno1lg2cF 1B/eH2iqTT0NdZf5rCtaChPianGSVJV3WqJRwU/+ny28Z05nQoc+/WqTZff/R1Ke30Hs UMsKo4CJnBV56TZJXekBVYQlAG2uVNS+lzxBaX2rZs7opkL9Zc32+/kQ25wOPHHFlkpz njhw== 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=0CxsauYjkoZseW/ibBD1PGmADMw/Du8ydHmuCEeqERA=; b=sL+/b5UL/phD3teklCqjAXo9xrSqCBRiR46Su7c083FoQa3acRLOcZqKYgQnTUw6Nl xRePQSgshUHwYVfUPutcZ+OmYpTFLFRyCCDt9LE1jUGnJdkaRbHumwKfUmNX5YfxlvRC 2ggtryitZ7iqIMTumLX20/Yb69E8j/pkipyOd+8h6vI9UBnyJBTiyNICri2qDtr8Huhz yN5RC30WRna40U/m0gnpej8lfUZENMHNAZNIl21dMUe1wn5xLSLvgIP9TbdmIrz17jvm /2AMhY6nLeW5Gam6Jty+GH2SKZWdXQMXX1lX7rjzt4UMeiyl8FLQSpU+bip85txQL1F2 6p2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kr7ODH7Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t14si3644287plr.219.2022.02.21.10.27.35; Mon, 21 Feb 2022 10:27:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=kr7ODH7Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1352655AbiBUJ4U (ORCPT + 99 others); Mon, 21 Feb 2022 04:56:20 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352916AbiBUJsC (ORCPT ); Mon, 21 Feb 2022 04:48:02 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D018924590; Mon, 21 Feb 2022 01:21:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id D240ECE0E89; Mon, 21 Feb 2022 09:21:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAB0BC340EC; Mon, 21 Feb 2022 09:21:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435278; bh=2okCbzb+8btK/pWqiwqGxhM4vD/yRs/35UwQ0lDpdPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kr7ODH7YwdzWvE67ik4VKiRDTf/oKH1WL03MrYKvtkkk0F2GxCZIg9+Ntjm85Xv2t AzJAe2Sf/lItQp1Xjvds2QvZZDV818hZwnSofip7URynDkxrlSn06ZBgGhkZ/M58Dx BetpIFoShNjz9OcMUEWutBS+PCDMIa1nXAwPOMU0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiasheng Jiang , Johannes Berg Subject: [PATCH 5.16 106/227] mac80211: mlme: check for null after calling kmemdup Date: Mon, 21 Feb 2022 09:48:45 +0100 Message-Id: <20220221084938.397787007@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org From: Jiasheng Jiang commit a72c01a94f1d285a274219d36e2a17b4846c0615 upstream. As the possible failure of the alloc, the ifmgd->assoc_req_ies might be NULL pointer returned from kmemdup(). Therefore it might be better to free the skb and return error in order to fail the association, like ieee80211_assoc_success(). Also, the caller, ieee80211_do_assoc(), needs to deal with the return value from ieee80211_send_assoc(). Fixes: 4d9ec73d2b78 ("cfg80211: Report Association Request frame IEs in association events") Signed-off-by: Jiasheng Jiang Link: https://lore.kernel.org/r/20220105081559.2387083-1-jiasheng@iscas.ac.cn [fix some paths to be errors, not success] Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- net/mac80211/mlme.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -664,7 +664,7 @@ static void ieee80211_add_he_ie(struct i ieee80211_ie_build_he_6ghz_cap(sdata, skb); } -static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) +static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) { struct ieee80211_local *local = sdata->local; struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; @@ -684,6 +684,7 @@ static void ieee80211_send_assoc(struct enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif); const struct ieee80211_sband_iftype_data *iftd; struct ieee80211_prep_tx_info info = {}; + int ret; /* we know it's writable, cast away the const */ if (assoc_data->ie_len) @@ -697,7 +698,7 @@ static void ieee80211_send_assoc(struct chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); if (WARN_ON(!chanctx_conf)) { rcu_read_unlock(); - return; + return -EINVAL; } chan = chanctx_conf->def.chan; rcu_read_unlock(); @@ -748,7 +749,7 @@ static void ieee80211_send_assoc(struct (iftd ? iftd->vendor_elems.len : 0), GFP_KERNEL); if (!skb) - return; + return -ENOMEM; skb_reserve(skb, local->hw.extra_tx_headroom); @@ -1029,15 +1030,22 @@ skip_rates: skb_put_data(skb, assoc_data->ie + offset, noffset - offset); } - if (assoc_data->fils_kek_len && - fils_encrypt_assoc_req(skb, assoc_data) < 0) { - dev_kfree_skb(skb); - return; + if (assoc_data->fils_kek_len) { + ret = fils_encrypt_assoc_req(skb, assoc_data); + if (ret < 0) { + dev_kfree_skb(skb); + return ret; + } } pos = skb_tail_pointer(skb); kfree(ifmgd->assoc_req_ies); ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC); + if (!ifmgd->assoc_req_ies) { + dev_kfree_skb(skb); + return -ENOMEM; + } + ifmgd->assoc_req_ies_len = pos - ie_start; drv_mgd_prepare_tx(local, sdata, &info); @@ -1047,6 +1055,8 @@ skip_rates: IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | IEEE80211_TX_INTFL_MLME_CONN_TX; ieee80211_tx_skb(sdata, skb); + + return 0; } void ieee80211_send_pspoll(struct ieee80211_local *local, @@ -4491,6 +4501,7 @@ static int ieee80211_do_assoc(struct iee { struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; struct ieee80211_local *local = sdata->local; + int ret; sdata_assert_lock(sdata); @@ -4511,7 +4522,9 @@ static int ieee80211_do_assoc(struct iee sdata_info(sdata, "associate with %pM (try %d/%d)\n", assoc_data->bss->bssid, assoc_data->tries, IEEE80211_ASSOC_MAX_TRIES); - ieee80211_send_assoc(sdata); + ret = ieee80211_send_assoc(sdata); + if (ret) + return ret; if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;