Skip to contentSkip to conversation

netfilter: nf_tables: add missing ->release_ops() in error path of newrule()

PATCH Applied Taehee Yoo 2 participants 2 messages Mar 19, 2019 – Mar 20, 2019

Subsystems (2)
lore
Share & tools
lore

Taehee Yoo

author
#0 lore raw

PATCH 1/1 netfilter: nf_tables: add missing ->release_ops() in error path of newrule()

->release_ops() callback releases resources and this is used in error path. If nf_tables_newrule() fails after ->select_ops(), it should release resources. but it can not call ->destroy() because that should be called after ->init().
At this point, ->release_ops() should be used for releasing resources.

Test commands:
modprobe -rv xt_tcpudp
iptables-nft -I INPUT -m tcp <-- error command
lsmod

Result:
Module Size Used by
xt_tcpudp 20480 2 <-- it should be 0

Fixes b8e204006340 ("netfilter: nft_compat: use .release_ops and remove list of extension")
---
 net/netfilter/nf_tables_api.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +4 -1
index 513f93118604..ef7772e976cc 100644
@@ -2806,8 +2806,11 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
 	nf_tables_rule_release(&ctx, rule);
 err1:
 	for (i = 0; i < n; i++) {
-		if (info[i].ops != NULL)
+		if (info[i].ops) {
 			module_put(info[i].ops->type->owner);
+			if (info[i].ops->type->release_ops)
+				info[i].ops->type->release_ops(info[i].ops);
+		}
 	}
 	kvfree(info);
 	return err;
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 6 lines · Taehee Yoo

->release_ops() callback releases resources and this is used in error path. If nf_tables_newrule() fails after ->select_ops(), it should release resources. but it can not call ->destroy() because that should be called after ->init().
At this point, ->release_ops() should be used for releasing resources.

Quoted 8 lines

Test commands:
modprobe -rv xt_tcpudp
iptables-nft -I INPUT -m tcp <-- error command
lsmod

Result:
Module Size Used by
xt_tcpudp 20480 2 <-- it should be 0

Applied, thanks!