diff options
author | Christian Taedcke <christian.taedcke@weidmueller.com> | 2024-07-24 11:03:38 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-07-26 12:28:42 +0100 |
commit | 138a1990e03183eae96a4c2c2f3daced329e7eba (patch) | |
tree | b0c4de961c513f83a7d861a18d856ae035298811 | |
parent | 1dda68d7f22817e0c8944b2e0eda858f53bd12f6 (diff) | |
download | poky-138a1990e03183eae96a4c2c2f3daced329e7eba.tar.gz |
iptables: fix memory corruption when parsing nft rules
This commit fixes a memory corruption issue when iptables (with
enabled PACKAGECONFIG libnftnl) is used to access rules created by
nft.
To reproduce the issue:
nft add chain ip filter TESTCHAIN { meta mark set 123 \;}
iptables -t filter -n -L TESTCHAIN
This produced the following output:
Chain TESTCHAIN (0 references)
target prot opt source destination
MARK 0 -- 0.0.0.0/0 0.0.0.0/0 MARK set 0x7b
malloc(): corrupted top size
Aborted (core dumped)
This commit fixes this issue.
(From OE-Core rev: 461d6333dabacdc181c91f31a8dd4ad6682cc0e4)
Signed-off-by: Christian Taedcke <christian.taedcke@weidmueller.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/recipes-extended/iptables/iptables/0002-nft-ruleparse-Add-missing-braces-around-ternary.patch | 37 | ||||
-rw-r--r-- | meta/recipes-extended/iptables/iptables_1.8.10.bb | 1 |
2 files changed, 38 insertions, 0 deletions
diff --git a/meta/recipes-extended/iptables/iptables/0002-nft-ruleparse-Add-missing-braces-around-ternary.patch b/meta/recipes-extended/iptables/iptables/0002-nft-ruleparse-Add-missing-braces-around-ternary.patch new file mode 100644 index 0000000000..4cbc8bdaf4 --- /dev/null +++ b/meta/recipes-extended/iptables/iptables/0002-nft-ruleparse-Add-missing-braces-around-ternary.patch | |||
@@ -0,0 +1,37 @@ | |||
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 | |||
6 | The expression evaluated the sum before the ternay, consequently not | ||
7 | adding target->size if tgsize was zero. | ||
8 | |||
9 | Identified by ASAN for a simple rule using standard target: | ||
10 | | # ebtables -A INPUT -s de:ad:be:ef:0:00 -j RETURN | ||
11 | | # ebtables -D INPUT -s de:ad:be:ef:0:00 -j RETURN | ||
12 | | ================================================================= | ||
13 | | ==18925==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000000120 at pc 0x7f627a4c75c5 bp 0x7ffe882b5180 sp 0x7ffe882b4928 | ||
14 | | READ of size 8 at 0x603000000120 thread T0 | ||
15 | | [...] | ||
16 | |||
17 | Upstream-Status: Backport [2026b08bce7fe87b5964f7912e1eef30f04922c1] | ||
18 | |||
19 | Fixes: 2a6eee89083c8 ("nft-ruleparse: Introduce nft_create_target()") | ||
20 | Signed-off-by: Phil Sutter <phil@nwl.cc> | ||
21 | --- | ||
22 | iptables/nft-ruleparse.c | 2 +- | ||
23 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
24 | |||
25 | diff --git a/iptables/nft-ruleparse.c b/iptables/nft-ruleparse.c | ||
26 | index 0bbdf44faf..3b1cbe4fa1 100644 | ||
27 | --- a/iptables/nft-ruleparse.c | ||
28 | +++ b/iptables/nft-ruleparse.c | ||
29 | @@ -94,7 +94,7 @@ __nft_create_target(struct nft_xt_ctx *ctx, const char *name, size_t tgsize) | ||
30 | if (!target) | ||
31 | return NULL; | ||
32 | |||
33 | - size = XT_ALIGN(sizeof(*target->t)) + tgsize ?: target->size; | ||
34 | + size = XT_ALIGN(sizeof(*target->t)) + (tgsize ?: target->size); | ||
35 | |||
36 | target->t = xtables_calloc(1, size); | ||
37 | target->t->u.target_size = size; | ||
diff --git a/meta/recipes-extended/iptables/iptables_1.8.10.bb b/meta/recipes-extended/iptables/iptables_1.8.10.bb index 81eba6c967..a94e4749ae 100644 --- a/meta/recipes-extended/iptables/iptables_1.8.10.bb +++ b/meta/recipes-extended/iptables/iptables_1.8.10.bb | |||
@@ -14,6 +14,7 @@ SRC_URI = "http://netfilter.org/projects/iptables/files/iptables-${PV}.tar.xz \ | |||
14 | file://ip6tables.service \ | 14 | file://ip6tables.service \ |
15 | file://ip6tables.rules \ | 15 | file://ip6tables.rules \ |
16 | file://0001-configure-Add-option-to-enable-disable-libnfnetlink.patch \ | 16 | file://0001-configure-Add-option-to-enable-disable-libnfnetlink.patch \ |
17 | file://0002-nft-ruleparse-Add-missing-braces-around-ternary.patch \ | ||
17 | " | 18 | " |
18 | SRC_URI[sha256sum] = "5cc255c189356e317d070755ce9371eb63a1b783c34498fb8c30264f3cc59c9c" | 19 | SRC_URI[sha256sum] = "5cc255c189356e317d070755ce9371eb63a1b783c34498fb8c30264f3cc59c9c" |
19 | 20 | ||