mbox series

[net,v1,0/3] add support for skb with sk ref cloning

Message ID 20210222151247.24534-1-o.rempel@pengutronix.de
Headers show
Series add support for skb with sk ref cloning | expand

Message

Oleksij Rempel Feb. 22, 2021, 3:12 p.m. UTC
Hello,

this series tries to fix a long standing problem in the CAN echo SKB
handling. The problem shows up if an echo SKB for a SKB that references
an already closed socket is created.

It looks like the mac80211/tx.c has the same problem, see RFC patch 3
for details.

regards,
Oleksij

Oleksij Rempel (3):
  skbuff: skb_clone_sk_optional(): add function to always clone a skb
    and increase refcount on sk if valid
  can: fix ref count warning if socket was closed before skb was cloned
  [RFC] mac80211: ieee80211_store_ack_skb(): make use of
    skb_clone_sk_optional()

 include/linux/can/skb.h   |  3 +--
 include/linux/skbuff.h    |  1 +
 net/can/af_can.c          |  6 +++---
 net/can/j1939/main.c      |  3 +--
 net/can/j1939/socket.c    |  3 +--
 net/can/j1939/transport.c |  4 +---
 net/core/skbuff.c         | 27 +++++++++++++++++++++++++++
 net/mac80211/tx.c         |  6 +-----
 8 files changed, 36 insertions(+), 17 deletions(-)

Comments

Johannes Berg Feb. 22, 2021, 4:30 p.m. UTC | #1
On Mon, 2021-02-22 at 16:12 +0100, Oleksij Rempel wrote:
> This code is trying to clone the skb with optional skb->sk. But this
> will fail to clone the skb if socket was closed just after the skb was
> pushed into the networking stack.

Which IMHO is completely fine. If we then still clone the SKB we can't
do anything with it, since the point would be to ... send it back to the
socket, but it's gone.

Nothing to fix here, I'd think. If you wanted to get a copy back that
gives you the status of the SKB, it should not come as a huge surprise
that you have to keep the socket open for that :)

Having the ACK skb will just make us do more work by handing it back
to skb_complete_wifi_ack() at TX status time, which is supposed to put
it into the socket's error queue, but if the socket is closed ... no
point in that.

johannes
Johannes Berg Feb. 23, 2021, 9:47 a.m. UTC | #2
On Mon, 2021-02-22 at 19:51 +0100, Marc Kleine-Budde wrote:
> On 22.02.2021 17:30:59, Johannes Berg wrote:
> > On Mon, 2021-02-22 at 16:12 +0100, Oleksij Rempel wrote:
> > > This code is trying to clone the skb with optional skb->sk. But this
> > > will fail to clone the skb if socket was closed just after the skb was
> > > pushed into the networking stack.
> > 
> > Which IMHO is completely fine. If we then still clone the SKB we can't
> > do anything with it, since the point would be to ... send it back to the
> > socket, but it's gone.
> 
> Ok, but why is the skb cloned if there is no socket linked in skb->sk?

Hm? There are two different ways to get here, one with and one without a
socket.

johannes