[Devel] [PATCH RH7 v2] vtty: possible ERR_PTR dereferencing in vtty_open_master

Konstantin Khorenko khorenko at virtuozzo.com
Mon Jun 1 18:37:52 MSK 2020


From: Vasily Averin <vvs at 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 at virtuozzo.com>
Acked-by: Konstantin Khorenko <khorenko at virtuozzo.com>

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

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);
-- 
2.15.1



More information about the Devel mailing list