Skip to contentSkip to conversation

libxl: handle read-only drives with qemu-xen

PATCH Superseded Stefano Stabellini 3 participants 6 messages Sep 11, 2015 – Sep 14, 2015 1 message not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: handle read-only drives with qemu-xen

The current libxl code doesn't deal with read-only drives at all.

Upstream QEMU and qemu-xen only support read-only cdrom drives: make sure to specify "readonly=on" for cdrom drives and return error in case the user requested a non-cdrom read-only drive.

---
 tools/libxl/libxl_dm.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
tools/libxl/libxl_dm.c +9 -4
index 02c0162..468ff9c 100644
@@ -1110,13 +1110,18 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
             if (disks[i].is_cdrom) {
                 if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY)
                     drive = libxl__sprintf
-                        (gc, "if=ide,index=%d,media=cdrom,cache=writeback,id=ide-%i",
-                         disk, dev_number);
+                        (gc, "if=ide,index=%d,readonly=%s,media=cdrom,cache=writeback,id=ide-%i",
+                         disk, disks[i].readwrite ? "off" : "on", dev_number);
                 else
                     drive = libxl__sprintf
-                        (gc, "file=%s,if=ide,index=%d,media=cdrom,format=%s,cache=writeback,id=ide-%i",
-                         disks[i].pdev_path, disk, format, dev_number);
+                        (gc, "file=%s,if=ide,index=%d,readonly=%s,media=cdrom,format=%s,cache=writeback,id=ide-%i",
+                         disks[i].pdev_path, disk, disks[i].readwrite ? "off" : "on", format, dev_number);
             } else {
+                if (!disks[i].readwrite) {
+                    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "QEMU doesn't support read-only disk drivers");
+                    return ERROR_INVAL;
+                }
+
                 if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY) {
                     LIBXL__LOG(ctx, LIBXL__LOG_WARNING, "cannot support"
                                " empty disk format for %s", disks[i].vdev);
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 6 lines · Stefano Stabellini

The current libxl code doesn't deal with read-only drives at all.

Upstream QEMU and qemu-xen only support read-only cdrom drives: make sure to specify "readonly=on" for cdrom drives and return error in case the user requested a non-cdrom read-only drive.

The commit message speaks about both upstream QEMU and traditional QEMU, but the code only touches upstream routine. I know that QEMU-trad uses different method to get disk parameters so _args_old is not an option, but perhaps something else is missing? Or is it because QEMU-trad is doing the right thing already?

Quoted 16 lines
---
 tools/libxl/libxl_dm.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
tools/libxl/libxl_dm.c +1 -2
index 02c0162..468ff9c 100644
@@ -1110,13 +1110,18 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
             if (disks[i].is_cdrom) {
                 if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY)
                     drive = libxl__sprintf
-                        (gc, "if=ide,index=%d,media=cdrom,cache=writeback,id=ide-%i",
-                         disk, dev_number);
+                        (gc, "if=ide,index=%d,readonly=%s,media=cdrom,cache=writeback,id=ide-%i",

tools/libxl/libxl_dm.c static int libxl__build_device_model_args_new(libxl__gc *gc, · line 1121

Quoted 10 lines
tools/libxl/libxl_dm.c +5 -2
+                         disk, disks[i].readwrite ? "off" : "on", dev_number);
                 else
                     drive = libxl__sprintf
-                        (gc, "file=%s,if=ide,index=%d,media=cdrom,format=%s,cache=writeback,id=ide-%i",
-                         disks[i].pdev_path, disk, format, dev_number);
+                        (gc, "file=%s,if=ide,index=%d,readonly=%s,media=cdrom,format=%s,cache=writeback,id=ide-%i",
+                         disks[i].pdev_path, disk, disks[i].readwrite ? "off" : "on", format, dev_number);
             } else {
+                if (!disks[i].readwrite) {
+                    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "QEMU doesn't support read-only disk drivers");

I think the "new" way of doing thing is to use LOG() macro. But for the sake of consistency I think this is fine.

I shall look into writing a spatch to covert all LIBXL__LOG macros to LOG.

Wei.

Quoted 8 lines
tools/libxl/libxl_dm.c +3 -0
+                    return ERROR_INVAL;
+                }
+
                 if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY) {
                     LIBXL__LOG(ctx, LIBXL__LOG_WARNING, "cannot support"
                                " empty disk format for %s", disks[i].vdev);
Signature · 1 line
1.7.10.4
#2 lore raw
Quoted 8 lines · Wei Liu
Quoted 6 lines · Stefano Stabellini

The current libxl code doesn't deal with read-only drives at all.

Upstream QEMU and qemu-xen only support read-only cdrom drives: make sure to specify "readonly=on" for cdrom drives and return error in case the user requested a non-cdrom read-only drive.

Quoted 5 lines

The commit message speaks about both upstream QEMU and traditional QEMU, but the code only touches upstream routine. I know that QEMU-trad uses different method to get disk parameters so _args_old is not an option, but perhaps something else is missing? Or is it because QEMU-trad is doing the right thing already?

I know that QEMU naming is very confusing, but qemu-xen is the upstream QEMU based tree which xen-unstable uses. We are only talking about upstream QEMU based trees here.

Quoted 44 lines
Quoted 16 lines
---
 tools/libxl/libxl_dm.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
tools/libxl/libxl_dm.c +1 -2
index 02c0162..468ff9c 100644
@@ -1110,13 +1110,18 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
             if (disks[i].is_cdrom) {
                 if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY)
                     drive = libxl__sprintf
-                        (gc, "if=ide,index=%d,media=cdrom,cache=writeback,id=ide-%i",
-                         disk, dev_number);
+                        (gc, "if=ide,index=%d,readonly=%s,media=cdrom,cache=writeback,id=ide-%i",

tools/libxl/libxl_dm.c static int libxl__build_device_model_args_new(libxl__gc *gc, · line 1121

Quoted 10 lines
tools/libxl/libxl_dm.c +5 -2
+                         disk, disks[i].readwrite ? "off" : "on", dev_number);
                 else
                     drive = libxl__sprintf
-                        (gc, "file=%s,if=ide,index=%d,media=cdrom,format=%s,cache=writeback,id=ide-%i",
-                         disks[i].pdev_path, disk, format, dev_number);
+                        (gc, "file=%s,if=ide,index=%d,readonly=%s,media=cdrom,format=%s,cache=writeback,id=ide-%i",
+                         disks[i].pdev_path, disk, disks[i].readwrite ? "off" : "on", format, dev_number);
             } else {
+                if (!disks[i].readwrite) {
+                    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "QEMU doesn't support read-only disk drivers");

I think the "new" way of doing thing is to use LOG() macro. But for the sake of consistency I think this is fine.

I shall look into writing a spatch to covert all LIBXL__LOG macros to LOG.

Wei.

Quoted 8 lines
tools/libxl/libxl_dm.c +3 -0
+                    return ERROR_INVAL;
+                }
+
                 if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY) {
                     LIBXL__LOG(ctx, LIBXL__LOG_WARNING, "cannot support"
                                " empty disk format for %s", disks[i].vdev);
Signature · 1 line
1.7.10.4
Acked-by
#3 lore raw
Quoted 15 lines · Stefano Stabellini
Quoted 8 lines · Wei Liu
Quoted 6 lines · Stefano Stabellini

The current libxl code doesn't deal with read-only drives at all.

Upstream QEMU and qemu-xen only support read-only cdrom drives: make sure to specify "readonly=on" for cdrom drives and return error in case the user requested a non-cdrom read-only drive.

Quoted 5 lines

The commit message speaks about both upstream QEMU and traditional QEMU, but the code only touches upstream routine. I know that QEMU-trad uses different method to get disk parameters so _args_old is not an option, but perhaps something else is missing? Or is it because QEMU-trad is doing the right thing already?

Quoted 4 lines

I know that QEMU naming is very confusing, but qemu-xen is the upstream QEMU based tree which xen-unstable uses. We are only talking about upstream QEMU based trees here.

Ah, alright. Sorry for the noise.

#4 lore raw
In reply to Stefano Stabellini

Stefano Stabellini writes ("[PATCH for-4.6] libxl: handle read-only drives with qemu-xen"):

Quoted 5 lines

The current libxl code doesn't deal with read-only drives at all.

Upstream QEMU and qemu-xen only support read-only cdrom drives: make sure to specify "readonly=on" for cdrom drives and return error in case the user requested a non-cdrom read-only drive.

This should have:

* an XSA
* a credit

tools/libxl/libxl_dm.c static int libxl__build_device_model_args_new(libxl__gc *gc, · line 1122

Quoted 3 lines
tools/libxl/libxl_dm.c +3 -0
+                if (!disks[i].readwrite) {
+                    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "QEMU doesn't support read-only disk drivers");
+                    return ERROR_INVAL;

This message should refer to `qemu-xen' specifically. The user can get the desired behaviour by going back to qemu-xen-traditional...

Ian.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: writing to read only scsi drives [and 1 more messages]

M A Young writes ("writing to read only scsi drives"):

Quoted 6 lines

I thought I would check here in case this is a new security issue but it was reported at https://bugzilla.redhat.com/show_bug.cgi?id=1257893 that in HVM guests it was possible to write to scsi devices (either specified as sda etc. in the configuration file or in a scsi device if the guest kernel is booted with the xen_emul_unplug=never option) that were specified as read only in the xl configuration file.

Thanks for passing this on.

This does not appear to be limited to SCSI. Stefano has kindly prepared a patch. (See below for the current draft of that patch.)

I have assigned this issue Xen Security Advisory number 142. There will be no embargo because the issue is already public.

I am going to do some more tests to understand the scope of the problem.

Ian.

Stefano Stabellini writes ("[PATCH for-4.6] libxl: handle read-only drives with qemu-xen"):

Quoted 41 lines

The current libxl code doesn't deal with read-only drives at all.

Upstream QEMU and qemu-xen only support read-only cdrom drives: make sure to specify "readonly=on" for cdrom drives and return error in case the user requested a non-cdrom read-only drive.

---
 tools/libxl/libxl_dm.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
tools/libxl/libxl_dm.c +9 -4
index 02c0162..468ff9c 100644
@@ -1110,13 +1110,18 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
             if (disks[i].is_cdrom) {
                 if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY)
                     drive = libxl__sprintf
-                        (gc, "if=ide,index=%d,media=cdrom,cache=writeback,id=ide-%i",
-                         disk, dev_number);
+                        (gc, "if=ide,index=%d,readonly=%s,media=cdrom,cache=writeback,id=ide-%i",
+                         disk, disks[i].readwrite ? "off" : "on", dev_number);
                 else
                     drive = libxl__sprintf
-                        (gc, "file=%s,if=ide,index=%d,media=cdrom,format=%s,cache=writeback,id=ide-%i",
-                         disks[i].pdev_path, disk, format, dev_number);
+                        (gc, "file=%s,if=ide,index=%d,readonly=%s,media=cdrom,format=%s,cache=writeback,id=ide-%i",
+                         disks[i].pdev_path, disk, disks[i].readwrite ? "off" : "on", format, dev_number);
             } else {
+                if (!disks[i].readwrite) {
+                    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "QEMU doesn't support read-only disk drivers");
+                    return ERROR_INVAL;
+                }
+
                 if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY) {
                     LIBXL__LOG(ctx, LIBXL__LOG_WARNING, "cannot support"
                                " empty disk format for %s", disks[i].vdev);
Signature · 1 line
1.7.10.4