18 Sep, 2013

1 commit

  • Starting from v3.10 (probably commit f91e2590410b: "tty: Signal
    foreground group processes in hangup") disassociate_ctty() sends SIGCONT
    if tty && on_exit. This breaks LSB test-suite, in particular test8 in
    _exit.c and test40 in sigcon5.c.

    Put the "!on_exit" check back to restore the old behaviour.

    Review by Peter Hurley:
    "Yes, this regression was introduced by me in that commit. The effect
    of the regression is that ptys will receive a SIGCONT when, in similar
    circumstances, ttys would not.

    The fact that two test vectors accidentally tripped over this
    regression suggests that some other apps may as well.

    Thanks for catching this"

    Cc: stable@vger.kernel.org # v3.10+
    Signed-off-by: Oleg Nesterov
    Reported-by: Karel Srot
    Reviewed-by: Peter Hurley
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     

02 Aug, 2013

1 commit

  • Instrumented testing shows a tty can be hungup multiple times [1].
    Although concurrent hangups are properly serialized, multiple
    hangups for the same tty should be prevented.

    If tty has already been HUPPED, abort hangup. Note it is not
    necessary to cleanup file *redirect on subsequent hangups,
    as only TIOCCONS can set that value and ioctls are disabled
    after hangup.

    [1]
    Test performed by simulating a concurrent async hangup via
    tty_hangup() with a sync hangup via tty_vhangup(), while
    __tty_hangup() was instrumented with:

    diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
    index 26bb78c..fe8b061 100644
    --- a/drivers/tty/tty_io.c
    +++ b/drivers/tty/tty_io.c
    @@ -629,6 +629,8 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)

    tty_lock(tty);

    + WARN_ON(test_bit(TTY_HUPPED, &tty->flags));
    +
    /* some functions below drop BTM, so we need this bit */
    set_bit(TTY_HUPPING, &tty->flags);

    Test result:

    WARNING: at /home/peter/src/kernels/mainline/drivers/tty/tty_io.c:632 __tty_hangup+0x459/0x460()
    Modules linked in: ip6table_filter ip6_tables ebtable_nat
    CPU: 6 PID: 1197 Comm: kworker/6:2 Not tainted 3.10.0-0+rfcomm-xeon #0+rfcomm
    Hardware name: Dell Inc. Precision WorkStation T5400 /0RW203, BIOS A11 04/30/2012
    Workqueue: events do_tty_hangup
    0000000000000009 ffff8802b16d7d18 ffffffff816b553e ffff8802b16d7d58
    ffffffff810407e0 ffff880254f95c00 ffff880254f95c00 ffff8802bfd92b00
    ffff8802bfd96b00 ffff880254f95e40 0000000000000180 ffff8802b16d7d68
    Call Trace:
    [] dump_stack+0x19/0x1b
    [] warn_slowpath_common+0x70/0xa0
    [] warn_slowpath_null+0x1a/0x20
    [] __tty_hangup+0x459/0x460
    [] ? finish_task_switch+0xbc/0xe0
    [] do_tty_hangup+0x17/0x20
    [] process_one_work+0x16f/0x450
    [] process_scheduled_works+0x2c/0x40
    [] worker_thread+0x26a/0x380
    [] ? rescuer_thread+0x310/0x310
    [] kthread+0xc0/0xd0
    [] ? destroy_compound_page+0x65/0x92
    [] ? kthread_create_on_node+0x130/0x130
    [] ret_from_fork+0x7c/0xb0
    [] ? kthread_create_on_node+0x130/0x130
    ---[ end trace 98d9f01536cf411e ]---

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     

25 Jul, 2013

