bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yoshiki Komachi <komachi.yoshiki@gmail.com>
To: "David S. Miller" <davem@davemloft.net>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>, Andrii Nakryiko <andriin@fb.com>
Cc: Yoshiki Komachi <komachi.yoshiki@gmail.com>,
	netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: [PATCH bpf 1/2] bpf/btf: Fix BTF verification of enum members in struct/union
Date: Tue, 10 Mar 2020 16:32:29 +0900	[thread overview]
Message-ID: <1583825550-18606-2-git-send-email-komachi.yoshiki@gmail.com> (raw)
In-Reply-To: <1583825550-18606-1-git-send-email-komachi.yoshiki@gmail.com>

btf_enum_check_member() was currently sure to recognize the size of
"enum" type members in struct/union as the size of "int" even if
its size was packed.

This patch fixes BTF enum verification to use the correct size
of member in BPF programs.

Fixes: 179cde8cef7e ("bpf: btf: Check members of struct/union")
Signed-off-by: Yoshiki Komachi <komachi.yoshiki@gmail.com>
---
 kernel/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 7871400..32ab922 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -2418,7 +2418,7 @@ static int btf_enum_check_member(struct btf_verifier_env *env,
 
 	struct_size = struct_type->size;
 	bytes_offset = BITS_ROUNDDOWN_BYTES(struct_bits_off);
-	if (struct_size - bytes_offset < sizeof(int)) {
+	if (struct_size - bytes_offset < member_type->size) {
 		btf_verifier_log_member(env, struct_type, member,
 					"Member exceeds struct_size");
 		return -EINVAL;
-- 
1.8.3.1


  reply	other threads:[~2020-03-10  7:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-10  7:32 [PATCH v2 bpf 0/2] Fix BTF verification of enum members with a selftest Yoshiki Komachi
2020-03-10  7:32 ` Yoshiki Komachi [this message]
2020-03-10  7:32 ` [PATCH bpf 2/2] selftests/bpf: Add test for the packed enum member in struct/union Yoshiki Komachi
2020-03-10 15:39 ` [PATCH v2 bpf 0/2] Fix BTF verification of enum members with a selftest Andrii Nakryiko
2020-03-10 16:46 ` Martin KaFai Lau
2020-03-10 17:26   ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1583825550-18606-2-git-send-email-komachi.yoshiki@gmail.com \
    --to=komachi.yoshiki@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=kafai@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).