Reapply "netfilter: ipset: Fix race between IPSET_CMD_CREATE and IPSET_CMD_SWAP"
This reverts commit 6c2e2d34f46dcedf0bdd62adc5ae1c19a9d07d81.
BUG=b/303207275
TEST=presubmit
RELEASE_NOTE=None
cos-patch: bug
Change-Id: I2c92eb3f8c7773471207aff2d51815ba55914776
Reviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/59058
Tested-by: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com>
Reviewed-by: Oleksandr Tymoshenko <ovt@google.com>
Reviewed-by: Chenglong Tang <chenglongtang@google.com>
diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
index c911fc0..33869db 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -683,6 +683,14 @@
* a separate reference counter
*/
static void
+__ip_set_get_netlink(struct ip_set *set)
+{
+ write_lock_bh(&ip_set_ref_lock);
+ set->ref_netlink++;
+ write_unlock_bh(&ip_set_ref_lock);
+}
+
+static void
__ip_set_put_netlink(struct ip_set *set)
{
write_lock_bh(&ip_set_ref_lock);
@@ -1695,11 +1703,11 @@
do {
if (retried) {
- __ip_set_get(set);
+ __ip_set_get_netlink(set);
nfnl_unlock(NFNL_SUBSYS_IPSET);
cond_resched();
nfnl_lock(NFNL_SUBSYS_IPSET);
- __ip_set_put(set);
+ __ip_set_put_netlink(set);
}
ip_set_lock(set);