Skip to content

Commit 4c84187

Browse files
keesKernel Patches Daemon
authored andcommitted
bpf: Convert bpf_sock_addr_kern "uaddr" to sockaddr_unspec
Change struct bpf_sock_addr_kern to use sockaddr_unspec for the "uaddr" field instead of sockaddr. This improves type safety in the BPF cgroup socket address filtering code. The casting in __cgroup_bpf_run_filter_sock_addr() is updated to match the new type, removing an unnecessary cast in the initialization and updating the conditional assignment to use the appropriate sockaddr_unspec cast. Signed-off-by: Kees Cook <[email protected]>
1 parent 27b0c9f commit 4c84187

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

include/linux/filter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,7 @@ static inline int bpf_tell_extensions(void)
15151515

15161516
struct bpf_sock_addr_kern {
15171517
struct sock *sk;
1518-
struct sockaddr *uaddr;
1518+
struct sockaddr_unspec *uaddr;
15191519
/* Temporary "register" to make indirect stores to nested structures
15201520
* defined above. We need three registers to make such a store, but
15211521
* only two (src and dst) are available at convert_ctx_access time

kernel/bpf/cgroup.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,10 +1673,10 @@ int __cgroup_bpf_run_filter_sock_addr(struct sock *sk,
16731673
{
16741674
struct bpf_sock_addr_kern ctx = {
16751675
.sk = sk,
1676-
.uaddr = (struct sockaddr *)uaddr,
1676+
.uaddr = uaddr,
16771677
.t_ctx = t_ctx,
16781678
};
1679-
struct sockaddr_storage unspec;
1679+
struct sockaddr_storage storage;
16801680
struct cgroup *cgrp;
16811681
int ret;
16821682

@@ -1688,8 +1688,8 @@ int __cgroup_bpf_run_filter_sock_addr(struct sock *sk,
16881688
return 0;
16891689

16901690
if (!ctx.uaddr) {
1691-
memset(&unspec, 0, sizeof(unspec));
1692-
ctx.uaddr = (struct sockaddr *)&unspec;
1691+
memset(&storage, 0, sizeof(storage));
1692+
ctx.uaddr = (struct sockaddr_unspec *)&storage;
16931693
ctx.uaddrlen = 0;
16941694
} else {
16951695
ctx.uaddrlen = *uaddrlen;

0 commit comments

Comments
 (0)