| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Linux::Landlock::Syscalls; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
14
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
109
|
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
160
|
|
|
5
|
2
|
|
|
2
|
|
13
|
use Config; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
94
|
|
|
6
|
2
|
|
|
2
|
|
11
|
use Exporter 'import'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
156
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw(NR Q_pack); |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my %SYSCALLS; |
|
10
|
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
12
|
my $supports_Q = eval { no warnings 'void'; pack('Q', 1); 1 }; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
1156
|
|
|
12
|
|
|
|
|
|
|
# endianness test from https://perldoc.perl.org/perlpacktut#Pack-Recipes |
|
13
|
|
|
|
|
|
|
my $is_le = unpack('c', pack('s', 1)); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# emulate pack('Q', ...) on Perl without 64-bit integer support |
|
16
|
|
|
|
|
|
|
#@type $arg Math::BigInt |
|
17
|
|
|
|
|
|
|
sub Q_pack { |
|
18
|
2
|
|
|
2
|
0
|
22
|
my ($arg) = @_; |
|
19
|
|
|
|
|
|
|
|
|
20
|
2
|
50
|
|
|
|
19
|
if ($supports_Q) { |
|
21
|
2
|
|
|
|
|
8
|
return pack('Q', $arg); |
|
22
|
|
|
|
|
|
|
} else { |
|
23
|
0
|
|
|
|
|
0
|
my $high = $arg >> 32; |
|
24
|
0
|
|
|
|
|
0
|
my $low = $arg & 0xFFFFFFFF; |
|
25
|
0
|
0
|
|
|
|
0
|
if ($is_le) { |
|
26
|
0
|
|
|
|
|
0
|
return pack('VV', $low, $high); |
|
27
|
|
|
|
|
|
|
} else { |
|
28
|
0
|
|
|
|
|
0
|
return pack('NN', $high, $low); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub NR { |
|
34
|
5
|
|
|
5
|
0
|
13
|
my ($name) = @_; |
|
35
|
|
|
|
|
|
|
|
|
36
|
5
|
100
|
66
|
|
|
26
|
if (!%SYSCALLS && $^O eq 'linux') { |
|
37
|
2
|
|
|
|
|
9
|
my $re_arm = qr/arm/x; |
|
38
|
2
|
|
|
|
|
8
|
my $re_aarch64 = qr/aarch64/x; |
|
39
|
2
|
|
|
|
|
7
|
my $re_x86 = qr/i686/x; |
|
40
|
2
|
|
|
|
|
6
|
my $re_x86_64 = qr/x86_64/x; |
|
41
|
|
|
|
|
|
|
# hardcoded syscall numbers for common architectures |
|
42
|
2
|
50
|
0
|
|
|
136
|
if (my ($arch) = $Config{archname} =~ /($re_x86_64|$re_x86|$re_arm|$re_aarch64)/x) { |
|
|
|
0
|
0
|
|
|
|
|
|
43
|
2
|
|
|
|
|
15
|
my %prctl = ( |
|
44
|
|
|
|
|
|
|
aarch64 => 167, |
|
45
|
|
|
|
|
|
|
arm => 172, |
|
46
|
|
|
|
|
|
|
i686 => 172, |
|
47
|
|
|
|
|
|
|
x86_64 => 157, |
|
48
|
|
|
|
|
|
|
); |
|
49
|
|
|
|
|
|
|
%SYSCALLS = ( |
|
50
|
|
|
|
|
|
|
landlock_create_ruleset => 444, |
|
51
|
|
|
|
|
|
|
landlock_add_rule => 445, |
|
52
|
|
|
|
|
|
|
landlock_restrict_self => 446, |
|
53
|
2
|
|
|
|
|
36
|
prctl => $prctl{$arch}, |
|
54
|
|
|
|
|
|
|
); |
|
55
|
|
|
|
|
|
|
} elsif ($^O eq 'linux' && (eval { require 'syscall.ph'; } || eval { require 'sys/syscall.ph'; })) { |
|
56
|
0
|
|
|
|
|
0
|
%SYSCALLS = ( |
|
57
|
|
|
|
|
|
|
landlock_create_ruleset => &SYS_landlock_create_ruleset, |
|
58
|
|
|
|
|
|
|
landlock_add_rule => &SYS_landlock_add_rule, |
|
59
|
|
|
|
|
|
|
landlock_restrict_self => &SYS_landlock_restrict_self, |
|
60
|
|
|
|
|
|
|
prctl => &SYS_prctl, |
|
61
|
|
|
|
|
|
|
); |
|
62
|
|
|
|
|
|
|
} else { |
|
63
|
0
|
|
|
|
|
0
|
warn "Could not determine syscall numbers, disabling Landlock support. You might need to run 'h2ph'\n"; |
|
64
|
0
|
|
|
|
|
0
|
return; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} |
|
67
|
5
|
|
|
|
|
25
|
return $SYSCALLS{$name}; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |