Skip to contentSkip to conversation

Btrfs: NUL-terminate path buffer in DEV_INFO ioctl result

PATCH In review Jim Meyering 2 participants 3 messages Apr 26, 2012 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: NUL-terminate path buffer in DEV_INFO ioctl result

A device with name of length BTRFS_DEVICE_PATH_NAME_MAX or longer would not be NUL-terminated in the DEV_INFO ioctl result buffer.

---
 fs/btrfs/ioctl.c |    1 +
 1 file changed, 1 insertion(+)
fs/btrfs/ioctl.c +1 -0
index 18cc23d..1578676 100644
@@ -2258,16 +2258,17 @@ static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg)
 		goto out;
 	}
 
 	di_args->devid = dev->devid;
 	di_args->bytes_used = dev->bytes_used;
 	di_args->total_bytes = dev->total_bytes;
 	memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid));
 	strncpy(di_args->path, dev->name, sizeof(di_args->path));
+	di_args->path[sizeof(di_args->path) - 1] = 0;
 
 out:
 	if (ret == 0 && copy_to_user(arg, di_args, sizeof(*di_args)))
 		ret = -EFAULT;
 
 	kfree(di_args);
 	return ret;
 }

--
1.7.10.336.gc5e31

#2 lore raw
In reply to Jim Meyering
Quoted 32 lines · Jim Meyering

A device with name of length BTRFS_DEVICE_PATH_NAME_MAX or longer would not be NUL-terminated in the DEV_INFO ioctl result buffer.

---
 fs/btrfs/ioctl.c |    1 +
 1 file changed, 1 insertion(+)
fs/btrfs/ioctl.c +1 -1
index 18cc23d..1578676 100644
@@ -2258,16 +2258,17 @@ static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg)
 		goto out;
 	}
 
 	di_args->devid = dev->devid;
 	di_args->bytes_used = dev->bytes_used;
 	di_args->total_bytes = dev->total_bytes;
 	memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid));
 	strncpy(di_args->path, dev->name, sizeof(di_args->path));
+	di_args->path[sizeof(di_args->path) - 1] = 0;
 
 out:
 	if (ret == 0 && copy_to_user(arg, di_args, sizeof(*di_args)))
 		ret = -EFAULT;
 
 	kfree(di_args);
 	return ret;
 }
--
Quoted 1 line

1.7.10.336.gc5e31

This didn't merge quite right onto btrfs-next btw so I've fixed it up manually (but left the log/author/signed off intact). Thanks,

Josef