Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3003318rwb; Mon, 15 Aug 2022 15:57:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR6fXP0lvIps07iOTBHcInLJaiJkLWyAqsHAAaZm35nHZ4Ql5tGMG8FyZdejDGqwcZQnz06R X-Received: by 2002:a63:fb4a:0:b0:429:8605:6ebf with SMTP id w10-20020a63fb4a000000b0042986056ebfmr2935250pgj.225.1660604247827; Mon, 15 Aug 2022 15:57:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660604247; cv=none; d=google.com; s=arc-20160816; b=E37NBUcf6PNJ5ShqkhTgx8DOs58PepV8VR7QLvuLixzFrkx2Oxj5SID6ZTor5ccZTQ RVKBFqoWukiUH/oPuSRe8MG9oOLbFPr4zDxaAxLpmQChbKAhl4qPT2dVcMEhiuScukL0 ccIS5727x/YhtqSOFOCJ7Z4iIKROXHhyZHHSfAcsizWjlii7NGcrYDIDzDCAi5E4GTuA V4+czz3Z8RWLvvuL/IZnUXWlPt83dQhLCIOlKvndWuSZWICfTFJjsy9tFqUO0IN0F3Lp vcJrAZWcxZPH76X5j0QRrN51wMqhKPzkamjCVe2d7gYDhF/AKBgmA13JGgGoTVsJ5xd4 NTkA== 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=iajX9dl2i3BdvxCq3gh/Gid2VCVg898ZIlczYZIQzHs=; b=lwqHJeDWkaVOedYQqew74bzS+LLtjjs/BhW27DUohJLBSwyHmvb/mm1S2g6Yi49kCk 1WvGzNmVfMoR2Vn9VSnFtaJxgYrfSPDCWzaq7Uh7VcrA7U+zLc4R0UFjwec2xLDo5qkt rvJVJMyXaOxV+/BVLrPIvJzeiZGYpNHiQzGidRSLEKJgy8oCjEnKr4NcyhSAvxKgrT02 rteXtDE6ebCnBW/wdiNFghxVoHnt7lPTH8btRDcFk3xp+/RdKmDRZBHH1v5Qo9ijJ9/V HI1T3z02k3U00uJ/LOANRqa+DXGOTsm44xpx4pJCV5SMtHs4kNb6VNvlDJOmcrC3S1xq 9+kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=s9DhqUzS; 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 m8-20020a654388000000b0041bd7937569si11424621pgp.481.2022.08.15.15.57.14; Mon, 15 Aug 2022 15:57:27 -0700 (PDT) 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=s9DhqUzS; 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 S1345520AbiHOUDI (ORCPT + 99 others); Mon, 15 Aug 2022 16:03:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346007AbiHOUB0 (ORCPT ); Mon, 15 Aug 2022 16:01:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B2327A530; Mon, 15 Aug 2022 11:53:24 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 897EAB81057; Mon, 15 Aug 2022 18:53:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2F20C433C1; Mon, 15 Aug 2022 18:53:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589601; bh=6hATWuGjC+v5hX5HKJfRtz4fpdLRzt5zZwyjJviBpEI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s9DhqUzSADCnol1VnntN/0tX39ed6qKSrVoyAzZiHoDLD0BxyIF5ILJWY9RfstBUX aw9gGpdwg+9n582zQO6Qib7yohR5uEbKqFyc0f/it2QFPufyHqZYnJ6mF/0to+AM08 yospz+FqCNfCqUDqIpmDVtQ+jmdVv22skzaxv3FU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ahmed Zaki , Johannes Berg , Viacheslav Sablin Subject: [PATCH 5.15 762/779] mac80211: fix a memory leak where sta_info is not freed Date: Mon, 15 Aug 2022 20:06:46 +0200 Message-Id: <20220815180409.996306392@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 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: Ahmed Zaki commit 8f9dcc29566626f683843ccac6113a12208315ca upstream. The following is from a system that went OOM due to a memory leak: wlan0: Allocated STA 74:83:c2:64:0b:87 wlan0: Allocated STA 74:83:c2:64:0b:87 wlan0: IBSS finish 74:83:c2:64:0b:87 (---from ieee80211_ibss_add_sta) wlan0: Adding new IBSS station 74:83:c2:64:0b:87 wlan0: moving STA 74:83:c2:64:0b:87 to state 2 wlan0: moving STA 74:83:c2:64:0b:87 to state 3 wlan0: Inserted STA 74:83:c2:64:0b:87 wlan0: IBSS finish 74:83:c2:64:0b:87 (---from ieee80211_ibss_work) wlan0: Adding new IBSS station 74:83:c2:64:0b:87 wlan0: moving STA 74:83:c2:64:0b:87 to state 2 wlan0: moving STA 74:83:c2:64:0b:87 to state 3 . . wlan0: expiring inactive not authorized STA 74:83:c2:64:0b:87 wlan0: moving STA 74:83:c2:64:0b:87 to state 2 wlan0: moving STA 74:83:c2:64:0b:87 to state 1 wlan0: Removed STA 74:83:c2:64:0b:87 wlan0: Destroyed STA 74:83:c2:64:0b:87 The ieee80211_ibss_finish_sta() is called twice on the same STA from 2 different locations. On the second attempt, the allocated STA is not destroyed creating a kernel memory leak. This is happening because sta_info_insert_finish() does not call sta_info_free() the second time when the STA already exists (returns -EEXIST). Note that the caller sta_info_insert_rcu() assumes STA is destroyed upon errors. Same fix is applied to -ENOMEM. Signed-off-by: Ahmed Zaki Link: https://lore.kernel.org/r/20211002145329.3125293-1-anzaki@gmail.com [change the error path label to use the existing code] Signed-off-by: Johannes Berg Signed-off-by: Viacheslav Sablin Signed-off-by: Greg Kroah-Hartman --- net/mac80211/sta_info.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -641,13 +641,13 @@ static int sta_info_insert_finish(struct /* check if STA exists already */ if (sta_info_get_bss(sdata, sta->sta.addr)) { err = -EEXIST; - goto out_err; + goto out_cleanup; } sinfo = kzalloc(sizeof(struct station_info), GFP_KERNEL); if (!sinfo) { err = -ENOMEM; - goto out_err; + goto out_cleanup; } local->num_sta++; @@ -703,8 +703,8 @@ static int sta_info_insert_finish(struct out_drop_sta: local->num_sta--; synchronize_net(); + out_cleanup: cleanup_single_sta(sta); - out_err: mutex_unlock(&local->sta_mtx); kfree(sinfo); rcu_read_lock();