From b4162d68eacdfdf3dd6d4c13e19e189c6fa0c70a Mon Sep 17 00:00:00 2001 From: Daniel Dawson Date: Tue, 8 Jan 2019 20:27:35 -0800 Subject: [PATCH] Fix data corruption leading to kernel panic. I found that trying to use Snapper to create a Btrfs snapshot with a qgroup set causes the system to lock up, sometimes with a kernel panic message on the console. I tracked down the problem to this code. As it currently stands, `buffer` goes out of scope before the `ioctl` call can use it, and in my case, at least, it seems some of the data is already overwritten. Moving it out of the `if` statement lets this work properly. --- snapper/BtrfsUtils.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/snapper/BtrfsUtils.cc b/snapper/BtrfsUtils.cc index f5fda6be..8c31c721 100644 --- a/snapper/BtrfsUtils.cc +++ b/snapper/BtrfsUtils.cc @@ -143,10 +143,11 @@ namespace snapper #ifdef ENABLE_BTRFS_QUOTA + size_t size = sizeof(btrfs_qgroup_inherit) + sizeof(((btrfs_qgroup_inherit*) 0)->qgroups[0]); + vector buffer(size, 0); + if (qgroup != no_qgroup) { - size_t size = sizeof(btrfs_qgroup_inherit) + sizeof(((btrfs_qgroup_inherit*) 0)->qgroups[0]); - vector buffer(size, 0); struct btrfs_qgroup_inherit* inherit = (btrfs_qgroup_inherit*) &buffer[0]; inherit->num_qgroups = 1; -- 2.47.3