Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: ipt_MASQUERADE: remove redundant rwlock

The lock "protects" an assignment and a comparision of an integer.
When the caller of device_cmp() evaluates the result, nat->masq_index
may already have been changed (regardless if the lock is there or not).

So, the lock either has to be held during nf_ct_iterate_cleanup(),
or can be removed.

This does the latter.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Patrick McHardy <kaber@trash.net>

authored by

Florian Westphal and committed by
Patrick McHardy
17f2f52b 10662aa3

+1 -11
+1 -11
net/ipv4/netfilter/ipt_MASQUERADE.c
··· 27 27 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); 28 28 MODULE_DESCRIPTION("Xtables: automatic-address SNAT"); 29 29 30 - /* Lock protects masq region inside conntrack */ 31 - static DEFINE_RWLOCK(masq_lock); 32 - 33 30 /* FIXME: Multiple targets. --RR */ 34 31 static bool masquerade_tg_check(const struct xt_tgchk_param *par) 35 32 { ··· 76 79 return NF_DROP; 77 80 } 78 81 79 - write_lock_bh(&masq_lock); 80 82 nat->masq_index = par->out->ifindex; 81 - write_unlock_bh(&masq_lock); 82 83 83 84 /* Transfer from original range. */ 84 85 newrange = ((struct nf_nat_range) ··· 92 97 device_cmp(struct nf_conn *i, void *ifindex) 93 98 { 94 99 const struct nf_conn_nat *nat = nfct_nat(i); 95 - int ret; 96 100 97 101 if (!nat) 98 102 return 0; 99 103 100 - read_lock_bh(&masq_lock); 101 - ret = (nat->masq_index == (int)(long)ifindex); 102 - read_unlock_bh(&masq_lock); 103 - 104 - return ret; 104 + return nat->masq_index == (int)(long)ifindex; 105 105 } 106 106 107 107 static int masq_device_event(struct notifier_block *this,