From: Florian Westphal <fw@strlen.de>
To: Richard Guy Briggs <rgb@redhat.com>
Cc: fwestpha@redhat.com, netfilter-devel@vger.kernel.org,
pmoore@redhat.com, pvrabec@redhat.com, willemb@google.com
Subject: Re: .config for iptables icmp rule delete failure
Date: Mon, 8 May 2017 22:22:36 +0200 [thread overview]
Message-ID: <20170508202236.GC9660@breakpoint.cc> (raw)
In-Reply-To: <20170507204306.GW25861@madcap2.tricolour.ca>
Richard Guy Briggs <rgb@redhat.com> wrote:
[ CC'ing Willem ]
> (Summary of IRC conversation for background...)
> Paul Moore and I hit what appears to be a bug since f25's 4.10.11 and
> upstream's 4.11-rc3 that would fail to locate on deletion an icmp rule
> in iptables. Paul narrowed it down to the icmp option.
> Here's our issue where it came up:
> https://github.com/linux-audit/audit-testsuite/pull/43#issuecomment-296831880
>
> The test case is:
> # iptables -t mangle -I INPUT -i lo -p icmp --icmp-type 1 -j MARK --set-mark 0xdeadbeef
> # iptables -t mangle -D INPUT -i lo -p icmp --icmp-type 1 -j MARK --set-mark 0xdeadbeef
> The error we're getting is "iptables: No chain/target/match by that name."
This is a iptables (yes, userspace) bug exposed with
f77bc5b23fb1af51fc0faa8a479dea8969eb5079
(iptables: use match, target and data copy_to_user helpers)
icmp is 4 byte in size, but for some silly(?) reason userspace size
in iptables userland is set as XT_ALIGN(sizeof(ipt_icmp), so userspace
thinks its 8.
In 4.10, kernel copied the full kernel blob to userspace, and since
its allocated with kz/vzalloc the 4 padding bytes are 0.
libiptc uses malloc, so in case that contains garbage bytes the
memcmp() used to figure out if we found the correct rule in libiptc
during -D mode returns false because it chokes on the extra padding
after struct ipt_icmp match :-/
Simples fix is to use calloc/memset to 0 in libiptc, but we can't
go with userspace-only fix ...
So we have to fix this in the kernel and have xt_data_to_user()
zero out any padding as well.
Willem, if you don't have time to fix this let me know and i'll
try to work on this tomorrow.
For testing, this iptables patch makes things barf reliably regardless what
malloc/libc is doing:
diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c
index 2c66d04..9497a5e 100644
--- a/libiptc/libiptc.c
+++ b/libiptc/libiptc.c
@@ -1286,6 +1286,7 @@ alloc_handle(const char *tablename, unsigned int size, unsigned int num_rules)
if (!h->entries)
goto out_free_handle;
+ memset(h->entries, 0x42, sizeof(STRUCT_GET_ENTRIES) + size);
strcpy(h->entries->name, tablename);
h->entries->size = size;
iptables -A INPUT -p icmp --icmp-type 1 &&
iptables -D INPUT -p icmp --icmp-type 1
Works on 4.10, but not >= 4.11 (assumes x86_64 kernel+userland).
next prev parent reply other threads:[~2017-05-08 20:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-07 20:43 .config for iptables icmp rule delete failure Richard Guy Briggs
2017-05-08 20:22 ` Florian Westphal [this message]
2017-05-09 2:22 ` Willem de Bruijn
2017-05-09 2:32 ` Florian Westphal
2017-05-09 4:18 ` Willem de Bruijn
2017-05-09 4:47 ` Willem de Bruijn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170508202236.GC9660@breakpoint.cc \
--to=fw@strlen.de \
--cc=fwestpha@redhat.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pmoore@redhat.com \
--cc=pvrabec@redhat.com \
--cc=rgb@redhat.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.