1
From: Pádraig Brady <pbrady@redhat.com>
2
Date: Fri, 23 Nov 2012 14:59:13 +0000 (+0000)
3
Subject: Don't leak info from libvirt LVM backed instances
4
X-Git-Url: https://review.openstack.org/gitweb?p=openstack%2Fnova.git;a=commitdiff_plain;h=a99a802e008eed18e39fc1d98170edc495cbd354
6
Don't leak info from libvirt LVM backed instances
8
* nova/virt/libvirt/utils.py (remove_logical_volumes):
9
Overwrite each logical volume with zero
10
(clear_logical_volume): LV obfuscation implementation.
11
(logical_volume_size): A utility function used by
12
clear_logical_volume()
15
Change-Id: I4e1024de8dfe9b0be3b0d6437c836d2042862f85
18
diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py
19
index cb39eac..82dc956 100644
20
--- a/nova/virt/libvirt/utils.py
21
+++ b/nova/virt/libvirt/utils.py
22
@@ -149,8 +149,52 @@ def list_logical_volumes(vg):
23
return [line.strip() for line in out.splitlines()]
26
+def logical_volume_size(path):
27
+ """Get logical volume size in bytes.
29
+ :param path: logical volume path
31
+ # TODO(p-draigbrady) POssibly replace with the more general
32
+ # use of blockdev --getsize64 in future
33
+ out, _err = execute('lvs', '-o', 'lv_size', '--noheadings', '--units',
34
+ 'b', '--nosuffix', path, run_as_root=True)
39
+def clear_logical_volume(path):
40
+ """Obfuscate the logical volume.
42
+ :param path: logical volume path
44
+ # TODO(p-draigbrady): We currently overwrite with zeros
45
+ # but we may want to make this configurable in future
46
+ # for more or less security conscious setups.
48
+ vol_size = logical_volume_size(path)
50
+ remaining_bytes = vol_size
52
+ # The loop caters for versions of dd that
53
+ # don't support the iflag=count_bytes option.
54
+ while remaining_bytes:
55
+ zero_blocks = remaining_bytes / bs
56
+ seek_blocks = (vol_size - remaining_bytes) / bs
57
+ zero_cmd = ('dd', 'bs=%s' % bs,
58
+ 'if=/dev/zero', 'of=%s' % path,
59
+ 'seek=%s' % seek_blocks, 'count=%s' % zero_blocks)
61
+ utils.execute(*zero_cmd, run_as_root=True)
62
+ remaining_bytes %= bs
63
+ bs /= 1024 # Limit to 3 iterations
66
def remove_logical_volumes(*paths):
67
"""Remove one or more logical volume."""
70
+ clear_logical_volume(path)
73
lvremove = ('lvremove', '-f') + paths
74
execute(*lvremove, attempts=3, run_as_root=True)