[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] xenconsole: adjust pty opening error checking and handling



commit 2d97f52713c3850bd3d6d865697a7738a98540aa
Author:     Matthew Daley <mattd@xxxxxxxxxxx>
AuthorDate: Sat Dec 14 14:04:47 2013 +1300
Commit:     Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
CommitDate: Mon Dec 16 11:55:22 2013 +0000

    xenconsole: adjust pty opening error checking and handling
    
    Currently we check the pty path received from xenstore with access(); if
    it indicates that the pty is not accessible, we loop around and wait for
    a new path to appear in xenstore.
    
    This has several issues:
    * If a path has been written to xenstore, it can be assumed that that
      pty should already be accessible to xenconsole, and hence any error
      that occurs while trying to open it should be fatal and not ignored
    * If access() indicates no access to the pty, the memory allocated for
      the path is leaked when going around the loop again
    * The accessibility of the pty could change between the access() and
      open() calls, leading to a TOCTOU race (this is what Coverity is
      complaining about).
    
    By removing the explicit access() check and just erroring out whenever
    open() fails, we fix all these issues.
    
    Coverity-ID: 1056047
    Signed-off-by: Matthew Daley <mattd@xxxxxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/console/client/main.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/tools/console/client/main.c b/tools/console/client/main.c
index 38c856a..3242008 100644
--- a/tools/console/client/main.c
+++ b/tools/console/client/main.c
@@ -116,12 +116,9 @@ static int get_pty_fd(struct xs_handle *xs, char *path, 
int seconds)
                         * disambiguate: just read the pty path */
                        pty_path = xs_read(xs, XBT_NULL, path, &len);
                        if (pty_path != NULL) {
-                               if (access(pty_path, R_OK|W_OK) != 0)
-                                       continue;
                                pty_fd = open(pty_path, O_RDWR | O_NOCTTY);
-                               if (pty_fd == -1) 
-                                       err(errno, "Could not open tty `%s'", 
-                                           pty_path);
+                               if (pty_fd == -1)
+                                       err(errno, "Could not open tty `%s'", 
pty_path);
                                free(pty_path);
                        }
                }
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.