From 8a33161080eba90148c0ab3e7d3866a521510662 Mon Sep 17 00:00:00 2001 From: Yunlu Wen Date: Thu, 16 Jul 2026 18:04:01 +0800 Subject: [PATCH] fix: downgrade to landlock v1 (#39139) --- dify-agent-runtime/cmd/runner/main.go | 8 ++---- .../internal/landlock/landlock_linux.go | 28 ++----------------- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/dify-agent-runtime/cmd/runner/main.go b/dify-agent-runtime/cmd/runner/main.go index 910eff8a9d2..29f35b4867d 100644 --- a/dify-agent-runtime/cmd/runner/main.go +++ b/dify-agent-runtime/cmd/runner/main.go @@ -16,7 +16,6 @@ package main import ( "encoding/json" - "errors" "fmt" "os" "os/exec" @@ -174,11 +173,8 @@ func childMode() { jobDir := filepath.Dir(scriptPath) cfg := landlock.ConfigFromEnv(home, cwd, jobDir) if err := landlock.Restrict(cfg); err != nil { - if errors.Is(err, landlock.ErrNotSupported) { - fmt.Fprintf(os.Stderr, "shellctl-runner: WARNING: %v — running without filesystem isolation\n", err) - } else { - cmdutil.HandleError(err, 125, "landlock restrict") - } + // the landlock is best-effort, so we just log the error whatever it is + fmt.Fprintf(os.Stderr, "shellctl-runner: WARNING: %v — running without filesystem isolation\n", err) } } diff --git a/dify-agent-runtime/internal/landlock/landlock_linux.go b/dify-agent-runtime/internal/landlock/landlock_linux.go index 8249df278dd..20524f4ebad 100644 --- a/dify-agent-runtime/internal/landlock/landlock_linux.go +++ b/dify-agent-runtime/internal/landlock/landlock_linux.go @@ -3,33 +3,17 @@ package landlock import ( - "errors" - "fmt" "os" - "syscall" golandlock "github.com/landlock-lsm/go-landlock/landlock" ) -// ErrNotSupported is returned when the kernel does not support Landlock. -var ErrNotSupported = errors.New("landlock: not supported by kernel") - -// Restrict applies Landlock filesystem restrictions for the current process. -// -// It first tries strict enforcement. If the kernel lacks Landlock support, -// it falls back to BestEffort (which may silently degrade) and returns -// ErrNotSupported so callers can log a warning. +// Restrict applies Landlock V1 filesystem restrictions for the current process. func Restrict(cfg *Config) error { rules := buildRules(cfg) - if err := golandlock.V5.RestrictPaths(rules...); err != nil { - if !isNotSupported(err) { - return fmt.Errorf("landlock: restrict paths: %w", err) - } - if err2 := golandlock.V5.BestEffort().RestrictPaths(rules...); err2 != nil { - return fmt.Errorf("landlock: best-effort restrict paths: %w", err2) - } - return ErrNotSupported + if err := golandlock.V1.RestrictPaths(rules...); err != nil { + return err } return nil } @@ -63,12 +47,6 @@ func buildRules(cfg *Config) []golandlock.Rule { return rules } -// isNotSupported reports whether err indicates the kernel does not support -// Landlock (ENOSYS = syscall absent, EOPNOTSUPP = feature disabled). -func isNotSupported(err error) bool { - return errors.Is(err, syscall.ENOSYS) || errors.Is(err, syscall.EOPNOTSUPP) -} - func filterExisting(paths []string) []string { var out []string for _, p := range paths {