All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	Alan Cox <alan@linux.intel.com>
Subject: [patch 055/123] tty: Fix the ldisc hangup race
Date: Fri, 12 Mar 2010 16:12:33 -0800	[thread overview]
Message-ID: <20100313001509.980265580@kvm.kroah.org> (raw)
In-Reply-To: <20100313001618.GA9811@kroah.com>
In-Reply-To: <20100313001618.GA9811@kroah.com>

2.6.33-stable review patch.  If anyone has any objections, please let me know.

-----------------

From: Alan Cox <alan@linux.intel.com>

commit 638b9648ab51c9c549ff5735d3de519ef6199df3 upstream.

This was noticed by Matthias Urlichs and he proposed a fix. This patch
does the fixing a different way to avoid introducing several new race
conditions into the code.

The problem case is TTY_DRIVER_RESET_TERMIOS = 0. In that case while we
abort the ldisc change, the hangup processing has not cleaned up and restarted
the ldisc either.

We can't restart the ldisc stuff in the set_ldisc as we don't know what
the hangup did and may touch stuff we shouldn't as we are no longer
supposed to influence the tty at that point in case it has been re-opened
before we get rescheduled.

Instead do it the simple way. Always re-init the ldisc on the hangup, but
use TTY_DRIVER_RESET_TERMIOS to indicate that we should force N_TTY.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/char/tty_ldisc.c |   50 ++++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 20 deletions(-)

