Re: [PATCH bpf-next v1 1/3] x86/mm: Resolve BPF exception fixups for user address faults under SMAP
From: Dave Hansen
Date: Mon Nov 23 2026 - 10:37:10 EST
On 10/9/26 08:23, Kumar Kartikeya Dwivedi wrote:
> SEC("fentry/tcp_retransmit_skb") <- attaches to the entry of tcp_retransmit_skb()
> int BPF_PROG(retrans, struct sock *sk)
> {
> struct file *f = sk->sk_socket->file;
>
> This program was written for doing a TCP related investigation. The first load
> of sk is fine, but sk_socket can be NULL (orphaned socket) or stale, so the
> second load becomes a mov with an extable entry. Below is the JITed sequence.
In every other part of the kernel, dereferencing a NULL pointer would be
called a bug. Isn't this just plain buggy code?
I assume the BPF program wants to tolerate these situations because it
can't fully participate in the synchronization mechanisms that the data
structure actually needs. So, it makes what (in the normal kernel) is a
buggy access.
The rest of the story is trying to fix that up.
But I don't quite know how this can be done "safely" in a way that the
fixups end up with good data or NULL. If SMAP isn't in play, can't this
just go reading garbage from userspace?
Also, can you talk a bit about the code generation on the BPF side here?
Are the instructions covered by the exception table handler all pure MOV's?