Unverified Commit 26a383fc authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!15100 ila: serialize calls to nf_register_net_hooks()

parents d83a5094 b6cce480
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -201,6 +201,8 @@ static const struct nf_hook_ops ila_nf_hook_ops[] = {
	},
};

static DEFINE_MUTEX(ila_mutex);

static int ila_add_mapping(struct net *net, struct ila_xlat_params *xp)
{
	struct ila_net *ilan = net_generic(net, ila_net_id);
@@ -208,16 +210,20 @@ static int ila_add_mapping(struct net *net, struct ila_xlat_params *xp)
	spinlock_t *lock = ila_get_lock(ilan, xp->ip.locator_match);
	int err = 0, order;

	if (!ilan->xlat.hooks_registered) {
	if (!READ_ONCE(ilan->xlat.hooks_registered)) {
		/* We defer registering net hooks in the namespace until the
		 * first mapping is added.
		 */
		mutex_lock(&ila_mutex);
		if (!ilan->xlat.hooks_registered) {
			err = nf_register_net_hooks(net, ila_nf_hook_ops,
						ARRAY_SIZE(ila_nf_hook_ops));
			if (!err)
				WRITE_ONCE(ilan->xlat.hooks_registered, true);
		}
		mutex_unlock(&ila_mutex);
		if (err)
			return err;

		ilan->xlat.hooks_registered = true;
	}

	ila = kzalloc(sizeof(*ila), GFP_KERNEL);