1 commit

  • Commits 6a1c0680cf3ba94356ecd58833e1540c93472a57 and
    9356b535fcb71db494fc434acceb79f56d15bda2, respectively
    'tty: Convert termios_mutex to termios_rwsem' and
    'n_tty: Access termios values safely'
    introduced a circular lock dependency with console_lock and
    termios_rwsem.

    The lockdep report [1] shows that n_tty_write() will attempt
    to claim console_lock while holding the termios_rwsem, whereas
    tty_do_resize() may already hold the console_lock while
    claiming the termios_rwsem.

    Since n_tty_write() and tty_do_resize() do not contend
    over the same data -- the tty->winsize structure -- correct
    the lock dependency by introducing a new lock which
    specifically serializes access to tty->winsize only.

    [1] Lockdep report

    ======================================================
    [ INFO: possible circular locking dependency detected ]
    3.10.0-0+tip-xeon+lockdep #0+tip Not tainted
    -------------------------------------------------------
    modprobe/277 is trying to acquire lock:
    (&tty->termios_rwsem){++++..}, at: [] tty_do_resize+0x36/0xe0

    but task is already holding lock:
    ((fb_notifier_list).rwsem){.+.+.+}, at: [] __blocking_notifier_call_chain+0x56/0xc0

    which lock already depends on the new lock.

    the existing dependency chain (in reverse order) is:

    -> #2 ((fb_notifier_list).rwsem){.+.+.+}:
    [] lock_acquire+0x92/0x1f0
    [] down_read+0x47/0x5c
    [] __blocking_notifier_call_chain+0x56/0xc0
    [] blocking_notifier_call_chain+0x16/0x20
    [] fb_notifier_call_chain+0x1b/0x20
    [] register_framebuffer+0x1e2/0x320
    [] drm_fb_helper_initial_config+0x371/0x540 [drm_kms_helper]
    [] nouveau_fbcon_init+0x105/0x140 [nouveau]
    [] nouveau_drm_load+0x43f/0x610 [nouveau]
    [] drm_get_pci_dev+0x17e/0x2a0 [drm]
    [] nouveau_drm_probe+0x25a/0x2a0 [nouveau]
    [] local_pci_probe+0x4b/0x80
    [] pci_device_probe+0x111/0x120
    [] driver_probe_device+0x8b/0x3a0
    [] __driver_attach+0xab/0xb0
    [] bus_for_each_dev+0x5d/0xa0
    [] driver_attach+0x1e/0x20
    [] bus_add_driver+0x111/0x290
    [] driver_register+0x77/0x170
    [] __pci_register_driver+0x64/0x70
    [] drm_pci_init+0x11a/0x130 [drm]
    [] nouveau_drm_init+0x4d/0x1000 [nouveau]
    [] do_one_initcall+0xea/0x1a0
    [] load_module+0x123b/0x1bf0
    [] SyS_init_module+0xd7/0x120
    [] system_call_fastpath+0x16/0x1b

    -> #1 (console_lock){+.+.+.}:
    [] lock_acquire+0x92/0x1f0
    [] console_lock+0x77/0x80
    [] con_flush_chars+0x31/0x50
    [] n_tty_write+0x1ec/0x4d0
    [] tty_write+0x159/0x2e0
    [] redirected_tty_write+0xb5/0xc0
    [] vfs_write+0xc5/0x1f0
    [] SyS_write+0x55/0xa0
    [] system_call_fastpath+0x16/0x1b

    -> #0 (&tty->termios_rwsem){++++..}:
    [] __lock_acquire+0x1c43/0x1d30
    [] lock_acquire+0x92/0x1f0
    [] down_write+0x44/0x70
    [] tty_do_resize+0x36/0xe0
    [] vc_do_resize+0x3e1/0x4c0
    [] vc_resize+0x1f/0x30
    [] fbcon_init+0x385/0x5a0
    [] visual_init+0xbc/0x120
    [] do_bind_con_driver+0x163/0x320
    [] do_take_over_console+0x61/0x70
    [] do_fbcon_takeover+0x63/0xc0
    [] fbcon_event_notify+0x715/0x820
    [] notifier_call_chain+0x5d/0x110
    [] __blocking_notifier_call_chain+0x6c/0xc0
    [] blocking_notifier_call_chain+0x16/0x20
    [] fb_notifier_call_chain+0x1b/0x20
    [] register_framebuffer+0x1e2/0x320
    [] drm_fb_helper_initial_config+0x371/0x540 [drm_kms_helper]
    [] nouveau_fbcon_init+0x105/0x140 [nouveau]
    [] nouveau_drm_load+0x43f/0x610 [nouveau]
    [] drm_get_pci_dev+0x17e/0x2a0 [drm]
    [] nouveau_drm_probe+0x25a/0x2a0 [nouveau]
    [] local_pci_probe+0x4b/0x80
    [] pci_device_probe+0x111/0x120
    [] driver_probe_device+0x8b/0x3a0
    [] __driver_attach+0xab/0xb0
    [] bus_for_each_dev+0x5d/0xa0
    [] driver_attach+0x1e/0x20
    [] bus_add_driver+0x111/0x290
    [] driver_register+0x77/0x170
    [] __pci_register_driver+0x64/0x70
    [] drm_pci_init+0x11a/0x130 [drm]
    [] nouveau_drm_init+0x4d/0x1000 [nouveau]
    [] do_one_initcall+0xea/0x1a0
    [] load_module+0x123b/0x1bf0
    [] SyS_init_module+0xd7/0x120
    [] system_call_fastpath+0x16/0x1b

    other info that might help us debug this:

    Chain exists of:
    &tty->termios_rwsem --> console_lock --> (fb_notifier_list).rwsem

    Possible unsafe locking scenario:

    CPU0 CPU1
    ---- ----
    lock((fb_notifier_list).rwsem);
    lock(console_lock);
    lock((fb_notifier_list).rwsem);
    lock(&tty->termios_rwsem);

    *** DEADLOCK ***

    7 locks held by modprobe/277:
    #0: (&__lockdep_no_validate__){......}, at: [] __driver_attach+0x5b/0xb0
    #1: (&__lockdep_no_validate__){......}, at: [] __driver_attach+0x69/0xb0
    #2: (drm_global_mutex){+.+.+.}, at: [] drm_get_pci_dev+0xbd/0x2a0 [drm]
    #3: (registration_lock){+.+.+.}, at: [] register_framebuffer+0x25/0x320
    #4: (&fb_info->lock){+.+.+.}, at: [] lock_fb_info+0x26/0x60
    #5: (console_lock){+.+.+.}, at: [] register_framebuffer+0x1d4/0x320
    #6: ((fb_notifier_list).rwsem){.+.+.+}, at: [] __blocking_notifier_call_chain+0x56/0xc0

    stack backtrace:
    CPU: 0 PID: 277 Comm: modprobe Not tainted 3.10.0-0+tip-xeon+lockdep #0+tip
    Hardware name: Dell Inc. Precision WorkStation T5400 /0RW203, BIOS A11 04/30/2012
    ffffffff8213e5e0 ffff8802aa2fb298 ffffffff81755f19 ffff8802aa2fb2e8
    ffffffff8174f506 ffff8802aa2fa000 ffff8802aa2fb378 ffff8802aa2ea8e8
    ffff8802aa2ea910 ffff8802aa2ea8e8 0000000000000006 0000000000000007
    Call Trace:
    [] dump_stack+0x19/0x1b
    [] print_circular_bug+0x1fb/0x20c
    [] __lock_acquire+0x1c43/0x1d30
    [] ? mark_held_locks+0xae/0x120
    [] ? trace_hardirqs_on_caller+0x105/0x1d0
    [] lock_acquire+0x92/0x1f0
    [] ? tty_do_resize+0x36/0xe0
    [] down_write+0x44/0x70
    [] ? tty_do_resize+0x36/0xe0
    [] tty_do_resize+0x36/0xe0
    [] vc_do_resize+0x3e1/0x4c0
    [] vc_resize+0x1f/0x30
    [] fbcon_init+0x385/0x5a0
    [] visual_init+0xbc/0x120
    [] do_bind_con_driver+0x163/0x320
    [] do_take_over_console+0x61/0x70
    [] do_fbcon_takeover+0x63/0xc0
    [] fbcon_event_notify+0x715/0x820
    [] notifier_call_chain+0x5d/0x110
    [] __blocking_notifier_call_chain+0x6c/0xc0
    [] blocking_notifier_call_chain+0x16/0x20
    [] fb_notifier_call_chain+0x1b/0x20
    [] register_framebuffer+0x1e2/0x320
    [] drm_fb_helper_initial_config+0x371/0x540 [drm_kms_helper]
    [] ? kmemleak_alloc+0x5b/0xc0
    [] ? kmem_cache_alloc_trace+0x104/0x290
    [] ? drm_fb_helper_single_add_all_connectors+0x81/0xf0 [drm_kms_helper]
    [] nouveau_fbcon_init+0x105/0x140 [nouveau]
    [] nouveau_drm_load+0x43f/0x610 [nouveau]
    [] drm_get_pci_dev+0x17e/0x2a0 [drm]
    [] nouveau_drm_probe+0x25a/0x2a0 [nouveau]
    [] ? _raw_spin_unlock_irqrestore+0x42/0x80
    [] local_pci_probe+0x4b/0x80
    [] pci_device_probe+0x111/0x120
    [] driver_probe_device+0x8b/0x3a0
    [] __driver_attach+0xab/0xb0
    [] ? driver_probe_device+0x3a0/0x3a0
    [] bus_for_each_dev+0x5d/0xa0
    [] driver_attach+0x1e/0x20
    [] bus_add_driver+0x111/0x290
    [] ? 0xffffffffa0229fff
    [] driver_register+0x77/0x170
    [] ? 0xffffffffa0229fff
    [] __pci_register_driver+0x64/0x70
    [] drm_pci_init+0x11a/0x130 [drm]
    [] ? 0xffffffffa0229fff
    [] ? 0xffffffffa0229fff
    [] nouveau_drm_init+0x4d/0x1000 [nouveau]
    [] do_one_initcall+0xea/0x1a0
    [] load_module+0x123b/0x1bf0
    [] ? ddebug_proc_open+0xb0/0xb0
    [] ? trace_hardirqs_on_thunk+0x3a/0x3f
    [] SyS_init_module+0xd7/0x120
    [] system_call_fastpath+0x16/0x1b

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     

