Skip to content

Commit

Permalink
Use mutex to protect access to librpm (elastic#40525)
Browse files Browse the repository at this point in the history
* use mutex for access to librpm

* add changelog
  • Loading branch information
fearful-symmetry authored Aug 15, 2024
1 parent 08dac31 commit 46fd21c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]

*Auditbeat*

- Fix segfaults that may happen if user runs multiple instances of the package metricset {pull}40525[40525]


*Filebeat*
Expand Down
7 changes: 6 additions & 1 deletion x-pack/auditbeat/module/system/package/rpm_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"runtime"
"strings"
"sync"
"time"
"unsafe"

Expand Down Expand Up @@ -178,9 +179,12 @@ const (
)

var openedLibrpm *librpm
var librpmLock sync.Mutex

// closeDataset performs cleanup when the dataset is closed.
func closeDataset() error {
librpmLock.Lock()
defer librpmLock.Unlock()
if openedLibrpm != nil {
err := openedLibrpm.close()
openedLibrpm = nil
Expand Down Expand Up @@ -341,6 +345,8 @@ func openLibrpm() (*librpm, error) {
}

func listRPMPackages(ownsThread bool) ([]*Package, error) {
librpmLock.Lock()
defer librpmLock.Unlock()
// In newer versions, librpm is using the thread-local variable
// `disableInterruptSafety` in rpmio/rpmsq.c to disable signal
// traps. To make sure our settings remain in effect throughout
Expand Down Expand Up @@ -398,7 +404,6 @@ func listRPMPackages(ownsThread bool) ([]*Package, error) {

packages = append(packages, pkg)
}

return packages, nil
}

Expand Down

0 comments on commit 46fd21c

Please sign in to comment.