bpf: Allow XDP dev-bound programs to perform XDP_REDIRECT into maps
[ Upstream commit 714070c4cb7a10ff57450a618a936775f3036245 ]
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: 3d76a4d3d4
("bpf: XDP metadata RX kfuncs")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
1066c5a7d0
commit
50bbbd2559
@@ -2258,7 +2258,7 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool bpf_prog_map_compatible(struct bpf_map *map,
|
static bool __bpf_prog_map_compatible(struct bpf_map *map,
|
||||||
const struct bpf_prog *fp)
|
const struct bpf_prog *fp)
|
||||||
{
|
{
|
||||||
enum bpf_prog_type prog_type = resolve_prog_type(fp);
|
enum bpf_prog_type prog_type = resolve_prog_type(fp);
|
||||||
@@ -2268,14 +2268,6 @@ bool bpf_prog_map_compatible(struct bpf_map *map,
|
|||||||
if (fp->kprobe_override)
|
if (fp->kprobe_override)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* XDP programs inserted into maps are not guaranteed to run on
|
|
||||||
* a particular netdev (and can run outside driver context entirely
|
|
||||||
* in the case of devmap and cpumap). Until device checks
|
|
||||||
* are implemented, prohibit adding dev-bound programs to program maps.
|
|
||||||
*/
|
|
||||||
if (bpf_prog_is_dev_bound(aux))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
spin_lock(&map->owner.lock);
|
spin_lock(&map->owner.lock);
|
||||||
if (!map->owner.type) {
|
if (!map->owner.type) {
|
||||||
/* There's no owner yet where we could check for
|
/* There's no owner yet where we could check for
|
||||||
@@ -2309,6 +2301,19 @@ bool bpf_prog_map_compatible(struct bpf_map *map,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool bpf_prog_map_compatible(struct bpf_map *map, const struct bpf_prog *fp)
|
||||||
|
{
|
||||||
|
/* XDP programs inserted into maps are not guaranteed to run on
|
||||||
|
* a particular netdev (and can run outside driver context entirely
|
||||||
|
* in the case of devmap and cpumap). Until device checks
|
||||||
|
* are implemented, prohibit adding dev-bound programs to program maps.
|
||||||
|
*/
|
||||||
|
if (bpf_prog_is_dev_bound(fp->aux))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return __bpf_prog_map_compatible(map, fp);
|
||||||
|
}
|
||||||
|
|
||||||
static int bpf_check_tail_call(const struct bpf_prog *fp)
|
static int bpf_check_tail_call(const struct bpf_prog *fp)
|
||||||
{
|
{
|
||||||
struct bpf_prog_aux *aux = fp->aux;
|
struct bpf_prog_aux *aux = fp->aux;
|
||||||
@@ -2321,7 +2326,7 @@ static int bpf_check_tail_call(const struct bpf_prog *fp)
|
|||||||
if (!map_type_contains_progs(map))
|
if (!map_type_contains_progs(map))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!bpf_prog_map_compatible(map, fp)) {
|
if (!__bpf_prog_map_compatible(map, fp)) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user