From: John Fastabend Subject: [PATCH bpf-next 3/8] bpf: skmsg, replace comments with BUILD bug Date: Thu, 20 Dec 2018 11:35:31 -0800 Message-ID: <1545334536-766-4-git-send-email-john.fastabend@gmail.com> References: <1545334536-766-1-git-send-email-john.fastabend@gmail.com> Cc: netdev@vger.kernel.org, john.fastabend@gmail.com To: ast@kernel.org, daniel@iogearbox.net Return-path: Received: from mail-io1-f67.google.com ([209.85.166.67]:46469 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725785AbeLTTgE (ORCPT ); Thu, 20 Dec 2018 14:36:04 -0500 Received: by mail-io1-f67.google.com with SMTP id v10so1737710ios.13 for ; Thu, 20 Dec 2018 11:36:03 -0800 (PST) In-Reply-To: <1545334536-766-1-git-send-email-john.fastabend@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: Enforce comment on structure layout dependency with a BUILD_BUG_ON to ensure the condition is maintained. Suggested-by: Daniel Borkmann Signed-off-by: John Fastabend --- include/linux/skmsg.h | 4 +--- net/core/filter.c | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/linux/skmsg.h b/include/linux/skmsg.h index eb8f6cb..dd57e6f4 100644 --- a/include/linux/skmsg.h +++ b/include/linux/skmsg.h @@ -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; diff --git a/net/core/filter.c b/net/core/filter.c index 6bd9f08..447dd1b 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -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), -- 2.7.4