mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: MahnurA <s.mahnur.a@gmail.com>
To: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>, Song Liu <song@kernel.org>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Syeda Mahnur Asif <s.mahnur.a@gmail.com>
Subject: [BUG] KASAN: slab-use-after-free in bpf_skc_to_* via fexit on sk_common_release
Date: Mon, 30 Nov 2026 16:12:12 +0100	[thread overview]
Message-ID: <20261130151212.504961-1-s.mahnur.a@gmail.com> (raw)

From: Syeda Mahnur Asif <s.mahnur.a@gmail.com>

Hi,

While running an fexit BPF program on sk_common_release() that calls
bpf_skc_to_tcp_sock(), my fuzzer hit a KASAN slab-use-after-free during network
namespace teardown.

Reproduced on Kernel: Kernel: 7.4.0-rc4 
(built from the mainline v7.4-rc4 tarball)

sk_common_release() drops the last reference to sk and frees it. The fexit
program then runs on the freed pointer and bpf_skc_to_* helpers read
sk->sk_state, tripping KASAN. The IGMP control socket created in
igmp_net_init() has no other holders, so the free happens inside the traced
function and netns teardown reproduces it reliably.

Reproducer: 

BPF program: Any bpf_skc_to_* helper taking the sk from the context as the argument

Trigger: C program (any short-lived network namespace should trigger it)

#define _GNU_SOURCE
#include <sched.h>
#include <unistd.h>

int main(void)
{
    unshare(CLONE_NEWNET);
    return 0;               
}

KASAN splat below. I can test patches. 


