-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/bpf: verify lsm_cgroup struct sock access
sk_priority & sk_mark are writable, the rest is readonly. Add new ldx_offset fixups to lookup the offset of struct field. Allow using test.kfunc regardless of prog_type. One interesting thing here is that the verifier doesn't really force me to add NULL checks anywhere :-/ Signed-off-by: Stanislav Fomichev <[email protected]>
- Loading branch information
Showing
2 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#define SK_WRITABLE_FIELD(tp, field, size, res) \ | ||
{ \ | ||
.descr = field, \ | ||
.insns = { \ | ||
/* r1 = *(u64 *)(r1 + 0) */ \ | ||
BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_1, 0), \ | ||
/* r1 = *(u64 *)(r1 + offsetof(struct socket, sk)) */ \ | ||
BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_1, 0), \ | ||
/* r2 = *(u64 *)(r1 + offsetof(struct sock, <field>)) */ \ | ||
BPF_LDX_MEM(size, BPF_REG_2, BPF_REG_1, 0), \ | ||
/* *(u64 *)(r1 + offsetof(struct sock, <field>)) = r2 */ \ | ||
BPF_STX_MEM(size, BPF_REG_1, BPF_REG_2, 0), \ | ||
BPF_MOV64_IMM(BPF_REG_0, 1), \ | ||
BPF_EXIT_INSN(), \ | ||
}, \ | ||
.result = res, \ | ||
.errstr = res ? "no write support to 'struct sock' at off" : "", \ | ||
.prog_type = BPF_PROG_TYPE_LSM, \ | ||
.expected_attach_type = BPF_LSM_CGROUP, \ | ||
.kfunc = "socket_post_create", \ | ||
.fixup_ldx = { \ | ||
{ "socket", "sk", 1 }, \ | ||
{ tp, field, 2 }, \ | ||
{ tp, field, 3 }, \ | ||
}, \ | ||
} | ||
|
||
SK_WRITABLE_FIELD("sock_common", "skc_family", BPF_H, REJECT), | ||
SK_WRITABLE_FIELD("sock", "sk_sndtimeo", BPF_DW, REJECT), | ||
SK_WRITABLE_FIELD("sock", "sk_priority", BPF_W, ACCEPT), | ||
SK_WRITABLE_FIELD("sock", "sk_mark", BPF_W, ACCEPT), | ||
SK_WRITABLE_FIELD("sock", "sk_pacing_rate", BPF_DW, REJECT), | ||
|
||
#undef SK_WRITABLE_FIELD |