Commit Graph

15 Commits

Author SHA1 Message Date
Andrew Halaney 3f9e31ae14 tty: convert THROTTLE constants into enum
JIRA: https://issues.redhat.com/browse/RHEL-24205

commit e5d0424ac31154e47bfce857ba908bbe861c7a92
Author: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Date:   Tue Sep 19 10:51:53 2023 +0200

    tty: convert THROTTLE constants into enum

    And make an explicit constant for zero too. This allows for easier type
    checking of the parameter.

    Note: tty_struct::flow_change is kept as int because include/tty.h
    (tty_struct) doesn't see tty/tty.h (this enum).

    Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
    Link: https://lore.kernel.org/r/20230919085156.1578-13-jirislaby@kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:13 -04:00
Andrew Halaney 019ace4d69 tty: audit: unify to u8
JIRA: https://issues.redhat.com/browse/RHEL-24205

commit 3e04ba41f22490873a60816ea31c6848d3426255
Author: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Date:   Thu Aug 10 11:15:04 2023 +0200

    tty: audit: unify to u8

    Somewhere, we use 'char', somewhere 'unsigned char'. Unify to 'u8' as
    the rest of the tty layer does.

    Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
    Link: https://lore.kernel.org/r/20230810091510.13006-31-jirislaby@kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:25:57 -04:00
Andrew Halaney 80058b320b tty: use u8 for chars
JIRA: https://issues.redhat.com/browse/RHEL-24205
Conflicts: Skipping the drivers/net/mctp/mctp-serial.c as it is
           not present in cs9

commit a8d9cd2318606627d3c0e4747dbd7bbc44c48e27
Author: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Date:   Thu Aug 10 11:14:50 2023 +0200

    tty: use u8 for chars

    This makes all those 'unsigned char's an explicit 'u8'. This is part of
    the continuing unification of chars and flags to be consistent u8.

    This approaches tty_port_default_receive_buf(). Flags to be next.

    Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
    Cc: William Hubbs <w.d.hubbs@gmail.com>
    Cc: Chris Brannon <chris@the-brannons.com>
    Cc: Kirk Reiser <kirk@reisers.ca>
    Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
    Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Max Staudt <max@enpas.org>
    Cc: Wolfgang Grandegger <wg@grandegger.com>
    Cc: Marc Kleine-Budde <mkl@pengutronix.de>
    Cc: "David S. Miller" <davem@davemloft.net>
    Cc: Eric Dumazet <edumazet@google.com>
    Cc: Jakub Kicinski <kuba@kernel.org>
    Cc: Paolo Abeni <pabeni@redhat.com>
    Cc: Dario Binacchi <dario.binacchi@amarulasolutions.com>
    Cc: Andreas Koensgen <ajk@comnets.uni-bremen.de>
    Cc: Jeremy Kerr <jk@codeconstruct.com.au>
    Cc: Matt Johnston <matt@codeconstruct.com.au>
    Cc: Liam Girdwood <lgirdwood@gmail.com>
    Cc: Mark Brown <broonie@kernel.org>
    Cc: Jaroslav Kysela <perex@perex.cz>
    Cc: Takashi Iwai <tiwai@suse.com>
    Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>
    Acked-by: Mark Brown <broonie@kernel.org>
    Link: https://lore.kernel.org/r/20230810091510.13006-17-jirislaby@kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:25:56 -04:00
Andrew Halaney 34714f3398 tty: change tty_write_lock()'s ndelay parameter to bool
JIRA: https://issues.redhat.com/browse/RHEL-24205

commit af815336556df28f800669c58ab3bdad7d786b98
Author: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Date:   Thu Aug 10 11:14:39 2023 +0200

    tty: change tty_write_lock()'s ndelay parameter to bool

    It's a yes-no parameter, so convert it to bool to be obvious.

    Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
    Link: https://lore.kernel.org/r/20230810091510.13006-6-jirislaby@kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:25:55 -04:00
