1. 30 1月, 2019 1 次提交
  2. 22 1月, 2019 1 次提交
  3. 12 1月, 2019 1 次提交
  4. 05 12月, 2018 3 次提交
    • D
      tty: Simplify tty->count math in tty_reopen() · cf62a1a1
      Dmitry Safonov 提交于
      As notted by Jiri, tty_ldisc_reinit() shouldn't rely on tty counter.
      Simplify math by increasing the counter after reinit success.
      
      Cc: Jiri Slaby <jslaby@suse.com>
      Link: lkml.kernel.org/r/<20180829022353.23568-2-dima@arista.com>
      Suggested-by: NJiri Slaby <jslaby@suse.com>
      Reviewed-by: NJiri Slaby <jslaby@suse.cz>
      Tested-by: NMark Rutland <mark.rutland@arm.com>
      Signed-off-by: NDmitry Safonov <dima@arista.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cf62a1a1
    • D
      tty: Hold tty_ldisc_lock() during tty_reopen() · 83d817f4
      Dmitry Safonov 提交于
      tty_ldisc_reinit() doesn't race with neither tty_ldisc_hangup()
      nor set_ldisc() nor tty_ldisc_release() as they use tty lock.
      But it races with anyone who expects line discipline to be the same
      after hoding read semaphore in tty_ldisc_ref().
      
      We've seen the following crash on v4.9.108 stable:
      
      BUG: unable to handle kernel paging request at 0000000000002260
      IP: [..] n_tty_receive_buf_common+0x5f/0x86d
      Workqueue: events_unbound flush_to_ldisc
      Call Trace:
       [..] n_tty_receive_buf2
       [..] tty_ldisc_receive_buf
       [..] flush_to_ldisc
       [..] process_one_work
       [..] worker_thread
       [..] kthread
       [..] ret_from_fork
      
      tty_ldisc_reinit() should be called with ldisc_sem hold for writing,
      which will protect any reader against line discipline changes.
      
      Cc: Jiri Slaby <jslaby@suse.com>
      Cc: stable@vger.kernel.org # b027e229 ("tty: fix data race between tty_init_dev and flush of buf")
      Reviewed-by: NJiri Slaby <jslaby@suse.cz>
      Reported-by: syzbot+3aa9784721dfb90e984d@syzkaller.appspotmail.com
      Tested-by: NMark Rutland <mark.rutland@arm.com>
      Tested-by: NTetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
      Signed-off-by: NDmitry Safonov <dima@arista.com>
      Tested-by: NTycho Andersen <tycho@tycho.ws>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      83d817f4
    • J
      USB: serial: console: fix reported terminal settings · f51ccf46
      Johan Hovold 提交于
      The USB-serial console implementation has never reported the actual
      terminal settings used. Despite storing the corresponding cflags in its
      struct console, these were never honoured on later tty open() where the
      tty termios would be left initialised to the driver defaults.
      
      Unlike the serial console implementation, the USB-serial code calls
      subdriver open() already at console setup. While calling set_termios()
      and write() before open() looks like it could work for some USB-serial
      drivers, others definitely do not expect this, so modelling this after
      serial core is going to be intrusive, if at all possible.
      
      Instead, use a (renamed) tty helper to save the termios data used at
      console setup so that the tty termios reflects the actual terminal
      settings after a subsequent tty open().
      
      Note that the calls to tty_init_termios() (tty_driver_install()) and
      tty_save_termios() are serialised using the disconnect mutex.
      
      This specifically fixes a regression that was triggered by a recent
      change adding software flow control to the pl2303 driver: a getty trying
      to disable flow control while leaving the baud rate unchanged would now
      also set the baud rate to the driver default (prior to the flow-control
      change this had been a noop).
      
      Fixes: 7041d9c3 ("USB: serial: pl2303: add support for tx xon/xoff flow control")
      Cc: stable <stable@vger.kernel.org>	# 4.18
      Cc: Florian Zumbiehl <florz@florz.de>
      Reported-by: NJarkko Nikula <jarkko.nikula@linux.intel.com>
      Tested-by: NJarkko Nikula <jarkko.nikula@linux.intel.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NJohan Hovold <johan@kernel.org>
      f51ccf46
  5. 13 10月, 2018 4 次提交
  6. 12 10月, 2018 1 次提交
    • M
      tty: check name length in tty_find_polling_driver() · 33a1a7be
      Miles Chen 提交于
      The issue is found by a fuzzing test.
      If tty_find_polling_driver() recevies an incorrect input such as
      ',,' or '0b', the len becomes 0 and strncmp() always return 0.
      In this case, a null p->ops->poll_init() is called and it causes a kernel
      panic.
      
      Fix this by checking name length against zero in tty_find_polling_driver().
      
      $echo ,, > /sys/module/kgdboc/parameters/kgdboc
      [   20.804451] WARNING: CPU: 1 PID: 104 at drivers/tty/serial/serial_core.c:457
      uart_get_baud_rate+0xe8/0x190
      [   20.804917] Modules linked in:
      [   20.805317] CPU: 1 PID: 104 Comm: sh Not tainted 4.19.0-rc7ajb #8
      [   20.805469] Hardware name: linux,dummy-virt (DT)
      [   20.805732] pstate: 20000005 (nzCv daif -PAN -UAO)
      [   20.805895] pc : uart_get_baud_rate+0xe8/0x190
      [   20.806042] lr : uart_get_baud_rate+0xc0/0x190
      [   20.806476] sp : ffffffc06acff940
      [   20.806676] x29: ffffffc06acff940 x28: 0000000000002580
      [   20.806977] x27: 0000000000009600 x26: 0000000000009600
      [   20.807231] x25: ffffffc06acffad0 x24: 00000000ffffeff0
      [   20.807576] x23: 0000000000000001 x22: 0000000000000000
      [   20.807807] x21: 0000000000000001 x20: 0000000000000000
      [   20.808049] x19: ffffffc06acffac8 x18: 0000000000000000
      [   20.808277] x17: 0000000000000000 x16: 0000000000000000
      [   20.808520] x15: ffffffffffffffff x14: ffffffff00000000
      [   20.808757] x13: ffffffffffffffff x12: 0000000000000001
      [   20.809011] x11: 0101010101010101 x10: ffffff880d59ff5f
      [   20.809292] x9 : ffffff880d59ff5e x8 : ffffffc06acffaf3
      [   20.809549] x7 : 0000000000000000 x6 : ffffff880d59ff5f
      [   20.809803] x5 : 0000000080008001 x4 : 0000000000000003
      [   20.810056] x3 : ffffff900853e6b4 x2 : dfffff9000000000
      [   20.810693] x1 : ffffffc06acffad0 x0 : 0000000000000cb0
      [   20.811005] Call trace:
      [   20.811214]  uart_get_baud_rate+0xe8/0x190
      [   20.811479]  serial8250_do_set_termios+0xe0/0x6f4
      [   20.811719]  serial8250_set_termios+0x48/0x54
      [   20.811928]  uart_set_options+0x138/0x1bc
      [   20.812129]  uart_poll_init+0x114/0x16c
      [   20.812330]  tty_find_polling_driver+0x158/0x200
      [   20.812545]  configure_kgdboc+0xbc/0x1bc
      [   20.812745]  param_set_kgdboc_var+0xb8/0x150
      [   20.812960]  param_attr_store+0xbc/0x150
      [   20.813160]  module_attr_store+0x40/0x58
      [   20.813364]  sysfs_kf_write+0x8c/0xa8
      [   20.813563]  kernfs_fop_write+0x154/0x290
      [   20.813764]  vfs_write+0xf0/0x278
      [   20.813951]  __arm64_sys_write+0x84/0xf4
      [   20.814400]  el0_svc_common+0xf4/0x1dc
      [   20.814616]  el0_svc_handler+0x98/0xbc
      [   20.814804]  el0_svc+0x8/0xc
      [   20.822005] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
      [   20.826913] Mem abort info:
      [   20.827103]   ESR = 0x84000006
      [   20.827352]   Exception class = IABT (current EL), IL = 16 bits
      [   20.827655]   SET = 0, FnV = 0
      [   20.827855]   EA = 0, S1PTW = 0
      [   20.828135] user pgtable: 4k pages, 39-bit VAs, pgdp = (____ptrval____)
      [   20.828484] [0000000000000000] pgd=00000000aadee003, pud=00000000aadee003, pmd=0000000000000000
      [   20.829195] Internal error: Oops: 84000006 [#1] SMP
      [   20.829564] Modules linked in:
      [   20.829890] CPU: 1 PID: 104 Comm: sh Tainted: G        W         4.19.0-rc7ajb #8
      [   20.830545] Hardware name: linux,dummy-virt (DT)
      [   20.830829] pstate: 60000085 (nZCv daIf -PAN -UAO)
      [   20.831174] pc :           (null)
      [   20.831457] lr : serial8250_do_set_termios+0x358/0x6f4
      [   20.831727] sp : ffffffc06acff9b0
      [   20.831936] x29: ffffffc06acff9b0 x28: ffffff9008d7c000
      [   20.832267] x27: ffffff900969e16f x26: 0000000000000000
      [   20.832589] x25: ffffff900969dfb0 x24: 0000000000000000
      [   20.832906] x23: ffffffc06acffad0 x22: ffffff900969e160
      [   20.833232] x21: 0000000000000000 x20: ffffffc06acffac8
      [   20.833559] x19: ffffff900969df90 x18: 0000000000000000
      [   20.833878] x17: 0000000000000000 x16: 0000000000000000
      [   20.834491] x15: ffffffffffffffff x14: ffffffff00000000
      [   20.834821] x13: ffffffffffffffff x12: 0000000000000001
      [   20.835143] x11: 0101010101010101 x10: ffffff880d59ff5f
      [   20.835467] x9 : ffffff880d59ff5e x8 : ffffffc06acffaf3
      [   20.835790] x7 : 0000000000000000 x6 : ffffff880d59ff5f
      [   20.836111] x5 : c06419717c314100 x4 : 0000000000000007
      [   20.836419] x3 : 0000000000000000 x2 : 0000000000000000
      [   20.836732] x1 : 0000000000000001 x0 : ffffff900969df90
      [   20.837100] Process sh (pid: 104, stack limit = 0x(____ptrval____))
      [   20.837396] Call trace:
      [   20.837566]            (null)
      [   20.837816]  serial8250_set_termios+0x48/0x54
      [   20.838089]  uart_set_options+0x138/0x1bc
      [   20.838570]  uart_poll_init+0x114/0x16c
      [   20.838834]  tty_find_polling_driver+0x158/0x200
      [   20.839119]  configure_kgdboc+0xbc/0x1bc
      [   20.839380]  param_set_kgdboc_var+0xb8/0x150
      [   20.839658]  param_attr_store+0xbc/0x150
      [   20.839920]  module_attr_store+0x40/0x58
      [   20.840183]  sysfs_kf_write+0x8c/0xa8
      [   20.840183]  sysfs_kf_write+0x8c/0xa8
      [   20.840440]  kernfs_fop_write+0x154/0x290
      [   20.840702]  vfs_write+0xf0/0x278
      [   20.840942]  __arm64_sys_write+0x84/0xf4
      [   20.841209]  el0_svc_common+0xf4/0x1dc
      [   20.841471]  el0_svc_handler+0x98/0xbc
      [   20.841713]  el0_svc+0x8/0xc
      [   20.842057] Code: bad PC value
      [   20.842764] ---[ end trace a8835d7de79aaadf ]---
      [   20.843134] Kernel panic - not syncing: Fatal exception
      [   20.843515] SMP: stopping secondary CPUs
      [   20.844289] Kernel Offset: disabled
      [   20.844634] CPU features: 0x0,21806002
      [   20.844857] Memory Limit: none
      [   20.845172] ---[ end Kernel panic - not syncing: Fatal exception ]---
      Signed-off-by: NMiles Chen <miles.chen@mediatek.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      33a1a7be
  7. 18 9月, 2018 1 次提交
  8. 16 9月, 2018 1 次提交
    • E
      tty_io: Use group_send_sig_info in __do_SACK to note it is a session being killed · a8ebd171
      Eric W. Biederman 提交于
      Replace send_sig and force_sig in __do_SAK with group_send_sig_info
      the general helper for sending a signal to a process group.  This is
      wordier but it allows specifying PIDTYPE_SID so that the signal code
      knows the signal went to a session.
      
      Both force_sig() and send_sig(..., 1) specify SEND_SIG_PRIV and the
      new call of group_send_sig_info does that explicitly.  This is enough
      to ensure even a pid namespace init is killed.
      
      The global init remains unkillable.  The guarantee that __do_SAK tries
      to provide is a clean path to login to a machine.  As the global init is
      unkillable, if it chooses to hold open a tty it can violate this
      guarantee.  A technique other than killing processes would be needed
      to provide this guarantee to userspace.
      
      The only difference between force_sig and send_sig when sending
      SIGKILL is that SIGNAL_UNKILLABLE is cleared.  This has no affect on
      the processing of a signal sent with SEND_SIG_PRIV by any process, making
      it unnecessary, and not behavior that needs to be preserved.
      
      force_sig was used originally because it did not take as many locks as
      send_sig.  Today send_sig, force_sig and group_send_sig_info take the
      same locks when delivering a signal.
      
      group_send_sig_info also contains a permission check that force_sig
      and send_sig do not.  However the presence of SEND_SIG_PRIV makes the
      permission check a noop.  So the permission check does not result
      in any behavioral differences.
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      a8ebd171
  9. 14 9月, 2018 3 次提交
  10. 21 7月, 2018 1 次提交
    • E
      signal: Use PIDTYPE_TGID to clearly store where file signals will be sent · 01919134
      Eric W. Biederman 提交于
      When f_setown is called a pid and a pid type are stored.  Replace the use
      of PIDTYPE_PID with PIDTYPE_TGID as PIDTYPE_TGID goes to the entire thread
      group.  Replace the use of PIDTYPE_MAX with PIDTYPE_PID as PIDTYPE_PID now
      is only for a thread.
      
      Update the users of __f_setown to use PIDTYPE_TGID instead of
      PIDTYPE_PID.
      
      For now the code continues to capture task_pid (when task_tgid would
      really be appropriate), and iterate on PIDTYPE_PID (even when type ==
      PIDTYPE_TGID) out of an abundance of caution to preserve existing
      behavior.
      
      Oleg Nesterov suggested using the test to ensure we use PIDTYPE_PID
      for tgid lookup also be used to avoid taking the tasklist lock.
      Suggested-by: NOleg Nesterov <oleg@redhat.com>
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      01919134
  11. 28 6月, 2018 1 次提交
  12. 06 6月, 2018 1 次提交
    • D
      vfs: change inode times to use struct timespec64 · 95582b00
      Deepa Dinamani 提交于
      struct timespec is not y2038 safe. Transition vfs to use
      y2038 safe struct timespec64 instead.
      
      The change was made with the help of the following cocinelle
      script. This catches about 80% of the changes.
      All the header file and logic changes are included in the
      first 5 rules. The rest are trivial substitutions.
      I avoid changing any of the function signatures or any other
      filesystem specific data structures to keep the patch simple
      for review.
      
      The script can be a little shorter by combining different cases.
      But, this version was sufficient for my usecase.
      
      virtual patch
      
      @ depends on patch @
      identifier now;
      @@
      - struct timespec
      + struct timespec64
        current_time ( ... )
        {
      - struct timespec now = current_kernel_time();
      + struct timespec64 now = current_kernel_time64();
        ...
      - return timespec_trunc(
      + return timespec64_trunc(
        ... );
        }
      
      @ depends on patch @
      identifier xtime;
      @@
       struct \( iattr \| inode \| kstat \) {
       ...
      -       struct timespec xtime;
      +       struct timespec64 xtime;
       ...
       }
      
      @ depends on patch @
      identifier t;
      @@
       struct inode_operations {
       ...
      int (*update_time) (...,
      -       struct timespec t,
      +       struct timespec64 t,
      ...);
       ...
       }
      
      @ depends on patch @
      identifier t;
      identifier fn_update_time =~ "update_time$";
      @@
       fn_update_time (...,
      - struct timespec *t,
      + struct timespec64 *t,
       ...) { ... }
      
      @ depends on patch @
      identifier t;
      @@
      lease_get_mtime( ... ,
      - struct timespec *t
      + struct timespec64 *t
        ) { ... }
      
      @te depends on patch forall@
      identifier ts;
      local idexpression struct inode *inode_node;
      identifier i_xtime =~ "^i_[acm]time$";
      identifier ia_xtime =~ "^ia_[acm]time$";
      identifier fn_update_time =~ "update_time$";
      identifier fn;
      expression e, E3;
      local idexpression struct inode *node1;
      local idexpression struct inode *node2;
      local idexpression struct iattr *attr1;
      local idexpression struct iattr *attr2;
      local idexpression struct iattr attr;
      identifier i_xtime1 =~ "^i_[acm]time$";
      identifier i_xtime2 =~ "^i_[acm]time$";
      identifier ia_xtime1 =~ "^ia_[acm]time$";
      identifier ia_xtime2 =~ "^ia_[acm]time$";
      @@
      (
      (
      - struct timespec ts;
      + struct timespec64 ts;
      |
      - struct timespec ts = current_time(inode_node);
      + struct timespec64 ts = current_time(inode_node);
      )
      
      <+... when != ts
      (
      - timespec_equal(&inode_node->i_xtime, &ts)
      + timespec64_equal(&inode_node->i_xtime, &ts)
      |
      - timespec_equal(&ts, &inode_node->i_xtime)
      + timespec64_equal(&ts, &inode_node->i_xtime)
      |
      - timespec_compare(&inode_node->i_xtime, &ts)
      + timespec64_compare(&inode_node->i_xtime, &ts)
      |
      - timespec_compare(&ts, &inode_node->i_xtime)
      + timespec64_compare(&ts, &inode_node->i_xtime)
      |
      ts = current_time(e)
      |
      fn_update_time(..., &ts,...)
      |
      inode_node->i_xtime = ts
      |
      node1->i_xtime = ts
      |
      ts = inode_node->i_xtime
      |
      <+... attr1->ia_xtime ...+> = ts
      |
      ts = attr1->ia_xtime
      |
      ts.tv_sec
      |
      ts.tv_nsec
      |
      btrfs_set_stack_timespec_sec(..., ts.tv_sec)
      |
      btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
      |
      - ts = timespec64_to_timespec(
      + ts =
      ...
      -)
      |
      - ts = ktime_to_timespec(
      + ts = ktime_to_timespec64(
      ...)
      |
      - ts = E3
      + ts = timespec_to_timespec64(E3)
      |
      - ktime_get_real_ts(&ts)
      + ktime_get_real_ts64(&ts)
      |
      fn(...,
      - ts
      + timespec64_to_timespec(ts)
      ,...)
      )
      ...+>
      (
      <... when != ts
      - return ts;
      + return timespec64_to_timespec(ts);
      ...>
      )
      |
      - timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
      + timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
      |
      - timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
      + timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
      |
      - timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
      + timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
      |
      node1->i_xtime1 =
      - timespec_trunc(attr1->ia_xtime1,
      + timespec64_trunc(attr1->ia_xtime1,
      ...)
      |
      - attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
      + attr1->ia_xtime1 =  timespec64_trunc(attr2->ia_xtime2,
      ...)
      |
      - ktime_get_real_ts(&attr1->ia_xtime1)
      + ktime_get_real_ts64(&attr1->ia_xtime1)
      |
      - ktime_get_real_ts(&attr.ia_xtime1)
      + ktime_get_real_ts64(&attr.ia_xtime1)
      )
      
      @ depends on patch @
      struct inode *node;
      struct iattr *attr;
      identifier fn;
      identifier i_xtime =~ "^i_[acm]time$";
      identifier ia_xtime =~ "^ia_[acm]time$";
      expression e;
      @@
      (
      - fn(node->i_xtime);
      + fn(timespec64_to_timespec(node->i_xtime));
      |
       fn(...,
      - node->i_xtime);
      + timespec64_to_timespec(node->i_xtime));
      |
      - e = fn(attr->ia_xtime);
      + e = fn(timespec64_to_timespec(attr->ia_xtime));
      )
      
      @ depends on patch forall @
      struct inode *node;
      struct iattr *attr;
      identifier i_xtime =~ "^i_[acm]time$";
      identifier ia_xtime =~ "^ia_[acm]time$";
      identifier fn;
      @@
      {
      + struct timespec ts;
      <+...
      (
      + ts = timespec64_to_timespec(node->i_xtime);
      fn (...,
      - &node->i_xtime,
      + &ts,
      ...);
      |
      + ts = timespec64_to_timespec(attr->ia_xtime);
      fn (...,
      - &attr->ia_xtime,
      + &ts,
      ...);
      )
      ...+>
      }
      
      @ depends on patch forall @
      struct inode *node;
      struct iattr *attr;
      struct kstat *stat;
      identifier ia_xtime =~ "^ia_[acm]time$";
      identifier i_xtime =~ "^i_[acm]time$";
      identifier xtime =~ "^[acm]time$";
      identifier fn, ret;
      @@
      {
      + struct timespec ts;
      <+...
      (
      + ts = timespec64_to_timespec(node->i_xtime);
      ret = fn (...,
      - &node->i_xtime,
      + &ts,
      ...);
      |
      + ts = timespec64_to_timespec(node->i_xtime);
      ret = fn (...,
      - &node->i_xtime);
      + &ts);
      |
      + ts = timespec64_to_timespec(attr->ia_xtime);
      ret = fn (...,
      - &attr->ia_xtime,
      + &ts,
      ...);
      |
      + ts = timespec64_to_timespec(attr->ia_xtime);
      ret = fn (...,
      - &attr->ia_xtime);
      + &ts);
      |
      + ts = timespec64_to_timespec(stat->xtime);
      ret = fn (...,
      - &stat->xtime);
      + &ts);
      )
      ...+>
      }
      
      @ depends on patch @
      struct inode *node;
      struct inode *node2;
      identifier i_xtime1 =~ "^i_[acm]time$";
      identifier i_xtime2 =~ "^i_[acm]time$";
      identifier i_xtime3 =~ "^i_[acm]time$";
      struct iattr *attrp;
      struct iattr *attrp2;
      struct iattr attr ;
      identifier ia_xtime1 =~ "^ia_[acm]time$";
      identifier ia_xtime2 =~ "^ia_[acm]time$";
      struct kstat *stat;
      struct kstat stat1;
      struct timespec64 ts;
      identifier xtime =~ "^[acmb]time$";
      expression e;
      @@
      (
      ( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1  ;
      |
       node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
      |
       node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
      |
       node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
      |
       stat->xtime = node2->i_xtime1;
      |
       stat1.xtime = node2->i_xtime1;
      |
      ( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1  ;
      |
      ( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
      |
      - e = node->i_xtime1;
      + e = timespec64_to_timespec( node->i_xtime1 );
      |
      - e = attrp->ia_xtime1;
      + e = timespec64_to_timespec( attrp->ia_xtime1 );
      |
      node->i_xtime1 = current_time(...);
      |
       node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
      - e;
      + timespec_to_timespec64(e);
      |
       node->i_xtime1 = node->i_xtime3 =
      - e;
      + timespec_to_timespec64(e);
      |
      - node->i_xtime1 = e;
      + node->i_xtime1 = timespec_to_timespec64(e);
      )
      Signed-off-by: NDeepa Dinamani <deepa.kernel@gmail.com>
      Cc: <anton@tuxera.com>
      Cc: <balbi@kernel.org>
      Cc: <bfields@fieldses.org>
      Cc: <darrick.wong@oracle.com>
      Cc: <dhowells@redhat.com>
      Cc: <dsterba@suse.com>
      Cc: <dwmw2@infradead.org>
      Cc: <hch@lst.de>
      Cc: <hirofumi@mail.parknet.co.jp>
      Cc: <hubcap@omnibond.com>
      Cc: <jack@suse.com>
      Cc: <jaegeuk@kernel.org>
      Cc: <jaharkes@cs.cmu.edu>
      Cc: <jslaby@suse.com>
      Cc: <keescook@chromium.org>
      Cc: <mark@fasheh.com>
      Cc: <miklos@szeredi.hu>
      Cc: <nico@linaro.org>
      Cc: <reiserfs-devel@vger.kernel.org>
      Cc: <richard@nod.at>
      Cc: <sage@redhat.com>
      Cc: <sfrench@samba.org>
      Cc: <swhiteho@redhat.com>
      Cc: <tj@kernel.org>
      Cc: <trond.myklebust@primarydata.com>
      Cc: <tytso@mit.edu>
      Cc: <viro@zeniv.linux.org.uk>
      95582b00
  13. 23 4月, 2018 1 次提交
  14. 28 2月, 2018 1 次提交
    • T
      tty: make n_tty_read() always abort if hangup is in progress · 28b0f8a6
      Tejun Heo 提交于
      A tty is hung up by __tty_hangup() setting file->f_op to
      hung_up_tty_fops, which is skipped on ttys whose write operation isn't
      tty_write().  This means that, for example, /dev/console whose write
      op is redirected_tty_write() is never actually marked hung up.
      
      Because n_tty_read() uses the hung up status to decide whether to
      abort the waiting readers, the lack of hung-up marking can lead to the
      following scenario.
      
       1. A session contains two processes.  The leader and its child.  The
          child ignores SIGHUP.
      
       2. The leader exits and starts disassociating from the controlling
          terminal (/dev/console).
      
       3. __tty_hangup() skips setting f_op to hung_up_tty_fops.
      
       4. SIGHUP is delivered and ignored.
      
       5. tty_ldisc_hangup() is invoked.  It wakes up the waits which should
          clear the read lockers of tty->ldisc_sem.
      
       6. The reader wakes up but because tty_hung_up_p() is false, it
          doesn't abort and goes back to sleep while read-holding
          tty->ldisc_sem.
      
       7. The leader progresses to tty_ldisc_lock() in tty_ldisc_hangup()
          and is now stuck in D sleep indefinitely waiting for
          tty->ldisc_sem.
      
      The following is Alan's explanation on why some ttys aren't hung up.
      
       http://lkml.kernel.org/r/20171101170908.6ad08580@alans-desktop
      
       1. It broke the serial consoles because they would hang up and close
          down the hardware. With tty_port that *should* be fixable properly
          for any cases remaining.
      
       2. The console layer was (and still is) completely broken and doens't
          refcount properly. So if you turn on console hangups it breaks (as
          indeed does freeing consoles and half a dozen other things).
      
      As neither can be fixed quickly, this patch works around the problem
      by introducing a new flag, TTY_HUPPING, which is used solely to tell
      n_tty_read() that hang-up is in progress for the console and the
      readers should be aborted regardless of the hung-up status of the
      device.
      
      The following is a sample hung task warning caused by this issue.
      
        INFO: task agetty:2662 blocked for more than 120 seconds.
              Not tainted 4.11.3-dbg-tty-lockup-02478-gfd6c7ee-dirty #28
        "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
            0  2662      1 0x00000086
        Call Trace:
         __schedule+0x267/0x890
         schedule+0x36/0x80
         schedule_timeout+0x23c/0x2e0
         ldsem_down_write+0xce/0x1f6
         tty_ldisc_lock+0x16/0x30
         tty_ldisc_hangup+0xb3/0x1b0
         __tty_hangup+0x300/0x410
         disassociate_ctty+0x6c/0x290
         do_exit+0x7ef/0xb00
         do_group_exit+0x3f/0xa0
         get_signal+0x1b3/0x5d0
         do_signal+0x28/0x660
         exit_to_usermode_loop+0x46/0x86
         do_syscall_64+0x9c/0xb0
         entry_SYSCALL64_slow_path+0x25/0x25
      
      The following is the repro.  Run "$PROG /dev/console".  The parent
      process hangs in D state.
      
        #include <sys/types.h>
        #include <sys/stat.h>
        #include <sys/wait.h>
        #include <sys/ioctl.h>
        #include <fcntl.h>
        #include <unistd.h>
        #include <stdio.h>
        #include <stdlib.h>
        #include <errno.h>
        #include <signal.h>
        #include <time.h>
        #include <termios.h>
      
        int main(int argc, char **argv)
        {
      	  struct sigaction sact = { .sa_handler = SIG_IGN };
      	  struct timespec ts1s = { .tv_sec = 1 };
      	  pid_t pid;
      	  int fd;
      
      	  if (argc < 2) {
      		  fprintf(stderr, "test-hung-tty /dev/$TTY\n");
      		  return 1;
      	  }
      
      	  /* fork a child to ensure that it isn't already the session leader */
      	  pid = fork();
      	  if (pid < 0) {
      		  perror("fork");
      		  return 1;
      	  }
      
      	  if (pid > 0) {
      		  /* top parent, wait for everyone */
      		  while (waitpid(-1, NULL, 0) >= 0)
      			  ;
      		  if (errno != ECHILD)
      			  perror("waitpid");
      		  return 0;
      	  }
      
      	  /* new session, start a new session and set the controlling tty */
      	  if (setsid() < 0) {
      		  perror("setsid");
      		  return 1;
      	  }
      
      	  fd = open(argv[1], O_RDWR);
      	  if (fd < 0) {
      		  perror("open");
      		  return 1;
      	  }
      
      	  if (ioctl(fd, TIOCSCTTY, 1) < 0) {
      		  perror("ioctl");
      		  return 1;
      	  }
      
      	  /* fork a child, sleep a bit and exit */
      	  pid = fork();
      	  if (pid < 0) {
      		  perror("fork");
      		  return 1;
      	  }
      
      	  if (pid > 0) {
      		  nanosleep(&ts1s, NULL);
      		  printf("Session leader exiting\n");
      		  exit(0);
      	  }
      
      	  /*
      	   * The child ignores SIGHUP and keeps reading from the controlling
      	   * tty.  Because SIGHUP is ignored, the child doesn't get killed on
      	   * parent exit and the bug in n_tty makes the read(2) block the
      	   * parent's control terminal hangup attempt.  The parent ends up in
      	   * D sleep until the child is explicitly killed.
      	   */
      	  sigaction(SIGHUP, &sact, NULL);
      	  printf("Child reading tty\n");
      	  while (1) {
      		  char buf[1024];
      
      		  if (read(fd, buf, sizeof(buf)) < 0) {
      			  perror("read");
      			  return 1;
      		  }
      	  }
      
      	  return 0;
        }
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Alan Cox <alan@llwyncelyn.cymru>
      Cc: stable@vger.kernel.org
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      28b0f8a6
  15. 12 2月, 2018 1 次提交
    • L
      vfs: do bulk POLL* -> EPOLL* replacement · a9a08845
      Linus Torvalds 提交于
      This is the mindless scripted replacement of kernel use of POLL*
      variables as described by Al, done by this script:
      
          for V in IN OUT PRI ERR RDNORM RDBAND WRNORM WRBAND HUP RDHUP NVAL MSG; do
              L=`git grep -l -w POLL$V | grep -v '^t' | grep -v /um/ | grep -v '^sa' | grep -v '/poll.h$'|grep -v '^D'`
              for f in $L; do sed -i "-es/^\([^\"]*\)\(\<POLL$V\>\)/\\1E\\2/" $f; done
          done
      
      with de-mangling cleanups yet to come.
      
      NOTE! On almost all architectures, the EPOLL* constants have the same
      values as the POLL* constants do.  But they keyword here is "almost".
      For various bad reasons they aren't the same, and epoll() doesn't
      actually work quite correctly in some cases due to this on Sparc et al.
      
      The next patch from Al will sort out the final differences, and we
      should be all done.
      Scripted-by: NAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      a9a08845
  16. 23 1月, 2018 1 次提交
  17. 19 12月, 2017 1 次提交
    • S
      pty: cancel pty slave port buf's work in tty_release · 2b022ab7
      Sahara 提交于
      In case that CONFIG_SLUB_DEBUG is on and pty is used, races between
      release_one_tty and flush_to_ldisc work threads may happen and lead
      to use-after-free condition on tty->link->port. Because SLUB_DEBUG
      is turned on, freed tty->link->port is filled with POISON_FREE value.
      So far without SLUB_DEBUG, port was filled with zero and flush_to_ldisc
      could return without a problem by checking if tty is NULL.
      
      CPU 0                                 CPU 1
      -----                                 -----
      release_tty                           pty_write
         cancel_work_sync(tty)                 to = tty->link
         tty_kref_put(tty->link)               tty_schedule_flip(to->port)
            << workqueue >>                 ...
            release_one_tty                 ...
               pty_cleanup                  ...
                  kfree(tty->link->port)       << workqueue >>
                                               flush_to_ldisc
                                                  tty = READ_ONCE(port->itty)
                                                  tty is 0x6b6b6b6b6b6b6b6b
                                                  !!PANIC!! access tty->ldisc
      
       Unable to handle kernel paging request at virtual address 6b6b6b6b6b6b6b93
       pgd = ffffffc0eb1c3000
       [6b6b6b6b6b6b6b93] *pgd=0000000000000000, *pud=0000000000000000
       ------------[ cut here ]------------
       Kernel BUG at ffffff800851154c [verbose debug info unavailable]
       Internal error: Oops - BUG: 96000004 [#1] PREEMPT SMP
       CPU: 3 PID: 265 Comm: kworker/u8:9 Tainted: G        W 3.18.31-g0a58eeb #1
       Hardware name: Qualcomm Technologies, Inc. MSM 8996pro v1.1 + PMI8996 Carbide (DT)
       Workqueue: events_unbound flush_to_ldisc
       task: ffffffc0ed610ec0 ti: ffffffc0ed624000 task.ti: ffffffc0ed624000
       PC is at ldsem_down_read_trylock+0x0/0x4c
       LR is at tty_ldisc_ref+0x24/0x4c
       pc : [<ffffff800851154c>] lr : [<ffffff800850f6c0>] pstate: 80400145
       sp : ffffffc0ed627cd0
       x29: ffffffc0ed627cd0 x28: 0000000000000000
       x27: ffffff8009e05000 x26: ffffffc0d382cfa0
       x25: 0000000000000000 x24: ffffff800a012f08
       x23: 0000000000000000 x22: ffffffc0703fbc88
       x21: 6b6b6b6b6b6b6b6b x20: 6b6b6b6b6b6b6b93
       x19: 0000000000000000 x18: 0000000000000001
       x17: 00e80000f80d6f53 x16: 0000000000000001
       x15: 0000007f7d826fff x14: 00000000000000a0
       x13: 0000000000000000 x12: 0000000000000109
       x11: 0000000000000000 x10: 0000000000000000
       x9 : ffffffc0ed624000 x8 : ffffffc0ed611580
       x7 : 0000000000000000 x6 : ffffff800a42e000
       x5 : 00000000000003fc x4 : 0000000003bd1201
       x3 : 0000000000000001 x2 : 0000000000000001
       x1 : ffffff800851004c x0 : 6b6b6b6b6b6b6b93
      Signed-off-by: NSahara <keun-o.park@darkmatter.ae>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2b022ab7
  18. 29 11月, 2017 1 次提交
  19. 28 11月, 2017 1 次提交
  20. 08 11月, 2017 1 次提交
    • G
      tty: add SPDX identifiers to all remaining files in drivers/tty/ · e3b3d0f5
      Greg Kroah-Hartman 提交于
      It's good to have SPDX identifiers in all files to make it easier to
      audit the kernel tree for correct licenses.
      
      Update the drivers/tty files files with the correct SPDX license
      identifier based on the license text in the file itself.  The SPDX
      identifier is a legally binding shorthand, which can be used instead of
      the full boiler plate text.
      
      This work is based on a script and data from Thomas Gleixner, Philippe
      Ombredanne, and Kate Stewart.
      
      Cc: Jiri Slaby <jslaby@suse.com>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Chris Metcalf <cmetcalf@mellanox.com>
      Cc: Jiri Kosina <jikos@kernel.org>
      Cc: David Sterba <dsterba@suse.com>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Eric Anholt <eric@anholt.net>
      Cc: Stefan Wahren <stefan.wahren@i2se.com>
      Cc: Florian Fainelli <f.fainelli@gmail.com>
      Cc: Ray Jui <rjui@broadcom.com>
      Cc: Scott Branden <sbranden@broadcom.com>
      Cc: bcm-kernel-feedback-list@broadcom.com
      Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
      Cc: Helge Deller <deller@gmx.de>
      Cc: Joachim Eastwood <manabian@gmail.com>
      Cc: Matthias Brugger <matthias.bgg@gmail.com>
      Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
      Cc: Tobias Klauser <tklauser@distanz.ch>
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Vineet Gupta <vgupta@synopsys.com>
      Cc: Richard Genoud <richard.genoud@gmail.com>
      Cc: Alexander Shiyan <shc_work@mail.ru>
      Cc: Baruch Siach <baruch@tkos.co.il>
      Cc: "Maciej W. Rozycki" <macro@linux-mips.org>
      Cc: "Uwe Kleine-König" <kernel@pengutronix.de>
      Cc: Pat Gefre <pfg@sgi.com>
      Cc: "Guilherme G. Piccoli" <gpiccoli@linux.vnet.ibm.com>
      Cc: Jason Wessel <jason.wessel@windriver.com>
      Cc: Vladimir Zapolskiy <vz@mleia.com>
      Cc: Sylvain Lemieux <slemieux.tyco@gmail.com>
      Cc: Carlo Caione <carlo@caione.org>
      Cc: Kevin Hilman <khilman@baylibre.com>
      Cc: Liviu Dudau <liviu.dudau@arm.com>
      Cc: Sudeep Holla <sudeep.holla@arm.com>
      Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Cc: Andy Gross <andy.gross@linaro.org>
      Cc: David Brown <david.brown@linaro.org>
      Cc: "Andreas Färber" <afaerber@suse.de>
      Cc: Kevin Cernekee <cernekee@gmail.com>
      Cc: Laxman Dewangan <ldewangan@nvidia.com>
      Cc: Thierry Reding <thierry.reding@gmail.com>
      Cc: Jonathan Hunter <jonathanh@nvidia.com>
      Cc: Barry Song <baohua@kernel.org>
      Cc: Patrice Chotard <patrice.chotard@st.com>
      Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
      Cc: Alexandre Torgue <alexandre.torgue@st.com>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Peter Korsgaard <jacmet@sunsite.dk>
      Cc: Timur Tabi <timur@tabi.org>
      Cc: Tony Prisk <linux@prisktech.co.nz>
      Cc: Michal Simek <michal.simek@xilinx.com>
      Cc: "Sören Brinkmann" <soren.brinkmann@xilinx.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: Philippe Ombredanne <pombredanne@nexb.com>
      Cc: Jiri Slaby <jslaby@suse.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e3b3d0f5
  21. 29 8月, 2017 1 次提交
    • M
      pty: show associative slave of ptmx in fdinfo · d01c3289
      Masatake YAMATO 提交于
      This patch adds "tty-index" field to /proc/PID/fdinfo/N if N
      specifies /dev/ptmx. The field shows the index of associative
      slave pts.
      
      Though a minor number is given for each pts instance, ptmx is not.
      It means there is no way in user-space to know the association between
      file descriptors for pts/n and ptmx. (n = 0, 1, ...)
      
      This is different from pipe. About pipe such association can be solved
      by inode of pipefs.
      
      Providing the way to know the association between pts/n and ptmx helps
      users understand the status of running system. lsof can utilize this field.
      Signed-off-by: NMasatake YAMATO <yamato@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d01c3289
  22. 28 8月, 2017 2 次提交
    • O
      tty: undo export of tty_open_by_driver · a033c3b1
      Okash Khawaja 提交于
      Since we have tty_kopen, we no longer need to export tty_open_by_driver.
      This patch makes this function static.
      Signed-off-by: NOkash Khawaja <okash.khawaja@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a033c3b1
    • O
      tty: resolve tty contention between kernel and user space · a09ac397
      Okash Khawaja 提交于
      The commit 12e84c71 ("tty: export tty_open_by_driver") exports
      tty_open_by_device to allow tty to be opened from inside kernel which
      works fine except that it doesn't handle contention with user space or
      another kernel-space open of the same tty. For example, opening a tty
      from user space while it is kernel opened results in failure and a
      kernel log message about mismatch between tty->count and tty's file
      open count.
      
      This patch makes kernel access to tty exclusive, so that if a user
      process or kernel opens a kernel opened tty, it gets -EBUSY. It does
      this by adding TTY_KOPENED flag to tty->flags. When this flag is set,
      tty_open_by_driver returns -EBUSY. Instead of overloading
      tty_open_by_driver for both kernel and user space, this
      patch creates a separate function tty_kopen which closely follows
      tty_open_by_driver. tty_kclose closes the tty opened by tty_kopen.
      
      To address the mismatch between tty->count and #fd's, this patch adds
      #kopen's to the count before comparing it with tty->count. That way
      check_tty_count reflects correct usage count.
      
      Returning -EBUSY on tty open is a change in the interface. I have
      tested this with minicom, picocom and commands like "echo foo >
      /dev/ttyS0". They all correctly report "Device or resource busy" when
      the tty is already kernel opened.
      Signed-off-by: NOkash Khawaja <okash.khawaja@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a09ac397
  23. 25 8月, 2017 1 次提交
    • E
      pty: Repair TIOCGPTPEER · 311fc65c
      Eric W. Biederman 提交于
      The implementation of TIOCGPTPEER has two issues.
      
      When /dev/ptmx (as opposed to /dev/pts/ptmx) is opened the wrong
      vfsmount is passed to dentry_open.  Which results in the kernel displaying
      the wrong pathname for the peer.
      
      The second is simply by caching the vfsmount and dentry of the peer it leaves
      them open, in a way they were not previously Which because of the inreased
      reference counts can cause unnecessary behaviour differences resulting in
      regressions.
      
      To fix these move the ioctl into tty_io.c at a generic level allowing
      the ioctl to have access to the struct file on which the ioctl is
      being called.  This allows the path of the slave to be derived when
      opening the slave through TIOCGPTPEER instead of requiring the path to
      the slave be cached.  Thus removing the need for caching the path.
      
      A new function devpts_ptmx_path is factored out of devpts_acquire and
      used to implement a function devpts_mntget.   The new function devpts_mntget
      takes a filp to perform the lookup on and fsi so that it can confirm
      that the superblock that is found by devpts_ptmx_path is the proper superblock.
      
      v2: Lots of fixes to make the code actually work
      v3: Suggestions by Linus
          - Removed the unnecessary initialization of filp in ptm_open_peer
          - Simplified devpts_ptmx_path as gotos are no longer required
      
      [ This is the fix for the issue that was reverted in commit
        143c97cc, but this time without breaking 'pbuilder' due to
        increased reference counts   - Linus ]
      
      Fixes: 54ebbfb1 ("tty: add TIOCGPTPEER ioctl")
      Reported-by: NChristian Brauner <christian.brauner@canonical.com>
      Reported-and-tested-by: NStefan Lippers-Hollmann <s.l-h@gmx.de>
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      311fc65c
  24. 27 6月, 2017 1 次提交
  25. 16 5月, 2017 1 次提交
    • O
      tty: export tty_open_by_driver · 12e84c71
      Okash Khawaja 提交于
      This exports tty_open_by_driver so that it can be called from other
      places inside the kernel. The checks for null file pointer are based on
      Alan Cox's patch here:
      http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1215095.html.
      Description below is quoted from it:
      
      "[RFC] tty_port: allow a port to be opened with a tty that has no file handle
      
          Let us create tty objects entirely in kernel space. Untested proposal to
          show why all the ideas around rewriting half the uart stack are not needed.
      
          With this a kernel created non file backed tty object could be used to handle
          data, and set terminal modes. Not all ldiscs can cope with this as N_TTY in
          particular has to work back to the fs/tty layer.
      
          The tty_port code is however otherwise clean of file handles as far as I can
          tell as is the low level tty port write path used by the ldisc, the
          configuration low level interfaces and most of the ldiscs.
      
          Currently you don't have any exposure to see tty hangups because those are
          built around the file layer. However a) it's a fixed port so you probably
          don't care about that b) if you do we can add a callback and c) you almost
          certainly don't want the userspace tear down/rebuild behaviour anyway.
      
          This should however be sufficient if we wanted for example to enumerate all
          the bluetooth bound fixed ports via ACPI and make them directly available.
      
          It doesn't deal with the case of a user opening a port that's also kernel
          opened and that would need some locking out (so it returned EBUSY if bound
          to a kernel device of some kind). That needs resolving along with how you
          "up" or "down" your new bluetooth device, or enumerate it while providing
          the existing tty API to avoid regressions (and to debug)."
      
      The exported funtion is used later in this patch set to gain access to tty_struct.
      
      [changed export symbol level - gkh]
      Signed-off-by: NOkash Khawaja <okash.khawaja@gmail.com>
      Reviewed-by: NSamuel Thibault <samuel.thibault@ens-lyon.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      12e84c71
  26. 24 4月, 2017 1 次提交
  27. 19 4月, 2017 2 次提交
  28. 09 4月, 2017 1 次提交
  29. 31 3月, 2017 3 次提交
    • J
      tty: reset termios state on device registration · 93857edd
      Johan Hovold 提交于
      Free any saved termios data when registering a tty device so that the
      termios state is reset when reusing a minor number.
      
      This is useful for hot-pluggable buses such as USB where it does not
      make much sense to reuse saved termios data from an unrelated device
      when a new device is later plugged in.
      
      This specifically avoids a situation where the new device does not have
      the carrier-detect signal wired, but the saved termios state has CLOCAL
      cleared, effectively preventing the port from being opened in blocking
      mode as noted by Jan Kundrát <jan.kundrat@cesnet.cz>.
      
      Note that clearing the saved data at deregistration would not work as
      the device could still be open.
      
      Also note that the termios data is not reset for drivers with
      TTY_DRIVER_DYNAMIC_ALLOC set (e.g. legacy pty) as their character device
      is registered at driver registration and could theoretically already
      have been opened (and pty termios state is never saved anyway).
      Reported-by: NJan Kundrát <jan.kundrat@cesnet.cz>
      Signed-off-by: NJohan Hovold <johan@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      93857edd
    • J
      tty: drop obsolete termios_locked comments · 16b00ae8
      Johan Hovold 提交于
      Drop comments about tty-driver termios_locked structures, which have
      been outdated since commit fe6e29fd ("tty: simplify ktermios
      allocation").
      Signed-off-by: NJohan Hovold <johan@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      16b00ae8
    • J
      tty: close race between device register and open · 6a7e6f78
      Johan Hovold 提交于
      The tty class device is currently not registered until after the
      character device has been registered thereby leaving a small window
      were a racing open could end up with a NULL tty->dev pointer due to the
      class-device lookup failing in alloc_tty_struct.
      
      Close this race by registering the class device before the character
      device while making sure to defer the user-space uevent notification
      until after the character device has been registered.
      
      Note that some tty drivers expect a valid tty->dev and would misbehave
      or crash otherwise. Some line disciplines also currently dereference the
      class device unconditionally despite the fact that not every tty is
      guaranteed to have one (Unix98 pty), but this is being fixed separately.
      Signed-off-by: NJohan Hovold <johan@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6a7e6f78