Skip to content

Commit 1c123c5

Browse files
tohojoMartin KaFai Lau
authored and
Martin KaFai Lau
committed
bpf: Resolve fext program type when checking map compatibility
The bpf_prog_map_compatible() check makes sure that BPF program types are not mixed inside BPF map types that can contain programs (tail call maps, cpumaps and devmaps). It does this by setting the fields of the map->owner struct to the values of the first program being checked against, and rejecting any subsequent programs if the values don't match. One of the values being set in the map owner struct is the program type, and since the code did not resolve the prog type for fext programs, the map owner type would be set to PROG_TYPE_EXT and subsequent loading of programs of the target type into the map would fail. This bug is seen in particular for XDP programs that are loaded as PROG_TYPE_EXT using libxdp; these cannot insert programs into devmaps and cpumaps because the check fails as described above. Fix the bug by resolving the fext program type to its target program type as elsewhere in the verifier. v3: - Add Yonghong's ACK Fixes: f45d5b6 ("bpf: generalise tail call map compatibility check") Acked-by: Yonghong Song <[email protected]> Signed-off-by: Toke Høiland-Jørgensen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent 4121d44 commit 1c123c5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kernel/bpf/core.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,7 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx,
20922092
bool bpf_prog_map_compatible(struct bpf_map *map,
20932093
const struct bpf_prog *fp)
20942094
{
2095+
enum bpf_prog_type prog_type = resolve_prog_type(fp);
20952096
bool ret;
20962097

20972098
if (fp->kprobe_override)
@@ -2102,12 +2103,12 @@ bool bpf_prog_map_compatible(struct bpf_map *map,
21022103
/* There's no owner yet where we could check for
21032104
* compatibility.
21042105
*/
2105-
map->owner.type = fp->type;
2106+
map->owner.type = prog_type;
21062107
map->owner.jited = fp->jited;
21072108
map->owner.xdp_has_frags = fp->aux->xdp_has_frags;
21082109
ret = true;
21092110
} else {
2110-
ret = map->owner.type == fp->type &&
2111+
ret = map->owner.type == prog_type &&
21112112
map->owner.jited == fp->jited &&
21122113
map->owner.xdp_has_frags == fp->aux->xdp_has_frags;
21132114
}

0 commit comments

Comments
 (0)