[RH7,v2] vtty: possible ERR_PTR dereferencing in vtty_open_master

Submitted by Konstantin Khorenko on June 1, 2020, 3:37 p.m.

Details

Message ID 20200601153752.25406-1-khorenko@virtuozzo.com
State New
Series "vtty: possible ERR_PTR dereferencing in vtty_open_master"
Headers show

Commit Message

Konstantin Khorenko June 1, 2020, 3:37 p.m.
From: Vasily Averin <vvs@virtuozzo.com>

found by swatch:
drivers/tty/pty.c:1306 vtty_open_master() error:
 'tty' dereferencing possible ERR_PTR()

Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Acked-by: Konstantin Khorenko <khorenko@virtuozzo.com>

v2: do set proper "ret" values on error paths
---
 drivers/tty/pty.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 698717e590503..17c5f51734762 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -1294,10 +1294,17 @@  int vtty_open_master(envid_t veid, int idx)
 	vtty_set_context(veid);
 
 	tty = vtty_lookup(vttym_driver, NULL, idx);
+	if (IS_ERR(tty)) {
+		ret = PTR_ERR(tty);
+		goto err_install;
+	}
+
 	if (!tty) {
 		tty = tty_init_dev(vttys_driver, idx);
-		if (IS_ERR(tty))
+		if (IS_ERR(tty)) {
+			ret = PTR_ERR(tty);
 			goto err_install;
+		}
 		tty->count--;
 		tty_unlock(tty);
 		tty_set_lock_subclass(tty);