linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: subvol sync: fix memory corruption, undersized array
@ 2016-03-17 10:47 David Sterba
  2016-03-17 14:10 ` Blocks changed since previous snapshot of subvolume sri
  0 siblings, 1 reply; 5+ messages in thread
From: David Sterba @ 2016-03-17 10:47 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The subvol sync command crashed randomly at the end with

*** glibc detected *** btrfs: double free or corruption (out): 0x00000000006ab040 ***

This is caused by running out of the ids array in case there are more
than 128 subvolumes. The array is increased in steps but does not
account the size of the item, so there was room for 1024 / 8 = 128
subvolume ids.

Fixes: c9f885ec8963 ("btrfs-progs: subvol: let sync check only current deletions")
Signed-off-by: David Sterba <dsterba@suse.com>
---
 cmds-subvolume.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index 02e1dec18ed2..32caaa5db9ec 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -1204,7 +1204,8 @@ static int enumerate_dead_subvols(int fd, u64 **ids)
 					u64 *newids;
 
 					count += SUBVOL_ID_BATCH;
-					newids = (u64*)realloc(*ids, count);
+					newids = (u64*)realloc(*ids,
+							count * sizeof(u64));
 					if (!newids)
 						return -ENOMEM;
 					*ids = newids;
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-03-19  0:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-17 10:47 [PATCH] btrfs-progs: subvol sync: fix memory corruption, undersized array David Sterba
2016-03-17 14:10 ` Blocks changed since previous snapshot of subvolume sri
2016-03-17 20:36   ` Henk Slager
2016-03-18 13:36     ` sri
2016-03-19  0:13       ` Duncan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).