1. 09 2月, 2021 1 次提交
    • L
      tty: avoid using vfs_iocb_iter_write() for redirected console writes · 2037cd7d
      Linus Torvalds 提交于
      stable inclusion
      from stable-5.10.13
      commit 8fe07159fc53d8103da4ca9899be782ec478692f
      bugzilla: 47995
      
      --------------------------------
      
      commit a9cbbb80 upstream.
      
      It turns out that the vfs_iocb_iter_{read,write}() functions are
      entirely broken, and don't actually use the passed-in file pointer for
      IO - only for the preparatory work (permission checking and for the
      write_iter function lookup).
      
      That worked fine for overlayfs, which always builds the new iocb with
      the same file pointer that it passes in, but in the general case it ends
      up doing nonsensical things (and could cause an iterator call that
      doesn't even match the passed-in file pointer).
      
      This subtly broke the tty conversion to write_iter in commit
      9bb48c82 ("tty: implement write_iter"), because the console
      redirection didn't actually end up redirecting anything, since the
      passed-in file pointer was basically ignored, and the actual write was
      done with the original non-redirected console tty after all.
      
      The main visible effect of this is that the console messages were no
      longer logged to /var/log/boot.log during graphical boot.
      
      Fix the issue by simply not using the vfs write "helper" function at
      all, and just redirecting the write entirely internally to the tty
      layer.  Do the target writability permission checks when actually
      registering the target tty with TIOCCONS instead of at write time.
      
      Fixes: 9bb48c82 ("tty: implement write_iter")
      Reported-and-tested-by: NHans de Goede <hdegoede@redhat.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: stable@kernel.org
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      2037cd7d
  2. 08 2月, 2021 3 次提交
  3. 05 12月, 2020 1 次提交
    • J
      tty: Fix ->session locking · c8bcd9c5
      Jann Horn 提交于
      Currently, locking of ->session is very inconsistent; most places
      protect it using the legacy tty mutex, but disassociate_ctty(),
      __do_SAK(), tiocspgrp() and tiocgsid() don't.
      Two of the writers hold the ctrl_lock (because they already need it for
      ->pgrp), but __proc_set_tty() doesn't do that yet.
      
      On a PREEMPT=y system, an unprivileged user can theoretically abuse
      this broken locking to read 4 bytes of freed memory via TIOCGSID if
      tiocgsid() is preempted long enough at the right point. (Other things
      might also go wrong, especially if root-only ioctls are involved; I'm
      not sure about that.)
      
      Change the locking on ->session such that:
      
       - tty_lock() is held by all writers: By making disassociate_ctty()
         hold it. This should be fine because the same lock can already be
         taken through the call to tty_vhangup_session().
         The tricky part is that we need to shorten the area covered by
         siglock to be able to take tty_lock() without ugly retry logic; as
         far as I can tell, this should be fine, since nothing in the
         signal_struct is touched in the `if (tty)` branch.
       - ctrl_lock is held by all writers: By changing __proc_set_tty() to
         hold the lock a little longer.
       - All readers that aren't holding tty_lock() hold ctrl_lock: By
         adding locking to tiocgsid() and __do_SAK(), and expanding the area
         covered by ctrl_lock in tiocspgrp().
      
      Cc: stable@kernel.org
      Signed-off-by: NJann Horn <jannh@google.com>
      Reviewed-by: NJiri Slaby <jirislaby@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c8bcd9c5
  4. 07 11月, 2020 1 次提交
  5. 18 8月, 2020 1 次提交
  6. 29 7月, 2020 3 次提交
  7. 18 3月, 2020 3 次提交
  8. 17 12月, 2019 1 次提交
  9. 22 11月, 2019 1 次提交
  10. 20 11月, 2019 1 次提交
  11. 23 10月, 2019 2 次提交
  12. 30 7月, 2019 1 次提交
  13. 24 5月, 2019 1 次提交
  14. 25 4月, 2019 1 次提交
  15. 29 3月, 2019 1 次提交
  16. 28 3月, 2019 1 次提交
    • S
      tty: pty: Fix race condition between release_one_tty and pty_write · b9ca5f85
      Sahara 提交于
      Especially when a linked tty is used such as pty, the linked tty
      port's buf works have not been cancelled while master tty port's
      buf work has been cancelled. Since release_one_tty and flush_to_ldisc
      run in workqueue threads separately, when pty_cleanup happens and
      link tty port is freed, flush_to_ldisc tries to access freed port
      and port->itty, eventually it causes a panic.
      This patch utilizes the magic value with holding the tty_mutex to
      check if the tty->link is valid.
      
      Fixes: 2b022ab7 ("pty: cancel pty slave port buf's work in tty_release")
      Signed-off-by: NSahara <keun-o.park@darkmatter.ae>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b9ca5f85
  17. 30 1月, 2019 1 次提交
  18. 22 1月, 2019 1 次提交
  19. 12 1月, 2019 1 次提交
  20. 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
  21. 13 10月, 2018 4 次提交
  22. 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
  23. 18 9月, 2018 1 次提交
  24. 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
  25. 14 9月, 2018 3 次提交
  26. 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