linux-stable/drivers/tty
Douglas Anderson ed56f3cfbe Revert "tty: serial: simplify qcom_geni_serial_send_chunk_fifo()"
commit 3d9319c27c upstream.

This reverts commit 5c7e105cd1.

As identified by KASAN, the simplification done by the cleanup patch
was not legal.

>From tracing through the code, it can be seen that we're transmitting
from a 4096-byte circular buffer. We copy anywhere from 1-4 bytes from
it each time. The simplification runs into trouble when we get near
the end of the circular buffer. For instance, we might start out with
xmit->tail = 4094 and we want to transfer 4 bytes. With the code
before simplification this was no problem. We'd read buf[4094],
buf[4095], buf[0], and buf[1]. With the new code we'll do a
memcpy(&buf[4094], 4) which reads 2 bytes past the end of the buffer
and then skips transmitting what's at buf[0] and buf[1].

KASAN isn't 100% consistent at reporting this for me, but to be extra
confident in the analysis, I added traces of the tail and tx_bytes and
then wrote a test program:

  while true; do
    echo -n "abcdefghijklmnopqrstuvwxyz0" > /dev/ttyMSM0
    sleep .1
  done

I watched the traces over SSH and saw:
  qcom_geni_serial_send_chunk_fifo: 4093 4
  qcom_geni_serial_send_chunk_fifo: 1 3

Which indicated that one byte should be missing. Sure enough the
output that should have been:

  abcdefghijklmnopqrstuvwxyz0

In one case was actually missing a byte:

  abcdefghijklmnopqrstuvwyz0

Running "ls -al" on large directories also made the missing bytes
obvious since columns didn't line up.

While the original code may not be the most elegant, we only talking
about copying up to 4 bytes here. Let's just go back to the code that
worked.

Fixes: 5c7e105cd1 ("tty: serial: simplify qcom_geni_serial_send_chunk_fifo()")
Cc: stable <stable@kernel.org>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Acked-by: Jiri Slaby <jirislaby@kernel.org>
Tested-by: Johan Hovold <johan+linaro@kernel.org>
Link: https://lore.kernel.org/r/20240304174952.1.I920a314049b345efd1f69d708e7f74d2213d0b49@changeid
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-03 15:28:43 +02:00
..
hvc hvc/xen: fix event channel handling for secondary consoles 2023-11-28 17:19:57 +00:00
ipwireless tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
serdev tty: make counts in tty_port_client_operations hooks size_t 2023-08-11 21:12:44 +02:00
serial Revert "tty: serial: simplify qcom_geni_serial_send_chunk_fifo()" 2024-04-03 15:28:43 +02:00
vt vt: fix unicode buffer corruption when deleting characters 2024-04-03 15:28:43 +02:00
Kconfig Merge commit b320441c04 ("Merge tag 'tty-6.5-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty") into tty-next 2023-08-20 14:29:37 +02:00
Makefile
amiserial.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
ehv_bytechan.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
goldfish.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
mips_ejtag_fdc.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
moxa.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
mxser.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
n_gsm.c tty: n_gsm: fix race condition in status line change on dead connections 2023-11-08 11:56:22 +01:00
n_hdlc.c tty: ldops: unify to u8 2023-08-11 21:12:47 +02:00
n_null.c tty: ldops: unify to u8 2023-08-11 21:12:47 +02:00
n_tty.c tty: n_tty: deduplicate copy code in n_tty_receive_buf_real_raw() 2023-08-27 11:46:52 +02:00
nozomi.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
pty.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
rpmsg_tty.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
synclink_gt.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
sysrq.c tty/sysrq: replace smp_processor_id() with get_cpu() 2023-11-28 17:19:57 +00:00
tty.h tty: audit: unify to u8 2023-08-11 21:12:46 +02:00
tty_audit.c tty: audit: unify to u8 2023-08-11 21:12:46 +02:00
tty_baudrate.c
tty_buffer.c tty: tty_buffer: invert conditions in __tty_buffer_request_room() 2023-08-22 14:58:16 +02:00
tty_io.c usb: cdc-acm: return correct error code on unsupported break 2024-01-25 15:35:53 -08:00
tty_ioctl.c tty: allow TIOCSLCKTRMIOS with CAP_CHECKPOINT_RESTORE 2024-02-05 20:14:32 +00:00
tty_jobctrl.c tty: tty_jobctrl: fix pid memleak in disassociate_ctty() 2023-11-20 11:59:25 +01:00
tty_ldisc.c
tty_ldsem.c
tty_mutex.c
tty_port.c tty: use u8 for flags 2023-08-11 21:12:45 +02:00
ttynull.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
vcc.c tty: vcc: Add check for kstrdup() in vcc_probe() 2023-11-28 17:19:45 +00:00