Skip to contentSkip to conversation

libxl: handle read-only drives with qemu-xen

PATCH In review Stefano Stabellini 5 participants 14 messages Sep 15, 2015 – Sep 21, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

This is XSA-142, discovered by Lin Liu
(https://bugzilla.redhat.com/show_bug.cgi?id=1257893).

---
XSA-142 is still unissued at this time

---
 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-xen 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
Acked-by on v2 1/1
#1 lore raw

Stefano Stabellini writes ("[PATCH v2 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.

I have determined by experiment that cdroms are always marked readonly. My qemu-dm opened a test iso, which I had expressed to be passed as a cdrom, readonly.

So maybe the guest would be able to get qemu to write to it, but this would just result in errors (or maybe a crash somewhere in qemu). I was not able to easily persuade Linux to write to the cdrom device.

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

Quoted 4 lines
tools/libxl/libxl_dm.c +2 -2
-                        (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);

I don't know what the effect of this would be on qemu iff readwrite==0. I think it might be ineffective. But that is certainly not a security problem.

I have just sent a draft of the advisory.

Ian.

#2 lore raw
Quoted 9 lines · Ian Jackson

Stefano Stabellini writes ("[PATCH v2 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.

I applied to staging and staging-4.6 with this Ack and Wei's say so elsewhere.

#3 lore raw
In reply to Stefano Stabellini

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

Quoted 6 lines · Stefano Stabellini
             } else {
tools/libxl/libxl_dm.c +5 -0
+                if (!disks[i].readwrite) {
+                    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "qemu-xen doesn't support read-only disk drivers");
+                    return ERROR_INVAL;
+                }
+

Is ERROR_INVAL the right error to return? I get

libxl_dm.c: In function 'libxl__build_device_model_args_new':
libxl_dm.c:807:28: error: return makes pointer from integer without a cast [-Werror=int-conversion]

                     return ERROR_INVAL;
                            ^

cc1: all warnings being treated as errors

when I try to build xen with the proposed patch. NULL is returned when there is a problem in other places in this function.

Michael Young

#4 lore raw

M A Young writes ("Re: [PATCH v2 for-4.6] libxl: handle read-only drives with qemu-xen"):

Quoted 9 lines · Stefano Stabellini

Is ERROR_INVAL the right error to return? I get

libxl_dm.c: In function 'libxl__build_device_model_args_new':
libxl_dm.c:807:28: error: return makes pointer from integer without a cast [-Werror=int-conversion]

                     return ERROR_INVAL;
                            ^

cc1: all warnings being treated as errors

Yikes.

Quoted 2 lines

when I try to build xen with the proposed patch. NULL is returned when there is a problem in other places in this function.

Clearly not.

Stefano, do you want to respin ?

Ian.

Acked-by
#5 lore raw
Quoted 15 lines · Ian Jackson

M A Young writes ("Re: [PATCH v2 for-4.6] libxl: handle read-only drives with qemu-xen"):

Quoted 10 lines · Stefano Stabellini

Is ERROR_INVAL the right error to return? I get

libxl_dm.c: In function 'libxl__build_device_model_args_new':
libxl_dm.c:807:28: error: return makes pointer from integer without a cast
[-Werror=int-conversion]

                     return ERROR_INVAL;
                            ^

cc1: all warnings being treated as errors

Yikes.

Quoted 8 lines
Quoted 2 lines

when I try to build xen with the proposed patch. NULL is returned when there is a problem in other places in this function.

Clearly not.

Stefano, do you want to respin ?

From the other subthread it seems this is down to:

commit de214e9f93de57fb5239e958372f314d29d3f7a9
Author: Olaf Hering < [email protected] >
Date: Mon Apr 20 13:40:31 2015 +0000

libxl: pass environment to device model

Prepare device-model setup functions to pass also environment variables to the spawned process. This is required for upcoming changes which will set DISPLAY and XAUTHORITY for SDL.

Cc Ian Jackson < [email protected] >
Cc Stefano Stabellini < [email protected] >
Cc Ian Campbell < [email protected] >
Cc Wei Liu < [email protected] >

which is 4.6 but not in 4.5 (where Michael was applying). So I think this is just an issue for backport (should return NULL instead) and not for applying now.

So shall we go ahead with this for 4.6 or is there more testing/discussion/whatever needed?

Ian.

#6 lore raw
Quoted 42 lines · Ian Campbell
Quoted 13 lines · Ian Jackson

M A Young writes ("Re: [PATCH v2 for-4.6] libxl: handle read-only drives with qemu-xen"):

Quoted 10 lines · Stefano Stabellini

Is ERROR_INVAL the right error to return? I get

libxl_dm.c: In function 'libxl__build_device_model_args_new':
libxl_dm.c:807:28: error: return makes pointer from integer without a cast
[-Werror=int-conversion]

                     return ERROR_INVAL;
                            ^

cc1: all warnings being treated as errors

Quoted 8 lines

Yikes.

Quoted 2 lines

when I try to build xen with the proposed patch. NULL is returned when there is a problem in other places in this function.

Clearly not.

Stefano, do you want to respin ?

From the other subthread it seems this is down to:

commit de214e9f93de57fb5239e958372f314d29d3f7a9
Author: Olaf Hering < [email protected] >
Date: Mon Apr 20 13:40:31 2015 +0000

libxl: pass environment to device model

Prepare device-model setup functions to pass also environment variables to the spawned process. This is required for upcoming changes which will set DISPLAY and XAUTHORITY for SDL.

Cc Ian Jackson < [email protected] >
Cc Stefano Stabellini < [email protected] >
Cc Ian Campbell < [email protected] >
Cc Wei Liu < [email protected] >
Quoted 6 lines

which is 4.6 but not in 4.5 (where Michael was applying). So I think this is just an issue for backport (should return NULL instead) and not for applying now.

So shall we go ahead with this for 4.6 or is there more testing/discussion/whatever needed?

There is an update in the bugzilla report (testing 4.5 with NULL returned) at https://bugzilla.redhat.com/show_bug.cgi?id=1257893#c9
querying whether xvd? read-only drives should work. I think the answer is still no, but I should at least mention the question here.

Michael Young

#7 lore raw
In reply to Ian Campbell
Quoted 42 lines · Ian Campbell
Quoted 15 lines · Ian Jackson

M A Young writes ("Re: [PATCH v2 for-4.6] libxl: handle read-only drives with qemu-xen"):

Quoted 10 lines · Stefano Stabellini

Is ERROR_INVAL the right error to return? I get

libxl_dm.c: In function 'libxl__build_device_model_args_new':
libxl_dm.c:807:28: error: return makes pointer from integer without a cast
[-Werror=int-conversion]

                     return ERROR_INVAL;
                            ^

cc1: all warnings being treated as errors

Yikes.

Quoted 8 lines
Quoted 2 lines

when I try to build xen with the proposed patch. NULL is returned when there is a problem in other places in this function.

Clearly not.

Stefano, do you want to respin ?

From the other subthread it seems this is down to:

commit de214e9f93de57fb5239e958372f314d29d3f7a9
Author: Olaf Hering < [email protected] >
Date: Mon Apr 20 13:40:31 2015 +0000

libxl: pass environment to device model

Prepare device-model setup functions to pass also environment variables to the spawned process. This is required for upcoming changes which will set DISPLAY and XAUTHORITY for SDL.

Cc Ian Jackson < [email protected] >
Cc Stefano Stabellini < [email protected] >
Cc Ian Campbell < [email protected] >
Cc Wei Liu < [email protected] >
Quoted 7 lines

which is 4.6 but not in 4.5 (where Michael was applying). So I think this is just an issue for backport (should return NULL instead) and not for applying now.

So shall we go ahead with this for 4.6 or is there more testing/discussion/whatever needed?

Yes, of course.

Wei.

Quoted 1 line

Ian.

#8 lore raw
Quoted 54 lines · Wei Liu
Quoted 53 lines · Ian Campbell
Quoted 21 lines · Ian Jackson

M A Young writes ("Re: [PATCH v2 for-4.6] libxl: handle read-only drives
with qemu-xen"):

Quoted 11 lines · Stefano Stabellini

Is ERROR_INVAL the right error to return? I get

libxl_dm.c: In function 'libxl__build_device_model_args_new':
libxl_dm.c:807:28: error: return makes pointer from integer without a
cast
[-Werror=int-conversion]

                     return ERROR_INVAL;
                            ^

cc1: all warnings being treated as errors

Yikes.

Quoted 3 lines

when I try to build xen with the proposed patch. NULL is returned when
there is a problem in other places in this function.

Quoted 5 lines

Clearly not.

Stefano, do you want to respin ?

From the other subthread it seems this is down to:

commit de214e9f93de57fb5239e958372f314d29d3f7a9
Author: Olaf Hering < [email protected] >
Date: Mon Apr 20 13:40:31 2015 +0000

libxl: pass environment to device model

Prepare device-model setup functions to pass also environment
variables
to the spawned process. This is required for upcoming changes
which will
set DISPLAY and XAUTHORITY for SDL.

Cc Ian Jackson < [email protected] >
Cc Stefano Stabellini < [email protected]
Quoted 1 line

which is 4.6 but not in 4.5 (where Michael was applying). So I think this
is just an issue for backport (should return NULL instead) and not for applying now.

Quoted 5 lines
Quoted 3 lines

So shall we go ahead with this for 4.6 or is there more testing/discussion/whatever needed?

Yes, of course.

"Yes, of course, go ahead" or "Yes, of course, more testing/discusion/whatever is needed" ?

Yes is not a helpful answer to a question which offers a choice ;-)

Ian.

#9 lore raw

On Thu, Sep 17, 2015 at 12:49:41PM +0100, Ian Campbell wrote:
[...]

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

So shall we go ahead with this for 4.6 or is there more testing/discussion/whatever needed?

Yes, of course.

"Yes, of course, go ahead" or "Yes, of course, more testing/discusion/whatever is needed" ?

Yes is not a helpful answer to a question which offers a choice ;-)

I think this patch should be applied to 4.6 and staging. The patch itself is correct.

Wei.

Quoted 1 line

Ian.

#10 lore raw
In reply to Ian Campbell

Ian Campbell writes ("Re: [PATCH v2 for-4.6] libxl: handle read-only drives with qemu-xen"):

Quoted 2 lines

So shall we go ahead with this for 4.6 or is there more testing/discussion/whatever needed?

I think we can commit it to 4.6. I would like to issue the actual advisory though.

I see no-one commented.

It is definitely wrong at least in that it asserts that the same patch works for 4.5. Would anyone care to supply a patch for 4.5 and earlier or shall I prepare one ?

Ian.

#11 lore raw
Quoted 5 lines · Ian Jackson

Ian Campbell writes ("Re: [PATCH v2 for-4.6] libxl: handle read-only drives with qemu-xen"):

Quoted 2 lines

So shall we go ahead with this for 4.6 or is there more testing/discussion/whatever needed?

Quoted 8 lines

I think we can commit it to 4.6. I would like to issue the actual advisory though.

I see no-one commented.

It is definitely wrong at least in that it asserts that the same patch works for 4.5. Would anyone care to supply a patch for 4.5 and earlier or shall I prepare one ?

I think it should be just s/ERROR_FOO/NULL/g?

Quoted 2 lines

Ian.

#12 lore raw
In reply to M A Young
Quoted 14 lines · M A Young

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

Quoted 6 lines · Stefano Stabellini
             } else {
tools/libxl/libxl_dm.c +5 -0
+                if (!disks[i].readwrite) {
+                    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "qemu-xen doesn't support read-only disk drivers");
+                    return ERROR_INVAL;
+                }
+

