netfilter: ipset fixes, second batch
Subsystems (2)
v2 cover netfilter: ipset fixes, second batch
Hi Pablo,
Here comes the reworked version of the patches, including the fixes of the relevant new issues sashiko complained about at the last review.
Best regards,
Jozsef
Jozsef Kadlecsik (9):
netfilter: ipset: Don't use test_bit() in lockless RCU readers in hash
types
netfilter: ipset: Don't use test_bit() in lockless RCU readers in
bitmap types
netfilter: ipset: fix order of kfree_rcu() and rcu_assign_pointer()
netfilter: ipset: Extend the rcu locked area properly
netfilter: ipset: exlude gc when resize is in progress
netfilter: ipset: fix potential double free at resize/del
netfilter: ipset: make sure gc is properly stopped
netfilter: ipset: fix potential torn read in reuse/forceadd cases
netfilter: ipset: rework cidr bookkeeping
include/linux/netfilter/ipset/ip_set.h | 11 +- net/netfilter/ipset/ip_set_bitmap_gen.h | 6 +- net/netfilter/ipset/ip_set_bitmap_ip.c | 6 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 6 +- net/netfilter/ipset/ip_set_bitmap_port.c | 6 +- net/netfilter/ipset/ip_set_core.c | 4 +- net/netfilter/ipset/ip_set_hash_gen.h | 118 ++++++++++++------- net/netfilter/ipset/ip_set_hash_ipportnet.c | 4 +- net/netfilter/ipset/ip_set_hash_net.c | 4 +- net/netfilter/ipset/ip_set_hash_netiface.c | 4 +- net/netfilter/ipset/ip_set_hash_netnet.c | 8 +- net/netfilter/ipset/ip_set_hash_netport.c | 4 +- net/netfilter/ipset/ip_set_hash_netportnet.c | 8 +- 13 files changed, 116 insertions(+), 73 deletions(-)
Signature · 1 line
2.39.5
PATCH v2 1/9 netfilter: ipset: Don't use test_bit() in lockless RCU readers in hash types
Sashiko pointed out that there are a few lockless RCU readers using test_bit() which is a relaxed atomic operation and provides no memory barrier guarantees. Use test_bit_acquire() instead where the operation may run parallel with add/del/gc, i.e. is not one from the next cases
- protected by region lock
- in a set destroy phase
- in a new/temporary set creation phase
Also, add missing smp_mb__[after|before]_atomic() operations.
--- net/netfilter/ipset/ip_set_hash_gen.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +6 -6
@@ -689,7 +689,7 @@ mtype_resize(struct ip_set *set, bool retried)continue ; pos =smp_load_acquire (&n->pos);for (j =0 ; j < pos; j++) { -if (!test_bit (j, n->used)) +if (!test_bit_acquire (j, n->used))continue ; data =ahash_data (n, j, dsize);if (SET_ELEM_EXPIRED (set, data))
@@ -826,7 +826,7 @@ mtype_ext_size(struct ip_set *set, u32 *elements, size_t *ext_size)continue ; pos =smp_load_acquire (&n->pos);for (j =0 ; j < pos; j++) { -if (!test_bit (j, n->used)) +if (!test_bit_acquire (j, n->used))continue ; data =ahash_data (n, j, set->dsize);if (!SET_ELEM_EXPIRED (set, data))
@@ -991,8 +991,8 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,/* Must come last for the case when timed out entry is reused */ if (SET_WITH_TIMEOUT (set))ip_set_timeout_set (ext_timeout (data, set), ext->timeout); -smp_mb__before_atomic ();/* Ensure all data writes are visible before updating position */ +smp_mb__before_atomic ();smp_store_release (&n->pos, npos);set_bit (j, n->used);if (old !=ERR_PTR (-ENOENT )) {
@@ -1201,7 +1201,7 @@ mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d,continue ; pos =smp_load_acquire (&n->pos);for (i =0 ; i < pos; i++) { -if (!test_bit (i, n->used)) +if (!test_bit_acquire (i, n->used))continue ; data =ahash_data (n, i, set->dsize);if (!mtype_data_equal (data, d, &multi))
@@ -1259,7 +1259,7 @@ mtype_test(struct ip_set *set, void *value, const struct ip_set_ext *ext, } pos =smp_load_acquire (&n->pos);for (i =0 ; i < pos; i++) { -if (!test_bit (i, n->used)) +if (!test_bit_acquire (i, n->used))continue ; data =ahash_data (n, i, set->dsize);if (!mtype_data_equal (data, d, &multi))
@@ -1396,7 +1396,7 @@ mtype_list(const struct ip_set *set,continue ; pos =smp_load_acquire (&n->pos);for (i =0 ; i < pos; i++) { -if (!test_bit (i, n->used)) +if (!test_bit_acquire (i, n->used))continue ; e =ahash_data (n, i, set->dsize);if (SET_ELEM_EXPIRED (set, e))
Signature · 1 line
2.39.5
PATCH v2 2/9 netfilter: ipset: Don't use test_bit() in lockless RCU readers in bitmap types
In reply to Jozsef KadlecsikThe pair of the patch "netfilter: ipset: Don't use test_bit() in lockless RCU readers in hash types" for the bitmap types.
--- net/netfilter/ipset/ip_set_bitmap_gen.h | 6 ++++-- net/netfilter/ipset/ip_set_bitmap_ip.c | 6 +++--- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 6 +++--- net/netfilter/ipset/ip_set_bitmap_port.c | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-)
net/netfilter/ipset/ip_set_bitmap_gen.h +4 -2
@@ -51,7 +51,7 @@ mtype_ext_cleanup(struct ip_set *set)u32 id;for (id =0 ; id < map->elements; id++) -if (test_bit (id, map->members)) +if (test_bit_acquire (id, map->members))ip_set_ext_destroy (set,get_ext (set, map, id)); }
@@ -165,6 +165,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,ip_set_init_skbinfo (ext_skbinfo (x, set), ext);/* Activate element */ +smp_mb__before_atomic ();set_bit (e->id, map->members); set->elements++;
@@ -219,7 +220,7 @@ mtype_list(const struct ip_set *set,cond_resched_rcu (); id = cb->args[IPSET_CB_ARG0 ]; x =get_ext (set, map, id); - if (!test_bit(id, map->members) || + if (!test_bit_acquire(id, map->members) || (SET_WITH_TIMEOUT(set) && #ifdef IP_SET_BITMAP_STORED_TIMEOUT mtype_is_filled(x) &&
@@ -278,6 +279,7 @@ mtype_gc(struct timer_list *t) x =get_ext (set, map, id);if (ip_set_timeout_expired (ext_timeout (x, set))) {clear_bit (id, map->members); +smp_mb__after_atomic ();ip_set_ext_destroy (set, x); set->elements--; }
net/netfilter/ipset/ip_set_bitmap_ip.c +3 -3
@@ -67,20 +67,20 @@ static int bitmap_ip_do_test(const struct bitmap_ip_adt_elem *e, struct bitmap_ip *map, size_t dsize) { - return !!test_bit(e->id, map->members); + return !!test_bit_acquire(e->id, map->members); }static int bitmap_ip_gc_test (u16 id,const struct bitmap_ip *map,size_t dsize) { -return !!test_bit (id, map->members); +return !!test_bit_acquire (id, map->members); }static int bitmap_ip_do_add (const struct bitmap_ip_adt_elem *e,struct bitmap_ip *map,u32 flags,size_t dsize) { -return !!test_bit (e->id, map->members); +return !!test_bit_acquire (e->id, map->members); } static int
net/netfilter/ipset/ip_set_bitmap_ipmac.c +3 -3
@@ -86,7 +86,7 @@ bitmap_ipmac_do_test(const struct bitmap_ipmac_adt_elem *e, {const struct bitmap_ipmac_elem *elem; -if (!test_bit (e->id, map->members)) +if (!test_bit_acquire (e->id, map->members))return 0 ; elem =get_const_elem (map->extensions, e->id, dsize);if (e->add_mac && elem->filled ==MAC_FILLED )
@@ -100,7 +100,7 @@ bitmap_ipmac_gc_test(u16 id, const struct bitmap_ipmac *map, size_t dsize) {const struct bitmap_ipmac_elem *elem; -if (!test_bit (id, map->members)) +if (!test_bit_acquire (id, map->members))return 0 ; elem =get_const_elem (map->extensions, id, dsize);/* Timer not started for the incomplete elements */
@@ -147,7 +147,7 @@ bitmap_ipmac_do_add(const struct bitmap_ipmac_adt_elem *e,struct bitmap_ipmac_elem *elem; elem =get_elem (map->extensions, e->id, dsize); -if (test_bit (e->id, map->members)) { +if (test_bit_acquire (e->id, map->members)) {if (elem->filled ==MAC_FILLED ) { if (e->add_mac && (flags & IPSET_FLAG_EXIST) &&
net/netfilter/ipset/ip_set_bitmap_port.c +3 -3
@@ -58,20 +58,20 @@ static int bitmap_port_do_test(const struct bitmap_port_adt_elem *e, const struct bitmap_port *map, size_t dsize) { - return !!test_bit(e->id, map->members); + return !!test_bit_acquire(e->id, map->members); }static int bitmap_port_gc_test (u16 id,const struct bitmap_port *map,size_t dsize) { -return !!test_bit (id, map->members); +return !!test_bit_acquire (id, map->members); }static int bitmap_port_do_add (const struct bitmap_port_adt_elem *e,struct bitmap_port *map,u32 flags,size_t dsize) { -return !!test_bit (e->id, map->members); +return !!test_bit_acquire (e->id, map->members); } static int
Signature · 1 line
2.39.5
PATCH v2 3/9 netfilter: ipset: fix order of kfree_rcu() and rcu_assign_pointer()
In reply to Jozsef KadlecsikSashiko pointed out that kfree_rcu() was called before rcu_assign_pointer() in handling the comment extension. Fix the order so that rcu_assign_pointer() called first.
--- net/netfilter/ipset/ip_set_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipset/ip_set_core.c +2 -2
@@ -351,8 +351,8 @@ ip_set_init_comment(struct ip_set *set, struct ip_set_comment *comment,if (unlikely (c)) { set->ext_size -=sizeof (*c) +strlen (c->str) +1 ; -kfree_rcu (c, rcu);rcu_assign_pointer (comment->c,NULL ); +kfree_rcu (c, rcu); }if (!len)return ;
@@ -393,8 +393,8 @@ ip_set_comment_free(struct ip_set *set, void *ptr)if (unlikely (!c))return ; set->ext_size -=sizeof (*c) +strlen (c->str) +1 ; -kfree_rcu (c, rcu);rcu_assign_pointer (comment->c,NULL ); +kfree_rcu (c, rcu); }typedef void (*destroyer )(struct ip_set *,void *);
Signature · 1 line
2.39.5
PATCH v2 4/9 netfilter: ipset: Extend the rcu locked area properly
In reply to Jozsef KadlecsikThe rcu locked areas not covered fully the parts which worked on the rcu protected pointers. Also, in hash gc we need to be rcu and not lock protected.
--- net/netfilter/ipset/ip_set_hash_gen.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +5 -7
@@ -569,8 +569,8 @@ mtype_gc(struct work_struct *work) set = gc->set; h = set->data; -spin_lock_bh (&set->lock); - t =ipset_dereference_set (h->table, set); +rcu_read_lock_bh (); + t =rcu_dereference_bh (h->table);atomic_inc (&t->uref); numof_locks =ahash_numof_locks (t->htable_bits); r = gc->region++;
@@ -580,7 +580,6 @@ mtype_gc(struct work_struct *work) next_run = (IPSET_GC_PERIOD (set->timeout) *HZ ) / numof_locks;if (next_run <HZ /10 ) next_run =HZ /10 ; -spin_unlock_bh (&set->lock);mtype_gc_do (set, h, t, r);
@@ -588,6 +587,7 @@ mtype_gc(struct work_struct *work)pr_debug ("Table destroy after resize by expire: %p\n" , t);mtype_ahash_destroy (set, t, false); } +rcu_read_unlock_bh ();queue_delayed_work (system_power_efficient_wq, &gc->dwork, next_run);
@@ -865,9 +865,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (elements >= maxelem) {u32 e;if (SET_WITH_TIMEOUT (set)) { -rcu_read_unlock_bh ();mtype_gc_do (set, h, t, r); -rcu_read_lock_bh (); } maxelem = h->maxelem; elements =0 ;
@@ -876,7 +874,6 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (elements >= maxelem &&SET_WITH_FORCEADD (set)) forceadd = true; } -rcu_read_unlock_bh ();spin_lock_bh (&t->hregion[r].lock); n =rcu_dereference_bh (hbucket (t, key));
@@ -1034,6 +1031,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,pr_debug ("Table destroy after resize by add: %p\n" , t);mtype_ahash_destroy (set, t, false); } +rcu_read_unlock_bh ();return ret; }
@@ -1062,7 +1060,6 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, key =HKEY (value, h->initval, t->htable_bits); r =ahash_region (key);atomic_inc (&t->uref); -rcu_read_unlock_bh ();spin_lock_bh (&t->hregion[r].lock); n =rcu_dereference_bh (hbucket (t, key));
@@ -1148,6 +1145,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,pr_debug ("Table destroy after resize by del: %p\n" , t);mtype_ahash_destroy (set, t, false); } +rcu_read_unlock_bh ();return ret; }
Signature · 1 line
2.39.5
PATCH v2 5/9 netfilter: ipset: exlude gc when resize is in progress
In reply to Jozsef KadlecsikZhengchuan Liang reported that because resize does not copy the comment extension into the resized set but uses it's pointer, ongoing gc can free the extension in the original set which then results stale pointer in the resized one. The proposed patch was to recreate the extensions for every element in the resized set. It is both expensive and wastes memory, so better exclude gc when resizing in progress detected: resizing will destroy the original set anyway, so doing gc on it is unnecessary.
Reported by: Zhengchuan Liang <[email protected]> Reported by: Eulgyu Kim <[email protected]>
--- net/netfilter/ipset/ip_set_hash_gen.h | 8 ++++++++ 1 file changed, 8 insertions(+)
net/netfilter/ipset/ip_set_hash_gen.h +8 -0
@@ -84,6 +84,7 @@ struct htable {atomic_t uref;/* References for dumping and gc */ u8 htable_bits;/* size of hash table == 2^htable_bits */ u32 maxelem;/* Maxelem per region */ +spinlock_t gc_lock;/* Lock to exclude gc and resize */ struct ip_set_region *hregion;/* Region locks and ext sizes */ struct hbucket __rcu *bucket[];/* hashtable buckets */ };
@@ -581,7 +582,9 @@ mtype_gc(struct work_struct *work)if (next_run <HZ /10 ) next_run =HZ /10 ; +spin_lock_bh (&t->gc_lock);mtype_gc_do (set, h, t, r); +spin_unlock_bh (&t->gc_lock);if (atomic_dec_and_test (&t->uref) &&atomic_read (&t->ref)) {pr_debug ("Table destroy after resize by expire: %p\n" , t);
@@ -646,6 +649,7 @@ mtype_resize(struct ip_set *set, bool retried)#endif orig =ipset_dereference_bh_nfnl (h->table); htable_bits = orig->htable_bits; +spin_lock_bh (&orig->gc_lock); retry: ret =0 ;
@@ -759,6 +763,8 @@ mtype_resize(struct ip_set *set, bool retried)/* There can't be any other writer. */ rcu_assign_pointer (h->table, t); +spin_unlock_bh (&orig->gc_lock); +/* Give time to other readers of the set */ synchronize_rcu ();
@@ -797,6 +803,7 @@ mtype_resize(struct ip_set *set, bool retried)mtype_ahash_destroy (set, t, false);if (ret == -EAGAIN ) goto retry; +spin_unlock_bh (&orig->gc_lock); goto out; hbwarn:
@@ -1617,6 +1624,7 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set, } t->htable_bits = hbits; t->maxelem = h->maxelem /ahash_numof_locks (hbits); +spin_lock_init (&t->gc_lock);RCU_INIT_POINTER (h->table, t);INIT_LIST_HEAD (&h->ad);
Signature · 1 line
2.39.5
Re: [PATCH v2 5/9] netfilter: ipset: exlude gc when resize is in progress
Hi Jozsef,
While reviewing this patch on Sashiko [1], I found it introduces a "scheduling while atomic" bug in mtype_resize(). Sashiko's automated review flagged the issue, and I was able to confirm it with a PoC that reliably triggers the kernel splat.
[1] https://sashiko.dev/#/patchset/20260609072750.318774-1-kadlec%40netfilter.org
Quoted 5 lines
net/netfilter/ipset/ip_set_hash_gen.h +0
-0@@ -84,6 +84,7 @@ struct htable {
Quoted 7 lines
atomic_turef; /* References for dumping and gc */ u8 htable_bits; /* size of hash table == 2^htable_bits */ u32 maxelem; /* Maxelem per region */
+spinlock_tgc_lock; /* Lock to exclude gc and resize */ structip_set_region*hregion; /* Region locks and ext sizes */ struct hbucket__rcu*bucket[]; /* hashtable buckets */ };
The new gc_lock is added to struct htable but correctly initialized in _create() via spin_lock_init(), so this part is fine.
net/netfilter/ipset/ip_set_hash_gen.h mtype_gc(struct work_struct *work) · line 590
Quoted 10 lines
net/netfilter/ipset/ip_set_hash_gen.h +2
-0@@ -581,7 +582,9 @@ mtype_gc(struct work_struct *work) if (next_run < HZ/10) next_run = HZ/10; + spin_lock_bh(&t->gc_lock); mtype_gc_do(set, h, t, r); + spin_unlock_bh(&t->gc_lock); if (atomic_dec_and_test(&t->uref) && atomic_read(&t->ref)) { pr_debug("Table destroy after resize by expire: %p\n", t);
mtype_gc() is fine — it does not allocate memory under the lock.
Quoted 8 lines
net/netfilter/ipset/ip_set_hash_gen.h +1
-0@@ -646,6 +649,7 @@ mtype_resize(struct ip_set *set, bool retried) #endif orig = ipset_dereference_bh_nfnl(h->table); htable_bits = orig->htable_bits; + spin_lock_bh(&orig->gc_lock);retry:
ret = 0;
The problem is here. spin_lock_bh() disables preemption and bottom halves, putting us in atomic context. Shortly after this, the function calls:
t = ip_set_alloc(hsize);
which eventually does kvzalloc(size, GFP_KERNEL_ACCOUNT). GFP_KERNEL allocations are sleepable — they can trigger direct reclaim or wait for memory to become available. Calling a sleepable function while holding a spinlock triggers:
BUG: sleeping function called from invalid context
This is reliably reproducible with the PoC below. spin_lock_bh() and GFP_KERNEL allocations are fundamentally incompatible.
Quoted 16 lines
net/netfilter/ipset/ip_set_hash_gen.h +3
-0@@ -759,6 +763,8 @@ mtype_resize(struct ip_set *set, bool retried) /* There can't be any other writer. */ rcu_assign_pointer(h->table, t); + spin_unlock_bh(&orig->gc_lock); + /* Give time to other readers of the set */ synchronize_rcu();@@ -797,6 +803,7 @@ mtype_resize(struct ip_set *set, bool retried) mtype_ahash_destroy(set, t, false); if (ret == -EAGAIN) goto retry; + spin_unlock_bh(&orig->gc_lock); goto out;
Quoted 1 line
hbwarn:
Note that the hbwarn error path bypasses the newly added spin_unlock_bh(), leaving the lock held on return. That's a separate issue, but worth fixing too.
net/netfilter/ipset/ip_set_hash_gen.h IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set, · line 1630
Quoted 8 lines
net/netfilter/ipset/ip_set_hash_gen.h +1
-0@@ -1617,6 +1624,7 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set, } t->htable_bits = hbits; t->maxelem = h->maxelem / ahash_numof_locks(hbits); + spin_lock_init(&t->gc_lock); RCU_INIT_POINTER(h->table, t); INIT_LIST_HEAD(&h->ad);
## Reproducer
The PoC below creates a hash:ip set with a small hashsize, then adds enough IPs to overflow buckets and force a resize, hitting the sleep-in-atomic path. Generated and verified via Sashiko's kernel testing framework.
Build: gcc -static -o poc poc.c
Run: ./poc (as root or with CAP_NET_ADMIN)
Check: dmesg | grep "sleeping function called from invalid context"
/* PoC: trigger scheduling while atomic in mtype_resize()
*
* Commit be2a510ec367 ("netfilter: ipset: exlude gc when resize is in
* progress") adds spin_lock_bh(&orig->gc_lock) in mtype_resize(), then
* calls ip_set_alloc() which uses kvzalloc(GFP_KERNEL). Since
* spin_lock_bh disables preemption, the sleepable GFP_KERNEL allocation
* triggers "BUG: sleeping function called from invalid context". *
* Build: gcc -static -o poc poc.c
* Run: ./poc (as root or with CAP_NET_ADMIN)
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/netlink.h>
#include <linux/netfilter/nfnetlink.h>
#include <linux/netfilter/ipset/ip_set.h>
#define A4(x) (((x) + 3) & ~3)
int main(void)
{
struct sockaddr_nl sa = { .nl_family = AF_NETLINK };
int fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_NETFILTER);
if (fd < 0) { perror("socket"); return 1; }
bind(fd, (struct sockaddr *)&sa, sizeof(sa));
char msg[4096];
unsigned char *b = (unsigned char *)msg;
char rsp[8192];
int o, ds, ips, r, i;
/* ---- IPSET_CMD_CREATE: hash:ip set 'h' ---- */ memset(msg, 0, sizeof(msg));
b[0] = 2; b[1] = 0; b[2] = 0; b[3] = 0; o = 4;
o = A4(o);
b[o] = 5; b[o + 1] = 0; b[o + 2] = 1; b[o + 3] = 0; b[o + 4] = 7; o += 5;
o = A4(o);
b[o] = 6; b[o + 1] = 0; b[o + 2] = 2; b[o + 3] = 0; b[o + 4] = 'h'; b[o + 5] = 0; o += 6;
o = A4(o);
b[o] = 12; b[o + 1] = 0; b[o + 2] = 3; b[o + 3] = 0; memcpy(b + o + 4, "hash:ip", 8); o += 12;
o = A4(o);
b[o] = 5; b[o + 1] = 0; b[o + 2] = 4; b[o + 3] = 0; b[o + 4] = 0; o += 5;
o = A4(o);
b[o] = 5; b[o + 1] = 0; b[o + 2] = 5; b[o + 3] = 0; b[o + 4] = 2; o += 5;
o = A4(o); ds = o; o += 4;
/* hashsize = 8 (small, so buckets overflow quickly -> resize) */
o = A4(o); {
__be32 v = htonl(8);
b[o] = 8; b[o + 1] = 0; b[o + 2] = 18; b[o + 3] = 0; memcpy(b + o + 4, &v, 4); o += 8;
}
/* maxelem = 1000000 */
o = A4(o); {
__be32 v = htonl(1000000);
b[o] = 8; b[o + 1] = 0; b[o + 2] = 19; b[o + 3] = 0; memcpy(b + o + 4, &v, 4); o += 8;
}
o = A4(o); b[ds] = o - ds; b[ds + 1] = 0;
b[ds + 2] = 7 | 0x80; b[ds + 3] = 0;
struct nlmsghdr nlh = {0};
int al = A4(o);
nlh.nlmsg_len = A4((int)sizeof(nlh)) + al; nlh.nlmsg_type = (NFNL_SUBSYS_IPSET << 8) | IPSET_CMD_CREATE; nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE; nlh.nlmsg_seq = 1;
struct iovec iov[2];
struct msghdr mh = {0};
iov[0].iov_base = &nlh;
iov[0].iov_len = A4((int)sizeof(nlh));
iov[1].iov_base = msg;
iov[1].iov_len = al;
mh.msg_name = &sa;
mh.msg_namelen = sizeof(sa);
mh.msg_iov = iov;
mh.msg_iovlen = 2;
sendmsg(fd, &mh, 0);
r = recv(fd, rsp, sizeof(rsp), 0);
if (r > 0) {
struct nlmsghdr *hdr = (struct nlmsghdr *)rsp;
if (hdr->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *e = (struct nlmsgerr *)NLMSG_DATA(hdr); if (e->error) {
printf("ERR %d\n", e->error);
close(fd);
return 1;
}
}
}
printf("[*] Hash:ip set 'h' created (hashsize=8).\n");
/* ---- Add 25000 IPs to trigger bucket overflow -> resize ---- */ printf("[*] Adding 25000 IPs to trigger resize...\n"); for (i = 0; i < 25000; i++) {
/* Cycle through 10000 unique IPs: 11.0.0.1 .. 11.0.39.16 */ __be32 ip = htonl(0x0b000000 + (i % 10000) + 1);
memset(msg, 0, sizeof(msg));
b[0] = 2; b[1] = 0; b[2] = 0; b[3] = 0; o = 4;
o = A4(o);
b[o] = 5; b[o + 1] = 0; b[o + 2] = 1; b[o + 3] = 0; b[o + 4] = 7; o += 5;
o = A4(o);
b[o] = 6; b[o + 1] = 0; b[o + 2] = 2; b[o + 3] = 0; b[o + 4] = 'h'; b[o + 5] = 0; o += 6;
o = A4(o); ds = o;
b[ds + 2] = 7; b[ds + 3] = 0x80; o += 4;
o = A4(o); ips = o;
b[ips + 2] = 1; b[ips + 3] = 0x80; o += 4;
o = A4(o);
b[o] = 8; b[o + 1] = 0; b[o + 2] = 1; b[o + 3] = 0x40; memcpy(b + o + 4, &ip, 4); o += 8;
o = A4(o);
b[ips] = o - ips; b[ips + 1] = 0;
b[ds] = o - ds; b[ds + 1] = 0;
int a2 = A4(o);
nlh.nlmsg_len = A4((int)sizeof(nlh)) + a2; nlh.nlmsg_type = (NFNL_SUBSYS_IPSET << 8) | IPSET_CMD_ADD; nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; nlh.nlmsg_seq = i + 2;
iov[1].iov_len = a2;
sendmsg(fd, &mh, 0);
r = recv(fd, rsp, sizeof(rsp), 0);
if (r > 0) {
struct nlmsghdr *hdr = (struct nlmsghdr *)rsp; if (hdr->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *e = (struct nlmsgerr *)NLMSG_DATA(hdr); if (e->error) {
printf("[!] %d err %d\n", i, e->error); if (e->error == -EAGAIN)
printf("*** EAGAIN - check dmesg ***\n"); break;
}
}
}
if (i % 2000 == 1999)
printf(" %d/25000\n", i + 1);
}
printf("[*] Done. Check dmesg.\n");
close(fd);
return 0;
}
## Kernel Splat
Running the PoC on 7.1.0-rc5 with this patch applied:
[ 4605.426526][T10324] BUG: sleeping function called from invalid context at include/linux/sched/mm.h:323
[ 4605.429032][T10324] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 10324, name: poc
[ 4605.430595][T10324] preempt_count: 201, expected: 0
[ 4605.432432][T10324] 2 locks held by poc/10324:
[ 4605.433263][T10324] #0: ffffffff9bc4e600 (nfnl_subsys_ipset){+.+.}-{4:4}, at: nfnetlink_rcv_msg+0x8ba/0x11f0
[ 4605.435525][T10324] #1: ffff888115560028 (&t->gc_lock){+...}-{3:3}, at: hash_ip4_resize+0x1a4/0x1c60
[ 4605.438773][T10324] CPU: 1 UID: 0 PID: 10324 Comm: poc Not tainted 7.1.0-rc5-gd81b843c2589 #1 PREEMPT(full)
[ 4605.438802][T10324] Call Trace:
[ 4605.438808][T10324] <TASK>
[ 4605.438814][T10324] dump_stack_lvl+0x16c/0x1f0
[ 4605.439190][T10324] __might_resched+0x3c5/0x5e0
[ 4605.439606][T10324] __kvmalloc_node_noprof+0x63f/0x920
[ 4605.439653][T10324] hash_ip4_resize+0x103a/0x1c60
[ 4605.439771][T10324] call_ad.constprop.0+0x372/0x950
[ 4605.439917][T10324] ip_set_ad.constprop.0.isra.0+0x3d3/0x880
[ 4605.440032][T10324] nfnetlink_rcv_msg+0x9e2/0x11f0
[ 4605.440164][T10324] netlink_rcv_skb+0x15d/0x430
[ 4605.440261][T10324] nfnetlink_rcv+0x1b8/0x430
[ 4605.440325][T10324] netlink_unicast+0x592/0x860
[ 4605.440385][T10324] netlink_sendmsg+0x8cd/0xdd0
[ 4605.440449][T10324] ____sys_sendmsg+0x9ec/0xb80
[ 4605.440595][T10324] ___sys_sendmsg+0x139/0x1e0
[ 4605.440682][T10324] __sys_sendmsg+0x172/0x220
[ 4605.440753][T10324] do_syscall_64+0x129/0x850
[ 4605.440770][T10324] entry_SYSCALL_64_after_hwframe+0x77/0x7f
[ 4605.440888][T10324] </TASK>The call chain is: hash_ip4_resize (holds &t->gc_lock) -> __kvmalloc_node_noprof (GFP_KERNEL) -> __might_resched -> BUG.
## Suggested Fix
Move the memory allocations before acquiring gc_lock, so the lock only protects the section where pointers are copied:
net/netfilter/ipset/ip_set_hash_gen.h +0 -0
@@ -657,12 +657,11 @@ mtype_resize(struct ip_set *set, bool retried)
orig = ipset_dereference_bh_nfnl(h->table);
htable_bits = orig->htable_bits;
- spin_lock_bh(&orig->gc_lock);
retry:
ret = 0;
t = ip_set_alloc(hsize);
if (!t) {
ret = -ENOMEM;
goto out;
}
t->hregion = ip_set_alloc(ahash_sizeof_regions(htable_bits)); if (!t->hregion) {
kvfree(t);
ret = -ENOMEM;
goto out;
}
+
+ spin_lock_bh(&orig->gc_lock);
/* ... copy elements from orig to t under gc_lock ... */
+ spin_unlock_bh(&orig->gc_lock);
mtype_ahash_destroy(set, orig, false);
Alternatively, if the allocations must remain under the lock, use GFP_ATOMIC and handle the NULL return gracefully.
Thanks,
Xiao
---
[1] Sashiko found this issue during automated patch review. Full results, including the PoC, kernel config, and raw serial log:
https://sashiko.dev/#/patchset/20260609072750.318774-1-kadlec%40netfilter.org
Re: [PATCH v2 5/9] netfilter: ipset: exlude gc when resize is in progress
Hi,
Quoted 4 lines · XIAO WU
While reviewing this patch on Sashiko [1], I found it introduces a "scheduling while atomic" bug in mtype_resize(). Sashiko's automated review flagged the issue, and I was able to confirm it with a PoC that reliably triggers the kernel splat.
Yes, a respin of the patches are required. Thanks for the thorough report!
Best regards,
Jozsef
Quoted 359 lines
[1]
https://sashiko.dev/#/patchset/20260609072750.318774-1-kadlec%40netfilter.orgReview
Quoted 1 line
(quoted diff) +0
-0
b/net/netfilter/ipset/ip_set_hash_gen.hQuoted 11 lines
index
20678116a..a41f6cdee100644net/netfilter/ipset/ip_set_hash_gen.h +0
-0@@ -84,6 +84,7 @@ struct htable {
atomic_turef; /* References for dumping and gc */ u8 htable_bits; /* size of hash table == 2^htable_bits */ u32 maxelem; /* Maxelem per region */
+spinlock_tgc_lock; /* Lock to exclude gc and resize */ structip_set_region*hregion; /* Region locks and ext sizes */ struct hbucket__rcu*bucket[]; /* hashtable buckets */ };The new
gc_lockis added to struct htable but correctly initialized in_create()viaspin_lock_init(), so this part is fine.net/netfilter/ipset/ip_set_hash_gen.h mtype_gc(struct work_struct *work) · line 590
Quoted 10 lines
net/netfilter/ipset/ip_set_hash_gen.h +2
-0@@ -581,7 +582,9 @@ mtype_gc(struct work_struct *work) if (next_run < HZ/10) next_run = HZ/10; + spin_lock_bh(&t->gc_lock); mtype_gc_do(set, h, t, r); + spin_unlock_bh(&t->gc_lock); if (atomic_dec_and_test(&t->uref) && atomic_read(&t->ref)) { pr_debug("Table destroy after resize by expire: %p\n", t);
mtype_gc()is fine — it does not allocate memory under the lock.Quoted 8 lines
net/netfilter/ipset/ip_set_hash_gen.h +1
-0@@ -646,6 +649,7 @@ mtype_resize(struct ip_set *set, bool retried) #endif orig = ipset_dereference_bh_nfnl(h->table); htable_bits = orig->htable_bits; + spin_lock_bh(&orig->gc_lock);retry:
ret = 0;The problem is here.
spin_lock_bh()disables preemption and bottom halves, putting us in atomic context. Shortly after this, the function calls:t =
ip_set_alloc(hsize);which eventually does
kvzalloc(size, GFP_KERNEL_ACCOUNT).GFP_KERNELallocations are sleepable — they can trigger direct reclaim or wait for memory to become available. Calling a sleepable function while holding a spinlock triggers:BUG: sleeping function called from invalid contextThis is reliably reproducible with the PoC below.
spin_lock_bh()andGFP_KERNELallocations are fundamentally incompatible.Quoted 16 lines
net/netfilter/ipset/ip_set_hash_gen.h +3
-0@@ -759,6 +763,8 @@ mtype_resize(struct ip_set *set, bool retried) /* There can't be any other writer. */ rcu_assign_pointer(h->table, t); + spin_unlock_bh(&orig->gc_lock); + /* Give time to other readers of the set */ synchronize_rcu();@@ -797,6 +803,7 @@ mtype_resize(struct ip_set *set, bool retried) mtype_ahash_destroy(set, t, false); if (ret == -EAGAIN) goto retry; + spin_unlock_bh(&orig->gc_lock); goto out;Quoted 1 line
hbwarn:
Note that the hbwarn error path bypasses the newly added
spin_unlock_bh(), leaving the lock held on return. That's a separate issue, but worth fixing too.net/netfilter/ipset/ip_set_hash_gen.h IPSET_TOKEN(HTYPE, _create)(struct net *net, struct
Quoted 1 line
net/netfilter/ipset/ip_set_hash_gen.h +0
-0@@ -1617,6 +1624,7 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct
ip_set*set,net/netfilter/ipset/ip_set_hash_gen.h IPSET_TOKEN(HTYPE, _create)(struct net *net, struct · line 1630
Quoted 7 lines
net/netfilter/ipset/ip_set_hash_gen.h +1
-0} t->htable_bits = hbits; t->maxelem = h->maxelem / ahash_numof_locks(hbits); + spin_lock_init(&t->gc_lock); RCU_INIT_POINTER(h->table, t); INIT_LIST_HEAD(&h->ad);## Reproducer
The PoC below creates a hash:ip set with a small hashsize, then adds enough IPs to overflow buckets and force a resize, hitting the sleep-in-atomic path. Generated and verified via Sashiko's kernel testing framework.
Build: gcc -static -o poc
poc.c
Run: ./poc (as root or withCAP_NET_ADMIN)
Check: dmesg | grep "sleeping function called from invalid context"/* PoC: trigger scheduling while atomic in
mtype_resize()
*
* Commitbe2a510ec367("netfilter: ipset: exlude gc when resize is in
* progress") addsspin_lock_bh(&orig->gc_lock)inmtype_resize(), then
* callsip_set_alloc()which uses kvzalloc(GFP_KERNEL). Since
*spin_lock_bhdisables preemption, the sleepableGFP_KERNELallocation
* triggers "BUG: sleeping function called from invalid context". *
* Build: gcc -static -o pocpoc.c
* Run: ./poc (as root or withCAP_NET_ADMIN)
*/
#define_GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/netlink.h>
#include <linux/netfilter/nfnetlink.h>
#include <linux/netfilter/ipset/ip_set.h>#define A4(x) (((x) + 3) & ~3)
int main(void)
{
structsockaddr_nlsa = { .nl_family =AF_NETLINK};
int fd =socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_NETFILTER);if (fd < 0) {
perror("socket"); return 1; }
bind(fd, (struct sockaddr *)&sa, sizeof(sa));char msg[4096];
unsigned char *b = (unsigned char *)msg;
char rsp[8192];
int o, ds, ips, r, i;/* ----
IPSET_CMD_CREATE: hash:ip set 'h' ---- */memset(msg, 0, sizeof(msg));
b[0] = 2; b[1] = 0; b[2] = 0; b[3] = 0; o = 4;o = A4(o);
b[o] = 5; b[o + 1] = 0; b[o + 2] = 1; b[o + 3] = 0; b[o + 4] = 7; o += 5;o = A4(o);
b[o] = 6; b[o + 1] = 0; b[o + 2] = 2; b[o + 3] = 0; b[o + 4] = 'h'; b[o + 5] = 0; o += 6;o = A4(o);
b[o] = 12; b[o + 1] = 0; b[o + 2] = 3; b[o + 3] = 0;memcpy(b + o + 4, "hash:ip", 8); o += 12;o = A4(o);
b[o] = 5; b[o + 1] = 0; b[o + 2] = 4; b[o + 3] = 0; b[o + 4] = 0; o += 5;o = A4(o);
b[o] = 5; b[o + 1] = 0; b[o + 2] = 5; b[o + 3] = 0; b[o + 4] = 2; o += 5;o = A4(o); ds = o; o += 4;
/* hashsize = 8 (small, so buckets overflow quickly -> resize) */
o = A4(o); {
__be32v = htonl(8);
b[o] = 8; b[o + 1] = 0; b[o + 2] = 18; b[o + 3] = 0;memcpy(b + o + 4, &v, 4); o += 8;
}
/* maxelem = 1000000 */
o = A4(o); {
__be32v = htonl(1000000);
b[o] = 8; b[o + 1] = 0; b[o + 2] = 19; b[o + 3] = 0;memcpy(b + o + 4, &v, 4); o += 8;
}o = A4(o); b[ds] = o - ds; b[ds + 1] = 0;
b[ds + 2] = 7 |0x80; b[ds + 3] = 0;struct nlmsghdr nlh = {0};
int al = A4(o);nlh.nlmsg_len = A4((int)sizeof(nlh)) + al; nlh.nlmsg_type = (
NFNL_SUBSYS_IPSET<< 8) |IPSET_CMD_CREATE; nlh.nlmsg_flags =NLM_F_REQUEST|NLM_F_ACK|NLM_F_CREATE; nlh.nlmsg_seq = 1;struct iovec iov[2];
struct msghdr mh = {0};
iov[0].iov_base = &nlh;
iov[0].iov_len = A4((int)sizeof(nlh));
iov[1].iov_base = msg;
iov[1].iov_len = al;
mh.msg_name = &sa;
mh.msg_namelen = sizeof(sa);
mh.msg_iov = iov;
mh.msg_iovlen = 2;
sendmsg(fd, &mh, 0);
r =recv(fd, rsp, sizeof(rsp), 0);
if (r > 0) {
struct nlmsghdr *hdr = (struct nlmsghdr *)rsp;
if (hdr->nlmsg_type==NLMSG_ERROR) {
struct nlmsgerr *e = (struct nlmsgerr *)NLMSG_DATA(hdr); if (e->error) {
printf("ERR %d\n", e->error);
close(fd);
return 1;
}
}
}
printf("[*] Hash:ip set 'h' created (hashsize=8).\n");/* ---- Add 25000 IPs to trigger bucket overflow -> resize ---- */
printf("[*] Adding 25000 IPs to trigger resize...\n"); for (i = 0; i < 25000; i++) {
/* Cycle through 10000 unique IPs: 11.0.0.1 .. 11.0.39.16 */__be32ip = htonl(0x0b000000 + (i % 10000) + 1);
memset(msg, 0, sizeof(msg));
b[0] = 2; b[1] = 0; b[2] = 0; b[3] = 0; o = 4;o = A4(o);
b[o] = 5; b[o + 1] = 0; b[o + 2] = 1; b[o + 3] = 0; b[o + 4] = 7; o += 5;o = A4(o);
b[o] = 6; b[o + 1] = 0; b[o + 2] = 2; b[o + 3] = 0; b[o + 4] = 'h'; b[o + 5] = 0; o += 6;o = A4(o); ds = o;
b[ds + 2] = 7; b[ds + 3] =0x80; o += 4;o = A4(o); ips = o;
b[ips + 2] = 1; b[ips + 3] =0x80; o += 4;o = A4(o);
b[o] = 8; b[o + 1] = 0; b[o + 2] = 1; b[o + 3] =0x40;memcpy(b + o + 4, &ip, 4); o += 8;o = A4(o);
b[ips] = o - ips; b[ips + 1] = 0;
b[ds] = o - ds; b[ds + 1] = 0;int a2 = A4(o);
nlh.nlmsg_len = A4((int)sizeof(nlh)) + a2; nlh.nlmsg_type = (NFNL_SUBSYS_IPSET<< 8) |IPSET_CMD_ADD; nlh.nlmsg_flags =NLM_F_REQUEST|NLM_F_ACK; nlh.nlmsg_seq = i + 2;
iov[1].iov_len = a2;
sendmsg(fd, &mh, 0);
r =recv(fd, rsp, sizeof(rsp), 0);
if (r > 0) {
struct nlmsghdr *hdr = (struct nlmsghdr *)rsp; if (hdr->nlmsg_type==NLMSG_ERROR) {
struct nlmsgerr *e = (struct nlmsgerr *)NLMSG_DATA(hdr); if (e->error) {
printf("[!] %d err %d\n", i, e->error); if (e->error==-EAGAIN)
printf("*** EAGAIN - check dmesg ***\n"); break;
}
}
}
if (i % 2000 == 1999)
printf(" %d/25000\n", i + 1);
}printf("[*] Done. Check dmesg.\n");
close(fd);
return 0;
}## Kernel Splat
Running the PoC on 7.1.0-rc5 with this patch applied:
[ 4605.426526][T10324] BUG: sleeping function called from invalid context at include/linux/sched/mm.h:323 [ 4605.429032][T10324] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 10324, name: poc [ 4605.430595][T10324] preempt_count: 201, expected: 0 [ 4605.432432][T10324] 2 locks held by poc/10324: [ 4605.433263][T10324] #0: ffffffff9bc4e600 (nfnl_subsys_ipset){+.+.}-{4:4}, at: nfnetlink_rcv_msg+0x8ba/0x11f0 [ 4605.435525][T10324] #1: ffff888115560028 (&t->gc_lock){+...}-{3:3}, at: hash_ip4_resize+0x1a4/0x1c60 [ 4605.438773][T10324] CPU: 1 UID: 0 PID: 10324 Comm: poc Not tainted 7.1.0-rc5-gd81b843c2589 #1 PREEMPT(full) [ 4605.438802][T10324] Call Trace: [ 4605.438808][T10324] <TASK> [ 4605.438814][T10324] dump_stack_lvl+0x16c/0x1f0 [ 4605.439190][T10324] __might_resched+0x3c5/0x5e0 [ 4605.439606][T10324] __kvmalloc_node_noprof+0x63f/0x920 [ 4605.439653][T10324] hash_ip4_resize+0x103a/0x1c60 [ 4605.439771][T10324] call_ad.constprop.0+0x372/0x950 [ 4605.439917][T10324] ip_set_ad.constprop.0.isra.0+0x3d3/0x880 [ 4605.440032][T10324] nfnetlink_rcv_msg+0x9e2/0x11f0 [ 4605.440164][T10324] netlink_rcv_skb+0x15d/0x430 [ 4605.440261][T10324] nfnetlink_rcv+0x1b8/0x430 [ 4605.440325][T10324] netlink_unicast+0x592/0x860 [ 4605.440385][T10324] netlink_sendmsg+0x8cd/0xdd0 [ 4605.440449][T10324] ____sys_sendmsg+0x9ec/0xb80 [ 4605.440595][T10324] ___sys_sendmsg+0x139/0x1e0 [ 4605.440682][T10324] __sys_sendmsg+0x172/0x220 [ 4605.440753][T10324] do_syscall_64+0x129/0x850 [ 4605.440770][T10324] entry_SYSCALL_64_after_hwframe+0x77/0x7f [ 4605.440888][T10324] </TASK>The call chain is:
hash_ip4_resize(holds&t->gc_lock) ->__kvmalloc_node_noprof(GFP_KERNEL) ->__might_resched-> BUG.## Suggested Fix
Move the memory allocations before acquiring
gc_lock, so the lock only protects the section where pointers are copied:net/netfilter/ipset/ip_set_hash_gen.h +0
-1@@ -657,12 +657,11 @@ mtype_resize(struct ip_set *set, bool retried) orig = ipset_dereference_bh_nfnl(h->table); htable_bits = orig->htable_bits; - spin_lock_bh(&orig->gc_lock);retry:
ret = 0;t =
ip_set_alloc(hsize);
if (!t) {
ret =-ENOMEM;
goto out;
}t->hregion = ip_set_alloc(ahash_sizeof_regions(htable_bits)); if (!t->hregion) {
kvfree(t);
ret =-ENOMEM;
goto out;
}
+
+spin_lock_bh(&orig->gc_lock);/* ... copy elements from orig to t under
gc_lock... */+
spin_unlock_bh(&orig->gc_lock);
mtype_ahash_destroy(set, orig, false);Alternatively, if the allocations must remain under the lock, use
GFP_ATOMICand handle the NULL return gracefully.Thanks,
Xiao---
[1] Sashiko found this issue during automated patch review. Full results, including the PoC, kernel config, and raw serial log:
https://sashiko.dev/#/patchset/20260609072750.318774-1-kadlec%40netfilter.org
Signature · 3 lines
E-mail : [email protected], [email protected], [email protected] Address: Wigner Research Centre for Physics H-1525 Budapest 114, POB. 49, Hungary
PATCH v2 6/9 netfilter: ipset: fix potential double free at resize/del
In reply to Jozsef KadlecsikWhen resizing is in progress, kernel side del element operations performed on the original set are saved in a list and replayed on the new set after resize finished. Make sure extensions are not freed when replaying the deletion of the given elements.
Issue was discovered by sashiko.
--- include/linux/netfilter/ipset/ip_set.h | 11 +++++++++-- net/netfilter/ipset/ip_set_hash_gen.h | 10 ++++++---- 2 files changed, 15 insertions(+), 6 deletions(-)
include/linux/netfilter/ipset/ip_set.h +9 -2
@@ -113,6 +113,12 @@ struct ip_set_skbinfo {u16 __pad; }; +enum ip_set_ext_context { +IPSET_EXT_CONTEXT_NONE =0 , +IPSET_EXT_CONTEXT_TARGET =1 , +IPSET_EXT_CONTEXT_REPLAY =2 , +}; +struct ip_set_ext {struct ip_set_skbinfo skbinfo;u64 packets;
@@ -121,7 +127,7 @@ struct ip_set_ext {u32 timeout;u8 packets_op;u8 bytes_op; -bool target; +u8 context; };#define ext_timeout (e, s) \
@@ -530,7 +536,8 @@ nf_inet_addr_mask_inplace(union nf_inet_addr *a1, }#define IP_SET_INIT_KEXT (skb, opt, set) \ - { .bytes = (skb)->len, .packets = 1, .target = true,\ + { .bytes = (skb)->len, .packets = 1, \ + .context = IPSET_EXT_CONTEXT_TARGET, \ .timeout = ip_set_adt_opt_timeout(opt, set) }#define IP_SET_INIT_UEXT (set) \
net/netfilter/ipset/ip_set_hash_gen.h +6 -4
@@ -630,6 +630,7 @@ mtype_resize(struct ip_set *set, bool retried)struct htable *t, *orig;u8 pos, htable_bits;size_t hsize, dsize = set->dsize; +struct ip_set_ext replay = { .context =IPSET_EXT_CONTEXT_REPLAY };#ifdef IP_SET_HASH_WITH_NETS u8 flags;struct mtype_elem *tmp;
@@ -779,7 +780,7 @@ mtype_resize(struct ip_set *set, bool retried)if (x->ad ==IPSET_ADD ) {mtype_add (set, &x->d, &x->ext, &x->mext, x->flags); }else { -mtype_del (set, &x->d,NULL ,NULL ,0 ); +mtype_del (set, &x->d, &replay, &replay,0 ); }list_del (l);kfree (l);
@@ -1007,7 +1008,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext, ret =0 ; resize:spin_unlock_bh (&t->hregion[r].lock); -if (atomic_read (&t->ref) && ext->target) { +if (atomic_read (&t->ref) && ext->context ==IPSET_EXT_CONTEXT_TARGET ) {/* Resize is in process and kernel side add, save values */ struct mtype_resize_ad *x;
@@ -1095,9 +1096,10 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,mtype_del_cidr (set, h,NCIDR_PUT (DCIDR_GET (d->cidr, j)), j);#endif -ip_set_ext_destroy (set, data); +if (ext->context !=IPSET_EXT_CONTEXT_REPLAY ) +ip_set_ext_destroy (set, data); -if (atomic_read (&t->ref) && ext->target) { +if (atomic_read (&t->ref) && ext->context ==IPSET_EXT_CONTEXT_TARGET ) {/* Resize is in process and kernel side del, * save values */
Signature · 1 line
2.39.5
PATCH v2 7/9 netfilter: ipset: make sure gc is properly stopped
In reply to Jozsef KadlecsikSashiko noticed that when destroying a set, cancel_delayed_work_sync() was called while gc calls queue_delayed_work() unconditionally which can lead not to properly shutting down the gc.
--- net/netfilter/ipset/ip_set_hash_gen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_gen.h +1 -1
@@ -609,7 +609,7 @@ mtype_cancel_gc(struct ip_set *set)struct htype *h = set->data;if (SET_WITH_TIMEOUT (set)) -cancel_delayed_work_sync (&h->gc.dwork); +disable_delayed_work_sync (&h->gc.dwork); } static int
Signature · 1 line
2.39.5
PATCH v2 8/9 netfilter: ipset: fix potential torn read in reuse/forceadd cases
In reply to Jozsef KadlecsikSashiko pointed out that due to using memcpy() to overwrite already existing entry in reuse/forceadd cases, it can lead to torn reads for concurrent lockless RCU readers. Delete the element explicitly before reusing its slot.
--- net/netfilter/ipset/ip_set_hash_gen.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +15 -4
@@ -857,12 +857,16 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,const struct mtype_elem *d = value;struct mtype_elem *data;struct hbucket *n, *old =ERR_PTR (-ENOENT ); -int i, j =-1 , ret; +int i, j, ret;bool flag_exist = flags &IPSET_FLAG_EXIST ; -bool deleted = false, forceadd = false, reuse = false; -u32 r, key, multi =0 , elements, maxelem; -u8 npos =0 ; +bool deleted, forceadd, reuse; +u32 r, key, multi, elements, maxelem; +u8 npos, retried =0 ; +retry: + multi =0 ; + j =-1 ; + deleted = forceadd = reuse = false;rcu_read_lock_bh (); t =rcu_dereference_bh (h->table); key =HKEY (value, h->initval, t->htable_bits);
@@ -931,6 +935,10 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext, j =0 ; data =ahash_data (n, j, set->dsize);if (!deleted) { +if (retried++) + goto set_full; +clear_bit (j, n->used); +smp_mb__after_atomic ();#ifdef IP_SET_HASH_WITH_NETS for (i =0 ; i <IPSET_NET_COUNT ; i++) mtype_del_cidr(set, h,
@@ -939,6 +947,9 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,#endif ip_set_ext_destroy (set, data); t->hregion[r].elements--; +spin_unlock_bh (&t->hregion[r].lock); +rcu_read_unlock_bh (); + goto retry; } goto copy_data; }
Signature · 1 line
2.39.5
PATCH v2 9/9 netfilter: ipset: rework cidr bookkeeping
In reply to Jozsef KadlecsikAccording to sashiko, the current bookkeeping of cidr values are unsafe on weakly-ordered architectures. Use active/backup cidr tables: at updates the backup table is refreshed and after it is completed, the reference to the tables are swapped.
--- net/netfilter/ipset/ip_set_hash_gen.h | 55 +++++++++++++------- net/netfilter/ipset/ip_set_hash_ipportnet.c | 4 +- net/netfilter/ipset/ip_set_hash_net.c | 4 +- net/netfilter/ipset/ip_set_hash_netiface.c | 4 +- net/netfilter/ipset/ip_set_hash_netnet.c | 8 +-- net/netfilter/ipset/ip_set_hash_netport.c | 4 +- net/netfilter/ipset/ip_set_hash_netportnet.c | 8 +-- 7 files changed, 51 insertions(+), 36 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +35 -20
@@ -142,6 +142,8 @@ htable_size(u8 hbits)#define INIT_CIDR (cidr, host_mask) \ DCIDR_PUT(((cidr) ? NCIDR_GET(cidr) : host_mask)) +#define FIRST_CIDR (h, n) \ + h->abnets[h->active][0].cidr[n]#ifdef IP_SET_HASH_WITH_NET0 /* cidr from 0 to HOST_MASK value and c = cidr + 1 */
@@ -305,7 +307,8 @@ struct htype {struct list_head ad;/* Resize add|del backlist */ struct mtype_elem next;/* temporary storage for uadd */ #ifdef IP_SET_HASH_WITH_NETS -struct net_prefixes nets[NLEN ];/* book-keeping of prefixes */ +struct net_prefixes abnets[2 ][NLEN ];/* book-keeping of prefixes */ +u8 active;/* active slot */ #endif };
@@ -326,26 +329,31 @@ struct mtype_resize_ad {static void mtype_add_cidr (struct ip_set *set,struct htype *h,u8 cidr,u8 n) { +struct net_prefixes (*anets)[NLEN ] = &h->abnets[h->active]; +struct net_prefixes (*bnets)[NLEN ] = &h->abnets[!h->active];int i, j;spin_lock_bh (&set->lock);/* Add in increasing prefix order, so larger cidr first */ -for (i =0 , j =-1 ; i <NLEN && h->nets[i].cidr[n]; i++) { +for (i =0 , j =-1 ; i <NLEN && (*anets)[i].cidr[n]; i++) {if (j !=-1 ) {continue ; - }else if (h->nets[i].cidr[n] < cidr) { + }else if ((*anets)[i].cidr[n] < cidr) { j = i; - }else if (h->nets[i].cidr[n] == cidr) { - h->nets[CIDR_POS (cidr)].nets[n]++; + }else if ((*anets)[i].cidr[n] == cidr) { + (*anets)[CIDR_POS (cidr)].nets[n]++; goto unlock; } } +memcpy (bnets, anets,sizeof (*bnets));if (j !=-1 ) {for (; i > j; i--) - h->nets[i].cidr[n] = h->nets[i -1 ].cidr[n]; + (*bnets)[i].cidr[n] = (*bnets)[i -1 ].cidr[n]; } - h->nets[i].cidr[n] = cidr; - h->nets[CIDR_POS (cidr)].nets[n] =1 ; + (*bnets)[i].cidr[n] = cidr; + (*bnets)[CIDR_POS (cidr)].nets[n] =1 ; +smp_rmb (); + h->active = !h->active; unlock:spin_unlock_bh (&set->lock); }
@@ -353,18 +361,23 @@ mtype_add_cidr(struct ip_set *set, struct htype *h, u8 cidr, u8 n)static void mtype_del_cidr (struct ip_set *set,struct htype *h,u8 cidr,u8 n) { +struct net_prefixes (*anets)[NLEN ] = &h->abnets[h->active]; +struct net_prefixes (*bnets)[NLEN ] = &h->abnets[!h->active];u8 i, j, net_end =NLEN -1 ;spin_lock_bh (&set->lock);for (i =0 ; i <NLEN ; i++) { -if (h->nets[i].cidr[n] != cidr) +if ((*anets)[i].cidr[n] != cidr)continue ; - h->nets[CIDR_POS (cidr)].nets[n]--; -if (h->nets[CIDR_POS (cidr)].nets[n] >0 ) + (*anets)[CIDR_POS (cidr)].nets[n]--; +if ((*anets)[CIDR_POS (cidr)].nets[n] >0 ) goto unlock; -for (j = i; j < net_end && h->nets[j].cidr[n]; j++) - h->nets[j].cidr[n] = h->nets[j +1 ].cidr[n]; - h->nets[j].cidr[n] =0 ; +memcpy (bnets, anets,sizeof (*bnets)); +for (j = i; j < net_end && (*bnets)[j].cidr[n]; j++) + (*bnets)[j].cidr[n] = (*bnets)[j +1 ].cidr[n]; + (*bnets)[j].cidr[n] =0 ; +smp_rmb (); + h->active = !h->active; goto unlock; } unlock:
@@ -422,7 +435,8 @@ mtype_flush(struct ip_set *set)spin_unlock_bh (&t->hregion[r].lock); }#ifdef IP_SET_HASH_WITH_NETS -memset (h->nets,0 ,sizeof (h->nets)); +memset (&h->abnets,0 ,sizeof (h->abnets)); + h->active =0 ;#endif }
@@ -1192,6 +1206,7 @@ mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d,struct htable *t =rcu_dereference_bh (h->table);struct hbucket *n;struct mtype_elem *data; +struct net_prefixes (*nets)[NLEN ] = &h->abnets[h->active];#if IPSET_NET_COUNT ==2 struct mtype_elem orig = *d;int ret, i, j =0 , k;
@@ -1202,16 +1217,16 @@ mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d,u8 pos;pr_debug ("test by nets\n" ); -for (; j <NLEN && h->nets[j].cidr[0 ] && !multi; j++) { +for (; j <NLEN && (*nets)[j].cidr[0 ] && !multi; j++) {#if IPSET_NET_COUNT ==2 mtype_data_reset_elem (d, &orig); -mtype_data_netmask (d,NCIDR_GET (h->nets[j].cidr[0 ]), false); -for (k =0 ; k <NLEN && h->nets[k].cidr[1 ] && !multi; +mtype_data_netmask (d,NCIDR_GET ((*nets)[j].cidr[0 ]), false); +for (k =0 ; k <NLEN && (*nets)[k].cidr[1 ] && !multi; k++) { -mtype_data_netmask (d,NCIDR_GET (h->nets[k].cidr[1 ]), +mtype_data_netmask (d,NCIDR_GET ((*nets)[k].cidr[1 ]), true);#else -mtype_data_netmask (d,NCIDR_GET (h->nets[j].cidr[0 ])); +mtype_data_netmask (d,NCIDR_GET ((*nets)[j].cidr[0 ]));#endif key =HKEY (d, h->initval, t->htable_bits); n =rcu_dereference_bh (hbucket (t, key));
net/netfilter/ipset/ip_set_hash_ipportnet.c +2 -2
@@ -138,7 +138,7 @@ hash_ipportnet4_kadt(struct ip_set *set, const struct sk_buff *skb,const struct hash_ipportnet4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportnet4_elem e = { - .cidr =INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), + .cidr =INIT_CIDR (FIRST_CIDR (h,0 ),HOST_MASK ), };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
@@ -398,7 +398,7 @@ hash_ipportnet6_kadt(struct ip_set *set, const struct sk_buff *skb,const struct hash_ipportnet6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportnet6_elem e = { - .cidr =INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), + .cidr =INIT_CIDR (FIRST_CIDR (h,0 ),HOST_MASK ), };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
net/netfilter/ipset/ip_set_hash_net.c +2 -2
@@ -117,7 +117,7 @@ hash_net4_kadt(struct ip_set *set, const struct sk_buff *skb,const struct hash_net4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_net4_elem e = { - .cidr =INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), + .cidr =INIT_CIDR (FIRST_CIDR (h,0 ),HOST_MASK ), };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
@@ -291,7 +291,7 @@ hash_net6_kadt(struct ip_set *set, const struct sk_buff *skb,const struct hash_net6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_net6_elem e = { - .cidr =INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), + .cidr =INIT_CIDR (FIRST_CIDR (h,0 ),HOST_MASK ), };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
net/netfilter/ipset/ip_set_hash_netiface.c +2 -2
@@ -161,7 +161,7 @@ hash_netiface4_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_netiface4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netiface4_elem e = { - .cidr =INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), + .cidr =INIT_CIDR (FIRST_CIDR (h,0 ),HOST_MASK ), .elem =1 , };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
@@ -382,7 +382,7 @@ hash_netiface6_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_netiface6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netiface6_elem e = { - .cidr =INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), + .cidr =INIT_CIDR (FIRST_CIDR (h,0 ),HOST_MASK ), .elem =1 , };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
net/netfilter/ipset/ip_set_hash_netnet.c +4 -4
@@ -149,8 +149,8 @@ hash_netnet4_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_netnet4_elem e = { };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set); - e.cidr[0 ] =INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ); - e.cidr[1 ] =INIT_CIDR (h->nets[0 ].cidr[1 ],HOST_MASK ); + e.cidr[0 ] =INIT_CIDR (FIRST_CIDR (h,0 ),HOST_MASK ); + e.cidr[1 ] =INIT_CIDR (FIRST_CIDR (h,1 ),HOST_MASK );if (adt ==IPSET_TEST ) e.ccmp = (HOST_MASK << (sizeof (e.cidr[0 ]) *8 )) |HOST_MASK ;
@@ -388,8 +388,8 @@ hash_netnet6_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_netnet6_elem e = { };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set); - e.cidr[0 ] =INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ); - e.cidr[1 ] =INIT_CIDR (h->nets[0 ].cidr[1 ],HOST_MASK ); + e.cidr[0 ] =INIT_CIDR (FIRST_CIDR (h,0 ),HOST_MASK ); + e.cidr[1 ] =INIT_CIDR (FIRST_CIDR (h,1 ),HOST_MASK );if (adt ==IPSET_TEST ) e.ccmp = (HOST_MASK << (sizeof (u8) *8 )) |HOST_MASK ;
net/netfilter/ipset/ip_set_hash_netport.c +2 -2
@@ -133,7 +133,7 @@ hash_netport4_kadt(struct ip_set *set, const struct sk_buff *skb,const struct hash_netport4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netport4_elem e = { - .cidr =INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), + .cidr =INIT_CIDR (FIRST_CIDR (h,0 ),HOST_MASK ), };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
@@ -353,7 +353,7 @@ hash_netport6_kadt(struct ip_set *set, const struct sk_buff *skb,const struct hash_netport6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netport6_elem e = { - .cidr =INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), + .cidr =INIT_CIDR (FIRST_CIDR (h,0 ),HOST_MASK ), };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
net/netfilter/ipset/ip_set_hash_netportnet.c +4 -4
@@ -157,8 +157,8 @@ hash_netportnet4_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_netportnet4_elem e = { };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set); - e.cidr[0 ] =INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ); - e.cidr[1 ] =INIT_CIDR (h->nets[0 ].cidr[1 ],HOST_MASK ); + e.cidr[0 ] =INIT_CIDR (FIRST_CIDR (h,0 ),HOST_MASK ); + e.cidr[1 ] =INIT_CIDR (FIRST_CIDR (h,1 ),HOST_MASK );if (adt ==IPSET_TEST ) e.ccmp = (HOST_MASK << (sizeof (e.cidr[0 ]) *8 )) |HOST_MASK ;
@@ -452,8 +452,8 @@ hash_netportnet6_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_netportnet6_elem e = { };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set); - e.cidr[0 ] =INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ); - e.cidr[1 ] =INIT_CIDR (h->nets[0 ].cidr[1 ],HOST_MASK ); + e.cidr[0 ] =INIT_CIDR (FIRST_CIDR (h,0 ),HOST_MASK ); + e.cidr[1 ] =INIT_CIDR (FIRST_CIDR (h,1 ),HOST_MASK );if (adt ==IPSET_TEST ) e.ccmp = (HOST_MASK << (sizeof (u8) *8 )) |HOST_MASK ;
Signature · 1 line
2.39.5
syzbot ci has tested the following series
syzbot ci has tested the following series
[v2] netfilter: ipset fixes, second batch
https://lore.kernel.org/all/[email protected]
* [PATCH v2 1/9] netfilter: ipset: Don't use test_bit() in lockless RCU readers in hash types
* [PATCH v2 2/9] netfilter: ipset: Don't use test_bit() in lockless RCU readers in bitmap types
* [PATCH v2 3/9] netfilter: ipset: fix order of kfree_rcu() and rcu_assign_pointer()
* [PATCH v2 4/9] netfilter: ipset: Extend the rcu locked area properly
* [PATCH v2 5/9] netfilter: ipset: exlude gc when resize is in progress
* [PATCH v2 6/9] netfilter: ipset: fix potential double free at resize/del
* [PATCH v2 7/9] netfilter: ipset: make sure gc is properly stopped
* [PATCH v2 8/9] netfilter: ipset: fix potential torn read in reuse/forceadd cases
* [PATCH v2 9/9] netfilter: ipset: rework cidr bookkeeping
and found the following issues:
* BUG: sleeping function called from invalid context in hash_ip4_resize
* BUG: sleeping function called from invalid context in hash_ipmark4_resize
* BUG: sleeping function called from invalid context in hash_ipport4_resize
* BUG: sleeping function called from invalid context in hash_ipportnet6_resize
* BUG: sleeping function called from invalid context in hash_net4_resize
Full report is available here:
https://ci.syzbot.org/series/60ee40c9-c67a-4d2e-8c5c-7cbc4f2c35e3
***
BUG: sleeping function called from invalid context in hash_ip4_resize
tree: nf-next URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/netfilter/nf-next.git base: bfa3d89cc15c09f7d1581c834a5ed725189ec19f arch: amd64 compiler: Debian clang version 21.1.8 (++20251221033036+2078da43e25a-1~exp1~20251221153213.50), Debian LLD 21.1.8 config: https://ci.syzbot.org/builds/63302f1b-7561-4e38-b3bc-890b9b65c7c1/config syz repro: https://ci.syzbot.org/findings/3f7d3e03-c73e-47d2-a969-7c113b094a23/syz_repro
BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:323
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 5837, name: syz.0.17preempt_count: 201, expected: 0
RCU nest depth: 0, expected: 0
2 locks held by syz.0.17/5837:
#0: ffffffff9a952da0 (nfnl_subsys_ipset){+.+.}-{4:4}, at: nfnl_lock net/netfilter/nfnetlink.c:96 [inline] #0: ffffffff9a952da0 (nfnl_subsys_ipset){+.+.}-{4:4}, at: nfnetlink_rcv_msg+0xa71/0x12c0 net/netfilter/nfnetlink.c:293 #1: ffff8881bbd48028 (&t->gc_lock){+...}-{3:3}, at: spin_lock_bh include/linux/spinlock.h:348 [inline] #1: ffff8881bbd48028 (&t->gc_lock){+...}-{3:3}, at: hash_ip4_resize+0x149/0x1a80 net/netfilter/ipset/ip_set_hash_gen.h:667
Preemption disabled at:
[<0000000000000000>] 0x0
CPU: 0 UID: 0 PID: 5837 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 __might_resched+0x378/0x4d0 kernel/sched/core.c:9163 might_alloc include/linux/sched/mm.h:323 [inline] slab_pre_alloc_hook mm/slub.c:4521 [inline] slab_alloc_node mm/slub.c:4876 [inline] __do_kmalloc_node mm/slub.c:5295 [inline] __kvmalloc_node_noprof+0x164/0x8a0 mm/slub.c:6833 hash_ip4_resize+0x278/0x1a80 net/netfilter/ipset/ip_set_hash_gen.h:682 call_ad+0x562/0xb60 net/netfilter/ipset/ip_set_core.c:1758 ip_set_ad+0x824/0x9d0 net/netfilter/ipset/ip_set_core.c:1842 nfnetlink_rcv_msg+0xc03/0x12c0 net/netfilter/nfnetlink.c:300 netlink_rcv_skb+0x232/0x4b0 net/netlink/af_netlink.c:2556 nfnetlink_rcv+0x2c0/0x27b0 net/netfilter/nfnetlink.c:667 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x75c/0x8e0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1900 sock_sendmsg_nosec net/socket.c:787 [inline] __sock_sendmsg net/socket.c:802 [inline] ____sys_sendmsg+0x972/0x9f0 net/socket.c:2698 ___sys_sendmsg+0x2a5/0x360 net/socket.c:2752 __sys_sendmsg net/socket.c:2784 [inline] __do_sys_sendmsg net/socket.c:2789 [inline] __se_sys_sendmsg net/socket.c:2787 [inline] __x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fb3ded9ce59 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fb3dfcee028 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007fb3df015fa0 RCX: 00007fb3ded9ce59 RDX: 00000000240008c4 RSI: 0000200000000000 RDI: 0000000000000004 RBP: 00007fb3dee32d6f R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007fb3df016038 R14: 00007fb3df015fa0 R15: 00007ffd0454d2c8 </TASK>
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator.
CPU: 0 UID: 0 PID: 5837 Comm: syz.0.17 Tainted: G W syzkaller #0 PREEMPT(full) Tainted: [W]=WARN Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 assign_lock_key+0x133/0x150 kernel/locking/lockdep.c:984 register_lock_class+0xcc/0x2e0 kernel/locking/lockdep.c:1299 __lock_acquire+0xad/0x2cf0 kernel/locking/lockdep.c:5112 lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868 __raw_spin_lock_bh include/linux/spinlock_api_smp.h:150 [inline] _raw_spin_lock_bh+0x36/0x50 kernel/locking/spinlock.c:182 spin_lock_bh include/linux/spinlock.h:348 [inline] hash_ip4_resize+0x149/0x1a80 net/netfilter/ipset/ip_set_hash_gen.h:667 call_ad+0x463/0xb60 net/netfilter/ipset/ip_set_core.c:1758 ip_set_ad+0x824/0x9d0 net/netfilter/ipset/ip_set_core.c:1842 nfnetlink_rcv_msg+0xc03/0x12c0 net/netfilter/nfnetlink.c:300 netlink_rcv_skb+0x232/0x4b0 net/netlink/af_netlink.c:2556 nfnetlink_rcv+0x2c0/0x27b0 net/netfilter/nfnetlink.c:667 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x75c/0x8e0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1900 sock_sendmsg_nosec net/socket.c:787 [inline] __sock_sendmsg net/socket.c:802 [inline] ____sys_sendmsg+0x972/0x9f0 net/socket.c:2698 ___sys_sendmsg+0x2a5/0x360 net/socket.c:2752 __sys_sendmsg net/socket.c:2784 [inline] __do_sys_sendmsg net/socket.c:2789 [inline] __se_sys_sendmsg net/socket.c:2787 [inline] __x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fb3ded9ce59 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fb3dfcee028 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007fb3df015fa0 RCX: 00007fb3ded9ce59 RDX: 00000000240008c4 RSI: 0000200000000000 RDI: 0000000000000004 RBP: 00007fb3dee32d6f R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007fb3df016038 R14: 00007fb3df015fa0 R15: 00007ffd0454d2c8 </TASK>
Set syz1 is full, maxelem 65536 reached
***
BUG: sleeping function called from invalid context in hash_ipmark4_resize
tree: nf-next URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/netfilter/nf-next.git base: bfa3d89cc15c09f7d1581c834a5ed725189ec19f arch: amd64 compiler: Debian clang version 21.1.8 (++20251221033036+2078da43e25a-1~exp1~20251221153213.50), Debian LLD 21.1.8 config: https://ci.syzbot.org/builds/63302f1b-7561-4e38-b3bc-890b9b65c7c1/config syz repro: https://ci.syzbot.org/findings/57335612-22e3-4e78-a4ec-3d06321de960/syz_repro
BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:323
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 5839, name: syz.1.18preempt_count: 201, expected: 0
RCU nest depth: 0, expected: 0
2 locks held by syz.1.18/5839:
#0: ffffffff9a952da0 (nfnl_subsys_ipset){+.+.}-{4:4}, at: nfnl_lock net/netfilter/nfnetlink.c:96 [inline] #0: ffffffff9a952da0 (nfnl_subsys_ipset){+.+.}-{4:4}, at: nfnetlink_rcv_msg+0xa71/0x12c0 net/netfilter/nfnetlink.c:293 #1: ffff888168150028 (&t->gc_lock){+...}-{3:3}, at: spin_lock_bh include/linux/spinlock.h:348 [inline] #1: ffff888168150028 (&t->gc_lock){+...}-{3:3}, at: hash_ipmark4_resize+0x13f/0x1ae0 net/netfilter/ipset/ip_set_hash_gen.h:667
Preemption disabled at:
[<0000000000000000>] 0x0
CPU: 1 UID: 0 PID: 5839 Comm: syz.1.18 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 __might_resched+0x378/0x4d0 kernel/sched/core.c:9163 might_alloc include/linux/sched/mm.h:323 [inline] slab_pre_alloc_hook mm/slub.c:4521 [inline] slab_alloc_node mm/slub.c:4876 [inline] __do_kmalloc_node mm/slub.c:5295 [inline] __kvmalloc_node_noprof+0x164/0x8a0 mm/slub.c:6833 hash_ipmark4_resize+0x26f/0x1ae0 net/netfilter/ipset/ip_set_hash_gen.h:682 call_ad+0x562/0xb60 net/netfilter/ipset/ip_set_core.c:1758 ip_set_ad+0x824/0x9d0 net/netfilter/ipset/ip_set_core.c:1842 nfnetlink_rcv_msg+0xc03/0x12c0 net/netfilter/nfnetlink.c:300 netlink_rcv_skb+0x232/0x4b0 net/netlink/af_netlink.c:2556 nfnetlink_rcv+0x2c0/0x27b0 net/netfilter/nfnetlink.c:667 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x75c/0x8e0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1900 sock_sendmsg_nosec net/socket.c:787 [inline] __sock_sendmsg net/socket.c:802 [inline] ____sys_sendmsg+0x972/0x9f0 net/socket.c:2698 ___sys_sendmsg+0x2a5/0x360 net/socket.c:2752 __sys_sendmsg net/socket.c:2784 [inline] __do_sys_sendmsg net/socket.c:2789 [inline] __se_sys_sendmsg net/socket.c:2787 [inline] __x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f37dad9ce59 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f37dbd30028 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007f37db015fa0 RCX: 00007f37dad9ce59 RDX: 00000000040c0080 RSI: 00002000000002c0 RDI: 0000000000000004 RBP: 00007f37dae32d6f R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f37db016038 R14: 00007f37db015fa0 R15: 00007fff6c4f3458 </TASK>
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator.
CPU: 1 UID: 0 PID: 5839 Comm: syz.1.18 Tainted: G W syzkaller #0 PREEMPT(full) Tainted: [W]=WARN Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 assign_lock_key+0x133/0x150 kernel/locking/lockdep.c:984 register_lock_class+0xcc/0x2e0 kernel/locking/lockdep.c:1299 __lock_acquire+0xad/0x2cf0 kernel/locking/lockdep.c:5112 lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868 __raw_spin_lock_bh include/linux/spinlock_api_smp.h:150 [inline] _raw_spin_lock_bh+0x36/0x50 kernel/locking/spinlock.c:182 spin_lock_bh include/linux/spinlock.h:348 [inline] hash_ipmark4_resize+0x13f/0x1ae0 net/netfilter/ipset/ip_set_hash_gen.h:667 call_ad+0x463/0xb60 net/netfilter/ipset/ip_set_core.c:1758 ip_set_ad+0x824/0x9d0 net/netfilter/ipset/ip_set_core.c:1842 nfnetlink_rcv_msg+0xc03/0x12c0 net/netfilter/nfnetlink.c:300 netlink_rcv_skb+0x232/0x4b0 net/netlink/af_netlink.c:2556 nfnetlink_rcv+0x2c0/0x27b0 net/netfilter/nfnetlink.c:667 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x75c/0x8e0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1900 sock_sendmsg_nosec net/socket.c:787 [inline] __sock_sendmsg net/socket.c:802 [inline] ____sys_sendmsg+0x972/0x9f0 net/socket.c:2698 ___sys_sendmsg+0x2a5/0x360 net/socket.c:2752 __sys_sendmsg net/socket.c:2784 [inline] __do_sys_sendmsg net/socket.c:2789 [inline] __se_sys_sendmsg net/socket.c:2787 [inline] __x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f37dad9ce59 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f37dbd30028 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007f37db015fa0 RCX: 00007f37dad9ce59 RDX: 00000000040c0080 RSI: 00002000000002c0 RDI: 0000000000000004 RBP: 00007f37dae32d6f R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f37db016038 R14: 00007f37db015fa0 R15: 00007fff6c4f3458 </TASK>
Set syz1 is full, maxelem 65536 reached
***
BUG: sleeping function called from invalid context in hash_ipport4_resize
tree: nf-next URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/netfilter/nf-next.git base: bfa3d89cc15c09f7d1581c834a5ed725189ec19f arch: amd64 compiler: Debian clang version 21.1.8 (++20251221033036+2078da43e25a-1~exp1~20251221153213.50), Debian LLD 21.1.8 config: https://ci.syzbot.org/builds/63302f1b-7561-4e38-b3bc-890b9b65c7c1/config syz repro: https://ci.syzbot.org/findings/79e04816-4100-48fa-8d49-43c546bef2fa/syz_repro
BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:323
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 5819, name: syz.2.19preempt_count: 201, expected: 0
RCU nest depth: 0, expected: 0
2 locks held by syz.2.19/5819:
#0: ffffffff9a952da0 (nfnl_subsys_ipset){+.+.}-{4:4}, at: nfnl_lock net/netfilter/nfnetlink.c:96 [inline] #0: ffffffff9a952da0 (nfnl_subsys_ipset){+.+.}-{4:4}, at: nfnetlink_rcv_msg+0xa71/0x12c0 net/netfilter/nfnetlink.c:293 #1: ffff888116501828 (&t->gc_lock){+...}-{3:3}, at: spin_lock_bh include/linux/spinlock.h:348 [inline] #1: ffff888116501828 (&t->gc_lock){+...}-{3:3}, at: hash_ipport4_resize+0x13f/0x1ae0 net/netfilter/ipset/ip_set_hash_gen.h:667
Preemption disabled at:
[<0000000000000000>] 0x0
CPU: 0 UID: 0 PID: 5819 Comm: syz.2.19 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 __might_resched+0x378/0x4d0 kernel/sched/core.c:9163 might_alloc include/linux/sched/mm.h:323 [inline] slab_pre_alloc_hook mm/slub.c:4521 [inline] slab_alloc_node mm/slub.c:4876 [inline] __do_kmalloc_node mm/slub.c:5295 [inline] __kvmalloc_node_noprof+0x164/0x8a0 mm/slub.c:6833 hash_ipport4_resize+0x219/0x1ae0 net/netfilter/ipset/ip_set_hash_gen.h:677 call_ad+0x562/0xb60 net/netfilter/ipset/ip_set_core.c:1758 ip_set_ad+0x824/0x9d0 net/netfilter/ipset/ip_set_core.c:1842 nfnetlink_rcv_msg+0xc03/0x12c0 net/netfilter/nfnetlink.c:300 netlink_rcv_skb+0x232/0x4b0 net/netlink/af_netlink.c:2556 nfnetlink_rcv+0x2c0/0x27b0 net/netfilter/nfnetlink.c:667 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x75c/0x8e0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1900 sock_sendmsg_nosec net/socket.c:787 [inline] __sock_sendmsg net/socket.c:802 [inline] ____sys_sendmsg+0x972/0x9f0 net/socket.c:2698 ___sys_sendmsg+0x2a5/0x360 net/socket.c:2752 __sys_sendmsg net/socket.c:2784 [inline] __do_sys_sendmsg net/socket.c:2789 [inline] __se_sys_sendmsg net/socket.c:2787 [inline] __x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fe5c739ce59 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fe5c8339028 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007fe5c7615fa0 RCX: 00007fe5c739ce59 RDX: 0000000000000090 RSI: 00002000000002c0 RDI: 0000000000000004 RBP: 00007fe5c7432d6f R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007fe5c7616038 R14: 00007fe5c7615fa0 R15: 00007ffd329f2868 </TASK>
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator.
CPU: 1 UID: 0 PID: 5819 Comm: syz.2.19 Tainted: G W syzkaller #0 PREEMPT(full) Tainted: [W]=WARN Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 assign_lock_key+0x133/0x150 kernel/locking/lockdep.c:984 register_lock_class+0xcc/0x2e0 kernel/locking/lockdep.c:1299 __lock_acquire+0xad/0x2cf0 kernel/locking/lockdep.c:5112 lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868 __raw_spin_lock_bh include/linux/spinlock_api_smp.h:150 [inline] _raw_spin_lock_bh+0x36/0x50 kernel/locking/spinlock.c:182 spin_lock_bh include/linux/spinlock.h:348 [inline] hash_ipport4_resize+0x13f/0x1ae0 net/netfilter/ipset/ip_set_hash_gen.h:667 call_ad+0x463/0xb60 net/netfilter/ipset/ip_set_core.c:1758 ip_set_ad+0x824/0x9d0 net/netfilter/ipset/ip_set_core.c:1842 nfnetlink_rcv_msg+0xc03/0x12c0 net/netfilter/nfnetlink.c:300 netlink_rcv_skb+0x232/0x4b0 net/netlink/af_netlink.c:2556 nfnetlink_rcv+0x2c0/0x27b0 net/netfilter/nfnetlink.c:667 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x75c/0x8e0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1900 sock_sendmsg_nosec net/socket.c:787 [inline] __sock_sendmsg net/socket.c:802 [inline] ____sys_sendmsg+0x972/0x9f0 net/socket.c:2698 ___sys_sendmsg+0x2a5/0x360 net/socket.c:2752 __sys_sendmsg net/socket.c:2784 [inline] __do_sys_sendmsg net/socket.c:2789 [inline] __se_sys_sendmsg net/socket.c:2787 [inline] __x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fe5c739ce59 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fe5c8339028 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007fe5c7615fa0 RCX: 00007fe5c739ce59 RDX: 0000000000000090 RSI: 00002000000002c0 RDI: 0000000000000004 RBP: 00007fe5c7432d6f R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007fe5c7616038 R14: 00007fe5c7615fa0 R15: 00007ffd329f2868 </TASK>
***
BUG: sleeping function called from invalid context in hash_ipportnet6_resize
tree: nf-next URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/netfilter/nf-next.git base: bfa3d89cc15c09f7d1581c834a5ed725189ec19f arch: amd64 compiler: Debian clang version 21.1.8 (++20251221033036+2078da43e25a-1~exp1~20251221153213.50), Debian LLD 21.1.8 config: https://ci.syzbot.org/builds/63302f1b-7561-4e38-b3bc-890b9b65c7c1/config syz repro: https://ci.syzbot.org/findings/8502cd2b-1718-4dd7-8c57-c8f6d494a2b7/syz_repro
BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:323
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 5835, name: syz.1.18preempt_count: 201, expected: 0
RCU nest depth: 0, expected: 0
2 locks held by syz.1.18/5835:
#0: ffffffff9a952da0 (nfnl_subsys_ipset){+.+.}-{4:4}, at: nfnl_lock net/netfilter/nfnetlink.c:96 [inline] #0: ffffffff9a952da0 (nfnl_subsys_ipset){+.+.}-{4:4}, at: nfnetlink_rcv_msg+0xa71/0x12c0 net/netfilter/nfnetlink.c:293 #1: ffff8881114d0028 (&t->gc_lock){+...}-{3:3}, at: spin_lock_bh include/linux/spinlock.h:348 [inline]
#1: ffff8881114d0028 (&t->gc_lock){+...}-{3:3}, at: hash_ipportnet6_resize+0x170/0x1eb0 net/netfilter/ipset/ip_set_hash_gen.h:667
Preemption disabled at:
[<0000000000000000>] 0x0
CPU: 0 UID: 0 PID: 5835 Comm: syz.1.18 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 __might_resched+0x378/0x4d0 kernel/sched/core.c:9163 might_alloc include/linux/sched/mm.h:323 [inline] slab_pre_alloc_hook mm/slub.c:4521 [inline] slab_alloc_node mm/slub.c:4876 [inline] __do_kmalloc_node mm/slub.c:5295 [inline] __kvmalloc_node_noprof+0x164/0x8a0 mm/slub.c:6833 hash_ipportnet6_resize+0x31d/0x1eb0 net/netfilter/ipset/ip_set_hash_gen.h:682 call_ad+0x562/0xb60 net/netfilter/ipset/ip_set_core.c:1758 ip_set_ad+0x824/0x9d0 net/netfilter/ipset/ip_set_core.c:1842 nfnetlink_rcv_msg+0xc03/0x12c0 net/netfilter/nfnetlink.c:300 netlink_rcv_skb+0x232/0x4b0 net/netlink/af_netlink.c:2556 nfnetlink_rcv+0x2c0/0x27b0 net/netfilter/nfnetlink.c:667 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x75c/0x8e0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1900 sock_sendmsg_nosec net/socket.c:787 [inline] __sock_sendmsg net/socket.c:802 [inline] ____sys_sendmsg+0x972/0x9f0 net/socket.c:2698 ___sys_sendmsg+0x2a5/0x360 net/socket.c:2752 __sys_sendmsg net/socket.c:2784 [inline] __do_sys_sendmsg net/socket.c:2789 [inline] __se_sys_sendmsg net/socket.c:2787 [inline] __x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f27c6b9ce59 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f27c7a44028 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007f27c6e15fa0 RCX: 00007f27c6b9ce59 RDX: 0000000000000000 RSI: 00002000000002c0 RDI: 0000000000000004 RBP: 00007f27c6c32d6f R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f27c6e16038 R14: 00007f27c6e15fa0 R15: 00007ffcb0b8a718 </TASK>
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator.
CPU: 0 UID: 0 PID: 5835 Comm: syz.1.18 Tainted: G W syzkaller #0 PREEMPT(full) Tainted: [W]=WARN Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 assign_lock_key+0x133/0x150 kernel/locking/lockdep.c:984 register_lock_class+0xcc/0x2e0 kernel/locking/lockdep.c:1299 __lock_acquire+0xad/0x2cf0 kernel/locking/lockdep.c:5112 lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868 __raw_spin_lock_bh include/linux/spinlock_api_smp.h:150 [inline] _raw_spin_lock_bh+0x36/0x50 kernel/locking/spinlock.c:182 spin_lock_bh include/linux/spinlock.h:348 [inline] hash_ipportnet6_resize+0x170/0x1eb0 net/netfilter/ipset/ip_set_hash_gen.h:667 call_ad+0x463/0xb60 net/netfilter/ipset/ip_set_core.c:1758 ip_set_ad+0x824/0x9d0 net/netfilter/ipset/ip_set_core.c:1842 nfnetlink_rcv_msg+0xc03/0x12c0 net/netfilter/nfnetlink.c:300 netlink_rcv_skb+0x232/0x4b0 net/netlink/af_netlink.c:2556 nfnetlink_rcv+0x2c0/0x27b0 net/netfilter/nfnetlink.c:667 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x75c/0x8e0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1900 sock_sendmsg_nosec net/socket.c:787 [inline] __sock_sendmsg net/socket.c:802 [inline] ____sys_sendmsg+0x972/0x9f0 net/socket.c:2698 ___sys_sendmsg+0x2a5/0x360 net/socket.c:2752 __sys_sendmsg net/socket.c:2784 [inline] __do_sys_sendmsg net/socket.c:2789 [inline] __se_sys_sendmsg net/socket.c:2787 [inline] __x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f27c6b9ce59 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f27c7a44028 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007f27c6e15fa0 RCX: 00007f27c6b9ce59 RDX: 0000000000000000 RSI: 00002000000002c0 RDI: 0000000000000004 RBP: 00007f27c6c32d6f R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f27c6e16038 R14: 00007f27c6e15fa0 R15: 00007ffcb0b8a718 </TASK>
***
BUG: sleeping function called from invalid context in hash_net4_resize
tree: nf-next URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/netfilter/nf-next.git base: bfa3d89cc15c09f7d1581c834a5ed725189ec19f arch: amd64 compiler: Debian clang version 21.1.8 (++20251221033036+2078da43e25a-1~exp1~20251221153213.50), Debian LLD 21.1.8 config: https://ci.syzbot.org/builds/63302f1b-7561-4e38-b3bc-890b9b65c7c1/config syz repro: https://ci.syzbot.org/findings/230cf2b1-2c8b-4558-b095-874702f9bc7d/syz_repro
BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:323
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 5814, name: syz.1.18preempt_count: 201, expected: 0
RCU nest depth: 0, expected: 0
2 locks held by syz.1.18/5814:
#0: ffffffff9a952da0 (nfnl_subsys_ipset){+.+.}-{4:4}, at: nfnl_lock net/netfilter/nfnetlink.c:96 [inline] #0: ffffffff9a952da0 (nfnl_subsys_ipset){+.+.}-{4:4}, at: nfnetlink_rcv_msg+0xa71/0x12c0 net/netfilter/nfnetlink.c:293 #1: ffff88816a8df028 (&t->gc_lock){+...}-{3:3}, at: spin_lock_bh include/linux/spinlock.h:348 [inline] #1: ffff88816a8df028 (&t->gc_lock){+...}-{3:3}, at: hash_net4_resize+0x168/0x1bb0 net/netfilter/ipset/ip_set_hash_gen.h:667
Preemption disabled at:
[<0000000000000000>] 0x0
CPU: 1 UID: 0 PID: 5814 Comm: syz.1.18 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 __might_resched+0x378/0x4d0 kernel/sched/core.c:9163 might_alloc include/linux/sched/mm.h:323 [inline] slab_pre_alloc_hook mm/slub.c:4521 [inline] slab_alloc_node mm/slub.c:4876 [inline] __do_kmalloc_node mm/slub.c:5295 [inline] __kvmalloc_node_noprof+0x164/0x8a0 mm/slub.c:6833 hash_net4_resize+0x26e/0x1bb0 net/netfilter/ipset/ip_set_hash_gen.h:677 call_ad+0x562/0xb60 net/netfilter/ipset/ip_set_core.c:1758 ip_set_ad+0x824/0x9d0 net/netfilter/ipset/ip_set_core.c:1842 nfnetlink_rcv_msg+0xc03/0x12c0 net/netfilter/nfnetlink.c:300 netlink_rcv_skb+0x232/0x4b0 net/netlink/af_netlink.c:2556 nfnetlink_rcv+0x2c0/0x27b0 net/netfilter/nfnetlink.c:667 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x75c/0x8e0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1900 sock_sendmsg_nosec net/socket.c:787 [inline] __sock_sendmsg net/socket.c:802 [inline] ____sys_sendmsg+0x972/0x9f0 net/socket.c:2698 ___sys_sendmsg+0x2a5/0x360 net/socket.c:2752 __sys_sendmsg net/socket.c:2784 [inline] __do_sys_sendmsg net/socket.c:2789 [inline] __se_sys_sendmsg net/socket.c:2787 [inline] __x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fe472d9ce59 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fe473bc7028 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007fe473015fa0 RCX: 00007fe472d9ce59 RDX: 0000000004000050 RSI: 0000200000000000 RDI: 0000000000000003 RBP: 00007fe472e32d6f R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007fe473016038 R14: 00007fe473015fa0 R15: 00007ffcba742758 </TASK>
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator.
CPU: 1 UID: 0 PID: 5814 Comm: syz.1.18 Tainted: G W syzkaller #0 PREEMPT(full) Tainted: [W]=WARN Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 assign_lock_key+0x133/0x150 kernel/locking/lockdep.c:984 register_lock_class+0xcc/0x2e0 kernel/locking/lockdep.c:1299 __lock_acquire+0xad/0x2cf0 kernel/locking/lockdep.c:5112 lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868 __raw_spin_lock_bh include/linux/spinlock_api_smp.h:150 [inline] _raw_spin_lock_bh+0x36/0x50 kernel/locking/spinlock.c:182 spin_lock_bh include/linux/spinlock.h:348 [inline] hash_net4_resize+0x168/0x1bb0 net/netfilter/ipset/ip_set_hash_gen.h:667 call_ad+0x463/0xb60 net/netfilter/ipset/ip_set_core.c:1758 ip_set_ad+0x824/0x9d0 net/netfilter/ipset/ip_set_core.c:1842 nfnetlink_rcv_msg+0xc03/0x12c0 net/netfilter/nfnetlink.c:300 netlink_rcv_skb+0x232/0x4b0 net/netlink/af_netlink.c:2556 nfnetlink_rcv+0x2c0/0x27b0 net/netfilter/nfnetlink.c:667 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x75c/0x8e0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1900 sock_sendmsg_nosec net/socket.c:787 [inline] __sock_sendmsg net/socket.c:802 [inline] ____sys_sendmsg+0x972/0x9f0 net/socket.c:2698 ___sys_sendmsg+0x2a5/0x360 net/socket.c:2752 __sys_sendmsg net/socket.c:2784 [inline] __do_sys_sendmsg net/socket.c:2789 [inline] __se_sys_sendmsg net/socket.c:2787 [inline] __x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fe472d9ce59 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fe473bc7028 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007fe473015fa0 RCX: 00007fe472d9ce59 RDX: 0000000004000050 RSI: 0000200000000000 RDI: 0000000000000003 RBP: 00007fe472e32d6f R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007fe473016038 R14: 00007fe473015fa0 R15: 00007ffcba742758 </TASK>
Set syz1 is full, maxelem 65536 reached
***
If these findings have caused you to resend the series or submit a separate fix, please add the following tag to your commit message:
---
This report is generated by a bot. It may contain errors. syzbot ci engineers can be reached at [email protected].
To test a patch for this bug, please reply with #syz test (should be on a separate line).
The patch should be attached to the email.
Note: arguments like custom git repos and branches are not supported.