Skip to contentSkip to conversation

qga umask fix addenda

PATCH Applied Laszlo Ersek 5 participants 10 messages May 8, 2013 – May 13, 2013

lore
Share & tools
lore
#0 lore raw

v2 cover qga umask fix addenda

I should have paid more attention to portability and error path cleanup in the CVE-2013-2007 fix.

(We continue to assume, like the rest of qemu code, that qemu_set_cloexec() never fails internally. This should be a reasonable assumption when the input fd is valid.)

Laszlo Ersek (2):
qga: distinguish binary modes in "guest_file_open_modes" map
qga: unlink just created guest-file if fchmod() or fdopen() fails on
it

 qga/commands-posix.c |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)
#1 lore raw

PATCH v2 1/2 qga: distinguish binary modes in "guest_file_open_modes" map

In Windows guests this may make a difference.

Since the original patch (commit c689b4f1) sought to be pedantic and to consider theoretical corner cases of portability, we should fix it up where it failed to come through in that pursuit.

---
 qga/commands-posix.c |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)
qga/commands-posix.c +16 -6
index 04c6951..2eec712 100644
@@ -242,17 +242,27 @@ static GuestFileHandle *guest_file_handle_find(int64_t id, Error **err)
 
 typedef const char * const ccpc;
 
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 /* http://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html */
 static const struct {
     ccpc *forms;
     int oflag_base;
 } guest_file_open_modes[] = {
-    { (ccpc[]){ "r",  "rb",         NULL }, O_RDONLY                      },
-    { (ccpc[]){ "w",  "wb",         NULL }, O_WRONLY | O_CREAT | O_TRUNC  },
-    { (ccpc[]){ "a",  "ab",         NULL }, O_WRONLY | O_CREAT | O_APPEND },
-    { (ccpc[]){ "r+", "rb+", "r+b", NULL }, O_RDWR                        },
-    { (ccpc[]){ "w+", "wb+", "w+b", NULL }, O_RDWR   | O_CREAT | O_TRUNC  },
-    { (ccpc[]){ "a+", "ab+", "a+b", NULL }, O_RDWR   | O_CREAT | O_APPEND }
+    { (ccpc[]){ "r",          NULL }, O_RDONLY                                 },
+    { (ccpc[]){ "rb",         NULL }, O_RDONLY                      | O_BINARY },
+    { (ccpc[]){ "w",          NULL }, O_WRONLY | O_CREAT | O_TRUNC             },
+    { (ccpc[]){ "wb",         NULL }, O_WRONLY | O_CREAT | O_TRUNC  | O_BINARY },
+    { (ccpc[]){ "a",          NULL }, O_WRONLY | O_CREAT | O_APPEND            },
+    { (ccpc[]){ "ab",         NULL }, O_WRONLY | O_CREAT | O_APPEND | O_BINARY },
+    { (ccpc[]){ "r+",         NULL }, O_RDWR                                   },
+    { (ccpc[]){ "rb+", "r+b", NULL }, O_RDWR                        | O_BINARY },
+    { (ccpc[]){ "w+",         NULL }, O_RDWR   | O_CREAT | O_TRUNC             },
+    { (ccpc[]){ "wb+", "w+b", NULL }, O_RDWR   | O_CREAT | O_TRUNC  | O_BINARY },
+    { (ccpc[]){ "a+",         NULL }, O_RDWR   | O_CREAT | O_APPEND            },
+    { (ccpc[]){ "ab+", "a+b", NULL }, O_RDWR   | O_CREAT | O_APPEND | O_BINARY }
 };
 
 static int
Signature · 1 line
1.7.1
#2 lore raw

PATCH v2 2/2 qga: unlink just created guest-file if fchmod() or fdopen() fails on it

In reply to Laszlo Ersek

We shouldn't allow guest filesystem pollution on error paths.

---
 qga/commands-posix.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
qga/commands-posix.c +3 -0
index 2eec712..e199738 100644
@@ -355,6 +355,9 @@ safe_open_or_create(const char *path, const char *mode, Error **err)
             }
 
             close(fd);
+            if (oflag & O_CREAT) {
+                unlink(path);
+            }
         }
     }
 
Signature · 1 line
1.7.1
Reviewed-by on v2 2/2
#3 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] qga: unlink just created guest-file if fchmod() or fdopen() fails on it

Quoted 7 lines · Laszlo Ersek

We shouldn't allow guest filesystem pollution on error paths.

---
 qga/commands-posix.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Quoted 16 lines
qga/commands-posix.c +3 -0
index 2eec712..e199738 100644
@@ -355,6 +355,9 @@ safe_open_or_create(const char *path, const char *mode, Error **err)
             }
 
             close(fd);
+            if (oflag & O_CREAT) {
+                unlink(path);
+            }
         }
     }
 
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on the v2 series
#4 lore raw
In reply to Laszlo Ersek
Quoted 6 lines · On Wed, 8 May 2013 17:31:34 +0200 Laszlo Ersek <[email protected]> wrote:

I should have paid more attention to portability and error path cleanup in the CVE-2013-2007 fix.

