diff options
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r-- | kernel/bpf/syscall.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 1d65e56594db..828518bb947b 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c | |||
@@ -2072,13 +2072,26 @@ static int bpf_map_get_fd_by_id(const union bpf_attr *attr) | |||
2072 | } | 2072 | } |
2073 | 2073 | ||
2074 | static const struct bpf_map *bpf_map_from_imm(const struct bpf_prog *prog, | 2074 | static const struct bpf_map *bpf_map_from_imm(const struct bpf_prog *prog, |
2075 | unsigned long addr) | 2075 | unsigned long addr, u32 *off, |
2076 | u32 *type) | ||
2076 | { | 2077 | { |
2078 | const struct bpf_map *map; | ||
2077 | int i; | 2079 | int i; |
2078 | 2080 | ||
2079 | for (i = 0; i < prog->aux->used_map_cnt; i++) | 2081 | for (i = 0, *off = 0; i < prog->aux->used_map_cnt; i++) { |
2080 | if (prog->aux->used_maps[i] == (void *)addr) | 2082 | map = prog->aux->used_maps[i]; |
2081 | return prog->aux->used_maps[i]; | 2083 | if (map == (void *)addr) { |
2084 | *type = BPF_PSEUDO_MAP_FD; | ||
2085 | return map; | ||
2086 | } | ||
2087 | if (!map->ops->map_direct_value_meta) | ||
2088 | continue; | ||
2089 | if (!map->ops->map_direct_value_meta(map, addr, off)) { | ||
2090 | *type = BPF_PSEUDO_MAP_VALUE; | ||
2091 | return map; | ||
2092 | } | ||
2093 | } | ||
2094 | |||
2082 | return NULL; | 2095 | return NULL; |
2083 | } | 2096 | } |
2084 | 2097 | ||
@@ -2086,6 +2099,7 @@ static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog) | |||
2086 | { | 2099 | { |
2087 | const struct bpf_map *map; | 2100 | const struct bpf_map *map; |
2088 | struct bpf_insn *insns; | 2101 | struct bpf_insn *insns; |
2102 | u32 off, type; | ||
2089 | u64 imm; | 2103 | u64 imm; |
2090 | int i; | 2104 | int i; |
2091 | 2105 | ||
@@ -2113,11 +2127,11 @@ static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog) | |||
2113 | continue; | 2127 | continue; |
2114 | 2128 | ||
2115 | imm = ((u64)insns[i + 1].imm << 32) | (u32)insns[i].imm; | 2129 | imm = ((u64)insns[i + 1].imm << 32) | (u32)insns[i].imm; |
2116 | map = bpf_map_from_imm(prog, imm); | 2130 | map = bpf_map_from_imm(prog, imm, &off, &type); |
2117 | if (map) { | 2131 | if (map) { |
2118 | insns[i].src_reg = BPF_PSEUDO_MAP_FD; | 2132 | insns[i].src_reg = type; |
2119 | insns[i].imm = map->id; | 2133 | insns[i].imm = map->id; |
2120 | insns[i + 1].imm = 0; | 2134 | insns[i + 1].imm = off; |
2121 | continue; | 2135 | continue; |
2122 | } | 2136 | } |
2123 | } | 2137 | } |