Is ERROR_INVAL the right error to return? I get

libxl_dm.c: In function 'libxl__build_device_model_args_new':
libxl_dm.c:807:28: error: return makes pointer from integer without a cast [-Werror=int-conversion]

Quoted 7 lines
                     return ERROR_INVAL;
                            ^

cc1: all warnings being treated as errors

when I try to build xen with the proposed patch. NULL is returned when there is a problem in other places in this function.

I don't follow.

The function in question is libxl__build_device_model_args_new, which returns an integer. And there are other places in that function that return ERROR_*.

Do I miss anything?

Wei.

Quoted 1 line

Michael Young

#13 lore raw
Quoted 25 lines · Wei Liu
Quoted 14 lines · M A Young

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

Quoted 6 lines · Stefano Stabellini
             } else {
tools/libxl/libxl_dm.c +5 -0
+                if (!disks[i].readwrite) {
+                    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "qemu-xen doesn't support read-only disk drivers");
+                    return ERROR_INVAL;
+                }
+

Is ERROR_INVAL the right error to return? I get

libxl_dm.c: In function 'libxl__build_device_model_args_new':
libxl_dm.c:807:28: error: return makes pointer from integer without a cast [-Werror=int-conversion]

Quoted 7 lines
                     return ERROR_INVAL;
                            ^

cc1: all warnings being treated as errors

when I try to build xen with the proposed patch. NULL is returned when there is a problem in other places in this function.

I don't follow.

Quoted 7 lines

The function in question is libxl__build_device_model_args_new, which returns an integer. And there are other places in that function that return ERROR_*.

Do I miss anything?

Wei.

Hang on, I think it is a case of 4.6 != 4.5 (which is what I was building on). So we probably just need a fixed version for earlier versions of xen.

Michael Young