Statfs Namelen should be NAME_MAX not PATH_MAX

We accidentally set the wrong maximum. I've also added PATH_MAX and
NAME_MAX to the linux abi package.

PiperOrigin-RevId: 216221311
Change-Id: I44805fcf21508831809692184a0eba4cee469633
This commit is contained in:
Michael Pratt 2018-10-08 11:38:02 -07:00 committed by Shentubot
parent e9e8be6613
commit 569c2b06c4
6 changed files with 12 additions and 9 deletions

View File

@ -28,6 +28,12 @@ const (
V9FS_MAGIC = 0x01021997
)
// Filesystem path limits, from uapi/linux/limits.h.
const (
NAME_MAX = 255
PATH_MAX = 4096
)
// Statfs is struct statfs, from uapi/asm-generic/statfs.h.
type Statfs struct {
// Type is one of the filesystem magic values, defined above.

View File

@ -19,7 +19,6 @@ import (
"debug/elf"
"fmt"
"io"
"syscall"
"gvisor.googlesource.com/gvisor/pkg/abi"
"gvisor.googlesource.com/gvisor/pkg/abi/linux"
@ -409,7 +408,7 @@ func loadParsedELF(ctx context.Context, m *mm.MemoryManager, f *fs.File, info el
ctx.Infof("PT_INTERP path too small: %v", phdr.Filesz)
return loadedELF{}, syserror.ENOEXEC
}
if phdr.Filesz > syscall.PathMax {
if phdr.Filesz > linux.PATH_MAX {
ctx.Infof("PT_INTERP path too big: %v", phdr.Filesz)
return loadedELF{}, syserror.ENOEXEC
}

View File

@ -133,7 +133,7 @@ func dump(t *kernel.Task, addr usermem.Addr, size uint, maximumBlobSize uint) st
}
func path(t *kernel.Task, addr usermem.Addr) string {
path, err := t.CopyInString(addr, syscall.PathMax)
path, err := t.CopyInString(addr, linux.PATH_MAX)
if err != nil {
return fmt.Sprintf("%#x (error decoding path: %s)", addr, err)
}

View File

@ -115,7 +115,7 @@ func fileOpOn(t *kernel.Task, dirFD kdefs.FD, path string, resolve bool, fn func
// copyInPath copies a path in.
func copyInPath(t *kernel.Task, addr usermem.Addr, allowEmpty bool) (path string, dirPath bool, err error) {
path, err = t.CopyInString(addr, syscall.PathMax)
path, err = t.CopyInString(addr, linux.PATH_MAX)
if err != nil {
return "", false, err
}
@ -1080,7 +1080,7 @@ func symlinkAt(t *kernel.Task, dirFD kdefs.FD, newAddr usermem.Addr, oldAddr use
// The oldPath is copied in verbatim. This is because the symlink
// will include all details, including trailing slashes.
oldPath, err := t.CopyInString(oldAddr, syscall.PathMax)
oldPath, err := t.CopyInString(oldAddr, linux.PATH_MAX)
if err != nil {
return err
}

View File

@ -15,8 +15,6 @@
package linux
import (
"syscall"
"gvisor.googlesource.com/gvisor/pkg/abi/linux"
"gvisor.googlesource.com/gvisor/pkg/sentry/arch"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs"
@ -198,7 +196,7 @@ func statfsImpl(t *kernel.Task, d *fs.Dirent, addr usermem.Addr) error {
Files: info.TotalFiles,
FilesFree: info.FreeFiles,
// Same as Linux for simple_statfs, see fs/libfs.c.
NameLength: syscall.PathMax,
NameLength: linux.NAME_MAX,
FragmentSize: d.Inode.StableAttr.BlockSize,
// Leave other fields 0 like simple_statfs does.
}

View File

@ -76,7 +76,7 @@ func Execve(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.Syscal
envvAddr := args[2].Pointer()
// Extract our arguments.
filename, err := t.CopyInString(filenameAddr, syscall.PathMax)
filename, err := t.CopyInString(filenameAddr, linux.PATH_MAX)
if err != nil {
return 0, nil, err
}