bpf: skmsg, replace comments with BUILD bug
authorJohn Fastabend <john.fastabend@gmail.com>
Thu, 20 Dec 2018 19:35:31 +0000 (11:35 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 20 Dec 2018 22:47:09 +0000 (23:47 +0100)
Enforce comment on structure layout dependency with a BUILD_BUG_ON
to ensure the condition is maintained.

Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
include/linux/skmsg.h
net/core/filter.c

index eb8f6cb84c10be11118cc7238065bb35e8895df7..dd57e6f408b180ee7a851041dc919d524f8ed64c 100644 (file)
@@ -36,9 +36,7 @@ struct sk_msg_sg {
        struct scatterlist              data[MAX_MSG_FRAGS + 1];
 };
 
-/* UAPI in filter.c depends on struct sk_msg_sg being first element. If
- * this is moved filter.c also must be updated.
- */
+/* UAPI in filter.c depends on struct sk_msg_sg being first element. */
 struct sk_msg {
        struct sk_msg_sg                sg;
        void                            *data;
index 6bd9f08f6162fcf7d1e039eefbc664f116856001..447dd1bad31fa953e222304e60af5519b2621798 100644 (file)
@@ -7425,6 +7425,9 @@ static u32 sk_msg_convert_ctx_access(enum bpf_access_type type,
        int off;
 #endif
 
+       /* convert ctx uses the fact sg element is first in struct */
+       BUILD_BUG_ON(offsetof(struct sk_msg, sg) != 0);
+
        switch (si->off) {
        case offsetof(struct sk_msg_md, data):
                *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_msg, data),