From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.simonwunderlich.de (mail.simonwunderlich.de [23.88.38.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E8F93F7A91 for ; Fri, 8 May 2026 15:43:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=23.88.38.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778255019; cv=none; b=LqUYTZT2lXRPU7xrlDAthS37WpiyFeBciizvzY/s77/+ITBWt+nzIx3nwyLskfXu25GHQeRGFH9mrfDV3uostjnwCSYUmRtXYf1rFoZpVJIZt13eXc+qYTp2JKwq47PsR6OXx1v/39Ml14cDE37UKVLKk2Qm1hwh+eVTq/Rt1AA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778255019; c=relaxed/simple; bh=M65G7ywCUgEGkx1nUdPlycUJUzXTTzHTpHl6LOwOoxA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hwDijsHicqCycnL3f18nxACZHkhR60/rNRHp0nc2Cb2rljaCpP8GkZV0RVHjwGydY/QvWgrYIJwKiHiUmROmJuAemE5+8LBvfe0Hix7MHSSsFlG92Ndyztf4i74IB1hIKMv8hpv+mMqOr02XWFvA63BEuOQW2UmzgzWWBkRkQZ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=simonwunderlich.de; spf=pass smtp.mailfrom=simonwunderlich.de; dkim=pass (2048-bit key) header.d=simonwunderlich.de header.i=@simonwunderlich.de header.b=G+0CeM6p; arc=none smtp.client-ip=23.88.38.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=simonwunderlich.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=simonwunderlich.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=simonwunderlich.de header.i=@simonwunderlich.de header.b="G+0CeM6p" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=simonwunderlich.de; s=09092022; t=1778255011; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KIfU73idM0J1qzjECasosBqZBJk4pqnhj27Zo4ddO7U=; b=G+0CeM6plJnRHWOvUcmV4tCJpiTCzBilPRDg+jYUcTLI8svm4r88XQ1nd43WAmgMZo9TWc WReTRlx7SKD8fvnT0RTbJpiHkvQkyg3HuaUkuw3XDrspSMUNZFbqtgJ0L0PykFlzeWf16W QK2HJh0/JlsS3QsnsyljINvLBnQ3Se13MPz4HrYCb6JBrwq9NsET1koXulmhcYFtYteo6s YKK0O40DVDskc6N0Fo9ZguC2cj/lNHiHR5bdyZnfNMS50qsuGHn/7Fp33c66EYB7C9DIjh WV29BVMuiTXwJO0zJLbzA/flmnwBgkpAf7qQx+PQiqc+hoy0VVEiyFYc2KkEdA== From: Simon Wunderlich To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , b.a.t.m.a.n@lists.open-mesh.org, Sven Eckelmann , stable@kernel.org, Simon Wunderlich Subject: [PATCH net 5/8] batman-adv: tp_meter: fix tp_num leak on kmalloc failure Date: Fri, 8 May 2026 17:43:11 +0200 Message-ID: <20260508154314.12817-6-sw@simonwunderlich.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260508154314.12817-1-sw@simonwunderlich.de> References: <20260508154314.12817-1-sw@simonwunderlich.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Sven Eckelmann When batadv_tp_start() or batadv_tp_init_recv() fail to allocate a new tp_vars object, the previously incremented bat_priv->tp_num counter is never decremented. This causes tp_num to drift upward on each allocation failure. Since only BATADV_TP_MAX_NUM sessions can be started and the count is never reduced for these failed allocations, it causes to an exhaustion of throughput meter sessions. In worst case, no new throughput meter session can be started until the mesh interface is removed. The error handling must decrement tp_num releasing the lock and aborting the creation of an throughput meter session Cc: stable@kernel.org Fixes: 33a3bb4a3345 ("batman-adv: throughput meter implementation") Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich --- net/batman-adv/tp_meter.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/batman-adv/tp_meter.c b/net/batman-adv/tp_meter.c index 58ca59a2799ed..066c76113fc43 100644 --- a/net/batman-adv/tp_meter.c +++ b/net/batman-adv/tp_meter.c @@ -994,6 +994,7 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst, tp_vars = kmalloc_obj(*tp_vars, GFP_ATOMIC); if (!tp_vars) { + atomic_dec(&bat_priv->tp_num); spin_unlock_bh(&bat_priv->tp_list_lock); batadv_dbg(BATADV_DBG_TP_METER, bat_priv, "Meter: %s cannot allocate list elements\n", @@ -1366,8 +1367,10 @@ batadv_tp_init_recv(struct batadv_priv *bat_priv, } tp_vars = kmalloc_obj(*tp_vars, GFP_ATOMIC); - if (!tp_vars) + if (!tp_vars) { + atomic_dec(&bat_priv->tp_num); goto out_unlock; + } ether_addr_copy(tp_vars->other_end, icmp->orig); tp_vars->role = BATADV_TP_RECEIVER; -- 2.47.3