0002-nft-ruleparse-Add-missing-braces-around-ternary.patch 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. From 2026b08bce7fe87b5964f7912e1eef30f04922c1 Mon Sep 17 00:00:00 2001
  2. From: Phil Sutter <phil@nwl.cc>
  3. Date: Fri, 26 Jan 2024 18:43:10 +0100
  4. Subject: [PATCH] nft: ruleparse: Add missing braces around ternary
  5. The expression evaluated the sum before the ternay, consequently not
  6. adding target->size if tgsize was zero.
  7. Identified by ASAN for a simple rule using standard target:
  8. | # ebtables -A INPUT -s de:ad:be:ef:0:00 -j RETURN
  9. | # ebtables -D INPUT -s de:ad:be:ef:0:00 -j RETURN
  10. | =================================================================
  11. | ==18925==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000000120 at pc 0x7f627a4c75c5 bp 0x7ffe882b5180 sp 0x7ffe882b4928
  12. | READ of size 8 at 0x603000000120 thread T0
  13. | [...]
  14. Upstream-Status: Backport [2026b08bce7fe87b5964f7912e1eef30f04922c1]
  15. Fixes: 2a6eee89083c8 ("nft-ruleparse: Introduce nft_create_target()")
  16. Signed-off-by: Phil Sutter <phil@nwl.cc>
  17. ---
  18. iptables/nft-ruleparse.c | 2 +-
  19. 1 file changed, 1 insertion(+), 1 deletion(-)
  20. diff --git a/iptables/nft-ruleparse.c b/iptables/nft-ruleparse.c
  21. index 0bbdf44faf..3b1cbe4fa1 100644
  22. --- a/iptables/nft-ruleparse.c
  23. +++ b/iptables/nft-ruleparse.c
  24. @@ -94,7 +94,7 @@ __nft_create_target(struct nft_xt_ctx *ctx, const char *name, size_t tgsize)
  25. if (!target)
  26. return NULL;
  27. - size = XT_ALIGN(sizeof(*target->t)) + tgsize ?: target->size;
  28. + size = XT_ALIGN(sizeof(*target->t)) + (tgsize ?: target->size);
  29. target->t = xtables_calloc(1, size);
  30. target->t->u.target_size = size;