[RHEL7,COMMIT] vtty: possible ERR_PTR dereferencing in vtty_open_master

Submitted by Konstantin Khorenko on June 3, 2020, 10:10 a.m.

Details

Message ID 202006031010.053AAXSr030209@finist-ce7.sw.ru
State New
Series "Revert "xfs: catch bad stripe alignment configurations""
Headers show

Commit Message

Konstantin Khorenko June 3, 2020, 10:10 a.m.
The commit is pushed to "branch-rh7-3.10.0-1127.8.2.vz7.151.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.8.2.vz7.151.11
------>
commit 3b28361b1c11898a9224bb922d7ea262d1747171
Author: Vasily Averin <vvs@virtuozzo.com>
Date:   Sun May 31 16:23:28 2020 +0300

    vtty: possible ERR_PTR dereferencing in vtty_open_master
    
    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);