Commit 257af63d authored by Alexei Starovoitov's avatar Alexei Starovoitov Committed by Daniel Borkmann
Browse files

bpf: Fix modifier skipping logic



Fix the way modifiers are skipped while walking pointers. Otherwise second
level dereferences of 'const struct foo *' will be rejected by the verifier.

Fixes: 9e15db66 ("bpf: Implement accurate raw_tp context access via BTF")
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarYonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20200201000314.261392-1-ast@kernel.org
parent a525b088
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -3931,6 +3931,7 @@ again:

		if (btf_type_is_ptr(mtype)) {
			const struct btf_type *stype;
			u32 id;

			if (msize != size || off != moff) {
				bpf_log(log,
@@ -3939,12 +3940,9 @@ again:
				return -EACCES;
			}

			stype = btf_type_by_id(btf_vmlinux, mtype->type);
			/* skip modifiers */
			while (btf_type_is_modifier(stype))
				stype = btf_type_by_id(btf_vmlinux, stype->type);
			stype = btf_type_skip_modifiers(btf_vmlinux, mtype->type, &id);
			if (btf_type_is_struct(stype)) {
				*next_btf_id = mtype->type;
				*next_btf_id = id;
				return PTR_TO_BTF_ID;
			}
		}