diff options
author | Zach Koopmans <zkoopmans@google.com> | 2019-02-05 10:00:22 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-02-05 10:02:06 -0800 |
commit | 0cf7fc4e115c2dcc40901c44b238ab36b5d966fc (patch) | |
tree | 0b283a209ab28fa6a32f8f357264e9ee947b4d84 /pkg/sentry/arch | |
parent | 3eae03fe4f2813dc56d6e33cd7feb7760fccfb25 (diff) |
Change /proc/PID/cmdline to read environment vector.
- Change proc to return envp on overwrite of argv with limitations from
upstream.
- Add unit tests
- Change layout of argv/envp on the stack so that end of argv is contiguous with
beginning of envp.
PiperOrigin-RevId: 232506107
Change-Id: I993880499ab2c1220f6dc456a922235c49304dec
Diffstat (limited to 'pkg/sentry/arch')
-rw-r--r-- | pkg/sentry/arch/stack.go | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/pkg/sentry/arch/stack.go b/pkg/sentry/arch/stack.go index 716a3574d..f2cfb0426 100644 --- a/pkg/sentry/arch/stack.go +++ b/pkg/sentry/arch/stack.go @@ -170,6 +170,24 @@ func (s *Stack) Load(args []string, env []string, aux Auxv) (StackLayout, error) // Make sure we start with a 16-byte alignment. s.Align(16) + // Push the environment vector so the end of the argument vector is adjacent to + // the beginning of the environment vector. + // While the System V abi for x86_64 does not specify an ordering to the + // Information Block (the block holding the arg, env, and aux vectors), + // support features like setproctitle(3) naturally expect these segments + // to be in this order. See: https://www.uclibc.org/docs/psABI-x86_64.pdf + // page 29. + l.EnvvEnd = s.Bottom + envAddrs := make([]usermem.Addr, len(env)) + for i := len(env) - 1; i >= 0; i-- { + addr, err := s.Push(env[i]) + if err != nil { + return StackLayout{}, err + } + envAddrs[i] = addr + } + l.EnvvStart = s.Bottom + // Push our strings. l.ArgvEnd = s.Bottom argAddrs := make([]usermem.Addr, len(args)) @@ -182,18 +200,6 @@ func (s *Stack) Load(args []string, env []string, aux Auxv) (StackLayout, error) } l.ArgvStart = s.Bottom - // Push our environment. - l.EnvvEnd = s.Bottom - envAddrs := make([]usermem.Addr, len(env)) - for i := len(env) - 1; i >= 0; i-- { - addr, err := s.Push(env[i]) - if err != nil { - return StackLayout{}, err - } - envAddrs[i] = addr - } - l.EnvvStart = s.Bottom - // We need to align the arguments appropriately. // // We must finish on a 16-byte alignment, but we'll play it |