android_kernel_xiaomi_sm8450/drivers/tty/hvc
Raghavendra Rao Ananta dbc45f4c7c tty: hvc_console, fix crashes on parallel open/close
hvc_open sets tty->driver_data to NULL when open fails at some point.
Typically, the failure happens in hp->ops->notifier_add(). If there is
a racing process which tries to open such mangled tty, which was not
closed yet, the process will crash in hvc_open as tty->driver_data is
NULL.

All this happens because close wants to know whether open failed or not.
But ->open should not NULL this and other tty fields for ->close to be
happy. ->open should call tty_port_set_initialized(true) and close
should check by tty_port_initialized() instead. So do this properly in
this driver.

So this patch removes these from ->open:
* tty_port_tty_set(&hp->port, NULL). This happens on last close.
* tty->driver_data = NULL. Dtto.
* tty_port_put(&hp->port). This happens in shutdown and until now, this
  must have been causing a reference underflow, if I am not missing
  something.

Change-Id: Ie67e9bc9038a282a22f7a7baf7a4588549416725
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: stable <stable@vger.kernel.org>
Reported-and-tested-by: Raghavendra <rananta@codeaurora.org>
Link: https://lore.kernel.org/r/20200526145632.13879-1-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 24eb2377f9
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
Signed-off-by: Raghavendra Rao Ananta <rananta@codeaurora.org>
2020-06-01 11:29:58 -07:00
..
hvc_console.c tty: hvc_console, fix crashes on parallel open/close 2020-06-01 11:29:58 -07:00
hvc_console.h tty: hvc: introduce the hv_ops.flush operation for hvc drivers 2018-07-23 20:13:20 +10:00
hvc_dcc.c hvc_dcc: Disable preemption when cheking for smp_processor_id 2019-06-05 08:39:25 -07:00
hvc_haven.c hvc: haven: Prevent tty layer from closing SELF console 2020-05-08 13:11:26 -07:00
hvc_irq.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hvc_iucv.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
hvc_opal.c tty: Use of_node_name_{eq,prefix} for node name comparisons 2018-12-17 16:12:17 +01:00
hvc_riscv_sbi.c tty: Don't force RISCV SBI console as preferred console 2019-05-16 20:42:11 -07:00
hvc_rtas.c tty: hvc: Remove redundant license text 2017-11-08 13:08:12 +01:00
hvc_udbg.c tty: hvc: Remove redundant license text 2017-11-08 13:08:12 +01:00
hvc_vio.c powerpc/pseries/hvconsole: Fix stack overread via udbg 2019-06-14 15:35:53 +10:00
hvc_xen.c tty: hvc_xen: Mark expected switch fall-through 2019-02-26 12:30:44 +01:00
hvcs.c tty: hvcs: Fix odd use of strlcpy 2019-09-04 12:43:44 +02:00
hvsi_lib.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hvsi.c tty: hvc: Remove redundant license text 2017-11-08 13:08:12 +01:00
Kconfig tty: Add Haven RM Console driver 2020-02-10 12:34:03 -08:00
Makefile tty: Add Haven RM Console driver 2020-02-10 12:34:03 -08:00