1. 21 1月, 2021 2 次提交
    • L
      tty: convert tty_ldisc_ops 'read()' function to take a kernel pointer · 3b830a9c
      Linus Torvalds 提交于
      The tty line discipline .read() function was passed the final user
      pointer destination as an argument, which doesn't match the 'write()'
      function, and makes it very inconvenient to do a splice method for
      ttys.
      
      This is a conversion to use a kernel buffer instead.
      
      NOTE! It does this by passing the tty line discipline ->read() function
      an additional "cookie" to fill in, and an offset into the cookie data.
      
      The line discipline can fill in the cookie data with its own private
      information, and then the reader will repeat the read until either the
      cookie is cleared or it runs out of data.
      
      The only real user of this is N_HDLC, which can use this to handle big
      packets, even if the kernel buffer is smaller than the whole packet.
      
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      3b830a9c
    • L
      tty: implement write_iter · 9bb48c82
      Linus Torvalds 提交于
      This makes the tty layer use the .write_iter() function instead of the
      traditional .write() functionality.
      
      That allows writev(), but more importantly also makes it possible to
      enable .splice_write() for ttys, reinstating the "splice to tty"
      functionality that was lost in commit 36e2c742 ("fs: don't allow
      splice read/write without explicit ops").
      
      Fixes: 36e2c742 ("fs: don't allow splice read/write without explicit ops")
      Reported-by: NOliver Giles <ohw.giles@gmail.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      9bb48c82
  2. 05 12月, 2020 2 次提交
    • 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
    • J
      tty: Fix ->pgrp locking in tiocspgrp() · 54ffccbf
      Jann Horn 提交于
      tiocspgrp() takes two tty_struct pointers: One to the tty that userspace
      passed to ioctl() (`tty`) and one to the TTY being changed (`real_tty`).
      These pointers are different when ioctl() is called with a master fd.
      
      To properly lock real_tty->pgrp, we must take real_tty->ctrl_lock.
      
      This bug makes it possible for racing ioctl(TIOCSPGRP, ...) calls on
      both sides of a PTY pair to corrupt the refcount of `struct pid`,
      leading to use-after-free errors.
      
      Fixes: 47f86834 ("redo locking of tty->pgrp")
      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>
      54ffccbf
  3. 12 11月, 2020 3 次提交
  4. 09 11月, 2020 1 次提交
    • D
      vt: Disable KD_FONT_OP_COPY · 3c4e0dff
      Daniel Vetter 提交于
      It's buggy:
      
      On Fri, Nov 06, 2020 at 10:30:08PM +0800, Minh Yuan wrote:
      > We recently discovered a slab-out-of-bounds read in fbcon in the latest
      > kernel ( v5.10-rc2 for now ).  The root cause of this vulnerability is that
      > "fbcon_do_set_font" did not handle "vc->vc_font.data" and
      > "vc->vc_font.height" correctly, and the patch
      > <https://lkml.org/lkml/2020/9/27/223> for VT_RESIZEX can't handle this
      > issue.
      >
      > Specifically, we use KD_FONT_OP_SET to set a small font.data for tty6, and
      > use  KD_FONT_OP_SET again to set a large font.height for tty1. After that,
      > we use KD_FONT_OP_COPY to assign tty6's vc_font.data to tty1's vc_font.data
      > in "fbcon_do_set_font", while tty1 retains the original larger
      > height. Obviously, this will cause an out-of-bounds read, because we can
      > access a smaller vc_font.data with a larger vc_font.height.
      
      Further there was only one user ever.
      - Android's loadfont, busybox and console-tools only ever use OP_GET
        and OP_SET
      - fbset documentation only mentions the kernel cmdline font: option,
        not anything else.
      - systemd used OP_COPY before release 232 published in Nov 2016
      
      Now unfortunately the crucial report seems to have gone down with
      gmane, and the commit message doesn't say much. But the pull request
      hints at OP_COPY being broken
      
      https://github.com/systemd/systemd/pull/3651
      
      So in other words, this never worked, and the only project which
      foolishly every tried to use it, realized that rather quickly too.
      
      Instead of trying to fix security issues here on dead code by adding
      missing checks, fix the entire thing by removing the functionality.
      
      Note that systemd code using the OP_COPY function ignored the return
      value, so it doesn't matter what we're doing here really - just in
      case a lone server somewhere happens to be extremely unlucky and
      running an affected old version of systemd. The relevant code from
      font_copy_to_all_vcs() in systemd was:
      
      	/* copy font from active VT, where the font was uploaded to */
      	cfo.op = KD_FONT_OP_COPY;
      	cfo.height = vcs.v_active-1; /* tty1 == index 0 */
      	(void) ioctl(vcfd, KDFONTOP, &cfo);
      
      Note this just disables the ioctl, garbage collecting the now unused
      callbacks is left for -next.
      
      v2: Tetsuo found the old mail, which allowed me to find it on another
      archive. Add the link too.
      Acked-by: NPeilin Ye <yepeilin.cs@gmail.com>
      Reported-by: NMinh Yuan <yuanmingbuaa@gmail.com>
      References: https://lists.freedesktop.org/archives/systemd-devel/2016-June/036935.html
      References: https://github.com/systemd/systemd/pull/3651
      Cc: Greg KH <greg@kroah.com>
      Cc: Peilin Ye <yepeilin.cs@gmail.com>
      Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
      Signed-off-by: NDaniel Vetter <daniel.vetter@intel.com>
      Link: https://lore.kernel.org/r/20201108153806.3140315-1-daniel.vetter@ffwll.chSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3c4e0dff
  5. 07 11月, 2020 4 次提交
  6. 03 11月, 2020 1 次提交
  7. 28 10月, 2020 5 次提交
  8. 07 10月, 2020 1 次提交
  9. 05 10月, 2020 2 次提交
  10. 02 10月, 2020 1 次提交
  11. 01 10月, 2020 1 次提交
    • T
      serial: max310x: rework RX interrupt handling · fce3c5c1
      Thomas Petazzoni 提交于
      Currently, the RX interrupt logic uses the RXEMPTY interrupt, with the
      RXEMPTYINV bit set, which means we get an RX interrupt as soon as the
      RX FIFO is non-empty.
      
      However, with the MAX310X having a FIFO of 128 bytes, this makes very
      poor use of the FIFO: we trigger an interrupt as soon as the RX FIFO
      has one byte, which means a lot of interrupts, each only collecting a
      few bytes from the FIFO, causing a significant CPU load.
      
      Instead this commit relies on two other RX interrupt events:
      
       - MAX310X_IRQ_RXFIFO_BIT, which triggers when the RX FIFO has reached
         a certain threshold, which we define to be half of the FIFO
         size. This ensure we get an interrupt before the RX FIFO fills up.
      
       - MAX310X_LSR_RXTO_BIT, which triggers when the RX FIFO has received
         some bytes, and then no more bytes are received for a certain
         time. Arbitrarily, this time is defined to the time is takes to
         receive 4 characters.
      
      On a Microchip SAMA5D3 platform that is receiving 20 bytes every 16ms
      over one MAX310X UART, this patch has allowed to reduce the CPU
      consumption of the interrupt handler thread from ~25% to 6-7%.
      Signed-off-by: NThomas Petazzoni <thomas.petazzoni@bootlin.com>
      Link: https://lore.kernel.org/r/20201001074415.349739-1-thomas.petazzoni@bootlin.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fce3c5c1
  12. 30 9月, 2020 9 次提交
  13. 29 9月, 2020 1 次提交
  14. 27 9月, 2020 5 次提交
  15. 18 9月, 2020 1 次提交
  16. 16 9月, 2020 1 次提交