Netdev List
 help / color / mirror / Atom feed
* [bpf-next PATCH] bpf: sockmap, fix skmsg recvmsg handler to track size correctly
@ 2018-10-16 17:36 John Fastabend
  2018-10-16 22:27 ` Alexei Starovoitov
  2018-10-17  0:32 ` Daniel Borkmann
  0 siblings, 2 replies; 3+ messages in thread
From: John Fastabend @ 2018-10-16 17:36 UTC (permalink / raw)
  To: ast, daniel; +Cc: netdev

When converting sockmap to new skmsg generic data structures we missed
that the recvmsg handler did not correctly use sg.size and instead was
using individual elements length. The result is if a sock is closed
with outstanding data we omit the call to sk_mem_uncharge() and can
get the warning below.

[   66.728282] WARNING: CPU: 6 PID: 5783 at net/core/stream.c:206 sk_stream_kill_queues+0x1fa/0x210

To fix this correct the redirect handler to xfer the size along with
the scatterlist and also decrement the size from the recvmsg handler.
Now when a sock is closed the remaining 'size' will be decremented
with sk_mem_uncharge().

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 include/linux/skmsg.h |    1 +
 net/ipv4/tcp_bpf.c    |    1 +
 2 files changed, 2 insertions(+)

diff --git a/include/linux/skmsg.h b/include/linux/skmsg.h
index 0b919f0..31df0d9 100644
--- a/include/linux/skmsg.h
+++ b/include/linux/skmsg.h
@@ -176,6 +176,7 @@ static inline void sk_msg_xfer(struct sk_msg *dst, struct sk_msg *src,
 {
 	dst->sg.data[which] = src->sg.data[which];
 	dst->sg.data[which].length  = size;
+	dst->sg.size		   += size;
 	src->sg.data[which].length -= size;
 	src->sg.data[which].offset += size;
 }
diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
index 80debb0..f9d3cf1 100644
--- a/net/ipv4/tcp_bpf.c
+++ b/net/ipv4/tcp_bpf.c
@@ -73,6 +73,7 @@ int __tcp_bpf_recvmsg(struct sock *sk, struct sk_psock *psock,
 			sge->offset += copy;
 			sge->length -= copy;
 			sk_mem_uncharge(sk, copy);
+			msg_rx->sg.size -= copy;
 			if (!sge->length) {
 				i++;
 				if (i == MAX_SKB_FRAGS)

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

* Re: [bpf-next PATCH] bpf: sockmap, fix skmsg recvmsg handler to track size correctly
  2018-10-16 17:36 [bpf-next PATCH] bpf: sockmap, fix skmsg recvmsg handler to track size correctly John Fastabend
@ 2018-10-16 22:27 ` Alexei Starovoitov
  2018-10-17  0:32 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2018-10-16 22:27 UTC (permalink / raw)
  To: John Fastabend; +Cc: ast, daniel, netdev

On Tue, Oct 16, 2018 at 10:36:01AM -0700, John Fastabend wrote:
> When converting sockmap to new skmsg generic data structures we missed
> that the recvmsg handler did not correctly use sg.size and instead was
> using individual elements length. The result is if a sock is closed
> with outstanding data we omit the call to sk_mem_uncharge() and can
> get the warning below.
> 
> [   66.728282] WARNING: CPU: 6 PID: 5783 at net/core/stream.c:206 sk_stream_kill_queues+0x1fa/0x210
> 
> To fix this correct the redirect handler to xfer the size along with
> the scatterlist and also decrement the size from the recvmsg handler.
> Now when a sock is closed the remaining 'size' will be decremented
> with sk_mem_uncharge().
> 
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>

Acked-by: Alexei Starovoitov <ast@kernel.org>

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

* Re: [bpf-next PATCH] bpf: sockmap, fix skmsg recvmsg handler to track size correctly
  2018-10-16 17:36 [bpf-next PATCH] bpf: sockmap, fix skmsg recvmsg handler to track size correctly John Fastabend
  2018-10-16 22:27 ` Alexei Starovoitov
@ 2018-10-17  0:32 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2018-10-17  0:32 UTC (permalink / raw)
  To: John Fastabend, ast; +Cc: netdev

On 10/16/2018 07:36 PM, John Fastabend wrote:
> When converting sockmap to new skmsg generic data structures we missed
> that the recvmsg handler did not correctly use sg.size and instead was
> using individual elements length. The result is if a sock is closed
> with outstanding data we omit the call to sk_mem_uncharge() and can
> get the warning below.
> 
> [   66.728282] WARNING: CPU: 6 PID: 5783 at net/core/stream.c:206 sk_stream_kill_queues+0x1fa/0x210
> 
> To fix this correct the redirect handler to xfer the size along with
> the scatterlist and also decrement the size from the recvmsg handler.
> Now when a sock is closed the remaining 'size' will be decremented
> with sk_mem_uncharge().
> 
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>

Applied to bpf-next, thanks!

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

end of thread, other threads:[~2018-10-17  8:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-16 17:36 [bpf-next PATCH] bpf: sockmap, fix skmsg recvmsg handler to track size correctly John Fastabend
2018-10-16 22:27 ` Alexei Starovoitov
2018-10-17  0:32 ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox