]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net/sched: act_ct: fix nf_connlabels leak on two error paths
authorMichael Bommarito <michael.bommarito@gmail.com>
Wed, 17 Jun 2026 21:57:08 +0000 (17:57 -0400)
committerJakub Kicinski <kuba@kernel.org>
Sun, 21 Jun 2026 22:00:47 +0000 (15:00 -0700)
tcf_ct_fill_params() calls nf_connlabels_get() (setting put_labels) when
TCA_CT_LABELS is present, but two later error sites use a bare return
instead of "goto err", skipping the err: nf_connlabels_put() cleanup.
They also precede the "p->put_labels = put_labels" assignment, so the
tcf_ct_params_free() fallback does not release the count either. Each
failed RTM_NEWACTION on these paths leaks one nf_connlabels reference:
net->ct.labels_used is incremented and never released. The action is
reachable with CAP_NET_ADMIN over the netns, i.e. from an unprivileged
user namespace on default-userns kernels.

Impact: an unprivileged user with CAP_NET_ADMIN over a network namespace
(e.g. via user namespaces) leaks one nf_connlabels reference per failed
RTM_NEWACTION on the two error paths; net->ct.labels_used is never
released.

The err: label is safe to reach from both sites: p->tmpl is still NULL
there (kzalloc'd, not yet assigned) and nf_ct_put(NULL) is a no-op, so
no inline release is needed.

Fixes: 70f06c115bcc ("sched: act_ct: switch to per-action label counting")
Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Link: https://patch.msgid.link/20260617215708.1115818-1-michael.bommarito@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/sched/act_ct.c

index d47a82f9ac6ca4a4ea1967a5164a62fafe3a1c5e..be535a261fa04a73a7d005b7c24b38161b3196e0 100644 (file)
@@ -1296,7 +1296,8 @@ static int tcf_ct_fill_params(struct net *net,
        if (tb[TCA_CT_ZONE]) {
                if (!IS_ENABLED(CONFIG_NF_CONNTRACK_ZONES)) {
                        NL_SET_ERR_MSG_MOD(extack, "Conntrack zones isn't enabled.");
-                       return -EOPNOTSUPP;
+                       err = -EOPNOTSUPP;
+                       goto err;
                }
 
                tcf_ct_set_key_val(tb,
@@ -1309,7 +1310,8 @@ static int tcf_ct_fill_params(struct net *net,
        tmpl = nf_ct_tmpl_alloc(net, &zone, GFP_KERNEL);
        if (!tmpl) {
                NL_SET_ERR_MSG_MOD(extack, "Failed to allocate conntrack template");
-               return -ENOMEM;
+               err = -ENOMEM;
+               goto err;
        }
        p->tmpl = tmpl;
        if (tb[TCA_CT_HELPER_NAME]) {