We've got user reported bugs that when opperating with slow NFS
backends with large (30+ GB) disk files, the prlimit of cpu_time 2 is
guessed to be the issue at hand because if folks hot patch a qemu-img
that runs before the prlimitted one, the prlimitted one succeeds.
This increases the allowed cpu timeout, as well as tweaking the error
message so that we return something more prescriptive when the
qemu-img command fails with prlimit abort.
The original bug (#
1449062) the main mitigation concern here was a
carefully crafted image that gets qemu-img to generate > 1G of json,
and hence could be a node attack vector. cpu_time was never mentioned,
and I think was added originally as a belt and suspenders addition. As
such, bumping it to 8 seconds shouldn't impact our protection in any
real way.
Change-Id: I1f4549b787fd3b458e2c48a90bf80025987f08c4
Closes-Bug: #
1646181
import mock
from oslo_concurrency import processutils
+import six
from nova import exception
from nova import test
'qcow2',
'raw')
+ @mock.patch.object(utils, 'execute')
+ @mock.patch.object(os.path, 'exists', return_value=True)
+ def test_convert_image_with_prlimit_fail(self, path, mocked_execute):
+ mocked_execute.side_effect = \
+ processutils.ProcessExecutionError(exit_code=-9)
+ exc = self.assertRaises(exception.InvalidDiskInfo,
+ images.qemu_img_info,
+ '/fake/path')
+ self.assertIn('qemu-img aborted by prlimits', six.text_type(exc))
+
@mock.patch.object(images, 'convert_image',
side_effect=exception.ImageUnacceptable)
@mock.patch.object(images, 'qemu_img_info')
IMAGE_API = image.API()
QEMU_IMG_LIMITS = processutils.ProcessLimits(
- cpu_time=2,
+ cpu_time=8,
address_space=1 * units.Gi)
cmd = cmd + ('-f', format)
out, err = utils.execute(*cmd, prlimit=QEMU_IMG_LIMITS)
except processutils.ProcessExecutionError as exp:
- msg = (_("qemu-img failed to execute on %(path)s : %(exp)s") %
- {'path': path, 'exp': exp})
+ # this means we hit prlimits, make the exception more specific
+ if exp.exit_code == -9:
+ msg = (_("qemu-img aborted by prlimits when inspecting "
+ "%(path)s : %(exp)s") % {'path': path, 'exp': exp})
+ else:
+ msg = (_("qemu-img failed to execute on %(path)s : %(exp)s") %
+ {'path': path, 'exp': exp})
raise exception.InvalidDiskInfo(reason=msg)
if not out: