aboutsummaryrefslogtreecommitdiffstats
path: root/net/caif
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2014-04-11 16:15:36 -0400
committerDavid S. Miller <davem@davemloft.net>2014-04-11 16:15:36 -0400
commit676d23690fb62b5d51ba5d659935e9f7d9da9f8e (patch)
treef6fbceee43e05c724868153ca37b702fb5e43b8c /net/caif
parentad20d5f673898578f9d8a156d7a4c921f5ca4584 (diff)
net: Fix use after free by removing length arg from sk_data_ready callbacks.
Several spots in the kernel perform a sequence like: skb_queue_tail(&sk->s_receive_queue, skb); sk->sk_data_ready(sk, skb->len); But at the moment we place the SKB onto the socket receive queue it can be consumed and freed up. So this skb->len access is potentially to freed up memory. Furthermore, the skb->len can be modified by the consumer so it is possible that the value isn't accurate. And finally, no actual implementation of this callback actually uses the length argument. And since nobody actually cared about it's value, lots of call sites pass arbitrary values in such as '0' and even '1'. So just remove the length argument from the callback, that way there is no confusion whatsoever and all of these use-after-free cases get fixed as a side effect. Based upon a patch by Eric Dumazet and his suggestion to audit this issue tree-wide. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/caif')
-rw-r--r--net/caif/caif_socket.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
index d6be3edb7a43..e8437094d15f 100644
--- a/net/caif/caif_socket.c
+++ b/net/caif/caif_socket.c
@@ -124,7 +124,6 @@ static void caif_flow_ctrl(struct sock *sk, int mode)
124static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) 124static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
125{ 125{
126 int err; 126 int err;
127 int skb_len;
128 unsigned long flags; 127 unsigned long flags;
129 struct sk_buff_head *list = &sk->sk_receive_queue; 128 struct sk_buff_head *list = &sk->sk_receive_queue;
130 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); 129 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk);
@@ -153,14 +152,13 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
153 * may be freed by other threads of control pulling packets 152 * may be freed by other threads of control pulling packets
154 * from the queue. 153 * from the queue.
155 */ 154 */
156 skb_len = skb->len;
157 spin_lock_irqsave(&list->lock, flags); 155 spin_lock_irqsave(&list->lock, flags);
158 if (!sock_flag(sk, SOCK_DEAD)) 156 if (!sock_flag(sk, SOCK_DEAD))
159 __skb_queue_tail(list, skb); 157 __skb_queue_tail(list, skb);
160 spin_unlock_irqrestore(&list->lock, flags); 158 spin_unlock_irqrestore(&list->lock, flags);
161 159
162 if (!sock_flag(sk, SOCK_DEAD)) 160 if (!sock_flag(sk, SOCK_DEAD))
163 sk->sk_data_ready(sk, skb_len); 161 sk->sk_data_ready(sk);
164 else 162 else
165 kfree_skb(skb); 163 kfree_skb(skb);
166 return 0; 164 return 0;