Skip to content

Refs/heads/patch 1 #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 19, 2024
Merged
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
31 changes: 14 additions & 17 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@ import (

// Reset only effective capabilites
func resetEffectiveCapabilities() error {
// Store original capabilities for cleanup
original := cap.GetProc()
// current capability
existing := cap.GetProc()
// Clear all effective capabilites
if err := existing.ClearFlag(cap.Effective); err != nil {
// Restore original capabilities on error
original.SetProc()
return fmt.Errorf("error cleaning effective capabilites %w", err)
}
// set updated capabilitis to current process
if err := existing.SetProc(); err != nil {
// Restore original capabilities on error
original.SetProc()
return fmt.Errorf("error during update capabilites %w", err)
}
return nil
// current capability
existing := cap.GetProc()

// Clear all effective capabilites
if err := existing.ClearFlag(cap.Effective); err != nil {
return fmt.Errorf("error cleaning effective capabilites %w", err)
}

// set updated capabilitis to current process
if err := existing.SetProc(); err != nil {
return fmt.Errorf("error during update capabilites %w", err)
}

return nil
}

// Enforce effective capabilites only
Expand Down
8 changes: 4 additions & 4 deletions selftest/uprobe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ recvLoop:

// symbolToOffset attempts to resolve a 'symbol' name in the binary found at
// 'path' to an offset. The offset can be used for attaching a u(ret)probe
func symbolToOffset(path, symbol string) (uint64, error) {
func symbolToOffset(path, symbol string) (uint32, error) {
f, err := elf.Open(path)
if err != nil {
return 0, fmt.Errorf("could not open elf file to resolve symbol offset: %w", err)
Expand Down Expand Up @@ -125,8 +125,8 @@ func symbolToOffset(path, symbol string) (uint64, error) {
// Find what section the symbol is in by checking the executable section's
// addr space.
for m := range sectionsToSearchForSymbol {
if syms[j].Value >= sectionsToSearchForSymbol[m].Addr &&
syms[j].Value <= sectionsToSearchForSymbol[m].Addr+sectionsToSearchForSymbol[m].Size {
if syms[j].Value > sectionsToSearchForSymbol[m].Addr &&
syms[j].Value < sectionsToSearchForSymbol[m].Addr+sectionsToSearchForSymbol[m].Size {
executableSection = sectionsToSearchForSymbol[m]
}
}
Expand All @@ -135,7 +135,7 @@ func symbolToOffset(path, symbol string) (uint64, error) {
return 0, errors.New("could not find symbol in executable sections of binary")
}

return syms[j].Value - executableSection.Addr + executableSection.Offset, nil
return uint32(syms[j].Value - executableSection.Addr + executableSection.Offset), nil
}
}

Expand Down