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
10 changes: 6 additions & 4 deletions locale-helper/allow_caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type persistedCallerEntry struct {
}

type persistedAllowCallers struct {
BusID string `json:"busId"`
BusID string `json:"busId"`
Callers []persistedCallerEntry `json:"callers"`
}

Expand All @@ -71,6 +71,7 @@ type allowCallerRegistry struct {
stateFile string
busID string
privilegedGroupID uint32
processStartTime func(uint32) (uint64, error)
processGroups func(uint32) ([]uint32, error)
processParent func(uint32) (uint32, error)

Expand Down Expand Up @@ -127,6 +128,7 @@ func newAllowCallerRegistryWithConfig(service allowCallerBus, stateFile string,
stateFile: stateFile,
busID: busID,
privilegedGroupID: privilegedGroupID,
processStartTime: getProcessStartTime,
processGroups: getProcessGroups,
processParent: getProcessParentPID,
callers: make(map[string]callerInfo),
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 Expand Up @@ -525,4 +527,4 @@ func (r *allowCallerRegistry) load() error {
}
r.mu.Unlock()
return nil
}
}
6 changes: 5 additions & 1 deletion locale-helper/allow_caller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func newRegistryForTest(t *testing.T, bus *mockAllowCallerBus) *allowCallerRegis
require.NoError(t, err)
require.NotNil(t, r)
require.Equal(t, bus.busID, r.busID)
r.processStartTime = func(uint32) (uint64, error) {
return 1, nil
}
return r
}

Expand Down Expand Up @@ -218,6 +221,7 @@ func TestNewAllowCallerRegistryWithConfig(t *testing.T) {
assert.Equal(t, uint32(42), r.privilegedGroupID)
assert.NotNil(t, r.callers)
assert.Len(t, r.callers, 0)
assert.NotNil(t, r.processStartTime)
assert.NotNil(t, r.processGroups)
assert.NotNil(t, r.processParent)
})
Expand Down Expand Up @@ -692,4 +696,4 @@ func TestLookupGroupID(t *testing.T) {
gid, err := lookupGroupID("root")
require.NoError(t, err)
assert.Equal(t, uint32(0), gid)
}
}
Loading