Skip to contentSkip to conversation

netfilter: nf_tables: autoload modules from the abort path

PATCH Superseded Pablo Neira Ayuso 1 participant 1 message Jan 22, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nf_tables: autoload modules from the abort path

This patch introduces a list of pending module requests that is updated from preparation phase. Then, at the very end of the abort phase, iterate over this list to load the requested modules. Given the mutex is released when loading modules, the list of modules is zapped so this is iteration occurs over a local list. Thus, the request_module() call occurs when object lists in consistent state and the commit list is empty.

This new module list is composed of nft_module_request objects that contain the module name and one status field that tells if the module has been already loaded (the 'done' field).

This patch also updates nfnetlink to include the reason to enter the abort phase, which is required for this new autoload module rationale.

Fixes ec7470b834fe ("netfilter: nf_tables: store transaction list locally while requesting module")
Fixes 452238e8d5ff ("netfilter: nf_tables: add and use helper for module autoload")
Reported-by [email protected]

---
Just quickly runned tests here from userspace. Will make a second pass on reviewing later.

 include/linux/netfilter/nfnetlink.h |   2 +-
 include/net/netns/nftables.h        |   1 +
 net/netfilter/nf_tables_api.c       | 119 ++++++++++++++++++++++++------------
 net/netfilter/nfnetlink.c           |   6 +-
 4 files changed, 84 insertions(+), 44 deletions(-)
include/linux/netfilter/nfnetlink.h +1 -1
index cf09ab37b45b..851425c3178f 100644
@@ -31,7 +31,7 @@ struct nfnetlink_subsystem {
 	const struct nfnl_callback *cb;	/* callback for individual types */
 	struct module *owner;
 	int (*commit)(struct net *net, struct sk_buff *skb);
-	int (*abort)(struct net *net, struct sk_buff *skb);
+	int (*abort)(struct net *net, struct sk_buff *skb, bool autoload);
 	void (*cleanup)(struct net *net);
 	bool (*valid_genid)(struct net *net, u32 genid);
 };
include/net/netns/nftables.h +1 -0
index 286fd960896f..a1a8d45adb42 100644
@@ -7,6 +7,7 @@
 struct netns_nftables {
 	struct list_head	tables;
 	struct list_head	commit_list;
+	struct list_head	module_list;
 	struct mutex		commit_mutex;
 	unsigned int		base_seq;
 	u8			gencursor;
net/netfilter/nf_tables_api.c +79 -40

226 lines not on this page · raw message

net/netfilter/nfnetlink.c +3 -3
index 4abbb452cf6c..99127e2d95a8 100644
@@ -476,7 +476,7 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
 	}
 done:
 	if (status & NFNL_BATCH_REPLAY) {
-		ss->abort(net, oskb);
+		ss->abort(net, oskb, true);
 		nfnl_err_reset(&err_list);
 		kfree_skb(skb);
 		module_put(ss->owner);
@@ -487,11 +487,11 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
 			status |= NFNL_BATCH_REPLAY;
 			goto done;
 		} else if (err) {
-			ss->abort(net, oskb);
+			ss->abort(net, oskb, false);
 			netlink_ack(oskb, nlmsg_hdr(oskb), err, NULL);
 		}
 	} else {
-		ss->abort(net, oskb);
+		ss->abort(net, oskb, false);
 	}
 	if (ss->cleanup)
 		ss->cleanup(net);
Signature · 1 line
2.11.0