24 Jul, 2013

5 commits

  • In canonical mode, an EOF which is not the first character of the line
    causes read() to complete and return the number of characters read so
    far (commonly referred to as EOF push). However, if the previous read()
    returned because the user buffer was full _and_ the next character
    is an EOF not at the beginning of the line, read() must not return 0,
    thus mistakenly indicating the end-of-file condition.

    The TTY_PUSH flag is used to indicate an EOF was received which is not
    at the beginning of the line. Because the EOF push condition is
    evaluated by a thread other than the read(), multiple EOF pushes can
    cause a premature end-of-file to be indicated.

    Instead, discover the 'EOF push as first read character' condition
    from the read() thread itself, and restart the i/o loop if detected.

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • No tty driver modifies termios during throttle() or unthrottle().
    Therefore, only read safety is required.

    However, tty_throttle_safe and tty_unthrottle_safe must still be
    mutually exclusive; introduce throttle_mutex for that purpose.

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • termios is commonly accessed unsafely (especially by N_TTY)
    because the existing mutex forces exclusive access.
    Convert existing usage.

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • Line discipline locking was performed with a combination of
    a mutex, a status bit, a count, and a waitqueue -- basically,
    a rw semaphore.

    Replace the existing combination with an ld_semaphore.

    Fixes:
    1) the 'reference acquire after ldisc locked' bug
    2) the over-complicated halt mechanism
    3) lock order wrt. tty_lock()
    4) dropping locks while changing ldisc
    5) previously unidentified deadlock while locking ldisc from
    both linked ttys concurrently
    6) previously unidentified recursive deadlocks

    Adds much-needed lockdep diagnostics.

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • The file scope spinlock identifier, tty_ldisc_lock, will collide
    with the file scope lock function tty_ldisc_lock() so rename it.

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     

