unix: correct sk_rmem_alloc accounting
Subsystems (3)
PATCH 1/1 unix: correct sk_rmem_alloc accounting
From: Cong Wang <[email protected]>
Yannick reported [1] we probably forgot to account ->sk_rmem_alloc before moving the skb to other->sk_receive_queue. I believe he is right. So, just call skb_set_owner_r() before every time we queuing skb into other->sk_receive_queue.
1. http://marc.info/?l=linux-netdev&m=135882012924930&w=2
---
net/unix/af_unix.c +3 -0
@@ -1205,6 +1205,7 @@ restart:unix_state_unlock (sk); +skb_set_owner_r (skb, other);/* take ten and and send info to listening sock */ spin_lock (&other->sk_receive_queue.lock);__skb_queue_tail (&other->sk_receive_queue, skb);
@@ -1579,6 +1580,7 @@ restart:if (sock_flag (other,SOCK_RCVTSTAMP ))__net_timestamp (skb);maybe_add_creds (skb, sock, other); +skb_set_owner_r (skb, other);skb_queue_tail (&other->sk_receive_queue, skb);if (max_level >unix_sk (other)->recursion_level)unix_sk (other)->recursion_level = max_level;
@@ -1694,6 +1696,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock, goto pipe_err_free;maybe_add_creds (skb, sock, other); +skb_set_owner_r (skb, other);skb_queue_tail (&other->sk_receive_queue, skb);if (max_level >unix_sk (other)->recursion_level)unix_sk (other)->recursion_level = max_level;
Quoted 6 lines · Cong Wang
From: Cong Wang <[email protected]>
Yannick reported [1] we probably forgot to account ->sk_rmem_alloc before moving the skb to
other->sk_receive_queue. I believe he is right. So, just callskb_set_owner_r()before every time we queuing skb intoother->sk_receive_queue.
I think Eric's comment on a possible DOS is correct. Having a quick look, it seems unix_recvq_full needs to check ->sk_rmem_alloc at a minimum.
Quoted 37 lines · Cong Wang
From: Cong Wang <[email protected]>
Yannick reported [1] we probably forgot to account ->sk_rmem_alloc before moving the skb to
other->sk_receive_queue. I believe he is right. So, just callskb_set_owner_r()before every time we queuing skb intoother->sk_receive_queue.1. http://marc.info/?l=linux-netdev&m=135882012924930&w=2
Reported-by Yannick Koehler <[email protected]>Cc Yannick Koehler <[email protected]>Cc Eric Dumazet <[email protected]>Cc David S. Miller <[email protected]>Signed-off-by Cong Wang <[email protected]>---
net/unix/af_unix.c +2
-0@@ -1205,6 +1205,7 @@ restart:unix_state_unlock (sk); +skb_set_owner_r (skb, other);/* take ten and and send info to listening sock */ spin_lock (&other->sk_receive_queue.lock);__skb_queue_tail (&other->sk_receive_queue, skb);@@ -1579,6 +1580,7 @@ restart:if (sock_flag (other,SOCK_RCVTSTAMP ))__net_timestamp (skb);maybe_add_creds (skb, sock, other); +skb_set_owner_r (skb, other);skb_queue_tail (&other->sk_receive_queue, skb);if (max_level >unix_sk (other)->recursion_level)unix_sk (other)->recursion_level = max_level;
net/unix/af_unix.c static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock, · line 1702
Quoted 7 lines
net/unix/af_unix.c +1
-0@@ -1694,6 +1696,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock, goto pipe_err_free;maybe_add_creds (skb, sock, other); +skb_set_owner_r (skb, other);skb_queue_tail (&other->sk_receive_queue, skb);if (max_level >unix_sk (other)->recursion_level)unix_sk (other)->recursion_level = max_level;
I Nack this patch, for reasons already given.