Skip to contentSkip to conversation

unix: correct sk_rmem_alloc accounting

PATCH In review Cong Wang 3 participants 3 messages Jan 23, 2013

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

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

Cc Yannick Koehler <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc David S. Miller <[email protected]>

---

net/unix/af_unix.c +3 -0
index 5b5c876..7e9dba3 100644
@@ -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;
#1 lore raw
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 call skb_set_owner_r() before every time we queuing skb into other->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.

#2 lore raw
In reply to Cong Wang
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 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

Cc Yannick Koehler <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc David S. Miller <[email protected]>

---

net/unix/af_unix.c +2 -0
index 5b5c876..7e9dba3 100644
@@ -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.