Andrew Halaney c0b8d64ae9 tty_audit: make tty pointers in exposed functions const
JIRA: https://issues.redhat.com/browse/RHEL-24205

commit e64ed44bce43e003dd154c0bc418a431c15bdf77
Author: Jiri Slaby <jirislaby@kernel.org>
Date:   Wed Jun 21 12:16:10 2023 +0200

    tty_audit: make tty pointers in exposed functions const

    Both tty_audit_add_data() and tty_audit_tiocsti() need only to read from
    the tty struct, so make the tty parameters of them both const. This
    aids the compiler a bit.

    Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
    Link: https://lore.kernel.org/r/20230621101611.10580-6-jirislaby@kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:25:45 -04:00
Andrew Halaney 9a07bee4cf tty: Prevent writing chars during tcsetattr TCSADRAIN/FLUSH
JIRA: https://issues.redhat.com/browse/RHEL-24205

commit 094fb49a2d0d6827c86d2e0840873e6db0c491d2
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Fri Mar 17 13:33:17 2023 +0200

    tty: Prevent writing chars during tcsetattr TCSADRAIN/FLUSH

    If userspace races tcsetattr() with a write, the drained condition
    might not be guaranteed by the kernel. There is a race window after
    checking Tx is empty before tty_set_termios() takes termios_rwsem for
    write. During that race window, more characters can be queued by a
    racing writer.

    Any ongoing transmission might produce garbage during HW's
    ->set_termios() call. The intent of TCSADRAIN/FLUSH seems to be
    preventing such a character corruption. If those flags are set, take
    tty's write lock to stop any writer before performing the lower layer
    Tx empty check and wait for the pending characters to be sent (if any).

    The initial wait for all-writers-done must be placed outside of tty's
    write lock to avoid deadlock which makes it impossible to use
    tty_wait_until_sent(). The write lock is retried if a racing write is
    detected.

    Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
    Cc: stable@vger.kernel.org
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Link: https://lore.kernel.org/r/20230317113318.31327-2-ilpo.jarvinen@linux.intel.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:25:38 -04:00
Andrew Halaney 91a41f9381 tty: Move sysctl setup into "core" tty logic
JIRA: https://issues.redhat.com/browse/RHEL-24205

commit 5fd8c2d3de3dd3cc6d36a0c7a08e44cd5bf173e6
Author: Kees Cook <keescook@chromium.org>
Date:   Sat Oct 22 11:29:48 2022 -0700

    tty: Move sysctl setup into "core" tty logic

    In preparation for adding another sysctl to the tty subsystem, move the
    tty setup code into the "core" tty code, which contains tty_init() itself.

    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Jiri Slaby <jirislaby@kernel.org>
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Link: https://lore.kernel.org/r/20221022182949.2684794-1-keescook@chromium.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:25:11 -04:00
Waiman Long bb442fd4f8 tty: Remove baudrate dead code & make ktermios params const
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2184097

commit 87888fb9ac0c71cdc1edd0779382052475dadb84
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Tue, 16 Aug 2022 14:57:32 +0300

    tty: Remove baudrate dead code & make ktermios params const

    With the architectures currently in-tree, either:
      1) CBAUDEX is zero
      2) The earlier BOTHER if check covers cbaud < 1 case
      3) All CBAUD bits are covered by the baud_table

    Thus, the check for cbaud being out-of-range for CBAUDEX case cannot
    ever be true.

    The ktermios parameters can now be made const.

    Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Link: https://lore.kernel.org/r/20220816115739.10928-2-ilpo.jarvinen@linux.intel.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Waiman Long <longman@redhat.com>
2023-04-19 21:33:20 -04:00
Rafael Aquini 6eb2a5642d tty: use new tty_insert_flip_string_and_push_buffer() in pty_write()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2078867
CVE: CVE-2022-1462
Conflicts: as documented on the backport notes section.

