netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <kernel@kyup.com>
To: kadlec@blackhole.kfki.hu, eric.dumazet@gmail.com
Cc: netfilter-devel@vger.kernel.org, pablo@netfilter.org,
	davem@davemloft.net, netdev@vger.kernel.org,
	operations@siteground.com
Subject: [PATCH v3] netfilter: ipset: Fix sleeping memory allocation in atomic context
Date: Fri, 16 Oct 2015 09:40:28 +0300	[thread overview]
Message-ID: <1444977628-19323-1-git-send-email-kernel@kyup.com> (raw)

Commit 00590fdd5be0 introduced RCU locking in list type and in
doing so introduced a memory allocation in list_set_add, which 
is done in an atomic context, due to the fact that ipset rcu 
list modifications are serialised with a spin lock. The reason 
why we can't use a mutex is that in addition to modifying the 
list with ipset commands, it's also being modified when a
particular ipset rule timeout expires aka garbage collection. 
This gc is triggered from set_cleanup_entries, which in turn 
is invoked from a timer thus requiring the lock to be bh-safe. 

Concretely the following call chain can lead to "sleeping function
called in atomic context" splat: 
call_ad -> list_set_uadt -> list_set_uadd -> kzalloc(, GFP_KERNEL).
And since GFP_KERNEL allows initiating direct reclaim thus
potentially sleeping in the allocation path.

To fix the issue change the allocation type to GFP_ATOMIC, to
correctly reflect that it is occuring in an atomic context.

Fixes: 00590fdd5be0 ("netfilter: ipset: Introduce RCU locking in list type")

Acked-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: Nikolay Borisov <kernel@kyup.com>
---

Changes since v2:
 * Massaged the changelog to reflect discussion 
 on the mailing list

Changes since v1: 
 * Added acked-by 
 * Fixed patch header

 

 net/netfilter/ipset/ip_set_list_set.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/ipset/ip_set_list_set.c b/net/netfilter/ipset/ip_set_list_set.c
index a1fe537..5a30ce6 100644
--- a/net/netfilter/ipset/ip_set_list_set.c
+++ b/net/netfilter/ipset/ip_set_list_set.c
@@ -297,7 +297,7 @@ list_set_uadd(struct ip_set *set, void *value, const struct ip_set_ext *ext,
 	      ip_set_timeout_expired(ext_timeout(n, set))))
 		n =  NULL;
 
-	e = kzalloc(set->dsize, GFP_KERNEL);
+	e = kzalloc(set->dsize, GFP_ATOMIC);
 	if (!e)
 		return -ENOMEM;
 	e->id = d->id;
-- 
2.5.0

             reply	other threads:[~2015-10-16  6:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-16  6:40 Nikolay Borisov [this message]
2015-10-16 11:58 ` [PATCH v3] netfilter: ipset: Fix sleeping memory allocation in atomic context Jozsef Kadlecsik
2015-10-17 10:59   ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1444977628-19323-1-git-send-email-kernel@kyup.com \
    --to=kernel@kyup.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=kadlec@blackhole.kfki.hu \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=operations@siteground.com \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).