Skip to content

Crash in iptables OUTPUT chain #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
genesisgardian opened this issue Dec 21, 2016 · 6 comments
Closed

Crash in iptables OUTPUT chain #25

genesisgardian opened this issue Dec 21, 2016 · 6 comments

Comments

@genesisgardian
Copy link

Hi,
I'm writing a simple code to capture the packet, and print the packet, just as the example code which you give to us. It works fine as the INPUT chain of iptables, but when I change to capture the output packet with OUTPUT chain of iptables, it crash and show the 'segmentation fault'.

I'm working on Ubuntu 16.04

@dany-fu
Copy link

dany-fu commented Jan 26, 2017

I ran into a similar issue with version 0.8 and 0.6 on Ubuntu 14.04; PREROUTE works fine, POSTROUTE crashes. Seems ok so far on 0.7

@Tey
Copy link

Tey commented Jan 27, 2017

Problem is at line 65 of netfilterqueue.pyx:

        self.hw_addr = self._hw.hw_addr

When sending packets, self._hw is NULL so the copy crashes. I have no idea how to fix that in the PYX file (what should be the value of self.hw_addr when self._hw is NULL?), but as a workaround, you can just comment the following lines in netfilterqueue.c and compile/install the module again:

  __pyx_t_2 = __pyx_v_self->_hw->hw_addr;
  memcpy(&(__pyx_v_self->hw_addr[0]), __pyx_t_2, sizeof(__pyx_v_self->hw_addr[0]) * (8 - 0));

@ojalexander
Copy link

I ran into the same issue using OUTPUT. Thanks for the workaround.

@mattfox
Copy link
Collaborator

mattfox commented Jan 27, 2017

Thanks for the details. I'll see if I can duplicate and fix within a few days.

@mattfox
Copy link
Collaborator

mattfox commented Jan 31, 2017

The fix leaves calling and parsing of nfq_get_packet_hw data until the get_hw() call, and just returns None if nfq_get_packet_hw returns NULL. I believe hw_addr was private on Packet, so this should be compatible with 0.8.

I've uploaded 0.8.1 to Pypi but reviews and improvements are welcome. Thanks for reporting this, all.

@Tey
Copy link

Tey commented Feb 6, 2017

Thanks @mattfox I experience no more crash with 0.8.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants