From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3D3C53446BE; Tue, 16 Dec 2025 12:19:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765887583; cv=none; b=MEekE8NEYL7/iiPWoPGHgqtkPZ+6azN1PJ4PMuTQveCganB2qyDwBCkHJK8g3PyTMX3lHw5KVHz3RX3IArN9jB2JBHvA1Va3T/A+eAwm60Pl0V+ZPh4M9RD04XwOWLaD3DWOpQF6WcqP1eD82X4Df+zDBdLwGPZRkF0elPGu8M4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765887583; c=relaxed/simple; bh=gbqYZV8HSYrDrWeCW9fZxtAJttOQU/dx1/S6G3wllAg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cNSPV+YdcvTO/VjgUjBrWyDSj4LYdSfyMWm68PtCy5+x2PcsRTggcYp7TqAFjAca5PHCf51xuJgNH6k8Pw4VXQmeGf2i3FNTNjVA0Z/pHk/7lSf3qy8YJKNj2JbpyWo9vbdxZySe10+D0NVkKbX8KWSxSMBPcdGvsJc1R38mHtg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1Lop231F; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1Lop231F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C75AC4CEF1; Tue, 16 Dec 2025 12:19:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1765887582; bh=gbqYZV8HSYrDrWeCW9fZxtAJttOQU/dx1/S6G3wllAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Lop231FgEet6UCEP2vLwTuoMWsyvGuJGCeptbh9/vSN96hxOWIfEWBlPQsAT1XoN ndhO8YnGfoCaARNMhyYQ0zgnmBWhaO6BYIXTQFtAYdX1o7dyc7zIU3/ICI+ywWYf+n TIHioiV7iMhnSY8tvcD4rgBGCxxFNL+EtHE806Nw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Leon Hwang , Yonghong Song , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.18 273/614] bpf: Free special fields when update [lru_,]percpu_hash maps Date: Tue, 16 Dec 2025 12:10:40 +0100 Message-ID: <20251216111411.266721671@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251216111401.280873349@linuxfoundation.org> References: <20251216111401.280873349@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Leon Hwang [ Upstream commit 6af6e49a76c9af7d42eb923703e7648cb2bf401a ] As [lru_,]percpu_hash maps support BPF_KPTR_{REF,PERCPU}, missing calls to 'bpf_obj_free_fields()' in 'pcpu_copy_value()' could cause the memory referenced by BPF_KPTR_{REF,PERCPU} fields to be held until the map gets freed. Fix this by calling 'bpf_obj_free_fields()' after 'copy_map_value[,_long]()' in 'pcpu_copy_value()'. Fixes: 65334e64a493 ("bpf: Support kptrs in percpu hashmap and percpu LRU hashmap") Signed-off-by: Leon Hwang Acked-by: Yonghong Song Link: https://lore.kernel.org/r/20251105151407.12723-2-leon.hwang@linux.dev Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/hashtab.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index c2fcd0cd51e51..e7721f0776c72 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -947,15 +947,21 @@ static void free_htab_elem(struct bpf_htab *htab, struct htab_elem *l) static void pcpu_copy_value(struct bpf_htab *htab, void __percpu *pptr, void *value, bool onallcpus) { + void *ptr; + if (!onallcpus) { /* copy true value_size bytes */ - copy_map_value(&htab->map, this_cpu_ptr(pptr), value); + ptr = this_cpu_ptr(pptr); + copy_map_value(&htab->map, ptr, value); + bpf_obj_free_fields(htab->map.record, ptr); } else { u32 size = round_up(htab->map.value_size, 8); int off = 0, cpu; for_each_possible_cpu(cpu) { - copy_map_value_long(&htab->map, per_cpu_ptr(pptr, cpu), value + off); + ptr = per_cpu_ptr(pptr, cpu); + copy_map_value_long(&htab->map, ptr, value + off); + bpf_obj_free_fields(htab->map.record, ptr); off += size; } } -- 2.51.0