Skip to contentSkip to conversation

PaX killing conntrackd (strange "execution attempt")

DISCUSSION Wolfram Schlich 3 participants 21 messages Nov 13, 2008 – Nov 24, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

Hi,

I set up a testbed for an HA firewall using Gentoo Hardened, keepalived and conntrackd.
After running for several hours, the kernel (PaX) seems to terminate the conntrackd process on the currently active firewall (hafw2) due to some odd execution attempt in a non-executable page:

--8<--

2008-11-13 07:38:34 +01:00; hafw2; kern.notice; kernel: ip4t_FW DENY_IN: IN=eth1 OUT= MAC=XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX SRC=XX.XXX.XX.XX DST=XX.XX.XXX.X LEN=48 TO
S=0x00 PREC=0x00 TTL=118 ID=23801 DF PROTO=TCP SPT=2608 DPT=21 WINDOW=65535 RES=0x00 SYN URGP=0
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: execution attempt in: <NULL>, 00000000-00000000 00000000
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: terminating task: /usr/sbin/conntrackd(conntrackd):6562, uid/euid: 0/0, PC: 0000000000000000, SP: 0000797077f7ea48
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: bytes at PC: ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: bytes at SP-8:
2008-11-13 07:38:34 +01:00; hafw2; kern.alert; kernel: grsec: denied resource overstep by requesting 4096 for RLIMIT_CORE against limit 0 for /usr/sbin/conntrackd[conntrackd:

6562] uid/euid:0/0 gid/egid:0/0, parent /sbin/init[init:1] uid/euid:0/0 gid/egid:0/0 --8<--

The log messages look somewhat strange, especially the 'NULL', '000..' and '??' parts :) I've always only seen such messages with a more meaningful content so far, thus I'm a bit confused.

What might be the reason for that?

Used software:
- Gentoo Hardened
- Kernel: 2.6.27.5 (Gentoo hardened-sources-2.6.27-r1, that is vanilla 2.6.27.5 + grsecurity 2.1.12-2.6.27.5-200811071900 + some other smaller patches)
.config: http://paste.frubar.net/9326/txt
- keepalived 1.1.15 (from Gentoo Portage)
- conntrack-tools 0.9.8 (from Gentoo Portage)

As you can see, a coredump was prevented by a resource limit. I've now removed the limit and am trying to reproduce the situation in order to get a coredump.

Signature · 3 lines
Regards,
Wolfram Schlich <[email protected]>
Gentoo Linux * http://dev.gentoo.org/~wschlich/
#1 lore raw

Here's the answer from the PaX team, for those who might be interested:

Quoted 18 lines · * [email protected] <[email protected]> [2008-11-13 14:18]:
Quoted 8 lines · Wolfram Schlich

--8<--

2008-11-13 07:38:34 +01:00; hafw2; kern.notice; kernel: ip4t_FW DENY_IN: IN=eth1 OUT= MAC=XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX SRC=XX.XXX.XX.XX DST=XX.XX.XXX.X LEN=48 TO
S=0x00 PREC=0x00 TTL=118 ID=23801 DF PROTO=TCP SPT=2608 DPT=21 WINDOW=65535 RES=0x00 SYN URGP=0
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: execution attempt in: <NULL>, 00000000-00000000 00000000
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: terminating task: /usr/sbin/conntrackd(conntrackd):6562, uid/euid: 0/0, PC: 0000000000000000, SP: 0000797077f7ea48
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: bytes at PC: ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: bytes at SP-8:
2008-11-13 07:38:34 +01:00; hafw2; kern.alert; kernel: grsec: denied resource overstep by requesting 4096 for RLIMIT_CORE against limit 0 for /usr/sbin/conntrackd[conntrackd:
Quoted 8 lines

6562] uid/euid:0/0 gid/egid:0/0, parent /sbin/init[init:1] uid/euid:0/0 gid/egid:0/0 --8<--

The log messages look somewhat strange, especially the 'NULL', '000..' and '??' parts :) I've always only seen such messages with a more meaningful content so far, thus I'm a bit confused.

What might be the reason for that?

Quoted 7 lines

this is a null function pointer dereference problem on the surface and you'll have to debug it to get more info. i wonder why nothing shows up in the stack dump however, maybe there's more corruption here behind the scenes. once you get the coredumps (and i hope you have debug info saved away ;) we can get a backtrace and other things. also disable randomization in /proc/sys/... so that results are comparable. best would be to find a way to directly trigger this crash, then you could have a live gdb session instead of coredump analysis.

I'll take care of these suggestions now and let you know about any news.

Signature · 3 lines
Regards,
Wolfram Schlich <[email protected]>
Gentoo Linux * http://dev.gentoo.org/~wschlich/
#2 lore raw
Quoted 28 lines · Wolfram Schlich

Here's the answer from the PaX team, for those who might be interested:

Quoted 16 lines · * [email protected] <[email protected]> [2008-11-13 14:18]:
Quoted 15 lines · Wolfram Schlich

--8<--

2008-11-13 07:38:34 +01:00; hafw2; kern.notice; kernel: ip4t_FW DENY_IN: IN=eth1 OUT= MAC=XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX SRC=XX.XXX.XX.XX DST=XX.XX.XXX.X LEN=48 TO
S=0x00 PREC=0x00 TTL=118 ID=23801 DF PROTO=TCP SPT=2608 DPT=21 WINDOW=65535 RES=0x00 SYN URGP=0
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: execution attempt in: <NULL>, 00000000-00000000 00000000
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: terminating task: /usr/sbin/conntrackd(conntrackd):6562, uid/euid: 0/0, PC: 0000000000000000, SP: 0000797077f7ea48
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: bytes at PC: ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: bytes at SP-8:
2008-11-13 07:38:34 +01:00; hafw2; kern.alert; kernel: grsec: denied resource overstep by requesting 4096 for RLIMIT_CORE against limit 0 for /usr/sbin/conntrackd[conntrackd:

6562] uid/euid:0/0 gid/egid:0/0, parent /sbin/init[init:1] uid/euid:0/0 gid/egid:0/0 --8<--

