Skip to content

Commit 7f4f7dd

Browse files
vpai-akamaiummakynes
authored andcommitted
netfilter: ipset: ipset list may return wrong member count for set with timeout
Simple testcase: $ ipset create test hash:ip timeout 5 $ ipset add test 1.2.3.4 $ ipset add test 1.2.2.2 $ sleep 5 $ ipset l Name: test Type: hash:ip Revision: 5 Header: family inet hashsize 1024 maxelem 65536 timeout 5 Size in memory: 296 References: 0 Number of entries: 2 Members: We return "Number of entries: 2" but no members are listed. That is because mtype_list runs "ip_set_timeout_expired" and does not list the expired entries, but set->elements is never upated (until mtype_gc cleans it up later). Reviewed-by: Joshua Hunt <[email protected]> Signed-off-by: Vishwanath Pai <[email protected]> Signed-off-by: Jozsef Kadlecsik <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent b0ade85 commit 7f4f7dd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

net/netfilter/ipset/ip_set_hash_gen.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,12 +1041,24 @@ mtype_test(struct ip_set *set, void *value, const struct ip_set_ext *ext,
10411041
static int
10421042
mtype_head(struct ip_set *set, struct sk_buff *skb)
10431043
{
1044-
const struct htype *h = set->data;
1044+
struct htype *h = set->data;
10451045
const struct htable *t;
10461046
struct nlattr *nested;
10471047
size_t memsize;
10481048
u8 htable_bits;
10491049

1050+
/* If any members have expired, set->elements will be wrong
1051+
* mytype_expire function will update it with the right count.
1052+
* we do not hold set->lock here, so grab it first.
1053+
* set->elements can still be incorrect in the case of a huge set,
1054+
* because elements might time out during the listing.
1055+
*/
1056+
if (SET_WITH_TIMEOUT(set)) {
1057+
spin_lock_bh(&set->lock);
1058+
mtype_expire(set, h);
1059+
spin_unlock_bh(&set->lock);
1060+
}
1061+
10501062
rcu_read_lock_bh();
10511063
t = rcu_dereference_bh_nfnl(h->table);
10521064
memsize = mtype_ahash_memsize(h, t) + set->ext_size;

0 commit comments

Comments
 (0)