From nobody Tue Jun 16 19:33:09 2026 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 60BA03CA4A3 for ; Wed, 29 Apr 2026 17:56:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777485379; cv=none; b=nWUqDeRKx3OyUgYBtcDLtQjSY5+7ZMTCr676Hw9JFsJFtPE4Ekhfk1WnPAzHMwyUSN5YBTiGJCR5jJ3ogdBLAvrXQ/i31O7y9NYAq8Ya4J3tlHuKFcrQlS9WhRag4OITHq00pD5E5GkWxtPh55cUfLC2raT1CBEbs9GFjLViHxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777485379; c=relaxed/simple; bh=eDBirYq4pCbL+nEUiEp7cl5+N06I9yeNRMJUvi0dUZs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gE31Z0K3UsqPV/DKu+zeukwFoMnQkqvzoB5u5pnIPO5eEtSPQp0FP4VtWzmjQS1psLHitm784z2GXVXbnKVdfGWmBFEsG4N5JvtYcB/R1BnID29Uoa5XdqT2DThZRA+0LhE+KSI7E2sTdi0rOpaXYT0/ceCvWQIwMLj1yiNPW5E= 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=jYQAlbJM; arc=none smtp.client-ip=209.85.128.52 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="jYQAlbJM" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-488a14c31eeso276735e9.0 for ; Wed, 29 Apr 2026 10:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777485376; x=1778090176; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZAVLe7MO2A1MyrDF6a2t4MvPRiDZqS4DmH+U/JOcnYM=; b=jYQAlbJMAUmgBX14wyxFlZBhXAKj3S+TKPLSDiohw7yy20edVzYsqczSigBf0J6CcC ktDQiI+MWNeYMkIasiq6Qa6I8khKvtNF5t2q33GMs9LFFsuSvZuUIy88OuGlTYUP4IkD WPkh/d+tsh2lw6msVv4Q+TiPhfofGlpslXAeSx/2MpTgu6SLSRqstfmuT/4zkVjdmJOL FOo889lSGnqyx97fziO/SI+wjyWY2ZOWYsmPwZ9UTjf4w/BYKexvsrhONblzXMIHeHEd FmQL/73zTpBwt2H6vWHOIHk9wYs0vqoo7ffG7R2+fu40Cx1svYsuGwplU06b9E4pzZCy uO4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777485376; x=1778090176; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ZAVLe7MO2A1MyrDF6a2t4MvPRiDZqS4DmH+U/JOcnYM=; b=U+FVg3BpyYKFTayu9HJuuiC/uYBl21h5vrate00UOvKNkTkb9pJWsl9zHJcA7l/lQ/ q9IKiYvXbQSgkk54sbvtnG+RcdNzJqqpJfwaOoJpFoLUG9pReN9ZJ4WT1dbpCtUgqeUO /yVVc1jNoNRS1089bqBOn+sqp7qBvVCh1AJe9kaAnM+BCjoY6dqYUzlutJKtwgesx/lh RVIDjz6G5hag3SOYV4GhcSZ9NKQB04wALK3lmb0cIFPhuK0zg6ZNODWBulWz9h8RB3qE GTLEOAicry862f5N+hRHwl+k1QXg2zVHEYJ2HJqOPozxMxPanRnvZzR36KbdgOdwH11k zUxQ== X-Forwarded-Encrypted: i=1; AFNElJ+NG+w3BRvgm/IZ8lS/vjgfRctkHnKWEfJlEl/hMHsBeiVh7JXof8xH4KIW0+pCp59FrRm0VzpNRGmHXYM=@vger.kernel.org X-Gm-Message-State: AOJu0YyrgjFwzXD0aVWsWwEUxBlKh7q/33PThaWjCHnWzs7giU3W6yVG ckSPxB8kvlVwTWqS1+yrsiAjU7UTTABVtLHYKeB7MS9PPTCM11oL2ek= X-Gm-Gg: AeBDiev9KJKaU82T8KzFqGdV1ul05Xg6dx00qhiscUC8MSuPxrKr1HfwOXjUYw+YQS4 1cUZ2vNSfXoquYhB/vlcyoHr4WlDBVSdRHglZxWmzZ4K5vj5pxug/Hjb3ew9+ggaBd8KGdYjH9z Pmx2Qj2aci32kp7ymIlkl+dc4ZYVaohzJGwI3i1HYIJMFmXFb2+TEv8cf2xGFh1nqu2J1EF4jy3 goGf2ipHir+q03HxxjThC7Vswo8hXDiYMNLfAcWbOGaalG9bgMvt50xfJ7nkOwiW22dLNalguQe OJKb9tsdlaIgNzV3UOCjl2W9FsdQaEO/kZUda8SQD26Pip1W2YRyyeRbgqePvOpLAa1X4z6+JO1 IqbyLO1CmhYNbfJNYkUONbIcI22unTXIyJdzP+eg9L9R5OxgHp4X+g+G57Y4ubfBqaaQsjwq3t0 7tb4M= X-Received: by 2002:a05:600c:c048:b0:485:39b2:a47c with SMTP id 5b1f17b1804b1-48a77b22dedmr99590625e9.25.1777485375550; Wed, 29 Apr 2026 10:56:15 -0700 (PDT) Received: from debian.. ([2001:41d0:303:db6b::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-447b3d48517sm6183750f8f.5.2026.04.29.10.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2026 10:56:14 -0700 (PDT) From: Tristan Madani To: Pablo Neira Ayuso Cc: Florian Westphal , Phil Sutter , netfilter-devel@vger.kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org, Tristan Madani Subject: [PATCH 1/2] netfilter: ip_tables: allocate hook ops before making table visible Date: Wed, 29 Apr 2026 17:56:11 +0000 Message-ID: <20260429175613.1459342-2-tristmd@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260429175613.1459342-1-tristmd@gmail.com> References: <20260429175613.1459342-1-tristmd@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Tristan Madani ipt_register_table() adds the table to the per-netns list via xt_register_table() before allocating the per-netns hook ops copy via kmemdup_array(). This leaves a window where the table is visible in the list with ops=3DNULL. If cleanup_net() runs during this window (e.g. due to concurrent netns teardown with failslab-induced allocation failures), the pre_exit callback finds the table via xt_find_table() and passes the NULL ops pointer to nf_unregister_net_hooks(), causing a NULL pointer dereference: general protection fault in nf_unregister_net_hooks+0xbc/0x150 RIP: nf_unregister_net_hooks (net/netfilter/core.c:613) Call Trace: ipt_unregister_table_pre_exit iptable_mangle_net_pre_exit ops_pre_exit_list cleanup_net Fix by moving the ops allocation before xt_register_table() so the table is never in the list without valid ops. Fixes: ae689334225f ("netfilter: ip_tables: pass table pointer via nf_hook_= ops") Cc: stable@vger.kernel.org Signed-off-by: Tristan Madani --- net/ipv4/netfilter/ip_tables.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c index 23c8deff8095a..c47bc776eb4f2 100644 --- a/net/ipv4/netfilter/ip_tables.c +++ b/net/ipv4/netfilter/ip_tables.c @@ -1745,6 +1745,21 @@ int ipt_register_table(struct net *net, const struct= xt_table *table, return ret; } =20 + if (template_ops) { + num_ops =3D hweight32(table->valid_hooks); + if (num_ops =3D=3D 0) { + xt_free_table_info(newinfo); + return -EINVAL; + } + + ops =3D kmemdup_array(template_ops, num_ops, sizeof(*ops), + GFP_KERNEL); + if (!ops) { + xt_free_table_info(newinfo); + return -ENOMEM; + } + } + new_table =3D xt_register_table(net, table, &bootstrap, newinfo); if (IS_ERR(new_table)) { struct ipt_entry *iter; @@ -1752,27 +1767,13 @@ int ipt_register_table(struct net *net, const struc= t xt_table *table, xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) cleanup_entry(iter, net); xt_free_table_info(newinfo); + kfree(ops); return PTR_ERR(new_table); } =20 - /* No template? No need to do anything. This is used by 'nat' table, it r= egisters - * with the nat core instead of the netfilter core. - */ if (!template_ops) return 0; =20 - num_ops =3D hweight32(table->valid_hooks); - if (num_ops =3D=3D 0) { - ret =3D -EINVAL; - goto out_free; - } - - ops =3D kmemdup_array(template_ops, num_ops, sizeof(*ops), GFP_KERNEL); - if (!ops) { - ret =3D -ENOMEM; - goto out_free; - } - for (i =3D 0; i < num_ops; i++) ops[i].priv =3D new_table; =20 --=20 2.47.3 From nobody Tue Jun 16 19:33:09 2026 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 12B0B41323C for ; Wed, 29 Apr 2026 17:56:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777485379; cv=none; b=Og4AYSWNPHC/raiInst8HcWCd5aTXT74uAZwvDl+ELhopLqEOLXNZ+Op8TEIOZ/gRUWN8jxdCygB/KTg5LoLPEhR8sLoQF06YHAaZt/ON/mSbjRlsKPsySkl7j3jlMho3u74eG6yzyH2oTOblu/tTVKk9aJbo7Hrr+HxVXQKOXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777485379; c=relaxed/simple; bh=hPxaXd3xjy2aLoQlfjNn2TCMZsSvXUAXKxOi1BUCOho=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Eo2V1V8gHAOSietNt2HPKoWQfZUdSriT7TYLipFyLR8+KcMxtITMROlK1EcZcOCO19ksf4uFlMfu61BdA4J/OhntwwZjLEqF3I+Y23va5MlHxhbqzRxE/+HclzwHALfleh9pFwhZcald9Lazhk2uwuxkyhRVJChY6smMJSa1BcY= 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=cOCqCjDy; arc=none smtp.client-ip=209.85.221.52 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="cOCqCjDy" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-43cfd832155so59307f8f.1 for ; Wed, 29 Apr 2026 10:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777485376; x=1778090176; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m+m+c0QFSmHtefs8UGhgSoeILNWZg2rQuDAplxBi5ys=; b=cOCqCjDy12B6ro9esSG+onM18Ju1+DNt8/lJj8j5rlGgFor/h5mlDqT3erRDdbA+ES gHnNUhRutovnkf/sUDku21JaD+l5b3ZO7HzsvKFyA+v1p8eOYzU+H/FXzPAMhg2ke7yG UNeh6nngm5LEjC2jXkbTF3ix0qJV3IHHLcfDQX/YcUUl2BwRkS8XkBfbgD6gMUlnw+ji lC5Ht0vquY4rWMH8MPLqKQAS/TYI6O7AFSiq9VyoMmWuzZPY4MDdk5o1k7fLD+0zEts9 TKqYWefBXPw6owlzPTYACRXr2GBB3VqLj7eitM5b9JV8SJJyPi5S7jhq1CfRZOEhEsBv eMzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777485376; x=1778090176; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=m+m+c0QFSmHtefs8UGhgSoeILNWZg2rQuDAplxBi5ys=; b=H+noyiRsColGBHI8s6u8MpOLAP4ecY8q6ELhY0S0VAevrOX5kWuppEB3Nd50+6oN1B rOlGIlD6RMG4mvsYuhZ2/oBIwBdaDpD9CSuIrpnSACCb3oCvJiFU6ZR4GoN+V4a/MWGf sGS6i7bOefxOq8BXrC2QQcc4kHMN5v8xz+YArSqekKch2sdgGeBlHWTEbYj0lcE58yJJ b84JsecuvseSsHHhRIpLtW5h8heKyoxyEWeGXGJ9g2lUIF2HiWSKWfET1UP7qO3dVF6i rG+5ZZqAdobofvkOVsiDc4mLvH19KyBTlw6XdJCcz3f1oGXKGyJEAGXGMai86lT68cNI IEmA== X-Forwarded-Encrypted: i=1; AFNElJ8f404iR/2rySRAfC/1aGPJilb598lYONtxQMAcR46f5S7RK1fq/4BnoUeOaf5u4W2cn/8Q7RXOHmPRnwI=@vger.kernel.org X-Gm-Message-State: AOJu0Yxqe4p9arNh0mZ6/4PHXT/6ky1Tqz7pp6jIZcUCwgVEgkIA/ndC ABr6E1kbE2hr+DdoRx3hwh0YTd7tF3XL2YE+vQ8TmohFe0uSHTgVO10= X-Gm-Gg: AeBDiet544G4ivTZJRhvWzJGkFDSc7ZAZJv6EHyRpepNI+uX93NpoO0AUlxquAWmfii /mNsofn5AMYRGGS8UPBF8EyoB1mmpIvneLmk4qDCDFk97p633u795jLe0L/0hHSY4ZAV9AgUcJw KqT0Tm9nBoosjeqtJTCUlbZIyvC5TtjO9zwXCZ61Ggr0uVocMyXtumYtwlZtFH4NrzqX3mWcJke D0Agi0QltzMMLsPnp6wniSY81hErLLOMTxelpDM5fDByT59pUJHS6ZFMItLyZ8S1bUCFYbhA6Rw wdcU/NnYQIIs7O55YpFaKRt/tN8SlxagGAr2rHXTGyLHqB04jetY7BOI9E5Z+Lm9xY/q6slt8dy 8/OMeJPYT10EpvKZOnS3IC8StvvbqOYItQyC/db8bhQZMrrErZdgWDt6pA8LGe9Z9EpDSiUU5kd Y+PTXqljaWGKh0Xg== X-Received: by 2002:a5d:5848:0:b0:441:2473:c30a with SMTP id ffacd0b85a97d-446496d79aemr15475160f8f.31.1777485376333; Wed, 29 Apr 2026 10:56:16 -0700 (PDT) Received: from debian.. ([2001:41d0:303:db6b::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-447b3d48517sm6183750f8f.5.2026.04.29.10.56.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2026 10:56:15 -0700 (PDT) From: Tristan Madani To: Pablo Neira Ayuso Cc: Florian Westphal , Phil Sutter , netfilter-devel@vger.kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org, Tristan Madani Subject: [PATCH 2/2] netfilter: ip6_tables: allocate hook ops before making table visible Date: Wed, 29 Apr 2026 17:56:12 +0000 Message-ID: <20260429175613.1459342-3-tristmd@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260429175613.1459342-1-tristmd@gmail.com> References: <20260429175613.1459342-1-tristmd@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Tristan Madani ip6t_register_table() first calls xt_register_table() which adds the table to the per-netns list, making it visible to other code paths. Only after that does it allocate the per-net copy of hook ops via kmemdup_array(). This leaves a window where the table is findable via xt_find_table() but has ops=3DNULL. If cleanup_net runs during this window (racing namespace teardown against lazy table init), ip6t_unregister_table_pre_exit() finds the table via xt_find_table() and passes the NULL ops pointer to nf_unregister_net_hooks(), causing a general protection fault when it dereferences ops[0].pf. Fix this by allocating the ops array before calling xt_register_table(), so the table is never visible in the list with a NULL ops pointer. Fixes: ee177a54413a ("netfilter: ip6_tables: pass table pointer via nf_hook= _ops") Cc: stable@vger.kernel.org Signed-off-by: Tristan Madani --- net/ipv6/netfilter/ip6_tables.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_table= s.c index d585ac3c11133..17143277637a5 100644 --- a/net/ipv6/netfilter/ip6_tables.c +++ b/net/ipv6/netfilter/ip6_tables.c @@ -1754,6 +1754,21 @@ int ip6t_register_table(struct net *net, const struc= t xt_table *table, return ret; } =20 + if (template_ops) { + num_ops =3D hweight32(table->valid_hooks); + if (num_ops =3D=3D 0) { + xt_free_table_info(newinfo); + return -EINVAL; + } + + ops =3D kmemdup_array(template_ops, num_ops, sizeof(*ops), + GFP_KERNEL); + if (!ops) { + xt_free_table_info(newinfo); + return -ENOMEM; + } + } + new_table =3D xt_register_table(net, table, &bootstrap, newinfo); if (IS_ERR(new_table)) { struct ip6t_entry *iter; @@ -1761,24 +1776,13 @@ int ip6t_register_table(struct net *net, const stru= ct xt_table *table, xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) cleanup_entry(iter, net); xt_free_table_info(newinfo); + kfree(ops); return PTR_ERR(new_table); } =20 if (!template_ops) return 0; =20 - num_ops =3D hweight32(table->valid_hooks); - if (num_ops =3D=3D 0) { - ret =3D -EINVAL; - goto out_free; - } - - ops =3D kmemdup_array(template_ops, num_ops, sizeof(*ops), GFP_KERNEL); - if (!ops) { - ret =3D -ENOMEM; - goto out_free; - } - for (i =3D 0; i < num_ops; i++) ops[i].priv =3D new_table; =20 --=20 2.47.3