(We continue to assume, like the rest of qemu code, that qemu_set_cloexec() never fails internally. This should be a reasonable assumption when the input fd is valid.)

Series:

Quoted 10 lines

Laszlo Ersek (2):
qga: distinguish binary modes in "guest_file_open_modes" map
qga: unlink just created guest-file if fchmod() or fdopen() fails on
it

 qga/commands-posix.c |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)
Applied
#5 lore raw
In reply to Laszlo Ersek
Quoted 11 lines · Laszlo Ersek

I should have paid more attention to portability and error path cleanup in the CVE-2013-2007 fix.

(We continue to assume, like the rest of qemu code, that qemu_set_cloexec() never fails internally. This should be a reasonable assumption when the input fd is valid.)

Laszlo Ersek (2):
qga: distinguish binary modes in "guest_file_open_modes" map
qga: unlink just created guest-file if fchmod() or fdopen() fails on
it

Thanks, applied to qga branch:

https://github.com/mdroth/qemu/commits/qga

Quoted 4 lines
 qga/commands-posix.c |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)
#6 lore raw
Quoted 8 lines · mdroth
Quoted 7 lines · Laszlo Ersek

I should have paid more attention to portability and error path cleanup in the CVE-2013-2007 fix.

(We continue to assume, like the rest of qemu code, that qemu_set_cloexec() never fails internally. This should be a reasonable assumption when the input fd is valid.)

Quoted 8 lines
Quoted 4 lines

Laszlo Ersek (2):
qga: distinguish binary modes in "guest_file_open_modes" map
qga: unlink just created guest-file if fchmod() or fdopen() fails on
it

Thanks, applied to qga branch:

https://github.com/mdroth/qemu/commits/qga

Thanks!

Can you reword the second commit to include Eric's R-b?
<http://lists.nongnu.org/archive/html/qemu-devel/2013-05/msg01179.html>

Thanks!
Laszlo

#7 lore raw
Quoted 14 lines · Laszlo Ersek
Quoted 13 lines · mdroth
Quoted 11 lines · Laszlo Ersek

I should have paid more attention to portability and error path cleanup in the CVE-2013-2007 fix.

(We continue to assume, like the rest of qemu code, that qemu_set_cloexec() never fails internally. This should be a reasonable assumption when the input fd is valid.)

Laszlo Ersek (2):
qga: distinguish binary modes in "guest_file_open_modes" map
qga: unlink just created guest-file if fchmod() or fdopen() fails on
it

Quoted 8 lines
Quoted 3 lines

Thanks, applied to qga branch:

https://github.com/mdroth/qemu/commits/qga

Thanks!

Can you reword the second commit to include Eric's R-b?
<http://lists.nongnu.org/archive/html/qemu-devel/2013-05/msg01179.html>

Sure, missed that one. Should be fixed in tree now.

Quoted 4 lines

Thanks!
Laszlo

#8 lore raw

Am 10.05.2013 22:09, schrieb mdroth:

Quoted 17 lines · Laszlo Ersek
Quoted 16 lines · mdroth
Quoted 15 lines · Laszlo Ersek
Quoted 11 lines

I should have paid more attention to portability and error path cleanup in the CVE-2013-2007 fix.

(We continue to assume, like the rest of qemu code, that qemu_set_cloexec() never fails internally. This should be a reasonable assumption when the input fd is valid.)

Laszlo Ersek (2):
qga: distinguish binary modes in "guest_file_open_modes" map
qga: unlink just created guest-file if fchmod() or fdopen() fails on
it

Thanks, applied to qga branch:

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

https://github.com/mdroth/qemu/commits/qga

Thanks!

Can you reword the second commit to include Eric's R-b?
<http://lists.nongnu.org/archive/html/qemu-devel/2013-05/msg01179.html>

Sure, missed that one. Should be fixed in tree now.

Shouldn't at least the unlinking be backported to stable as well?

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#9 lore raw
Quoted 20 lines · Andreas Färber

Am 10.05.2013 22:09, schrieb mdroth:

Quoted 19 lines · Laszlo Ersek
Quoted 18 lines · mdroth
Quoted 16 lines · Laszlo Ersek
Quoted 11 lines

I should have paid more attention to portability and error path cleanup in the CVE-2013-2007 fix.

(We continue to assume, like the rest of qemu code, that qemu_set_cloexec() never fails internally. This should be a reasonable assumption when the input fd is valid.)

Laszlo Ersek (2):
qga: distinguish binary modes in "guest_file_open_modes" map
qga: unlink just created guest-file if fchmod() or fdopen() fails on
it

Thanks, applied to qga branch:

https://github.com/mdroth/qemu/commits/qga

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Thanks!

Can you reword the second commit to include Eric's R-b?
<http://lists.nongnu.org/archive/html/qemu-devel/2013-05/msg01179.html>

Sure, missed that one. Should be fixed in tree now.

Shouldn't at least the unlinking be backported to stable as well?

Yes, these are basically updates to the CVE fix, so I think they should all be applied to stable. I'll send PULL today so hopefully we can get them into 1.5 prior to patch freeze for 1.4.2. Otherwise I'll backport from the qga tree.

Quoted 7 lines

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg