<html>
<head>
<base href="https://bugzilla.netfilter.org/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - iptables-restore crashes on some fuzzed input"
href="https://bugzilla.netfilter.org/show_bug.cgi?id=1131">1131</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>iptables-restore crashes on some fuzzed input
</td>
</tr>
<tr>
<th>Product</th>
<td>iptables
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P5
</td>
</tr>
<tr>
<th>Component</th>
<td>iptables-restore
</td>
</tr>
<tr>
<th>Assignee</th>
<td>netfilter-buglog@lists.netfilter.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>oleg.strikov@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>This issue doesn't have any security implication. I file this bug only because
crashing on any input (even carefully crafted) is considered undesirable
nowadays.
<span class="quote">> iptables/iptables-restore.c:438
> ret = do_command4(newargc, newargv,
> &newargv[2], &handle, true);</span >
<...>
<span class="quote">> free_argv();</span >
By passing &newargv[2] to do_command4() we assume that this pointer won't be
overwritten by the function. Otherwise, following call to free_argv() may crash
if the overwritten pointer is either malformed or have duplicates in the
newargv array. This pointer gets overwritten only when -t/--table option gets
passed to do_command4() and we specifically check for this corner case:
<span class="quote">> iptables/iptables-restore.c:157
> if (!strncmp(param_buffer, "-t", 2)
> || !strncmp(param_buffer, "--table", 8)) {
> xtables_error(PARAMETER_PROBLEM,
> "The -t option (seen in line %u) cannot be "
> "used in iptables-restore.\n", line);
> exit(1);
> }</span >
Unfortunately, do_command4() uses getopt_long() to parse its arguments. This
function is quite smart and provides some ways to bypass the check above but
still pass -t/--table to the function:
(1) --t,--ta,--tab,--tabl are treated as --table (try ls --he)
(2) -ftf is treated as -f --table f
In both cases argv[2] gets overwritten by malformed or duplicate pointer which
leads to a crash inside free_argv():
$ cat << EOF > crash1
*filter
-A INPUT --t 1194 -j ACCEPT
-A OUTPUT
COMMIT
EOF
$ ./xtables-multi iptables-restore -t < crash1
Segmentation fault (core dumped)
$ cat << EOF > crash2
*filter
-A INPUT -ftf -j ACCEPT
COMMIT
EOF
$ ./xtables-multi iptables-restore -t < crash2
*** Error in `./xtables-multi': free(): invalid pointer: 0x00000000006ab673 ***
Aborted (core dumped)
Issue has been discovered with AFL (<a href="http://lcamtuf.coredump.cx/afl/">http://lcamtuf.coredump.cx/afl/</a>).</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are watching all bug changes.</li>
</ul>
</body>
</html>