tty: n_gsm: fix buffer over-read in gsm_dlci_data()
authorDaniel Starke <daniel.starke@siemens.com>
Wed, 4 May 2022 08:17:31 +0000 (10:17 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 May 2022 08:26:54 +0000 (10:26 +0200)
commite68de92d2f393cc192c3a857bed4b6e8d6993cdb
treead8d000de4a47d257ace9e944016c8e30fb1bf20
parent99fbf26538365ab141835c05c11e6c2a316169c5
tty: n_gsm: fix buffer over-read in gsm_dlci_data()

commit fd442e5ba30aaa75ea47b32149e7a3110dc20a46 upstream.

'len' is decreased after each octet that has its EA bit set to 0, which
means that the value is encoded with additional octets. However, the final
octet does not decreases 'len' which results in 'len' being one byte too
long. A buffer over-read may occur in tty_insert_flip_string() as it tries
to read one byte more than the passed content size of 'data'.
Decrease 'len' also for the final octet which has the EA bit set to 1 to
write the correct number of bytes from the internal receive buffer to the
virtual tty.

Fixes: 2e124b4a390c ("TTY: switch tty_flip_buffer_push")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
Link: https://lore.kernel.org/r/20220504081733.3494-1-daniel.starke@siemens.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/n_gsm.c