]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
btrfs: Fix use-after-free when cleaning up fs_devs with a single stale device
authorNikolay Borisov <nborisov@suse.com>
Tue, 30 Jan 2018 14:07:37 +0000 (16:07 +0200)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Wed, 21 Mar 2018 16:40:31 +0000 (13:40 -0300)
commit6b2f4cacdd3308874e23534ef425e8bb3442ac59
treeb4d36a488e583773316619ebbd34d0e1372a9749
parent272b3be7b4fc420a9e523403f0d061cdfa533b23
btrfs: Fix use-after-free when cleaning up fs_devs with a single stale device

BugLink: http://bugs.launchpad.net/bugs/1757465
commit fd649f10c3d21ee9d7542c609f29978bdf73ab94 upstream.

Commit 4fde46f0cc71 ("Btrfs: free the stale device") introduced
btrfs_free_stale_device which iterates the device lists for all
registered btrfs filesystems and deletes those devices which aren't
mounted. In a btrfs_devices structure has only 1 device attached to it
and it is unused then btrfs_free_stale_devices will proceed to also free
the btrfs_fs_devices struct itself. Currently this leads to a use after
free since list_for_each_entry will try to perform a check on the
already freed memory to see if it has to terminate the loop.

The fix is to use 'break' when we know we are freeing the current
fs_devs.

Fixes: 4fde46f0cc71 ("Btrfs: free the stale device")
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
fs/btrfs/volumes.c