int called_socket_post_create; int called_socket_post_create2; int called_socket_bind; int called_socket_bind2; int called_socket_alloc; int called_socket_clone;
static __always_inline int test_local_storage(void)
{
__u64 *val;
val = bpf_get_local_storage(&cgroup_storage, 0); if (!val) return 0;
*val += 1;
return 1;
}
static __always_inline int real_create(struct socket *sock, int family, int protocol)
{ struct sock *sk; int prio = 123;
/* The rest of the sockets get default policy. */ if (bpf_setsockopt(sk, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio))) return 0; /* EPERM */
/* Make sure bpf_getsockopt is allowed and works. */
prio = 0; if (bpf_getsockopt(sk, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio))) return 0; /* EPERM */ if (prio != 123) return 0; /* EPERM */
/* Can access cgroup local storage. */ if (!test_local_storage()) return 0; /* EPERM */
return 1;
}
/* __cgroup_bpf_run_lsm_socket */
SEC("lsm_cgroup/socket_post_create") int BPF_PROG(socket_post_create, struct socket *sock, int family, int type, int protocol, int kern)
{
called_socket_post_create++; return real_create(sock, family, protocol);
}
/* __cgroup_bpf_run_lsm_socket */
SEC("lsm_cgroup/socket_post_create") int BPF_PROG(socket_post_create2, struct socket *sock, int family, int type, int protocol, int kern)
{
called_socket_post_create2++; return real_create(sock, family, protocol);
}
static __always_inline int real_bind(struct socket *sock, struct sockaddr *address, int addrlen)
{ struct sockaddr_ll sa = {}; struct sock *sk = sock->sk;
if (!sk) return 1;
if (sk->__sk_common.skc_family != AF_PACKET) return 1;
if (sk->sk_kern_sock) return 1;
bpf_probe_read_kernel(&sa, sizeof(sa), address); if (sa.sll_protocol) return 0; /* EPERM */
/* Can access cgroup local storage. */ if (!test_local_storage()) return 0; /* EPERM */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.