From: Luis Henriques <luis.henriques@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
kernel-team@lists.ubuntu.com
Cc: Peter Hurley <peter@hurleysoftware.com>,
Jiri Slaby <jslaby@suse.cz>,
Linus Torvalds <torvalds@linux-foundation.org>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Luis Henriques <luis.henriques@canonical.com>
Subject: [PATCH 3.11 69/70] n_tty: Fix n_tty_write crash when echoing in raw mode
Date: Wed, 7 May 2014 14:13:12 +0100 [thread overview]
Message-ID: <1399468393-10140-70-git-send-email-luis.henriques@canonical.com> (raw)
In-Reply-To: <1399468393-10140-1-git-send-email-luis.henriques@canonical.com>
3.11.10.10 -stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Hurley <peter@hurleysoftware.com>
commit 4291086b1f081b869c6d79e5b7441633dc3ace00 upstream.
The tty atomic_write_lock does not provide an exclusion guarantee for
the tty driver if the termios settings are LECHO & !OPOST. And since
it is unexpected and not allowed to call TTY buffer helpers like
tty_insert_flip_string concurrently, this may lead to crashes when
concurrect writers call pty_write. In that case the following two
writers:
* the ECHOing from a workqueue and
* pty_write from the process
race and can overflow the corresponding TTY buffer like follows.
If we look into tty_insert_flip_string_fixed_flag, there is:
int space = __tty_buffer_request_room(port, goal, flags);
struct tty_buffer *tb = port->buf.tail;
...
memcpy(char_buf_ptr(tb, tb->used), chars, space);
...
tb->used += space;
so the race of the two can result in something like this:
A B
__tty_buffer_request_room
__tty_buffer_request_room
memcpy(buf(tb->used), ...)
tb->used += space;
memcpy(buf(tb->used), ...) ->BOOM
B's memcpy is past the tty_buffer due to the previous A's tb->used
increment.
Since the N_TTY line discipline input processing can output
concurrently with a tty write, obtain the N_TTY ldisc output_lock to
serialize echo output with normal tty writes. This ensures the tty
buffer helper tty_insert_flip_string is not called concurrently and
everything is fine.
Note that this is nicely reproducible by an ordinary user using
forkpty and some setup around that (raw termios + ECHO). And it is
present in kernels at least after commit
d945cb9cce20ac7143c2de8d88b187f62db99bdc (pty: Rework the pty layer to
use the normal buffering logic) in 2.6.31-rc3.
js: add more info to the commit log
js: switch to bool
js: lock unconditionally
js: lock only the tty->ops->write call
References: CVE-2014-0196
Reported-and-tested-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
---
drivers/tty/n_tty.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 4bf0fc0..10354a8 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2066,8 +2066,12 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
if (tty->ops->flush_chars)
tty->ops->flush_chars(tty);
} else {
+ struct n_tty_data *ldata = tty->disc_data;
+
while (nr > 0) {
+ mutex_lock(&ldata->output_lock);
c = tty->ops->write(tty, b, nr);
+ mutex_unlock(&ldata->output_lock);
if (c < 0) {
retval = c;
goto break_out;
--
1.9.1
next prev parent reply other threads:[~2014-05-07 13:13 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-07 13:12 [3.11.y.z extended stable] Linux 3.11.10.10 stable review Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 01/70] core, nfqueue, openvswitch: Orphan frags in skb_zerocopy and handle errors Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 02/70] KVM: ioapic: fix assignment of ioapic->rtc_status.pending_eoi (CVE-2014-0155) Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 03/70] iio: querying buffer scan_mask should return 0/1 Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 04/70] pata_at91: fix ata_host_activate() failure handling Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 05/70] ext4: note the error in ext4_end_bio() Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 06/70] ext4: fix jbd2 warning under heavy xattr load Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 07/70] ext4: use i_size_read in ext4_unaligned_aio() Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 08/70] locks: allow __break_lease to sleep even when break_time is 0 Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 09/70] usb: gadget: zero: Fix SuperSpeed enumeration for alternate setting 1 Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 10/70] ahci: do not request irq for dummy port Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 11/70] genirq: Allow forcing cpu affinity of interrupts Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 12/70] irqchip: Gic: Support forced affinity setting Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 13/70] clocksource: Exynos_mct: Register clock event after request_irq() Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 14/70] nfsd: set timeparms.to_maxval in setup_callback_client Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 15/70] ahci: Do not receive interrupts sent by dummy ports Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 16/70] libata/ahci: accommodate tag ordered controllers Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 17/70] Input: synaptics - add min/max quirk for ThinkPad T431s, L440, L540, S1 Yoga and X1 Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 18/70] drm/radeon: fix count in cik_sdma_ring_test() Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 19/70] drm/radeon/pm: don't walk the crtc list before it has been initialized (v2) Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 20/70] drm/radeon: fix ATPX detection on non-VGA GPUs Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 21/70] mm: make fixup_user_fault() check the vma access rights too Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 22/70] ARM: 8027/1: fix do_div() bug in big-endian systems Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 23/70] ARM: 8030/1: ARM : kdump : add arch_crash_save_vmcoreinfo Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 24/70] USB: serial: fix sysfs-attribute removal deadlock Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 25/70] 8250_core: Fix unwanted TX chars write Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 26/70] serial: 8250: Fix thread unsafe __dma_tx_complete function Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 27/70] Btrfs: fix inode caching vs tree log Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 28/70] usb: xhci: Prefer endpoint context dequeue pointer over stopped_trb Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 29/70] xhci: Switch Intel Lynx Point ports to EHCI on shutdown Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 30/70] usb/xhci: fix compilation warning when !CONFIG_PCI && !CONFIG_PM Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 31/70] USB: io_ti: fix firmware download on big-endian machines Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 32/70] usb: qcserial: add Sierra Wireless EM7355 Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 33/70] usb: qcserial: add Sierra Wireless MC73xx Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 34/70] usb: qcserial: add Sierra Wireless MC7305/MC7355 Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 35/70] usb: option: add Olivetti Olicard 500 Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 36/70] usb: option: add Alcatel L800MA Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 37/70] usb: option: add and update a number of CMOTech devices Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 38/70] crypto: crypto_wq - Fix late crypto work queue initialization Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 39/70] i2c: i801: Add Device IDs for Intel Wildcat Point-LP PCH Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 40/70] i2c: i801: enable Intel BayTrail SMBUS Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 41/70] ftrace/x86: One more missing sync after fixup of function modification failure Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 42/70] Bluetooth: Add support for Intel Bluetooth device [8087:0a2a] Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 43/70] ARM: 8007/1: Remove extraneous kcmp syscall ignore Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 44/70] ARM: mvebu: ensure the mdio node has a clock reference on Armada 370/XP Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 45/70] ARM: OMAP3: hwmod data: Correct clock domains for USB modules Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 46/70] ARM: OMAP4: Fix definition of IS_PM44XX_ERRATUM Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 47/70] xhci: extend quirk for Renesas cards Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 48/70] [SCSI] qla2xxx: fix error handling of qla2x00_mem_alloc() Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 49/70] [SCSI] arcmsr: upper 32 of dma address lost Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 50/70] ARM: 7840/1: LPAE: don't reject mapping /dev/mem above 4GB Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 51/70] s390/chsc: fix SEI usage on old FW levels Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 52/70] drm/i915: Don't check gmch state on inherited configs Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 53/70] drm/vmwgfx: Make sure user-space can't DMA across buffer object boundaries v2 Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 54/70] s390/bpf,jit: initialize A register if 1st insn is BPF_S_LDX_B_MSH Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 55/70] arm: KVM: fix possible misalignment of PGDs and bounce page Luis Henriques
2014-05-07 13:12 ` [PATCH 3.11 56/70] KVM: ARM: vgic: Fix sgi dispatch problem Luis Henriques
2014-05-07 13:13 ` [PATCH 3.11 57/70] ftrace/module: Hardcode ftrace_module_init() call into load_module() Luis Henriques
2014-05-07 13:13 ` [PATCH 3.11 58/70] [SCSI] mpt2sas: Don't disable device twice at suspend Luis Henriques
2014-05-07 13:13 ` [PATCH 3.11 59/70] [SCSI] virtio-scsi: Skip setting affinity on uninitialized vq Luis Henriques
2014-05-07 13:13 ` [PATCH 3.11 60/70] drivercore: deferral race condition fix Luis Henriques
2014-05-07 13:13 ` [PATCH 3.11 61/70] hrtimer: Prevent all reprogramming if hang detected Luis Henriques
2014-05-07 13:13 ` [PATCH 3.11 62/70] hrtimer: Prevent remote enqueue of leftmost timers Luis Henriques
2014-05-07 13:13 ` [PATCH 3.11 63/70] timer: Prevent overflow in apply_slack Luis Henriques
2014-05-07 13:13 ` [PATCH 3.11 64/70] ARC: Entry Handler tweaks: Optimize away redundant IRQ_DISABLE_SAVE Luis Henriques
2014-05-07 13:13 ` [PATCH 3.11 65/70] ARC: !PREEMPT: Ensure Return to kernel mode is IRQ safe Luis Henriques
2014-05-07 13:13 ` [PATCH 3.11 66/70] iser-target: Add missing se_cmd put for WRITE_PENDING in tx_comp_err Luis Henriques
2014-05-07 13:13 ` [PATCH 3.11 67/70] floppy: ignore kernel-only members in FDRAWCMD ioctl input Luis Henriques
2014-05-07 13:13 ` [PATCH 3.11 68/70] floppy: don't write kernel-only members to FDRAWCMD ioctl output Luis Henriques
2014-05-07 13:13 ` Luis Henriques [this message]
2014-05-07 13:13 ` [PATCH 3.11 70/70] KVM: s390: Optimize ucontrol path Luis Henriques
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=1399468393-10140-70-git-send-email-luis.henriques@canonical.com \
--to=luis.henriques@canonical.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.cz \
--cc=kernel-team@lists.ubuntu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peter@hurleysoftware.com \
--cc=stable@vger.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 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).