Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 136813 - iptables binary corrupt with USE=static
Summary: iptables binary corrupt with USE=static
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: PPC Linux
: High major (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-14 12:40 UTC by Timothy Stotts
Modified: 2007-06-26 14:36 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge info (iptables_emerge_info.txt,4.09 KB, text/plain)
2006-06-14 12:41 UTC, Timothy Stotts
Details
Output of 'strace -f -o out iptables' (strace.out.txt,730 bytes, text/plain)
2006-06-17 17:25 UTC, Timothy Stotts
Details
Output of 'strace -f -o out iptables' (USE=-static) (strace_dynamic.txt,3.12 KB, text/plain)
2006-06-17 21:58 UTC, Timothy Stotts
Details
small test program that produces same symptom (weird_getsockopt.c,1.03 KB, text/plain)
2006-07-19 22:48 UTC, Wormo (RETIRED)
Details
register dump from iptables failure (BAD.reg,3.66 KB, text/plain)
2006-07-19 22:51 UTC, Wormo (RETIRED)
Details
register dump from iptables success (GOOD.reg,3.67 KB, text/plain)
2006-07-19 22:53 UTC, Wormo (RETIRED)
Details
Not checking the return values is not good... okay? :p (ip_tables.patch,340 bytes, patch)
2007-04-28 06:24 UTC, Joe Jezak (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Timothy Stotts 2006-06-14 12:40:34 UTC
Expected:
   # USE='static ipv6 -extensions' emerge =iptables-1.3.5-r1
to provide functional binary.

Actual:
   # USE='static ipv6 -extensions' emerge =iptables-1.3.5-r1
produces misbehaving binary.

Reproducible: always, on PPC.  Cannot reproduce on x86.

Work-around:
   # USE='-static' emerge =iptables-1.3.5-r1

Details:
   # iptables
   getsockopt failed strangely: No such file or directory

   Issue is unresolved on NetFilter list at:
   http://lists.netfilter.org/pipermail/netfilter/2006-May/065675.html
Comment 1 Timothy Stotts 2006-06-14 12:41:04 UTC
Created attachment 89199 [details]
emerge info
Comment 2 SpanKY gentoo-dev 2006-06-17 14:56:53 UTC
works fine for me on my ppc

run `strace -f -o out iptables` and post the 'out' file as an attachment
Comment 3 Timothy Stotts 2006-06-17 17:25:42 UTC
Created attachment 89426 [details]
Output of 'strace -f -o out iptables'
Comment 4 SpanKY gentoo-dev 2006-06-17 18:09:28 UTC
that should of course be reading:

getsockopt(3, SOL_IP, 0x42 /* IP_??? */, 0xffdb7b8c, 0xffdb7b88) = -1 ENOPROTOOPT (Protocol not available)

instead of ENOENT
Comment 5 SpanKY gentoo-dev 2006-06-17 21:04:08 UTC
also post a log of strace when run on iptables with USE=-static

getsockopt() is just a system call ... there isnt any logic in glibc ...
Comment 6 Timothy Stotts 2006-06-17 21:58:20 UTC
Created attachment 89443 [details]
Output of 'strace -f -o out iptables' (USE=-static)
Comment 7 Wormo (RETIRED) gentoo-dev 2006-07-19 22:44:51 UTC
This looks like an interesting kernel bug

Quick overview after spending some quality time with gdb
(some attachments will follow)

* the weird return value occurs only if "ip_tables" module is loaded; 
  it goes away whenever you unload the module
* I reproduced the problem with a small test program, and it occurs
  regardless of whether it is statically linked or not
* the arguments going into the getsockopt system call are IDENTICAL
  when the sympton occurs and when it doesn't, and the socket descriptor
  passed is valid in both cases
* the weird return value is present in the registers immediately after
  the syscall returns, before userspace code has any chance to corrupt errno

The reason why this problem is only occuring in the static iptables is that the problematic code happens inside some init functions only used by static iptables.

Kernel team: any suggestions on what to look at next?
 
Comment 8 Wormo (RETIRED) gentoo-dev 2006-07-19 22:48:33 UTC
Created attachment 92262 [details]
small test program that produces same symptom
Comment 9 Wormo (RETIRED) gentoo-dev 2006-07-19 22:51:30 UTC
Created attachment 92263 [details]
register dump from iptables failure
Comment 10 Wormo (RETIRED) gentoo-dev 2006-07-19 22:53:14 UTC
Created attachment 92264 [details]
register dump from iptables success
Comment 11 SpanKY gentoo-dev 2006-07-19 23:13:12 UTC
perhaps related ...

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=367656
Comment 12 Wormo (RETIRED) gentoo-dev 2006-07-20 14:13:33 UTC
I don't think so; the amd64 one is a glibc bug. I think a glibc bug has been ruled out in this case because gdb showed the syscall coming back with different results despite identical arguments coming in -- the presence or absence of ip_tables module in the kernel determined the result code, not whether the program was statically or dynamically compiled.
Comment 13 Joe Jezak (RETIRED) gentoo-dev 2006-10-04 15:27:28 UTC
Wormo:
Well, when ip_tables loads, it overrides getsockopt with nf_getsockopt, so I guess the bug is in nf_sockopt.c in the kernel.  I'll look into it a little more.
Comment 14 Joe Jezak (RETIRED) gentoo-dev 2007-04-28 06:21:39 UTC
Okay, I figured this one out. :p  It's a pretty annoying bug, but I'm not sure why this only comes up with USE="static".  Okay, so we know that ip_tables loads sockopts to support its features, so lets take a look at that code: /usr/src/linux/net/ipv4/netfilter/iptables.c

The get method that's causing this problem is assigned in ipt_sockopts, specifically the function do_ipt_get_ctl.  In do_ipt_get_ctl, the specific command we have a problem with is IPT_SO_GET_REVISION_[MATCH|TARGET].  Now, here's where the problem is.  try_then_request_module tries to call the symbol: xt_find_revision to satisfy this request.  Unfortunately, the symbol isn't available, so it tries to request it.  If you haven't compiled the module it's requesting, you'll get -2 (-ENOENT) back, and hence this is the value that's returned that confuses iptables.

A patch to add a check for -ENOENT and printing out the missing module name then return -EPROTONOSUPPORT instead of -ENOENT will be attached and fixes the bug for me.  
Comment 15 Joe Jezak (RETIRED) gentoo-dev 2007-04-28 06:24:04 UTC
Created attachment 117470 [details, diff]
Not checking the return values is not good... okay? :p

Please test this and tell me if it fixes the problem for you.
Comment 16 SpanKY gentoo-dev 2007-04-30 18:58:57 UTC
perhaps it should even go so far as:
if (ret == -ENOENT) {
    ....
} else if (ret < 0) {
    <complain about unhandled error value here>
}
Comment 17 Joe Jezak (RETIRED) gentoo-dev 2007-05-16 19:13:41 UTC
Yeah, that's probably a good idea.  I still haven't gotten a response from upstream about it.
Comment 18 Joe Jezak (RETIRED) gentoo-dev 2007-06-26 14:36:48 UTC
Fixed upstream: http://svn.netfilter.org/cgi-bin/viewcvs.cgi?rev=6890&view=rev