]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
Btrfs: ensure path name is null terminated at btrfs_control_ioctl
authorFilipe Manana <fdmanana@suse.com>
Wed, 14 Nov 2018 11:35:24 +0000 (11:35 +0000)
committerDavid Sterba <dsterba@suse.com>
Wed, 14 Nov 2018 17:26:20 +0000 (18:26 +0100)
We were using the path name received from user space without checking that
it is null terminated. While btrfs-progs is well behaved and does proper
validation and null termination, someone could call the ioctl and pass
a non-null terminated patch, leading to buffer overrun problems in the
kernel.  The ioctl is protected by CAP_SYS_ADMIN.

So just set the last byte of the path to a null character, similar to what
we do in other ioctls (add/remove/resize device, snapshot creation, etc).

CC: stable@vger.kernel.org # 4.4+
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/super.c

index cbc9d0d2c12de42786da57c41ebbc9f0364ffabd..645fc81e2a948eab03431a08c0c4b062ce7fd25e 100644 (file)
@@ -2237,6 +2237,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
        vol = memdup_user((void __user *)arg, sizeof(*vol));
        if (IS_ERR(vol))
                return PTR_ERR(vol);
+       vol->name[BTRFS_PATH_NAME_MAX] = '\0';
 
        switch (cmd) {
        case BTRFS_IOC_SCAN_DEV: