bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bpf PATCH 0/3] sockmap fixes
@ 2019-05-13 14:19 John Fastabend
  2019-05-13 14:19 ` [bpf PATCH 1/3] bpf: sockmap, only stop/flush strp if it was enabled at some point John Fastabend
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: John Fastabend @ 2019-05-13 14:19 UTC (permalink / raw)
  To: jakub.kicinski, ast, daniel; +Cc: netdev, bpf, john.fastabend

A couple fixes for sockmap code. Previously this was bundled with a tls
fix for unhash() path however, that is becoming a larger fix so push
these on their own.

---

John Fastabend (3):
      bpf: sockmap, only stop/flush strp if it was enabled at some point
      bpf: sockmap remove duplicate queue free
      bpf: sockmap fix msg->sg.size account on ingress skb


 net/core/skmsg.c   |    7 +++++--
 net/ipv4/tcp_bpf.c |    2 --
 2 files changed, 5 insertions(+), 4 deletions(-)

--
Signature

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [bpf PATCH 1/3] bpf: sockmap, only stop/flush strp if it was enabled at some point
  2019-05-13 14:19 [bpf PATCH 0/3] sockmap fixes John Fastabend
@ 2019-05-13 14:19 ` John Fastabend
  2019-05-13 14:19 ` [bpf PATCH 2/3] bpf: sockmap remove duplicate queue free John Fastabend
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: John Fastabend @ 2019-05-13 14:19 UTC (permalink / raw)
  To: jakub.kicinski, ast, daniel; +Cc: netdev, bpf, john.fastabend

If we try to call strp_done on a parser that has never been
initialized, because the sockmap user is only using TX side for
example we get the following error.


  [  883.422081] WARNING: CPU: 1 PID: 208 at kernel/workqueue.c:3030 __flush_work+0x1ca/0x1e0
  ...
  [  883.422095] Workqueue: events sk_psock_destroy_deferred
  [  883.422097] RIP: 0010:__flush_work+0x1ca/0x1e0


This had been wrapped in a 'if (psock->parser.enabled)' logic which
was broken because the strp_done() was never actually being called
because we do a strp_stop() earlier in the tear down logic will
set parser.enabled to false. This could result in a use after free
if work was still in the queue and was resolved by the patch here,
1d79895aef18f ("sk_msg: Always cancel strp work before freeing the
psock"). However, calling strp_stop(), done by the patch marked in
the fixes tag, only is useful if we never initialized a strp parser
program and never initialized the strp to start with. Because if
we had initialized a stream parser strp_stop() would have been called
by sk_psock_drop() earlier in the tear down process.  By forcing the
strp to stop we get past the WARNING in strp_done that checks
the stopped flag but calling cancel_work_sync on work that has never
been initialized is also wrong and generates the warning above.

To fix check if the parser program exists. If the program exists
then the strp work has been initialized and must be sync'd and
cancelled before free'ing any structures. If no program exists we
never initialized the stream parser in the first place so skip the
sync/cancel logic implemented by strp_done.

Finally, remove the strp_done its not needed and in the case where we are using the
stream parser has already been called.

Fixes: e8e3437762ad9 ("bpf: Stop the psock parser before canceling its work")
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 net/core/skmsg.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index cc94d921476c..49d1efa329d7 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -554,8 +554,10 @@ static void sk_psock_destroy_deferred(struct work_struct *gc)
 	struct sk_psock *psock = container_of(gc, struct sk_psock, gc);
 
 	/* No sk_callback_lock since already detached. */
-	strp_stop(&psock->parser.strp);
-	strp_done(&psock->parser.strp);
+
+	/* Parser has been stopped */
+	if (psock->progs.skb_parser)
+		strp_done(&psock->parser.strp);
 
 	cancel_work_sync(&psock->work);
 


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [bpf PATCH 2/3] bpf: sockmap remove duplicate queue free
  2019-05-13 14:19 [bpf PATCH 0/3] sockmap fixes John Fastabend
  2019-05-13 14:19 ` [bpf PATCH 1/3] bpf: sockmap, only stop/flush strp if it was enabled at some point John Fastabend
@ 2019-05-13 14:19 ` John Fastabend
  2019-05-13 14:19 ` [bpf PATCH 3/3] bpf: sockmap fix msg->sg.size account on ingress skb John Fastabend
  2019-05-13 23:34 ` [bpf PATCH 0/3] sockmap fixes Daniel Borkmann
  3 siblings, 0 replies; 6+ messages in thread
From: John Fastabend @ 2019-05-13 14:19 UTC (permalink / raw)
  To: jakub.kicinski, ast, daniel; +Cc: netdev, bpf, john.fastabend

In tcp bpf remove we free the cork list and purge the ingress msg
list. However we do this before the ref count reaches zero so it
could be possible some other access is in progress. In this case
(tcp close and/or tcp_unhash) we happen to also hold the sock
lock so no path exists but lets fix it otherwise it is extremely
fragile and breaks the reference counting rules. Also we already
check the cork list and ingress msg queue and free them once the
ref count reaches zero so its wasteful to check twice.

Fixes: 604326b41a6fb ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 net/ipv4/tcp_bpf.c |    2 --
 1 file changed, 2 deletions(-)

diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
index 1bb7321a256d..4a619c85daed 100644
--- a/net/ipv4/tcp_bpf.c
+++ b/net/ipv4/tcp_bpf.c
@@ -528,8 +528,6 @@ static void tcp_bpf_remove(struct sock *sk, struct sk_psock *psock)
 {
 	struct sk_psock_link *link;
 
-	sk_psock_cork_free(psock);
-	__sk_psock_purge_ingress_msg(psock);
 	while ((link = sk_psock_link_pop(psock))) {
 		sk_psock_unlink(sk, link);
 		sk_psock_free_link(link);


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [bpf PATCH 3/3] bpf: sockmap fix msg->sg.size account on ingress skb
  2019-05-13 14:19 [bpf PATCH 0/3] sockmap fixes John Fastabend
  2019-05-13 14:19 ` [bpf PATCH 1/3] bpf: sockmap, only stop/flush strp if it was enabled at some point John Fastabend
  2019-05-13 14:19 ` [bpf PATCH 2/3] bpf: sockmap remove duplicate queue free John Fastabend
@ 2019-05-13 14:19 ` John Fastabend
  2019-05-13 23:34 ` [bpf PATCH 0/3] sockmap fixes Daniel Borkmann
  3 siblings, 0 replies; 6+ messages in thread
From: John Fastabend @ 2019-05-13 14:19 UTC (permalink / raw)
  To: jakub.kicinski, ast, daniel; +Cc: netdev, bpf, john.fastabend

When converting a skb to msg->sg we forget to set the size after the
latest ktls/tls code conversion. This patch can be reached by doing
a redir into ingress path from BPF skb sock recv hook. Then trying to
read the size fails.

Fix this by setting the size.

Fixes: 604326b41a6fb ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 net/core/skmsg.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index 49d1efa329d7..93bffaad2135 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -411,6 +411,7 @@ static int sk_psock_skb_ingress(struct sk_psock *psock, struct sk_buff *skb)
 	sk_mem_charge(sk, skb->len);
 	copied = skb->len;
 	msg->sg.start = 0;
+	msg->sg.size = copied;
 	msg->sg.end = num_sge == MAX_MSG_FRAGS ? 0 : num_sge;
 	msg->skb = skb;
 


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [bpf PATCH 0/3] sockmap fixes
  2019-05-13 14:19 [bpf PATCH 0/3] sockmap fixes John Fastabend
                   ` (2 preceding siblings ...)
  2019-05-13 14:19 ` [bpf PATCH 3/3] bpf: sockmap fix msg->sg.size account on ingress skb John Fastabend
@ 2019-05-13 23:34 ` Daniel Borkmann
  3 siblings, 0 replies; 6+ messages in thread
From: Daniel Borkmann @ 2019-05-13 23:34 UTC (permalink / raw)
  To: John Fastabend, jakub.kicinski, ast; +Cc: netdev, bpf

On 05/13/2019 04:19 PM, John Fastabend wrote:
> A couple fixes for sockmap code. Previously this was bundled with a tls
> fix for unhash() path however, that is becoming a larger fix so push
> these on their own.

Agree, applied, thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [bpf PATCH 2/3] bpf: sockmap remove duplicate queue free
  2019-04-24 19:20 [bpf PATCH 0/3] sockmap/ktls fixes John Fastabend
@ 2019-04-24 19:21 ` John Fastabend
  0 siblings, 0 replies; 6+ messages in thread
From: John Fastabend @ 2019-04-24 19:21 UTC (permalink / raw)
  To: ast, daniel; +Cc: netdev, bpf, john.fastabend

In tcp bpf remove we free the cork list and purge the ingress msg
list. However we do this before the ref count reaches zero so it
could be possible some other access is in progress. In this case
(tcp close and/or tcp_unhash) we happen to also hold the sock
lock so no path exists but lets fix it otherwise it is extremely
fragile and breaks the reference counting rules. Also we already
check the cork list and ingress msg queue and free them once the
ref count reaches zero so its wasteful to check twice.

Fixes: 604326b41a6fb ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 net/ipv4/tcp_bpf.c |    2 --
 1 file changed, 2 deletions(-)

diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
index 1bb7321a256d..4a619c85daed 100644
--- a/net/ipv4/tcp_bpf.c
+++ b/net/ipv4/tcp_bpf.c
@@ -528,8 +528,6 @@ static void tcp_bpf_remove(struct sock *sk, struct sk_psock *psock)
 {
 	struct sk_psock_link *link;
 
-	sk_psock_cork_free(psock);
-	__sk_psock_purge_ingress_msg(psock);
 	while ((link = sk_psock_link_pop(psock))) {
 		sk_psock_unlink(sk, link);
 		sk_psock_free_link(link);


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-05-13 23:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-13 14:19 [bpf PATCH 0/3] sockmap fixes John Fastabend
2019-05-13 14:19 ` [bpf PATCH 1/3] bpf: sockmap, only stop/flush strp if it was enabled at some point John Fastabend
2019-05-13 14:19 ` [bpf PATCH 2/3] bpf: sockmap remove duplicate queue free John Fastabend
2019-05-13 14:19 ` [bpf PATCH 3/3] bpf: sockmap fix msg->sg.size account on ingress skb John Fastabend
2019-05-13 23:34 ` [bpf PATCH 0/3] sockmap fixes Daniel Borkmann
  -- strict thread matches above, loose matches on Subject: below --
2019-04-24 19:20 [bpf PATCH 0/3] sockmap/ktls fixes John Fastabend
2019-04-24 19:21 ` [bpf PATCH 2/3] bpf: sockmap remove duplicate queue free John Fastabend

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).