[ 1983.388616] BUG: KASAN: slab-use-after-free in bpf_skc_to_tcp_sock (./include/net/sock.h:2295 net/core/filter.c:12345 net/core/filter.c:12343)
[ 1983.388631] Read of size 1 at addr ffff888102f48912 by task kworker/u4:0/13
[ 1983.388637]
[ 1983.388643] CPU: 0 UID: 0 PID: 13 Comm: kworker/u4:0 Not tainted 7.4.0-rc4 #2 PREEMPT(full)
[ 1983.388652] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
[ 1983.388658] Workqueue: netns cleanup_net
[ 1983.388671] Call Trace:
[ 1983.388673]  <TASK>
[ 1983.388678]  dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120)
[ 1983.388687]  print_report (mm/kasan/report.c:378 mm/kasan/report.c:482)
[ 1983.388714]  kasan_report (mm/kasan/report.c:595)
[ 1983.388766]  bpf_skc_to_tcp_sock (./include/net/sock.h:2295 net/core/filter.c:12345 net/core/filter.c:12343)
[ 1983.388773]  bpf_prog_76aaea67dcf4f15b_bpf_prog4321+0x3b/0x3f
[ 1983.388786]  bpf_trampoline_6442594000+0x64/0xd3
[ 1983.388792]  ? ip_mc_drop_socket (net/ipv4/igmp.c:2898)
[ 1983.388803]  udp_lib_close (./include/net/udp.h:322)
[ 1983.388814]  inet_release (net/ipv4/af_inet.c:443)
[ 1983.388824]  sock_release (net/socket.c:735 net/socket.c:763)
[ 1983.388843]  igmp_net_exit (./include/net/inet_common.h:72 net/ipv4/igmp.c:3245)
[ 1983.388851]  ops_undo_list (net/core/net_namespace.c:200 net/core/net_namespace.c:253)
[ 1983.388885]  cleanup_net (net/core/net_namespace.c:713)
[ 1983.388916]  process_one_work (kernel/workqueue.c:3495)
[ 1983.388955]  worker_thread (kernel/workqueue.c:3578 kernel/workqueue.c:3659)
[ 1983.388973]  kthread (kernel/kthread.c:436)
[ 1983.388992]  ret_from_fork (arch/x86/kernel/process.c:158)
[ 1983.389024]  ret_from_fork_asm (arch/x86/entry/entry_64.S:245)
[ 1983.389042]  </TASK>
[ 1983.389045]
[ 1983.389048] Allocated by task 88:
[ 1983.389052]  kasan_save_stack (mm/kasan/common.c:57)
[ 1983.389062]  kasan_save_track (mm/kasan/common.c:79)
[ 1983.389069]  kasan_save_alloc_info (mm/kasan/generic.c:585)
[ 1983.389076]  __kasan_slab_alloc (mm/kasan/common.c:354 mm/kasan/common.c:380)
[ 1983.389084]  kmem_cache_alloc_noprof (./include/linux/kasan.h:257 mm/slub.c:4720 mm/slub.c:5033 mm/slub.c:5047)
[ 1983.389092]  sk_prot_alloc (net/core/sock.c:2275 (discriminator 2))
[ 1983.389101]  sk_alloc (net/core/sock.c:2337)
[ 1983.389107]  inet_create (net/ipv4/af_inet.c:334 net/ipv4/af_inet.c:260)
[ 1983.389113]  __sock_create (net/socket.c:1679)
[ 1983.389120]  sock_create_kern (net/socket.c:1755)
[ 1983.389128]  inet_ctl_sock_create (net/ipv4/af_inet.c:1642)
[ 1983.389135]  igmp_net_init (net/ipv4/igmp.c:3223)
[ 1983.389143]  ops_init (net/core/net_namespace.c:137)
[ 1983.389149]  setup_net (net/core/net_namespace.c:448)
[ 1983.389164]  copy_net_ns (net/core/net_namespace.c:589)
[ 1983.389171]  create_new_namespaces (kernel/nsproxy.c:132)
[ 1983.389182]  unshare_nsproxy_namespaces (kernel/nsproxy.c:234 (discriminator 4))
[ 1983.389190]  ksys_unshare (kernel/fork.c:3306)
[ 1983.389190]  __x64_sys_unshare (kernel/fork.c:3372 kernel/fork.c:3370 kernel/fork.c:3370)
[ 1983.389190]  x64_sys_call (./arch/x86/include/generated/asm/syscalls_64.h:273)
[ 1983.389190]  do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:89)
[ 1983.389190]  entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
[ 1983.389190]
[ 1983.389190] The buggy address belongs to the object at ffff888102f48900
[ 1983.389190]  which belongs to the cache UDP of size 1984
[ 1983.389190] The buggy address is located 18 bytes inside of
[ 1983.389190]  freed 1984-byte region [ffff888102f48900, ffff888102f490c0)
[ 1983.389190]
[ 1983.389190] The buggy address belongs to the physical page:
[ 1983.389190] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888102f491c0 pfn:0x102f48
[ 1983.389190] head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
[ 1983.389190] flags: 0x200000000000240(workingset|head|node=0|zone=2)
[ 1983.389190] page_type: f5(slab)
[ 1983.389190] raw: 0200000000000240 ffff888102d29040 ffff888102d28308 ffff888102d28308
[ 1983.389190] raw: ffff888102f491c0 00000002000e0002 00000000f5000000 0000000000000000
[ 1983.389190] head: 0200000000000240 ffff888102d29040 ffff888102d28308 ffff888102d28308
[ 1983.389190] head: ffff888102f491c0 00000002000e0002 00000000f5000000 0000000000000000
[ 1983.389190] head: 0200000000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff
[ 1983.389190] head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000008
[ 1983.389190] page dumped because: kasan: bad access detected
[ 1983.389190]
[ 1983.389190] Memory state around the buggy address:
[ 1983.389190]  ffff888102f48800: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[ 1983.389190]  ffff888102f48880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[ 1983.389190] >ffff888102f48900: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 1983.389190]                          ^
[ 1983.389190]  ffff888102f48980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 1983.389190]  ffff888102f48a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 1983.389190] ==================================================================

                 reply	other threads:[~2026-11-30 15:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130151212.504961-1-s.mahnur.a@gmail.com \
    --to=s.mahnur.a@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®