Skip to content

Commit

Permalink
Merge pull request #35 from stackhpc/zed-cve-2024-32498
Browse files Browse the repository at this point in the history
zed cve 2024 32498
  • Loading branch information
markgoddard authored Jul 11, 2024
2 parents 4eafdfa + 1ae4324 commit 671c3b1
Show file tree
Hide file tree
Showing 9 changed files with 506 additions and 35 deletions.
1 change: 0 additions & 1 deletion .zuul.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@
- release-notes-jobs-python3
check:
jobs:
- openstack-tox-functional-py38-fips
- openstack-tox-functional-py39
- glance-tox-functional-py39-rbac-defaults
- glance-ceph-thin-provisioning:
Expand Down
10 changes: 10 additions & 0 deletions glance/async_/flows/base_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ def execute(self, image_id):
'bfile': backing_file}
raise RuntimeError(msg)

try:
data_file = metadata['format-specific']['data']['data-file']
except KeyError:
data_file = None
if data_file is not None:
msg = _("File %(path)s has invalid data-file "
"%(dfile)s, aborting.") % {"path": path,
"dfile": data_file}
raise RuntimeError(msg)

return path

def revert(self, image_id, result, **kwargs):
Expand Down
52 changes: 45 additions & 7 deletions glance/async_/flows/plugins/image_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from taskflow import task

from glance.async_ import utils
from glance.common import format_inspector
from glance.i18n import _, _LI

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -87,8 +88,40 @@ def _execute(self, action, file_path, **kwargs):
'target': target_format}
self.dest_path = dest_path

source_format = action.image_disk_format
inspector_cls = format_inspector.get_inspector(source_format)
if not inspector_cls:
# We cannot convert from disk_format types that qemu-img doesn't
# support (like iso, ploop, etc). The ones it supports overlaps
# with the ones we have inspectors for, so reject conversion for
# any format we don't have an inspector for.
raise RuntimeError(
'Unable to convert from format %s' % source_format)

# Use our own cautious inspector module (if we have one for this
# format) to make sure a file is the format the submitter claimed
# it is and that it passes some basic safety checks _before_ we run
# qemu-img on it.
# See https://bugs.launchpad.net/nova/+bug/2059809 for details.
try:
inspector = inspector_cls.from_file(src_path)
if not inspector.safety_check():
LOG.error('Image failed %s safety check; aborting conversion',
source_format)
raise RuntimeError('Image has disallowed configuration')
except RuntimeError:
raise
except format_inspector.ImageFormatError as e:
LOG.error('Image claimed to be %s format failed format '
'inspection: %s', source_format, e)
raise RuntimeError('Image format detection failed')
except Exception as e:
LOG.exception('Unknown error inspecting image format: %s', e)
raise RuntimeError('Unable to inspect image')

try:
stdout, stderr = putils.trycmd("qemu-img", "info",
"-f", source_format,
"--output=json",
src_path,
prlimit=utils.QEMU_IMG_PROC_LIMITS,
Expand All @@ -105,13 +138,10 @@ def _execute(self, action, file_path, **kwargs):
raise RuntimeError(stderr)

metadata = json.loads(stdout)
try:
source_format = metadata['format']
except KeyError:
msg = ("Failed to do introspection as part of image "
"conversion for %(iid)s: Source format not reported")
LOG.error(msg, {'iid': self.image_id})
raise RuntimeError(msg)
if metadata.get('format') != source_format:
LOG.error('Image claiming to be %s reported as %s by qemu-img',
source_format, metadata.get('format', 'unknown'))
raise RuntimeError('Image metadata disagrees about format')

virtual_size = metadata.get('virtual-size', 0)
action.set_image_attribute(virtual_size=virtual_size)
Expand All @@ -121,6 +151,14 @@ def _execute(self, action, file_path, **kwargs):
raise RuntimeError(
'QCOW images with backing files are not allowed')

try:
data_file = metadata['format-specific']['data']['data-file']
except KeyError:
data_file = None
if data_file is not None:
raise RuntimeError(
'QCOW images with data-file set are not allowed')

if metadata.get('format') == 'vmdk':
create_type = metadata.get(
'format-specific', {}).get(
Expand Down
Loading

0 comments on commit 671c3b1

Please sign in to comment.