diff --git a/cinder/image/image_utils.py b/cinder/image/image_utils.py index 6d59bc74303..c82d3734d00 100644 --- a/cinder/image/image_utils.py +++ b/cinder/image/image_utils.py @@ -54,13 +54,18 @@ image_helper_opts = [cfg.StrOpt('image_conversion_dir', CONF = cfg.CONF CONF.register_opts(image_helper_opts) +QEMU_IMG_LIMITS = processutils.ProcessLimits( + cpu_time=2, + address_space=1 * units.Gi) + def qemu_img_info(path, run_as_root=True): """Return a object containing the parsed output from qemu-img info.""" cmd = ('env', 'LC_ALL=C', 'qemu-img', 'info', path) if os.name == 'nt': cmd = cmd[2:] - out, _err = utils.execute(*cmd, run_as_root=run_as_root) + out, _err = utils.execute(*cmd, run_as_root=run_as_root, + prlimit=QEMU_IMG_LIMITS) return imageutils.QemuImgInfo(out) diff --git a/cinder/tests/unit/test_image_utils.py b/cinder/tests/unit/test_image_utils.py index 6bce1140fec..7c92e731179 100644 --- a/cinder/tests/unit/test_image_utils.py +++ b/cinder/tests/unit/test_image_utils.py @@ -38,7 +38,8 @@ class TestQemuImgInfo(test.TestCase): output = image_utils.qemu_img_info(test_path) mock_exec.assert_called_once_with('env', 'LC_ALL=C', 'qemu-img', - 'info', test_path, run_as_root=True) + 'info', test_path, run_as_root=True, + prlimit=image_utils.QEMU_IMG_LIMITS) self.assertEqual(mock_info.return_value, output) @mock.patch('cinder.openstack.common.imageutils.QemuImgInfo') @@ -51,7 +52,8 @@ class TestQemuImgInfo(test.TestCase): output = image_utils.qemu_img_info(test_path, run_as_root=False) mock_exec.assert_called_once_with('env', 'LC_ALL=C', 'qemu-img', - 'info', test_path, run_as_root=False) + 'info', test_path, run_as_root=False, + prlimit=image_utils.QEMU_IMG_LIMITS) self.assertEqual(mock_info.return_value, output) @mock.patch('cinder.image.image_utils.os') @@ -66,7 +68,8 @@ class TestQemuImgInfo(test.TestCase): output = image_utils.qemu_img_info(test_path) mock_exec.assert_called_once_with('qemu-img', 'info', test_path, - run_as_root=True) + run_as_root=True, + prlimit=image_utils.QEMU_IMG_LIMITS) self.assertEqual(mock_info.return_value, output) @mock.patch('cinder.utils.execute') diff --git a/releasenotes/notes/apply-limits-to-qemu-img-29f722a1bf4b91f8.yaml b/releasenotes/notes/apply-limits-to-qemu-img-29f722a1bf4b91f8.yaml new file mode 100644 index 00000000000..1ec4c3e6246 --- /dev/null +++ b/releasenotes/notes/apply-limits-to-qemu-img-29f722a1bf4b91f8.yaml @@ -0,0 +1,7 @@ +--- +security: + - The qemu-img tool now has resource limits applied + which prevent it from using more than 1GB of address + space or more than 2 seconds of CPU time. This provides + protection against denial of service attacks from + maliciously crafted or corrupted disk images.