aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2018-08-17 17:26:14 -0400
committerAlexei Starovoitov <ast@kernel.org>2018-08-17 18:56:23 -0400
commitf6069b9aa9934ede26f41ac0781fce241279ad43 (patch)
treedf9009742722dc032801dcf2f1250042935da580 /include
parenta85da34e97f553d27b520757ffc9b31232694a78 (diff)
bpf: fix redirect to map under tail calls
Commits 109980b894e9 ("bpf: don't select potentially stale ri->map from buggy xdp progs") and 7c3001313396 ("bpf: fix ri->map_owner pointer on bpf_prog_realloc") tried to mitigate that buggy programs using bpf_redirect_map() helper call do not leave stale maps behind. Idea was to add a map_owner cookie into the per CPU struct redirect_info which was set to prog->aux by the prog making the helper call as a proof that the map is not stale since the prog is implicitly holding a reference to it. This owner cookie could later on get compared with the program calling into BPF whether they match and therefore the redirect could proceed with processing the map safely. In (obvious) hindsight, this approach breaks down when tail calls are involved since the original caller's prog->aux pointer does not have to match the one from one of the progs out of the tail call chain, and therefore the xdp buffer will be dropped instead of redirected. A way around that would be to fix the issue differently (which also allows to remove related work in fast path at the same time): once the life-time of a redirect map has come to its end we use it's map free callback where we need to wait on synchronize_rcu() for current outstanding xdp buffers and remove such a map pointer from the redirect info if found to be present. At that time no program is using this map anymore so we simply invalidate the map pointers to NULL iff they previously pointed to that instance while making sure that the redirect path only reads out the map once. Fixes: 97f91a7cf04f ("bpf: add bpf_redirect_map helper routine") Fixes: 109980b894e9 ("bpf: don't select potentially stale ri->map from buggy xdp progs") Reported-by: Sebastiano Miano <sebastiano.miano@polito.it> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/filter.h3
-rw-r--r--include/trace/events/xdp.h5
2 files changed, 4 insertions, 4 deletions
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 5d565c50bcb2..6791a0ac0139 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -543,7 +543,6 @@ struct bpf_redirect_info {
543 u32 flags; 543 u32 flags;
544 struct bpf_map *map; 544 struct bpf_map *map;
545 struct bpf_map *map_to_flush; 545 struct bpf_map *map_to_flush;
546 unsigned long map_owner;
547 u32 kern_flags; 546 u32 kern_flags;
548}; 547};
549 548
@@ -781,6 +780,8 @@ static inline bool bpf_dump_raw_ok(void)
781struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off, 780struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,
782 const struct bpf_insn *patch, u32 len); 781 const struct bpf_insn *patch, u32 len);
783 782
783void bpf_clear_redirect_map(struct bpf_map *map);
784
784static inline bool xdp_return_frame_no_direct(void) 785static inline bool xdp_return_frame_no_direct(void)
785{ 786{
786 struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info); 787 struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
diff --git a/include/trace/events/xdp.h b/include/trace/events/xdp.h
index 1ecf4c67fcf7..e95cb86b65cf 100644
--- a/include/trace/events/xdp.h
+++ b/include/trace/events/xdp.h
@@ -147,9 +147,8 @@ struct _bpf_dtab_netdev {
147 147
148#define devmap_ifindex(fwd, map) \ 148#define devmap_ifindex(fwd, map) \
149 (!fwd ? 0 : \ 149 (!fwd ? 0 : \
150 (!map ? 0 : \ 150 ((map->map_type == BPF_MAP_TYPE_DEVMAP) ? \
151 ((map->map_type == BPF_MAP_TYPE_DEVMAP) ? \ 151 ((struct _bpf_dtab_netdev *)fwd)->dev->ifindex : 0))
152 ((struct _bpf_dtab_netdev *)fwd)->dev->ifindex : 0)))
153 152
154#define _trace_xdp_redirect_map(dev, xdp, fwd, map, idx) \ 153#define _trace_xdp_redirect_map(dev, xdp, fwd, map, idx) \
155 trace_xdp_redirect_map(dev, xdp, devmap_ifindex(fwd, map), \ 154 trace_xdp_redirect_map(dev, xdp, devmap_ifindex(fwd, map), \