Re: iptables patch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Tue, Mar 28, 2023 at 07:28:50AM +0000, Kevin Peeters wrote:
> I am using the 'iptables' source code in one of my software projects. More in detail, I am calling libiptc and libxtables from my own software API to add/delete/... iptables firewall rules.
> 
> While developing, I bumped into one issue while using libxtables and made a patch for it which we now use on our checkout of the 'iptables' repository. We do however use multiple checkouts of this repository in different places and don't want to add the patch to each of those checkouts.
> Would it be possible for you to add this patch to the mainline of your repository so we can stop patching it locally?
> 
> The details about the patch:
> In libxtables/xtables.c:
> 
> The libxtables code uses a xtables_pending_matches, xtables_pending_targets, xtables_matches and xtables_targets pointer list to track all (pending) matches and targets registered to the current iptables command. In my code, I add/delete firewall rules multiple times from one main process (without killing the main process in between) by calling xtables_init_all, xtables_register_target and xtables_register_match every time. When a rule is added, I call xtables_fini to clean up.

I don't think you should call xtables_register_{target,match} over and
over again. Why don't you follow what iptables does and call
xtables_find_{target,match} to lookup an extension? It tries loading the
DSO which calls xtables_register_*. After adding the rule, you should
free the rule, not deinit the library.

> I do notice when adding a rule in my code twice that on the second time, the (pending) targets/matches lists are not empty and when I try to register the same target (the one I registered in the previous rule) again, it links to itself and creates an infinite loop.
> 
> I managed to fix it by setting the pointers to NULL in xtables_fini.

Your patch seems to leak memory because the list elements are not freed.

Cheers, Phil



[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux