Skip to contentSkip to conversation

gluster: Fix use after free in glfs_clear_preopened()

PATCH Applied Kevin Wolf 2 participants 2 messages Nov 17, 2016 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 gluster: Fix use after free in glfs_clear_preopened()

This fixes a use-after-free bug introduced in commit 6349c154. We need to use QLIST_FOREACH_SAFE() when freeing elements in the loop. Spotted by Coverity.

---
 block/gluster.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
block/gluster.c +2 -1
index 0ce15f7..891c13b 100644
@@ -239,12 +239,13 @@ static glfs_t *glfs_find_preopened(const char *volume)
 static void glfs_clear_preopened(glfs_t *fs)
 {
     ListElement *entry = NULL;
+    ListElement *next;
 
     if (fs == NULL) {
         return;
     }
 
-    QLIST_FOREACH(entry, &glfs_list, list) {
+    QLIST_FOREACH_SAFE(entry, &glfs_list, list, next) {
         if (entry->saved.fs == fs) {
             if (--entry->saved.ref) {
                 return;
Signature · 1 line
1.8.3.1
Applied
#1 lore raw
Quoted 31 lines · Kevin Wolf

This fixes a use-after-free bug introduced in commit 6349c154. We need to use QLIST_FOREACH_SAFE() when freeing elements in the loop. Spotted by Coverity.

---
 block/gluster.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
block/gluster.c +2 -1
index 0ce15f7..891c13b 100644
@@ -239,12 +239,13 @@ static glfs_t *glfs_find_preopened(const char *volume)
 static void glfs_clear_preopened(glfs_t *fs)
 {
     ListElement *entry = NULL;
+    ListElement *next;
 
     if (fs == NULL) {
         return;
     }
 
-    QLIST_FOREACH(entry, &glfs_list, list) {
+    QLIST_FOREACH_SAFE(entry, &glfs_list, list, next) {
         if (entry->saved.fs == fs) {
             if (--entry->saved.ref) {
                 return;
Signature · 1 line
1.8.3.1

Thanks,

Applied to my block branch:

git://github.com/codyprime/qemu-kvm-jtc.git block

-Jeff