| 1 |
package landlock |
| 2 |
|
| 3 |
import "github.com/landlock-lsm/go-landlock/landlock/internal" |
| 4 |
|
| 5 |
type abiInfo struct { |
| 6 |
version int |
| 7 |
supportedAccessFS AccessFSSet |
| 8 |
supportedAccessNet AccessNetSet |
| 9 |
supportedScoped ScopedSet |
| 10 |
supportedRestrictFlags restrictFlagsSet |
| 11 |
} |
| 12 |
|
| 13 |
var abiInfos = []abiInfo{ |
| 14 |
{ |
| 15 |
version: 0, |
| 16 |
supportedAccessFS: 0, |
| 17 |
}, |
| 18 |
{ |
| 19 |
version: 1, |
| 20 |
supportedAccessFS: (1 << 13) - 1, |
| 21 |
}, |
| 22 |
{ |
| 23 |
version: 2, |
| 24 |
supportedAccessFS: (1 << 14) - 1, |
| 25 |
}, |
| 26 |
{ |
| 27 |
version: 3, |
| 28 |
supportedAccessFS: (1 << 15) - 1, |
| 29 |
}, |
| 30 |
{ |
| 31 |
version: 4, |
| 32 |
supportedAccessFS: (1 << 15) - 1, |
| 33 |
supportedAccessNet: (1 << 2) - 1, |
| 34 |
}, |
| 35 |
{ |
| 36 |
version: 5, |
| 37 |
supportedAccessFS: (1 << 16) - 1, |
| 38 |
supportedAccessNet: (1 << 2) - 1, |
| 39 |
}, |
| 40 |
{ |
| 41 |
version: 6, |
| 42 |
supportedAccessFS: (1 << 16) - 1, |
| 43 |
supportedAccessNet: (1 << 2) - 1, |
| 44 |
supportedScoped: (1 << 2) - 1, |
| 45 |
}, |
| 46 |
{ |
| 47 |
version: 7, |
| 48 |
supportedAccessFS: (1 << 16) - 1, |
| 49 |
supportedAccessNet: (1 << 2) - 1, |
| 50 |
supportedScoped: (1 << 2) - 1, |
| 51 |
supportedRestrictFlags: (1 << 3) - 1, |
| 52 |
}, |
| 53 |
{ |
| 54 |
version: 8, |
| 55 |
supportedAccessFS: (1 << 16) - 1, |
| 56 |
supportedAccessNet: (1 << 2) - 1, |
| 57 |
supportedScoped: (1 << 2) - 1, |
| 58 |
supportedRestrictFlags: (1 << 4) - 1, |
| 59 |
}, |
| 60 |
{ |
| 61 |
version: 9, |
| 62 |
supportedAccessFS: (1 << 17) - 1, |
| 63 |
supportedAccessNet: (1 << 2) - 1, |
| 64 |
supportedScoped: (1 << 2) - 1, |
| 65 |
supportedRestrictFlags: (1 << 4) - 1, |
| 66 |
}, |
| 67 |
} |
| 68 |
|
| 69 |
func (a abiInfo) asConfig() Config { |
| 70 |
return Config{ |
| 71 |
handledAccessFS: a.supportedAccessFS, |
| 72 |
handledAccessNet: a.supportedAccessNet, |
| 73 |
scoped: a.supportedScoped, |
| 74 |
flags: 0, |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
// getSupportedABIVersion returns the kernel-supported ABI version. |
| 79 |
// |
| 80 |
// If the ABI version supported by the kernel is higher than the |
| 81 |
// newest one known to go-landlock, the highest ABI version known to |
| 82 |
// go-landlock is returned. |
| 83 |
func getSupportedABIVersion() abiInfo { |
| 84 |
v := internal.DetectedABIVersion() |
| 85 |
if v >= len(abiInfos) { |
| 86 |
v = len(abiInfos) - 1 |
| 87 |
} |
| 88 |
return abiInfos[v] |
| 89 |
} |