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: <sta...@vger.kernel.org>
Reported-by: Mateusz Guzik <mgu...@redhat.com>
Signed-off-by: Amit Shah <amit.s...@redhat.com>
---
 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

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Reply via email to