Skip to content

Commit 8316336

Browse files
authored
[CWS] fix process context zero (#44066)
### What does this PR do? This PR fixes a bug where the zero process context was being unintentionally reused. It removes the process-context allocation from the zeroer function; the pointer should only be initialized via setProcessContext and must not be modified directly. By removing the default allocation, we can detect incorrect access patterns earlier through a panic. ### Motivation ### Describe how you validated your changes ### Additional Notes Co-authored-by: sylvain.afchain <[email protected]>
1 parent 76ef9df commit 8316336

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

pkg/security/probe/probe_ebpf.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,11 +1015,7 @@ func (p *EBPFProbe) setProcessContext(eventType model.EventType, event *model.Ev
10151015
panic("should always return a process cache entry")
10161016
}
10171017

1018-
// use ProcessCacheEntry process context as process context
10191018
event.ProcessContext = &event.ProcessCacheEntry.ProcessContext
1020-
if event.ProcessContext == nil {
1021-
panic("should always return a process context")
1022-
}
10231019

10241020
if process.IsKThread(event.ProcessContext.PPid, event.ProcessContext.Pid) {
10251021
return false
@@ -1620,6 +1616,8 @@ func (p *EBPFProbe) handleBeforeProcessContext(event *model.Event, data []byte,
16201616
// handleEarlyReturnEvents processes events that may require early termination of the event handling pipeline.
16211617
// It returns false if an error occurs or if the event should not be dispatched further, true otherwise
16221618
func (p *EBPFProbe) handleEarlyReturnEvents(event *model.Event, offset int, dataLen uint64, data []byte, newEntryCb func(entry *model.ProcessCacheEntry, err error)) bool {
1619+
event.ProcessContext = &model.ProcessContext{}
1620+
16231621
var err error
16241622
eventType := event.GetEventType()
16251623
switch eventType {

pkg/security/secl/model/model_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ type Event struct {
154154

155155
// NewEventZeroer returns a function that can be used to zero an Event
156156
func NewEventZeroer() func(*Event) {
157-
var eventZero = Event{BaseEvent: BaseEvent{Os: runtime.GOOS, ProcessContext: &ProcessContext{}}}
157+
var eventZero = Event{BaseEvent: BaseEvent{Os: runtime.GOOS}}
158158

159159
return func(e *Event) {
160160
*e = eventZero

0 commit comments

Comments
 (0)