This patch is a backport of the following upstream commit:
commit a501ab75e7624d133a5a3c7ec010687c8b961d23
Author: Jiri Slaby <jirislaby@kernel.org>
Date:   Thu Jul 7 10:25:58 2022 +0200

    tty: use new tty_insert_flip_string_and_push_buffer() in pty_write()

    There is a race in pty_write(). pty_write() can be called in parallel
    with e.g. ioctl(TIOCSTI) or ioctl(TCXONC) which also inserts chars to
    the buffer. Provided, tty_flip_buffer_push() in pty_write() is called
    outside the lock, it can commit inconsistent tail. This can lead to out
    of bounds writes and other issues. See the Link below.

    To fix this, we have to introduce a new helper called
    tty_insert_flip_string_and_push_buffer(). It does both
    tty_insert_flip_string() and tty_flip_buffer_commit() under the port
    lock. It also calls queue_work(), but outside the lock. See
    71a174b39f (pty: do tty_flip_buffer_push without port->lock in
    pty_write) for the reasons.

    Keep the helper internal-only (in drivers' tty.h). It is not intended to
    be used widely.

    Link: https://seclists.org/oss-sec/2022/q2/155
    Fixes: 71a174b39f (pty: do tty_flip_buffer_push without port->lock in pty_write)
    Cc: 一只狗 <chennbnbnb@gmail.com>
    Cc: Dan Carpenter <dan.carpenter@oracle.com>
    Suggested-by: Hillf Danton <hdanton@sina.com>
    Signed-off-by: Jiri Slaby <jslaby@suse.cz>
    Link: https://lore.kernel.org/r/20220707082558.9250-2-jslaby@suse.cz
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

RHEL BACKPORT NOTES:
* drivers/tty/tty_buffer.c: minor context diff due to RHEL9 missing upstream
  commit bc17b7236b47 ("tty: reformat kernel-doc in tty_buffer.c"), which
  is not a hard dependency for this port

Signed-off-by: Rafael Aquini <aquini@redhat.com>
2022-09-07 19:15:14 -04:00
Greg Kroah-Hartman 5ffa6e344a tty: clean include/linux/tty.h up
There are a lot of tty-core-only functions that are listed in
include/linux/tty.h.  Move them to drivers/tty/tty.h so that no one else
can accidentally call them or think that they are public functions.

Cc: Jiri Slaby <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20210408125134.3016837-14-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-04-15 10:32:17 +02:00
Greg Kroah-Hartman 9f72cab159 tty: move some tty-only functions to drivers/tty/tty.h
The flow change and restricted_tty_write() logic is internal to the tty
core only, so move it out of the include/linux/tty.h file.

Cc: Jiri Slaby <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20210408125134.3016837-12-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-04-15 10:30:18 +02:00
Greg Kroah-Hartman 6c80c0b94b tty: move some internal tty lock enums and functions out of tty.h
Move the TTY_LOCK_* enums and tty_ldisc lock functions out of the global
tty.h into the local header file to clean things up.

Cc: Jiri Slaby <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20210408125134.3016837-10-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-04-15 10:26:58 +02:00
Greg Kroah-Hartman da5d669e00 tty: audit: move some local functions out of tty.h
The functions tty_audit_add_data() and tty_audit_tiocsti() are local to
the tty core code, and do not need to be in a "kernel-wide" header file
so move them to drivers/tty/tty.h

Cc: Jiri Slaby <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20210408125134.3016837-9-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-04-15 10:24:58 +02:00
Greg Kroah-Hartman 4d5a64cbc7 tty: tty.h: remove tty_info()
No one is calling this macro, and no one should, so remove it from the
.h file.

Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: Jiri Slaby <jirislaby@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20210408125134.3016837-3-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-04-15 10:23:08 +02:00
Greg Kroah-Hartman 98602c010c tty: create internal tty.h file
There are a number of functions and #defines in include/linux/tty.h that
do not belong there as they are private to the tty core code.

Create an initial drivers/tty/tty.h file and copy the odd "tty logging"
macros into it to seed the file with some initial things that we know
nothing outside of the tty core should be calling.

Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: Jiri Slaby <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20210408125134.3016837-2-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-04-15 10:22:17 +02:00