18 Jun, 2013

2 commits

  • Commit 19ffd68f816878aed456d5e87697f43bd9e3bd2b
    ('pty: Remove redundant itty reset') introduced a regression
    whereby the other pty's linkage is not cleared on teardown.
    This triggers a false positive diagnostic in testing.

    Properly reset the itty linkage.

    Signed-off-by: Peter Hurley
    Cc: stable # 3.10
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • minimum_to_wake is unique to N_TTY processing, and belongs in
    per-ldisc data.

    Add the ldisc method, ldisc_ops::fasync(), to notify line disciplines
    when signal-driven I/O is enabled or disabled. When enabled for N_TTY
    (by fcntl(F_SETFL, O_ASYNC)), blocking reader/polls will be woken
    for any readable input. When disabled, blocking reader/polls are not
    woken until the read buffer is full.

    Canonical mode (L_ICANON(tty), n_tty_data::icanon) is not affected by
    the minimum_to_wake setting.

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     

01 May, 2013

1 commit

  • We first tried to avoid updating atime/mtime entirely (commit
    b0de59b5733d: "TTY: do not update atime/mtime on read/write"), and then
    limited it to only update it occasionally (commit 37b7f3c76595: "TTY:
    fix atime/mtime regression"), but it turns out that this was both
    insufficient and overkill.

    It was insufficient because we let people attach to the shared ptmx node
    to see activity without even reading atime/mtime, and it was overkill
    because the "only once a minute" means that you can't really tell an
    idle person from an active one with 'w'.

    So this tries to fix the problem properly. It marks the shared ptmx
    node as un-notifiable, and it lowers the "only once a minute" to a few
    seconds instead - still long enough that you can't time individual
    keystrokes, but short enough that you can tell whether somebody is
    active or not.

    Reported-by: Simon Kirby
    Acked-by: Jiri Slaby
    Cc: Greg Kroah-Hartman
    Cc: stable@vger.kernel.org
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

30 Apr, 2013

1 commit

  • Pull tty/serial driver update from Greg Kroah-Hartman:
    "Here's the big tty/serial driver merge request for 3.10-rc1

    Once again, Jiri has a number of TTY driver fixes and cleanups, and
    Peter Hurley came through with a bunch of ldisc fixes that resolve a
    number of reported issues. There are some other serial driver
    cleanups as well.

    All of these have been in the linux-next tree for a while"

    * tag 'tty-3.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (117 commits)
    tty/serial/sirf: fix MODULE_DEVICE_TABLE
    serial: mxs: drop superfluous {get|put}_device
    serial: mxs: fix buffer overflow
    ARM: PL011: add support for extended FIFO-size of PL011-r1p5
    serial_core.c: add put_device() after device_find_child()
    tty: Fix unsafe bit ops in tty_throttle_safe/unthrottle_safe
    serial: sccnxp: Replace pdata.init/exit with regulator API
    serial: sccnxp: Do not override device name
    TTY: pty, fix compilation warning
    TTY: rocket, fix compilation warning
    TTY: ircomm: fix DTR being raised on hang up
    TTY: synclinkmp: fix DTR being raised on hang up
    TTY: synclink_gt: fix DTR being raised on hang up
    TTY: synclink: fix DTR being raised on hang up
    serial: 8250_dw: Fix the stub for dw8250_probe_acpi()
    serial: 8250_dw: Convert to devm_ioremap()
    serial: 8250_dw: Set port capabilities based on CPR register
    serial: 8250_dw: Let ACPI code extract the DMA client info
    serial: 8250_dw: Support clk framework also with ACPI
    serial: 8250_dw: Enable runtime PM
    ...

    Linus Torvalds
     

26 Apr, 2013

1 commit

  • In commit b0de59b5733d ("TTY: do not update atime/mtime on read/write")
    we removed timestamps from tty inodes to fix a security issue and waited
    if something breaks. Well, 'w', the utility to find out logged users
    and their inactivity time broke. It shows that users are inactive since
    the time they logged in.

    To revert to the old behaviour while still preventing attackers to
    guess the password length, we update the timestamps in one-minute
    intervals by this patch.

    Signed-off-by: Jiri Slaby
    Cc: Greg Kroah-Hartman
    Signed-off-by: Linus Torvalds

    Jiri Slaby
     

26 Mar, 2013

1 commit


19 Mar, 2013

5 commits

  • test_bit() is already atomic; drop mutex lock/unlock.

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • Expected typical log output:
    [ 2.437211] tty_open: opening pts1...
    [ 2.443376] tty_open: opening pts5...
    [ 2.447830] tty_release: ptm0 (tty count=1)...
    [ 2.447849] pts0 vhangup...
    [ 2.447865] tty_release: ptm0: final close
    [ 2.447876] tty_release: ptm0: freeing structure...
    [ 2.451634] tty_release: tty1 (tty count=1)...
    [ 2.451638] tty_release: tty1: final close
    [ 2.451654] tty_release: tty1: freeing structure...
    [ 2.452505] tty_release: pts5 (tty count=2)...
    [ 2.453029] tty_open: opening pts0...

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • The tty core relies on the ldisc layer for synchronizing destruction
    of the tty. Instead, the final tty release must wait for any pending tty
    work to complete prior to tty destruction.

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • Waiting for buffer work to complete is not required for safely
    performing changes to the line discipline, once the line discipline
    is halted. The buffer work routine, flush_to_ldisc(), will be
    unable to acquire an ldisc ref and all existing references were
    waited until released (so it can't already have one).

    Ensure running buffer work which may reference the soon-to-be-gone
    tty completes and any buffer work running after this point retrieves
    a NULL tty.

    Also, ensure all buffer work is cancelled on port destruction.

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • tty_ldisc_hangup() guarantees the ldisc is enabled (or that there
    is no ldisc). Since __tty_hangup() was the only user, re-define
    tty_ldisc_enable() in file-scope.

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     

16 Mar, 2013

5 commits

  • An exiting session leader can hang if a foreground process is
    blocking for line discipline i/o, eg. in n_tty_read(). This happens
    because the blocking reader is holding an ldisc reference (indicating
    the line discipline is in-use) which prevents __tty_hangup() from
    recycling the line discipline. Although waiters are woken before
    attempting to gain exclusive access for changing the ldisc, the
    blocking reader in this case will not exit the i/o loop since it
    has not yet received SIGHUP (because it has not been sent).

    Instead, perform signalling first, then recycle the line discipline.

    Fixes:

    INFO: task init:1 blocked for more than 120 seconds.
    "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
    init D 00000000001d7180 2688 1 0 0x00000002
    ffff8800b9acfba8 0000000000000002 00000000001d7180 ffff8800b9b10048
    ffff8800b94cb000 ffff8800b9b10000 00000000001d7180 00000000001d7180
    ffff8800b9b10000 ffff8800b9acffd8 00000000001d7180 00000000001d7180
    Call Trace:
    [] __schedule+0x2e9/0x3b0
    [] schedule+0x55/0x60
    [] schedule_timeout+0x3a/0x370
    [] ? mark_held_locks+0xf9/0x130
    [] ? down_failed+0x108/0x200
    [] ? _raw_spin_unlock_irq+0x2b/0x80
    [] ? trace_hardirqs_on_caller+0x128/0x160
    [] down_failed+0x131/0x200
    [] ? tty_ldisc_lock_pair_timeout+0xcd/0x120
    [] ldsem_down_write+0xd3/0x113
    [] ? tty_ldisc_lock_pair_timeout+0xcd/0x120
    [] ? trace_hardirqs_on+0xd/0x10
    [] tty_ldisc_lock_pair_timeout+0xcd/0x120
    [] tty_ldisc_hangup+0xd0/0x220
    [] __tty_hangup+0x137/0x4f0
    [] disassociate_ctty+0x6c/0x230
    [] do_exit+0x41c/0x590
    [] ? syscall_trace_enter+0x24/0x2e0
    [] do_group_exit+0x8a/0xc0
    [] sys_exit_group+0x12/0x20
    [] tracesys+0xe1/0xe6
    1 lock held by init/1:
    #0: (&tty->ldisc_sem){++++++}, at: [] tty_ldisc_lock_pair_timeout+0xcd/0x120

    Reported-by: Sasha Levin
    Signed-off-by: Peter Hurley
    Acked-by: Jiri Slaby
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • When the session leader is exiting, signal the foreground group
    processes as part of the hangup sequence, instead of after the
    hangup is complete. This prepares for hanging up the
    line discipline _after_ signalling processes which
    may be blocking on ldisc i/o.

    Parameterize __tty_hangup() to distinguish between when the
    session leader is exiting and all other hangups; signal the
    foreground group after signalling the session leader and its
    process group, which preserves the original signal order.

    Signed-off-by: Peter Hurley
    Acked-by: Jiri Slaby
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • The interrupt state does not need to be saved, disabled and
    restored here; interrupts are already off because this lock
    is bracketed by spin_lock_irq/spin_unlock_irq.

    Signed-off-by: Peter Hurley
    Acked-by: Jiri Slaby
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • __tty_hangup() and tty_vhangup() cannot be called from atomic context,
    so locks do not need to preserve the interrupt state (although,
    still disable interrupts).

    Signed-off-by: Peter Hurley
    Acked-by: Jiri Slaby
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     
  • Reduce complexity of __tty_hangup(); separate SIGHUP signalling
    into tty_signal_session_leader().

    Signed-off-by: Peter Hurley
    Acked-by: Jiri Slaby
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     

28 Feb, 2013

1 commit


22 Feb, 2013

2 commits

  • Pull s390 update from Martin Schwidefsky:
    "The most prominent change in this patch set is the software dirty bit
    patch for s390. It removes __HAVE_ARCH_PAGE_TEST_AND_CLEAR_DIRTY and
    the page_test_and_clear_dirty primitive which makes the common memory
    management code a bit less obscure.

    Heiko fixed most of the PCI related fallout, more often than not
    missing GENERIC_HARDIRQS dependencies. Notable is one of the 3270
    patches which adds an export to tty_io to be able to resize a tty.

    The rest is the usual bunch of cleanups and bug fixes."

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: (42 commits)
    s390/module: Add missing R_390_NONE relocation type
    drivers/gpio: add missing GENERIC_HARDIRQ dependency
    drivers/input: add couple of missing GENERIC_HARDIRQS dependencies
    s390/cleanup: rename SPP to LPP
    s390/mm: implement software dirty bits
    s390/mm: Fix crst upgrade of mmap with MAP_FIXED
    s390/linker skript: discard exit.data at runtime
    drivers/media: add missing GENERIC_HARDIRQS dependency
    s390/bpf,jit: add vlan tag support
    drivers/net,AT91RM9200: add missing GENERIC_HARDIRQS dependency
    iucv: fix kernel panic at reboot
    s390/Kconfig: sort list of arch selected config options
    phylib: remove !S390 dependeny from Kconfig
    uio: remove !S390 dependency from Kconfig
    dasd: fix sysfs cleanup in dasd_generic_remove
    s390/pci: fix hotplug module init
    s390/pci: cleanup clp page allocation
    s390/pci: cleanup clp inline assembly
    s390/perf: cpum_cf: fallback to software sampling events
    s390/mm: provide PAGE_SHARED define
    ...

    Linus Torvalds
     
  • Pull tty/serial patches from Greg Kroah-Hartman:
    "Here's the big tty/serial driver patches for 3.9-rc1.

    More tty port rework and fixes from Jiri here, as well as lots of
    individual serial driver updates and fixes.

    All of these have been in the linux-next tree for a while."

    * tag 'tty-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (140 commits)
    tty: mxser: improve error handling in mxser_probe() and mxser_module_init()
    serial: imx: fix uninitialized variable warning
    serial: tegra: assume CONFIG_OF
    TTY: do not update atime/mtime on read/write
    lguest: select CONFIG_TTY to build properly.
    ARM defconfigs: add missing inclusions of linux/platform_device.h
    fb/exynos: include platform_device.h
    ARM: sa1100/assabet: include platform_device.h directly
    serial: imx: Fix recursive locking bug
    pps: Fix build breakage from decoupling pps from tty
    tty: Remove ancient hardpps()
    pps: Additional cleanups in uart_handle_dcd_change
    pps: Move timestamp read into PPS code proper
    pps: Don't crash the machine when exiting will do
    pps: Fix a use-after free bug when unregistering a source.
    pps: Use pps_lookup_dev to reduce ldisc coupling
    pps: Add pps_lookup_dev() function
    tty: serial: uartlite: Support uartlite on big and little endian systems
    tty: serial: uartlite: Fix sparse and checkpatch warnings
    serial/arc-uart: Miscll DT related updates (Grant's review comments)
    ...

    Fix up trivial conflicts, mostly just due to the TTY config option
    clashing with the EXPERIMENTAL removal.

    Linus Torvalds
     

16 Feb, 2013

1 commit

  • On http://vladz.devzero.fr/013_ptmx-timing.php, we can see how to find
    out length of a password using timestamps of /dev/ptmx. It is
    documented in "Timing Analysis of Keystrokes and Timing Attacks on
    SSH". To avoid that problem, do not update time when reading
    from/writing to a TTY.

    I am afraid of regressions as this is a behavior we have since 0.97
    and apps may expect the time to be current, e.g. for monitoring
    whether there was a change on the TTY. Now, there is no change. So
    this would better have a lot of testing before it goes upstream.

    References: CVE-2013-0160

    Signed-off-by: Jiri Slaby
    Cc: stable # after 3.9 is out
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     

14 Feb, 2013

1 commit

  • Convert the synchronous size sense code to an interrupt driven
    approach. This allows to set the device online even if the
    terminal is not connected. With the new code views can be
    registered without a connected terminal, the tty can be opened
    as soon as the device is online. After the terminal has been
    connected and the size has been determined the tty is resized
    to match the device characteristics..

    Signed-off-by: Martin Schwidefsky

    Martin Schwidefsky
     

07 Feb, 2013

1 commit


16 Jan, 2013

1 commit


22 Nov, 2012

1 commit


26 Oct, 2012

1 commit

  • For checkpoint/restore we need to know if tty has
    exclusive or packet mode set, as well as if pty
    is currently locked. Just to be able to restore
    this characteristics.

    For this sake the following ioctl codes are introduced

    - TIOCGPKT to get packet mode state
    - TIOCGPTLCK to get Pty locked state
    - TIOCGEXCL to get Exclusive mode state

    Note this ioctls are a bit unsafe in terms of data
    obtained consistency. The tty characteristics might
    be changed right after ioctl complete. Keep it in
    mind and use this ioctl carefully.

    v2:
    - Use TIOC prefix for ioctl codes (by jslaby@)

    Signed-off-by: Cyrill Gorcunov
    CC: Alan Cox
    CC: "H. Peter Anvin"
    CC: Pavel Emelyanov
    CC: Jiri Slaby
    Signed-off-by: Greg Kroah-Hartman

    Cyrill Gorcunov
     

23 Oct, 2012

5 commits

  • So this is it. The big step why we did all the work over the past
    kernel releases. Now everything is prepared, so nothing protects us
    from doing that big step.

    | | \ \ nnnn/^l | |
    | | \ / / | |
    | '-,.__ => \/ ,-` => | '-,.__
    | O __.´´) ( .` | O __.´´)
    ~~~ ~~ `` ~~~ ~~
    The buffers are now in the tty_port structure and we can start
    teaching the buffer helpers (insert char/string, flip etc.) to use
    tty_port instead of tty_struct all around.

    Signed-off-by: Jiri Slaby
    Acked-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     
  • For that purpose we have to temporarily introduce a second tty back
    pointer into tty_port. It is because serial layer, and maybe others,
    still do not use tty_port_tty_set/get. So that we cannot set the
    tty_port->tty to NULL at will now.

    Yes, the fix would be to convert whole serial layer and all its users
    to tty_port_tty_set/get. However we are in the process of removing the
    need of tty in most of the call sites, so this would lead to a
    duplicated work.

    Instead we have now tty_port->itty (internal tty) which will be used
    only in flush_to_ldisc. For that one it is ensured that itty is valid
    wherever the work is run. IOW, the work is synchronously cancelled
    before we set itty to NULL and also before hangup is processed.

    After we need only tty_port and not tty_struct in most code, this
    shall be changed to tty_port_tty_set/get and itty removed completely.

    Signed-off-by: Jiri Slaby
    Acked-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     
  • atomic_write_lock is not n_tty specific, so move it up in the
    tty_struct.

    And since these are the last ones to move, remove also the comment
    saying there are some ldisc' members. There are none now.

    Signed-off-by: Jiri Slaby
    Acked-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     
  • Here we start moving all the n_tty related bits from tty_struct to
    the newly defined n_tty_data struct in n_tty proper.

    In this patch primitive members and bits are moved. The rest will be
    done per-partes in the next patches.

    Signed-off-by: Jiri Slaby
    Acked-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     
  • Now that we have control over tty->driver_data in pty, we can just
    kill the /dev/pts/ in pty code too. Namely, in ->shutdown hook of
    tty. For pty, this is called only once, for whichever end is closed
    last. But we don't care, both driver_data are the inode as it used to
    be till now.

    Signed-off-by: Jiri Slaby
    Acked-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     

03 Oct, 2012

1 commit

  • Pull vfs update from Al Viro:

    - big one - consolidation of descriptor-related logics; almost all of
    that is moved to fs/file.c

    (BTW, I'm seriously tempted to rename the result to fd.c. As it is,
    we have a situation when file_table.c is about handling of struct
    file and file.c is about handling of descriptor tables; the reasons
    are historical - file_table.c used to be about a static array of
    struct file we used to have way back).

    A lot of stray ends got cleaned up and converted to saner primitives,
    disgusting mess in android/binder.c is still disgusting, but at least
    doesn't poke so much in descriptor table guts anymore. A bunch of
    relatively minor races got fixed in process, plus an ext4 struct file
    leak.

    - related thing - fget_light() partially unuglified; see fdget() in
    there (and yes, it generates the code as good as we used to have).

    - also related - bits of Cyrill's procfs stuff that got entangled into
    that work; _not_ all of it, just the initial move to fs/proc/fd.c and
    switch of fdinfo to seq_file.

    - Alex's fs/coredump.c spiltoff - the same story, had been easier to
    take that commit than mess with conflicts. The rest is a separate
    pile, this was just a mechanical code movement.

    - a few misc patches all over the place. Not all for this cycle,
    there'll be more (and quite a few currently sit in akpm's tree)."

    Fix up trivial conflicts in the android binder driver, and some fairly
    simple conflicts due to two different changes to the sock_alloc_file()
    interface ("take descriptor handling from sock_alloc_file() to callers"
    vs "net: Providing protocol type via system.sockprotoname xattr of
    /proc/PID/fd entries" adding a dentry name to the socket)

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (72 commits)
    MAX_LFS_FILESIZE should be a loff_t
    compat: fs: Generic compat_sys_sendfile implementation
    fs: push rcu_barrier() from deactivate_locked_super() to filesystems
    btrfs: reada_extent doesn't need kref for refcount
    coredump: move core dump functionality into its own file
    coredump: prevent double-free on an error path in core dumper
    usb/gadget: fix misannotations
    fcntl: fix misannotations
    ceph: don't abuse d_delete() on failure exits
    hypfs: ->d_parent is never NULL or negative
    vfs: delete surplus inode NULL check
    switch simple cases of fget_light to fdget
    new helpers: fdget()/fdput()
    switch o2hb_region_dev_write() to fget_light()
    proc_map_files_readdir(): don't bother with grabbing files
    make get_file() return its argument
    vhost_set_vring(): turn pollstart/pollstop into bool
    switch prctl_set_mm_exe_file() to fget_light()
    switch xfs_find_handle() to fget_light()
    switch xfs_swapext() to fget_light()
    ...

    Linus Torvalds
     

27 Sep, 2012

1 commit