github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/sys/linux/test/bpf_cgroup (about)

     1  # First, write to an entry of /proc/sys. It should work fine.
     2  
     3  r0 = openat$tcp_congestion(AUTO, &AUTO='/proc/sys/net/ipv4/tcp_congestion_control', AUTO, AUTO)
     4  
     5  r1 = write$tcp_congestion(r0, &AUTO='reno\x00', AUTO)
     6  
     7  # Now, load a BPF_PROG_TYPE_CGROUP_SYSCTL that simply returns 0, which will block all writes to /proc/sys
     8  
     9  r2 = bpf$PROG_LOAD(AUTO, &AUTO={0x17, AUTO, &AUTO=@framed={{AUTO, AUTO, AUTO, AUTO, 0x0, AUTO, AUTO, AUTO, 0x0}, [], AUTO}, &AUTO='GPL\x00', 0x0, 0x0, 0x0, 0x0, 0x0, "00000000000000000000000000000000", 0x0, 0x12, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 0xa0)
    10  
    11  r3 = openat(0xffffffffffffff9c, &AUTO='./cgroup\x00', 0x0, 0x0)
    12  
    13  r4 = bpf$BPF_PROG_ATTACH(AUTO, &AUTO={@cgroup=r3, r2, 0x12, 0x0, 0x0, @prog_id=0x0, 0x0}, AUTO)
    14  
    15  # It should fail now.
    16  
    17  r5 = write$tcp_congestion(r0, &AUTO='reno\x00', AUTO) # EPERM
    18  
    19  # Detach the BPF program.
    20  
    21  r6 = bpf$BPF_PROG_DETACH(AUTO, &AUTO={@cgroup=r3, r2, 0x12, 0x0, 0x0, @prog_id=0x0, 0x0}, AUTO)
    22  
    23  # It should work again.
    24  
    25  r7 = write$tcp_congestion(r0, &AUTO='reno\x00', AUTO)