diff --git a/cmd/tether/ops_linux.go b/cmd/tether/ops_linux.go index 82ee3f491f..f9bb538999 100644 --- a/cmd/tether/ops_linux.go +++ b/cmd/tether/ops_linux.go @@ -151,12 +151,22 @@ func ApplyDefaultULimit() { log.Errorf("Cannot set ulimit for nofile: %s", err.Error()) } + // Setting the soft stack limit to Unlimited causes Linux to enable + // a legacy address-space-layout which is not acceptable to some + // applications. We leave the soft limit unchanged. + // Issue: https://github.com/vmware/vic/issues/8141 + if err := syscall.Getrlimit(syscall.RLIMIT_STACK, &rLimit); err != nil { + log.Errorf("Cannot get ulimit for stack: %s ", err.Error()) + } + + // The hard limit can be safely set to Unlimited. rLimit.Max = defaultULimit - rLimit.Cur = rLimit.Max if err := syscall.Setrlimit(syscall.RLIMIT_STACK, &rLimit); err != nil { log.Errorf("Cannot set ulimit for stack: %s ", err.Error()) } + rLimit.Max = defaultULimit + rLimit.Cur = rLimit.Max if err := syscall.Setrlimit(syscall.RLIMIT_CORE, &rLimit); err != nil { log.Errorf("Cannot set ulimit for core blocks: %s", err.Error()) } diff --git a/cmd/tether/ops_linux_test.go b/cmd/tether/ops_linux_test.go index cc7eea3830..9eda0bb1b6 100644 --- a/cmd/tether/ops_linux_test.go +++ b/cmd/tether/ops_linux_test.go @@ -20,7 +20,10 @@ import ( "errors" "fmt" "syscall" + "testing" + "github.com/Sirupsen/logrus" + "github.com/stretchr/testify/require" "github.com/vishvananda/netlink" "github.com/vmware/vic/pkg/trace" @@ -159,3 +162,32 @@ func (t *Mocker) LinkBySlot(slot int32) (netlink.Link, error) { return nil, errors.New("no such interface") } + +func TestLimitSetting(t *testing.T) { + var rLimitOut syscall.Rlimit + + // CORE Limit should be set to Unlimited, MEMLOCK and NPROC, can only + // be set by root, therefore they cannot be tested here + ApplyDefaultULimit() + + if err := syscall.Getrlimit(syscall.RLIMIT_CORE, &rLimitOut); err != nil { + logrus.Errorf("Cannot get ulimit for stack: %s ", err.Error()) + } + require.Equal(t, rLimitOut.Max, uint64(defaultULimit)) + require.Equal(t, rLimitOut.Cur, uint64(defaultULimit)) + + // Check the soft limit on the stack size, the new soft limit should be unchanged + // Issue: https://github.com/vmware/vic/issues/8141 + if err := syscall.Getrlimit(syscall.RLIMIT_STACK, &rLimitOut); err != nil { + logrus.Errorf("Cannot get ulimit for stack: %s ", err.Error()) + } + defaultSoftLimit := rLimitOut.Cur + + ApplyDefaultULimit() + + if err := syscall.Getrlimit(syscall.RLIMIT_STACK, &rLimitOut); err != nil { + logrus.Errorf("Cannot get ulimit for stack: %s ", err.Error()) + } + require.Equal(t, rLimitOut.Max, uint64(defaultULimit)) + require.Equal(t, rLimitOut.Cur, defaultSoftLimit) +}