Skip to contentSkip to conversation

block/vvfat: Fix crash when reporting error about too many files in directory

PATCH Superseded Thomas Huth 3 participants 6 messages Jul 18, 2018 – Jul 24, 2018 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/vvfat: Fix crash when reporting error about too many files in directory

When using the vvfat driver with a directory that contains too many files, QEMU currently crashes. We are trying to print the wrong path variable here.

---
 block/vvfat.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/vvfat.c +1 -2
index fc41841..6ae7458 100644
@@ -975,8 +975,7 @@ static int init_directories(BDRVVVFATState* s,
         if (mapping->mode & MODE_DIRECTORY) {
             mapping->begin = cluster;
             if(read_directory(s, i)) {
-                error_setg(errp, "Could not read directory %s",
-                           mapping->path);
+                error_setg(errp, "Could not read directory \"%s\"", s->path);
                 return -1;
             }
             mapping = array_get(&(s->mapping), i);
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Thomas Huth

When using the vvfat driver with a directory that contains too many files, QEMU currently crashes. We are trying to print the wrong path variable here.

---
 block/vvfat.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/vvfat.c +0 -0
index fc41841..6ae7458 100644

block/vvfat.c static int init_directories(BDRVVVFATState* s, · line 981

Quoted 9 lines
block/vvfat.c +1 -2
@@ -975,8 +975,7 @@ static int init_directories(BDRVVVFATState* s,
         if (mapping->mode & MODE_DIRECTORY) {
             mapping->begin = cluster;
             if(read_directory(s, i)) {
-                error_setg(errp, "Could not read directory %s",
-                           mapping->path);
+                error_setg(errp, "Could not read directory \"%s\"", s->path);
                 return -1;
             }
             mapping = array_get(&(s->mapping), i);
#2 lore raw
In reply to Thomas Huth

Am 18.07.2018 um 17:28 hat Thomas Huth geschrieben:

Quoted 13 lines

When using the vvfat driver with a directory that contains too many files, QEMU currently crashes. We are trying to print the wrong path variable here.

---
 block/vvfat.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/vvfat.c +0 -0
index fc41841..6ae7458 100644

block/vvfat.c static int init_directories(BDRVVVFATState* s, · line 978

Quoted 6 lines
block/vvfat.c +1 -2
@@ -975,8 +975,7 @@ static int init_directories(BDRVVVFATState* s,
         if (mapping->mode & MODE_DIRECTORY) {
             mapping->begin = cluster;
             if(read_directory(s, i)) {
-                error_setg(errp, "Could not read directory %s",
-                           mapping->path);
+                error_setg(errp, "Could not read directory \"%s\"", s->path);

Hm, I'm not sure if that's right. Before this patch we were printing the name of the subdirectory that couldn't be loaded, now it's the parent directory.

My test case where this difference is visible is a subdirectory with chmod 000.

block/vvfat.c static int init_directories(BDRVVVFATState* s, · line 981

Quoted 3 lines
block/vvfat.c +0 -0
                 return -1;
             }
             mapping = array_get(&(s->mapping), i);

Maybe the right solution would be moving the reloading of mapping to between the read_directory() call and the error path?

Kevin

#3 lore raw
Quoted 25 lines · Kevin Wolf

Am 18.07.2018 um 17:28 hat Thomas Huth geschrieben:

Quoted 13 lines

When using the vvfat driver with a directory that contains too many files, QEMU currently crashes. We are trying to print the wrong path variable here.

---
 block/vvfat.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/vvfat.c +0 -0
index fc41841..6ae7458 100644

block/vvfat.c static int init_directories(BDRVVVFATState* s, · line 978

Quoted 6 lines
block/vvfat.c +1 -2
@@ -975,8 +975,7 @@ static int init_directories(BDRVVVFATState* s,
         if (mapping->mode & MODE_DIRECTORY) {
             mapping->begin = cluster;
             if(read_directory(s, i)) {
-                error_setg(errp, "Could not read directory %s",
-                           mapping->path);
+                error_setg(errp, "Could not read directory \"%s\"", s->path);

Hm, I'm not sure if that's right. Before this patch we were printing the name of the subdirectory that couldn't be loaded, now it's the parent directory.

Quoted 2 lines

My test case where this difference is visible is a subdirectory with chmod 000.

Right.

Quoted 6 lines

block/vvfat.c static int init_directories(BDRVVVFATState* s, · line 981

Quoted 3 lines
block/vvfat.c +0 -0
                 return -1;
             }
             mapping = array_get(&(s->mapping), i);

Maybe the right solution would be moving the reloading of mapping to between the read_directory() call and the error path?

No, that does not work either. The problem seems to be that read_directory() is changing the mapping->path pointer to something invalid in between, but I've been unable to track it down where it happens. This patch here seems to work for me, though:

block/vvfat.c +2 -2
index fc41841..f2e7d50 100644
@@ -973,10 +973,10 @@ static int init_directories(BDRVVVFATState* s,
         mapping = array_get(&(s->mapping), i);
 
         if (mapping->mode & MODE_DIRECTORY) {
+            char *path = mapping->path;
             mapping->begin = cluster;
             if(read_directory(s, i)) {
-                error_setg(errp, "Could not read directory %s",
-                           mapping->path);
+                error_setg(errp, "Could not read directory %s", path);
                 return -1;
             }
             mapping = array_get(&(s->mapping), i);

Does this look reasonable for you, too?

Thomas

#4 lore raw

Am 24.07.2018 um 11:56 hat Thomas Huth geschrieben:

Quoted 61 lines · Kevin Wolf
Quoted 25 lines

Am 18.07.2018 um 17:28 hat Thomas Huth geschrieben:

Quoted 13 lines

When using the vvfat driver with a directory that contains too many files, QEMU currently crashes. We are trying to print the wrong path variable here.

---
 block/vvfat.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/vvfat.c +0 -0
index fc41841..6ae7458 100644

block/vvfat.c static int init_directories(BDRVVVFATState* s, · line 978

Quoted 6 lines
block/vvfat.c +1 -2
@@ -975,8 +975,7 @@ static int init_directories(BDRVVVFATState* s,
         if (mapping->mode & MODE_DIRECTORY) {
             mapping->begin = cluster;
             if(read_directory(s, i)) {
-                error_setg(errp, "Could not read directory %s",
-                           mapping->path);
+                error_setg(errp, "Could not read directory \"%s\"", s->path);

Hm, I'm not sure if that's right. Before this patch we were printing the name of the subdirectory that couldn't be loaded, now it's the parent directory.

Quoted 2 lines

My test case where this difference is visible is a subdirectory with chmod 000.

Right.

Quoted 6 lines

block/vvfat.c static int init_directories(BDRVVVFATState* s, · line 982

Quoted 3 lines
block/vvfat.c +0 -0
                 return -1;
             }
             mapping = array_get(&(s->mapping), i);

Maybe the right solution would be moving the reloading of mapping to between the read_directory() call and the error path?

No, that does not work either. The problem seems to be that read_directory() is changing the mapping->path pointer to something invalid in between, but I've been unable to track it down where it happens. This patch here seems to work for me, though:

block/vvfat.c +2 -2
index fc41841..f2e7d50 100644
@@ -973,10 +973,10 @@ static int init_directories(BDRVVVFATState* s,
         mapping = array_get(&(s->mapping), i);
 
         if (mapping->mode & MODE_DIRECTORY) {
+            char *path = mapping->path;
             mapping->begin = cluster;
             if(read_directory(s, i)) {
-                error_setg(errp, "Could not read directory %s",
-                           mapping->path);
+                error_setg(errp, "Could not read directory %s", path);
                 return -1;
             }
             mapping = array_get(&(s->mapping), i);
Quoted 1 line

Does this look reasonable for you, too?

I can't say I understand what's going on (the change I suggested did work for my test case, without valgrind errors), but the above patch doesn't look wrong to me at least.

Kevin

#5 lore raw
Quoted 62 lines · Kevin Wolf

Am 24.07.2018 um 11:56 hat Thomas Huth geschrieben:

Quoted 61 lines · Kevin Wolf
Quoted 25 lines

Am 18.07.2018 um 17:28 hat Thomas Huth geschrieben:

Quoted 13 lines

When using the vvfat driver with a directory that contains too many files, QEMU currently crashes. We are trying to print the wrong path variable here.

---
 block/vvfat.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/vvfat.c +0 -0
index fc41841..6ae7458 100644

block/vvfat.c static int init_directories(BDRVVVFATState* s, · line 978

Quoted 6 lines
block/vvfat.c +1 -2
@@ -975,8 +975,7 @@ static int init_directories(BDRVVVFATState* s,
         if (mapping->mode & MODE_DIRECTORY) {
             mapping->begin = cluster;
             if(read_directory(s, i)) {
-                error_setg(errp, "Could not read directory %s",
-                           mapping->path);
+                error_setg(errp, "Could not read directory \"%s\"", s->path);

Hm, I'm not sure if that's right. Before this patch we were printing the name of the subdirectory that couldn't be loaded, now it's the parent directory.

Quoted 2 lines

My test case where this difference is visible is a subdirectory with chmod 000.

Right.

Quoted 6 lines

block/vvfat.c static int init_directories(BDRVVVFATState* s, · line 982

Quoted 3 lines
block/vvfat.c +0 -0
                 return -1;
             }
             mapping = array_get(&(s->mapping), i);

Maybe the right solution would be moving the reloading of mapping to between the read_directory() call and the error path?

No, that does not work either. The problem seems to be that read_directory() is changing the mapping->path pointer to something invalid in between, but I've been unable to track it down where it happens. This patch here seems to work for me, though:

block/vvfat.c +2 -2
index fc41841..f2e7d50 100644
@@ -973,10 +973,10 @@ static int init_directories(BDRVVVFATState* s,
         mapping = array_get(&(s->mapping), i);
 
         if (mapping->mode & MODE_DIRECTORY) {
+            char *path = mapping->path;
             mapping->begin = cluster;
             if(read_directory(s, i)) {
-                error_setg(errp, "Could not read directory %s",
-                           mapping->path);
+                error_setg(errp, "Could not read directory %s", path);
                 return -1;
             }
             mapping = array_get(&(s->mapping), i);
Quoted 5 lines
Quoted 1 line

Does this look reasonable for you, too?

I can't say I understand what's going on (the change I suggested did work for my test case, without valgrind errors), but the above patch doesn't look wrong to me at least.

FWIW, my test:

mkdir /tmp/vvfattest
cd /tmp/vvfattest
for ((x=0;x<=513;x++)); do mkdir $x; done qemu-system-x86_64 -drive \
file.driver=vvfat,file.dir=.,read-only=on,media=cdrom

I'll send a proper patch with above suggestion.

Thomas