Skip to content

netfilter: fix NULL ops dereference in iptable lazy init

Tristan Madani lkml netdev netfilter-devel stable 2 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 5 repliesIn review
  2. v12 patches 2 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2netfilter: ip_tables: guard ipt_unregister_table_pre_exit against NULL opsnet/ipv4/netfilter/ip_tables.c+1 -15 replies
2/2netfilter: ip6_tables: guard ip6t_unregister_table_pre_exit against NULL opsnet/ipv6/netfilter/ip6_tables.c+1 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/2] netfilter: fix NULL ops dereference in iptable lazy init

v1 moved the ops allocation before xt_register_table(), but as Phil Sutter pointed out, new_table->ops is still assigned after the table becomes visible via list_add() inside xt_register_table(). The race window was reduced but not eliminated.

v2 takes a different approach: guard the pre_exit path against a NULL ops pointer. If cleanup_net races against lazy table init and finds the table before ops has been assigned, it simply skips the nf_unregister_net_hooks() call. The register path will either complete normally or fail and clean up via __ipt_unregister_table().

v1: https://lore.kernel.org/netdev/[email protected]/

Tristan Madani (2):
netfilter: ip_tables: guard ipt_unregister_table_pre_exit against NULL ops
netfilter: ip6_tables: guard ip6t_unregister_table_pre_exit against NULL ops

 net/ipv4/netfilter/ip_tables.c  | 2 +-
 net/ipv6/netfilter/ip6_tables.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)