Bug 2118231

Summary: mount through procfd: operation not permitted: OCI permission denied
Product: Red Hat Enterprise Linux 8 Reporter: Jian Zhang <jiazha>
Component: runcAssignee: Jindrich Novy <jnovy>
Status: CLOSED ERRATA QA Contact: Alex Jia <ajia>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.4CC: dwalsh, gscrivan, jnovy, mheon, pthomas, tsweeney, umohnani, ypu
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: runc-1.1.3-2.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-11-08 09:16:44 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jian Zhang 2022-08-15 06:04:06 UTC
Description of problem:

[cloud-user@preserve-olm-env2 interview]$ podman run quay.io/olmqe/interview:v1
Error: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:75: mounting "sysfs" to rootfs at "/sys" caused: mount through procfd: operation not permitted: OCI permission denied

But, it works with `crun`.
[cloud-user@preserve-olm-env2 interview]$ podman run --runtime crun quay.io/olmqe/interview:v1
10
...

More details: https://github.com/containers/podman/issues/15314

Version-Release number of selected component (if applicable):
[cloud-user@preserve-olm-env2 interview]$ cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.4 (Ootpa)
[cloud-user@preserve-olm-env2 interview]$ podman version
Client:       Podman Engine
Version:      4.1.1
API Version:  4.1.1
Go Version:   go1.17.7
Built:        Mon Jul 11 22:56:53 2022
OS/Arch:      linux/amd64

How reproducible:
always

Steps to Reproduce:
1. Build an image

[cloud-user@preserve-olm-env2 interview]$ cat test.go 
package main

import (
	"fmt"
)

func main() {
	testMap := make(map[string]int, 10)
	array := [10]string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}
	for i, v := range array {
		testMap[v] = i + 20
	}
	fmt.Println(len(testMap))
	for _, v := range testMap {
		fmt.Println(v)
	}

}
[cloud-user@preserve-olm-env2 interview]$ cat Dockerfile 
FROM golang:1.18
WORKDIR /app
COPY test.go ./
RUN go build -o main test.go && pwd && ls -l
ENTRYPOINT ["/bin/bash", "-c", "./main"]

[cloud-user@preserve-olm-env2 interview]$ podman build -t quay.io/olmqe/interview:v1 .
STEP 1/5: FROM golang:1.18
...

2. Run it with the default runtime
[cloud-user@preserve-olm-env2 interview]$ podman run quay.io/olmqe/interview:v1
Error: runc: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:75: mounting "sysfs" to rootfs at "/sys" caused: mount through procfd: operation not permitted: OCI permission denied



Actual results:
Error: runc: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:75: mounting "sysfs" to rootfs at "/sys" caused: mount through procfd: operation not permitted: OCI permission denied

Expected results:
It should work well.


Additional info:
It works well when specifying the `crun`.
[cloud-user@preserve-olm-env2 interview]$ podman run --runtime crun quay.io/olmqe/interview:v1
10
...
...

Comment 2 Tom Sweeney 2022-08-16 18:42:14 UTC
Giuseppe, can you look at this one too please?

Comment 3 Giuseppe Scrivano 2022-08-17 07:24:21 UTC
I think this one is fixed upstream with:

commit d370e3c04660201e72ba6968342ce964c31a2d7f
Author: Kir Kolyshkin <kolyshkin>
Date:   Tue Jun 14 17:19:10 2022 -0700

    libct: fix mounting via wrong proc fd
    
    Due to a bug in commit 9c444070ec7, when the user and mount namespaces
    are used, and the bind mount is followed by the cgroup mount in the
    spec, the cgroup is mounted using the bind mount's mount fd.
    
    This can be reproduced with podman 4.1 (when configured to use runc):
    
    $ podman run --uidmap 0:100:10000 quay.io/libpod/testimage:20210610 mount
    Error: /home/kir/git/runc/runc: runc create failed: unable to start container process: error during container init: error mounting "cgroup" to rootfs at "/sys/fs/cgroup": mount /proc/self/fd/11:/sys/fs/cgroup/systemd (via /proc/self/fd/12), flags: 0x20502f: operation not permitted: OCI permission denied
    
    or manually with the spec mounts containing something like this:
    
        {
          "destination": "/etc/resolv.conf",
          "type": "bind",
          "source": "/userdata/resolv.conf",
          "options": [
            "bind"
          ]
        },
        {
          "destination": "/sys/fs/cgroup",
          "type": "cgroup",
          "source": "cgroup",
          "options": [
            "rprivate",
            "nosuid",
            "noexec",
            "nodev",
            "relatime",
            "ro"
          ]
        }
    
    The issue was not found earlier since it requires using userns, and even then
    mount fd is ignored by mountToRootfs, except for bind mounts, and all the bind
    mounts have mountfd set, except for the case of cgroup v1's /sys/fs/cgroup
    which is internally transformed into a bunch of bind mounts.
    
    This is a minimal fix for the issue, suitable for backporting.
    
    A test case is added which reproduces the issue without the fix applied.
    
    Fixes: 9c444070ec7 ("Open bind mount sources from the host userns")
    Signed-off-by: Kir Kolyshkin <kolyshkin>

