-
Notifications
You must be signed in to change notification settings - Fork 324
/
checkprocfs.go
36 lines (30 loc) · 964 Bytes
/
checkprocfs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Tetragon
package checkprocfs
import (
"path/filepath"
"syscall"
"github.com/cilium/tetragon/pkg/logger"
"github.com/cilium/tetragon/pkg/option"
"github.com/sirupsen/logrus"
)
// Check tries to determine whether the configured procfs is the host's procfs
func Check() {
path := filepath.Join(option.Config.ProcFS, "1", "ns", "pid")
var stat syscall.Stat_t
if err := syscall.Stat(path, &stat); err != nil {
logger.GetLogger().WithField("path", path).WithError(err).Info("stat failed")
}
// we compare against the known inode of the host pid namespace:
// ...
// PROC_PID_INIT_INO = 0xEFFFFFFCU,
// ...
expectedIno := uint64(0xEFFFFFFC)
if stat.Ino != expectedIno {
logger.GetLogger().WithFields(logrus.Fields{
"path": path,
"inode": stat.Ino,
"expected inode": expectedIno,
}).Warn("inode mismatch: procfs does not appear to be host procfs")
}
}