From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev, Jozsef Kadlecsik <kadlec@netfilter.org>,
Pablo Neira Ayuso <pablo@netfilter.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10 03/97] netfilter: ipset: fix race condition between swap/destroy and kernel side add/del/test
Date: Mon, 11 Dec 2023 19:21:06 +0100 [thread overview]
Message-ID: <20231211182019.957772144@linuxfoundation.org> (raw)
In-Reply-To: <20231211182019.802717483@linuxfoundation.org>
5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jozsef Kadlecsik <kadlec@netfilter.org>
[ Upstream commit 28628fa952fefc7f2072ce6e8016968cc452b1ba ]
Linkui Xiao reported that there's a race condition when ipset swap and destroy is
called, which can lead to crash in add/del/test element operations. Swap then
destroy are usual operations to replace a set with another one in a production
system. The issue can in some cases be reproduced with the script:
ipset create hash_ip1 hash:net family inet hashsize 1024 maxelem 1048576
ipset add hash_ip1 172.20.0.0/16
ipset add hash_ip1 192.168.0.0/16
iptables -A INPUT -m set --match-set hash_ip1 src -j ACCEPT
while [ 1 ]
do
# ... Ongoing traffic...
ipset create hash_ip2 hash:net family inet hashsize 1024 maxelem 1048576
ipset add hash_ip2 172.20.0.0/16
ipset swap hash_ip1 hash_ip2
ipset destroy hash_ip2
sleep 0.05
done
In the race case the possible order of the operations are
CPU0 CPU1
ip_set_test
ipset swap hash_ip1 hash_ip2
ipset destroy hash_ip2
hash_net_kadt
Swap replaces hash_ip1 with hash_ip2 and then destroy removes hash_ip2 which
is the original hash_ip1. ip_set_test was called on hash_ip1 and because destroy
removed it, hash_net_kadt crashes.
The fix is to force ip_set_swap() to wait for all readers to finish accessing the
old set pointers by calling synchronize_rcu().
The first version of the patch was written by Linkui Xiao <xiaolinkui@kylinos.cn>.
v2: synchronize_rcu() is moved into ip_set_swap() in order not to burden
ip_set_destroy() unnecessarily when all sets are destroyed.
v3: Florian Westphal pointed out that all netfilter hooks run with rcu_read_lock() held
and em_ipset.c wraps the entire ip_set_test() in rcu read lock/unlock pair.
So there's no need to extend the rcu read locked area in ipset itself.
Closes: https://lore.kernel.org/all/69e7963b-e7f8-3ad0-210-7b86eebf7f78@netfilter.org/
Reported by: Linkui Xiao <xiaolinkui@kylinos.cn>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
net/netfilter/ipset/ip_set_core.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
index 26613e3731d02..24f81826ed4a5 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -61,6 +61,8 @@ MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_IPSET);
ip_set_dereference((inst)->ip_set_list)[id]
#define ip_set_ref_netlink(inst,id) \
rcu_dereference_raw((inst)->ip_set_list)[id]
+#define ip_set_dereference_nfnl(p) \
+ rcu_dereference_check(p, lockdep_nfnl_is_held(NFNL_SUBSYS_IPSET))
/* The set types are implemented in modules and registered set types
* can be found in ip_set_type_list. Adding/deleting types is
@@ -708,15 +710,10 @@ __ip_set_put_netlink(struct ip_set *set)
static struct ip_set *
ip_set_rcu_get(struct net *net, ip_set_id_t index)
{
- struct ip_set *set;
struct ip_set_net *inst = ip_set_pernet(net);
- rcu_read_lock();
- /* ip_set_list itself needs to be protected */
- set = rcu_dereference(inst->ip_set_list)[index];
- rcu_read_unlock();
-
- return set;
+ /* ip_set_list and the set pointer need to be protected */
+ return ip_set_dereference_nfnl(inst->ip_set_list)[index];
}
static inline void
@@ -1407,6 +1404,9 @@ static int ip_set_swap(struct net *net, struct sock *ctnl, struct sk_buff *skb,
ip_set(inst, to_id) = from;
write_unlock_bh(&ip_set_ref_lock);
+ /* Make sure all readers of the old set pointers are completed. */
+ synchronize_rcu();
+
return 0;
}
--
2.42.0
next prev parent reply other threads:[~2023-12-11 18:37 UTC|newest]
Thread overview: 108+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-11 18:21 [PATCH 5.10 00/97] 5.10.204-rc1 review Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 01/97] hrtimers: Push pending hrtimers away from outgoing CPU earlier Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 02/97] i2c: designware: Fix corrupted memory seen in the ISR Greg Kroah-Hartman
2023-12-11 18:21 ` Greg Kroah-Hartman [this message]
2023-12-11 18:21 ` [PATCH 5.10 04/97] tg3: Move the [rt]x_dropped counters to tg3_napi Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 05/97] tg3: Increment tx_dropped in tg3_tso_bug() Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 06/97] kconfig: fix memory leak from range properties Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 07/97] drm/amdgpu: correct chunk_ptr to a pointer to chunk Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 08/97] platform/x86: asus-wmi: Add support for SW_TABLET_MODE on UX360 Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 09/97] platform/x86: asus-nb-wmi: Allow configuring SW_TABLET_MODE method with a module option Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 10/97] platform/x86: asus-nb-wmi: Add tablet_mode_sw=lid-flip quirk for the TP200s Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 11/97] asus-wmi: Add dgpu disable method Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 12/97] platform/x86: asus-wmi: Adjust tablet/lidflip handling to use enum Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 13/97] platform/x86: asus-wmi: Add support for ROG X13 tablet mode Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 14/97] platform/x86: asus-wmi: Simplify tablet-mode-switch probing Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 15/97] platform/x86: asus-wmi: Simplify tablet-mode-switch handling Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 16/97] platform/x86: asus-wmi: Move i8042 filter install to shared asus-wmi code Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 17/97] of: base: Fix some formatting issues and provide missing descriptions Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 18/97] of: Fix kerneldoc output formatting Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 19/97] of: Add missing Return section in kerneldoc comments Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 20/97] of: dynamic: Fix of_reconfig_get_state_change() return value documentation Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 21/97] ipv6: fix potential NULL deref in fib6_add() Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 22/97] octeontx2-pf: Add missing mutex lock in otx2_get_pauseparam Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 23/97] hv_netvsc: rndis_filter needs to select NLS Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 24/97] mlxbf-bootctl: correctly identify secure boot with development keys Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 25/97] net: arcnet: com20020 fix error handling Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 26/97] arcnet: restoring support for multiple Sohard Arcnet cards Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 27/97] i40e: Fix unexpected MFS warning message Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 28/97] net: bnxt: fix a potential use-after-free in bnxt_init_tc Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 29/97] ionic: fix snprintf format length warning Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 30/97] ionic: Fix dim work handling in split interrupt mode Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 31/97] ipv4: ip_gre: Avoid skb_pull() failure in ipgre_xmit() Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 32/97] net: hns: fix fake link up on xge port Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 33/97] netfilter: xt_owner: Fix for unsafe access of sk->sk_socket Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 34/97] tcp: do not accept ACK of bytes we never sent Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 35/97] bpf: sockmap, updating the sg structure should also update curr Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 36/97] tee: optee: Fix supplicant based device enumeration Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 37/97] arm64: dts: rockchip: Expand reg size of vdec node for RK3399 Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 38/97] RDMA/rtrs-clt: Remove the warnings for req in_use check Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 39/97] RDMA/bnxt_re: Correct module description string Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 40/97] hwmon: (acpi_power_meter) Fix 4.29 MW bug Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 41/97] ASoC: wm_adsp: fix memleak in wm_adsp_buffer_populate Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 42/97] tracing: Fix a warning when allocating buffered events fails Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 43/97] scsi: be2iscsi: Fix a memleak in beiscsi_init_wrb_handle() Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 44/97] ARM: imx: Check return value of devm_kasprintf in imx_mmdc_perf_init Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 45/97] ARM: dts: imx7: Declare timers compatible with fsl,imx6dl-gpt Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 46/97] riscv: fix misaligned access handling of C.SWSP and C.SDSP Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 47/97] ALSA: pcm: fix out-of-bounds in snd_pcm_state_names Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 48/97] ALSA: hda/realtek: Enable headset on Lenovo M90 Gen5 Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 49/97] nilfs2: fix missing error check for sb_set_blocksize call Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 50/97] nilfs2: prevent WARNING in nilfs_sufile_set_segment_usage() Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 51/97] checkstack: fix printed address Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 52/97] tracing: Always update snapshot buffer size Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 53/97] tracing: Disable snapshot buffer when stopping instance tracers Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 54/97] tracing: Fix incomplete locking when disabling buffered events Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 55/97] tracing: Fix a possible race " Greg Kroah-Hartman
2023-12-11 18:21 ` [PATCH 5.10 56/97] packet: Move reference count in packet_sock to atomic_long_t Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 57/97] arm64: dts: mediatek: mt7622: fix memory node warning check Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 58/97] arm64: dts: mediatek: mt8173-evb: Fix regulator-fixed node names Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 59/97] arm64: dts: mediatek: mt8183: Fix unit address for scp reserved memory Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 60/97] misc: mei: client.c: return negative error code in mei_cl_write Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 61/97] misc: mei: client.c: fix problem of return -EOVERFLOW " Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 62/97] ring-buffer: Force absolute timestamp on discard of event Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 63/97] tracing: Set actual size after ring buffer resize Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 64/97] tracing: Stop current tracer when resizing buffer Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 65/97] perf/core: Add a new read format to get a number of lost samples Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 66/97] perf: Fix perf_event_validate_size() Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 67/97] gpiolib: sysfs: Fix error handling on failed export Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 68/97] drm/amdgpu: correct the amdgpu runtime dereference usage count Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 69/97] usb: gadget: f_hid: fix report descriptor allocation Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 70/97] parport: Add support for Brainboxes IX/UC/PX parallel cards Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 71/97] Revert "xhci: Loosen RPM as default policy to cover for AMD xHC 1.1" Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 72/97] usb: typec: class: fix typec_altmode_put_partner to put plugs Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 73/97] ARM: PL011: Fix DMA support Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 74/97] serial: sc16is7xx: address RX timeout interrupt errata Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 75/97] serial: 8250: 8250_omap: Clear UART_HAS_RHR_IT_DIS bit Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 76/97] serial: 8250: 8250_omap: Do not start RX DMA on THRI interrupt Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 77/97] serial: 8250_omap: Add earlycon support for the AM654 UART controller Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 78/97] x86/CPU/AMD: Check vendor in the AMD microcode callback Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 79/97] KVM: s390/mm: Properly reset no-dat Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 80/97] MIPS: Loongson64: Reserve vgabios memory on boot Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 81/97] MIPS: Loongson64: Enable DMA noncoherent support Greg Kroah-Hartman
2023-12-30 19:38 ` Salvatore Bonaccorso
2023-12-30 23:16 ` Jiaxun Yang
2023-12-31 9:33 ` Salvatore Bonaccorso
2024-01-03 10:40 ` Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 82/97] io_uring/af_unix: disable sending io_uring over sockets Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 83/97] netlink: dont call ->netlink_bind with table lock held Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 84/97] genetlink: add CAP_NET_ADMIN test for multicast bind Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 85/97] psample: Require CAP_NET_ADMIN when joining "packets" group Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 86/97] drop_monitor: Require CAP_SYS_ADMIN when joining "events" group Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 87/97] netfilter: nft_set_pipapo: skip inactive elements during set walk Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 88/97] platform/x86: asus-wmi: Fix kbd_dock_devid tablet-switch reporting Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 89/97] tools headers UAPI: Sync linux/perf_event.h with the kernel sources Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 90/97] platform/x86: asus-wmi: Document the dgpu_disable sysfs attribute Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 91/97] mmc: block: Be sure to wait while busy in CQE error recovery Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 92/97] Revert "btrfs: add dmesg output for first mount and last unmount of a filesystem" Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 93/97] cifs: Fix non-availability of dedup breaking generic/304 Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 94/97] smb: client: fix potential NULL deref in parse_dfs_referrals() Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 95/97] devcoredump : Serialize devcd_del work Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 96/97] devcoredump: Send uevent once devcd is ready Greg Kroah-Hartman
2023-12-11 18:22 ` [PATCH 5.10 97/97] r8169: fix rtl8125b PAUSE frames blasting when suspended Greg Kroah-Hartman
2023-12-11 19:17 ` [PATCH 5.10 00/97] 5.10.204-rc1 review Florian Fainelli
2023-12-12 16:29 ` Naresh Kamboju
2023-12-12 17:01 ` Guenter Roeck
2023-12-12 19:08 ` Pavel Machek
2023-12-12 22:20 ` Jon Hunter
2023-12-13 3:43 ` Dominique Martinet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231211182019.957772144@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=kadlec@netfilter.org \
--cc=pablo@netfilter.org \
--cc=patches@lists.linux.dev \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).