-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feature: PoC to mknod devices for user namespace containers #5138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,13 +18,15 @@ | |
| "syscall" | ||
| "time" | ||
|
|
||
| securejoin "github.com/cyphar/filepath-securejoin" | ||
| "github.com/sirupsen/logrus" | ||
| "golang.org/x/sys/unix" | ||
|
|
||
| "github.com/opencontainers/runtime-spec/specs-go" | ||
|
|
||
| "github.com/opencontainers/cgroups" | ||
| "github.com/opencontainers/cgroups/fs2" | ||
| "github.com/opencontainers/runc/internal/sys" | ||
| "github.com/opencontainers/runc/libcontainer/configs" | ||
| "github.com/opencontainers/runc/libcontainer/intelrdt" | ||
| "github.com/opencontainers/runc/libcontainer/internal/userns" | ||
|
|
@@ -729,7 +731,45 @@ | |
| if !ok { | ||
| break loop | ||
| } | ||
| src, err := mountFd(nsHandles, m) | ||
| var src *mountSource | ||
| var err error | ||
| if m.Device == "usernsMknod" { | ||
| // Create device in initial user ns | ||
| for _, device := range p.config.Config.Devices { | ||
| if device.Path == m.Source { | ||
| src, err = usernsMknod(p.config.Config.Rootfs, device) | ||
| break | ||
| } | ||
| } | ||
| if src == nil && err == nil { | ||
| err = fmt.Errorf("can not find device node") | ||
| } | ||
|
Comment on lines
+736
to
+746
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A magical mount type really feels like the wrong way of doing this. It would also need a runtime-spec change. |
||
| } else if m.Device != "tmpfs" { | ||
| src, err = mountFd(nsHandles, m) | ||
| } else { | ||
| // Mount tmpfs in initial user ns and chown it | ||
| entry := mountEntry{Mount: m} | ||
| mountConfig := &mountConfig{ | ||
| root: p.config.Config.Rootfs, | ||
| label: p.config.Config.MountLabel, | ||
| rootlessCgroups: p.config.Config.RootlessCgroups, | ||
| cgroupns: p.config.Config.Namespaces.Contains(configs.NEWCGROUP), | ||
| } | ||
| err := mountToRootfs(mountConfig, entry) | ||
| if err == nil { | ||
| destPath, _ := securejoin.SecureJoin(mountConfig.root, m.Destination) | ||
| mountFile, err := os.OpenFile(destPath, unix.O_PATH|unix.O_CLOEXEC, 0) | ||
|
Comment on lines
+760
to
+761
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also insecure for the same reason as above, this should've been |
||
| uid, _ := p.config.Config.HostRootUID() | ||
| gid, _ := p.config.Config.HostRootGID() | ||
| err = sys.FchownFile(mountFile, uid, gid) | ||
| if err == nil { | ||
| src = &mountSource{ | ||
| file: mountFile, | ||
| Type: mountSourcePlain, | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+750
to
+771
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be done with |
||
| } | ||
| logrus.Debugf("mount source thread: handling request for %q: %v %v", m.Source, src, err) | ||
| responseCh <- response{ | ||
| src: src, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1116,17 +1116,15 @@ func setupUserNamespace(spec *specs.Spec, config *configs.Config) error { | |
| "gid_map": gidMap, | ||
| }).Debugf("config uses path-based userns configuration -- current uid and gid mappings cached") | ||
| } | ||
| rootUID, err := config.HostRootUID() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| rootGID, err := config.HostRootGID() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| for _, node := range config.Devices { | ||
| node.Uid = uint32(rootUID) | ||
| node.Gid = uint32(rootGID) | ||
| hostUID, err := config.HostUID(int(node.Uid)) | ||
| if err == nil { | ||
| node.Uid = uint32(hostUID) | ||
| } | ||
| hostGID, err := config.HostGID(int(node.Gid)) | ||
| if err == nil { | ||
| node.Gid = uint32(hostGID) | ||
| } | ||
| } | ||
|
Comment on lines
1119
to
1128
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this in general, but in the |
||
| return nil | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all insecure. You need to use
mknodatwithOpenInRootand then after doing the re-open (again withOpenInRoot) you need to doVerifyInode. libpathrs has helpers for tne first bit.