From nobody Sat Feb 7 21:14:58 2026 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (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 1F7722D12EC for ; Sun, 26 Oct 2025 15:40:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761493251; cv=none; b=VOWKSgxvlqkuxmdqQTtl25jWvDVEKMbkuMwqJffT7AvT2vlqFUNDRN9Al4myE35TDi4P4T1XX0i0/aQAlPNuY3ddyn9P0Lr6xlXmLowM/rTRN0pmL3SsD/qoi21XKUmJsT4YUykgDuW43a9XBuwVJ4PpHflQTEdBruHn9DMJ2Gs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761493251; c=relaxed/simple; bh=gaTmvfHNFqge4dQ7wx+Ukv4Yxs/3l/QORPaBttPJ8Jo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XB8jy+0t/4Qss1T4Wx5IvQdTm9VfzNAW0SuuezsjzPBZaFKjP0etnLHNSYk55FFYO+IB+kWhrcsGXyTyee2dFh05LJtPQrZe5i1seXje3mqukNLaWP8wce8st6+jo4/yjo2JvlZutBY8OvJ2nCOQBaP0ofECN1g4i7mNNOfBG3M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=aXPAr817; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="aXPAr817" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1761493247; 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=ElRnlDcK8q21WZxBfi9bb0x6nOn4UNgvLQNmGbaQ58Q=; b=aXPAr817+KtXmB1j1jeq1VWjgf8ZRwo5QVlReVpTd1uETw2pD7ZZ406AdYo/97fuz6zVtz EeZlUuuHI+uXDNjPEvr39fU0EWjjmvjAJsFkCiwApsxl0deG14lzY94eCGfDXQGXp8eBOh M+bpAE7iL60/4XaJYUvs8WLDR1gQFqo= From: Leon Hwang To: bpf@vger.kernel.org Cc: ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, linux-kernel@vger.kernel.org, kernel-patches-bot@fb.com, Leon Hwang Subject: [PATCH bpf v3 2/4] bpf: Free special fields when update hash maps with BPF_F_LOCK Date: Sun, 26 Oct 2025 23:39:58 +0800 Message-ID: <20251026154000.34151-3-leon.hwang@linux.dev> In-Reply-To: <20251026154000.34151-1-leon.hwang@linux.dev> References: <20251026154000.34151-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" When updating hash maps with BPF_F_LOCK, the special fields were not freed after being replaced. This could cause memory referenced by BPF_KPTR_{REF,PERCPU} fields to be held until the map gets freed. Fix this by calling 'check_and_free_fields()' after 'copy_map_value_locked()' to properly release the old fields. Fixes: 14a324f6a67e ("bpf: Wire up freeing of referenced kptr") Signed-off-by: Leon Hwang --- kernel/bpf/hashtab.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 26308adc9ccb3..65009ea3e9379 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -1124,6 +1124,7 @@ static long htab_map_update_elem(struct bpf_map *map,= void *key, void *value, copy_map_value_locked(map, htab_elem_value(l_old, key_size), value, false); + check_and_free_fields(htab, l_old); return 0; } /* fall through, grab the bucket lock and lookup again. @@ -1152,6 +1153,7 @@ static long htab_map_update_elem(struct bpf_map *map,= void *key, void *value, copy_map_value_locked(map, htab_elem_value(l_old, key_size), value, false); + check_and_free_fields(htab, l_old); ret =3D 0; goto err; } --=20 2.51.0