Skip to contentSkip to conversation

qcow2: Prevent backing file names longer than 1023

PATCH Superseded Max Reitz 3 participants 3 messages Apr 6, 2016 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 qcow2: Prevent backing file names longer than 1023

We reject backing file names with a length of more than 1023 characters when opening a qcow2 file, so we should not produce such files ourselves.

---
 block/qcow2.c | 5 +++++
 1 file changed, 5 insertions(+)
block/qcow2.c +5 -0
index 056525c..011a0ae 100644
@@ -1957,6 +1957,11 @@ int qcow2_update_header(BlockDriverState *bs)
     if (s->image_backing_file) {
         size_t backing_file_len = strlen(s->image_backing_file);
 
+        if (backing_file_len > 1023) {
+            ret = -EINVAL;
+            goto fail;
+        }
+
         if (buflen < backing_file_len) {
             ret = -ENOSPC;
             goto fail;
Signature · 1 line
2.8.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Max Reitz

We reject backing file names with a length of more than 1023 characters when opening a qcow2 file, so we should not produce such files ourselves.

---
 block/qcow2.c | 5 +++++
 1 file changed, 5 insertions(+)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
In reply to Max Reitz

Am 06.04.2016 um 17:14 hat Max Reitz geschrieben:

Quoted 16 lines

We reject backing file names with a length of more than 1023 characters when opening a qcow2 file, so we should not produce such files ourselves.

---
 block/qcow2.c | 5 +++++
 1 file changed, 5 insertions(+)
block/qcow2.c +0 -0
index 056525c..011a0ae 100644
@@ -1957,6 +1957,11 @@ int qcow2_update_header(BlockDriverState *bs)
     if (s->image_backing_file) {

block/qcow2.c int qcow2_update_header(BlockDriverState *bs) · line 1967

Quoted 10 lines
block/qcow2.c +5 -0
         size_t backing_file_len = strlen(s->image_backing_file);
 
+        if (backing_file_len > 1023) {
+            ret = -EINVAL;
+            goto fail;
+        }
+
         if (buflen < backing_file_len) {
             ret = -ENOSPC;
             goto fail;

We should probably already check this in qcow2_change_backing_file(), so that s->image_backing_file can never contain anything longer than that. If you like, you can keep an assertion here.

The advantage is that in qcow2_change_backing_file() we can fail the operation before all of the variables are updated and therefore become inconsistent with the on-disk state of the image.

Kevin