Skip to contentSkip to conversation

netfilter: nft_connlimit: fix nft_connlimit_clone()

PATCH In review Dan Carpenter 1 participant 2 messages Jan 11, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: nft_connlimit: fix nft_connlimit_clone()

The NULL check is reversed so nft_connlimit_clone() can never succeed.

Fixes 37f319f37d90 ("netfilter: nft_connlimit: move stateful fields out of expression data")

---
Haha haha. A couple months back I accidentally reversed a NULL check and invested several days in writing multiple Smatch checks to make sure that never happened again. Everyone made fun of me for wasting my time but who's laughing now? ha ha. <- me

 net/netfilter/nft_connlimit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_connlimit.c +1 -1
index 58dcafe8bf79..7d00a1452b1d 100644
@@ -206,7 +206,7 @@ static int nft_connlimit_clone(struct nft_expr *dst, const struct nft_expr *src)
 	struct nft_connlimit *priv_src = nft_expr_priv(src);
 
 	priv_dst->list = kmalloc(sizeof(*priv_dst->list), GFP_ATOMIC);
-	if (priv_dst->list)
+	if (!priv_dst->list)
 		return -ENOMEM;
 
 	nf_conncount_list_init(priv_dst->list);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 18 lines · Dan Carpenter

The NULL check is reversed so nft_connlimit_clone() can never succeed.

Fixes 37f319f37d90 ("netfilter: nft_connlimit: move stateful fields out of expression data")

---
Haha haha. A couple months back I accidentally reversed a NULL check and invested several days in writing multiple Smatch checks to make sure that never happened again. Everyone made fun of me for wasting my time but who's laughing now? ha ha. <- me

 net/netfilter/nft_connlimit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_connlimit.c +0 -0
index 58dcafe8bf79..7d00a1452b1d 100644

net/netfilter/nft_connlimit.c static int nft_connlimit_clone(struct nft_expr *dst, const struct nft_expr *src) · line 212

Quoted 8 lines
net/netfilter/nft_connlimit.c +1 -1
@@ -206,7 +206,7 @@ static int nft_connlimit_clone(struct nft_expr *dst, const struct nft_expr *src)
 	struct nft_connlimit *priv_src = nft_expr_priv(src);
 
 	priv_dst->list = kmalloc(sizeof(*priv_dst->list), GFP_ATOMIC);
-	if (priv_dst->list)
+	if (!priv_dst->list)
 		return -ENOMEM;
 
 	nf_conncount_list_init(priv_dst->list);

Ugh... Hold of on this. I'll send v2. nft_last_clone() has a similar issue.

regards,
dan carpenter