The log messages look somewhat strange, especially the 'NULL', '000..' and '??' parts :) I've always only seen such messages with a more meaningful content so far, thus I'm a bit confused.

Quoted 8 lines
Quoted 1 line

What might be the reason for that?

this is a null function pointer dereference problem on the surface and you'll have to debug it to get more info. i wonder why nothing shows up in the stack dump however, maybe there's more corruption here behind the scenes. once you get the coredumps (and i hope you have debug info saved away ;) we can get a backtrace and other things. also disable randomization in /proc/sys/... so that results are comparable. best would be to find a way to directly trigger this crash, then you could have a live gdb session instead of coredump analysis.

Quoted 2 lines

I'll take care of these suggestions now and let you know about any news.

Thank you. BTW, what version of conntrackd is triggering this problem? Is it latest 0.9.8?

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
#3 lore raw
Quoted 29 lines · Pablo Neira Ayuso
Quoted 28 lines · Wolfram Schlich

Here's the answer from the PaX team, for those who might be interested:

Quoted 24 lines · * [email protected] <[email protected]> [2008-11-13 14:18]:
Quoted 8 lines · Wolfram Schlich

--8<--

2008-11-13 07:38:34 +01:00; hafw2; kern.notice; kernel: ip4t_FW DENY_IN: IN=eth1 OUT= MAC=XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX SRC=XX.XXX.XX.XX DST=XX.XX.XXX.X LEN=48 TO
S=0x00 PREC=0x00 TTL=118 ID=23801 DF PROTO=TCP SPT=2608 DPT=21 WINDOW=65535 RES=0x00 SYN URGP=0
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: execution attempt in: <NULL>, 00000000-00000000 00000000
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: terminating task: /usr/sbin/conntrackd(conntrackd):6562, uid/euid: 0/0, PC: 0000000000000000, SP: 0000797077f7ea48
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: bytes at PC: ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
2008-11-13 07:38:34 +01:00; hafw2; kern.err; kernel: PAX: bytes at SP-8:
2008-11-13 07:38:34 +01:00; hafw2; kern.alert; kernel: grsec: denied resource overstep by requesting 4096 for RLIMIT_CORE against limit 0 for /usr/sbin/conntrackd[conntrackd:
Quoted 8 lines

6562] uid/euid:0/0 gid/egid:0/0, parent /sbin/init[init:1] uid/euid:0/0 gid/egid:0/0 --8<--

The log messages look somewhat strange, especially the 'NULL', '000..' and '??' parts :) I've always only seen such messages with a more meaningful content so far, thus I'm a bit confused.

What might be the reason for that?

this is a null function pointer dereference problem on the surface and you'll have to debug it to get more info. i wonder why nothing shows up in the stack dump however, maybe there's more corruption here behind the scenes. once you get the coredumps (and i hope you have debug info saved away ;) we can get a backtrace and other things. also disable randomization in /proc/sys/... so that results are comparable. best would be to find a way to directly trigger this crash, then you could have a live gdb session instead of coredump analysis.

Quoted 5 lines
Quoted 2 lines

I'll take care of these suggestions now and let you know about any news.

Thank you. BTW, what version of conntrackd is triggering this problem? Is it latest 0.9.8?

Yep, as you can see from my initial mail :)

Signature · 3 lines
Regards,
Wolfram Schlich <[email protected]>
Gentoo Linux * http://dev.gentoo.org/~wschlich/
#4 lore raw
In reply to Wolfram Schlich
Quoted 11 lines · Wolfram Schlich

Here's the answer from the PaX team, for those who might be interested:

Quoted 8 lines · * [email protected] <[email protected]> [2008-11-13 14:18]:

[...]
this is a null function pointer dereference problem on the surface and you'll have to debug it to get more info. i wonder why nothing shows up in the stack dump however, maybe there's more corruption here behind the scenes. once you get the coredumps (and i hope you have debug info saved away ;) we can get a backtrace and other things. also disable randomization in /proc/sys/... so that results are comparable. best would be to find a way to directly trigger this crash, then you could have a live gdb session instead of coredump analysis.

Quoted 2 lines

I'll take care of these suggestions now and let you know about any news.

I've now recompiled conntrack-tools using these CFLAGS:

-march=nocona -O0 -ggdb -DDEBUG

Also, the binaries were not stripped anymore:

/usr/sbin/conntrackd: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, not stripped

(I forgot to mention I'm on a 64bit kernel + userland).

I'm now stressing the firewalls with packets.

Signature · 3 lines
Regards,
Wolfram Schlich <[email protected]>
Gentoo Linux * http://dev.gentoo.org/~wschlich/
#5 lore raw
Quoted 19 lines · Wolfram Schlich
Quoted 11 lines · Wolfram Schlich

Here's the answer from the PaX team, for those who might be interested:

Quoted 8 lines · * [email protected] <[email protected]> [2008-11-13 14:18]:

[...]
this is a null function pointer dereference problem on the surface and you'll have to debug it to get more info. i wonder why nothing shows up in the stack dump however, maybe there's more corruption here behind the scenes. once you get the coredumps (and i hope you have debug info saved away ;) we can get a backtrace and other things. also disable randomization in /proc/sys/... so that results are comparable. best would be to find a way to directly trigger this crash, then you could have a live gdb session instead of coredump analysis.

Quoted 2 lines

I'll take care of these suggestions now and let you know about any news.

I've now recompiled conntrack-tools using these CFLAGS:

-march=nocona -O0 -ggdb -DDEBUG

Quoted 7 lines

Also, the binaries were not stripped anymore:

/usr/sbin/conntrackd: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, not stripped

(I forgot to mention I'm on a 64bit kernel + userland).

I'm now stressing the firewalls with packets.

Damnit, it doesn't break! :)
Been stressing the firewall with gigabytes of packets... Last time it crashed, it hadn't receive a hundred megabytes of packets at all... *sigh*

Signature · 3 lines
Regards,
Wolfram Schlich <[email protected]>
Gentoo Linux * http://dev.gentoo.org/~wschlich/
#6 lore raw
Quoted 16 lines · Wolfram Schlich
Quoted 15 lines · Wolfram Schlich
Quoted 10 lines · Wolfram Schlich

Here's the answer from the PaX team, for those who might be interested:

Quoted 8 lines · * [email protected] <[email protected]> [2008-11-13 14:18]:

[...]
this is a null function pointer dereference problem on the surface and you'll have to debug it to get more info. i wonder why nothing shows up in the stack dump however, maybe there's more corruption here behind the scenes. once you get the coredumps (and i hope you have debug info saved away ;) we can get a backtrace and other things. also disable randomization in /proc/sys/... so that results are comparable. best would be to find a way to directly trigger this crash, then you could have a live gdb session instead of coredump analysis.

Quoted 2 lines

I'll take care of these suggestions now and let you know about any news.

I've now recompiled conntrack-tools using these CFLAGS:

Quoted 7 lines
Quoted 7 lines

-march=nocona -O0 -ggdb -DDEBUG

Also, the binaries were not stripped anymore:

/usr/sbin/conntrackd: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, not stripped

(I forgot to mention I'm on a 64bit kernel + userland).

My testbed for stress testing is also a 64 bit platform.

Quoted 3 lines
Quoted 1 line

I'm now stressing the firewalls with packets.

Damnit, it doesn't break! :)

So it seems that it is only triggered with PaX enabled.

Quoted 3 lines

Been stressing the firewall with gigabytes of packets... Last time it crashed, it hadn't receive a hundred megabytes of packets at all... *sigh*

Probably you can run conntrackd inside valgrind to see if it complains about any invalid memory access.

BTW, I'm interested in whatever benchmark results of conntrackd, just for the record.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
#7 lore raw
Quoted 11 lines · Pablo Neira Ayuso
Quoted 10 lines · Wolfram Schlich
Quoted 9 lines · Wolfram Schlich

I've now recompiled conntrack-tools using these CFLAGS:

-march=nocona -O0 -ggdb -DDEBUG

Also, the binaries were not stripped anymore:

/usr/sbin/conntrackd: ELF 64-bit LSB shared object, x86-64, version 1
(SYSV), for GNU/Linux 2.6.9, not stripped

Quoted 6 lines

[...]

Quoted 3 lines
Quoted 1 line

I'm now stressing the firewalls with packets.

Damnit, it doesn't break! :)

So it seems that it is only triggered with PaX enabled.

I never disabled PaX!

Now I got a core, after more than a day, but it doesn't look good :(

Here's the log entry:
--8<--
11-14 14:25:20 +01:00; hafw2; kern.err; kernel: PAX: From 10.10.10.249: execution attempt in: <NULL>, 00000000-00000000 00000000
11-14 14:25:20 +01:00; hafw2; kern.err; kernel: PAX: terminating task: /usr/sbin/conntrackd(conntrackd):7543, uid/euid: 0/0, PC: 0000000000000000, SP: 00007fffffffb398 11-14 14:25:20 +01:00; hafw2; kern.err; kernel: PAX: bytes at PC: ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
11-14 14:25:20 +01:00; hafw2; kern.err; kernel: PAX: bytes at SP-8:
--8<--

Here's the backtrace:
--8<--
hafw2 conntrackd-core # gdb /usr/sbin/conntrackd --core conntrackd.core --batch --quiet -ex "thread apply all bt full" -ex "quit" Using host libthread_db library "/lib/libthread_db.so.1".
Core was generated by `/usr/sbin/conntrackd -d -C /etc/conntrackd/conntrackd.conf'.
Program terminated with signal 9, Killed.
#0 0x0000000000000000 in ?? () from /lib64/ld-linux-x86-64.so.2

Thread 1 (process 7543):
#0 0x0000000000000000 in ?? () from /lib64/ld-linux-x86-64.so.2 No symbol table info available.
#1 0x00007ffff7ba28b5 in ?? ()
No symbol table info available.
#2 0x0000000000000001 in ?? () from /lib64/ld-linux-x86-64.so.2 No symbol table info available.
#3 0x00007ffff82197e0 in ?? ()
No symbol table info available.
#4 0x0000000000000000 in ?? () from /lib64/ld-linux-x86-64.so.2 No symbol table info available.
hafw2 conntrackd-core #
--8<--

I also ran "sysctl -w kernel.randomize_va_space=0" before restarting conntrackd after recompilation as suggested by the PaX team.

Any ideas?

Signature · 3 lines
Regards,
Wolfram Schlich <[email protected]>
Gentoo Linux * http://dev.gentoo.org/~wschlich/
#8 lore raw
Quoted 7 lines · Wolfram Schlich

Here's the log entry:
--8<--
11-14 14:25:20 +01:00; hafw2; kern.err; kernel: PAX: From 10.10.10.249: execution attempt in: <NULL>, 00000000-00000000 00000000
11-14 14:25:20 +01:00; hafw2; kern.err; kernel: PAX: terminating task: /usr/sbin/conntrackd(conntrackd):7543, uid/euid: 0/0, PC: 0000000000000000, SP: 00007fffffffb398 11-14 14:25:20 +01:00; hafw2; kern.err; kernel: PAX: bytes at PC: ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
11-14 14:25:20 +01:00; hafw2; kern.err; kernel: PAX: bytes at SP-8:
--8<--

ok, here's the rest of the story:

(gdb) x/16x $sp
0x7fffffffb398: 0xf7ba28b5 0x00007fff 0x00000001 0x00000000
(gdb) x/8i 0x00007ffff7ba28b5-3

0x7ffff7ba28b2 <__build_protoinfo+450>: callq  *(%rdx,%rax,8)
0x7ffff7ba28b5 <__build_protoinfo+453>: mov    $0x1,%eax
0x7ffff7ba28ba <__build_protoinfo+458>: mov    %ebp,%ecx
0x7ffff7ba28bc <__build_protoinfo+460>: shl    %cl,%rax
0x7ffff7ba28bf <__build_protoinfo+463>: or     %eax,(%r14,%rbx,4)
0x7ffff7ba28c3 <__build_protoinfo+467>: cmp    $0x37,%r12d
0x7ffff7ba28c7 <__build_protoinfo+471>: jle    0xfffffffff7ba287f
0x7ffff7ba28c9 <__build_protoinfo+473>: mov    0x10(%rsp),%rdx

(gdb) i r rdx rax
rdx 0x7ffff7db5000 140737351733248
rax 0x37 55
(gdb) x/8x $rdx+8*$rax

0x7ffff7db51b8: 0x00000000      0x00000000      0xf7ba9468      0x00007fff
0x7ffff7db51c8: 0xf7ba94b1      0x00007fff      0xf7ba9505      0x00007fff

so that's a null function pointer in whatever structure __build_protoinfo dereferences there. is it of any help to you or do you need me to dig out more?

#9 lore raw
Quoted 27 lines · [email protected] wrote:
Quoted 7 lines · Wolfram Schlich

Here's the log entry:
--8<--
11-14 14:25:20 +01:00; hafw2; kern.err; kernel: PAX: From 10.10.10.249: execution attempt in: <NULL>, 00000000-00000000 00000000
11-14 14:25:20 +01:00; hafw2; kern.err; kernel: PAX: terminating task: /usr/sbin/conntrackd(conntrackd):7543, uid/euid: 0/0, PC: 0000000000000000, SP: 00007fffffffb398 11-14 14:25:20 +01:00; hafw2; kern.err; kernel: PAX: bytes at PC: ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
11-14 14:25:20 +01:00; hafw2; kern.err; kernel: PAX: bytes at SP-8:
--8<--

ok, here's the rest of the story:

(gdb) x/16x $sp
0x7fffffffb398: 0xf7ba28b5 0x00007fff 0x00000001 0x00000000
(gdb) x/8i 0x00007ffff7ba28b5-3

0x7ffff7ba28b2 <__build_protoinfo+450>: callq  *(%rdx,%rax,8)
0x7ffff7ba28b5 <__build_protoinfo+453>: mov    $0x1,%eax
0x7ffff7ba28ba <__build_protoinfo+458>: mov    %ebp,%ecx
0x7ffff7ba28bc <__build_protoinfo+460>: shl    %cl,%rax
0x7ffff7ba28bf <__build_protoinfo+463>: or     %eax,(%r14,%rbx,4)
0x7ffff7ba28c3 <__build_protoinfo+467>: cmp    $0x37,%r12d
0x7ffff7ba28c7 <__build_protoinfo+471>: jle    0xfffffffff7ba287f
0x7ffff7ba28c9 <__build_protoinfo+473>: mov    0x10(%rsp),%rdx

(gdb) i r rdx rax
rdx 0x7ffff7db5000 140737351733248
rax 0x37 55
(gdb) x/8x $rdx+8*$rax

Quoted 5 lines
0x7ffff7db51b8: 0x00000000      0x00000000      0xf7ba9468      0x00007fff
0x7ffff7db51c8: 0xf7ba94b1      0x00007fff      0xf7ba9505      0x00007fff

so that's a null function pointer in whatever structure __build_protoinfo dereferences there. is it of any help to you or do you need me to dig out more?

Hm, that code belongs to libnetfilter_conntrack (src/conntrack/build.c). The annoying thing is that I see no structure with function pointers in that piece of bits. There are only calls to libnfnetlink functions to build the netlink message that is sent to kernel-space.

@Wolfram: that code is only reachable during a fail-over - ie. when the external cache commits the entries or if you have CacheWriteThrough enabled (you shouldn't unless you know what you're doing). I'm telling this because otherwise I don't see a way to reach that code - considering the posibility of having a memory corruption so that this backtrace becomes useless.

BTW, thank you for the detailed report.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
#10 lore raw
Quoted 11 lines · Pablo Neira Ayuso
Quoted 4 lines · [email protected] wrote:

[...]
so that's a null function pointer in whatever structure __build_protoinfo dereferences
there. is it of any help to you or do you need me to dig out more?

Hm, that code belongs to libnetfilter_conntrack (src/conntrack/build.c). The annoying thing is that I see no structure with function pointers in that piece of bits. There are only calls to libnfnetlink functions to build the netlink message that is sent to kernel-space.

Quoted 5 lines

@Wolfram: that code is only reachable during a fail-over - ie. when the external cache commits the entries or if you have CacheWriteThrough enabled (you shouldn't unless you know what you're doing). I'm telling this because otherwise I don't see a way to reach that code - considering the posibility of having a memory corruption so that this backtrace becomes useless.

Hmm. There was definitely no fail-over at that time and I didn't enable CacheWriteThrough either.
But I got a second coredump from the second firewall machine which I already sent to the PaX team -- maybe the analysis of that one shows different results. I guess we should wait for this one before thinking about possible causes.

@PaX team: did you already have time to look at the second coredump?

Signature · 3 lines
Regards,
Wolfram Schlich <[email protected]>
Gentoo Linux * http://dev.gentoo.org/~wschlich/
#11 lore raw
Quoted 1 line · Wolfram Schlich

@PaX team: did you already have time to look at the second coredump?

i've been very busy since, i'll take a look a bit later, sorry guys.

#12 lore raw
In reply to Pablo Neira Ayuso
Quoted 20 lines · Pablo Neira Ayuso
Quoted 20 lines

ok, here's the rest of the story:

(gdb) x/16x $sp
0x7fffffffb398: 0xf7ba28b5 0x00007fff 0x00000001 0x00000000
(gdb) x/8i 0x00007ffff7ba28b5-3

0x7ffff7ba28b2 <__build_protoinfo+450>: callq  *(%rdx,%rax,8)
0x7ffff7ba28b5 <__build_protoinfo+453>: mov    $0x1,%eax
0x7ffff7ba28ba <__build_protoinfo+458>: mov    %ebp,%ecx
0x7ffff7ba28bc <__build_protoinfo+460>: shl    %cl,%rax
0x7ffff7ba28bf <__build_protoinfo+463>: or     %eax,(%r14,%rbx,4)
0x7ffff7ba28c3 <__build_protoinfo+467>: cmp    $0x37,%r12d
0x7ffff7ba28c7 <__build_protoinfo+471>: jle    0xfffffffff7ba287f
0x7ffff7ba28c9 <__build_protoinfo+473>: mov    0x10(%rsp),%rdx

(gdb) i r rdx rax
rdx 0x7ffff7db5000 140737351733248
rax 0x37 55
(gdb) x/8x $rdx+8*$rax

0x7ffff7db51b8: 0x00000000      0x00000000      0xf7ba9468      0x00007fff
0x7ffff7db51c8: 0xf7ba94b1      0x00007fff      0xf7ba9505      0x00007fff
Quoted 7 lines
Quoted 2 lines

so that's a null function pointer in whatever structure __build_protoinfo dereferences there. is it of any help to you or do you need me to dig out more?

Hm, that code belongs to libnetfilter_conntrack (src/conntrack/build.c). The annoying thing is that I see no structure with function pointers in that piece of bits. There are only calls to libnfnetlink functions to build the netlink message that is sent to kernel-space.

sorry, gdb used the wrong symbols, i decoded it by hand now and the failing code is nfct_copy calling through copy_attr_array[] and it so happens that the array has no function defined for index ATTR_HELPER_NAME, the last entry in enum nf_conntrack_attr so i guess it was added without the person being aware of its uses elsewhere... maybe check your tree for similar issues and also add some big fat comment to the enum definition to remind yourselves to update other places when adding a new enum there ;)

#13 lore raw
Quoted 8 lines · * [email protected] <[email protected]> [2008-11-20 13:48]:

[...]
sorry, gdb used the wrong symbols, i decoded it by hand now and the failing code is nfct_copy calling through copy_attr_array[] and it so happens that the array has no function defined for index ATTR_HELPER_NAME, the last entry in enum nf_conntrack_attr so i guess it was added without the person being aware of its uses elsewhere... maybe check your tree for similar issues and also add some big fat comment to the enum definition to remind yourselves to update other places when adding a new enum there ;)

Pablo? :)

Signature · 3 lines
Regards,
Wolfram Schlich <[email protected]>
Gentoo Linux * http://dev.gentoo.org/~wschlich/
#14 lore raw
In reply to [email protected]
Quoted 29 lines · [email protected] wrote:
Quoted 20 lines · Pablo Neira Ayuso
Quoted 20 lines

ok, here's the rest of the story:

(gdb) x/16x $sp
0x7fffffffb398: 0xf7ba28b5 0x00007fff 0x00000001 0x00000000
(gdb) x/8i 0x00007ffff7ba28b5-3

0x7ffff7ba28b2 <__build_protoinfo+450>: callq  *(%rdx,%rax,8)
0x7ffff7ba28b5 <__build_protoinfo+453>: mov    $0x1,%eax
0x7ffff7ba28ba <__build_protoinfo+458>: mov    %ebp,%ecx
0x7ffff7ba28bc <__build_protoinfo+460>: shl    %cl,%rax
0x7ffff7ba28bf <__build_protoinfo+463>: or     %eax,(%r14,%rbx,4)
0x7ffff7ba28c3 <__build_protoinfo+467>: cmp    $0x37,%r12d
0x7ffff7ba28c7 <__build_protoinfo+471>: jle    0xfffffffff7ba287f
0x7ffff7ba28c9 <__build_protoinfo+473>: mov    0x10(%rsp),%rdx

(gdb) i r rdx rax
rdx 0x7ffff7db5000 140737351733248
rax 0x37 55
(gdb) x/8x $rdx+8*$rax

0x7ffff7db51b8: 0x00000000      0x00000000      0xf7ba9468      0x00007fff
0x7ffff7db51c8: 0xf7ba94b1      0x00007fff      0xf7ba9505      0x00007fff
Quoted 6 lines
Quoted 2 lines

so that's a null function pointer in whatever structure __build_protoinfo dereferences there. is it of any help to you or do you need me to dig out more?

Hm, that code belongs to libnetfilter_conntrack (src/conntrack/build.c). The annoying thing is that I see no structure with function pointers in that piece of bits. There are only calls to libnfnetlink functions to build the netlink message that is sent to kernel-space.

Quoted 7 lines

sorry, gdb used the wrong symbols, i decoded it by hand now and the failing code is nfct_copy calling through copy_attr_array[] and it so happens that the array has no function defined for index ATTR_HELPER_NAME, the last entry in enum nf_conntrack_attr so i guess it was added without the person being aware of its uses elsewhere... maybe check your tree for similar issues and also add some big fat comment to the enum definition to remind yourselves to update other places when adding a new enum there ;)

Thanks for the detailed report and your time. I'm going to push the following patches to git. One of them is a rudimentary test file for automated checking of unset function pointers, this should be better that the big-fat-comment elsewhere :)

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers

helper: fix missing copy function for helper name

From: Pablo Neira Ayuso <[email protected]>

This patch fixes a NULL dereference to a function pointer in nfct_copy() that is triggered when you try to copy the helper name. This patch also adds an assertion to easily report similar problems in the future.

Thanks to <[email protected]> for his detailed debugging report.

---

 src/conntrack/api.c  |    5 +++++
 src/conntrack/copy.c |    7 +++++++
 2 files changed, 12 insertions(+), 0 deletions(-)
src/conntrack/api.c +5 -0
index a5ddbc2..6dae83f 100644
@@ -892,6 +892,7 @@ void nfct_copy(struct nf_conntrack *ct1,
 	if (flags == NFCT_CP_ALL) {
 		for (i=0; i<ATTR_MAX; i++) {
 			if (test_bit(i, ct2->set)) {
+				assert(copy_attr_array[i]);
 				copy_attr_array[i](ct1, ct2);
 				set_bit(i, ct1->set);
 			}
@@ -917,6 +918,7 @@ void nfct_copy(struct nf_conntrack *ct1,
 	if (flags & NFCT_CP_ORIG) {
 		for (i=0; i<__CP_ORIG_MAX; i++) {
 			if (test_bit(cp_orig_mask[i], ct2->set)) {
+				assert(copy_attr_array[i]);
 				copy_attr_array[cp_orig_mask[i]](ct1, ct2);
 				set_bit(cp_orig_mask[i], ct1->set);
 			}
@@ -938,6 +940,7 @@ void nfct_copy(struct nf_conntrack *ct1,
 	if (flags & NFCT_CP_REPL) {
 		for (i=0; i<__CP_REPL_MAX; i++) {
 			if (test_bit(cp_repl_mask[i], ct2->set)) {
+				assert(copy_attr_array[i]);
 				copy_attr_array[cp_repl_mask[i]](ct1, ct2);
 				set_bit(cp_repl_mask[i], ct1->set);
 			}
@@ -947,6 +950,7 @@ void nfct_copy(struct nf_conntrack *ct1,
 	if (flags & NFCT_CP_META) {
 		for (i=ATTR_TCP_STATE; i<ATTR_MAX; i++) {
 			if (test_bit(i, ct2->set)) {
+				assert(copy_attr_array[i]),
 				copy_attr_array[i](ct1, ct2);
 				set_bit(i, ct1->set);
 			}
@@ -967,6 +971,7 @@ void nfct_copy_attr(struct nf_conntrack *ct1,
 		    const enum nf_conntrack_attr type)
 {
 	if (test_bit(type, ct2->set)) {
+		assert(copy_attr_array[type]);
 		copy_attr_array[type](ct1, ct2);
 		set_bit(type, ct1->set);
 	}
src/conntrack/copy.c +7 -0
index 45633f2..21511f9 100644
@@ -370,6 +370,12 @@ static void copy_attr_repl_off_aft(struct nf_conntrack *dest,
 		orig->tuple[__DIR_REPL].natseq.offset_after;
 }
 
+static void copy_attr_helper_name(struct nf_conntrack *dest,
+				  const struct nf_conntrack *orig)
+{
+	memcpy(dest->helper_name, orig->helper_name, 30);
+}
+
 copy_attr copy_attr_array[ATTR_MAX] = {
 	[ATTR_ORIG_IPV4_SRC]		= copy_attr_orig_ipv4_src,
 	[ATTR_ORIG_IPV4_DST] 		= copy_attr_orig_ipv4_dst,
@@ -426,4 +432,5 @@ copy_attr copy_attr_array[ATTR_MAX] = {
 	[ATTR_SCTP_STATE]		= copy_attr_sctp_state,
 	[ATTR_SCTP_VTAG_ORIG]		= copy_attr_sctp_vtag_orig,
 	[ATTR_SCTP_VTAG_REPL]		= copy_attr_sctp_vtag_repl,
+	[ATTR_HELPER_NAME]		= copy_attr_helper_name,
 };

src: set specific array size for the API

From: Pablo Neira Ayuso <[email protected]>

This patch adds the size of the arrays to set to NULL unset elements. This helps to spot unset functions for new attributes.

---

 src/conntrack/copy.c       |    2 +-
 src/conntrack/filter.c     |    2 +-
 src/conntrack/getter.c     |    2 +-
 src/conntrack/grp_getter.c |    2 +-
 src/conntrack/grp_setter.c |    2 +-
 src/conntrack/objopt.c     |    4 ++--
 src/conntrack/setter.c     |    2 +-
 7 files changed, 8 insertions(+), 8 deletions(-)
src/conntrack/copy.c +1 -1
index 92866fb..45633f2 100644
@@ -370,7 +370,7 @@ static void copy_attr_repl_off_aft(struct nf_conntrack *dest,
 		orig->tuple[__DIR_REPL].natseq.offset_after;
 }
 
-copy_attr copy_attr_array[] = {
+copy_attr copy_attr_array[ATTR_MAX] = {
 	[ATTR_ORIG_IPV4_SRC]		= copy_attr_orig_ipv4_src,
 	[ATTR_ORIG_IPV4_DST] 		= copy_attr_orig_ipv4_dst,
 	[ATTR_REPL_IPV4_SRC]		= copy_attr_repl_ipv4_src,
src/conntrack/filter.c +1 -1
index 952cbba..7966e54 100644
@@ -38,7 +38,7 @@ static void filter_attr_dst_ipv4(struct nfct_filter *filter, const void *value)
 	filter->l3proto_elems[1]++;
 }
 
-filter_attr filter_attr_array[] = {
+filter_attr filter_attr_array[NFCT_FILTER_MAX] = {
 	[NFCT_FILTER_L4PROTO]		= filter_attr_l4proto,
 	[NFCT_FILTER_L4PROTO_STATE]	= filter_attr_l4proto_state,
 	[NFCT_FILTER_SRC_IPV4]		= filter_attr_src_ipv4,
src/conntrack/getter.c +1 -1
index 658d010..65661d4 100644
@@ -287,7 +287,7 @@ static const void *get_attr_helper_name(const struct nf_conntrack *ct)
 	return ct->helper_name;
 }
 
-get_attr get_attr_array[] = {
+get_attr get_attr_array[ATTR_MAX] = {
 	[ATTR_ORIG_IPV4_SRC]		= get_attr_orig_ipv4_src,
 	[ATTR_ORIG_IPV4_DST] 		= get_attr_orig_ipv4_dst,
 	[ATTR_REPL_IPV4_SRC]		= get_attr_repl_ipv4_src,
src/conntrack/grp_getter.c +1 -1
index adfd903..60e0b7e 100644
@@ -92,7 +92,7 @@ static void get_attr_grp_repl_ctrs(const struct nf_conntrack *ct, void *data)
 	this->bytes = ct->counters[__DIR_REPL].bytes;
 }
 
-get_attr_grp get_attr_grp_array[] = {
+get_attr_grp get_attr_grp_array[ATTR_GRP_MAX] = {
 	[ATTR_GRP_ORIG_IPV4]		= get_attr_grp_orig_ipv4,
 	[ATTR_GRP_REPL_IPV4]		= get_attr_grp_repl_ipv4,
 	[ATTR_GRP_ORIG_IPV6]		= get_attr_grp_orig_ipv6,
src/conntrack/grp_setter.c +1 -1
index 16f0a10..99ae4f8 100644
@@ -140,7 +140,7 @@ static void set_attr_grp_do_nothing(struct nf_conntrack *ct, const void *value)
 {
 }
 
-set_attr_grp set_attr_grp_array[] = {
+set_attr_grp set_attr_grp_array[ATTR_GRP_MAX] = {
 	[ATTR_GRP_ORIG_IPV4]		= set_attr_grp_orig_ipv4,
 	[ATTR_GRP_REPL_IPV4]		= set_attr_grp_repl_ipv4,
 	[ATTR_GRP_ORIG_IPV6]		= set_attr_grp_orig_ipv6,
src/conntrack/objopt.c +2 -2
index 682cba1..d678f2d 100644
@@ -72,7 +72,7 @@ static void setobjopt_setup_repl(struct nf_conntrack *ct)
 	__autocomplete(ct, __DIR_REPL);
 }
 
-setobjopt setobjopt_array[] = {
+setobjopt setobjopt_array[__NFCT_SOPT_MAX] = {
 	[NFCT_SOPT_UNDO_SNAT] 		= setobjopt_undo_snat,
 	[NFCT_SOPT_UNDO_DNAT] 		= setobjopt_undo_dnat,
 	[NFCT_SOPT_UNDO_SPAT] 		= setobjopt_undo_spat,
@@ -122,7 +122,7 @@ static int getobjopt_is_dpat(const struct nf_conntrack *ct)
 		ct->tuple[__DIR_ORIG].l4dst.tcp.port);
 }
 
-getobjopt getobjopt_array[] = {
+getobjopt getobjopt_array[__NFCT_GOPT_MAX] = {
 	[NFCT_GOPT_IS_SNAT] = getobjopt_is_snat,
 	[NFCT_GOPT_IS_DNAT] = getobjopt_is_dnat,
 	[NFCT_GOPT_IS_SPAT] = getobjopt_is_spat,
src/conntrack/setter.c +1 -1
index 3291bd1..6e275ab 100644
@@ -316,7 +316,7 @@ static void set_attr_helper_name(struct nf_conntrack *ct, const void *value)
 
 static void set_attr_do_nothing(struct nf_conntrack *ct, const void *value) {}
 
-set_attr set_attr_array[] = {
+set_attr set_attr_array[ATTR_MAX] = {
 	[ATTR_ORIG_IPV4_SRC]	= set_attr_orig_ipv4_src,
 	[ATTR_ORIG_IPV4_DST] 	= set_attr_orig_ipv4_dst,
 	[ATTR_REPL_IPV4_SRC]	= set_attr_repl_ipv4_src,

qa: add test file to check for missing indirect function calls

From: Pablo Neira Ayuso <[email protected]>

This patch adds a rudimentary test file to check for possible unset indirect function calls. This automated test should be run after adding a new attribute.

---

 Makefile.am    |    2 +
 configure.in   |    2 +
 qa/Makefile.am |    7 ++++
 qa/test_api.c  |  102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 111 insertions(+), 2 deletions(-)
 create mode 100644 qa/Makefile.am
 create mode 100644 qa/test_api.c
Makefile.am +1 -1
index 262028c..f31ebb4 100644
@@ -2,7 +2,7 @@ include $(top_srcdir)/Make_global.am
 
 AUTOMAKE_OPTIONS = foreign dist-bzip2 1.6
 
-SUBDIRS	= include src utils
+SUBDIRS	= include src utils qa
 
 man_MANS = #nfnetlink_conntrack.3 nfnetlink_conntrack.7
 
configure.in +1 -1
index 6768235..0aa9c40 100644
@@ -78,5 +78,5 @@ LIBNFCONNTRACK_LIBS="$LIBNFNETLINK_LIBS"
 AC_SUBST(LIBNFCONNTRACK_LIBS)
 
 dnl Output the makefile
-AC_OUTPUT(Makefile src/Makefile include/Makefile utils/Makefile include/libnetfilter_conntrack/Makefile include/internal/Makefile src/conntrack/Makefile src/expect/Makefile src/deprecated/Makefile src/deprecated/l3extensions/Makefile src/deprecated/extensions/Makefile libnetfilter_conntrack.pc)
+AC_OUTPUT(Makefile src/Makefile include/Makefile utils/Makefile qa/Makefile include/libnetfilter_conntrack/Makefile include/internal/Makefile src/conntrack/Makefile src/expect/Makefile src/deprecated/Makefile src/deprecated/l3extensions/Makefile src/deprecated/extensions/Makefile libnetfilter_conntrack.pc)
 
qa/Makefile.am new file +7 -0
new file mode 100644
index 0000000..6a9471b
@@ -0,0 +1,7 @@
+include $(top_srcdir)/Make_global.am
+
+check_PROGRAMS = test_api
+
+test_api_SOURCES = test_api.c
+test_api_LDADD = ../src/libnetfilter_conntrack.la
+test_api_LDFLAGS = -dynamic -ldl
qa/test_api.c new file +102 -0

102 lines not on this page · raw message

#15 lore raw
Quoted 5 lines · Pablo Neira Ayuso

[...]
Thanks for the detailed report and your time. I'm going to push the following patches to git. One of them is a rudimentary test file for automated checking of unset function pointers, this should be better that the big-fat-comment elsewhere :)

Thanks, Pablo! :)
I'll add the patches to our Gentoo ebuild for 0.9.8. When do you plan to release a new version?

Signature · 3 lines
Regards,
Wolfram Schlich <[email protected]>
Gentoo Linux * http://dev.gentoo.org/~wschlich/
#16 lore raw
Quoted 10 lines · Wolfram Schlich
Quoted 5 lines · Pablo Neira Ayuso

[...]
Thanks for the detailed report and your time. I'm going to push the following patches to git. One of them is a rudimentary test file for automated checking of unset function pointers, this should be better that the big-fat-comment elsewhere :)

Thanks, Pablo! :)
I'll add the patches to our Gentoo ebuild for 0.9.8. When do you plan to release a new version?

I'll release one libnetfilter_conntrack including these fixes soon, probably along this week.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
#17 lore raw
In reply to Pablo Neira Ayuso
Quoted 4 lines · Pablo Neira Ayuso

Thanks for the detailed report and your time. I'm going to push the following patches to git. One of them is a rudimentary test file for automated checking of unset function pointers, this should be better that the big-fat-comment elsewhere :)

just one comment on this: the memcpy in copy_attr_helper_name should probably use a symbolic constant or sizeof instead of a hardcoded value.

#18 lore raw
Quoted 9 lines · [email protected] wrote:
Quoted 4 lines · Pablo Neira Ayuso

Thanks for the detailed report and your time. I'm going to push the following patches to git. One of them is a rudimentary test file for automated checking of unset function pointers, this should be better that the big-fat-comment elsewhere :)

just one comment on this: the memcpy in copy_attr_helper_name should probably use a symbolic constant or sizeof instead of a hardcoded value.

I actually did after I sent the patch that I pushed to git yesterday :)

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
#19 lore raw
In reply to Wolfram Schlich
Quoted 1 line · Wolfram Schlich

Now I got a core, after more than a day, but it doesn't look good :(

Here's the reply of the PaX team (I sent in the conntrackd binary along with the coredump):

Quoted 17 lines · * [email protected] <[email protected]> [2008-11-14 16:48]:

ok, here's the rest of the story:

(gdb) x/16x $sp
0x7fffffffb398: 0xf7ba28b5 0x00007fff 0x00000001 0x00000000
(gdb) x/8i 0x00007ffff7ba28b5-3

0x7ffff7ba28b2 <__build_protoinfo+450>: callq  *(%rdx,%rax,8)
0x7ffff7ba28b5 <__build_protoinfo+453>: mov    $0x1,%eax
0x7ffff7ba28ba <__build_protoinfo+458>: mov    %ebp,%ecx
0x7ffff7ba28bc <__build_protoinfo+460>: shl    %cl,%rax
0x7ffff7ba28bf <__build_protoinfo+463>: or     %eax,(%r14,%rbx,4)
0x7ffff7ba28c3 <__build_protoinfo+467>: cmp    $0x37,%r12d
0x7ffff7ba28c7 <__build_protoinfo+471>: jle    0xfffffffff7ba287f
0x7ffff7ba28c9 <__build_protoinfo+473>: mov    0x10(%rsp),%rdx

(gdb) i r rdx rax
rdx 0x7ffff7db5000 140737351733248
rax 0x37 55
(gdb) x/8x $rdx+8*$rax

Quoted 5 lines
0x7ffff7db51b8: 0x00000000      0x00000000      0xf7ba9468      0x00007fff
0x7ffff7db51c8: 0xf7ba94b1      0x00007fff      0xf7ba9505      0x00007fff

so that's a null function pointer in whatever structure __build_protoinfo dereferences there. is it of any help to you or do you need me to dig out more?

Pablo, is this sufficient information for you?

Signature · 3 lines
Regards,
Wolfram Schlich <[email protected]>
Gentoo Linux * http://dev.gentoo.org/~wschlich/
#20 lore raw
Quoted 5 lines · Wolfram Schlich
Quoted 1 line · Wolfram Schlich

Now I got a core, after more than a day, but it doesn't look good :(

Here's the reply of the PaX team (I sent in the conntrackd binary along with the coredump):

Whoops!
Didn't notice the PaX team sent their reply to this list as well ;)

Signature · 3 lines
Regards,
Wolfram Schlich <[email protected]>
Gentoo Linux * http://dev.gentoo.org/~wschlich/