stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, syzbot <syzkaller@googlegroups.com>,
	Eric Dumazet <edumazet@google.com>,
	Wang Yufen <wangyufen@huawei.com>,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH 5.10 94/95] net: tun: call napi_schedule_prep() to ensure we own a napi
Date: Mon, 14 Nov 2022 13:46:28 +0100	[thread overview]
Message-ID: <20221114124446.401128521@linuxfoundation.org> (raw)
In-Reply-To: <20221114124442.530286937@linuxfoundation.org>

From: Eric Dumazet <edumazet@google.com>

commit 07d120aa33cc9d9115753d159f64d20c94458781 upstream.

A recent patch exposed another issue in napi_get_frags()
caught by syzbot [1]

Before feeding packets to GRO, and calling napi_complete()
we must first grab NAPI_STATE_SCHED.

[1]
WARNING: CPU: 0 PID: 3612 at net/core/dev.c:6076 napi_complete_done+0x45b/0x880 net/core/dev.c:6076
Modules linked in:
CPU: 0 PID: 3612 Comm: syz-executor408 Not tainted 6.1.0-rc3-syzkaller-00175-g1118b2049d77 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
RIP: 0010:napi_complete_done+0x45b/0x880 net/core/dev.c:6076
Code: c1 ea 03 0f b6 14 02 4c 89 f0 83 e0 07 83 c0 03 38 d0 7c 08 84 d2 0f 85 24 04 00 00 41 89 5d 1c e9 73 fc ff ff e8 b5 53 22 fa <0f> 0b e9 82 fe ff ff e8 a9 53 22 fa 48 8b 5c 24 08 31 ff 48 89 de
RSP: 0018:ffffc90003c4f920 EFLAGS: 00010293
RAX: 0000000000000000 RBX: 0000000000000030 RCX: 0000000000000000
RDX: ffff8880251c0000 RSI: ffffffff875a58db RDI: 0000000000000007
RBP: 0000000000000001 R08: 0000000000000007 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000001 R12: ffff888072d02628
R13: ffff888072d02618 R14: ffff888072d02634 R15: 0000000000000000
FS: 0000555555f13300(0000) GS:ffff8880b9a00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055c44d3892b8 CR3: 00000000172d2000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
napi_complete include/linux/netdevice.h:510 [inline]
tun_get_user+0x206d/0x3a60 drivers/net/tun.c:1980
tun_chr_write_iter+0xdb/0x200 drivers/net/tun.c:2027
call_write_iter include/linux/fs.h:2191 [inline]
do_iter_readv_writev+0x20b/0x3b0 fs/read_write.c:735
do_iter_write+0x182/0x700 fs/read_write.c:861
vfs_writev+0x1aa/0x630 fs/read_write.c:934
do_writev+0x133/0x2f0 fs/read_write.c:977
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f37021a3c19

Fixes: 1118b2049d77 ("net: tun: Fix memory leaks of napi_get_frags")
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Wang Yufen <wangyufen@huawei.com>
Link: https://lore.kernel.org/r/20221107180011.188437-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/net/tun.c |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1986,18 +1986,25 @@ drop:
 					  skb_headlen(skb));
 
 		if (unlikely(headlen > skb_headlen(skb))) {
+			WARN_ON_ONCE(1);
+			err = -ENOMEM;
 			this_cpu_inc(tun->pcpu_stats->rx_dropped);
+napi_busy:
 			napi_free_frags(&tfile->napi);
 			rcu_read_unlock();
 			mutex_unlock(&tfile->napi_mutex);
-			WARN_ON(1);
-			return -ENOMEM;
+			return err;
 		}
 
