[PATCH v2 1/2] tty: fix compat TIOCGSERIAL leaking uninitialized memory

From: Eric Biggers
Date: Mon Feb 24 2020 - 13:22:01 EST


From: Eric Biggers <ebiggers@xxxxxxxxxx>

Commit 77654350306a ("take compat TIOC[SG]SERIAL treatment into
tty_compat_ioctl()") changed the compat version of TIOCGSERIAL to start
copying a whole 'serial_struct32' to userspace rather than individual
fields, but failed to initialize all padding and fields -- namely the
hole after the 'iomem_reg_shift' field, and the 'reserved' field.

Fix this by initializing the struct to zero.

[v2: use sizeof, and convert the adjacent line for consistency.]

Reported-by: syzbot+8da9175e28eadcb203ce@xxxxxxxxxxxxxxxxxxxxxxxxx
Fixes: 77654350306a ("take compat TIOC[SG]SERIAL treatment into tty_compat_ioctl()")
Cc: <stable@xxxxxxxxxxxxxxx> # v4.20+
Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
---
drivers/tty/tty_io.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 1fcf7ad83dfa0a..db4a13bc855ed6 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2730,7 +2730,9 @@ static int compat_tty_tiocgserial(struct tty_struct *tty,
struct serial_struct32 v32;
struct serial_struct v;
int err;
- memset(&v, 0, sizeof(struct serial_struct));
+
+ memset(&v, 0, sizeof(v));
+ memset(&v32, 0, sizeof(v32));

if (!tty->ops->set_serial)
return -ENOTTY;
--
2.25.0.265.gbab2e86ba0-goog