summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/kernel/semaphore
diff options
context:
space:
mode:
authorJing Chen <chjing@google.com>2021-02-25 12:54:36 -0800
committergVisor bot <gvisor-bot@google.com>2021-02-25 12:57:01 -0800
commite50ee26207a99930be966bd48e04f5bccd85cc05 (patch)
tree33961a0d07df93ee592c9a84d021d75cb2058a35 /pkg/sentry/kernel/semaphore
parent56053f084f06e61e963b0007e7bf99e69a0f9144 (diff)
Implement SEM_STAT_ANY cmd of semctl.
PiperOrigin-RevId: 359591577
Diffstat (limited to 'pkg/sentry/kernel/semaphore')
-rw-r--r--pkg/sentry/kernel/semaphore/semaphore.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/pkg/sentry/kernel/semaphore/semaphore.go b/pkg/sentry/kernel/semaphore/semaphore.go
index db01e4a97..fe2ab1662 100644
--- a/pkg/sentry/kernel/semaphore/semaphore.go
+++ b/pkg/sentry/kernel/semaphore/semaphore.go
@@ -381,15 +381,24 @@ func (s *Set) Change(ctx context.Context, creds *auth.Credentials, owner fs.File
// GetStat extracts semid_ds information from the set.
func (s *Set) GetStat(creds *auth.Credentials) (*linux.SemidDS, error) {
+ // "The calling process must have read permission on the semaphore set."
+ return s.semStat(creds, fs.PermMask{Read: true})
+}
+
+// GetStatAny extracts semid_ds information from the set without requiring read access.
+func (s *Set) GetStatAny(creds *auth.Credentials) (*linux.SemidDS, error) {
+ return s.semStat(creds, fs.PermMask{})
+}
+
+func (s *Set) semStat(creds *auth.Credentials, permMask fs.PermMask) (*linux.SemidDS, error) {
s.mu.Lock()
defer s.mu.Unlock()
- // "The calling process must have read permission on the semaphore set."
- if !s.checkPerms(creds, fs.PermMask{Read: true}) {
+ if !s.checkPerms(creds, permMask) {
return nil, syserror.EACCES
}
- ds := &linux.SemidDS{
+ return &linux.SemidDS{
SemPerm: linux.IPCPerm{
Key: uint32(s.key),
UID: uint32(creds.UserNamespace.MapFromKUID(s.owner.UID)),
@@ -402,8 +411,7 @@ func (s *Set) GetStat(creds *auth.Credentials) (*linux.SemidDS, error) {
SemOTime: s.opTime.TimeT(),
SemCTime: s.changeTime.TimeT(),
SemNSems: uint64(s.Size()),
- }
- return ds, nil
+ }, nil
}
// SetVal overrides a semaphore value, waking up waiters as needed.