--- a/drivers/char/tty_ldisc.c
+++ b/drivers/char/tty_ldisc.c
@@ -706,12 +706,13 @@ static void tty_reset_termios(struct tty
 /**
  *	tty_ldisc_reinit	-	reinitialise the tty ldisc
  *	@tty: tty to reinit
+ *	@ldisc: line discipline to reinitialize
  *
- *	Switch the tty back to N_TTY line discipline and leave the
- *	ldisc state closed
+ *	Switch the tty to a line discipline and leave the ldisc
+ *	state closed
  */
 
-static void tty_ldisc_reinit(struct tty_struct *tty)
+static void tty_ldisc_reinit(struct tty_struct *tty, int ldisc)
 {
 	struct tty_ldisc *ld;
 
@@ -721,10 +722,10 @@ static void tty_ldisc_reinit(struct tty_
 	/*
 	 *	Switch the line discipline back
 	 */
-	ld = tty_ldisc_get(N_TTY);
+	ld = tty_ldisc_get(ldisc);
 	BUG_ON(IS_ERR(ld));
 	tty_ldisc_assign(tty, ld);
-	tty_set_termios_ldisc(tty, N_TTY);
+	tty_set_termios_ldisc(tty, ldisc);
 }
 
 /**
@@ -745,6 +746,8 @@ static void tty_ldisc_reinit(struct tty_
 void tty_ldisc_hangup(struct tty_struct *tty)
 {
 	struct tty_ldisc *ld;
+	int reset = tty->driver->flags & TTY_DRIVER_RESET_TERMIOS;
+	int err = 0;
 
 	/*
 	 * FIXME! What are the locking issues here? This may me overdoing
@@ -772,25 +775,32 @@ void tty_ldisc_hangup(struct tty_struct
 	wake_up_interruptible_poll(&tty->read_wait, POLLIN);
 	/*
 	 * Shutdown the current line discipline, and reset it to
-	 * N_TTY.
+	 * N_TTY if need be.
+	 *
+	 * Avoid racing set_ldisc or tty_ldisc_release
 	 */
-	if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) {
-		/* Avoid racing set_ldisc or tty_ldisc_release */
-		mutex_lock(&tty->ldisc_mutex);
-		tty_ldisc_halt(tty);
-		if (tty->ldisc) {	/* Not yet closed */
-			/* Switch back to N_TTY */
-			tty_ldisc_reinit(tty);
-			/* At this point we have a closed ldisc and we want to
-			   reopen it. We could defer this to the next open but
-			   it means auditing a lot of other paths so this is
-			   a FIXME */
+	mutex_lock(&tty->ldisc_mutex);
+	tty_ldisc_halt(tty);
+	/* At this point we have a closed ldisc and we want to
+	   reopen it. We could defer this to the next open but
+	   it means auditing a lot of other paths so this is
+	   a FIXME */
+	if (tty->ldisc) {	/* Not yet closed */
+		if (reset == 0) {
+			tty_ldisc_reinit(tty, tty->termios->c_line);
+			err = tty_ldisc_open(tty, tty->ldisc);
+		}
+		/* If the re-open fails or we reset then go to N_TTY. The
+		   N_TTY open cannot fail */
+		if (reset || err) {
+			tty_ldisc_reinit(tty, N_TTY);
 			WARN_ON(tty_ldisc_open(tty, tty->ldisc));
-			tty_ldisc_enable(tty);
 		}
-		mutex_unlock(&tty->ldisc_mutex);
-		tty_reset_termios(tty);
+		tty_ldisc_enable(tty);
 	}
+	mutex_unlock(&tty->ldisc_mutex);
+	if (reset)
+		tty_reset_termios(tty);
 }
 
 /**



  parent reply	other threads:[~2010-03-13  1:24 UTC|newest]

Thread overview: 140+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-13  0:16 [patch 000/123] 2.6.33.1-stable review Greg KH
2010-03-13  0:11 ` [patch 001/123] ahci: disable FPDMA auto-activate optimization on NVIDIA AHCI Greg KH
2010-03-13  0:11 ` [patch 002/123] netlabel: fix export of SELinux categories > 127 Greg KH
2010-03-13  0:11 ` [patch 003/123] PCI hotplug: ibmphp: read the length of ebda and map entire ebda region Greg KH
2010-03-13  0:11 ` [patch 004/123] PCI hotplug: check ioremap() return value in ibmphp_ebda.c Greg KH
2010-03-13  0:11 ` [patch 005/123] security: fix error return path in ima_inode_alloc Greg KH
2010-03-13  0:11 ` [patch 006/123] airo: fix setting zero length WEP key Greg KH
2010-03-13  0:11 ` [patch 007/123] HID: remove TENX iBuddy from blacklist Greg KH
2010-03-13  0:11 ` [patch 008/123] HID: usbhid: introduce timeout for stuck ctrl/out URBs Greg KH
2010-03-13  0:11 ` [patch 009/123] mac80211: quit addba_resp_timer if Tx BA session is torn down Greg KH
2010-03-13  0:11 ` [patch 010/123] mac80211: Reset dynamic ps timer in Rx path Greg KH
2010-03-13  0:11 ` [patch 011/123] [SCSI] mpt2sas: Delete volume before HBA detach Greg KH
2010-03-13  0:11 ` [patch 012/123] readahead: introduce FMODE_RANDOM for POSIX_FADV_RANDOM Greg KH
2010-03-13  0:11 ` [patch 013/123] slab: initialize unused alien cache entry as NULL at alloc_alien_cache() Greg KH
2010-03-13  0:11 ` [patch 014/123] V4L/DVB (13991): gspca_mr973010a: Fix cif type 1 cameras not streaming on UHCI controllers Greg KH
2010-03-13  0:11 ` [patch 015/123] vfs: take f_lock on modifying f_mode after open time Greg KH
2010-03-13  0:11 ` [patch 016/123] x86, uv: uv_global_gru_mmr_address() macro fix Greg KH
2010-03-13  0:11 ` [patch 017/123] drm/i915: give up on 8xx lid status Greg KH
2010-03-13  0:11 ` [patch 018/123] ath9k: fix keycache leak in split tkip case Greg KH
2010-03-13  0:11 ` [patch 019/123] rtc-core: fix memory leak Greg KH
2010-03-13  0:11 ` [patch 020/123] x86/PCI: Prevent mmconfig memory corruption Greg KH
2010-03-13  0:11 ` [patch 021/123] clocksource: Fix up a registration/IRQ race in the sh drivers Greg KH
2010-03-13  0:12 ` [patch 022/123] SCSI: qla1280: Drop host_lock while requesting firmware Greg KH
2010-03-13  0:12 ` [patch 023/123] Staging: hv: add a pci device table Greg KH
2010-03-13  0:12 ` [patch 024/123] Staging: hv: match on DMI values to know if we should run Greg KH
2010-03-13  0:12 ` [patch 025/123] Staging: Fixed pohmelfs regression because of per-bdi writeback Greg KH
2010-03-13  0:12 ` [patch 026/123] Staging: wlan-ng: Add select WEXT_PRIV to Kconfig to prevent build failure Greg KH
2010-03-13  0:12 ` [patch 027/123] Staging: mimio: remove the mimio driver Greg KH
2010-03-13  0:12 ` [patch 028/123] dvb-core: Fix DoS bug in ULE decapsulation code that can be triggered by an invalid Payload Pointer Greg KH
2010-03-13  0:12 ` [patch 029/123] V4L/DVB: v4l: soc_camera: fix bound checking of mbus_fmt[] index Greg KH
2010-03-13  0:12 ` [patch 030/123] PM / Hibernate: Fix preallocating of memory Greg KH
2010-03-13  0:12 ` [patch 031/123] macintosh/therm_adt746x: Fix sysfs attributes lifetime Greg KH
2010-03-13  0:12 ` [patch 032/123] macintosh/hwmon/ams: Fix device removal sequence Greg KH
2010-03-13  0:12 ` [patch 033/123] oprofile/x86: fix perfctr nmi reservation for mulitplexing Greg KH
2010-03-13  0:12 ` [patch 034/123] perf symbols: Check the right return variable Greg KH
2010-03-13  0:12 ` [patch 035/123] perf_event: Fix preempt warning in perf_clock() Greg KH
2010-03-13  0:12 ` [patch 036/123] oprofile: remove tracing build dependency Greg KH
2010-03-13  0:12 ` [patch 037/123] oprofile/x86: remove node check in AMD IBS initialization Greg KH
2010-03-13  0:12 ` [patch 038/123] oprofile/x86: use kzalloc() instead of kmalloc() Greg KH
2010-03-13  0:12 ` [patch 039/123] oprofile/x86: fix msr access to reserved counters Greg KH
2010-03-13  0:12 ` [patch 040/123] perf: Reimplement frequency driven sampling Greg KH
2010-03-13  0:12 ` [patch 041/123] tracing: Fix ftrace_event_call alignment for use with gcc 4.5 Greg KH
2010-03-13  0:12 ` [patch 042/123] ALSA: hda: Use 3stack quirk for Toshiba Satellite L40-10Q Greg KH
2010-03-13  0:12 ` [patch 043/123] ALSA: via82xx: add quirk for D1289 motherboard Greg KH
2010-03-13  0:12 ` [patch 044/123] ALSA: pcm core - fix fifo_size channels interval check Greg KH
2010-03-13  0:12 ` [patch 045/123] ALSA: usb-audio: reduce MIDI packet size to work around broken firmware Greg KH
2010-03-13  0:12 ` [patch 046/123] ALSA: USB MIDI support for Access Music VirusTI Greg KH
2010-03-13  0:12 ` [patch 047/123] thinkpad-acpi: fix ALSA callback return status Greg KH
2010-03-13  0:12 ` [patch 048/123] ALSA: hda: Use LPIB for Dell Latitude 131L Greg KH
2010-03-13  0:12 ` [patch 049/123] ALSA: hda: Use LPIB for a Biostar Microtech board Greg KH
2010-03-13  0:12 ` [patch 050/123] ALSA: hda-intel: Add position_fix quirk for ASUS M2V-MX SE Greg KH
2010-03-13  0:12 ` [patch 051/123] ASoC: fix ak4104 register array access Greg KH
2010-03-13  0:12 ` [patch 052/123] driver-core: fix race condition in get_device_parent() Greg KH
2010-03-13  0:12 ` [patch 053/123] Driver-Core: devtmpfs - reset inode permissions before unlinking Greg KH
2010-03-13  0:12 ` [patch 054/123] sysfs: Cache the last sysfs_dirent to improve readdir scalability v2 Greg KH
2010-03-13  0:12 ` Greg KH [this message]
2010-03-13  0:12 ` [patch 056/123] serial: imx: fix NULL dereference Oops when pdata == NULL Greg KH
2010-03-13  0:12 ` [patch 057/123] USB: serial: sierra driver indat_callback fix Greg KH
2010-03-13  0:12 ` [patch 058/123] USB: fix I2C API usage in ohci-pnx4008 Greg KH
2010-03-13  0:12 ` [patch 059/123] p54usb: Add the USB ID for Belkin (Accton) FD7050E ver 1010ec Greg KH
2010-03-13  0:12 ` [patch 060/123] p54pci: handle dma mapping errors Greg KH
2010-03-13  0:12 ` [patch 061/123] gpiolib: Actually set output state in wm831x_gpio_direction_output() Greg KH
2010-03-13  0:12 ` [patch 062/123] gpio: cs5535-gpio: fix input direction Greg KH
2010-03-13  0:12 ` [patch 063/123] hwmon: (tmp421) Fix temperature conversions Greg KH
2010-03-13  0:12 ` [patch 064/123] hwmon: (tmp421) Restore missing inputs Greg KH
2010-03-13  0:12 ` [patch 065/123] hwmon: Fix off-by-one kind values Greg KH
2010-03-13  0:12 ` [patch 066/123] pata_hpt3x2n: always stretch UltraDMA timing Greg KH
2010-03-13  0:12 ` [patch 067/123] scm: Only support SCM_RIGHTS on unix domain sockets Greg KH
2010-03-13  0:12 ` [patch 068/123] skbuff: align sk_buff::cb to 64 bit and close some potential holes Greg KH
2010-03-13  0:12 ` [patch 069/123] netdevice.h: check for CONFIG_WLAN instead of CONFIG_WLAN_80211 Greg KH
2010-03-13  0:12 ` [patch 070/123] ath9k: re-enable ps by default for new single chip families Greg KH
2010-03-16  1:04   ` [Stable-review] " Luis R. Rodriguez
2010-03-19  0:04     ` [stable] " Greg KH
2010-03-23 19:26       ` [Stable-review] [stable] " Luis R. Rodriguez
2010-04-02 17:37       ` [stable] [Stable-review] " Luis R. Rodriguez
2010-03-13  0:12 ` [patch 071/123] ath9k: fix beacon timer restart after a card reset Greg KH
2010-03-13  0:12 ` [patch 072/123] ath9k: fix rate control fallback rate selection Greg KH
2010-03-13  0:12 ` [patch 073/123] ath9k: disable RIFS search for AR91xx based chips Greg KH
2010-03-13  0:12 ` [patch 074/123] ath5k: use correct packet type when transmitting Greg KH
2010-03-13  0:12 ` [patch 075/123] b43/b43legacy: Wake queues in wireless_core_start Greg KH
2010-03-13  0:12 ` [patch 076/123] netfilter: xt_recent: fix buffer overflow Greg KH
2010-03-13  0:12 ` [patch 077/123] netfilter: xt_recent: fix false match Greg KH
2010-03-13  0:12 ` [patch 078/123] sunxvr500: Additional PCI id for sunxvr500 driver Greg KH
2010-03-13  0:12 ` [patch 079/123] mac80211: do not transmit frames on unconfigured 4-addr vlan interfaces Greg KH
2010-03-13  0:12 ` [patch 080/123] eeepc-laptop: disable wireless hotplug for 1005PE Greg KH
2010-03-13  0:12 ` [patch 081/123] thinkpad-acpi: fix poll thread auto-start Greg KH
2010-03-13  0:13 ` [patch 082/123] thinkpad-acpi: R52 brightness_mode has been confirmed Greg KH
2010-03-13  0:13 ` [patch 083/123] thinkpad-acpi: document HKEY event 3006 Greg KH
2010-03-13  0:13 ` [patch 084/123] thinkpad-acpi: make driver events work in NVRAM poll mode Greg KH
2010-03-13  0:13 ` [patch 085/123] thinkpad-acpi: fix bluetooth/wwan resume Greg KH
2010-03-13  0:13 ` [patch 086/123] thinkpad-acpi: lock down video output state access Greg KH
2010-03-13  0:13 ` [patch 087/123] ocfs2: Only bug out in direct io write for reflinked extent Greg KH
2010-03-13  0:13 ` [patch 088/123] x86, ia32_aout: do not kill argument mapping Greg KH
2010-03-13  0:13 ` [patch 089/123] x86: Add iMac9,1 to pci_reboot_dmi_table Greg KH
2010-03-13  0:13 ` [patch 090/123] x86, xen: Disable highmem PTE allocation even when CONFIG_HIGHPTE=y Greg KH
2010-03-13  0:13   ` Greg KH
2010-03-13  0:13 ` [patch 091/123] x86: Avoid race condition in pci_enable_msix() Greg KH
2010-03-13  0:13 ` [patch 092/123] x86: Fix SCI on IOAPIC != 0 Greg KH
2010-03-13  0:13 ` [patch 093/123] USB: xhci: Fix finding extended capabilities registers Greg KH
2010-03-13  0:13 ` [patch 094/123] USB: fix the idProduct value for USB-3.0 root hubs Greg KH
2010-03-13  0:13 ` [patch 095/123] USB: fix crash in uhci_scan_schedule Greg KH
2010-03-13  0:13 ` [patch 096/123] USB: remove debugging message for uevent constructions Greg KH
2010-03-13  0:13 ` [patch 097/123] USB: Move hcd free_dev call into usb_disconnect to fix oops Greg KH
2010-03-13  0:13 ` [patch 098/123] USB: f_mass_storage: fix crash on bind() error Greg KH
2010-03-13  0:13 ` [patch 099/123] USB: add new ftdi_sio device ids Greg KH
2010-03-13  0:13 ` [patch 100/123] USB: serial: ftdi: add CONTEC vendor and product id Greg KH
2010-03-13  0:13 ` [patch 101/123] USB: cp210x: Add 81E8 (Zephyr Bioharness) Greg KH
2010-03-13  0:13 ` [patch 102/123] USB: unusual_devs: Add support for multiple Option 3G sticks Greg KH
2010-03-13  0:13 ` [patch 103/123] drm/i915: Use a dmi quirk to skip a broken SDVO TV output Greg KH
2010-03-13  0:13 ` [patch 104/123] drm/ttm: handle OOM in ttm_tt_swapout Greg KH
2010-03-13  0:13 ` [patch 105/123] drm/radeon/kms/atom: fix shr/shl ops Greg KH
2010-03-13  0:13 ` [patch 106/123] sunrpc: remove unnecessary svc_xprt_put Greg KH
2010-03-13  0:13 ` [patch 107/123] SUNRPC: Handle EINVAL error returns from the TCP connect operation Greg KH
2010-03-13  0:13 ` [patch 108/123] s3cmci: s3cmci_card_present: Use no_detect to decide whether there is a card detect pin Greg KH
2010-03-13  0:13   ` Greg KH
2010-03-13  0:13 ` [patch 109/123] s3cmci: initialize default platform data no_wprotect and no_detect with 1 Greg KH
2010-03-13  0:13   ` Greg KH
2010-03-15 16:16   ` [Stable-review] " Stefan Bader
2010-03-30 21:17     ` Greg KH
2010-03-13  0:13 ` [patch 110/123] scripts/get_maintainer.pl: fix possible infinite loop Greg KH
2010-03-13  0:13 ` [patch 111/123] rtc-coh901331: fix braces in resume code Greg KH
2010-03-13  0:13 ` [patch 112/123] NFS: Fix an allocation-under-spinlock bug Greg KH
2010-03-13  0:13 ` [patch 113/123] dm: free dm_io before bio_endio not after Greg KH
2010-03-13  0:13 ` [patch 114/123] dm ioctl: only issue uevent on resume if state changed Greg KH
2010-03-22 18:43   ` Mike Snitzer
2010-03-22 18:54     ` Alasdair G Kergon
2010-04-19 17:44       ` [stable] " Greg KH
2010-03-13  0:13 ` [patch 115/123] KVM: VMX: Trap and invalid MWAIT/MONITOR instruction Greg KH
2010-03-13  0:13 ` [patch 116/123] KVM: x86 emulator: Add group8 instruction decoding Greg KH
2010-03-13  0:13 ` [patch 117/123] KVM: x86 emulator: Forbid modifying CS segment register by mov instruction Greg KH
2010-03-13  0:13 ` [patch 118/123] KVM: x86 emulator: Add group9 instruction decoding Greg KH
2010-03-13  0:13 ` [patch 119/123] KVM: x86 emulator: Check CPL level during privilege instruction emulation Greg KH
2010-03-13  0:13 ` [patch 120/123] sched: Fix sched_mv_power_savings for !SMT Greg KH
2010-03-15  5:51   ` Vaidyanathan Srinivasan
2010-03-15 14:27     ` Greg KH
2010-03-13  0:13 ` [patch 121/123] sched: Fix SMT scheduler regression in find_busiest_queue() Greg KH
2010-03-13  0:13 ` [patch 122/123] sched: Dont use possibly stale sched_class Greg KH
2010-03-13  0:13 ` [patch 123/123] x86, mm: Allow highmem user page tables to be disabled at boot time Greg KH
2010-03-13  2:58 ` [patch 000/123] 2.6.33.1-stable review Grant Coady
2010-03-13  3:27   ` Greg KH

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=20100313001509.980265580@kvm.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@linux.intel.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable-review@kernel.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.