Skip to content

Commit 8aad74c

Browse files
LorenzoBianconiKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
bpf: Allow XDP dev-bound programs to perform XDP_REDIRECT into maps
In the current implementation if the program is dev-bound to a specific device, it will not be possible to perform XDP_REDIRECT into a DEVMAP or CPUMAP even if the program is running in the driver NAPI context and it is not attached to any map entry. This seems in contrast with the explanation available in bpf_prog_map_compatible routine. Fix the issue introducing __bpf_prog_map_compatible utility routine in order to avoid bpf_prog_is_dev_bound() check running bpf_check_tail_call() at program load time (bpf_prog_select_runtime()). Continue forbidding to attach a dev-bound program to XDP maps (BPF_MAP_TYPE_PROG_ARRAY, BPF_MAP_TYPE_DEVMAP and BPF_MAP_TYPE_CPUMAP). Fixes: 3d76a4d ("bpf: XDP metadata RX kfuncs") Acked-by: Stanislav Fomichev <[email protected]> Signed-off-by: Lorenzo Bianconi <[email protected]>
1 parent a041a61 commit 8aad74c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

kernel/bpf/core.c

+16-11
Original file line numberDiff line numberDiff line change
@@ -2358,8 +2358,8 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx,
23582358
return 0;
23592359
}
23602360

2361-
bool bpf_prog_map_compatible(struct bpf_map *map,
2362-
const struct bpf_prog *fp)
2361+
static bool __bpf_prog_map_compatible(struct bpf_map *map,
2362+
const struct bpf_prog *fp)
23632363
{
23642364
enum bpf_prog_type prog_type = resolve_prog_type(fp);
23652365
bool ret;
@@ -2368,14 +2368,6 @@ bool bpf_prog_map_compatible(struct bpf_map *map,
23682368
if (fp->kprobe_override)
23692369
return false;
23702370

2371-
/* XDP programs inserted into maps are not guaranteed to run on
2372-
* a particular netdev (and can run outside driver context entirely
2373-
* in the case of devmap and cpumap). Until device checks
2374-
* are implemented, prohibit adding dev-bound programs to program maps.
2375-
*/
2376-
if (bpf_prog_is_dev_bound(aux))
2377-
return false;
2378-
23792371
spin_lock(&map->owner.lock);
23802372
if (!map->owner.type) {
23812373
/* There's no owner yet where we could check for
@@ -2409,6 +2401,19 @@ bool bpf_prog_map_compatible(struct bpf_map *map,
24092401
return ret;
24102402
}
24112403

2404+
bool bpf_prog_map_compatible(struct bpf_map *map, const struct bpf_prog *fp)
2405+
{
2406+
/* XDP programs inserted into maps are not guaranteed to run on
2407+
* a particular netdev (and can run outside driver context entirely
2408+
* in the case of devmap and cpumap). Until device checks
2409+
* are implemented, prohibit adding dev-bound programs to program maps.
2410+
*/
2411+
if (bpf_prog_is_dev_bound(fp->aux))
2412+
return false;
2413+
2414+
return __bpf_prog_map_compatible(map, fp);
2415+
}
2416+
24122417
static int bpf_check_tail_call(const struct bpf_prog *fp)
24132418
{
24142419
struct bpf_prog_aux *aux = fp->aux;
@@ -2421,7 +2426,7 @@ static int bpf_check_tail_call(const struct bpf_prog *fp)
24212426
if (!map_type_contains_progs(map))
24222427
continue;
24232428

2424-
if (!bpf_prog_map_compatible(map, fp)) {
2429+
if (!__bpf_prog_map_compatible(map, fp)) {
24252430
ret = -EINVAL;
24262431
goto out;
24272432
}

0 commit comments

Comments
 (0)