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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
package landlock
import ll "github.com/landlock-lsm/go-landlock/landlock/syscall"
type abiInfo struct {
version int
supportedAccessFS AccessFSSet
supportedAccessNet AccessNetSet
}
var abiInfos = []abiInfo{
{
version: 0,
supportedAccessFS: 0,
},
{
version: 1,
supportedAccessFS: (1 << 13) - 1,
},
{
version: 2,
supportedAccessFS: (1 << 14) - 1,
},
{
version: 3,
supportedAccessFS: (1 << 15) - 1,
},
{
version: 4,
supportedAccessFS: (1 << 15) - 1,
supportedAccessNet: (1 << 2) - 1,
},
{
version: 5,
supportedAccessFS: (1 << 16) - 1,
supportedAccessNet: (1 << 2) - 1,
},
}
func (a abiInfo) asConfig() Config {
return Config{
handledAccessFS: a.supportedAccessFS,
handledAccessNet: a.supportedAccessNet,
}
}
// getSupportedABIVersion returns the kernel-supported ABI version.
//
// If the ABI version supported by the kernel is higher than the
// newest one known to go-landlock, the highest ABI version known to
// go-landlock is returned.
func getSupportedABIVersion() abiInfo {
v, err := ll.LandlockGetABIVersion()
if err != nil {
v = 0 // ABI version 0 is "no Landlock support".
}
if v >= len(abiInfos) {
v = len(abiInfos) - 1
}
return abiInfos[v]
}
|