From nobody Mon Jun 8 06:36:39 2026 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03BC82ECEB9 for ; Sat, 6 Jun 2026 09:19:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780737599; cv=none; b=dY2vsBxZ3Up9rsoUsBezsG2nTHZCavvJ2/AGAoBQAFx+Hh5nFXMhjgWjYtgdOzy0ecte0B6dzI9d3atwcMAei+/TFjijEa7CH2kLlMRw+PkHMk7o9nsNhuUEB3TXKupiceutXqB0CTffrPhwOPePX/TsgawJvyv++Qg8VU9iWAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780737599; c=relaxed/simple; bh=jRlVNt33dcmY+Gqh8IAK/Cp9Kzl0Ro5FZJQSIpzuERA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kw0QPqOYd7SwnRqPlRrZKbak7c/1n9pzAY47XmCyJtz+CjuffI1iSmatPc0V1DeNa4j7OJSIms6eGMHhfodeeB0uNs/U8AXi1aGArPT888nxgbVVGP7IzzV1kAjF6soUcLLwtYxa9b+EqFJhvVO4ydu/hUGJcg9vHMC5FSFUOIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lbQTgX5p; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lbQTgX5p" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-8422524cb38so909351b3a.0 for ; Sat, 06 Jun 2026 02:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780737596; x=1781342396; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=C8Z2dEedFACMstCQHDyAELUklZOwhGF6wngz7Y8OzOo=; b=lbQTgX5pA3SBIOoFew67y43tFwHHBOvqrSFuyQCpOPS/+nJMnhlqHMxXNPkd1HxzqM ghXA2LvpBju1UC8FkpCF8pC+FoCunfJ8VCsOQvdkvnc6xQJmQeOzMLQ3o5FOShLffta2 jzUvqRF2SV9b/+nz/sfiBj59Jqrxk1x508jFTfr19bpQuRdUA3dEFYA9GB8cXbxKBFGf GUpAXBojDexfFgfDNdw6jYP6nqb5WS2PnT4VroXeczBsgIyrgnyTDRurn8UY8vUbQdMb 4J9otEO7I8YvIDpgcvnRfSpkoiKkPbIcFcRPubtyYYIzUsYc7brxMfTm4oQVRUoSfMHx d9dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780737596; x=1781342396; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=C8Z2dEedFACMstCQHDyAELUklZOwhGF6wngz7Y8OzOo=; b=WIzDqkz1rfl5X6XDvR5BunNlApBb3ehhef09JI/B4TnGDqlUn/cbS5X3uH/y1zgNXr /+ZthpTMHzfr16146D1eVGSMoaXX5c7gTnCH2E52hupMpbNxGkI/x5MtWnbK5a7p/POJ uCywFibg6QoNth2ASIU3ZEFP8vbz+4paNF6CwAB/dX6QCplqEeIArYBQ08Ximw6ohwlC sjM4zfpx+JpnomGxqaab+Hva88VnB5VvFqLDEagZE0mt05SOBQV4OL0DTzCS3GxD8vye hQf9gh7FSuoaHjyM+WQPrYTIAnW0JnlqgZs2gmQdzV+PcpS4n0bgpsMvLGK7rDy00aj0 Bdxg== X-Forwarded-Encrypted: i=1; AFNElJ+9AjCEp8Y2+reWE4TvbeEjEkVvcRw0Iy4ff8F6rTN9/vx/q2rH9AN8OwlqtgmqA/p+dUZ6mBRQERJ/iLM=@vger.kernel.org X-Gm-Message-State: AOJu0YxbektM4ei5DAG6v8EVgWeWqbGD2GMCBs3qvuu9OKVK4cMIvqJP CbG+4kiUuvpXCtzAe3z8jrfQ4TxIb6prpZLkID0htAfCX07ug36FIy38 X-Gm-Gg: Acq92OFAlfFGXBzALNAKZJcCcTLknMCyKw8WNyTKbc6eIGQIt9xcf+aIgau9L04rDpc QCUEvKIS4Y5YJqDpN8nlWBi1HbHI3JYzGreJTnVYnzDXqBX36n4+961p8rFs3rq92TS5Mhp85Eh Ojpvdj/ZQIxIr5XyErLZs8GpOrReORdco/AshdwbFMUR1fTeMffy6IwqZ++ASPBAQWtZxRMQaUa y8UvgPvZs7YW5LiEpCWDpsro3KfNFqAbGURi1Qw6jbT3k/axxp7g/IfO30YShdI9bft/jBivtbl 2DHhvhwmEnZqH5Bbgqm1dpYfCB4PxeZrbnS/BLHhQwTl8Fd+hkkOavM3F5AYNwD+nICeXfxirJv 1SnVPnmhlzXIYKQ8Svd19ayh3y3u61NIGBM0gmu9zF+x3XNMydie1N46KDyQCNI9AuatcIr4LHA PPoLaD4fbWLHymJoaJnSO7aZPguoChIID+5924tCo3j18OR2gYSLcwrfput9ZOTzZK3wQB0m6T X-Received: by 2002:a05:6a00:23ca:b0:842:5b63:6119 with SMTP id d2e1a72fcca58-842b0e2f430mr7485422b3a.1.1780737596208; Sat, 06 Jun 2026 02:19:56 -0700 (PDT) Received: from cps-manycore-1.. ([147.46.174.222]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8428291ed20sm14585734b3a.61.2026.06.06.02.19.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jun 2026 02:19:55 -0700 (PDT) From: Sechang Lim To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi Cc: Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Juntong Deng , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf v3] bpf: fix NULL pointer dereference in bpf_task_from_vpid() Date: Sat, 6 Jun 2026 09:19:27 +0000 Message-ID: <20260606091941.1803115-1-rhkrqnwk98@gmail.com> X-Mailer: git-send-email 2.43.0 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 Content-Type: text/plain; charset="utf-8" bpf_task_from_vpid() looks up a task in the pid namespace of the current task, via find_task_by_vpid(): find_task_by_vpid(vpid) find_task_by_pid_ns(vpid, task_active_pid_ns(current)) find_pid_ns(nr, ns) -> idr_find(&ns->idr, nr) cgroup_skb programs run in softirq, which may interrupt a task that is itself in do_exit(). Once that task has passed exit_notify() -> release_task() -> __unhash_process(), its thread_pid is cleared, so task_active_pid_ns(current) returns NULL and find_pid_ns() dereferences &NULL->idr: BUG: kernel NULL pointer dereference, address: 0000000000000050 RIP: 0010:idr_find+0x11/0x30 lib/idr.c:176 Call Trace: find_pid_ns kernel/pid.c:370 [inline] find_task_by_pid_ns+0x3b/0xe0 kernel/pid.c:485 bpf_task_from_vpid+0x5b/0x200 kernel/bpf/helpers.c:2916 bpf_prog_run_array_cg+0x17e/0x530 kernel/bpf/cgroup.c:81 __cgroup_bpf_run_filter_skb+0x12b/0x250 kernel/bpf/cgroup.c:1612 sk_filter_trim_cap+0x1dc/0x4c0 net/core/filter.c:148 tcp_v4_rcv+0x18d1/0x2200 net/ipv4/tcp_ipv4.c:2223 do_exit+0xa63/0x1270 kernel/exit.c:1010 get_signal+0x141c/0x1530 kernel/signal.c:3037 Return NULL when bpf_task_from_vpid() runs in interrupt context, or when current has no pid namespace. Acked-by: Yonghong Song Fixes: 675c3596ff32 ("bpf: Add bpf_task_from_vpid() kfunc") Signed-off-by: Sechang Lim --- v3: - Also handle current with no pid namespace=20 v2: - Reject calls from interrupt context (Yonghong Song) - https://lore.kernel.org/bpf/20260605200501.1619406-1-rhkrqnwk98@gmail.co= m/ v1: - https://lore.kernel.org/bpf/20260603204206.773482-1-rhkrqnwk98@gmail.com/ kernel/bpf/helpers.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index b5314c9fed3c..226c31ccb5d6 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -2912,7 +2912,14 @@ __bpf_kfunc struct task_struct *bpf_task_from_vpid(s= 32 vpid) { struct task_struct *p; =20 + if (in_interrupt()) + return NULL; + rcu_read_lock(); + if (!task_active_pid_ns(current)) { + rcu_read_unlock(); + return NULL; + } p =3D find_task_by_vpid(vpid); if (p) p =3D bpf_task_acquire(p); --=20 2.43.0