Skip to contentSkip to conversation

btrfs-progs: fix double free during scanning

PATCH New David Sterba 1 participant 1 message Oct 2, 2015 Btrfs file system

lore
Share & tools
lore

David Sterba

author maintainer
#0 lore raw

PATCH 1/1 btrfs-progs: fix double free during scanning

If there are different devices mounted to the same directory we can run into double free issue in the scanning code and this can lead to a crash. The dev_info_arg buffer allocation get_fs_info might be skipped, eg. if the FS_INFO ioctl fails due to EPERM in older kernels. Reset the pointer before each loop starts.

---
 cmds-filesystem.c | 2 ++
 1 file changed, 2 insertions(+)
cmds-filesystem.c +2 -0
index b4576ed30360..366373473c56 100644
@@ -485,6 +485,7 @@ static int btrfs_scan_kernel(void *search, unsigned unit_mode)
 		if (search && !match_search_item_kernel(fs_info_arg.fsid,
 					mnt->mnt_dir, label, search)) {
 			kfree(dev_info_arg);
+			dev_info_arg = NULL;
 			continue;
 		}
 
@@ -500,6 +501,7 @@ static int btrfs_scan_kernel(void *search, unsigned unit_mode)
 		if (fd != -1)
 			close(fd);
 		kfree(dev_info_arg);
+		dev_info_arg = NULL;
 	}
 
 out:
Signature · 1 line
2.1.3