Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions locale-helper/allow_caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type allowCallerRegistry struct {
privilegedGroupID uint32
processGroups func(uint32) ([]uint32, error)
processParent func(uint32) (uint32, error)
processStartTime func(uint32) (uint64, error)

mu sync.RWMutex
callers map[string]callerInfo
Expand Down Expand Up @@ -128,6 +129,7 @@ func newAllowCallerRegistryWithConfig(service allowCallerBus, stateFile string,
busID: busID,
privilegedGroupID: privilegedGroupID,
processGroups: getProcessGroups,
processStartTime: getProcessStartTime,
processParent: getProcessParentPID,
callers: make(map[string]callerInfo),
}, nil
Expand Down Expand Up @@ -336,7 +338,7 @@ func (r *allowCallerRegistry) authorizeRegistrar(sender dbus.Sender, uniqueName
}

// Capture starttime before reading /proc to detect PID reuse (TOCTOU mitigation).
senderStartTime, err := getProcessStartTime(senderPID)
senderStartTime, err := r.processStartTime(senderPID)
if err != nil {
return fmt.Errorf("get sender %s start time failed: %w", sender, err)
}
Expand All @@ -347,7 +349,7 @@ func (r *allowCallerRegistry) authorizeRegistrar(sender dbus.Sender, uniqueName
}

// Verify PID was not recycled during /proc access.
checkStartTime, err := getProcessStartTime(senderPID)
checkStartTime, err := r.processStartTime(senderPID)
if err != nil || checkStartTime != senderStartTime {
return fmt.Errorf("sender %s PID %d reused during authorization", sender, senderPID)
}
Expand Down
15 changes: 15 additions & 0 deletions locale-helper/allow_caller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ func TestAddCallerAuthorizedSender(t *testing.T) {

r := newRegistryForTest(t, bus)
r.privilegedGroupID = 42
r.processStartTime = func(pid uint32) (uint64, error) {
return 12345, nil
}
r.processGroups = func(pid uint32) ([]uint32, error) {
return []uint32{42}, nil
}
Expand Down Expand Up @@ -604,6 +607,9 @@ func TestAuthorizeRegistrar(t *testing.T) {
bus.connPID[":1.0"] = 5
r := newRegistryForTest(t, bus)
r.privilegedGroupID = 42
r.processStartTime = func(pid uint32) (uint64, error) {
return 12345, nil
}
r.processGroups = func(pid uint32) ([]uint32, error) {
return []uint32{99}, nil
}
Expand All @@ -619,6 +625,9 @@ func TestAuthorizeRegistrar(t *testing.T) {
bus.connUID[":1.100"] = 2000
r := newRegistryForTest(t, bus)
r.privilegedGroupID = 42
r.processStartTime = func(pid uint32) (uint64, error) {
return 12345, nil
}
r.processGroups = func(pid uint32) ([]uint32, error) {
return []uint32{42}, nil
}
Expand All @@ -635,6 +644,9 @@ func TestAuthorizeRegistrar(t *testing.T) {
bus.connPID[":1.100"] = 10
r := newRegistryForTest(t, bus)
r.privilegedGroupID = 42
r.processStartTime = func(pid uint32) (uint64, error) {
return 12345, nil
}
r.processGroups = func(pid uint32) ([]uint32, error) {
return []uint32{42}, nil
}
Expand Down Expand Up @@ -662,6 +674,9 @@ func TestAuthorizeRegistrar(t *testing.T) {
bus.connPID[":1.100"] = 10
r := newRegistryForTest(t, bus)
r.privilegedGroupID = 42
r.processStartTime = func(pid uint32) (uint64, error) {
return 12345, nil
}
r.processGroups = func(pid uint32) ([]uint32, error) {
return []uint32{42}, nil
}
Expand Down
Loading