Comment 4 Alex Jia 2022-08-19 10:24:51 UTC
It works well for runc-1.1.3-2.module+el8.7.0+15895+a6753917.

[root@ibm-x3650m4-01-vm-16 ~]# podman run quay.io/olmqe/interview:v1
10
21
22
25
26
28
20
23
24
27
29

[root@ibm-x3650m4-01-vm-16 ~]# podman run --uidmap 0:100:10000 quay.io/libpod/testimage:20210610 mount|grep proc
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
proc on /proc/asound type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/bus type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/fs type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/irq type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/sys type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/sysrq-trigger type proc (ro,nosuid,nodev,noexec,relatime)
tmpfs on /proc/acpi type tmpfs (ro,context="system_u:object_r:container_file_t:s0:c624,c969",relatime,uid=100,gid=100)
devtmpfs on /proc/kcore type devtmpfs (rw,seclabel,nosuid,size=1890704k,nr_inodes=472676,mode=755)
devtmpfs on /proc/keys type devtmpfs (rw,seclabel,nosuid,size=1890704k,nr_inodes=472676,mode=755)
devtmpfs on /proc/timer_list type devtmpfs (rw,seclabel,nosuid,size=1890704k,nr_inodes=472676,mode=755)
devtmpfs on /proc/sched_debug type devtmpfs (rw,seclabel,nosuid,size=1890704k,nr_inodes=472676,mode=755)
tmpfs on /proc/scsi type tmpfs (ro,context="system_u:object_r:container_file_t:s0:c624,c969",relatime,uid=100,gid=100)

[root@ibm-x3650m4-01-vm-16 ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.7 Beta (Ootpa)

[root@ibm-x3650m4-01-vm-16 ~]# rpm -q runc podman systemd kernel
runc-1.1.3-2.module+el8.7.0+15895+a6753917.x86_64
podman-4.1.1-6.module+el8.7.0+15895+a6753917.x86_64
systemd-239-62.el8.x86_64
kernel-4.18.0-418.el8.x86_64

Comment 7 Alex Jia 2022-08-29 12:43:19 UTC
This bug has been verified on runc-1.1.4-1.module+el8.7.0+16493+89f82ab8.x86_64.

[root@hpe-dl380pgen8-02-vm-7 interview]# cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.7 Beta (Ootpa)

[root@hpe-dl380pgen8-02-vm-7 interview]# rpm -q runc podman systemd kernel
runc-1.1.4-1.module+el8.7.0+16493+89f82ab8.x86_64
podman-4.2.0-1.module+el8.7.0+16493+89f82ab8.x86_64
systemd-239-65.el8.x86_64
kernel-4.18.0-422.el8.x86_64

[root@hpe-dl380pgen8-02-vm-7 interview]# podman run quay.io/olmqe/interview:v1
10
21
23
25
29
28
20
22
24
26
27
[root@hpe-dl380pgen8-02-vm-7 interview]# podman run --uidmap 0:100:10000 quay.io/libpod/testimage:20210610 mount|grep proc
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
proc on /proc/asound type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/bus type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/fs type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/irq type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/sys type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/sysrq-trigger type proc (ro,nosuid,nodev,noexec,relatime)
tmpfs on /proc/acpi type tmpfs (ro,context="system_u:object_r:container_file_t:s0:c47,c896",relatime,uid=100,gid=100)
devtmpfs on /proc/kcore type devtmpfs (rw,seclabel,nosuid,size=1890744k,nr_inodes=472686,mode=755)
devtmpfs on /proc/keys type devtmpfs (rw,seclabel,nosuid,size=1890744k,nr_inodes=472686,mode=755)
devtmpfs on /proc/timer_list type devtmpfs (rw,seclabel,nosuid,size=1890744k,nr_inodes=472686,mode=755)
devtmpfs on /proc/sched_debug type devtmpfs (rw,seclabel,nosuid,size=1890744k,nr_inodes=472686,mode=755)
tmpfs on /proc/scsi type tmpfs (ro,context="system_u:object_r:container_file_t:s0:c47,c896",relatime,uid=100,gid=100)

Comment 9 errata-xmlrpc 2022-11-08 09:16:44 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: container-tools:rhel8 security, bug fix, and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2022:7457