summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBrian Geffon <bgeffon@google.com>2018-08-27 17:20:36 -0700
committerShentubot <shentubot@google.com>2018-08-27 17:21:37 -0700
commitf0492d45aa31e32f8a04b13b7bf53e0161e1afb6 (patch)
tree78ef1626271ba6c96e0482c2e19874774887aa3b
parent0923bcf06bffe0216cd685f49e83a07201d48cc3 (diff)
Add /proc/sys/kernel/shm[all,max,mni].
PiperOrigin-RevId: 210459956 Change-Id: I51859b90fa967631e0a54a390abc3b5541fbee66
-rw-r--r--pkg/abi/linux/shm.go11
-rw-r--r--pkg/sentry/fs/proc/sys.go6
-rw-r--r--pkg/sentry/kernel/shm/shm.go34
3 files changed, 25 insertions, 26 deletions
diff --git a/pkg/abi/linux/shm.go b/pkg/abi/linux/shm.go
index 9149ed094..f50b3c2e2 100644
--- a/pkg/abi/linux/shm.go
+++ b/pkg/abi/linux/shm.go
@@ -14,6 +14,8 @@
package linux
+import "math"
+
// shmat(2) flags. Source: include/uapi/linux/shm.h
const (
SHM_RDONLY = 010000 // Read-only access.
@@ -38,6 +40,15 @@ const (
SHM_INFO = 14
)
+// SHM defaults as specified by linux. Source: include/uapi/linux/shm.h
+const (
+ SHMMIN = 1
+ SHMMNI = 4096
+ SHMMAX = math.MaxUint64 - 1<<24
+ SHMALL = math.MaxUint64 - 1<<24
+ SHMSEG = 4096
+)
+
// ShmidDS is equivalent to struct shmid64_ds. Source:
// include/uapi/asm-generic/shmbuf.h
type ShmidDS struct {
diff --git a/pkg/sentry/fs/proc/sys.go b/pkg/sentry/fs/proc/sys.go
index a2d36ca23..384b4ffe1 100644
--- a/pkg/sentry/fs/proc/sys.go
+++ b/pkg/sentry/fs/proc/sys.go
@@ -17,7 +17,9 @@ package proc
import (
"fmt"
"io"
+ "strconv"
+ "gvisor.googlesource.com/gvisor/pkg/abi/linux"
"gvisor.googlesource.com/gvisor/pkg/sentry/context"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs/proc/seqfile"
@@ -102,6 +104,10 @@ func (p *proc) newKernelDir(ctx context.Context, msrc *fs.MountSource) *fs.Inode
d := &ramfs.Dir{}
d.InitDir(ctx, nil, fs.RootOwner, fs.FilePermsFromMode(0555))
d.AddChild(ctx, "hostname", p.newHostname(ctx, msrc))
+
+ d.AddChild(ctx, "shmmax", p.newStubProcFSFile(ctx, msrc, []byte(strconv.FormatUint(linux.SHMMAX, 10))))
+ d.AddChild(ctx, "shmall", p.newStubProcFSFile(ctx, msrc, []byte(strconv.FormatUint(linux.SHMALL, 10))))
+ d.AddChild(ctx, "shmmni", p.newStubProcFSFile(ctx, msrc, []byte(strconv.FormatUint(linux.SHMMNI, 10))))
return newFile(d, msrc, fs.SpecialDirectory, nil)
}
diff --git a/pkg/sentry/kernel/shm/shm.go b/pkg/sentry/kernel/shm/shm.go
index 1ac444094..77973951e 100644
--- a/pkg/sentry/kernel/shm/shm.go
+++ b/pkg/sentry/kernel/shm/shm.go
@@ -35,7 +35,6 @@ package shm
import (
"fmt"
- "math"
"sync"
"gvisor.googlesource.com/gvisor/pkg/abi/linux"
@@ -52,23 +51,6 @@ import (
"gvisor.googlesource.com/gvisor/pkg/syserror"
)
-// Various limits for shared memory segments.
-const (
- // shmsTotalMaxPages is the system-wide limit on all shared memory segments, measured
- // in number of pages.
- shmsTotalMaxPages = math.MaxInt64 // SHMALL
-
- // shmMaxSize is the maximum size of a single segment, in bytes.
- shmMaxSize = math.MaxInt64 // SHMMAX
-
- // shmMinSize is the minimum specifiable size of a segment, effectively
- // yielding a size rounded up to the next page size. Measured in bytes.
- shmMinSize = 1 // SHMMIN
-
- // shmsTotalMax is the maximum number of segments on the system.
- shmsTotalMax = 4096 // SHMMNI
-)
-
// Registry tracks all shared memory segments in an IPC namespace. The registry
// provides the mechanisms for creating and finding segments, and reporting
// global shm parameters.
@@ -119,7 +101,7 @@ func (r *Registry) findByKey(key int32) *Shm {
// FindOrCreate looks up or creates a segment in the registry. It's functionally
// analogous to open(2).
func (r *Registry) FindOrCreate(ctx context.Context, pid, key int32, size uint64, mode linux.FileMode, private, create, exclusive bool) (*Shm, error) {
- if create && (size < shmMinSize || size > shmMaxSize) {
+ if create && (size < linux.SHMMIN || size > linux.SHMMAX) {
// "A new segment was to be created and size is less than SHMMIN or
// greater than SHMMAX." - man shmget(2)
return nil, syserror.EINVAL
@@ -128,7 +110,7 @@ func (r *Registry) FindOrCreate(ctx context.Context, pid, key int32, size uint64
r.mu.Lock()
defer r.mu.Unlock()
- if len(r.shms) >= shmsTotalMax {
+ if len(r.shms) >= linux.SHMMNI {
// "All possible shared memory IDs have been taken (SHMMNI) ..."
// - man shmget(2)
return nil, syserror.ENOSPC
@@ -179,7 +161,7 @@ func (r *Registry) FindOrCreate(ctx context.Context, pid, key int32, size uint64
return nil, syserror.EINVAL
}
- if numPages := sizeAligned / usermem.PageSize; r.totalPages+numPages > shmsTotalMaxPages {
+ if numPages := sizeAligned / usermem.PageSize; r.totalPages+numPages > linux.SHMALL {
// "... allocating a segment of the requested size would cause the
// system to exceed the system-wide limit on shared memory (SHMALL)."
// - man shmget(2)
@@ -245,11 +227,11 @@ func (r *Registry) newShm(ctx context.Context, pid, key int32, creator fs.FileOw
// system. See shmctl(IPC_INFO).
func (r *Registry) IPCInfo() *linux.ShmParams {
return &linux.ShmParams{
- ShmMax: shmMaxSize,
- ShmMin: shmMinSize,
- ShmMni: shmsTotalMax,
- ShmSeg: shmsTotalMax, // Linux also sets this to SHMMNI.
- ShmAll: shmsTotalMaxPages,
+ ShmMax: linux.SHMMAX,
+ ShmMin: linux.SHMMIN,
+ ShmMni: linux.SHMMNI,
+ ShmSeg: linux.SHMSEG,
+ ShmAll: linux.SHMALL,
}
}