Skip to contentSkip to conversation

tc: m_xt: Fix segfault with iptables-1.6.0

PATCH In review Phil Sutter 2 participants 3 messages Jan 12, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tc: m_xt: Fix segfault with iptables-1.6.0

Said iptables version introduced struct xtables_globals field 'compat_rev', a function pointer. Initializing it is mandatory as libxtables calls it without existence check.

Without this, tc segfaults when using the xt action like so:

| tc filter add dev d0 parent ffff: u32 match u32 0 0 \
| action xt -j MARK --set-mark 20

---
 tc/m_xt.c | 3 +++
 1 file changed, 3 insertions(+)
tc/m_xt.c +3 -0
index dbb54981462ee..57ed40d7aa3a8 100644
@@ -77,6 +77,9 @@ static struct xtables_globals tcipt_globals = {
 	.orig_opts = original_opts,
 	.opts = original_opts,
 	.exit_err = NULL,
+#if (XTABLES_VERSION_CODE >= 11)
+	.compat_rev = xtables_compatible_revision,
+#endif
 };
 
 /*
Signature · 1 line
2.11.0
#1 lore raw
Quoted 19 lines · On Thu, 12 Jan 2017 15:22:49 +0100 Phil Sutter <[email protected]> wrote:

Said iptables version introduced struct xtables_globals field 'compat_rev', a function pointer. Initializing it is mandatory as libxtables calls it without existence check.

Without this, tc segfaults when using the xt action like so:

| tc filter add dev d0 parent ffff: u32 match u32 0 0 \
| action xt -j MARK --set-mark 20

---
 tc/m_xt.c | 3 +++
 1 file changed, 3 insertions(+)
tc/m_xt.c +0 -0
index dbb54981462ee..57ed40d7aa3a8 100644

tc/m_xt.c static struct xtables_globals tcipt_globals = { · line 85

Quoted 9 lines
tc/m_xt.c +3 -0
@@ -77,6 +77,9 @@ static struct xtables_globals tcipt_globals = {
 	.orig_opts = original_opts,
 	.opts = original_opts,
 	.exit_err = NULL,
+#if (XTABLES_VERSION_CODE >= 11)
+	.compat_rev = xtables_compatible_revision,
+#endif
 };
 
 /*

Ah the xtables API is not really an application friendly API by any stretch of the imagination

Parenthesis not really necessary there.

#2 lore raw
Quoted 30 lines · Stephen Hemminger
Quoted 27 lines · On Thu, 12 Jan 2017 15:22:49 +0100 Phil Sutter <[email protected]> wrote:

Said iptables version introduced struct xtables_globals field 'compat_rev', a function pointer. Initializing it is mandatory as libxtables calls it without existence check.

Without this, tc segfaults when using the xt action like so:

| tc filter add dev d0 parent ffff: u32 match u32 0 0 \
| action xt -j MARK --set-mark 20

---
 tc/m_xt.c | 3 +++
 1 file changed, 3 insertions(+)
tc/m_xt.c +3 -0
index dbb54981462ee..57ed40d7aa3a8 100644
@@ -77,6 +77,9 @@ static struct xtables_globals tcipt_globals = {
 	.orig_opts = original_opts,
 	.opts = original_opts,
 	.exit_err = NULL,
+#if (XTABLES_VERSION_CODE >= 11)
+	.compat_rev = xtables_compatible_revision,
+#endif
 };
 
Quoted 4 lines

tc/m_xt.c static struct xtables_globals tcipt_globals = { · line 85

Quoted 1 line
tc/m_xt.c +0 -0
 /*

Ah the xtables API is not really an application friendly API by any stretch of the imagination

Yeah, this could have really been handled by the lib, especially since it provides the callback to assign to it. But whatever, looking at the git log shows it's not happening for the first time so at least it's consistent. :)

Quoted 1 line

Parenthesis not really necessary there.

Oh, indeed! I just stuck to how the other XTABLES_VERSION_CODE checks are made. Are you going to apply this patch either way? I'll then follow-up dropping the parentheses at all places at once.

Thanks, Phil