Mateusz Guzik points out that we update the 'file' struct's private_data
field before we've successfully done all our checks.  This means we can
return an error with the private_data field updated.  This could lead to
problems.

Fix by moving the assignment after all checks are done.

CC: <[email protected]>
Reported-by: Mateusz Guzik <[email protected]>
Signed-off-by: Amit Shah <[email protected]>
---
 drivers/char/virtio_console.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index a39702a..7728af9 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1032,7 +1032,6 @@ static int port_fops_open(struct inode *inode, struct 
file *filp)
                /* Port was unplugged before we could proceed */
                return -ENXIO;
        }
-       filp->private_data = port;
 
        /*
         * Don't allow opening of console port devices -- that's done
@@ -1051,6 +1050,7 @@ static int port_fops_open(struct inode *inode, struct 
file *filp)
                goto out;
        }
 
+       filp->private_data = port;
        port->guest_connected = true;
        spin_unlock_irq(&port->inbuf_lock);
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to