diff options
author | Eric Dumazet <edumazet@google.com> | 2015-09-29 21:52:25 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-10-17 08:01:11 -0400 |
commit | c7c49b8fde26b74277188bdc6c9dca38db6fa35b (patch) | |
tree | 27ac5d0c1469aeacade0db5540362e8e9772b6b4 | |
parent | 5f715c097965c0ad037f64393d0b95c50287775b (diff) |
net: add pfmemalloc check in sk_add_backlog()
Greg reported crashes hitting the following check in __sk_backlog_rcv()
BUG_ON(!sock_flag(sk, SOCK_MEMALLOC));
The pfmemalloc bit is currently checked in sk_filter().
This works correctly for TCP, because sk_filter() is ran in
tcp_v[46]_rcv() before hitting the prequeue or backlog checks.
For UDP or other protocols, this does not work, because the sk_filter()
is ran from sock_queue_rcv_skb(), which might be called _after_ backlog
queuing if socket is owned by user by the time packet is processed by
softirq handler.
Fixes: b4b9e35585089 ("netvm: set PF_MEMALLOC as appropriate during SKB processing")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Greg Thelen <gthelen@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/sock.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index 7aa78440559a..e23717013a4e 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -828,6 +828,14 @@ static inline __must_check int sk_add_backlog(struct sock *sk, struct sk_buff *s | |||
828 | if (sk_rcvqueues_full(sk, limit)) | 828 | if (sk_rcvqueues_full(sk, limit)) |
829 | return -ENOBUFS; | 829 | return -ENOBUFS; |
830 | 830 | ||
831 | /* | ||
832 | * If the skb was allocated from pfmemalloc reserves, only | ||
833 | * allow SOCK_MEMALLOC sockets to use it as this socket is | ||
834 | * helping free memory | ||
835 | */ | ||
836 | if (skb_pfmemalloc(skb) && !sock_flag(sk, SOCK_MEMALLOC)) | ||
837 | return -ENOMEM; | ||
838 | |||
831 | __sk_add_backlog(sk, skb); | 839 | __sk_add_backlog(sk, skb); |
832 | sk->sk_backlog.len += skb->truesize; | 840 | sk->sk_backlog.len += skb->truesize; |
833 | return 0; | 841 | return 0; |