* [PATCH bpf] flow_dissector: Fix potential use-after-free on BPF_PROG_DETACH
@ 2019-08-21 12:17 Jakub Sitnicki
2019-08-22 6:00 ` Petar Penkov
2019-08-23 23:34 ` Daniel Borkmann
0 siblings, 2 replies; 3+ messages in thread
From: Jakub Sitnicki @ 2019-08-21 12:17 UTC (permalink / raw)
To: bpf; +Cc: netdev, kernel-team, Petar Penkov, Willem de Bruijn, Lorenz Bauer
Call to bpf_prog_put(), with help of call_rcu(), queues an RCU-callback to
free the program once a grace period has elapsed. The callback can run
together with new RCU readers that started after the last grace period.
New RCU readers can potentially see the "old" to-be-freed or already-freed
pointer to the program object before the RCU update-side NULLs it.
Reorder the operations so that the RCU update-side resets the protected
pointer before the end of the grace period after which the program will be
freed.
Fixes: d58e468b1112 ("flow_dissector: implements flow dissector BPF hook")
Reported-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
---
net/core/flow_dissector.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 3e6fedb57bc1..2470b4b404e6 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -142,8 +142,8 @@ int skb_flow_dissector_bpf_prog_detach(const union bpf_attr *attr)
mutex_unlock(&flow_dissector_mutex);
return -ENOENT;
}
- bpf_prog_put(attached);
RCU_INIT_POINTER(net->flow_dissector_prog, NULL);
+ bpf_prog_put(attached);
mutex_unlock(&flow_dissector_mutex);
return 0;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] flow_dissector: Fix potential use-after-free on BPF_PROG_DETACH
2019-08-21 12:17 [PATCH bpf] flow_dissector: Fix potential use-after-free on BPF_PROG_DETACH Jakub Sitnicki
@ 2019-08-22 6:00 ` Petar Penkov
2019-08-23 23:34 ` Daniel Borkmann
1 sibling, 0 replies; 3+ messages in thread
From: Petar Penkov @ 2019-08-22 6:00 UTC (permalink / raw)
To: Jakub Sitnicki
Cc: bpf, Networking, kernel-team, Petar Penkov, Willem de Bruijn,
Lorenz Bauer
This makes sense, thanks!
Acked-by: Petar Penkov <ppenkov@google.com>
On Wed, Aug 21, 2019 at 5:19 AM Jakub Sitnicki <jakub@cloudflare.com> wrote:
>
> Call to bpf_prog_put(), with help of call_rcu(), queues an RCU-callback to
> free the program once a grace period has elapsed. The callback can run
> together with new RCU readers that started after the last grace period.
> New RCU readers can potentially see the "old" to-be-freed or already-freed
> pointer to the program object before the RCU update-side NULLs it.
>
> Reorder the operations so that the RCU update-side resets the protected
> pointer before the end of the grace period after which the program will be
> freed.
>
> Fixes: d58e468b1112 ("flow_dissector: implements flow dissector BPF hook")
> Reported-by: Lorenz Bauer <lmb@cloudflare.com>
> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
> ---
> net/core/flow_dissector.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
> index 3e6fedb57bc1..2470b4b404e6 100644
> --- a/net/core/flow_dissector.c
> +++ b/net/core/flow_dissector.c
> @@ -142,8 +142,8 @@ int skb_flow_dissector_bpf_prog_detach(const union bpf_attr *attr)
> mutex_unlock(&flow_dissector_mutex);
> return -ENOENT;
> }
> - bpf_prog_put(attached);
> RCU_INIT_POINTER(net->flow_dissector_prog, NULL);
> + bpf_prog_put(attached);
> mutex_unlock(&flow_dissector_mutex);
> return 0;
> }
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] flow_dissector: Fix potential use-after-free on BPF_PROG_DETACH
2019-08-21 12:17 [PATCH bpf] flow_dissector: Fix potential use-after-free on BPF_PROG_DETACH Jakub Sitnicki
2019-08-22 6:00 ` Petar Penkov
@ 2019-08-23 23:34 ` Daniel Borkmann
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2019-08-23 23:34 UTC (permalink / raw)
To: Jakub Sitnicki, bpf
Cc: netdev, kernel-team, Petar Penkov, Willem de Bruijn, Lorenz Bauer
On 8/21/19 2:17 PM, Jakub Sitnicki wrote:
> Call to bpf_prog_put(), with help of call_rcu(), queues an RCU-callback to
> free the program once a grace period has elapsed. The callback can run
> together with new RCU readers that started after the last grace period.
> New RCU readers can potentially see the "old" to-be-freed or already-freed
> pointer to the program object before the RCU update-side NULLs it.
>
> Reorder the operations so that the RCU update-side resets the protected
> pointer before the end of the grace period after which the program will be
> freed.
>
> Fixes: d58e468b1112 ("flow_dissector: implements flow dissector BPF hook")
> Reported-by: Lorenz Bauer <lmb@cloudflare.com>
> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Applied, thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-08-23 23:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-21 12:17 [PATCH bpf] flow_dissector: Fix potential use-after-free on BPF_PROG_DETACH Jakub Sitnicki
2019-08-22 6:00 ` Petar Penkov
2019-08-23 23:34 ` Daniel Borkmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).