Skip to content

netfilter: nf_tables: unconditionally bump set->nelems before insertion

Steffen Pfendtner netfilter-devel stable 3 versions – Applied

Status from this message: Queued the series for 5.10, thanks.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest posting 2/22 patches 1 replyApplied
  2. v2 posting 1/22 patches 1 replyApplied
  3. v11 patch 1 replySuperseded

Changes in v2 from the cover letter

- Add d4b7f29eb85c as patch 1/2 (Sasha). 5.10 only counts an element when set->size is non-zero but always decrements, and nft_dynset_init() gives an unsized set a size when a dynset rule binds it. Elements added before the bind are never counted, deleting them drives set->nelems negative, and the new unsigned nelems > max check then returns -ENFILE on an empty set. Reproduced on 5.10 with v1 applied; v2 accepts the add.
- 1/2 is adapted: 5.10 has no NFT_SET_ELEM_CATCHALL, so every element is counted.
- 2/2: drop v1's set->size guards on the increment and the error-path atomic_dec(); the ceiling is set->size ? set->size + set->ndeact :
UINT_MAX, the same expression 1/2 uses.
- 2/2: restore Pablo's authorship (Sasha; v1 had no in-body From:).
- Rebased onto the current queue-5.10.

Patches in v2 posting 2/2 Applied

#Subject and filesSizeRepliesApplied
1/2netfilter: nf_tables: always increment set element countnet/netfilter/nf_tables_api.c+2 -20 replies
2/2netfilter: nf_tables: unconditionally bump set->nelems before insertionnet/netfilter/nf_tables_api.c+12 -100 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 5.10.y 0/2] netfilter: nf_tables: unconditionally bump set->nelems before insertion

This is the 5.10.y backport of def602e498a4 ("netfilter: nf_tables:
unconditionally bump set->nelems before insertion"), now with its prerequisite d4b7f29eb85c ("netfilter: nf_tables: always increment set element count") as patch 1, as in 6.1.y and as in the 5.15.y v2.

Changes in v2:
- Add d4b7f29eb85c as patch 1/2 (Sasha). 5.10 only counts an element when set->size is non-zero but always decrements, and nft_dynset_init() gives an unsized set a size when a dynset rule binds it. Elements added before the bind are never counted, deleting them drives set->nelems negative, and the new unsigned nelems > max check then returns -ENFILE on an empty set. Reproduced on 5.10 with v1 applied; v2 accepts the add.
- 1/2 is adapted: 5.10 has no NFT_SET_ELEM_CATCHALL, so every element is counted.
- 2/2: drop v1's set->size guards on the increment and the error-path atomic_dec(); the ceiling is set->size ? set->size + set->ndeact :
UINT_MAX, the same expression 1/2 uses.
- 2/2: restore Pablo's authorship (Sasha; v1 had no in-body From:).
- Rebased onto the current queue-5.10.

Build-tested (arm64, W=1) and boot-tested under QEMU with KASAN on top of queue-5.10: the set size limit is still enforced (-ENFILE), counts stay correct across delete/re-add and flush, unlimited sets are unaffected, dynset (packet path) plus control-plane adds/deletes give no spurious -ENFILE, including when the dynset rule binds a set that already holds elements. No KASAN reports.

Florian Westphal (1):
netfilter: nf_tables: always increment set element count

Pablo Neira Ayuso (1):
netfilter: nf_tables: unconditionally bump set->nelems before
insertion

 net/netfilter/nf_tables_api.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
Signature · 1 line
2.39.5