-		local_bh_disable();
-		napi_gro_frags(&tfile->napi);
-		napi_complete(&tfile->napi);
-		local_bh_enable();
+		if (likely(napi_schedule_prep(&tfile->napi))) {
+			local_bh_disable();
+			napi_gro_frags(&tfile->napi);
+			napi_complete(&tfile->napi);
+			local_bh_enable();
+		} else {
+			err = -EBUSY;
+			goto napi_busy;
+		}
 		mutex_unlock(&tfile->napi_mutex);
 	} else if (tfile->napi_enabled) {
 		struct sk_buff_head *queue = &tfile->sk.sk_write_queue;



  parent reply	other threads:[~2022-11-14 12:52 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14 12:44 [PATCH 5.10 00/95] 5.10.155-rc1 review Greg Kroah-Hartman
2022-11-14 12:44 ` [PATCH 5.10 01/95] fuse: fix readdir cache race Greg Kroah-Hartman
2022-11-14 12:44 ` [PATCH 5.10 02/95] hwspinlock: qcom: correct MMIO max register for newer SoCs Greg Kroah-Hartman
2022-11-14 12:44 ` [PATCH 5.10 03/95] phy: stm32: fix an error code in probe Greg Kroah-Hartman
2022-11-14 12:44 ` [PATCH 5.10 04/95] wifi: cfg80211: silence a sparse RCU warning Greg Kroah-Hartman
2022-11-14 12:44 ` [PATCH 5.10 05/95] wifi: cfg80211: fix memory leak in query_regdb_file() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 06/95] bpf, sockmap: Fix the sk->sk_forward_alloc warning of sk_stream_kill_queues Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 07/95] bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 08/95] HID: hyperv: fix possible memory leak in mousevsc_probe() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 09/95] bpf: Support for pointers beyond pkt_end Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 10/95] bpf: Add helper macro bpf_for_each_reg_in_vstate Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 11/95] bpf: Fix wrong reg type conversion in release_reference() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 12/95] net: gso: fix panic on frag_list with mixed head alloc types Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 13/95] macsec: delete new rxsc when offload fails Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 14/95] macsec: fix secy->n_rx_sc accounting Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 15/95] macsec: fix detection of RXSCs when toggling offloading Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 16/95] macsec: clear encryption keys from the stack after setting up offload Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 17/95] net: tun: Fix memory leaks of napi_get_frags Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 18/95] bnxt_en: Fix possible crash in bnxt_hwrm_set_coal() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 19/95] bnxt_en: fix potentially incorrect return value for ndo_rx_flow_steer Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 20/95] net: fman: Unregister ethernet device on removal Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 21/95] capabilities: fix undefined behavior in bit shift for CAP_TO_MASK Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 22/95] KVM: s390x: fix SCK locking Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 23/95] KVM: s390: pv: dont allow userspace to set the clock under PV Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 24/95] net: lapbether: fix issue of dev reference count leakage in lapbeth_device_event() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 25/95] hamradio: fix issue of dev reference count leakage in bpq_device_event() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 26/95] drm/vc4: Fix missing platform_unregister_drivers() call in vc4_drm_register() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 27/95] tcp: prohibit TCP_REPAIR_OPTIONS if data was already sent Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 28/95] ipv6: addrlabel: fix infoleak when sending struct ifaddrlblmsg to network Greg Kroah-Hartman
2022-11-14 12:48   ` syzbot
2022-11-14 12:45 ` [PATCH 5.10 29/95] can: af_can: fix NULL pointer dereference in can_rx_register() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 30/95] net: stmmac: dwmac-meson8b: fix meson8b_devm_clk_prepare_enable() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 31/95] net: broadcom: Fix BCMGENET Kconfig Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 32/95] tipc: fix the msg->req tlv len check in tipc_nl_compat_name_table_dump_header Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 33/95] dmaengine: pxa_dma: use platform_get_irq_optional Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 34/95] dmaengine: mv_xor_v2: Fix a resource leak in mv_xor_v2_remove() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 35/95] drivers: net: xgene: disable napi when register irq failed in xgene_enet_open() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 36/95] perf stat: Fix printing os->prefix in CSV metrics output Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 37/95] net: marvell: prestera: fix memory leak in prestera_rxtx_switch_init() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 38/95] net: nixge: disable napi when enable interrupts failed in nixge_open() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 39/95] net/mlx5: Allow async trigger completion execution on single CPU systems Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 40/95] net/mlx5e: E-Switch, Fix comparing termination table instance Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 41/95] net: cpsw: disable napi in cpsw_ndo_open() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 42/95] net: cxgb3_main: disable napi when bind qsets failed in cxgb_up() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 43/95] cxgb4vf: shut down the adapter when t4vf_update_port_info() failed in cxgb4vf_open() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 44/95] net: phy: mscc: macsec: clear encryption keys when freeing a flow Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 45/95] net: atlantic: macsec: clear encryption keys from the stack Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 46/95] ethernet: s2io: disable napi when start nic failed in s2io_card_up() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 47/95] net: mv643xx_eth: disable napi when init rxq or txq failed in mv643xx_eth_open() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 48/95] ethernet: tundra: free irq when alloc ring failed in tsi108_open() Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 49/95] net: macvlan: fix memory leaks of macvlan_common_newlink Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 50/95] riscv: process: fix kernel info leakage Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 51/95] riscv: vdso: fix build with llvm Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 52/95] riscv: Enable CMA support Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 53/95] riscv: Separate memory init from paging init Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 54/95] riscv: fix reserved memory setup Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 55/95] arm64: efi: Fix handling of misaligned runtime regions and drop warning Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 56/95] MIPS: jump_label: Fix compat branch range check Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 57/95] mmc: cqhci: Provide helper for resetting both SDHCI and CQHCI Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 58/95] mmc: sdhci-of-arasan: Fix SDHCI_RESET_ALL for CQHCI Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 59/95] mmc: sdhci_am654: " Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 60/95] mmc: sdhci-tegra: " Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 61/95] ALSA: hda/hdmi - enable runtime pm for more AMD display audio Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 62/95] ALSA: hda/ca0132: add quirk for EVGA Z390 DARK Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 63/95] ALSA: hda: fix potential memleak in add_widget_node Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 64/95] ALSA: hda/realtek: Add Positivo C6300 model quirk Greg Kroah-Hartman
2022-11-14 12:45 ` [PATCH 5.10 65/95] ALSA: usb-audio: Add quirk entry for M-Audio Micro Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 66/95] ALSA: usb-audio: Add DSD support for Accuphase DAC-60 Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 67/95] vmlinux.lds.h: Fix placement of .data..decrypted section Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 68/95] ata: libata-scsi: fix SYNCHRONIZE CACHE (16) command failure Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 69/95] nilfs2: fix deadlock in nilfs_count_free_blocks() Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 70/95] nilfs2: fix use-after-free bug of ns_writer on remount Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 71/95] drm/i915/dmabuf: fix sg_table handling in map_dma_buf Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 72/95] platform/x86: hp_wmi: Fix rfkill causing soft blocked wifi Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 73/95] btrfs: selftests: fix wrong error check in btrfs_free_dummy_root() Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 74/95] mms: sdhci-esdhc-imx: Fix SDHCI_RESET_ALL for CQHCI Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 75/95] udf: Fix a slab-out-of-bounds write bug in udf_find_entry() Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 76/95] mm/memremap.c: map FS_DAX device memory as decrypted Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 77/95] can: j1939: j1939_send_one(): fix missing CAN header initialization Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 78/95] cert host tools: Stop complaining about deprecated OpenSSL functions Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 79/95] dmaengine: at_hdmac: Fix at_lli struct definition Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 80/95] dmaengine: at_hdmac: Dont start transactions at tx_submit level Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 81/95] dmaengine: at_hdmac: Start transfer for cyclic channels in issue_pending Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 82/95] dmaengine: at_hdmac: Fix premature completion of desc " Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 83/95] dmaengine: at_hdmac: Do not call the complete callback on device_terminate_all Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 84/95] dmaengine: at_hdmac: Protect atchan->status with the channel lock Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 85/95] dmaengine: at_hdmac: Fix concurrency problems by removing atc_complete_all() Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 86/95] dmaengine: at_hdmac: Fix concurrency over descriptor Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 87/95] dmaengine: at_hdmac: Free the memset buf without holding the chan lock Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 88/95] dmaengine: at_hdmac: Fix concurrency over the active list Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 89/95] dmaengine: at_hdmac: Fix descriptor handling when issuing it to hardware Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 90/95] dmaengine: at_hdmac: Fix completion of unissued descriptor in case of errors Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 91/95] dmaengine: at_hdmac: Dont allow CPU to reorder channel enable Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 92/95] dmaengine: at_hdmac: Fix impossible condition Greg Kroah-Hartman
2022-11-14 12:46 ` [PATCH 5.10 93/95] dmaengine: at_hdmac: Check return code of dma_async_device_register Greg Kroah-Hartman
2022-11-14 12:46 ` Greg Kroah-Hartman [this message]
2022-11-14 12:46 ` [PATCH 5.10 95/95] mmc: sdhci-esdhc-imx: Convert the driver to DT-only Greg Kroah-Hartman
2022-11-14 18:35 ` [PATCH 5.10 00/95] 5.10.155-rc1 review Pavel Machek
2022-11-14 20:20 ` Shuah Khan
2022-11-14 21:06 ` Slade Watkins
2022-11-14 21:44 ` Florian Fainelli
2022-11-15  0:12 ` Guenter Roeck
2022-11-15 10:50 ` Sudip Mukherjee
2022-11-15 10:58 ` Naresh Kamboju
2022-11-15 11:49 ` Rudi Heitbaum
2022-11-16  1:44 ` zhouzhixiu

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=20221114124446.401128521@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=syzkaller@googlegroups.com \
    --cc=wangyufen@huawei.com \
    /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).