qrtr: orphan skb before queuing in xmit
Subsystems (3)
PATCH 1/1 qrtr: orphan skb before queuing in xmit
Similar to tun_net_xmit(), we have to orphan the skb before queuing it, otherwise we may use the socket when purging the queue after it is freed by user-space.
--- net/qrtr/tun.c | 1 + 1 file changed, 1 insertion(+)
net/qrtr/tun.c +1 -0
@@ -20,6 +20,7 @@ static int qrtr_tun_send(struct qrtr_endpoint *ep, struct sk_buff *skb) { struct qrtr_tun *tun = container_of(ep, struct qrtr_tun, ep); +skb_orphan (skb);skb_queue_tail (&tun->queue, skb);/* wake up any blocking processes, waiting for new data */
Signature · 1 line
2.27.0
Quoted 3 lines · Cong Wang
Similar to
tun_net_xmit(), we have to orphan the skb before queuing it, otherwise we may use the socket when purging the queue after it is freed by user-space.
Which socket ?
By not calling skb_orphan(skb), this skb should own a reference on skb->sk preventing skb->sk to disappear.
It seems that instead of skb_orphan() here, we could avoid calling skb_set_owner_w() in the first place, because this is confusing.
Also, there seems to be no limit on number of skbs that can be queued, this looks rather dangerous.
net/qrtr/qrtr.c +0 -2
@@ -661,7 +661,6 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) pkt->client.node =cpu_to_le32 (ipc->us.sq_node); pkt->client.port =cpu_to_le32 (ipc->us.sq_port); -skb_set_owner_w (skb, &ipc->sk);qrtr_bcast_enqueue (NULL , skb,QRTR_TYPE_DEL_CLIENT , &ipc->us, &to); }
@@ -855,7 +854,6 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb, skbn =skb_clone (skb,GFP_KERNEL );if (!skbn)break ; -skb_set_owner_w (skbn, skb->sk);qrtr_node_enqueue (node, skbn, type, from, to); }mutex_unlock (&qrtr_node_lock);
Quoted 22 lines
Reported-and-tested-by [email protected]Fixes 28fb4e59a47d ("net: qrtr: Expose tunneling endpoint to user space")Cc Bjorn Andersson <[email protected]>Signed-off-by Cong Wang <[email protected]>--- net/qrtr/tun.c | 1 + 1 file changed, 1 insertion(+)net/qrtr/tun.c +1
-0@@ -20,6 +20,7 @@ static int qrtr_tun_send(struct qrtr_endpoint *ep, struct sk_buff *skb) { struct qrtr_tun *tun = container_of(ep, struct qrtr_tun, ep); +skb_orphan (skb);skb_queue_tail (&tun->queue, skb);/* wake up any blocking processes, waiting for new data */
Quoted 9 lines · Eric Dumazet
Quoted 3 lines · Cong Wang
Similar to
tun_net_xmit(), we have to orphan the skb before queuing it, otherwise we may use the socket when purging the queue after it is freed by user-space.Which socket ?
sk->sk_wq points to &sock->wq. The socket is of course from qrtr_create().
Quoted 4 lines
By not calling
skb_orphan(skb), this skb should own a reference onskb->skpreventingskb->skto disappear.
I said socket, not sock. I believe the socket can be gone while the sock is still there.
Quoted 2 lines
It seems that instead of
skb_orphan()here, we could avoid callingskb_set_owner_w()in the first place, because this is confusing.
Not sure about this, at least tun calls skb_set_owner_w() too. More importantly, sock_alloc_send_skb() calls it too. :)
Quoted 3 lines · Cong Wang
I said socket, not sock. I believe the socket can be gone while the sock is still there.
Hmm, looks llike sock_orphan() should be called...
Quoted 23 lines · Cong Wang
Quoted 9 lines · Eric Dumazet
Quoted 3 lines · Cong Wang
Similar to
tun_net_xmit(), we have to orphan the skb before queuing it, otherwise we may use the socket when purging the queue after it is freed by user-space.Which socket ?
sk->sk_wqpoints to&sock->wq. The socket is of course fromqrtr_create().Quoted 4 lines
By not calling
skb_orphan(skb), this skb should own a reference onskb->skpreventingskb->skto disappear.I said socket, not sock. I believe the socket can be gone while the sock is still there.
Quoted 6 lines
Quoted 2 lines
It seems that instead of
skb_orphan()here, we could avoid callingskb_set_owner_w()in the first place, because this is confusing.Not sure about this, at least tun calls
skb_set_owner_w()too. More importantly,sock_alloc_send_skb()calls it too. :)
tun is very different : skbs reaching it came come from all over the places, like TCP stack. Their skb->sk is not pointing to the tun sock.
Here, the skbs are cooked from net/qrtr/qrtr.c locations only.