Skip to content

Conversation

@kernel-patches-daemon-bpf-rc
Copy link

Pull request for series with
subject: bpf: Explicitly check accesses to bpf_sock_addr
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1002970

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: f36caa7
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1002970
version: 1

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: f36caa7
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1002970
version: 1

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: f36caa7
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1002970
version: 1

Syzkaller found a kernel warning on the following sock_addr program:

    0: r0 = 0
    1: r2 = *(u32 *)(r1 +60)
    2: exit

which triggers:

    verifier bug: error during ctx access conversion (0)

This is happening because offset 60 in bpf_sock_addr corresponds to an
implicit padding of 4 bytes, right after msg_src_ip4. Access to this
padding isn't rejected in sock_addr_is_valid_access and it thus later
fails to convert the access.

This patch fixes it by explicitly checking the various fields of
bpf_sock_addr in sock_addr_is_valid_access.

I checked the other ctx structures and is_valid_access functions and
didn't find any other similar cases. Other cases of (properly handled)
padding are covered in new tests in a subsequent patch.

Fixes: 1cedee1 ("bpf: Hooks for sys_sendmsg")
Reported-by: [email protected]
Closes: https://syzkaller.appspot.com/bug?extid=136ca59d411f92e821b7
Signed-off-by: Paul Chaignon <[email protected]>
Acked-by: Eduard Zingerman <[email protected]>
@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: f36caa7
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1002970
version: 1

Move the sizeof_field and offsetofend macros from individual test files
to the common bpf_misc.h to avoid duplication.

Signed-off-by: Paul Chaignon <[email protected]>
Acked-by: Eduard Zingerman <[email protected]>
This patch adds tests covering the various paddings in ctx structures.
In case of sk_lookup BPF programs, the behavior is a bit different
because accesses to the padding are explicitly allowed. Other cases
result in a clear reject from the verifier.

Signed-off-by: Paul Chaignon <[email protected]>
Acked-by: Eduard Zingerman <[email protected]>
@kernel-patches-daemon-bpf-rc
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1002970 expired. Closing PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants