Skip to content

Commit

Permalink
usm: sowatcher: Extend paths support up to 220 characters (#31975)
Browse files Browse the repository at this point in the history
  • Loading branch information
guyarb authored Dec 10, 2024
1 parent 6dea12d commit 90e7b91
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/network/ebpf/c/shared-libraries/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "ktypes.h"

#define LIB_SO_SUFFIX_SIZE 9
#define LIB_PATH_MAX_SIZE 120
#define LIB_PATH_MAX_SIZE 220

typedef struct {
__u32 pid;
Expand Down
4 changes: 2 additions & 2 deletions pkg/network/usm/sharedlibraries/types_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions pkg/network/usm/sharedlibraries/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,53 @@ func (s *SharedLibrarySuite) TestSharedLibraryDetection() {
}, time.Second*10, 100*time.Millisecond)
}

func (s *SharedLibrarySuite) TestLongPath() {
t := s.T()

const (
fileName = "foo-libssl.so"
nullTerminatorLength = len("\x00")
)
padLength := LibPathMaxSize - len(fileName) - len(t.TempDir()) - len("_") - len(string(filepath.Separator)) - nullTerminatorLength
fooPath1, fooPathID1 := createTempTestFile(t, strings.Repeat("a", padLength)+"_"+fileName)
// fooPath2 is longer than the limit we have, thus it will be ignored.
fooPath2, fooPathID2 := createTempTestFile(t, strings.Repeat("a", padLength+1)+"_"+fileName)

registerRecorder := new(utils.CallbackRecorder)
unregisterRecorder := new(utils.CallbackRecorder)

watcher, err := NewWatcher(utils.NewUSMEmptyConfig(), LibsetCrypto,
Rule{
Re: regexp.MustCompile(`foo-libssl.so`),
RegisterCB: registerRecorder.Callback(),
UnregisterCB: unregisterRecorder.Callback(),
},
)
require.NoError(t, err)
watcher.Start()
t.Cleanup(watcher.Stop)

// create files
command1, err := fileopener.OpenFromAnotherProcess(t, fooPath1)
require.NoError(t, err)

command2, err := fileopener.OpenFromAnotherProcess(t, fooPath2)
require.NoError(t, err)

require.Eventuallyf(t, func() bool {
return registerRecorder.CallsForPathID(fooPathID1) == 1 &&
registerRecorder.CallsForPathID(fooPathID2) == 0
}, time.Second*10, 100*time.Millisecond, "")

require.NoError(t, command1.Process.Kill())
require.NoError(t, command2.Process.Kill())

require.Eventually(t, func() bool {
return unregisterRecorder.CallsForPathID(fooPathID1) == 1 &&
unregisterRecorder.CallsForPathID(fooPathID2) == 0
}, time.Second*10, 100*time.Millisecond)
}

func (s *SharedLibrarySuite) TestSharedLibraryDetectionWithPIDAndRootNamespace() {
t := s.T()
_, err := os.Stat("/usr/bin/busybox")
Expand Down

0 comments on commit 90e7b91

Please sign in to comment.