diff --git a/locale-helper/allow_caller.go b/locale-helper/allow_caller.go index ddc3492..eadcdf8 100644 --- a/locale-helper/allow_caller.go +++ b/locale-helper/allow_caller.go @@ -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 @@ -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 @@ -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) } @@ -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) } diff --git a/locale-helper/allow_caller_test.go b/locale-helper/allow_caller_test.go index cc8cebc..c414e6b 100644 --- a/locale-helper/allow_caller_test.go +++ b/locale-helper/allow_caller_test.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 }