* [PATCH net] net: add pfmemalloc check in sk_add_backlog()
@ 2015-09-30 1:52 Eric Dumazet
2015-09-30 4:56 ` David Miller
0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2015-09-30 1:52 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Greg Thelen, Michal Hocko, Mel Gorman
From: Eric Dumazet <edumazet@google.com>
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>
---
include/net/sock.h | 8 ++++++++
1 file changed, 8 insertions(+)
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
if (sk_rcvqueues_full(sk, limit))
return -ENOBUFS;
+ /*
+ * If the skb was allocated from pfmemalloc reserves, only
+ * allow SOCK_MEMALLOC sockets to use it as this socket is
+ * helping free memory
+ */
+ if (skb_pfmemalloc(skb) && !sock_flag(sk, SOCK_MEMALLOC))
+ return -ENOMEM;
+
__sk_add_backlog(sk, skb);
sk->sk_backlog.len += skb->truesize;
return 0;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: add pfmemalloc check in sk_add_backlog()
2015-09-30 1:52 [PATCH net] net: add pfmemalloc check in sk_add_backlog() Eric Dumazet
@ 2015-09-30 4:56 ` David Miller
2015-10-02 9:38 ` Eric Dumazet
2015-10-16 15:38 ` Eric Dumazet
0 siblings, 2 replies; 6+ messages in thread
From: David Miller @ 2015-09-30 4:56 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev, gthelen, mhocko, mgorman
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Tue, 29 Sep 2015 18:52:25 -0700
> From: Eric Dumazet <edumazet@google.com>
>
> 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>
Applied, thanks Eric.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: add pfmemalloc check in sk_add_backlog()
2015-09-30 4:56 ` David Miller
@ 2015-10-02 9:38 ` Eric Dumazet
2015-10-16 15:38 ` Eric Dumazet
1 sibling, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2015-10-02 9:38 UTC (permalink / raw)
To: David Miller; +Cc: netdev, gthelen, mhocko, mgorman
On Tue, 2015-09-29 at 21:56 -0700, David Miller wrote:
> From: Eric Dumazet <eric.dumazet@gmail.com>
> Date: Tue, 29 Sep 2015 18:52:25 -0700
>
> > From: Eric Dumazet <edumazet@google.com>
> >
> > 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>
>
> Applied, thanks Eric.
Hi David
I could not find this patch in any of your trees, would you take a
look ?
Thanks !
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: add pfmemalloc check in sk_add_backlog()
2015-09-30 4:56 ` David Miller
2015-10-02 9:38 ` Eric Dumazet
@ 2015-10-16 15:38 ` Eric Dumazet
2015-10-17 12:02 ` David Miller
1 sibling, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2015-10-16 15:38 UTC (permalink / raw)
To: David Miller; +Cc: netdev
On Tue, 2015-09-29 at 21:56 -0700, David Miller wrote:
> From: Eric Dumazet <eric.dumazet@gmail.com>
> Date: Tue, 29 Sep 2015 18:52:25 -0700
>
> > From: Eric Dumazet <edumazet@google.com>
> >
> > 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>
>
> Applied, thanks Eric.
Hi David
This patch never reached a public net tree.
Should I respin it ?
Thanks !
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: add pfmemalloc check in sk_add_backlog()
2015-10-16 15:38 ` Eric Dumazet
@ 2015-10-17 12:02 ` David Miller
2015-10-17 16:04 ` Eric Dumazet
0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2015-10-17 12:02 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Fri, 16 Oct 2015 08:38:38 -0700
> On Tue, 2015-09-29 at 21:56 -0700, David Miller wrote:
>> From: Eric Dumazet <eric.dumazet@gmail.com>
>> Date: Tue, 29 Sep 2015 18:52:25 -0700
>>
>> > From: Eric Dumazet <edumazet@google.com>
>> >
>> > 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>
>>
>> Applied, thanks Eric.
>
> Hi David
>
> This patch never reached a public net tree.
>
> Should I respin it ?
Sorry I've been meaning to go back and apply it properly. I'll do that right
now...
There, done and properly queued up for -stable too. :)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: add pfmemalloc check in sk_add_backlog()
2015-10-17 12:02 ` David Miller
@ 2015-10-17 16:04 ` Eric Dumazet
0 siblings, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2015-10-17 16:04 UTC (permalink / raw)
To: David Miller; +Cc: netdev
On Sat, 2015-10-17 at 05:02 -0700, David Miller wrote:
> Sorry I've been meaning to go back and apply it properly. I'll do that right
> now...
>
> There, done and properly queued up for -stable too. :)
>
Perfect, thanks a lot David.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-10-17 16:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-30 1:52 [PATCH net] net: add pfmemalloc check in sk_add_backlog() Eric Dumazet
2015-09-30 4:56 ` David Miller
2015-10-02 9:38 ` Eric Dumazet
2015-10-16 15:38 ` Eric Dumazet
2015-10-17 12:02 ` David Miller
2015-10-17 16:04 ` Eric Dumazet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).