Thread (14 messages) 14 messages, 3 authors, 2021-05-21

Re: [Patch bpf] udp: fix a memory leak in udp_read_sock()

From: Cong Wang <hidden>
Date: 2021-05-19 20:18:01
Also in: netdev

On Wed, May 19, 2021 at 12:06 PM John Fastabend
[off-list ref] wrote:
Cong Wang wrote:
quoted
On Tue, May 18, 2021 at 12:56 PM John Fastabend
[off-list ref] wrote:
quoted
Cong Wang wrote:
quoted
On Mon, May 17, 2021 at 10:36 PM John Fastabend
[off-list ref] wrote:
quoted
Cong Wang wrote:
quoted
From: Cong Wang <redacted>

sk_psock_verdict_recv() clones the skb and uses the clone
afterward, so udp_read_sock() should free the original skb after
done using it.
The clone only happens if sk_psock_verdict_recv() returns >0.
Sure, in case of error, no one uses the original skb either,
so still need to free it.
But the data is going to be dropped then. I'm questioning if this
is the best we can do or not. Its simplest sure, but could we
do a bit more work and peek those skbs or requeue them? Otherwise
if you cross memory limits for a bit your likely to drop these
unnecessarily.
What are the benefits of not dropping it? When sockmap takes
over sk->sk_data_ready() it should have total control over the skb's
in the receive queue. Otherwise user-space recvmsg() would race
with sockmap when they try to read the first skb at the same time,
therefore potentially user-space could get duplicated data (one via
recvmsg(), one via sockmap). I don't see any benefits but races here.
The benefit of _not_ dropping it is the packet gets to the receiver
side. We've spent a bit of effort to get a packet across the network,
received on the stack, and then we drop it at the last point is not
so friendly.
Well, at least udp_recvmsg() could drop packets too in various
scenarios, for example, a copy error. So, I do not think sockmap
is special.
About races is the socket is locked by the caller here? Or is this
not the case for UDP.
Unlike TCP, the sock is not locked during BH for UDP receive path.
Locking it is not the answer here, because 1) we certainly do not want
to slow down UDP fast path; 2) UDP lacks sk->sk_backlog_rcv().
Its OK in the end to say "its UDP and lossy" but ideally we don't
make things worse by adding sockmap into the stack. We had these
problems already on TCP side, where they are much more severe
because sender believes retransmits will happen, and fixed them
by now. It would be nice if UDP side also didn't introduce
drops.
Like I said, the normal UDP receive path drops packets too,
sockmap is not different here. TCP does peek packets, for two
reasons: 1) it has to support splice(); 2) it has locked the socket
during BH receive. UDP has none of them, so UDP can't peek
packets here.

Thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help