From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D3253C2798 for ; Wed, 17 Jun 2026 21:57:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781733435; cv=none; b=ltSilqHJolIvF4RQExIs+p/ztJ3pPwZJsScHnUORJ7epV6TUXM63AFMbPtiipVulGfaYGst2+2DzlYWmn8MPla/vUamsb3Q9lauoR8xI+rQDjUCiGS5Woub4J3mPs0YOqpjBhRxIrg+5KaFHEv+8fJwTw8bZiIT7hwsqye0mae0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781733435; c=relaxed/simple; bh=sOUDH/eBmJIXEIBOWDo6NLiv7IeXNalHO5VNllEyR4Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=IjUz8msaICfH9qI75Tq8a2pymp7sBhmc4ye0ZU4d1Ea8a5qbxfT252tbCBRGSm1tVGLy2UQ0LLfMslqb/vqjxwbuX4CKdwyMFUna3eV/FgLRM5yty/BZSZHPnkR7ca6+IIZuqSnFFc4vAXw7hM3wGGFVMhP8Oz8vgnvAFWPAsUU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QiLhRK8r; arc=none smtp.client-ip=209.85.128.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QiLhRK8r" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-7fffb090ddfso158597b3.1 for ; Wed, 17 Jun 2026 14:57:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781733432; x=1782338232; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=b4i79txrSdWrklA7gXTPspyO0HfIb8EB9otPoipYJpQ=; b=QiLhRK8r51/esrPFFE3uE1dzndxQLqNKe5FwJmESKWRcY+wmASyzR9pp0KB8/NOKSZ bxULrhjRkcx8L/7dspE/zJM8gQIf1CdRB8L9JuTLie9yvZJXWHwl35KDUYuEzVRITG6E sVLPewzTgD/keq98hfWa2FZHmjbA0thQk4Uk4dGM0tBshCZ10+KZBkw6JXUfcTBvKOGc z7iNTUEY4tG0DA0j7iBbPQkNgvK7PV2M+mof0srraSVo4kMlIz03ioCuwvZA9siOH7xo b+OT5DfRm/t0fEJjTMlH6vhApxR1d1o3fa7wb4oNdzEGkNvmnPAXj43dqCnGTICYLecq o8jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781733432; x=1782338232; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=b4i79txrSdWrklA7gXTPspyO0HfIb8EB9otPoipYJpQ=; b=hM4gTpej3z2ZwviMFVcAjjvQmvt1FcLuffom5bJzsqEBTGdLlAMJoCGU22CYyuKrhn tm5Q6qbMeX3VkdOHtO0AXn5fykuy+0Ux3UHyS0oH9fFY+YwisdZheUR9nhTcEi1ehmET HAqLmjik+nZTMqwaO/VezehWBKnRy8FAbKmVrJtf3mn9N2OUwTI7MOA3yHt+0ZJBJRA1 aXoewY8etZOupcKsrrylD+Ne00aLgC4iKtjruTpnpwlPlyp9qNu38OoSK/W3hJo8gQAn 2TJs3V2Omu8gILXcbudDqXXd1Ny1nnBzJzaGEOCiCU8kax+meBqtIZuI9AcgWsJ6u1NU pm8A== X-Forwarded-Encrypted: i=1; AFNElJ+qJbdhGBaWuoVATh2EsV0Qi9+paIH/x1BQw3lbYc4nYH9GPwA9Fpg9QczWmUCIsI/ptJCx5CB5/ID4AhA=@vger.kernel.org X-Gm-Message-State: AOJu0YyRgifjcqLN/jG1JHi4KKWCa/l2nQlc5H51cpCVr5ZjZyVYsArq 5yAdUoLXD2MX/A6Dvo7bXd3sKpjo1JPMRfFtolynZM6LPX5jFYfhnie+ X-Gm-Gg: AfdE7cn9qCiyyZhwUkeo93he4OKNkACvykrSZBnX5z/FAV9qGZeagwtp+fGyLbXXOvS hieYrmkP52EtIJ6n+bp36GA2JciLMvRtVIa54KCLcS79WmfUHMDi/Gk+7nqXjRmEqGUc1ovhVuG Ryud6x4p/w9n1Nqx12e5sKBhGP0RzKShVrQ5xXea3IbQMDbiME+yr1NekscTiuo2UKBYyhDvdNU livtgcAXNNexLH9f148RaZ/TsbUnIGrZnemYhWUEtPgbgsdxUDKxCprzyXs3Sqo8d9iTXMR9YsS QEgqFykxU33sVDCYZvWxNJHnfCBBYn4KjXrzEj8nN6dDaZ/NI12nUpVECh6kHXGPqou80qCha24 bzM5KzcwJLUsN0XqcyBYY3EdY/d4hZRJU5mHY70F+MmDH+kfJ1NsrAPXuiWf4nYs9L5scIB4KfJ yNq1tsxdfJuB2jCpBT1/1L7AIc08MkODOEVt95U2f5OEfRTveLxcATGtC3zqApjL5kSHB3daEJg x1l1/D+MwQay0FT+zY5Dudavab5iUt0 X-Received: by 2002:a05:690c:7107:b0:7dd:a645:a57 with SMTP id 00721157ae682-7ffa0a80b1bmr13574617b3.10.1781733431970; Wed, 17 Jun 2026 14:57:11 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7fcd3465c7csm55945147b3.39.2026.06.17.14.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2026 14:57:11 -0700 (PDT) From: Michael Bommarito To: Jamal Hadi Salim , Jiri Pirko Cc: Pablo Neira Ayuso , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net] net/sched: act_ct: fix nf_connlabels leak on two error paths Date: Wed, 17 Jun 2026 17:57:08 -0400 Message-ID: <20260617215708.1115818-1-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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") Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito --- Testing: refcount/counter leak (CWE-772); no sanitizer for this class, so the oracle is the nf_connlabels accounting counter net->ct.labels_used. Reproduction (UML, before/after, same trigger): CONFIG_NET_ACT_CT=y, NF_CONNTRACK_LABELS=y, NF_CONNTRACK_ZONES=n (forces the zone-disabled path). A raw RTM_NEWACTION trigger adds "action ct label 0x1/0x1 zone 1" 20 times; each returns -EOPNOTSUPP. stock: net->ct.labels_used climbs 1,2,...,20 (get, then bare return, no put) -- 20 leaked counts, never recovered. patched: counter stays balanced (get then goto err -> put); baseline. Control: the same loop without "label" (no nf_connlabels_get) leaves the counter unchanged on both trees -- the trigger reached the labels path and the synthesis is not itself the cause. Conditions: reachable via RTM_NEWACTION with CAP_NET_ADMIN over the netns, i.e. an unprivileged user in a fresh user+net namespace on default-userns distros. The easy path needs CONFIG_NF_CONNTRACK_ZONES=n; the nf_ct_tmpl_alloc ENOMEM path leaks on any config under memory pressure. Mitigations: restrict unprivileged user namespaces; otherwise none short of the fix. Harness (trigger.c, init) available on request. net/sched/act_ct.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c index 6158e13c98d35..f5866a364a74a 100644 --- a/net/sched/act_ct.c +++ b/net/sched/act_ct.c @@ -1295,7 +1295,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, @@ -1308,7 +1309,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]) { -- 2.53.0