diff --git a/4974.patch b/4974.patch new file mode 100644 index 0000000..f0d9f89 --- /dev/null +++ b/4974.patch @@ -0,0 +1,213 @@ +From fd50472486365819fe95e164c4c67ecf0c5803b4 Mon Sep 17 00:00:00 2001 +From: Cedric Clerget +Date: Fri, 24 Jan 2020 15:52:08 +0100 +Subject: [PATCH] Fix a logic error when 'allow setuid = no' with a privileged + installation was forced root user to always fallback to user namespace. Add + CAP_SYS_ADMIN check for root user to automatically fallback to user namespace + if the capability is missing. + +--- + cmd/internal/cli/actions_linux.go | 35 +++++++++++----- + pkg/util/capabilities/process.go | 58 +++++++++++++++++++++++++++ + pkg/util/capabilities/process_test.go | 51 +++++++++++++++++++++++ + 3 files changed, 134 insertions(+), 10 deletions(-) + create mode 100644 pkg/util/capabilities/process.go + create mode 100644 pkg/util/capabilities/process_test.go + +diff --git a/cmd/internal/cli/actions_linux.go b/cmd/internal/cli/actions_linux.go +index 8cc823379e..1d68ae9876 100644 +--- a/cmd/internal/cli/actions_linux.go ++++ b/cmd/internal/cli/actions_linux.go +@@ -33,9 +33,11 @@ import ( + "github.com/sylabs/singularity/pkg/image/unpacker" + "github.com/sylabs/singularity/pkg/runtime/engine/config" + singularityConfig "github.com/sylabs/singularity/pkg/runtime/engine/singularity/config" ++ "github.com/sylabs/singularity/pkg/util/capabilities" + "github.com/sylabs/singularity/pkg/util/crypt" + "github.com/sylabs/singularity/pkg/util/gpu" + "github.com/sylabs/singularity/pkg/util/namespaces" ++ "golang.org/x/sys/unix" + ) + + // EnsureRootPriv ensures that a command is executed with root privileges. +@@ -216,23 +218,42 @@ func execStarter(cobraCmd *cobra.Command, image string, args []string, name stri + engineConfig.SetImage(abspath) + } + ++ // privileged installation by default + useSuid := true + + // singularity was compiled with '--without-suid' option + if buildcfg.SINGULARITY_SUID_INSTALL == 0 { + useSuid = false ++ ++ if !UserNamespace && uid != 0 { ++ sylog.Verbosef("Unprivileged installation: using user namespace") ++ UserNamespace = true ++ } + } + + // use non privileged starter binary: +- // - if we are the root user +- // - if we are already running inside a user namespace ++ // - if running as root ++ // - if already running inside a user namespace + // - if user namespace is requested +- // - if 'allow setuid = no' is set in singularity.conf ++ // - if running as user and 'allow setuid = no' is set in singularity.conf + if uid == 0 || insideUserNs || UserNamespace || !engineConfig.File.AllowSetuid { + useSuid = false +- if buildcfg.SINGULARITY_SUID_INSTALL == 1 && !engineConfig.File.AllowSetuid { ++ ++ // fallback to user namespace: ++ // - for non root user with setuid installation and 'allow setuid = no' ++ // - for root user without effective capability CAP_SYS_ADMIN ++ if uid != 0 && buildcfg.SINGULARITY_SUID_INSTALL == 1 && !engineConfig.File.AllowSetuid { + sylog.Verbosef("'allow setuid' set to 'no' by configuration, fallback to user namespace") + UserNamespace = true ++ } else if uid == 0 && !UserNamespace { ++ caps, err := capabilities.GetProcessEffective() ++ if err != nil { ++ sylog.Fatalf("Could not get process effective capabilities: %s", err) ++ } ++ if caps&uint64(1< - 3.5.2-1.2 +- Add patch for PR #4974. Only the src rpm is being used, for + building a --without-suid installation, so this won't be released + to EPEL or Fedora other than rawhide.. + * Tue Dec 17 2019 Dave Dykstra - 3.5.2-1.1 - Upgrade to upstream 3.5.2, keeping #4768 patch only on el8