MCPcopy Create free account
hub / github.com/opencontainers/runc / PatchAndLoad

Function PatchAndLoad

libcontainer/seccomp/patchbpf/enosys_linux.go:729–758  ·  view source on GitHub ↗

PatchAndLoad takes a seccomp configuration and a libseccomp filter which has been pre-configured with the set of rules in the seccomp config. It then patches said filter to handle -ENOSYS in a much nicer manner than the default libseccomp default action behaviour, and loads the patched filter into t

(config *configs.Seccomp, filter *libseccomp.ScmpFilter)

Source from the content-addressed store, hash-verified

727// default libseccomp default action behaviour, and loads the patched filter
728// into the kernel for the current process.
729func PatchAndLoad(config *configs.Seccomp, filter *libseccomp.ScmpFilter) (int, error) {
730 // Generate a patched filter.
731 fprog, err := enosysPatchFilter(config, filter)
732 if err != nil {
733 return -1, fmt.Errorf("error patching filter: %w", err)
734 }
735
736 // Get the set of libseccomp flags set.
737 seccompFlags, noNewPrivs, err := filterFlags(config, filter)
738 if err != nil {
739 return -1, fmt.Errorf("unable to fetch seccomp filter flags: %w", err)
740 }
741
742 // Set no_new_privs if it was requested, though in runc we handle
743 // no_new_privs separately so warn if we hit this path.
744 if noNewPrivs {
745 logrus.Warnf("potentially misconfigured filter -- setting no_new_privs in seccomp path")
746 if err := unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); err != nil {
747 return -1, fmt.Errorf("error enabling no_new_privs bit: %w", err)
748 }
749 }
750
751 // Finally, load the filter.
752 fd, err := sysSeccompSetFilter(seccompFlags, fprog)
753 if err != nil {
754 return -1, fmt.Errorf("error loading seccomp filter: %w", err)
755 }
756
757 return fd, nil
758}

Callers 1

InitSeccompFunction · 0.92

Calls 3

enosysPatchFilterFunction · 0.85
filterFlagsFunction · 0.85
sysSeccompSetFilterFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…