diff options
author | David S. Miller <davem@davemloft.net> | 2009-12-05 18:22:26 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-12-05 18:22:26 -0500 |
commit | 28b4d5cc17c20786848cdc07b7ea237a309776bb (patch) | |
tree | bae406a4b17229dcce7c11be5073f7a67665e477 /scripts | |
parent | d29cecda036f251aee4947f47eea0fe9ed8cc931 (diff) | |
parent | 96fa2b508d2d3fe040cf4ef2fffb955f0a537ea1 (diff) |
Merge branch 'master' of /home/davem/src/GIT/linux-2.6/
Conflicts:
drivers/net/pcmcia/fmvj18x_cs.c
drivers/net/pcmcia/nmclan_cs.c
drivers/net/pcmcia/xirc2ps_cs.c
drivers/net/wireless/ray_cs.c
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/recordmcount.pl | 219 | ||||
-rw-r--r-- | scripts/selinux/Makefile | 4 | ||||
-rw-r--r-- | scripts/selinux/genheaders/.gitignore | 1 | ||||
-rw-r--r-- | scripts/selinux/genheaders/Makefile | 5 | ||||
-rw-r--r-- | scripts/selinux/genheaders/genheaders.c | 118 | ||||
-rw-r--r-- | scripts/selinux/mdp/mdp.c | 151 |
6 files changed, 274 insertions, 224 deletions
diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl index 090d300d7394..f0d14452632b 100755 --- a/scripts/recordmcount.pl +++ b/scripts/recordmcount.pl | |||
@@ -6,77 +6,93 @@ | |||
6 | # all the offsets to the calls to mcount. | 6 | # all the offsets to the calls to mcount. |
7 | # | 7 | # |
8 | # | 8 | # |
9 | # What we want to end up with is a section in vmlinux called | 9 | # What we want to end up with this is that each object file will have a |
10 | # __mcount_loc that contains a list of pointers to all the | 10 | # section called __mcount_loc that will hold the list of pointers to mcount |
11 | # call sites in the kernel that call mcount. Later on boot up, the kernel | 11 | # callers. After final linking, the vmlinux will have within .init.data the |
12 | # will read this list, save the locations and turn them into nops. | 12 | # list of all callers to mcount between __start_mcount_loc and __stop_mcount_loc. |
13 | # When tracing or profiling is later enabled, these locations will then | 13 | # Later on boot up, the kernel will read this list, save the locations and turn |
14 | # be converted back to pointers to some function. | 14 | # them into nops. When tracing or profiling is later enabled, these locations |
15 | # will then be converted back to pointers to some function. | ||
15 | # | 16 | # |
16 | # This is no easy feat. This script is called just after the original | 17 | # This is no easy feat. This script is called just after the original |
17 | # object is compiled and before it is linked. | 18 | # object is compiled and before it is linked. |
18 | # | 19 | # |
19 | # The references to the call sites are offsets from the section of text | 20 | # When parse this object file using 'objdump', the references to the call |
20 | # that the call site is in. Hence, all functions in a section that | 21 | # sites are offsets from the section that the call site is in. Hence, all |
21 | # has a call site to mcount, will have the offset from the beginning of | 22 | # functions in a section that has a call site to mcount, will have the |
22 | # the section and not the beginning of the function. | 23 | # offset from the beginning of the section and not the beginning of the |
24 | # function. | ||
25 | # | ||
26 | # But where this section will reside finally in vmlinx is undetermined at | ||
27 | # this point. So we can't use this kind of offsets to record the final | ||
28 | # address of this call site. | ||
29 | # | ||
30 | # The trick is to change the call offset referring the start of a section to | ||
31 | # referring a function symbol in this section. During the link step, 'ld' will | ||
32 | # compute the final address according to the information we record. | ||
23 | # | 33 | # |
24 | # The trick is to find a way to record the beginning of the section. | ||
25 | # The way we do this is to look at the first function in the section | ||
26 | # which will also be the location of that section after final link. | ||
27 | # e.g. | 34 | # e.g. |
28 | # | 35 | # |
29 | # .section ".sched.text", "ax" | 36 | # .section ".sched.text", "ax" |
30 | # .globl my_func | ||
31 | # my_func: | ||
32 | # [...] | 37 | # [...] |
33 | # call mcount (offset: 0x5) | 38 | # func1: |
39 | # [...] | ||
40 | # call mcount (offset: 0x10) | ||
34 | # [...] | 41 | # [...] |
35 | # ret | 42 | # ret |
36 | # other_func: | 43 | # .globl fun2 |
44 | # func2: (offset: 0x20) | ||
37 | # [...] | 45 | # [...] |
38 | # call mcount (offset: 0x1b) | 46 | # [...] |
47 | # ret | ||
48 | # func3: | ||
49 | # [...] | ||
50 | # call mcount (offset: 0x30) | ||
39 | # [...] | 51 | # [...] |
40 | # | 52 | # |
41 | # Both relocation offsets for the mcounts in the above example will be | 53 | # Both relocation offsets for the mcounts in the above example will be |
42 | # offset from .sched.text. If we make another file called tmp.s with: | 54 | # offset from .sched.text. If we choose global symbol func2 as a reference and |
55 | # make another file called tmp.s with the new offsets: | ||
43 | # | 56 | # |
44 | # .section __mcount_loc | 57 | # .section __mcount_loc |
45 | # .quad my_func + 0x5 | 58 | # .quad func2 - 0x10 |
46 | # .quad my_func + 0x1b | 59 | # .quad func2 + 0x10 |
47 | # | 60 | # |
48 | # We can then compile this tmp.s into tmp.o, and link it to the original | 61 | # We can then compile this tmp.s into tmp.o, and link it back to the original |
49 | # object. | 62 | # object. |
50 | # | 63 | # |
51 | # But this gets hard if my_func is not globl (a static function). | 64 | # In our algorithm, we will choose the first global function we meet in this |
52 | # In such a case we have: | 65 | # section as the reference. But this gets hard if there is no global functions |
66 | # in this section. In such a case we have to select a local one. E.g. func1: | ||
53 | # | 67 | # |
54 | # .section ".sched.text", "ax" | 68 | # .section ".sched.text", "ax" |
55 | # my_func: | 69 | # func1: |
56 | # [...] | 70 | # [...] |
57 | # call mcount (offset: 0x5) | 71 | # call mcount (offset: 0x10) |
58 | # [...] | 72 | # [...] |
59 | # ret | 73 | # ret |
60 | # other_func: | 74 | # func2: |
61 | # [...] | 75 | # [...] |
62 | # call mcount (offset: 0x1b) | 76 | # call mcount (offset: 0x20) |
63 | # [...] | 77 | # [...] |
78 | # .section "other.section" | ||
64 | # | 79 | # |
65 | # If we make the tmp.s the same as above, when we link together with | 80 | # If we make the tmp.s the same as above, when we link together with |
66 | # the original object, we will end up with two symbols for my_func: | 81 | # the original object, we will end up with two symbols for func1: |
67 | # one local, one global. After final compile, we will end up with | 82 | # one local, one global. After final compile, we will end up with |
68 | # an undefined reference to my_func. | 83 | # an undefined reference to func1 or a wrong reference to another global |
84 | # func1 in other files. | ||
69 | # | 85 | # |
70 | # Since local objects can reference local variables, we need to find | 86 | # Since local objects can reference local variables, we need to find |
71 | # a way to make tmp.o reference the local objects of the original object | 87 | # a way to make tmp.o reference the local objects of the original object |
72 | # file after it is linked together. To do this, we convert the my_func | 88 | # file after it is linked together. To do this, we convert func1 |
73 | # into a global symbol before linking tmp.o. Then after we link tmp.o | 89 | # into a global symbol before linking tmp.o. Then after we link tmp.o |
74 | # we will only have a single symbol for my_func that is global. | 90 | # we will only have a single symbol for func1 that is global. |
75 | # We can convert my_func back into a local symbol and we are done. | 91 | # We can convert func1 back into a local symbol and we are done. |
76 | # | 92 | # |
77 | # Here are the steps we take: | 93 | # Here are the steps we take: |
78 | # | 94 | # |
79 | # 1) Record all the local symbols by using 'nm' | 95 | # 1) Record all the local and weak symbols by using 'nm' |
80 | # 2) Use objdump to find all the call site offsets and sections for | 96 | # 2) Use objdump to find all the call site offsets and sections for |
81 | # mcount. | 97 | # mcount. |
82 | # 3) Compile the list into its own object. | 98 | # 3) Compile the list into its own object. |
@@ -86,10 +102,8 @@ | |||
86 | # 6) Link together this new object with the list object. | 102 | # 6) Link together this new object with the list object. |
87 | # 7) Convert the local functions back to local symbols and rename | 103 | # 7) Convert the local functions back to local symbols and rename |
88 | # the result as the original object. | 104 | # the result as the original object. |
89 | # End. | ||
90 | # 8) Link the object with the list object. | 105 | # 8) Link the object with the list object. |
91 | # 9) Move the result back to the original object. | 106 | # 9) Move the result back to the original object. |
92 | # End. | ||
93 | # | 107 | # |
94 | 108 | ||
95 | use strict; | 109 | use strict; |
@@ -99,7 +113,7 @@ $P =~ s@.*/@@g; | |||
99 | 113 | ||
100 | my $V = '0.1'; | 114 | my $V = '0.1'; |
101 | 115 | ||
102 | if ($#ARGV < 7) { | 116 | if ($#ARGV != 10) { |
103 | print "usage: $P arch bits objdump objcopy cc ld nm rm mv is_module inputfile\n"; | 117 | print "usage: $P arch bits objdump objcopy cc ld nm rm mv is_module inputfile\n"; |
104 | print "version: $V\n"; | 118 | print "version: $V\n"; |
105 | exit(1); | 119 | exit(1); |
@@ -109,7 +123,7 @@ my ($arch, $bits, $objdump, $objcopy, $cc, | |||
109 | $ld, $nm, $rm, $mv, $is_module, $inputfile) = @ARGV; | 123 | $ld, $nm, $rm, $mv, $is_module, $inputfile) = @ARGV; |
110 | 124 | ||
111 | # This file refers to mcount and shouldn't be ftraced, so lets' ignore it | 125 | # This file refers to mcount and shouldn't be ftraced, so lets' ignore it |
112 | if ($inputfile eq "kernel/trace/ftrace.o") { | 126 | if ($inputfile =~ m,kernel/trace/ftrace\.o$,) { |
113 | exit(0); | 127 | exit(0); |
114 | } | 128 | } |
115 | 129 | ||
@@ -119,6 +133,7 @@ my %text_sections = ( | |||
119 | ".sched.text" => 1, | 133 | ".sched.text" => 1, |
120 | ".spinlock.text" => 1, | 134 | ".spinlock.text" => 1, |
121 | ".irqentry.text" => 1, | 135 | ".irqentry.text" => 1, |
136 | ".text.unlikely" => 1, | ||
122 | ); | 137 | ); |
123 | 138 | ||
124 | $objdump = "objdump" if ((length $objdump) == 0); | 139 | $objdump = "objdump" if ((length $objdump) == 0); |
@@ -137,13 +152,47 @@ my %weak; # List of weak functions | |||
137 | my %convert; # List of local functions used that needs conversion | 152 | my %convert; # List of local functions used that needs conversion |
138 | 153 | ||
139 | my $type; | 154 | my $type; |
140 | my $nm_regex; # Find the local functions (return function) | 155 | my $local_regex; # Match a local function (return function) |
156 | my $weak_regex; # Match a weak function (return function) | ||
141 | my $section_regex; # Find the start of a section | 157 | my $section_regex; # Find the start of a section |
142 | my $function_regex; # Find the name of a function | 158 | my $function_regex; # Find the name of a function |
143 | # (return offset and func name) | 159 | # (return offset and func name) |
144 | my $mcount_regex; # Find the call site to mcount (return offset) | 160 | my $mcount_regex; # Find the call site to mcount (return offset) |
145 | my $alignment; # The .align value to use for $mcount_section | 161 | my $alignment; # The .align value to use for $mcount_section |
146 | my $section_type; # Section header plus possible alignment command | 162 | my $section_type; # Section header plus possible alignment command |
163 | my $can_use_local = 0; # If we can use local function references | ||
164 | |||
165 | # Shut up recordmcount if user has older objcopy | ||
166 | my $quiet_recordmcount = ".tmp_quiet_recordmcount"; | ||
167 | my $print_warning = 1; | ||
168 | $print_warning = 0 if ( -f $quiet_recordmcount); | ||
169 | |||
170 | ## | ||
171 | # check_objcopy - whether objcopy supports --globalize-symbols | ||
172 | # | ||
173 | # --globalize-symbols came out in 2.17, we must test the version | ||
174 | # of objcopy, and if it is less than 2.17, then we can not | ||
175 | # record local functions. | ||
176 | sub check_objcopy | ||
177 | { | ||
178 | open (IN, "$objcopy --version |") or die "error running $objcopy"; | ||
179 | while (<IN>) { | ||
180 | if (/objcopy.*\s(\d+)\.(\d+)/) { | ||
181 | $can_use_local = 1 if ($1 > 2 || ($1 == 2 && $2 >= 17)); | ||
182 | last; | ||
183 | } | ||
184 | } | ||
185 | close (IN); | ||
186 | |||
187 | if (!$can_use_local && $print_warning) { | ||
188 | print STDERR "WARNING: could not find objcopy version or version " . | ||
189 | "is less than 2.17.\n" . | ||
190 | "\tLocal function references are disabled.\n"; | ||
191 | open (QUIET, ">$quiet_recordmcount"); | ||
192 | printf QUIET "Disables the warning from recordmcount.pl\n"; | ||
193 | close QUIET; | ||
194 | } | ||
195 | } | ||
147 | 196 | ||
148 | if ($arch eq "x86") { | 197 | if ($arch eq "x86") { |
149 | if ($bits == 64) { | 198 | if ($bits == 64) { |
@@ -157,7 +206,8 @@ if ($arch eq "x86") { | |||
157 | # We base the defaults off of i386, the other archs may | 206 | # We base the defaults off of i386, the other archs may |
158 | # feel free to change them in the below if statements. | 207 | # feel free to change them in the below if statements. |
159 | # | 208 | # |
160 | $nm_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\S+)"; | 209 | $local_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\S+)"; |
210 | $weak_regex = "^[0-9a-fA-F]+\\s+([wW])\\s+(\\S+)"; | ||
161 | $section_regex = "Disassembly of section\\s+(\\S+):"; | 211 | $section_regex = "Disassembly of section\\s+(\\S+):"; |
162 | $function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:"; | 212 | $function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:"; |
163 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount\$"; | 213 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount\$"; |
@@ -206,7 +256,7 @@ if ($arch eq "x86_64") { | |||
206 | $cc .= " -m32"; | 256 | $cc .= " -m32"; |
207 | 257 | ||
208 | } elsif ($arch eq "powerpc") { | 258 | } elsif ($arch eq "powerpc") { |
209 | $nm_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\.?\\S+)"; | 259 | $local_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\.?\\S+)"; |
210 | $function_regex = "^([0-9a-fA-F]+)\\s+<(\\.?.*?)>:"; | 260 | $function_regex = "^([0-9a-fA-F]+)\\s+<(\\.?.*?)>:"; |
211 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s\\.?_mcount\$"; | 261 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s\\.?_mcount\$"; |
212 | 262 | ||
@@ -278,44 +328,17 @@ if ($filename =~ m,^(.*)(\.\S),) { | |||
278 | my $mcount_s = $dirname . "/.tmp_mc_" . $prefix . ".s"; | 328 | my $mcount_s = $dirname . "/.tmp_mc_" . $prefix . ".s"; |
279 | my $mcount_o = $dirname . "/.tmp_mc_" . $prefix . ".o"; | 329 | my $mcount_o = $dirname . "/.tmp_mc_" . $prefix . ".o"; |
280 | 330 | ||
281 | # | 331 | check_objcopy(); |
282 | # --globalize-symbols came out in 2.17, we must test the version | ||
283 | # of objcopy, and if it is less than 2.17, then we can not | ||
284 | # record local functions. | ||
285 | my $use_locals = 01; | ||
286 | my $local_warn_once = 0; | ||
287 | my $found_version = 0; | ||
288 | |||
289 | open (IN, "$objcopy --version |") || die "error running $objcopy"; | ||
290 | while (<IN>) { | ||
291 | if (/objcopy.*\s(\d+)\.(\d+)/) { | ||
292 | my $major = $1; | ||
293 | my $minor = $2; | ||
294 | |||
295 | $found_version = 1; | ||
296 | if ($major < 2 || | ||
297 | ($major == 2 && $minor < 17)) { | ||
298 | $use_locals = 0; | ||
299 | } | ||
300 | last; | ||
301 | } | ||
302 | } | ||
303 | close (IN); | ||
304 | |||
305 | if (!$found_version) { | ||
306 | print STDERR "WARNING: could not find objcopy version.\n" . | ||
307 | "\tDisabling local function references.\n"; | ||
308 | } | ||
309 | 332 | ||
310 | # | 333 | # |
311 | # Step 1: find all the local (static functions) and weak symbols. | 334 | # Step 1: find all the local (static functions) and weak symbols. |
312 | # 't' is local, 'w/W' is weak (we never use a weak function) | 335 | # 't' is local, 'w/W' is weak |
313 | # | 336 | # |
314 | open (IN, "$nm $inputfile|") || die "error running $nm"; | 337 | open (IN, "$nm $inputfile|") || die "error running $nm"; |
315 | while (<IN>) { | 338 | while (<IN>) { |
316 | if (/$nm_regex/) { | 339 | if (/$local_regex/) { |
317 | $locals{$1} = 1; | 340 | $locals{$1} = 1; |
318 | } elsif (/^[0-9a-fA-F]+\s+([wW])\s+(\S+)/) { | 341 | } elsif (/$weak_regex/) { |
319 | $weak{$2} = $1; | 342 | $weak{$2} = $1; |
320 | } | 343 | } |
321 | } | 344 | } |
@@ -333,26 +356,20 @@ my $offset = 0; # offset of ref_func to section beginning | |||
333 | # | 356 | # |
334 | sub update_funcs | 357 | sub update_funcs |
335 | { | 358 | { |
336 | return if ($#offsets < 0); | 359 | return unless ($ref_func and @offsets); |
337 | |||
338 | defined($ref_func) || die "No function to reference"; | ||
339 | 360 | ||
340 | # A section only had a weak function, to represent it. | 361 | # Sanity check on weak function. A weak function may be overwritten by |
341 | # Unfortunately, a weak function may be overwritten by another | 362 | # another function of the same name, making all these offsets incorrect. |
342 | # function of the same name, making all these offsets incorrect. | ||
343 | # To be safe, we simply print a warning and bail. | ||
344 | if (defined $weak{$ref_func}) { | 363 | if (defined $weak{$ref_func}) { |
345 | print STDERR | 364 | die "$inputfile: ERROR: referencing weak function" . |
346 | "$inputfile: WARNING: referencing weak function" . | ||
347 | " $ref_func for mcount\n"; | 365 | " $ref_func for mcount\n"; |
348 | return; | ||
349 | } | 366 | } |
350 | 367 | ||
351 | # is this function static? If so, note this fact. | 368 | # is this function static? If so, note this fact. |
352 | if (defined $locals{$ref_func}) { | 369 | if (defined $locals{$ref_func}) { |
353 | 370 | ||
354 | # only use locals if objcopy supports globalize-symbols | 371 | # only use locals if objcopy supports globalize-symbols |
355 | if (!$use_locals) { | 372 | if (!$can_use_local) { |
356 | return; | 373 | return; |
357 | } | 374 | } |
358 | $convert{$ref_func} = 1; | 375 | $convert{$ref_func} = 1; |
@@ -378,9 +395,27 @@ open(IN, "$objdump -hdr $inputfile|") || die "error running $objdump"; | |||
378 | 395 | ||
379 | my $text; | 396 | my $text; |
380 | 397 | ||
398 | |||
399 | # read headers first | ||
381 | my $read_headers = 1; | 400 | my $read_headers = 1; |
382 | 401 | ||
383 | while (<IN>) { | 402 | while (<IN>) { |
403 | |||
404 | if ($read_headers && /$mcount_section/) { | ||
405 | # | ||
406 | # Somehow the make process can execute this script on an | ||
407 | # object twice. If it does, we would duplicate the mcount | ||
408 | # section and it will cause the function tracer self test | ||
409 | # to fail. Check if the mcount section exists, and if it does, | ||
410 | # warn and exit. | ||
411 | # | ||
412 | print STDERR "ERROR: $mcount_section already in $inputfile\n" . | ||
413 | "\tThis may be an indication that your build is corrupted.\n" . | ||
414 | "\tDelete $inputfile and try again. If the same object file\n" . | ||
415 | "\tstill causes an issue, then disable CONFIG_DYNAMIC_FTRACE.\n"; | ||
416 | exit(-1); | ||
417 | } | ||
418 | |||
384 | # is it a section? | 419 | # is it a section? |
385 | if (/$section_regex/) { | 420 | if (/$section_regex/) { |
386 | $read_headers = 0; | 421 | $read_headers = 0; |
@@ -392,7 +427,7 @@ while (<IN>) { | |||
392 | $read_function = 0; | 427 | $read_function = 0; |
393 | } | 428 | } |
394 | # print out any recorded offsets | 429 | # print out any recorded offsets |
395 | update_funcs() if (defined($ref_func)); | 430 | update_funcs(); |
396 | 431 | ||
397 | # reset all markers and arrays | 432 | # reset all markers and arrays |
398 | $text_found = 0; | 433 | $text_found = 0; |
@@ -421,21 +456,7 @@ while (<IN>) { | |||
421 | $offset = hex $1; | 456 | $offset = hex $1; |
422 | } | 457 | } |
423 | } | 458 | } |
424 | } elsif ($read_headers && /$mcount_section/) { | ||
425 | # | ||
426 | # Somehow the make process can execute this script on an | ||
427 | # object twice. If it does, we would duplicate the mcount | ||
428 | # section and it will cause the function tracer self test | ||
429 | # to fail. Check if the mcount section exists, and if it does, | ||
430 | # warn and exit. | ||
431 | # | ||
432 | print STDERR "ERROR: $mcount_section already in $inputfile\n" . | ||
433 | "\tThis may be an indication that your build is corrupted.\n" . | ||
434 | "\tDelete $inputfile and try again. If the same object file\n" . | ||
435 | "\tstill causes an issue, then disable CONFIG_DYNAMIC_FTRACE.\n"; | ||
436 | exit(-1); | ||
437 | } | 459 | } |
438 | |||
439 | # is this a call site to mcount? If so, record it to print later | 460 | # is this a call site to mcount? If so, record it to print later |
440 | if ($text_found && /$mcount_regex/) { | 461 | if ($text_found && /$mcount_regex/) { |
441 | $offsets[$#offsets + 1] = hex $1; | 462 | $offsets[$#offsets + 1] = hex $1; |
@@ -443,7 +464,7 @@ while (<IN>) { | |||
443 | } | 464 | } |
444 | 465 | ||
445 | # dump out anymore offsets that may have been found | 466 | # dump out anymore offsets that may have been found |
446 | update_funcs() if (defined($ref_func)); | 467 | update_funcs(); |
447 | 468 | ||
448 | # If we did not find any mcount callers, we are done (do nothing). | 469 | # If we did not find any mcount callers, we are done (do nothing). |
449 | if (!$opened) { | 470 | if (!$opened) { |
diff --git a/scripts/selinux/Makefile b/scripts/selinux/Makefile index ca4b1ec01822..e8049da1831f 100644 --- a/scripts/selinux/Makefile +++ b/scripts/selinux/Makefile | |||
@@ -1,2 +1,2 @@ | |||
1 | subdir-y := mdp | 1 | subdir-y := mdp genheaders |
2 | subdir- += mdp | 2 | subdir- += mdp genheaders |
diff --git a/scripts/selinux/genheaders/.gitignore b/scripts/selinux/genheaders/.gitignore new file mode 100644 index 000000000000..4c0b646ff8d5 --- /dev/null +++ b/scripts/selinux/genheaders/.gitignore | |||
@@ -0,0 +1 @@ | |||
genheaders | |||
diff --git a/scripts/selinux/genheaders/Makefile b/scripts/selinux/genheaders/Makefile new file mode 100644 index 000000000000..417b165008ee --- /dev/null +++ b/scripts/selinux/genheaders/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | hostprogs-y := genheaders | ||
2 | HOST_EXTRACFLAGS += -Isecurity/selinux/include | ||
3 | |||
4 | always := $(hostprogs-y) | ||
5 | clean-files := $(hostprogs-y) | ||
diff --git a/scripts/selinux/genheaders/genheaders.c b/scripts/selinux/genheaders/genheaders.c new file mode 100644 index 000000000000..24626968055d --- /dev/null +++ b/scripts/selinux/genheaders/genheaders.c | |||
@@ -0,0 +1,118 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <unistd.h> | ||
4 | #include <string.h> | ||
5 | #include <errno.h> | ||
6 | #include <ctype.h> | ||
7 | |||
8 | struct security_class_mapping { | ||
9 | const char *name; | ||
10 | const char *perms[sizeof(unsigned) * 8 + 1]; | ||
11 | }; | ||
12 | |||
13 | #include "classmap.h" | ||
14 | #include "initial_sid_to_string.h" | ||
15 | |||
16 | #define max(x, y) (((int)(x) > (int)(y)) ? x : y) | ||
17 | |||
18 | const char *progname; | ||
19 | |||
20 | static void usage(void) | ||
21 | { | ||
22 | printf("usage: %s flask.h av_permissions.h\n", progname); | ||
23 | exit(1); | ||
24 | } | ||
25 | |||
26 | static char *stoupperx(const char *s) | ||
27 | { | ||
28 | char *s2 = strdup(s); | ||
29 | char *p; | ||
30 | |||
31 | if (!s2) { | ||
32 | fprintf(stderr, "%s: out of memory\n", progname); | ||
33 | exit(3); | ||
34 | } | ||
35 | |||
36 | for (p = s2; *p; p++) | ||
37 | *p = toupper(*p); | ||
38 | return s2; | ||
39 | } | ||
40 | |||
41 | int main(int argc, char *argv[]) | ||
42 | { | ||
43 | int i, j, k; | ||
44 | int isids_len; | ||
45 | FILE *fout; | ||
46 | |||
47 | progname = argv[0]; | ||
48 | |||
49 | if (argc < 3) | ||
50 | usage(); | ||
51 | |||
52 | fout = fopen(argv[1], "w"); | ||
53 | if (!fout) { | ||
54 | fprintf(stderr, "Could not open %s for writing: %s\n", | ||
55 | argv[1], strerror(errno)); | ||
56 | exit(2); | ||
57 | } | ||
58 | |||
59 | for (i = 0; secclass_map[i].name; i++) { | ||
60 | struct security_class_mapping *map = &secclass_map[i]; | ||
61 | map->name = stoupperx(map->name); | ||
62 | for (j = 0; map->perms[j]; j++) | ||
63 | map->perms[j] = stoupperx(map->perms[j]); | ||
64 | } | ||
65 | |||
66 | isids_len = sizeof(initial_sid_to_string) / sizeof (char *); | ||
67 | for (i = 1; i < isids_len; i++) | ||
68 | initial_sid_to_string[i] = stoupperx(initial_sid_to_string[i]); | ||
69 | |||
70 | fprintf(fout, "/* This file is automatically generated. Do not edit. */\n"); | ||
71 | fprintf(fout, "#ifndef _SELINUX_FLASK_H_\n#define _SELINUX_FLASK_H_\n\n"); | ||
72 | |||
73 | for (i = 0; secclass_map[i].name; i++) { | ||
74 | struct security_class_mapping *map = &secclass_map[i]; | ||
75 | fprintf(fout, "#define SECCLASS_%s", map->name); | ||
76 | for (j = 0; j < max(1, 40 - strlen(map->name)); j++) | ||
77 | fprintf(fout, " "); | ||
78 | fprintf(fout, "%2d\n", i+1); | ||
79 | } | ||
80 | |||
81 | fprintf(fout, "\n"); | ||
82 | |||
83 | for (i = 1; i < isids_len; i++) { | ||
84 | char *s = initial_sid_to_string[i]; | ||
85 | fprintf(fout, "#define SECINITSID_%s", s); | ||
86 | for (j = 0; j < max(1, 40 - strlen(s)); j++) | ||
87 | fprintf(fout, " "); | ||
88 | fprintf(fout, "%2d\n", i); | ||
89 | } | ||
90 | fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1); | ||
91 | fprintf(fout, "\n#endif\n"); | ||
92 | fclose(fout); | ||
93 | |||
94 | fout = fopen(argv[2], "w"); | ||
95 | if (!fout) { | ||
96 | fprintf(stderr, "Could not open %s for writing: %s\n", | ||
97 | argv[2], strerror(errno)); | ||
98 | exit(4); | ||
99 | } | ||
100 | |||
101 | fprintf(fout, "/* This file is automatically generated. Do not edit. */\n"); | ||
102 | fprintf(fout, "#ifndef _SELINUX_AV_PERMISSIONS_H_\n#define _SELINUX_AV_PERMISSIONS_H_\n\n"); | ||
103 | |||
104 | for (i = 0; secclass_map[i].name; i++) { | ||
105 | struct security_class_mapping *map = &secclass_map[i]; | ||
106 | for (j = 0; map->perms[j]; j++) { | ||
107 | fprintf(fout, "#define %s__%s", map->name, | ||
108 | map->perms[j]); | ||
109 | for (k = 0; k < max(1, 40 - strlen(map->name) - strlen(map->perms[j])); k++) | ||
110 | fprintf(fout, " "); | ||
111 | fprintf(fout, "0x%08xUL\n", (1<<j)); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | fprintf(fout, "\n#endif\n"); | ||
116 | fclose(fout); | ||
117 | exit(0); | ||
118 | } | ||
diff --git a/scripts/selinux/mdp/mdp.c b/scripts/selinux/mdp/mdp.c index b4ced8562587..62b34ce1f50d 100644 --- a/scripts/selinux/mdp/mdp.c +++ b/scripts/selinux/mdp/mdp.c | |||
@@ -29,86 +29,27 @@ | |||
29 | #include <unistd.h> | 29 | #include <unistd.h> |
30 | #include <string.h> | 30 | #include <string.h> |
31 | 31 | ||
32 | #include "flask.h" | ||
33 | |||
34 | static void usage(char *name) | 32 | static void usage(char *name) |
35 | { | 33 | { |
36 | printf("usage: %s [-m] policy_file context_file\n", name); | 34 | printf("usage: %s [-m] policy_file context_file\n", name); |
37 | exit(1); | 35 | exit(1); |
38 | } | 36 | } |
39 | 37 | ||
40 | static void find_common_name(char *cname, char *dest, int len) | 38 | /* Class/perm mapping support */ |
41 | { | 39 | struct security_class_mapping { |
42 | char *start, *end; | 40 | const char *name; |
43 | 41 | const char *perms[sizeof(unsigned) * 8 + 1]; | |
44 | start = strchr(cname, '_')+1; | ||
45 | end = strchr(start, '_'); | ||
46 | if (!start || !end || start-cname > len || end-start > len) { | ||
47 | printf("Error with commons defines\n"); | ||
48 | exit(1); | ||
49 | } | ||
50 | strncpy(dest, start, end-start); | ||
51 | dest[end-start] = '\0'; | ||
52 | } | ||
53 | |||
54 | #define S_(x) x, | ||
55 | static char *classlist[] = { | ||
56 | #include "class_to_string.h" | ||
57 | NULL | ||
58 | }; | 42 | }; |
59 | #undef S_ | ||
60 | 43 | ||
44 | #include "classmap.h" | ||
61 | #include "initial_sid_to_string.h" | 45 | #include "initial_sid_to_string.h" |
62 | 46 | ||
63 | #define TB_(x) char *x[] = { | ||
64 | #define TE_(x) NULL }; | ||
65 | #define S_(x) x, | ||
66 | #include "common_perm_to_string.h" | ||
67 | #undef TB_ | ||
68 | #undef TE_ | ||
69 | #undef S_ | ||
70 | |||
71 | struct common { | ||
72 | char *cname; | ||
73 | char **perms; | ||
74 | }; | ||
75 | struct common common[] = { | ||
76 | #define TB_(x) { #x, x }, | ||
77 | #define S_(x) | ||
78 | #define TE_(x) | ||
79 | #include "common_perm_to_string.h" | ||
80 | #undef TB_ | ||
81 | #undef TE_ | ||
82 | #undef S_ | ||
83 | }; | ||
84 | |||
85 | #define S_(x, y, z) {x, #y}, | ||
86 | struct av_inherit { | ||
87 | int class; | ||
88 | char *common; | ||
89 | }; | ||
90 | struct av_inherit av_inherit[] = { | ||
91 | #include "av_inherit.h" | ||
92 | }; | ||
93 | #undef S_ | ||
94 | |||
95 | #include "av_permissions.h" | ||
96 | #define S_(x, y, z) {x, y, z}, | ||
97 | struct av_perms { | ||
98 | int class; | ||
99 | int perm_i; | ||
100 | char *perm_s; | ||
101 | }; | ||
102 | struct av_perms av_perms[] = { | ||
103 | #include "av_perm_to_string.h" | ||
104 | }; | ||
105 | #undef S_ | ||
106 | |||
107 | int main(int argc, char *argv[]) | 47 | int main(int argc, char *argv[]) |
108 | { | 48 | { |
109 | int i, j, mls = 0; | 49 | int i, j, mls = 0; |
50 | int initial_sid_to_string_len; | ||
110 | char **arg, *polout, *ctxout; | 51 | char **arg, *polout, *ctxout; |
111 | int classlist_len, initial_sid_to_string_len; | 52 | |
112 | FILE *fout; | 53 | FILE *fout; |
113 | 54 | ||
114 | if (argc < 3) | 55 | if (argc < 3) |
@@ -127,64 +68,25 @@ int main(int argc, char *argv[]) | |||
127 | usage(argv[0]); | 68 | usage(argv[0]); |
128 | } | 69 | } |
129 | 70 | ||
130 | classlist_len = sizeof(classlist) / sizeof(char *); | ||
131 | /* print out the classes */ | 71 | /* print out the classes */ |
132 | for (i=1; i < classlist_len; i++) { | 72 | for (i = 0; secclass_map[i].name; i++) |
133 | if(classlist[i]) | 73 | fprintf(fout, "class %s\n", secclass_map[i].name); |
134 | fprintf(fout, "class %s\n", classlist[i]); | ||
135 | else | ||
136 | fprintf(fout, "class user%d\n", i); | ||
137 | } | ||
138 | fprintf(fout, "\n"); | 74 | fprintf(fout, "\n"); |
139 | 75 | ||
140 | initial_sid_to_string_len = sizeof(initial_sid_to_string) / sizeof (char *); | 76 | initial_sid_to_string_len = sizeof(initial_sid_to_string) / sizeof (char *); |
141 | /* print out the sids */ | 77 | /* print out the sids */ |
142 | for (i=1; i < initial_sid_to_string_len; i++) | 78 | for (i = 1; i < initial_sid_to_string_len; i++) |
143 | fprintf(fout, "sid %s\n", initial_sid_to_string[i]); | 79 | fprintf(fout, "sid %s\n", initial_sid_to_string[i]); |
144 | fprintf(fout, "\n"); | 80 | fprintf(fout, "\n"); |
145 | 81 | ||
146 | /* print out the commons */ | ||
147 | for (i=0; i< sizeof(common)/sizeof(struct common); i++) { | ||
148 | char cname[101]; | ||
149 | find_common_name(common[i].cname, cname, 100); | ||
150 | cname[100] = '\0'; | ||
151 | fprintf(fout, "common %s\n{\n", cname); | ||
152 | for (j=0; common[i].perms[j]; j++) | ||
153 | fprintf(fout, "\t%s\n", common[i].perms[j]); | ||
154 | fprintf(fout, "}\n\n"); | ||
155 | } | ||
156 | fprintf(fout, "\n"); | ||
157 | |||
158 | /* print out the class permissions */ | 82 | /* print out the class permissions */ |
159 | for (i=1; i < classlist_len; i++) { | 83 | for (i = 0; secclass_map[i].name; i++) { |
160 | if (classlist[i]) { | 84 | struct security_class_mapping *map = &secclass_map[i]; |
161 | int firstperm = -1, numperms = 0; | 85 | fprintf(fout, "class %s\n", map->name); |
162 | 86 | fprintf(fout, "{\n"); | |
163 | fprintf(fout, "class %s\n", classlist[i]); | 87 | for (j = 0; map->perms[j]; j++) |
164 | /* does it inherit from a common? */ | 88 | fprintf(fout, "\t%s\n", map->perms[j]); |
165 | for (j=0; j < sizeof(av_inherit)/sizeof(struct av_inherit); j++) | 89 | fprintf(fout, "}\n\n"); |
166 | if (av_inherit[j].class == i) | ||
167 | fprintf(fout, "inherits %s\n", av_inherit[j].common); | ||
168 | |||
169 | for (j=0; j < sizeof(av_perms)/sizeof(struct av_perms); j++) { | ||
170 | if (av_perms[j].class == i) { | ||
171 | if (firstperm == -1) | ||
172 | firstperm = j; | ||
173 | numperms++; | ||
174 | } | ||
175 | } | ||
176 | if (!numperms) { | ||
177 | fprintf(fout, "\n"); | ||
178 | continue; | ||
179 | } | ||
180 | |||
181 | fprintf(fout, "{\n"); | ||
182 | /* print out the av_perms */ | ||
183 | for (j=0; j < numperms; j++) { | ||
184 | fprintf(fout, "\t%s\n", av_perms[firstperm+j].perm_s); | ||
185 | } | ||
186 | fprintf(fout, "}\n\n"); | ||
187 | } | ||
188 | } | 90 | } |
189 | fprintf(fout, "\n"); | 91 | fprintf(fout, "\n"); |
190 | 92 | ||
@@ -197,31 +99,34 @@ int main(int argc, char *argv[]) | |||
197 | /* types, roles, and allows */ | 99 | /* types, roles, and allows */ |
198 | fprintf(fout, "type base_t;\n"); | 100 | fprintf(fout, "type base_t;\n"); |
199 | fprintf(fout, "role base_r types { base_t };\n"); | 101 | fprintf(fout, "role base_r types { base_t };\n"); |
200 | for (i=1; i < classlist_len; i++) { | 102 | for (i = 0; secclass_map[i].name; i++) |
201 | if (classlist[i]) | 103 | fprintf(fout, "allow base_t base_t:%s *;\n", |
202 | fprintf(fout, "allow base_t base_t:%s *;\n", classlist[i]); | 104 | secclass_map[i].name); |
203 | else | ||
204 | fprintf(fout, "allow base_t base_t:user%d *;\n", i); | ||
205 | } | ||
206 | fprintf(fout, "user user_u roles { base_r };\n"); | 105 | fprintf(fout, "user user_u roles { base_r };\n"); |
207 | fprintf(fout, "\n"); | 106 | fprintf(fout, "\n"); |
208 | 107 | ||
209 | /* default sids */ | 108 | /* default sids */ |
210 | for (i=1; i < initial_sid_to_string_len; i++) | 109 | for (i = 1; i < initial_sid_to_string_len; i++) |
211 | fprintf(fout, "sid %s user_u:base_r:base_t\n", initial_sid_to_string[i]); | 110 | fprintf(fout, "sid %s user_u:base_r:base_t\n", initial_sid_to_string[i]); |
212 | fprintf(fout, "\n"); | 111 | fprintf(fout, "\n"); |
213 | 112 | ||
214 | |||
215 | fprintf(fout, "fs_use_xattr ext2 user_u:base_r:base_t;\n"); | 113 | fprintf(fout, "fs_use_xattr ext2 user_u:base_r:base_t;\n"); |
216 | fprintf(fout, "fs_use_xattr ext3 user_u:base_r:base_t;\n"); | 114 | fprintf(fout, "fs_use_xattr ext3 user_u:base_r:base_t;\n"); |
115 | fprintf(fout, "fs_use_xattr ext4 user_u:base_r:base_t;\n"); | ||
217 | fprintf(fout, "fs_use_xattr jfs user_u:base_r:base_t;\n"); | 116 | fprintf(fout, "fs_use_xattr jfs user_u:base_r:base_t;\n"); |
218 | fprintf(fout, "fs_use_xattr xfs user_u:base_r:base_t;\n"); | 117 | fprintf(fout, "fs_use_xattr xfs user_u:base_r:base_t;\n"); |
219 | fprintf(fout, "fs_use_xattr reiserfs user_u:base_r:base_t;\n"); | 118 | fprintf(fout, "fs_use_xattr reiserfs user_u:base_r:base_t;\n"); |
119 | fprintf(fout, "fs_use_xattr jffs2 user_u:base_r:base_t;\n"); | ||
120 | fprintf(fout, "fs_use_xattr gfs2 user_u:base_r:base_t;\n"); | ||
121 | fprintf(fout, "fs_use_xattr lustre user_u:base_r:base_t;\n"); | ||
220 | 122 | ||
123 | fprintf(fout, "fs_use_task eventpollfs user_u:base_r:base_t;\n"); | ||
221 | fprintf(fout, "fs_use_task pipefs user_u:base_r:base_t;\n"); | 124 | fprintf(fout, "fs_use_task pipefs user_u:base_r:base_t;\n"); |
222 | fprintf(fout, "fs_use_task sockfs user_u:base_r:base_t;\n"); | 125 | fprintf(fout, "fs_use_task sockfs user_u:base_r:base_t;\n"); |
223 | 126 | ||
127 | fprintf(fout, "fs_use_trans mqueue user_u:base_r:base_t;\n"); | ||
224 | fprintf(fout, "fs_use_trans devpts user_u:base_r:base_t;\n"); | 128 | fprintf(fout, "fs_use_trans devpts user_u:base_r:base_t;\n"); |
129 | fprintf(fout, "fs_use_trans hugetlbfs user_u:base_r:base_t;\n"); | ||
225 | fprintf(fout, "fs_use_trans tmpfs user_u:base_r:base_t;\n"); | 130 | fprintf(fout, "fs_use_trans tmpfs user_u:base_r:base_t;\n"); |
226 | fprintf(fout, "fs_use_trans shm user_u:base_r:base_t;\n"); | 131 | fprintf(fout, "fs_use_trans shm user_u:base_r:base_t;\n"); |
227 | 132 | ||