]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.16.2-201409060014.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.16.2-201409060014.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 9de9813..1462492 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -3,9 +3,11 @@
6 *.bc
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -15,6 +17,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -51,14 +54,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -72,9 +78,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 +TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56 @@ -83,6 +91,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60 +ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64 @@ -95,32 +104,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68 +builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74 +clut_vga16.c
75 +common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82 +config.c
83 config.mak
84 config.mak.autogen
85 +config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92 +devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97 +dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101 +exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105 @@ -128,12 +145,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109 +gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116 +hash
117 +hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121 @@ -148,14 +168,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125 -kconfig
126 +kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133 -linux
134 +lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138 @@ -165,14 +185,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142 -media
143 mconf
144 +mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151 +mkpiggy
152 mkprep
153 mkregtable
154 mktables
155 @@ -188,6 +209,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159 +parse-events*
160 +pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164 @@ -197,6 +220,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168 +pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172 @@ -206,7 +230,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176 +randomize_layout_hash.h
177 +randomize_layout_seed.h
178 +realmode.lds
179 +realmode.relocs
180 recordmcount
181 +regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185 @@ -216,8 +245,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189 +signing_key*
190 +size_overflow_hash.h
191 sImage
192 +slabinfo
193 sm_tbl*
194 +sortextable
195 split-include
196 syscalltab.h
197 tables.c
198 @@ -227,6 +260,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202 +user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206 @@ -238,13 +272,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210 +vdsox32.lds
211 +vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218 +vmlinux.bin.bz2
219 vmlinux.lds
220 +vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224 @@ -252,9 +290,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228 +utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232 +x509*
233 zImage*
234 zconf.hash.c
235 +zconf.lex.c
236 zoffset.h
237 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
238 index b7fa2f5..90cd9f8 100644
239 --- a/Documentation/kernel-parameters.txt
240 +++ b/Documentation/kernel-parameters.txt
241 @@ -1138,6 +1138,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
242 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
243 Default: 1024
244
245 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
246 + ignore grsecurity's /proc restrictions
247 +
248 +
249 hashdist= [KNL,NUMA] Large hashes allocated during boot
250 are distributed across NUMA nodes. Defaults on
251 for 64-bit NUMA, off otherwise.
252 @@ -2141,6 +2145,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
253 noexec=on: enable non-executable mappings (default)
254 noexec=off: disable non-executable mappings
255
256 + nopcid [X86-64]
257 + Disable PCID (Process-Context IDentifier) even if it
258 + is supported by the processor.
259 +
260 nosmap [X86]
261 Disable SMAP (Supervisor Mode Access Prevention)
262 even if it is supported by processor.
263 @@ -2418,6 +2426,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
264 the specified number of seconds. This is to be used if
265 your oopses keep scrolling off the screen.
266
267 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
268 + virtualization environments that don't cope well with the
269 + expand down segment used by UDEREF on X86-32 or the frequent
270 + page table updates on X86-64.
271 +
272 + pax_sanitize_slab=
273 + 0/1 to disable/enable slab object sanitization (enabled by
274 + default).
275 +
276 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
277 +
278 + pax_extra_latent_entropy
279 + Enable a very simple form of latent entropy extraction
280 + from the first 4GB of memory as the bootmem allocator
281 + passes the memory pages to the buddy allocator.
282 +
283 + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
284 + when the processor supports PCID.
285 +
286 pcbit= [HW,ISDN]
287
288 pcd. [PARIDE]
289 diff --git a/Documentation/networking/filter.txt b/Documentation/networking/filter.txt
290 index ee78eba..a06b48d 100644
291 --- a/Documentation/networking/filter.txt
292 +++ b/Documentation/networking/filter.txt
293 @@ -277,11 +277,10 @@ Possible BPF extensions are shown in the following table:
294 mark skb->mark
295 queue skb->queue_mapping
296 hatype skb->dev->type
297 - rxhash skb->hash
298 + rxhash skb->rxhash
299 cpu raw_smp_processor_id()
300 vlan_tci vlan_tx_tag_get(skb)
301 vlan_pr vlan_tx_tag_present(skb)
302 - rand prandom_u32()
303
304 These extensions can also be prefixed with '#'.
305 Examples for low-level BPF:
306 @@ -309,18 +308,6 @@ Examples for low-level BPF:
307 ret #-1
308 drop: ret #0
309
310 -** icmp random packet sampling, 1 in 4
311 - ldh [12]
312 - jne #0x800, drop
313 - ldb [23]
314 - jneq #1, drop
315 - # get a random uint32 number
316 - ld rand
317 - mod #4
318 - jneq #1, drop
319 - ret #-1
320 - drop: ret #0
321 -
322 ** SECCOMP filter example:
323
324 ld [4] /* offsetof(struct seccomp_data, arch) */
325 @@ -559,456 +546,6 @@ ffffffffa0069c8f + <x>:
326 For BPF JIT developers, bpf_jit_disasm, bpf_asm and bpf_dbg provides a useful
327 toolchain for developing and testing the kernel's JIT compiler.
328
329 -BPF kernel internals
330 ---------------------
331 -Internally, for the kernel interpreter, a different instruction set
332 -format with similar underlying principles from BPF described in previous
333 -paragraphs is being used. However, the instruction set format is modelled
334 -closer to the underlying architecture to mimic native instruction sets, so
335 -that a better performance can be achieved (more details later). This new
336 -ISA is called 'eBPF' or 'internal BPF' interchangeably. (Note: eBPF which
337 -originates from [e]xtended BPF is not the same as BPF extensions! While
338 -eBPF is an ISA, BPF extensions date back to classic BPF's 'overloading'
339 -of BPF_LD | BPF_{B,H,W} | BPF_ABS instruction.)
340 -
341 -It is designed to be JITed with one to one mapping, which can also open up
342 -the possibility for GCC/LLVM compilers to generate optimized eBPF code through
343 -an eBPF backend that performs almost as fast as natively compiled code.
344 -
345 -The new instruction set was originally designed with the possible goal in
346 -mind to write programs in "restricted C" and compile into eBPF with a optional
347 -GCC/LLVM backend, so that it can just-in-time map to modern 64-bit CPUs with
348 -minimal performance overhead over two steps, that is, C -> eBPF -> native code.
349 -
350 -Currently, the new format is being used for running user BPF programs, which
351 -includes seccomp BPF, classic socket filters, cls_bpf traffic classifier,
352 -team driver's classifier for its load-balancing mode, netfilter's xt_bpf
353 -extension, PTP dissector/classifier, and much more. They are all internally
354 -converted by the kernel into the new instruction set representation and run
355 -in the eBPF interpreter. For in-kernel handlers, this all works transparently
356 -by using sk_unattached_filter_create() for setting up the filter, resp.
357 -sk_unattached_filter_destroy() for destroying it. The macro
358 -SK_RUN_FILTER(filter, ctx) transparently invokes eBPF interpreter or JITed
359 -code to run the filter. 'filter' is a pointer to struct sk_filter that we
360 -got from sk_unattached_filter_create(), and 'ctx' the given context (e.g.
361 -skb pointer). All constraints and restrictions from sk_chk_filter() apply
362 -before a conversion to the new layout is being done behind the scenes!
363 -
364 -Currently, the classic BPF format is being used for JITing on most of the
365 -architectures. Only x86-64 performs JIT compilation from eBPF instruction set,
366 -however, future work will migrate other JIT compilers as well, so that they
367 -will profit from the very same benefits.
368 -
369 -Some core changes of the new internal format:
370 -
371 -- Number of registers increase from 2 to 10:
372 -
373 - The old format had two registers A and X, and a hidden frame pointer. The
374 - new layout extends this to be 10 internal registers and a read-only frame
375 - pointer. Since 64-bit CPUs are passing arguments to functions via registers
376 - the number of args from eBPF program to in-kernel function is restricted
377 - to 5 and one register is used to accept return value from an in-kernel
378 - function. Natively, x86_64 passes first 6 arguments in registers, aarch64/
379 - sparcv9/mips64 have 7 - 8 registers for arguments; x86_64 has 6 callee saved
380 - registers, and aarch64/sparcv9/mips64 have 11 or more callee saved registers.
381 -
382 - Therefore, eBPF calling convention is defined as:
383 -
384 - * R0 - return value from in-kernel function, and exit value for eBPF program
385 - * R1 - R5 - arguments from eBPF program to in-kernel function
386 - * R6 - R9 - callee saved registers that in-kernel function will preserve
387 - * R10 - read-only frame pointer to access stack
388 -
389 - Thus, all eBPF registers map one to one to HW registers on x86_64, aarch64,
390 - etc, and eBPF calling convention maps directly to ABIs used by the kernel on
391 - 64-bit architectures.
392 -
393 - On 32-bit architectures JIT may map programs that use only 32-bit arithmetic
394 - and may let more complex programs to be interpreted.
395 -
396 - R0 - R5 are scratch registers and eBPF program needs spill/fill them if
397 - necessary across calls. Note that there is only one eBPF program (== one
398 - eBPF main routine) and it cannot call other eBPF functions, it can only
399 - call predefined in-kernel functions, though.
400 -
401 -- Register width increases from 32-bit to 64-bit:
402 -
403 - Still, the semantics of the original 32-bit ALU operations are preserved
404 - via 32-bit subregisters. All eBPF registers are 64-bit with 32-bit lower
405 - subregisters that zero-extend into 64-bit if they are being written to.
406 - That behavior maps directly to x86_64 and arm64 subregister definition, but
407 - makes other JITs more difficult.
408 -
409 - 32-bit architectures run 64-bit internal BPF programs via interpreter.
410 - Their JITs may convert BPF programs that only use 32-bit subregisters into
411 - native instruction set and let the rest being interpreted.
412 -
413 - Operation is 64-bit, because on 64-bit architectures, pointers are also
414 - 64-bit wide, and we want to pass 64-bit values in/out of kernel functions,
415 - so 32-bit eBPF registers would otherwise require to define register-pair
416 - ABI, thus, there won't be able to use a direct eBPF register to HW register
417 - mapping and JIT would need to do combine/split/move operations for every
418 - register in and out of the function, which is complex, bug prone and slow.
419 - Another reason is the use of atomic 64-bit counters.
420 -
421 -- Conditional jt/jf targets replaced with jt/fall-through:
422 -
423 - While the original design has constructs such as "if (cond) jump_true;
424 - else jump_false;", they are being replaced into alternative constructs like
425 - "if (cond) jump_true; /* else fall-through */".
426 -
427 -- Introduces bpf_call insn and register passing convention for zero overhead
428 - calls from/to other kernel functions:
429 -
430 - Before an in-kernel function call, the internal BPF program needs to
431 - place function arguments into R1 to R5 registers to satisfy calling
432 - convention, then the interpreter will take them from registers and pass
433 - to in-kernel function. If R1 - R5 registers are mapped to CPU registers
434 - that are used for argument passing on given architecture, the JIT compiler
435 - doesn't need to emit extra moves. Function arguments will be in the correct
436 - registers and BPF_CALL instruction will be JITed as single 'call' HW
437 - instruction. This calling convention was picked to cover common call
438 - situations without performance penalty.
439 -
440 - After an in-kernel function call, R1 - R5 are reset to unreadable and R0 has
441 - a return value of the function. Since R6 - R9 are callee saved, their state
442 - is preserved across the call.
443 -
444 - For example, consider three C functions:
445 -
446 - u64 f1() { return (*_f2)(1); }
447 - u64 f2(u64 a) { return f3(a + 1, a); }
448 - u64 f3(u64 a, u64 b) { return a - b; }
449 -
450 - GCC can compile f1, f3 into x86_64:
451 -
452 - f1:
453 - movl $1, %edi
454 - movq _f2(%rip), %rax
455 - jmp *%rax
456 - f3:
457 - movq %rdi, %rax
458 - subq %rsi, %rax
459 - ret
460 -
461 - Function f2 in eBPF may look like:
462 -
463 - f2:
464 - bpf_mov R2, R1
465 - bpf_add R1, 1
466 - bpf_call f3
467 - bpf_exit
468 -
469 - If f2 is JITed and the pointer stored to '_f2'. The calls f1 -> f2 -> f3 and
470 - returns will be seamless. Without JIT, __sk_run_filter() interpreter needs to
471 - be used to call into f2.
472 -
473 - For practical reasons all eBPF programs have only one argument 'ctx' which is
474 - already placed into R1 (e.g. on __sk_run_filter() startup) and the programs
475 - can call kernel functions with up to 5 arguments. Calls with 6 or more arguments
476 - are currently not supported, but these restrictions can be lifted if necessary
477 - in the future.
478 -
479 - On 64-bit architectures all register map to HW registers one to one. For
480 - example, x86_64 JIT compiler can map them as ...
481 -
482 - R0 - rax
483 - R1 - rdi
484 - R2 - rsi
485 - R3 - rdx
486 - R4 - rcx
487 - R5 - r8
488 - R6 - rbx
489 - R7 - r13
490 - R8 - r14
491 - R9 - r15
492 - R10 - rbp
493 -
494 - ... since x86_64 ABI mandates rdi, rsi, rdx, rcx, r8, r9 for argument passing
495 - and rbx, r12 - r15 are callee saved.
496 -
497 - Then the following internal BPF pseudo-program:
498 -
499 - bpf_mov R6, R1 /* save ctx */
500 - bpf_mov R2, 2
501 - bpf_mov R3, 3
502 - bpf_mov R4, 4
503 - bpf_mov R5, 5
504 - bpf_call foo
505 - bpf_mov R7, R0 /* save foo() return value */
506 - bpf_mov R1, R6 /* restore ctx for next call */
507 - bpf_mov R2, 6
508 - bpf_mov R3, 7
509 - bpf_mov R4, 8
510 - bpf_mov R5, 9
511 - bpf_call bar
512 - bpf_add R0, R7
513 - bpf_exit
514 -
515 - After JIT to x86_64 may look like:
516 -
517 - push %rbp
518 - mov %rsp,%rbp
519 - sub $0x228,%rsp
520 - mov %rbx,-0x228(%rbp)
521 - mov %r13,-0x220(%rbp)
522 - mov %rdi,%rbx
523 - mov $0x2,%esi
524 - mov $0x3,%edx
525 - mov $0x4,%ecx
526 - mov $0x5,%r8d
527 - callq foo
528 - mov %rax,%r13
529 - mov %rbx,%rdi
530 - mov $0x2,%esi
531 - mov $0x3,%edx
532 - mov $0x4,%ecx
533 - mov $0x5,%r8d
534 - callq bar
535 - add %r13,%rax
536 - mov -0x228(%rbp),%rbx
537 - mov -0x220(%rbp),%r13
538 - leaveq
539 - retq
540 -
541 - Which is in this example equivalent in C to:
542 -
543 - u64 bpf_filter(u64 ctx)
544 - {
545 - return foo(ctx, 2, 3, 4, 5) + bar(ctx, 6, 7, 8, 9);
546 - }
547 -
548 - In-kernel functions foo() and bar() with prototype: u64 (*)(u64 arg1, u64
549 - arg2, u64 arg3, u64 arg4, u64 arg5); will receive arguments in proper
550 - registers and place their return value into '%rax' which is R0 in eBPF.
551 - Prologue and epilogue are emitted by JIT and are implicit in the
552 - interpreter. R0-R5 are scratch registers, so eBPF program needs to preserve
553 - them across the calls as defined by calling convention.
554 -
555 - For example the following program is invalid:
556 -
557 - bpf_mov R1, 1
558 - bpf_call foo
559 - bpf_mov R0, R1
560 - bpf_exit
561 -
562 - After the call the registers R1-R5 contain junk values and cannot be read.
563 - In the future an eBPF verifier can be used to validate internal BPF programs.
564 -
565 -Also in the new design, eBPF is limited to 4096 insns, which means that any
566 -program will terminate quickly and will only call a fixed number of kernel
567 -functions. Original BPF and the new format are two operand instructions,
568 -which helps to do one-to-one mapping between eBPF insn and x86 insn during JIT.
569 -
570 -The input context pointer for invoking the interpreter function is generic,
571 -its content is defined by a specific use case. For seccomp register R1 points
572 -to seccomp_data, for converted BPF filters R1 points to a skb.
573 -
574 -A program, that is translated internally consists of the following elements:
575 -
576 - op:16, jt:8, jf:8, k:32 ==> op:8, dst_reg:4, src_reg:4, off:16, imm:32
577 -
578 -So far 87 internal BPF instructions were implemented. 8-bit 'op' opcode field
579 -has room for new instructions. Some of them may use 16/24/32 byte encoding. New
580 -instructions must be multiple of 8 bytes to preserve backward compatibility.
581 -
582 -Internal BPF is a general purpose RISC instruction set. Not every register and
583 -every instruction are used during translation from original BPF to new format.
584 -For example, socket filters are not using 'exclusive add' instruction, but
585 -tracing filters may do to maintain counters of events, for example. Register R9
586 -is not used by socket filters either, but more complex filters may be running
587 -out of registers and would have to resort to spill/fill to stack.
588 -
589 -Internal BPF can used as generic assembler for last step performance
590 -optimizations, socket filters and seccomp are using it as assembler. Tracing
591 -filters may use it as assembler to generate code from kernel. In kernel usage
592 -may not be bounded by security considerations, since generated internal BPF code
593 -may be optimizing internal code path and not being exposed to the user space.
594 -Safety of internal BPF can come from a verifier (TBD). In such use cases as
595 -described, it may be used as safe instruction set.
596 -
597 -Just like the original BPF, the new format runs within a controlled environment,
598 -is deterministic and the kernel can easily prove that. The safety of the program
599 -can be determined in two steps: first step does depth-first-search to disallow
600 -loops and other CFG validation; second step starts from the first insn and
601 -descends all possible paths. It simulates execution of every insn and observes
602 -the state change of registers and stack.
603 -
604 -eBPF opcode encoding
605 ---------------------
606 -
607 -eBPF is reusing most of the opcode encoding from classic to simplify conversion
608 -of classic BPF to eBPF. For arithmetic and jump instructions the 8-bit 'code'
609 -field is divided into three parts:
610 -
611 - +----------------+--------+--------------------+
612 - | 4 bits | 1 bit | 3 bits |
613 - | operation code | source | instruction class |
614 - +----------------+--------+--------------------+
615 - (MSB) (LSB)
616 -
617 -Three LSB bits store instruction class which is one of:
618 -
619 - Classic BPF classes: eBPF classes:
620 -
621 - BPF_LD 0x00 BPF_LD 0x00
622 - BPF_LDX 0x01 BPF_LDX 0x01
623 - BPF_ST 0x02 BPF_ST 0x02
624 - BPF_STX 0x03 BPF_STX 0x03
625 - BPF_ALU 0x04 BPF_ALU 0x04
626 - BPF_JMP 0x05 BPF_JMP 0x05
627 - BPF_RET 0x06 [ class 6 unused, for future if needed ]
628 - BPF_MISC 0x07 BPF_ALU64 0x07
629 -
630 -When BPF_CLASS(code) == BPF_ALU or BPF_JMP, 4th bit encodes source operand ...
631 -
632 - BPF_K 0x00
633 - BPF_X 0x08
634 -
635 - * in classic BPF, this means:
636 -
637 - BPF_SRC(code) == BPF_X - use register X as source operand
638 - BPF_SRC(code) == BPF_K - use 32-bit immediate as source operand
639 -
640 - * in eBPF, this means:
641 -
642 - BPF_SRC(code) == BPF_X - use 'src_reg' register as source operand
643 - BPF_SRC(code) == BPF_K - use 32-bit immediate as source operand
644 -
645 -... and four MSB bits store operation code.
646 -
647 -If BPF_CLASS(code) == BPF_ALU or BPF_ALU64 [ in eBPF ], BPF_OP(code) is one of:
648 -
649 - BPF_ADD 0x00
650 - BPF_SUB 0x10
651 - BPF_MUL 0x20
652 - BPF_DIV 0x30
653 - BPF_OR 0x40
654 - BPF_AND 0x50
655 - BPF_LSH 0x60
656 - BPF_RSH 0x70
657 - BPF_NEG 0x80
658 - BPF_MOD 0x90
659 - BPF_XOR 0xa0
660 - BPF_MOV 0xb0 /* eBPF only: mov reg to reg */
661 - BPF_ARSH 0xc0 /* eBPF only: sign extending shift right */
662 - BPF_END 0xd0 /* eBPF only: endianness conversion */
663 -
664 -If BPF_CLASS(code) == BPF_JMP, BPF_OP(code) is one of:
665 -
666 - BPF_JA 0x00
667 - BPF_JEQ 0x10
668 - BPF_JGT 0x20
669 - BPF_JGE 0x30
670 - BPF_JSET 0x40
671 - BPF_JNE 0x50 /* eBPF only: jump != */
672 - BPF_JSGT 0x60 /* eBPF only: signed '>' */
673 - BPF_JSGE 0x70 /* eBPF only: signed '>=' */
674 - BPF_CALL 0x80 /* eBPF only: function call */
675 - BPF_EXIT 0x90 /* eBPF only: function return */
676 -
677 -So BPF_ADD | BPF_X | BPF_ALU means 32-bit addition in both classic BPF
678 -and eBPF. There are only two registers in classic BPF, so it means A += X.
679 -In eBPF it means dst_reg = (u32) dst_reg + (u32) src_reg; similarly,
680 -BPF_XOR | BPF_K | BPF_ALU means A ^= imm32 in classic BPF and analogous
681 -src_reg = (u32) src_reg ^ (u32) imm32 in eBPF.
682 -
683 -Classic BPF is using BPF_MISC class to represent A = X and X = A moves.
684 -eBPF is using BPF_MOV | BPF_X | BPF_ALU code instead. Since there are no
685 -BPF_MISC operations in eBPF, the class 7 is used as BPF_ALU64 to mean
686 -exactly the same operations as BPF_ALU, but with 64-bit wide operands
687 -instead. So BPF_ADD | BPF_X | BPF_ALU64 means 64-bit addition, i.e.:
688 -dst_reg = dst_reg + src_reg
689 -
690 -Classic BPF wastes the whole BPF_RET class to represent a single 'ret'
691 -operation. Classic BPF_RET | BPF_K means copy imm32 into return register
692 -and perform function exit. eBPF is modeled to match CPU, so BPF_JMP | BPF_EXIT
693 -in eBPF means function exit only. The eBPF program needs to store return
694 -value into register R0 before doing a BPF_EXIT. Class 6 in eBPF is currently
695 -unused and reserved for future use.
696 -
697 -For load and store instructions the 8-bit 'code' field is divided as:
698 -
699 - +--------+--------+-------------------+
700 - | 3 bits | 2 bits | 3 bits |
701 - | mode | size | instruction class |
702 - +--------+--------+-------------------+
703 - (MSB) (LSB)
704 -
705 -Size modifier is one of ...
706 -
707 - BPF_W 0x00 /* word */
708 - BPF_H 0x08 /* half word */
709 - BPF_B 0x10 /* byte */
710 - BPF_DW 0x18 /* eBPF only, double word */
711 -
712 -... which encodes size of load/store operation:
713 -
714 - B - 1 byte
715 - H - 2 byte
716 - W - 4 byte
717 - DW - 8 byte (eBPF only)
718 -
719 -Mode modifier is one of:
720 -
721 - BPF_IMM 0x00 /* classic BPF only, reserved in eBPF */
722 - BPF_ABS 0x20
723 - BPF_IND 0x40
724 - BPF_MEM 0x60
725 - BPF_LEN 0x80 /* classic BPF only, reserved in eBPF */
726 - BPF_MSH 0xa0 /* classic BPF only, reserved in eBPF */
727 - BPF_XADD 0xc0 /* eBPF only, exclusive add */
728 -
729 -eBPF has two non-generic instructions: (BPF_ABS | <size> | BPF_LD) and
730 -(BPF_IND | <size> | BPF_LD) which are used to access packet data.
731 -
732 -They had to be carried over from classic to have strong performance of
733 -socket filters running in eBPF interpreter. These instructions can only
734 -be used when interpreter context is a pointer to 'struct sk_buff' and
735 -have seven implicit operands. Register R6 is an implicit input that must
736 -contain pointer to sk_buff. Register R0 is an implicit output which contains
737 -the data fetched from the packet. Registers R1-R5 are scratch registers
738 -and must not be used to store the data across BPF_ABS | BPF_LD or
739 -BPF_IND | BPF_LD instructions.
740 -
741 -These instructions have implicit program exit condition as well. When
742 -eBPF program is trying to access the data beyond the packet boundary,
743 -the interpreter will abort the execution of the program. JIT compilers
744 -therefore must preserve this property. src_reg and imm32 fields are
745 -explicit inputs to these instructions.
746 -
747 -For example:
748 -
749 - BPF_IND | BPF_W | BPF_LD means:
750 -
751 - R0 = ntohl(*(u32 *) (((struct sk_buff *) R6)->data + src_reg + imm32))
752 - and R1 - R5 were scratched.
753 -
754 -Unlike classic BPF instruction set, eBPF has generic load/store operations:
755 -
756 -BPF_MEM | <size> | BPF_STX: *(size *) (dst_reg + off) = src_reg
757 -BPF_MEM | <size> | BPF_ST: *(size *) (dst_reg + off) = imm32
758 -BPF_MEM | <size> | BPF_LDX: dst_reg = *(size *) (src_reg + off)
759 -BPF_XADD | BPF_W | BPF_STX: lock xadd *(u32 *)(dst_reg + off16) += src_reg
760 -BPF_XADD | BPF_DW | BPF_STX: lock xadd *(u64 *)(dst_reg + off16) += src_reg
761 -
762 -Where size is one of: BPF_B or BPF_H or BPF_W or BPF_DW. Note that 1 and
763 -2 byte atomic increments are not supported.
764 -
765 -Testing
766 --------
767 -
768 -Next to the BPF toolchain, the kernel also ships a test module that contains
769 -various test cases for classic and internal BPF that can be executed against
770 -the BPF interpreter and JIT compiler. It can be found in lib/test_bpf.c and
771 -enabled via Kconfig:
772 -
773 - CONFIG_TEST_BPF=m
774 -
775 -After the module has been built and installed, the test suite can be executed
776 -via insmod or modprobe against 'test_bpf' module. Results of the test cases
777 -including timings in nsec can be found in the kernel log (dmesg).
778 -
779 Misc
780 ----
781
782 @@ -1024,4 +561,3 @@ the underlying architecture.
783
784 Jay Schulist <jschlst@samba.org>
785 Daniel Borkmann <dborkman@redhat.com>
786 -Alexei Starovoitov <ast@plumgrid.com>
787 diff --git a/Makefile b/Makefile
788 index c261752..7b9958b 100644
789 --- a/Makefile
790 +++ b/Makefile
791 @@ -303,8 +303,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
792
793 HOSTCC = gcc
794 HOSTCXX = g++
795 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
796 -HOSTCXXFLAGS = -O2
797 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
798 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
799 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
800
801 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
802 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
803 @@ -449,8 +450,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
804 # Rules shared between *config targets and build targets
805
806 # Basic helpers built in scripts/
807 -PHONY += scripts_basic
808 -scripts_basic:
809 +PHONY += scripts_basic gcc-plugins
810 +scripts_basic: gcc-plugins
811 $(Q)$(MAKE) $(build)=scripts/basic
812 $(Q)rm -f .tmp_quiet_recordmcount
813
814 @@ -621,6 +622,75 @@ else
815 KBUILD_CFLAGS += -O2
816 endif
817
818 +# Tell gcc to never replace conditional load with a non-conditional one
819 +KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
820 +
821 +ifndef DISABLE_PAX_PLUGINS
822 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
823 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
824 +else
825 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
826 +endif
827 +ifneq ($(PLUGINCC),)
828 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
829 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
830 +endif
831 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
832 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
833 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
834 +endif
835 +ifdef CONFIG_KALLOCSTAT_PLUGIN
836 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
837 +endif
838 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
839 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
840 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
841 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
842 +endif
843 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
844 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
845 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
846 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
847 +endif
848 +endif
849 +ifdef CONFIG_CHECKER_PLUGIN
850 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
851 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
852 +endif
853 +endif
854 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
855 +ifdef CONFIG_PAX_SIZE_OVERFLOW
856 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
857 +endif
858 +ifdef CONFIG_PAX_LATENT_ENTROPY
859 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
860 +endif
861 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
862 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
863 +endif
864 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
865 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
866 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
867 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
868 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
869 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
870 +ifeq ($(KBUILD_EXTMOD),)
871 +gcc-plugins:
872 + $(Q)$(MAKE) $(build)=tools/gcc
873 +else
874 +gcc-plugins: ;
875 +endif
876 +else
877 +gcc-plugins:
878 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
879 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
880 +else
881 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
882 +endif
883 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
884 +endif
885 +endif
886 +
887 ifdef CONFIG_READABLE_ASM
888 # Disable optimizations that make assembler listings hard to read.
889 # reorder blocks reorders the control in the function
890 @@ -839,7 +909,7 @@ export mod_sign_cmd
891
892
893 ifeq ($(KBUILD_EXTMOD),)
894 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
895 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
896
897 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
898 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
899 @@ -888,6 +958,8 @@ endif
900
901 # The actual objects are generated when descending,
902 # make sure no implicit rule kicks in
903 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
904 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
905 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
906
907 # Handle descending into subdirectories listed in $(vmlinux-dirs)
908 @@ -897,7 +969,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
909 # Error messages still appears in the original language
910
911 PHONY += $(vmlinux-dirs)
912 -$(vmlinux-dirs): prepare scripts
913 +$(vmlinux-dirs): gcc-plugins prepare scripts
914 $(Q)$(MAKE) $(build)=$@
915
916 define filechk_kernel.release
917 @@ -940,10 +1012,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
918
919 archprepare: archheaders archscripts prepare1 scripts_basic
920
921 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
922 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
923 prepare0: archprepare FORCE
924 $(Q)$(MAKE) $(build)=.
925
926 # All the preparing..
927 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
928 prepare: prepare0
929
930 # Generate some files
931 @@ -1051,6 +1126,8 @@ all: modules
932 # using awk while concatenating to the final file.
933
934 PHONY += modules
935 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
936 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
937 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
938 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
939 @$(kecho) ' Building modules, stage 2.';
940 @@ -1066,7 +1143,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
941
942 # Target to prepare building external modules
943 PHONY += modules_prepare
944 -modules_prepare: prepare scripts
945 +modules_prepare: gcc-plugins prepare scripts
946
947 # Target to install modules
948 PHONY += modules_install
949 @@ -1132,7 +1209,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
950 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
951 signing_key.priv signing_key.x509 x509.genkey \
952 extra_certificates signing_key.x509.keyid \
953 - signing_key.x509.signer include/linux/version.h
954 + signing_key.x509.signer include/linux/version.h \
955 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
956 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
957 + tools/gcc/randomize_layout_seed.h
958
959 # clean - Delete most, but leave enough to build external modules
960 #
961 @@ -1171,7 +1251,7 @@ distclean: mrproper
962 @find $(srctree) $(RCS_FIND_IGNORE) \
963 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
964 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
965 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
966 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
967 -type f -print | xargs rm -f
968
969
970 @@ -1332,6 +1412,8 @@ PHONY += $(module-dirs) modules
971 $(module-dirs): crmodverdir $(objtree)/Module.symvers
972 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
973
974 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
975 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
976 modules: $(module-dirs)
977 @$(kecho) ' Building modules, stage 2.';
978 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
979 @@ -1471,17 +1553,21 @@ else
980 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
981 endif
982
983 -%.s: %.c prepare scripts FORCE
984 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
985 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
986 +%.s: %.c gcc-plugins prepare scripts FORCE
987 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
988 %.i: %.c prepare scripts FORCE
989 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
990 -%.o: %.c prepare scripts FORCE
991 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
992 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
993 +%.o: %.c gcc-plugins prepare scripts FORCE
994 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
995 %.lst: %.c prepare scripts FORCE
996 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
997 -%.s: %.S prepare scripts FORCE
998 +%.s: %.S gcc-plugins prepare scripts FORCE
999 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1000 -%.o: %.S prepare scripts FORCE
1001 +%.o: %.S gcc-plugins prepare scripts FORCE
1002 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1003 %.symtypes: %.c prepare scripts FORCE
1004 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1005 @@ -1491,11 +1577,15 @@ endif
1006 $(cmd_crmodverdir)
1007 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1008 $(build)=$(build-dir)
1009 -%/: prepare scripts FORCE
1010 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
1011 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
1012 +%/: gcc-plugins prepare scripts FORCE
1013 $(cmd_crmodverdir)
1014 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1015 $(build)=$(build-dir)
1016 -%.ko: prepare scripts FORCE
1017 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
1018 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
1019 +%.ko: gcc-plugins prepare scripts FORCE
1020 $(cmd_crmodverdir)
1021 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1022 $(build)=$(build-dir) $(@:.ko=.o)
1023 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
1024 index ed60a1e..47f1a55 100644
1025 --- a/arch/alpha/include/asm/atomic.h
1026 +++ b/arch/alpha/include/asm/atomic.h
1027 @@ -292,4 +292,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
1028 #define atomic_dec(v) atomic_sub(1,(v))
1029 #define atomic64_dec(v) atomic64_sub(1,(v))
1030
1031 +#define atomic64_read_unchecked(v) atomic64_read(v)
1032 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1033 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1034 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1035 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1036 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
1037 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1038 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
1039 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1040 +
1041 #endif /* _ALPHA_ATOMIC_H */
1042 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
1043 index ad368a9..fbe0f25 100644
1044 --- a/arch/alpha/include/asm/cache.h
1045 +++ b/arch/alpha/include/asm/cache.h
1046 @@ -4,19 +4,19 @@
1047 #ifndef __ARCH_ALPHA_CACHE_H
1048 #define __ARCH_ALPHA_CACHE_H
1049
1050 +#include <linux/const.h>
1051
1052 /* Bytes per L1 (data) cache line. */
1053 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
1054 -# define L1_CACHE_BYTES 64
1055 # define L1_CACHE_SHIFT 6
1056 #else
1057 /* Both EV4 and EV5 are write-through, read-allocate,
1058 direct-mapped, physical.
1059 */
1060 -# define L1_CACHE_BYTES 32
1061 # define L1_CACHE_SHIFT 5
1062 #endif
1063
1064 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1065 #define SMP_CACHE_BYTES L1_CACHE_BYTES
1066
1067 #endif
1068 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
1069 index 968d999..d36b2df 100644
1070 --- a/arch/alpha/include/asm/elf.h
1071 +++ b/arch/alpha/include/asm/elf.h
1072 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1073
1074 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
1075
1076 +#ifdef CONFIG_PAX_ASLR
1077 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
1078 +
1079 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
1080 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
1081 +#endif
1082 +
1083 /* $0 is set by ld.so to a pointer to a function which might be
1084 registered using atexit. This provides a mean for the dynamic
1085 linker to call DT_FINI functions for shared libraries that have
1086 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
1087 index aab14a0..b4fa3e7 100644
1088 --- a/arch/alpha/include/asm/pgalloc.h
1089 +++ b/arch/alpha/include/asm/pgalloc.h
1090 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
1091 pgd_set(pgd, pmd);
1092 }
1093
1094 +static inline void
1095 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
1096 +{
1097 + pgd_populate(mm, pgd, pmd);
1098 +}
1099 +
1100 extern pgd_t *pgd_alloc(struct mm_struct *mm);
1101
1102 static inline void
1103 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
1104 index d8f9b7e..f6222fa 100644
1105 --- a/arch/alpha/include/asm/pgtable.h
1106 +++ b/arch/alpha/include/asm/pgtable.h
1107 @@ -102,6 +102,17 @@ struct vm_area_struct;
1108 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
1109 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
1110 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
1111 +
1112 +#ifdef CONFIG_PAX_PAGEEXEC
1113 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
1114 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
1115 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
1116 +#else
1117 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1118 +# define PAGE_COPY_NOEXEC PAGE_COPY
1119 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1120 +#endif
1121 +
1122 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
1123
1124 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
1125 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
1126 index 2fd00b7..cfd5069 100644
1127 --- a/arch/alpha/kernel/module.c
1128 +++ b/arch/alpha/kernel/module.c
1129 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
1130
1131 /* The small sections were sorted to the end of the segment.
1132 The following should definitely cover them. */
1133 - gp = (u64)me->module_core + me->core_size - 0x8000;
1134 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
1135 got = sechdrs[me->arch.gotsecindex].sh_addr;
1136
1137 for (i = 0; i < n; i++) {
1138 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
1139 index 1402fcc..0b1abd2 100644
1140 --- a/arch/alpha/kernel/osf_sys.c
1141 +++ b/arch/alpha/kernel/osf_sys.c
1142 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
1143 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
1144
1145 static unsigned long
1146 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
1147 - unsigned long limit)
1148 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
1149 + unsigned long limit, unsigned long flags)
1150 {
1151 struct vm_unmapped_area_info info;
1152 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
1153
1154 info.flags = 0;
1155 info.length = len;
1156 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
1157 info.high_limit = limit;
1158 info.align_mask = 0;
1159 info.align_offset = 0;
1160 + info.threadstack_offset = offset;
1161 return vm_unmapped_area(&info);
1162 }
1163
1164 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1165 merely specific addresses, but regions of memory -- perhaps
1166 this feature should be incorporated into all ports? */
1167
1168 +#ifdef CONFIG_PAX_RANDMMAP
1169 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1170 +#endif
1171 +
1172 if (addr) {
1173 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
1174 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
1175 if (addr != (unsigned long) -ENOMEM)
1176 return addr;
1177 }
1178
1179 /* Next, try allocating at TASK_UNMAPPED_BASE. */
1180 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
1181 - len, limit);
1182 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
1183 +
1184 if (addr != (unsigned long) -ENOMEM)
1185 return addr;
1186
1187 /* Finally, try allocating in low memory. */
1188 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
1189 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
1190
1191 return addr;
1192 }
1193 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
1194 index 98838a0..b304fb4 100644
1195 --- a/arch/alpha/mm/fault.c
1196 +++ b/arch/alpha/mm/fault.c
1197 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
1198 __reload_thread(pcb);
1199 }
1200
1201 +#ifdef CONFIG_PAX_PAGEEXEC
1202 +/*
1203 + * PaX: decide what to do with offenders (regs->pc = fault address)
1204 + *
1205 + * returns 1 when task should be killed
1206 + * 2 when patched PLT trampoline was detected
1207 + * 3 when unpatched PLT trampoline was detected
1208 + */
1209 +static int pax_handle_fetch_fault(struct pt_regs *regs)
1210 +{
1211 +
1212 +#ifdef CONFIG_PAX_EMUPLT
1213 + int err;
1214 +
1215 + do { /* PaX: patched PLT emulation #1 */
1216 + unsigned int ldah, ldq, jmp;
1217 +
1218 + err = get_user(ldah, (unsigned int *)regs->pc);
1219 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
1220 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
1221 +
1222 + if (err)
1223 + break;
1224 +
1225 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
1226 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
1227 + jmp == 0x6BFB0000U)
1228 + {
1229 + unsigned long r27, addr;
1230 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
1231 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
1232 +
1233 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
1234 + err = get_user(r27, (unsigned long *)addr);
1235 + if (err)
1236 + break;
1237 +
1238 + regs->r27 = r27;
1239 + regs->pc = r27;
1240 + return 2;
1241 + }
1242 + } while (0);
1243 +
1244 + do { /* PaX: patched PLT emulation #2 */
1245 + unsigned int ldah, lda, br;
1246 +
1247 + err = get_user(ldah, (unsigned int *)regs->pc);
1248 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
1249 + err |= get_user(br, (unsigned int *)(regs->pc+8));
1250 +
1251 + if (err)
1252 + break;
1253 +
1254 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
1255 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
1256 + (br & 0xFFE00000U) == 0xC3E00000U)
1257 + {
1258 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
1259 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
1260 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
1261 +
1262 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
1263 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
1264 + return 2;
1265 + }
1266 + } while (0);
1267 +
1268 + do { /* PaX: unpatched PLT emulation */
1269 + unsigned int br;
1270 +
1271 + err = get_user(br, (unsigned int *)regs->pc);
1272 +
1273 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
1274 + unsigned int br2, ldq, nop, jmp;
1275 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
1276 +
1277 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
1278 + err = get_user(br2, (unsigned int *)addr);
1279 + err |= get_user(ldq, (unsigned int *)(addr+4));
1280 + err |= get_user(nop, (unsigned int *)(addr+8));
1281 + err |= get_user(jmp, (unsigned int *)(addr+12));
1282 + err |= get_user(resolver, (unsigned long *)(addr+16));
1283 +
1284 + if (err)
1285 + break;
1286 +
1287 + if (br2 == 0xC3600000U &&
1288 + ldq == 0xA77B000CU &&
1289 + nop == 0x47FF041FU &&
1290 + jmp == 0x6B7B0000U)
1291 + {
1292 + regs->r28 = regs->pc+4;
1293 + regs->r27 = addr+16;
1294 + regs->pc = resolver;
1295 + return 3;
1296 + }
1297 + }
1298 + } while (0);
1299 +#endif
1300 +
1301 + return 1;
1302 +}
1303 +
1304 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1305 +{
1306 + unsigned long i;
1307 +
1308 + printk(KERN_ERR "PAX: bytes at PC: ");
1309 + for (i = 0; i < 5; i++) {
1310 + unsigned int c;
1311 + if (get_user(c, (unsigned int *)pc+i))
1312 + printk(KERN_CONT "???????? ");
1313 + else
1314 + printk(KERN_CONT "%08x ", c);
1315 + }
1316 + printk("\n");
1317 +}
1318 +#endif
1319
1320 /*
1321 * This routine handles page faults. It determines the address,
1322 @@ -133,8 +251,29 @@ retry:
1323 good_area:
1324 si_code = SEGV_ACCERR;
1325 if (cause < 0) {
1326 - if (!(vma->vm_flags & VM_EXEC))
1327 + if (!(vma->vm_flags & VM_EXEC)) {
1328 +
1329 +#ifdef CONFIG_PAX_PAGEEXEC
1330 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
1331 + goto bad_area;
1332 +
1333 + up_read(&mm->mmap_sem);
1334 + switch (pax_handle_fetch_fault(regs)) {
1335 +
1336 +#ifdef CONFIG_PAX_EMUPLT
1337 + case 2:
1338 + case 3:
1339 + return;
1340 +#endif
1341 +
1342 + }
1343 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
1344 + do_group_exit(SIGKILL);
1345 +#else
1346 goto bad_area;
1347 +#endif
1348 +
1349 + }
1350 } else if (!cause) {
1351 /* Allow reads even for write-only mappings */
1352 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
1353 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
1354 index 290f02ee..a639059 100644
1355 --- a/arch/arm/Kconfig
1356 +++ b/arch/arm/Kconfig
1357 @@ -1787,7 +1787,7 @@ config ALIGNMENT_TRAP
1358
1359 config UACCESS_WITH_MEMCPY
1360 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
1361 - depends on MMU
1362 + depends on MMU && !PAX_MEMORY_UDEREF
1363 default y if CPU_FEROCEON
1364 help
1365 Implement faster copy_to_user and clear_user methods for CPU
1366 @@ -2051,6 +2051,7 @@ config XIP_PHYS_ADDR
1367 config KEXEC
1368 bool "Kexec system call (EXPERIMENTAL)"
1369 depends on (!SMP || PM_SLEEP_SMP)
1370 + depends on !GRKERNSEC_KMEM
1371 help
1372 kexec is a system call that implements the ability to shutdown your
1373 current kernel, and to start another kernel. It is like a reboot
1374 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
1375 index 3040359..89b3dfc 100644
1376 --- a/arch/arm/include/asm/atomic.h
1377 +++ b/arch/arm/include/asm/atomic.h
1378 @@ -18,17 +18,35 @@
1379 #include <asm/barrier.h>
1380 #include <asm/cmpxchg.h>
1381
1382 +#ifdef CONFIG_GENERIC_ATOMIC64
1383 +#include <asm-generic/atomic64.h>
1384 +#endif
1385 +
1386 #define ATOMIC_INIT(i) { (i) }
1387
1388 #ifdef __KERNEL__
1389
1390 +#define _ASM_EXTABLE(from, to) \
1391 +" .pushsection __ex_table,\"a\"\n"\
1392 +" .align 3\n" \
1393 +" .long " #from ", " #to"\n" \
1394 +" .popsection"
1395 +
1396 /*
1397 * On ARM, ordinary assignment (str instruction) doesn't clear the local
1398 * strex/ldrex monitor on some implementations. The reason we can use it for
1399 * atomic_set() is the clrex or dummy strex done on every exception return.
1400 */
1401 #define atomic_read(v) (*(volatile int *)&(v)->counter)
1402 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
1403 +{
1404 + return v->counter;
1405 +}
1406 #define atomic_set(v,i) (((v)->counter) = (i))
1407 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1408 +{
1409 + v->counter = i;
1410 +}
1411
1412 #if __LINUX_ARM_ARCH__ >= 6
1413
1414 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
1415
1416 prefetchw(&v->counter);
1417 __asm__ __volatile__("@ atomic_add\n"
1418 +"1: ldrex %1, [%3]\n"
1419 +" adds %0, %1, %4\n"
1420 +
1421 +#ifdef CONFIG_PAX_REFCOUNT
1422 +" bvc 3f\n"
1423 +"2: bkpt 0xf103\n"
1424 +"3:\n"
1425 +#endif
1426 +
1427 +" strex %1, %0, [%3]\n"
1428 +" teq %1, #0\n"
1429 +" bne 1b"
1430 +
1431 +#ifdef CONFIG_PAX_REFCOUNT
1432 +"\n4:\n"
1433 + _ASM_EXTABLE(2b, 4b)
1434 +#endif
1435 +
1436 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1437 + : "r" (&v->counter), "Ir" (i)
1438 + : "cc");
1439 +}
1440 +
1441 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1442 +{
1443 + unsigned long tmp;
1444 + int result;
1445 +
1446 + prefetchw(&v->counter);
1447 + __asm__ __volatile__("@ atomic_add_unchecked\n"
1448 "1: ldrex %0, [%3]\n"
1449 " add %0, %0, %4\n"
1450 " strex %1, %0, [%3]\n"
1451 @@ -63,6 +111,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
1452 prefetchw(&v->counter);
1453
1454 __asm__ __volatile__("@ atomic_add_return\n"
1455 +"1: ldrex %1, [%3]\n"
1456 +" adds %0, %1, %4\n"
1457 +
1458 +#ifdef CONFIG_PAX_REFCOUNT
1459 +" bvc 3f\n"
1460 +" mov %0, %1\n"
1461 +"2: bkpt 0xf103\n"
1462 +"3:\n"
1463 +#endif
1464 +
1465 +" strex %1, %0, [%3]\n"
1466 +" teq %1, #0\n"
1467 +" bne 1b"
1468 +
1469 +#ifdef CONFIG_PAX_REFCOUNT
1470 +"\n4:\n"
1471 + _ASM_EXTABLE(2b, 4b)
1472 +#endif
1473 +
1474 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1475 + : "r" (&v->counter), "Ir" (i)
1476 + : "cc");
1477 +
1478 + smp_mb();
1479 +
1480 + return result;
1481 +}
1482 +
1483 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1484 +{
1485 + unsigned long tmp;
1486 + int result;
1487 +
1488 + smp_mb();
1489 + prefetchw(&v->counter);
1490 +
1491 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1492 "1: ldrex %0, [%3]\n"
1493 " add %0, %0, %4\n"
1494 " strex %1, %0, [%3]\n"
1495 @@ -84,6 +169,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1496
1497 prefetchw(&v->counter);
1498 __asm__ __volatile__("@ atomic_sub\n"
1499 +"1: ldrex %1, [%3]\n"
1500 +" subs %0, %1, %4\n"
1501 +
1502 +#ifdef CONFIG_PAX_REFCOUNT
1503 +" bvc 3f\n"
1504 +"2: bkpt 0xf103\n"
1505 +"3:\n"
1506 +#endif
1507 +
1508 +" strex %1, %0, [%3]\n"
1509 +" teq %1, #0\n"
1510 +" bne 1b"
1511 +
1512 +#ifdef CONFIG_PAX_REFCOUNT
1513 +"\n4:\n"
1514 + _ASM_EXTABLE(2b, 4b)
1515 +#endif
1516 +
1517 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1518 + : "r" (&v->counter), "Ir" (i)
1519 + : "cc");
1520 +}
1521 +
1522 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1523 +{
1524 + unsigned long tmp;
1525 + int result;
1526 +
1527 + prefetchw(&v->counter);
1528 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1529 "1: ldrex %0, [%3]\n"
1530 " sub %0, %0, %4\n"
1531 " strex %1, %0, [%3]\n"
1532 @@ -103,11 +218,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1533 prefetchw(&v->counter);
1534
1535 __asm__ __volatile__("@ atomic_sub_return\n"
1536 -"1: ldrex %0, [%3]\n"
1537 -" sub %0, %0, %4\n"
1538 +"1: ldrex %1, [%3]\n"
1539 +" subs %0, %1, %4\n"
1540 +
1541 +#ifdef CONFIG_PAX_REFCOUNT
1542 +" bvc 3f\n"
1543 +" mov %0, %1\n"
1544 +"2: bkpt 0xf103\n"
1545 +"3:\n"
1546 +#endif
1547 +
1548 " strex %1, %0, [%3]\n"
1549 " teq %1, #0\n"
1550 " bne 1b"
1551 +
1552 +#ifdef CONFIG_PAX_REFCOUNT
1553 +"\n4:\n"
1554 + _ASM_EXTABLE(2b, 4b)
1555 +#endif
1556 +
1557 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1558 : "r" (&v->counter), "Ir" (i)
1559 : "cc");
1560 @@ -152,12 +281,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1561 __asm__ __volatile__ ("@ atomic_add_unless\n"
1562 "1: ldrex %0, [%4]\n"
1563 " teq %0, %5\n"
1564 -" beq 2f\n"
1565 -" add %1, %0, %6\n"
1566 +" beq 4f\n"
1567 +" adds %1, %0, %6\n"
1568 +
1569 +#ifdef CONFIG_PAX_REFCOUNT
1570 +" bvc 3f\n"
1571 +"2: bkpt 0xf103\n"
1572 +"3:\n"
1573 +#endif
1574 +
1575 " strex %2, %1, [%4]\n"
1576 " teq %2, #0\n"
1577 " bne 1b\n"
1578 -"2:"
1579 +"4:"
1580 +
1581 +#ifdef CONFIG_PAX_REFCOUNT
1582 + _ASM_EXTABLE(2b, 4b)
1583 +#endif
1584 +
1585 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1586 : "r" (&v->counter), "r" (u), "r" (a)
1587 : "cc");
1588 @@ -168,6 +309,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1589 return oldval;
1590 }
1591
1592 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1593 +{
1594 + unsigned long oldval, res;
1595 +
1596 + smp_mb();
1597 +
1598 + do {
1599 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1600 + "ldrex %1, [%3]\n"
1601 + "mov %0, #0\n"
1602 + "teq %1, %4\n"
1603 + "strexeq %0, %5, [%3]\n"
1604 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1605 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1606 + : "cc");
1607 + } while (res);
1608 +
1609 + smp_mb();
1610 +
1611 + return oldval;
1612 +}
1613 +
1614 #else /* ARM_ARCH_6 */
1615
1616 #ifdef CONFIG_SMP
1617 @@ -186,7 +349,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1618
1619 return val;
1620 }
1621 +
1622 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1623 +{
1624 + return atomic_add_return(i, v);
1625 +}
1626 +
1627 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1628 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1629 +{
1630 + (void) atomic_add_return(i, v);
1631 +}
1632
1633 static inline int atomic_sub_return(int i, atomic_t *v)
1634 {
1635 @@ -201,6 +374,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1636 return val;
1637 }
1638 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1639 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1640 +{
1641 + (void) atomic_sub_return(i, v);
1642 +}
1643
1644 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1645 {
1646 @@ -216,6 +393,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1647 return ret;
1648 }
1649
1650 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1651 +{
1652 + return atomic_cmpxchg(v, old, new);
1653 +}
1654 +
1655 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1656 {
1657 int c, old;
1658 @@ -229,13 +411,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1659 #endif /* __LINUX_ARM_ARCH__ */
1660
1661 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1662 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1663 +{
1664 + return xchg(&v->counter, new);
1665 +}
1666
1667 #define atomic_inc(v) atomic_add(1, v)
1668 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1669 +{
1670 + atomic_add_unchecked(1, v);
1671 +}
1672 #define atomic_dec(v) atomic_sub(1, v)
1673 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1674 +{
1675 + atomic_sub_unchecked(1, v);
1676 +}
1677
1678 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1679 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1680 +{
1681 + return atomic_add_return_unchecked(1, v) == 0;
1682 +}
1683 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1684 #define atomic_inc_return(v) (atomic_add_return(1, v))
1685 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1686 +{
1687 + return atomic_add_return_unchecked(1, v);
1688 +}
1689 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1690 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1691
1692 @@ -246,6 +448,14 @@ typedef struct {
1693 long long counter;
1694 } atomic64_t;
1695
1696 +#ifdef CONFIG_PAX_REFCOUNT
1697 +typedef struct {
1698 + long long counter;
1699 +} atomic64_unchecked_t;
1700 +#else
1701 +typedef atomic64_t atomic64_unchecked_t;
1702 +#endif
1703 +
1704 #define ATOMIC64_INIT(i) { (i) }
1705
1706 #ifdef CONFIG_ARM_LPAE
1707 @@ -262,6 +472,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1708 return result;
1709 }
1710
1711 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1712 +{
1713 + long long result;
1714 +
1715 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1716 +" ldrd %0, %H0, [%1]"
1717 + : "=&r" (result)
1718 + : "r" (&v->counter), "Qo" (v->counter)
1719 + );
1720 +
1721 + return result;
1722 +}
1723 +
1724 static inline void atomic64_set(atomic64_t *v, long long i)
1725 {
1726 __asm__ __volatile__("@ atomic64_set\n"
1727 @@ -270,6 +493,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1728 : "r" (&v->counter), "r" (i)
1729 );
1730 }
1731 +
1732 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1733 +{
1734 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1735 +" strd %2, %H2, [%1]"
1736 + : "=Qo" (v->counter)
1737 + : "r" (&v->counter), "r" (i)
1738 + );
1739 +}
1740 #else
1741 static inline long long atomic64_read(const atomic64_t *v)
1742 {
1743 @@ -284,6 +516,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1744 return result;
1745 }
1746
1747 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1748 +{
1749 + long long result;
1750 +
1751 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1752 +" ldrexd %0, %H0, [%1]"
1753 + : "=&r" (result)
1754 + : "r" (&v->counter), "Qo" (v->counter)
1755 + );
1756 +
1757 + return result;
1758 +}
1759 +
1760 static inline void atomic64_set(atomic64_t *v, long long i)
1761 {
1762 long long tmp;
1763 @@ -298,6 +543,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1764 : "r" (&v->counter), "r" (i)
1765 : "cc");
1766 }
1767 +
1768 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1769 +{
1770 + long long tmp;
1771 +
1772 + prefetchw(&v->counter);
1773 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1774 +"1: ldrexd %0, %H0, [%2]\n"
1775 +" strexd %0, %3, %H3, [%2]\n"
1776 +" teq %0, #0\n"
1777 +" bne 1b"
1778 + : "=&r" (tmp), "=Qo" (v->counter)
1779 + : "r" (&v->counter), "r" (i)
1780 + : "cc");
1781 +}
1782 #endif
1783
1784 static inline void atomic64_add(long long i, atomic64_t *v)
1785 @@ -309,6 +569,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1786 __asm__ __volatile__("@ atomic64_add\n"
1787 "1: ldrexd %0, %H0, [%3]\n"
1788 " adds %Q0, %Q0, %Q4\n"
1789 +" adcs %R0, %R0, %R4\n"
1790 +
1791 +#ifdef CONFIG_PAX_REFCOUNT
1792 +" bvc 3f\n"
1793 +"2: bkpt 0xf103\n"
1794 +"3:\n"
1795 +#endif
1796 +
1797 +" strexd %1, %0, %H0, [%3]\n"
1798 +" teq %1, #0\n"
1799 +" bne 1b"
1800 +
1801 +#ifdef CONFIG_PAX_REFCOUNT
1802 +"\n4:\n"
1803 + _ASM_EXTABLE(2b, 4b)
1804 +#endif
1805 +
1806 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1807 + : "r" (&v->counter), "r" (i)
1808 + : "cc");
1809 +}
1810 +
1811 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1812 +{
1813 + long long result;
1814 + unsigned long tmp;
1815 +
1816 + prefetchw(&v->counter);
1817 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1818 +"1: ldrexd %0, %H0, [%3]\n"
1819 +" adds %Q0, %Q0, %Q4\n"
1820 " adc %R0, %R0, %R4\n"
1821 " strexd %1, %0, %H0, [%3]\n"
1822 " teq %1, #0\n"
1823 @@ -329,6 +620,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1824 __asm__ __volatile__("@ atomic64_add_return\n"
1825 "1: ldrexd %0, %H0, [%3]\n"
1826 " adds %Q0, %Q0, %Q4\n"
1827 +" adcs %R0, %R0, %R4\n"
1828 +
1829 +#ifdef CONFIG_PAX_REFCOUNT
1830 +" bvc 3f\n"
1831 +" mov %0, %1\n"
1832 +" mov %H0, %H1\n"
1833 +"2: bkpt 0xf103\n"
1834 +"3:\n"
1835 +#endif
1836 +
1837 +" strexd %1, %0, %H0, [%3]\n"
1838 +" teq %1, #0\n"
1839 +" bne 1b"
1840 +
1841 +#ifdef CONFIG_PAX_REFCOUNT
1842 +"\n4:\n"
1843 + _ASM_EXTABLE(2b, 4b)
1844 +#endif
1845 +
1846 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1847 + : "r" (&v->counter), "r" (i)
1848 + : "cc");
1849 +
1850 + smp_mb();
1851 +
1852 + return result;
1853 +}
1854 +
1855 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1856 +{
1857 + long long result;
1858 + unsigned long tmp;
1859 +
1860 + smp_mb();
1861 +
1862 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1863 +"1: ldrexd %0, %H0, [%3]\n"
1864 +" adds %Q0, %Q0, %Q4\n"
1865 " adc %R0, %R0, %R4\n"
1866 " strexd %1, %0, %H0, [%3]\n"
1867 " teq %1, #0\n"
1868 @@ -351,6 +680,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1869 __asm__ __volatile__("@ atomic64_sub\n"
1870 "1: ldrexd %0, %H0, [%3]\n"
1871 " subs %Q0, %Q0, %Q4\n"
1872 +" sbcs %R0, %R0, %R4\n"
1873 +
1874 +#ifdef CONFIG_PAX_REFCOUNT
1875 +" bvc 3f\n"
1876 +"2: bkpt 0xf103\n"
1877 +"3:\n"
1878 +#endif
1879 +
1880 +" strexd %1, %0, %H0, [%3]\n"
1881 +" teq %1, #0\n"
1882 +" bne 1b"
1883 +
1884 +#ifdef CONFIG_PAX_REFCOUNT
1885 +"\n4:\n"
1886 + _ASM_EXTABLE(2b, 4b)
1887 +#endif
1888 +
1889 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1890 + : "r" (&v->counter), "r" (i)
1891 + : "cc");
1892 +}
1893 +
1894 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1895 +{
1896 + long long result;
1897 + unsigned long tmp;
1898 +
1899 + prefetchw(&v->counter);
1900 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1901 +"1: ldrexd %0, %H0, [%3]\n"
1902 +" subs %Q0, %Q0, %Q4\n"
1903 " sbc %R0, %R0, %R4\n"
1904 " strexd %1, %0, %H0, [%3]\n"
1905 " teq %1, #0\n"
1906 @@ -371,16 +731,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1907 __asm__ __volatile__("@ atomic64_sub_return\n"
1908 "1: ldrexd %0, %H0, [%3]\n"
1909 " subs %Q0, %Q0, %Q4\n"
1910 -" sbc %R0, %R0, %R4\n"
1911 +" sbcs %R0, %R0, %R4\n"
1912 +
1913 +#ifdef CONFIG_PAX_REFCOUNT
1914 +" bvc 3f\n"
1915 +" mov %0, %1\n"
1916 +" mov %H0, %H1\n"
1917 +"2: bkpt 0xf103\n"
1918 +"3:\n"
1919 +#endif
1920 +
1921 " strexd %1, %0, %H0, [%3]\n"
1922 " teq %1, #0\n"
1923 " bne 1b"
1924 +
1925 +#ifdef CONFIG_PAX_REFCOUNT
1926 +"\n4:\n"
1927 + _ASM_EXTABLE(2b, 4b)
1928 +#endif
1929 +
1930 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1931 : "r" (&v->counter), "r" (i)
1932 : "cc");
1933
1934 - smp_mb();
1935 -
1936 return result;
1937 }
1938
1939 @@ -410,6 +783,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1940 return oldval;
1941 }
1942
1943 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1944 + long long new)
1945 +{
1946 + long long oldval;
1947 + unsigned long res;
1948 +
1949 + smp_mb();
1950 +
1951 + do {
1952 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1953 + "ldrexd %1, %H1, [%3]\n"
1954 + "mov %0, #0\n"
1955 + "teq %1, %4\n"
1956 + "teqeq %H1, %H4\n"
1957 + "strexdeq %0, %5, %H5, [%3]"
1958 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1959 + : "r" (&ptr->counter), "r" (old), "r" (new)
1960 + : "cc");
1961 + } while (res);
1962 +
1963 + smp_mb();
1964 +
1965 + return oldval;
1966 +}
1967 +
1968 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1969 {
1970 long long result;
1971 @@ -435,21 +833,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1972 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1973 {
1974 long long result;
1975 - unsigned long tmp;
1976 + u64 tmp;
1977
1978 smp_mb();
1979 prefetchw(&v->counter);
1980
1981 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1982 -"1: ldrexd %0, %H0, [%3]\n"
1983 -" subs %Q0, %Q0, #1\n"
1984 -" sbc %R0, %R0, #0\n"
1985 +"1: ldrexd %1, %H1, [%3]\n"
1986 +" subs %Q0, %Q1, #1\n"
1987 +" sbcs %R0, %R1, #0\n"
1988 +
1989 +#ifdef CONFIG_PAX_REFCOUNT
1990 +" bvc 3f\n"
1991 +" mov %Q0, %Q1\n"
1992 +" mov %R0, %R1\n"
1993 +"2: bkpt 0xf103\n"
1994 +"3:\n"
1995 +#endif
1996 +
1997 " teq %R0, #0\n"
1998 -" bmi 2f\n"
1999 +" bmi 4f\n"
2000 " strexd %1, %0, %H0, [%3]\n"
2001 " teq %1, #0\n"
2002 " bne 1b\n"
2003 -"2:"
2004 +"4:\n"
2005 +
2006 +#ifdef CONFIG_PAX_REFCOUNT
2007 + _ASM_EXTABLE(2b, 4b)
2008 +#endif
2009 +
2010 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
2011 : "r" (&v->counter)
2012 : "cc");
2013 @@ -473,13 +885,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
2014 " teq %0, %5\n"
2015 " teqeq %H0, %H5\n"
2016 " moveq %1, #0\n"
2017 -" beq 2f\n"
2018 +" beq 4f\n"
2019 " adds %Q0, %Q0, %Q6\n"
2020 -" adc %R0, %R0, %R6\n"
2021 +" adcs %R0, %R0, %R6\n"
2022 +
2023 +#ifdef CONFIG_PAX_REFCOUNT
2024 +" bvc 3f\n"
2025 +"2: bkpt 0xf103\n"
2026 +"3:\n"
2027 +#endif
2028 +
2029 " strexd %2, %0, %H0, [%4]\n"
2030 " teq %2, #0\n"
2031 " bne 1b\n"
2032 -"2:"
2033 +"4:\n"
2034 +
2035 +#ifdef CONFIG_PAX_REFCOUNT
2036 + _ASM_EXTABLE(2b, 4b)
2037 +#endif
2038 +
2039 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
2040 : "r" (&v->counter), "r" (u), "r" (a)
2041 : "cc");
2042 @@ -492,10 +916,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
2043
2044 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
2045 #define atomic64_inc(v) atomic64_add(1LL, (v))
2046 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
2047 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
2048 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
2049 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
2050 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
2051 #define atomic64_dec(v) atomic64_sub(1LL, (v))
2052 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
2053 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
2054 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
2055 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
2056 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
2057 index c6a3e73..35cca85 100644
2058 --- a/arch/arm/include/asm/barrier.h
2059 +++ b/arch/arm/include/asm/barrier.h
2060 @@ -63,7 +63,7 @@
2061 do { \
2062 compiletime_assert_atomic_type(*p); \
2063 smp_mb(); \
2064 - ACCESS_ONCE(*p) = (v); \
2065 + ACCESS_ONCE_RW(*p) = (v); \
2066 } while (0)
2067
2068 #define smp_load_acquire(p) \
2069 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
2070 index 75fe66b..ba3dee4 100644
2071 --- a/arch/arm/include/asm/cache.h
2072 +++ b/arch/arm/include/asm/cache.h
2073 @@ -4,8 +4,10 @@
2074 #ifndef __ASMARM_CACHE_H
2075 #define __ASMARM_CACHE_H
2076
2077 +#include <linux/const.h>
2078 +
2079 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
2080 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2081 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2082
2083 /*
2084 * Memory returned by kmalloc() may be used for DMA, so we must make
2085 @@ -24,5 +26,6 @@
2086 #endif
2087
2088 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2089 +#define __read_only __attribute__ ((__section__(".data..read_only")))
2090
2091 #endif
2092 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
2093 index fd43f7f..a817f5a 100644
2094 --- a/arch/arm/include/asm/cacheflush.h
2095 +++ b/arch/arm/include/asm/cacheflush.h
2096 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
2097 void (*dma_unmap_area)(const void *, size_t, int);
2098
2099 void (*dma_flush_range)(const void *, const void *);
2100 -};
2101 +} __no_const;
2102
2103 /*
2104 * Select the calling method
2105 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
2106 index 5233151..87a71fa 100644
2107 --- a/arch/arm/include/asm/checksum.h
2108 +++ b/arch/arm/include/asm/checksum.h
2109 @@ -37,7 +37,19 @@ __wsum
2110 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
2111
2112 __wsum
2113 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
2114 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
2115 +
2116 +static inline __wsum
2117 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
2118 +{
2119 + __wsum ret;
2120 + pax_open_userland();
2121 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
2122 + pax_close_userland();
2123 + return ret;
2124 +}
2125 +
2126 +
2127
2128 /*
2129 * Fold a partial checksum without adding pseudo headers
2130 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
2131 index abb2c37..96db950 100644
2132 --- a/arch/arm/include/asm/cmpxchg.h
2133 +++ b/arch/arm/include/asm/cmpxchg.h
2134 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
2135
2136 #define xchg(ptr,x) \
2137 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
2138 +#define xchg_unchecked(ptr,x) \
2139 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
2140
2141 #include <asm-generic/cmpxchg-local.h>
2142
2143 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
2144 index 6ddbe44..b5e38b1 100644
2145 --- a/arch/arm/include/asm/domain.h
2146 +++ b/arch/arm/include/asm/domain.h
2147 @@ -48,18 +48,37 @@
2148 * Domain types
2149 */
2150 #define DOMAIN_NOACCESS 0
2151 -#define DOMAIN_CLIENT 1
2152 #ifdef CONFIG_CPU_USE_DOMAINS
2153 +#define DOMAIN_USERCLIENT 1
2154 +#define DOMAIN_KERNELCLIENT 1
2155 #define DOMAIN_MANAGER 3
2156 +#define DOMAIN_VECTORS DOMAIN_USER
2157 #else
2158 +
2159 +#ifdef CONFIG_PAX_KERNEXEC
2160 #define DOMAIN_MANAGER 1
2161 +#define DOMAIN_KERNEXEC 3
2162 +#else
2163 +#define DOMAIN_MANAGER 1
2164 +#endif
2165 +
2166 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2167 +#define DOMAIN_USERCLIENT 0
2168 +#define DOMAIN_UDEREF 1
2169 +#define DOMAIN_VECTORS DOMAIN_KERNEL
2170 +#else
2171 +#define DOMAIN_USERCLIENT 1
2172 +#define DOMAIN_VECTORS DOMAIN_USER
2173 +#endif
2174 +#define DOMAIN_KERNELCLIENT 1
2175 +
2176 #endif
2177
2178 #define domain_val(dom,type) ((type) << (2*(dom)))
2179
2180 #ifndef __ASSEMBLY__
2181
2182 -#ifdef CONFIG_CPU_USE_DOMAINS
2183 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2184 static inline void set_domain(unsigned val)
2185 {
2186 asm volatile(
2187 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
2188 isb();
2189 }
2190
2191 -#define modify_domain(dom,type) \
2192 - do { \
2193 - struct thread_info *thread = current_thread_info(); \
2194 - unsigned int domain = thread->cpu_domain; \
2195 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
2196 - thread->cpu_domain = domain | domain_val(dom, type); \
2197 - set_domain(thread->cpu_domain); \
2198 - } while (0)
2199 -
2200 +extern void modify_domain(unsigned int dom, unsigned int type);
2201 #else
2202 static inline void set_domain(unsigned val) { }
2203 static inline void modify_domain(unsigned dom, unsigned type) { }
2204 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
2205 index f4b46d3..abc9b2b 100644
2206 --- a/arch/arm/include/asm/elf.h
2207 +++ b/arch/arm/include/asm/elf.h
2208 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
2209 the loader. We need to make sure that it is out of the way of the program
2210 that it will "exec", and that there is sufficient room for the brk. */
2211
2212 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2213 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2214 +
2215 +#ifdef CONFIG_PAX_ASLR
2216 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
2217 +
2218 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
2219 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
2220 +#endif
2221
2222 /* When the program starts, a1 contains a pointer to a function to be
2223 registered with atexit, as per the SVR4 ABI. A value of 0 means we
2224 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
2225 extern void elf_set_personality(const struct elf32_hdr *);
2226 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
2227
2228 -struct mm_struct;
2229 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2230 -#define arch_randomize_brk arch_randomize_brk
2231 -
2232 #ifdef CONFIG_MMU
2233 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2234 struct linux_binprm;
2235 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
2236 index de53547..52b9a28 100644
2237 --- a/arch/arm/include/asm/fncpy.h
2238 +++ b/arch/arm/include/asm/fncpy.h
2239 @@ -81,7 +81,9 @@
2240 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
2241 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
2242 \
2243 + pax_open_kernel(); \
2244 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
2245 + pax_close_kernel(); \
2246 flush_icache_range((unsigned long)(dest_buf), \
2247 (unsigned long)(dest_buf) + (size)); \
2248 \
2249 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
2250 index 53e69da..3fdc896 100644
2251 --- a/arch/arm/include/asm/futex.h
2252 +++ b/arch/arm/include/asm/futex.h
2253 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
2254 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
2255 return -EFAULT;
2256
2257 + pax_open_userland();
2258 +
2259 smp_mb();
2260 /* Prefetching cannot fault */
2261 prefetchw(uaddr);
2262 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
2263 : "cc", "memory");
2264 smp_mb();
2265
2266 + pax_close_userland();
2267 +
2268 *uval = val;
2269 return ret;
2270 }
2271 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
2272 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
2273 return -EFAULT;
2274
2275 + pax_open_userland();
2276 +
2277 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
2278 "1: " TUSER(ldr) " %1, [%4]\n"
2279 " teq %1, %2\n"
2280 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
2281 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
2282 : "cc", "memory");
2283
2284 + pax_close_userland();
2285 +
2286 *uval = val;
2287 return ret;
2288 }
2289 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
2290 return -EFAULT;
2291
2292 pagefault_disable(); /* implies preempt_disable() */
2293 + pax_open_userland();
2294
2295 switch (op) {
2296 case FUTEX_OP_SET:
2297 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
2298 ret = -ENOSYS;
2299 }
2300
2301 + pax_close_userland();
2302 pagefault_enable(); /* subsumes preempt_enable() */
2303
2304 if (!ret) {
2305 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
2306 index 83eb2f7..ed77159 100644
2307 --- a/arch/arm/include/asm/kmap_types.h
2308 +++ b/arch/arm/include/asm/kmap_types.h
2309 @@ -4,6 +4,6 @@
2310 /*
2311 * This is the "bare minimum". AIO seems to require this.
2312 */
2313 -#define KM_TYPE_NR 16
2314 +#define KM_TYPE_NR 17
2315
2316 #endif
2317 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
2318 index 9e614a1..3302cca 100644
2319 --- a/arch/arm/include/asm/mach/dma.h
2320 +++ b/arch/arm/include/asm/mach/dma.h
2321 @@ -22,7 +22,7 @@ struct dma_ops {
2322 int (*residue)(unsigned int, dma_t *); /* optional */
2323 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
2324 const char *type;
2325 -};
2326 +} __do_const;
2327
2328 struct dma_struct {
2329 void *addr; /* single DMA address */
2330 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
2331 index f98c7f3..e5c626d 100644
2332 --- a/arch/arm/include/asm/mach/map.h
2333 +++ b/arch/arm/include/asm/mach/map.h
2334 @@ -23,17 +23,19 @@ struct map_desc {
2335
2336 /* types 0-3 are defined in asm/io.h */
2337 enum {
2338 - MT_UNCACHED = 4,
2339 - MT_CACHECLEAN,
2340 - MT_MINICLEAN,
2341 + MT_UNCACHED_RW = 4,
2342 + MT_CACHECLEAN_RO,
2343 + MT_MINICLEAN_RO,
2344 MT_LOW_VECTORS,
2345 MT_HIGH_VECTORS,
2346 - MT_MEMORY_RWX,
2347 + __MT_MEMORY_RWX,
2348 MT_MEMORY_RW,
2349 - MT_ROM,
2350 - MT_MEMORY_RWX_NONCACHED,
2351 + MT_MEMORY_RX,
2352 + MT_ROM_RX,
2353 + MT_MEMORY_RW_NONCACHED,
2354 + MT_MEMORY_RX_NONCACHED,
2355 MT_MEMORY_RW_DTCM,
2356 - MT_MEMORY_RWX_ITCM,
2357 + MT_MEMORY_RX_ITCM,
2358 MT_MEMORY_RW_SO,
2359 MT_MEMORY_DMA_READY,
2360 };
2361 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
2362 index 891a56b..48f337e 100644
2363 --- a/arch/arm/include/asm/outercache.h
2364 +++ b/arch/arm/include/asm/outercache.h
2365 @@ -36,7 +36,7 @@ struct outer_cache_fns {
2366
2367 /* This is an ARM L2C thing */
2368 void (*write_sec)(unsigned long, unsigned);
2369 -};
2370 +} __no_const;
2371
2372 extern struct outer_cache_fns outer_cache;
2373
2374 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
2375 index 4355f0e..cd9168e 100644
2376 --- a/arch/arm/include/asm/page.h
2377 +++ b/arch/arm/include/asm/page.h
2378 @@ -23,6 +23,7 @@
2379
2380 #else
2381
2382 +#include <linux/compiler.h>
2383 #include <asm/glue.h>
2384
2385 /*
2386 @@ -114,7 +115,7 @@ struct cpu_user_fns {
2387 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
2388 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
2389 unsigned long vaddr, struct vm_area_struct *vma);
2390 -};
2391 +} __no_const;
2392
2393 #ifdef MULTI_USER
2394 extern struct cpu_user_fns cpu_user;
2395 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
2396 index 78a7793..e3dc06c 100644
2397 --- a/arch/arm/include/asm/pgalloc.h
2398 +++ b/arch/arm/include/asm/pgalloc.h
2399 @@ -17,6 +17,7 @@
2400 #include <asm/processor.h>
2401 #include <asm/cacheflush.h>
2402 #include <asm/tlbflush.h>
2403 +#include <asm/system_info.h>
2404
2405 #define check_pgt_cache() do { } while (0)
2406
2407 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2408 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
2409 }
2410
2411 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2412 +{
2413 + pud_populate(mm, pud, pmd);
2414 +}
2415 +
2416 #else /* !CONFIG_ARM_LPAE */
2417
2418 /*
2419 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2420 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
2421 #define pmd_free(mm, pmd) do { } while (0)
2422 #define pud_populate(mm,pmd,pte) BUG()
2423 +#define pud_populate_kernel(mm,pmd,pte) BUG()
2424
2425 #endif /* CONFIG_ARM_LPAE */
2426
2427 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
2428 __free_page(pte);
2429 }
2430
2431 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
2432 +{
2433 +#ifdef CONFIG_ARM_LPAE
2434 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2435 +#else
2436 + if (addr & SECTION_SIZE)
2437 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
2438 + else
2439 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2440 +#endif
2441 + flush_pmd_entry(pmdp);
2442 +}
2443 +
2444 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
2445 pmdval_t prot)
2446 {
2447 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
2448 static inline void
2449 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
2450 {
2451 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
2452 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
2453 }
2454 #define pmd_pgtable(pmd) pmd_page(pmd)
2455
2456 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
2457 index 5cfba15..f415e1a 100644
2458 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
2459 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
2460 @@ -20,12 +20,15 @@
2461 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
2462 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
2463 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
2464 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
2465 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
2466 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
2467 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
2468 +
2469 /*
2470 * - section
2471 */
2472 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
2473 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
2474 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
2475 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
2476 @@ -37,6 +40,7 @@
2477 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
2478 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
2479 #define PMD_SECT_AF (_AT(pmdval_t, 0))
2480 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
2481
2482 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
2483 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
2484 @@ -66,6 +70,7 @@
2485 * - extended small page/tiny page
2486 */
2487 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
2488 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
2489 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
2490 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
2491 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
2492 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
2493 index 219ac88..73ec32a 100644
2494 --- a/arch/arm/include/asm/pgtable-2level.h
2495 +++ b/arch/arm/include/asm/pgtable-2level.h
2496 @@ -126,6 +126,9 @@
2497 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
2498 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
2499
2500 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2501 +#define L_PTE_PXN (_AT(pteval_t, 0))
2502 +
2503 /*
2504 * These are the memory types, defined to be compatible with
2505 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2506 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2507 index 626989f..9d67a33 100644
2508 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2509 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2510 @@ -75,6 +75,7 @@
2511 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2512 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2513 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2514 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2515 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2516
2517 /*
2518 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2519 index 85c60ad..b0bbd7e 100644
2520 --- a/arch/arm/include/asm/pgtable-3level.h
2521 +++ b/arch/arm/include/asm/pgtable-3level.h
2522 @@ -82,6 +82,7 @@
2523 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
2524 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2525 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2526 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2527 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2528 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2529 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2530 @@ -95,6 +96,7 @@
2531 /*
2532 * To be used in assembly code with the upper page attributes.
2533 */
2534 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2535 #define L_PTE_XN_HIGH (1 << (54 - 32))
2536 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2537
2538 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2539 index 5478e5d..f5b5cb3 100644
2540 --- a/arch/arm/include/asm/pgtable.h
2541 +++ b/arch/arm/include/asm/pgtable.h
2542 @@ -33,6 +33,9 @@
2543 #include <asm/pgtable-2level.h>
2544 #endif
2545
2546 +#define ktla_ktva(addr) (addr)
2547 +#define ktva_ktla(addr) (addr)
2548 +
2549 /*
2550 * Just any arbitrary offset to the start of the vmalloc VM area: the
2551 * current 8MB value just means that there will be a 8MB "hole" after the
2552 @@ -48,6 +51,9 @@
2553 #define LIBRARY_TEXT_START 0x0c000000
2554
2555 #ifndef __ASSEMBLY__
2556 +extern pteval_t __supported_pte_mask;
2557 +extern pmdval_t __supported_pmd_mask;
2558 +
2559 extern void __pte_error(const char *file, int line, pte_t);
2560 extern void __pmd_error(const char *file, int line, pmd_t);
2561 extern void __pgd_error(const char *file, int line, pgd_t);
2562 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2563 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2564 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2565
2566 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2567 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2568 +
2569 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2570 +#include <asm/domain.h>
2571 +#include <linux/thread_info.h>
2572 +#include <linux/preempt.h>
2573 +
2574 +static inline int test_domain(int domain, int domaintype)
2575 +{
2576 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2577 +}
2578 +#endif
2579 +
2580 +#ifdef CONFIG_PAX_KERNEXEC
2581 +static inline unsigned long pax_open_kernel(void) {
2582 +#ifdef CONFIG_ARM_LPAE
2583 + /* TODO */
2584 +#else
2585 + preempt_disable();
2586 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2587 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2588 +#endif
2589 + return 0;
2590 +}
2591 +
2592 +static inline unsigned long pax_close_kernel(void) {
2593 +#ifdef CONFIG_ARM_LPAE
2594 + /* TODO */
2595 +#else
2596 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2597 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2598 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2599 + preempt_enable_no_resched();
2600 +#endif
2601 + return 0;
2602 +}
2603 +#else
2604 +static inline unsigned long pax_open_kernel(void) { return 0; }
2605 +static inline unsigned long pax_close_kernel(void) { return 0; }
2606 +#endif
2607 +
2608 /*
2609 * This is the lowest virtual address we can permit any user space
2610 * mapping to be mapped at. This is particularly important for
2611 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2612 /*
2613 * The pgprot_* and protection_map entries will be fixed up in runtime
2614 * to include the cachable and bufferable bits based on memory policy,
2615 - * as well as any architecture dependent bits like global/ASID and SMP
2616 - * shared mapping bits.
2617 + * as well as any architecture dependent bits like global/ASID, PXN,
2618 + * and SMP shared mapping bits.
2619 */
2620 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2621
2622 @@ -265,7 +313,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2623 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2624 {
2625 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2626 - L_PTE_NONE | L_PTE_VALID;
2627 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2628 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2629 return pte;
2630 }
2631 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2632 index c25ef3e..735f14b 100644
2633 --- a/arch/arm/include/asm/psci.h
2634 +++ b/arch/arm/include/asm/psci.h
2635 @@ -32,7 +32,7 @@ struct psci_operations {
2636 int (*affinity_info)(unsigned long target_affinity,
2637 unsigned long lowest_affinity_level);
2638 int (*migrate_info_type)(void);
2639 -};
2640 +} __no_const;
2641
2642 extern struct psci_operations psci_ops;
2643 extern struct smp_operations psci_smp_ops;
2644 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2645 index 2ec765c..beb1fe16 100644
2646 --- a/arch/arm/include/asm/smp.h
2647 +++ b/arch/arm/include/asm/smp.h
2648 @@ -113,7 +113,7 @@ struct smp_operations {
2649 int (*cpu_disable)(unsigned int cpu);
2650 #endif
2651 #endif
2652 -};
2653 +} __no_const;
2654
2655 struct of_cpu_method {
2656 const char *method;
2657 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2658 index e4e4208..086684a 100644
2659 --- a/arch/arm/include/asm/thread_info.h
2660 +++ b/arch/arm/include/asm/thread_info.h
2661 @@ -88,9 +88,9 @@ struct thread_info {
2662 .flags = 0, \
2663 .preempt_count = INIT_PREEMPT_COUNT, \
2664 .addr_limit = KERNEL_DS, \
2665 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2666 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2667 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2668 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2669 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2670 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2671 .restart_block = { \
2672 .fn = do_no_restart_syscall, \
2673 }, \
2674 @@ -164,7 +164,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2675 #define TIF_SYSCALL_AUDIT 9
2676 #define TIF_SYSCALL_TRACEPOINT 10
2677 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2678 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2679 +/* within 8 bits of TIF_SYSCALL_TRACE
2680 + * to meet flexible second operand requirements
2681 + */
2682 +#define TIF_GRSEC_SETXID 12
2683 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2684 #define TIF_USING_IWMMXT 17
2685 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2686 #define TIF_RESTORE_SIGMASK 20
2687 @@ -178,10 +182,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2688 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2689 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2690 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2691 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2692
2693 /* Checks for any syscall work in entry-common.S */
2694 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2695 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2696 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2697
2698 /*
2699 * Change these and you break ASM code in entry-common.S
2700 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2701 index 75d9579..b5b40e4 100644
2702 --- a/arch/arm/include/asm/uaccess.h
2703 +++ b/arch/arm/include/asm/uaccess.h
2704 @@ -18,6 +18,7 @@
2705 #include <asm/domain.h>
2706 #include <asm/unified.h>
2707 #include <asm/compiler.h>
2708 +#include <asm/pgtable.h>
2709
2710 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2711 #include <asm-generic/uaccess-unaligned.h>
2712 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2713 static inline void set_fs(mm_segment_t fs)
2714 {
2715 current_thread_info()->addr_limit = fs;
2716 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2717 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2718 }
2719
2720 #define segment_eq(a,b) ((a) == (b))
2721
2722 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2723 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2724 +
2725 +static inline void pax_open_userland(void)
2726 +{
2727 +
2728 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2729 + if (segment_eq(get_fs(), USER_DS)) {
2730 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2731 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2732 + }
2733 +#endif
2734 +
2735 +}
2736 +
2737 +static inline void pax_close_userland(void)
2738 +{
2739 +
2740 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2741 + if (segment_eq(get_fs(), USER_DS)) {
2742 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2743 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2744 + }
2745 +#endif
2746 +
2747 +}
2748 +
2749 #define __addr_ok(addr) ({ \
2750 unsigned long flag; \
2751 __asm__("cmp %2, %0; movlo %0, #0" \
2752 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2753
2754 #define get_user(x,p) \
2755 ({ \
2756 + int __e; \
2757 might_fault(); \
2758 - __get_user_check(x,p); \
2759 + pax_open_userland(); \
2760 + __e = __get_user_check(x,p); \
2761 + pax_close_userland(); \
2762 + __e; \
2763 })
2764
2765 extern int __put_user_1(void *, unsigned int);
2766 @@ -196,8 +228,12 @@ extern int __put_user_8(void *, unsigned long long);
2767
2768 #define put_user(x,p) \
2769 ({ \
2770 + int __e; \
2771 might_fault(); \
2772 - __put_user_check(x,p); \
2773 + pax_open_userland(); \
2774 + __e = __put_user_check(x,p); \
2775 + pax_close_userland(); \
2776 + __e; \
2777 })
2778
2779 #else /* CONFIG_MMU */
2780 @@ -221,6 +257,7 @@ static inline void set_fs(mm_segment_t fs)
2781
2782 #endif /* CONFIG_MMU */
2783
2784 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2785 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2786
2787 #define user_addr_max() \
2788 @@ -238,13 +275,17 @@ static inline void set_fs(mm_segment_t fs)
2789 #define __get_user(x,ptr) \
2790 ({ \
2791 long __gu_err = 0; \
2792 + pax_open_userland(); \
2793 __get_user_err((x),(ptr),__gu_err); \
2794 + pax_close_userland(); \
2795 __gu_err; \
2796 })
2797
2798 #define __get_user_error(x,ptr,err) \
2799 ({ \
2800 + pax_open_userland(); \
2801 __get_user_err((x),(ptr),err); \
2802 + pax_close_userland(); \
2803 (void) 0; \
2804 })
2805
2806 @@ -320,13 +361,17 @@ do { \
2807 #define __put_user(x,ptr) \
2808 ({ \
2809 long __pu_err = 0; \
2810 + pax_open_userland(); \
2811 __put_user_err((x),(ptr),__pu_err); \
2812 + pax_close_userland(); \
2813 __pu_err; \
2814 })
2815
2816 #define __put_user_error(x,ptr,err) \
2817 ({ \
2818 + pax_open_userland(); \
2819 __put_user_err((x),(ptr),err); \
2820 + pax_close_userland(); \
2821 (void) 0; \
2822 })
2823
2824 @@ -426,11 +471,44 @@ do { \
2825
2826
2827 #ifdef CONFIG_MMU
2828 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2829 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2830 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2831 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2832 +
2833 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2834 +{
2835 + unsigned long ret;
2836 +
2837 + check_object_size(to, n, false);
2838 + pax_open_userland();
2839 + ret = ___copy_from_user(to, from, n);
2840 + pax_close_userland();
2841 + return ret;
2842 +}
2843 +
2844 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2845 +{
2846 + unsigned long ret;
2847 +
2848 + check_object_size(from, n, true);
2849 + pax_open_userland();
2850 + ret = ___copy_to_user(to, from, n);
2851 + pax_close_userland();
2852 + return ret;
2853 +}
2854 +
2855 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2856 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2857 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2858 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2859 +
2860 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2861 +{
2862 + unsigned long ret;
2863 + pax_open_userland();
2864 + ret = ___clear_user(addr, n);
2865 + pax_close_userland();
2866 + return ret;
2867 +}
2868 +
2869 #else
2870 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2871 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2872 @@ -439,6 +517,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2873
2874 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2875 {
2876 + if ((long)n < 0)
2877 + return n;
2878 +
2879 if (access_ok(VERIFY_READ, from, n))
2880 n = __copy_from_user(to, from, n);
2881 else /* security hole - plug it */
2882 @@ -448,6 +529,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2883
2884 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2885 {
2886 + if ((long)n < 0)
2887 + return n;
2888 +
2889 if (access_ok(VERIFY_WRITE, to, n))
2890 n = __copy_to_user(to, from, n);
2891 return n;
2892 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2893 index 5af0ed1..cea83883 100644
2894 --- a/arch/arm/include/uapi/asm/ptrace.h
2895 +++ b/arch/arm/include/uapi/asm/ptrace.h
2896 @@ -92,7 +92,7 @@
2897 * ARMv7 groups of PSR bits
2898 */
2899 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2900 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2901 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2902 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2903 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2904
2905 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2906 index f7b450f..f5364c5 100644
2907 --- a/arch/arm/kernel/armksyms.c
2908 +++ b/arch/arm/kernel/armksyms.c
2909 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2910
2911 /* networking */
2912 EXPORT_SYMBOL(csum_partial);
2913 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2914 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2915 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2916 EXPORT_SYMBOL(__csum_ipv6_magic);
2917
2918 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2919 #ifdef CONFIG_MMU
2920 EXPORT_SYMBOL(copy_page);
2921
2922 -EXPORT_SYMBOL(__copy_from_user);
2923 -EXPORT_SYMBOL(__copy_to_user);
2924 -EXPORT_SYMBOL(__clear_user);
2925 +EXPORT_SYMBOL(___copy_from_user);
2926 +EXPORT_SYMBOL(___copy_to_user);
2927 +EXPORT_SYMBOL(___clear_user);
2928
2929 EXPORT_SYMBOL(__get_user_1);
2930 EXPORT_SYMBOL(__get_user_2);
2931 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2932 index 52a949a..d8bbcab 100644
2933 --- a/arch/arm/kernel/entry-armv.S
2934 +++ b/arch/arm/kernel/entry-armv.S
2935 @@ -47,6 +47,87 @@
2936 9997:
2937 .endm
2938
2939 + .macro pax_enter_kernel
2940 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2941 + @ make aligned space for saved DACR
2942 + sub sp, sp, #8
2943 + @ save regs
2944 + stmdb sp!, {r1, r2}
2945 + @ read DACR from cpu_domain into r1
2946 + mov r2, sp
2947 + @ assume 8K pages, since we have to split the immediate in two
2948 + bic r2, r2, #(0x1fc0)
2949 + bic r2, r2, #(0x3f)
2950 + ldr r1, [r2, #TI_CPU_DOMAIN]
2951 + @ store old DACR on stack
2952 + str r1, [sp, #8]
2953 +#ifdef CONFIG_PAX_KERNEXEC
2954 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2955 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2956 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2957 +#endif
2958 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2959 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2960 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2961 +#endif
2962 + @ write r1 to current_thread_info()->cpu_domain
2963 + str r1, [r2, #TI_CPU_DOMAIN]
2964 + @ write r1 to DACR
2965 + mcr p15, 0, r1, c3, c0, 0
2966 + @ instruction sync
2967 + instr_sync
2968 + @ restore regs
2969 + ldmia sp!, {r1, r2}
2970 +#endif
2971 + .endm
2972 +
2973 + .macro pax_open_userland
2974 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2975 + @ save regs
2976 + stmdb sp!, {r0, r1}
2977 + @ read DACR from cpu_domain into r1
2978 + mov r0, sp
2979 + @ assume 8K pages, since we have to split the immediate in two
2980 + bic r0, r0, #(0x1fc0)
2981 + bic r0, r0, #(0x3f)
2982 + ldr r1, [r0, #TI_CPU_DOMAIN]
2983 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2984 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2985 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2986 + @ write r1 to current_thread_info()->cpu_domain
2987 + str r1, [r0, #TI_CPU_DOMAIN]
2988 + @ write r1 to DACR
2989 + mcr p15, 0, r1, c3, c0, 0
2990 + @ instruction sync
2991 + instr_sync
2992 + @ restore regs
2993 + ldmia sp!, {r0, r1}
2994 +#endif
2995 + .endm
2996 +
2997 + .macro pax_close_userland
2998 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2999 + @ save regs
3000 + stmdb sp!, {r0, r1}
3001 + @ read DACR from cpu_domain into r1
3002 + mov r0, sp
3003 + @ assume 8K pages, since we have to split the immediate in two
3004 + bic r0, r0, #(0x1fc0)
3005 + bic r0, r0, #(0x3f)
3006 + ldr r1, [r0, #TI_CPU_DOMAIN]
3007 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
3008 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
3009 + @ write r1 to current_thread_info()->cpu_domain
3010 + str r1, [r0, #TI_CPU_DOMAIN]
3011 + @ write r1 to DACR
3012 + mcr p15, 0, r1, c3, c0, 0
3013 + @ instruction sync
3014 + instr_sync
3015 + @ restore regs
3016 + ldmia sp!, {r0, r1}
3017 +#endif
3018 + .endm
3019 +
3020 .macro pabt_helper
3021 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
3022 #ifdef MULTI_PABORT
3023 @@ -89,11 +170,15 @@
3024 * Invalid mode handlers
3025 */
3026 .macro inv_entry, reason
3027 +
3028 + pax_enter_kernel
3029 +
3030 sub sp, sp, #S_FRAME_SIZE
3031 ARM( stmib sp, {r1 - lr} )
3032 THUMB( stmia sp, {r0 - r12} )
3033 THUMB( str sp, [sp, #S_SP] )
3034 THUMB( str lr, [sp, #S_LR] )
3035 +
3036 mov r1, #\reason
3037 .endm
3038
3039 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
3040 .macro svc_entry, stack_hole=0
3041 UNWIND(.fnstart )
3042 UNWIND(.save {r0 - pc} )
3043 +
3044 + pax_enter_kernel
3045 +
3046 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
3047 +
3048 #ifdef CONFIG_THUMB2_KERNEL
3049 SPFIX( str r0, [sp] ) @ temporarily saved
3050 SPFIX( mov r0, sp )
3051 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
3052 ldmia r0, {r3 - r5}
3053 add r7, sp, #S_SP - 4 @ here for interlock avoidance
3054 mov r6, #-1 @ "" "" "" ""
3055 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3056 + @ offset sp by 8 as done in pax_enter_kernel
3057 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
3058 +#else
3059 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
3060 +#endif
3061 SPFIX( addeq r2, r2, #4 )
3062 str r3, [sp, #-4]! @ save the "real" r0 copied
3063 @ from the exception stack
3064 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
3065 .macro usr_entry
3066 UNWIND(.fnstart )
3067 UNWIND(.cantunwind ) @ don't unwind the user space
3068 +
3069 + pax_enter_kernel_user
3070 +
3071 sub sp, sp, #S_FRAME_SIZE
3072 ARM( stmib sp, {r1 - r12} )
3073 THUMB( stmia sp, {r0 - r12} )
3074 @@ -421,7 +518,9 @@ __und_usr:
3075 tst r3, #PSR_T_BIT @ Thumb mode?
3076 bne __und_usr_thumb
3077 sub r4, r2, #4 @ ARM instr at LR - 4
3078 + pax_open_userland
3079 1: ldrt r0, [r4]
3080 + pax_close_userland
3081 ARM_BE8(rev r0, r0) @ little endian instruction
3082
3083 @ r0 = 32-bit ARM instruction which caused the exception
3084 @@ -455,11 +554,15 @@ __und_usr_thumb:
3085 */
3086 .arch armv6t2
3087 #endif
3088 + pax_open_userland
3089 2: ldrht r5, [r4]
3090 + pax_close_userland
3091 ARM_BE8(rev16 r5, r5) @ little endian instruction
3092 cmp r5, #0xe800 @ 32bit instruction if xx != 0
3093 blo __und_usr_fault_16 @ 16bit undefined instruction
3094 + pax_open_userland
3095 3: ldrht r0, [r2]
3096 + pax_close_userland
3097 ARM_BE8(rev16 r0, r0) @ little endian instruction
3098 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
3099 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
3100 @@ -489,7 +592,8 @@ ENDPROC(__und_usr)
3101 */
3102 .pushsection .fixup, "ax"
3103 .align 2
3104 -4: str r4, [sp, #S_PC] @ retry current instruction
3105 +4: pax_close_userland
3106 + str r4, [sp, #S_PC] @ retry current instruction
3107 mov pc, r9
3108 .popsection
3109 .pushsection __ex_table,"a"
3110 @@ -698,7 +802,7 @@ ENTRY(__switch_to)
3111 THUMB( str lr, [ip], #4 )
3112 ldr r4, [r2, #TI_TP_VALUE]
3113 ldr r5, [r2, #TI_TP_VALUE + 4]
3114 -#ifdef CONFIG_CPU_USE_DOMAINS
3115 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3116 ldr r6, [r2, #TI_CPU_DOMAIN]
3117 #endif
3118 switch_tls r1, r4, r5, r3, r7
3119 @@ -707,7 +811,7 @@ ENTRY(__switch_to)
3120 ldr r8, =__stack_chk_guard
3121 ldr r7, [r7, #TSK_STACK_CANARY]
3122 #endif
3123 -#ifdef CONFIG_CPU_USE_DOMAINS
3124 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3125 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
3126 #endif
3127 mov r5, r0
3128 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
3129 index 7139d4a..feaf37f 100644
3130 --- a/arch/arm/kernel/entry-common.S
3131 +++ b/arch/arm/kernel/entry-common.S
3132 @@ -10,18 +10,46 @@
3133
3134 #include <asm/unistd.h>
3135 #include <asm/ftrace.h>
3136 +#include <asm/domain.h>
3137 #include <asm/unwind.h>
3138
3139 +#include "entry-header.S"
3140 +
3141 #ifdef CONFIG_NEED_RET_TO_USER
3142 #include <mach/entry-macro.S>
3143 #else
3144 .macro arch_ret_to_user, tmp1, tmp2
3145 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3146 + @ save regs
3147 + stmdb sp!, {r1, r2}
3148 + @ read DACR from cpu_domain into r1
3149 + mov r2, sp
3150 + @ assume 8K pages, since we have to split the immediate in two
3151 + bic r2, r2, #(0x1fc0)
3152 + bic r2, r2, #(0x3f)
3153 + ldr r1, [r2, #TI_CPU_DOMAIN]
3154 +#ifdef CONFIG_PAX_KERNEXEC
3155 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
3156 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
3157 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
3158 +#endif
3159 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3160 + @ set current DOMAIN_USER to DOMAIN_UDEREF
3161 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
3162 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
3163 +#endif
3164 + @ write r1 to current_thread_info()->cpu_domain
3165 + str r1, [r2, #TI_CPU_DOMAIN]
3166 + @ write r1 to DACR
3167 + mcr p15, 0, r1, c3, c0, 0
3168 + @ instruction sync
3169 + instr_sync
3170 + @ restore regs
3171 + ldmia sp!, {r1, r2}
3172 +#endif
3173 .endm
3174 #endif
3175
3176 -#include "entry-header.S"
3177 -
3178 -
3179 .align 5
3180 /*
3181 * This is the fast syscall return path. We do as little as
3182 @@ -405,6 +433,12 @@ ENTRY(vector_swi)
3183 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
3184 #endif
3185
3186 + /*
3187 + * do this here to avoid a performance hit of wrapping the code above
3188 + * that directly dereferences userland to parse the SWI instruction
3189 + */
3190 + pax_enter_kernel_user
3191 +
3192 adr tbl, sys_call_table @ load syscall table pointer
3193
3194 #if defined(CONFIG_OABI_COMPAT)
3195 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
3196 index 5d702f8..f5fc51a 100644
3197 --- a/arch/arm/kernel/entry-header.S
3198 +++ b/arch/arm/kernel/entry-header.S
3199 @@ -188,6 +188,60 @@
3200 msr cpsr_c, \rtemp @ switch back to the SVC mode
3201 .endm
3202
3203 + .macro pax_enter_kernel_user
3204 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3205 + @ save regs
3206 + stmdb sp!, {r0, r1}
3207 + @ read DACR from cpu_domain into r1
3208 + mov r0, sp
3209 + @ assume 8K pages, since we have to split the immediate in two
3210 + bic r0, r0, #(0x1fc0)
3211 + bic r0, r0, #(0x3f)
3212 + ldr r1, [r0, #TI_CPU_DOMAIN]
3213 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3214 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
3215 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
3216 +#endif
3217 +#ifdef CONFIG_PAX_KERNEXEC
3218 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
3219 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
3220 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
3221 +#endif
3222 + @ write r1 to current_thread_info()->cpu_domain
3223 + str r1, [r0, #TI_CPU_DOMAIN]
3224 + @ write r1 to DACR
3225 + mcr p15, 0, r1, c3, c0, 0
3226 + @ instruction sync
3227 + instr_sync
3228 + @ restore regs
3229 + ldmia sp!, {r0, r1}
3230 +#endif
3231 + .endm
3232 +
3233 + .macro pax_exit_kernel
3234 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3235 + @ save regs
3236 + stmdb sp!, {r0, r1}
3237 + @ read old DACR from stack into r1
3238 + ldr r1, [sp, #(8 + S_SP)]
3239 + sub r1, r1, #8
3240 + ldr r1, [r1]
3241 +
3242 + @ write r1 to current_thread_info()->cpu_domain
3243 + mov r0, sp
3244 + @ assume 8K pages, since we have to split the immediate in two
3245 + bic r0, r0, #(0x1fc0)
3246 + bic r0, r0, #(0x3f)
3247 + str r1, [r0, #TI_CPU_DOMAIN]
3248 + @ write r1 to DACR
3249 + mcr p15, 0, r1, c3, c0, 0
3250 + @ instruction sync
3251 + instr_sync
3252 + @ restore regs
3253 + ldmia sp!, {r0, r1}
3254 +#endif
3255 + .endm
3256 +
3257 #ifndef CONFIG_THUMB2_KERNEL
3258 .macro svc_exit, rpsr, irq = 0
3259 .if \irq != 0
3260 @@ -207,6 +261,9 @@
3261 blne trace_hardirqs_off
3262 #endif
3263 .endif
3264 +
3265 + pax_exit_kernel
3266 +
3267 msr spsr_cxsf, \rpsr
3268 #if defined(CONFIG_CPU_V6)
3269 ldr r0, [sp]
3270 @@ -265,6 +322,9 @@
3271 blne trace_hardirqs_off
3272 #endif
3273 .endif
3274 +
3275 + pax_exit_kernel
3276 +
3277 ldr lr, [sp, #S_SP] @ top of the stack
3278 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
3279 clrex @ clear the exclusive monitor
3280 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
3281 index 918875d..cd5fa27 100644
3282 --- a/arch/arm/kernel/fiq.c
3283 +++ b/arch/arm/kernel/fiq.c
3284 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
3285 void *base = vectors_page;
3286 unsigned offset = FIQ_OFFSET;
3287
3288 + pax_open_kernel();
3289 memcpy(base + offset, start, length);
3290 + pax_close_kernel();
3291 +
3292 if (!cache_is_vipt_nonaliasing())
3293 flush_icache_range((unsigned long)base + offset, offset +
3294 length);
3295 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
3296 index 2c35f0f..7747ee6 100644
3297 --- a/arch/arm/kernel/head.S
3298 +++ b/arch/arm/kernel/head.S
3299 @@ -437,7 +437,7 @@ __enable_mmu:
3300 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
3301 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
3302 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
3303 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
3304 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
3305 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
3306 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
3307 #endif
3308 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
3309 index 45e4781..8eac93d 100644
3310 --- a/arch/arm/kernel/module.c
3311 +++ b/arch/arm/kernel/module.c
3312 @@ -38,12 +38,39 @@
3313 #endif
3314
3315 #ifdef CONFIG_MMU
3316 -void *module_alloc(unsigned long size)
3317 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
3318 {
3319 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
3320 + return NULL;
3321 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
3322 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
3323 + GFP_KERNEL, prot, NUMA_NO_NODE,
3324 __builtin_return_address(0));
3325 }
3326 +
3327 +void *module_alloc(unsigned long size)
3328 +{
3329 +
3330 +#ifdef CONFIG_PAX_KERNEXEC
3331 + return __module_alloc(size, PAGE_KERNEL);
3332 +#else
3333 + return __module_alloc(size, PAGE_KERNEL_EXEC);
3334 +#endif
3335 +
3336 +}
3337 +
3338 +#ifdef CONFIG_PAX_KERNEXEC
3339 +void module_free_exec(struct module *mod, void *module_region)
3340 +{
3341 + module_free(mod, module_region);
3342 +}
3343 +EXPORT_SYMBOL(module_free_exec);
3344 +
3345 +void *module_alloc_exec(unsigned long size)
3346 +{
3347 + return __module_alloc(size, PAGE_KERNEL_EXEC);
3348 +}
3349 +EXPORT_SYMBOL(module_alloc_exec);
3350 +#endif
3351 #endif
3352
3353 int
3354 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
3355 index 07314af..c46655c 100644
3356 --- a/arch/arm/kernel/patch.c
3357 +++ b/arch/arm/kernel/patch.c
3358 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
3359 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
3360 int size;
3361
3362 + pax_open_kernel();
3363 if (thumb2 && __opcode_is_thumb16(insn)) {
3364 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
3365 size = sizeof(u16);
3366 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
3367 *(u32 *)addr = insn;
3368 size = sizeof(u32);
3369 }
3370 + pax_close_kernel();
3371
3372 flush_icache_range((uintptr_t)(addr),
3373 (uintptr_t)(addr) + size);
3374 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
3375 index 81ef686..f4130b8 100644
3376 --- a/arch/arm/kernel/process.c
3377 +++ b/arch/arm/kernel/process.c
3378 @@ -212,6 +212,7 @@ void machine_power_off(void)
3379
3380 if (pm_power_off)
3381 pm_power_off();
3382 + BUG();
3383 }
3384
3385 /*
3386 @@ -225,7 +226,7 @@ void machine_power_off(void)
3387 * executing pre-reset code, and using RAM that the primary CPU's code wishes
3388 * to use. Implementing such co-ordination would be essentially impossible.
3389 */
3390 -void machine_restart(char *cmd)
3391 +__noreturn void machine_restart(char *cmd)
3392 {
3393 local_irq_disable();
3394 smp_send_stop();
3395 @@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
3396
3397 show_regs_print_info(KERN_DEFAULT);
3398
3399 - print_symbol("PC is at %s\n", instruction_pointer(regs));
3400 - print_symbol("LR is at %s\n", regs->ARM_lr);
3401 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
3402 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
3403 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
3404 "sp : %08lx ip : %08lx fp : %08lx\n",
3405 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
3406 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
3407 return 0;
3408 }
3409
3410 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3411 -{
3412 - unsigned long range_end = mm->brk + 0x02000000;
3413 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
3414 -}
3415 -
3416 #ifdef CONFIG_MMU
3417 #ifdef CONFIG_KUSER_HELPERS
3418 /*
3419 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
3420
3421 static int __init gate_vma_init(void)
3422 {
3423 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
3424 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
3425 return 0;
3426 }
3427 arch_initcall(gate_vma_init);
3428 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
3429
3430 const char *arch_vma_name(struct vm_area_struct *vma)
3431 {
3432 - return is_gate_vma(vma) ? "[vectors]" :
3433 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
3434 - "[sigpage]" : NULL;
3435 + return is_gate_vma(vma) ? "[vectors]" : NULL;
3436 }
3437
3438 -static struct page *signal_page;
3439 -extern struct page *get_signal_page(void);
3440 -
3441 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3442 {
3443 struct mm_struct *mm = current->mm;
3444 - unsigned long addr;
3445 - int ret;
3446 -
3447 - if (!signal_page)
3448 - signal_page = get_signal_page();
3449 - if (!signal_page)
3450 - return -ENOMEM;
3451
3452 down_write(&mm->mmap_sem);
3453 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
3454 - if (IS_ERR_VALUE(addr)) {
3455 - ret = addr;
3456 - goto up_fail;
3457 - }
3458 -
3459 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
3460 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
3461 - &signal_page);
3462 -
3463 - if (ret == 0)
3464 - mm->context.sigpage = addr;
3465 -
3466 - up_fail:
3467 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3468 up_write(&mm->mmap_sem);
3469 - return ret;
3470 + return 0;
3471 }
3472 #endif
3473 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3474 index f73891b..cf3004e 100644
3475 --- a/arch/arm/kernel/psci.c
3476 +++ b/arch/arm/kernel/psci.c
3477 @@ -28,7 +28,7 @@
3478 #include <asm/psci.h>
3479 #include <asm/system_misc.h>
3480
3481 -struct psci_operations psci_ops;
3482 +struct psci_operations psci_ops __read_only;
3483
3484 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3485 typedef int (*psci_initcall_t)(const struct device_node *);
3486 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3487 index 0c27ed6..b67388e 100644
3488 --- a/arch/arm/kernel/ptrace.c
3489 +++ b/arch/arm/kernel/ptrace.c
3490 @@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3491 regs->ARM_ip = ip;
3492 }
3493
3494 +#ifdef CONFIG_GRKERNSEC_SETXID
3495 +extern void gr_delayed_cred_worker(void);
3496 +#endif
3497 +
3498 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3499 {
3500 current_thread_info()->syscall = scno;
3501
3502 +#ifdef CONFIG_GRKERNSEC_SETXID
3503 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3504 + gr_delayed_cred_worker();
3505 +#endif
3506 +
3507 /* Do the secure computing check first; failures should be fast. */
3508 if (secure_computing(scno) == -1)
3509 return -1;
3510 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3511 index 8a16ee5..4f560e5 100644
3512 --- a/arch/arm/kernel/setup.c
3513 +++ b/arch/arm/kernel/setup.c
3514 @@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3515 unsigned int elf_hwcap2 __read_mostly;
3516 EXPORT_SYMBOL(elf_hwcap2);
3517
3518 +pteval_t __supported_pte_mask __read_only;
3519 +pmdval_t __supported_pmd_mask __read_only;
3520
3521 #ifdef MULTI_CPU
3522 -struct processor processor __read_mostly;
3523 +struct processor processor __read_only;
3524 #endif
3525 #ifdef MULTI_TLB
3526 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3527 +struct cpu_tlb_fns cpu_tlb __read_only;
3528 #endif
3529 #ifdef MULTI_USER
3530 -struct cpu_user_fns cpu_user __read_mostly;
3531 +struct cpu_user_fns cpu_user __read_only;
3532 #endif
3533 #ifdef MULTI_CACHE
3534 -struct cpu_cache_fns cpu_cache __read_mostly;
3535 +struct cpu_cache_fns cpu_cache __read_only;
3536 #endif
3537 #ifdef CONFIG_OUTER_CACHE
3538 -struct outer_cache_fns outer_cache __read_mostly;
3539 +struct outer_cache_fns outer_cache __read_only;
3540 EXPORT_SYMBOL(outer_cache);
3541 #endif
3542
3543 @@ -251,9 +253,13 @@ static int __get_cpu_architecture(void)
3544 asm("mrc p15, 0, %0, c0, c1, 4"
3545 : "=r" (mmfr0));
3546 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3547 - (mmfr0 & 0x000000f0) >= 0x00000030)
3548 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3549 cpu_arch = CPU_ARCH_ARMv7;
3550 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3551 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3552 + __supported_pte_mask |= L_PTE_PXN;
3553 + __supported_pmd_mask |= PMD_PXNTABLE;
3554 + }
3555 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3556 (mmfr0 & 0x000000f0) == 0x00000020)
3557 cpu_arch = CPU_ARCH_ARMv6;
3558 else
3559 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3560 index bd19834..e4d8c66 100644
3561 --- a/arch/arm/kernel/signal.c
3562 +++ b/arch/arm/kernel/signal.c
3563 @@ -24,8 +24,6 @@
3564
3565 extern const unsigned long sigreturn_codes[7];
3566
3567 -static unsigned long signal_return_offset;
3568 -
3569 #ifdef CONFIG_CRUNCH
3570 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3571 {
3572 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3573 * except when the MPU has protected the vectors
3574 * page from PL0
3575 */
3576 - retcode = mm->context.sigpage + signal_return_offset +
3577 - (idx << 2) + thumb;
3578 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3579 } else
3580 #endif
3581 {
3582 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3583 } while (thread_flags & _TIF_WORK_MASK);
3584 return 0;
3585 }
3586 -
3587 -struct page *get_signal_page(void)
3588 -{
3589 - unsigned long ptr;
3590 - unsigned offset;
3591 - struct page *page;
3592 - void *addr;
3593 -
3594 - page = alloc_pages(GFP_KERNEL, 0);
3595 -
3596 - if (!page)
3597 - return NULL;
3598 -
3599 - addr = page_address(page);
3600 -
3601 - /* Give the signal return code some randomness */
3602 - offset = 0x200 + (get_random_int() & 0x7fc);
3603 - signal_return_offset = offset;
3604 -
3605 - /*
3606 - * Copy signal return handlers into the vector page, and
3607 - * set sigreturn to be a pointer to these.
3608 - */
3609 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3610 -
3611 - ptr = (unsigned long)addr + offset;
3612 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3613 -
3614 - return page;
3615 -}
3616 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3617 index 7c4fada..8581286 100644
3618 --- a/arch/arm/kernel/smp.c
3619 +++ b/arch/arm/kernel/smp.c
3620 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3621
3622 static DECLARE_COMPLETION(cpu_running);
3623
3624 -static struct smp_operations smp_ops;
3625 +static struct smp_operations smp_ops __read_only;
3626
3627 void __init smp_set_ops(struct smp_operations *ops)
3628 {
3629 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3630 index 7a3be1d..b00c7de 100644
3631 --- a/arch/arm/kernel/tcm.c
3632 +++ b/arch/arm/kernel/tcm.c
3633 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3634 .virtual = ITCM_OFFSET,
3635 .pfn = __phys_to_pfn(ITCM_OFFSET),
3636 .length = 0,
3637 - .type = MT_MEMORY_RWX_ITCM,
3638 + .type = MT_MEMORY_RX_ITCM,
3639 }
3640 };
3641
3642 @@ -267,7 +267,9 @@ no_dtcm:
3643 start = &__sitcm_text;
3644 end = &__eitcm_text;
3645 ram = &__itcm_start;
3646 + pax_open_kernel();
3647 memcpy(start, ram, itcm_code_sz);
3648 + pax_close_kernel();
3649 pr_debug("CPU ITCM: copied code from %p - %p\n",
3650 start, end);
3651 itcm_present = true;
3652 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3653 index abd2fc0..895dbb6 100644
3654 --- a/arch/arm/kernel/traps.c
3655 +++ b/arch/arm/kernel/traps.c
3656 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3657 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3658 {
3659 #ifdef CONFIG_KALLSYMS
3660 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3661 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3662 #else
3663 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3664 #endif
3665 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3666 static int die_owner = -1;
3667 static unsigned int die_nest_count;
3668
3669 +extern void gr_handle_kernel_exploit(void);
3670 +
3671 static unsigned long oops_begin(void)
3672 {
3673 int cpu;
3674 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3675 panic("Fatal exception in interrupt");
3676 if (panic_on_oops)
3677 panic("Fatal exception");
3678 +
3679 + gr_handle_kernel_exploit();
3680 +
3681 if (signr)
3682 do_exit(signr);
3683 }
3684 @@ -643,7 +648,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3685 * The user helper at 0xffff0fe0 must be used instead.
3686 * (see entry-armv.S for details)
3687 */
3688 + pax_open_kernel();
3689 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3690 + pax_close_kernel();
3691 }
3692 return 0;
3693
3694 @@ -900,7 +907,11 @@ void __init early_trap_init(void *vectors_base)
3695 kuser_init(vectors_base);
3696
3697 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3698 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3699 +
3700 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3701 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3702 +#endif
3703 +
3704 #else /* ifndef CONFIG_CPU_V7M */
3705 /*
3706 * on V7-M there is no need to copy the vector table to a dedicated
3707 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3708 index 7bcee5c..e2f3249 100644
3709 --- a/arch/arm/kernel/vmlinux.lds.S
3710 +++ b/arch/arm/kernel/vmlinux.lds.S
3711 @@ -8,7 +8,11 @@
3712 #include <asm/thread_info.h>
3713 #include <asm/memory.h>
3714 #include <asm/page.h>
3715 -
3716 +
3717 +#ifdef CONFIG_PAX_KERNEXEC
3718 +#include <asm/pgtable.h>
3719 +#endif
3720 +
3721 #define PROC_INFO \
3722 . = ALIGN(4); \
3723 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3724 @@ -34,7 +38,7 @@
3725 #endif
3726
3727 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3728 - defined(CONFIG_GENERIC_BUG)
3729 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3730 #define ARM_EXIT_KEEP(x) x
3731 #define ARM_EXIT_DISCARD(x)
3732 #else
3733 @@ -90,6 +94,11 @@ SECTIONS
3734 _text = .;
3735 HEAD_TEXT
3736 }
3737 +
3738 +#ifdef CONFIG_PAX_KERNEXEC
3739 + . = ALIGN(1<<SECTION_SHIFT);
3740 +#endif
3741 +
3742 .text : { /* Real text segment */
3743 _stext = .; /* Text and read-only data */
3744 __exception_text_start = .;
3745 @@ -112,6 +121,8 @@ SECTIONS
3746 ARM_CPU_KEEP(PROC_INFO)
3747 }
3748
3749 + _etext = .; /* End of text section */
3750 +
3751 RO_DATA(PAGE_SIZE)
3752
3753 . = ALIGN(4);
3754 @@ -142,7 +153,9 @@ SECTIONS
3755
3756 NOTES
3757
3758 - _etext = .; /* End of text and rodata section */
3759 +#ifdef CONFIG_PAX_KERNEXEC
3760 + . = ALIGN(1<<SECTION_SHIFT);
3761 +#endif
3762
3763 #ifndef CONFIG_XIP_KERNEL
3764 . = ALIGN(PAGE_SIZE);
3765 @@ -220,6 +233,11 @@ SECTIONS
3766 . = PAGE_OFFSET + TEXT_OFFSET;
3767 #else
3768 __init_end = .;
3769 +
3770 +#ifdef CONFIG_PAX_KERNEXEC
3771 + . = ALIGN(1<<SECTION_SHIFT);
3772 +#endif
3773 +
3774 . = ALIGN(THREAD_SIZE);
3775 __data_loc = .;
3776 #endif
3777 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3778 index 3c82b37..69fa3d2 100644
3779 --- a/arch/arm/kvm/arm.c
3780 +++ b/arch/arm/kvm/arm.c
3781 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3782 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3783
3784 /* The VMID used in the VTTBR */
3785 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3786 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3787 static u8 kvm_next_vmid;
3788 static DEFINE_SPINLOCK(kvm_vmid_lock);
3789
3790 @@ -409,7 +409,7 @@ void force_vm_exit(const cpumask_t *mask)
3791 */
3792 static bool need_new_vmid_gen(struct kvm *kvm)
3793 {
3794 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3795 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3796 }
3797
3798 /**
3799 @@ -442,7 +442,7 @@ static void update_vttbr(struct kvm *kvm)
3800
3801 /* First user of a new VMID generation? */
3802 if (unlikely(kvm_next_vmid == 0)) {
3803 - atomic64_inc(&kvm_vmid_gen);
3804 + atomic64_inc_unchecked(&kvm_vmid_gen);
3805 kvm_next_vmid = 1;
3806
3807 /*
3808 @@ -459,7 +459,7 @@ static void update_vttbr(struct kvm *kvm)
3809 kvm_call_hyp(__kvm_flush_vm_context);
3810 }
3811
3812 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3813 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3814 kvm->arch.vmid = kvm_next_vmid;
3815 kvm_next_vmid++;
3816
3817 @@ -1034,7 +1034,7 @@ static void check_kvm_target_cpu(void *ret)
3818 /**
3819 * Initialize Hyp-mode and memory mappings on all CPUs.
3820 */
3821 -int kvm_arch_init(void *opaque)
3822 +int kvm_arch_init(const void *opaque)
3823 {
3824 int err;
3825 int ret, cpu;
3826 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3827 index 14a0d98..7771a7d 100644
3828 --- a/arch/arm/lib/clear_user.S
3829 +++ b/arch/arm/lib/clear_user.S
3830 @@ -12,14 +12,14 @@
3831
3832 .text
3833
3834 -/* Prototype: int __clear_user(void *addr, size_t sz)
3835 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3836 * Purpose : clear some user memory
3837 * Params : addr - user memory address to clear
3838 * : sz - number of bytes to clear
3839 * Returns : number of bytes NOT cleared
3840 */
3841 ENTRY(__clear_user_std)
3842 -WEAK(__clear_user)
3843 +WEAK(___clear_user)
3844 stmfd sp!, {r1, lr}
3845 mov r2, #0
3846 cmp r1, #4
3847 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3848 USER( strnebt r2, [r0])
3849 mov r0, #0
3850 ldmfd sp!, {r1, pc}
3851 -ENDPROC(__clear_user)
3852 +ENDPROC(___clear_user)
3853 ENDPROC(__clear_user_std)
3854
3855 .pushsection .fixup,"ax"
3856 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3857 index 66a477a..bee61d3 100644
3858 --- a/arch/arm/lib/copy_from_user.S
3859 +++ b/arch/arm/lib/copy_from_user.S
3860 @@ -16,7 +16,7 @@
3861 /*
3862 * Prototype:
3863 *
3864 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3865 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3866 *
3867 * Purpose:
3868 *
3869 @@ -84,11 +84,11 @@
3870
3871 .text
3872
3873 -ENTRY(__copy_from_user)
3874 +ENTRY(___copy_from_user)
3875
3876 #include "copy_template.S"
3877
3878 -ENDPROC(__copy_from_user)
3879 +ENDPROC(___copy_from_user)
3880
3881 .pushsection .fixup,"ax"
3882 .align 0
3883 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3884 index 6ee2f67..d1cce76 100644
3885 --- a/arch/arm/lib/copy_page.S
3886 +++ b/arch/arm/lib/copy_page.S
3887 @@ -10,6 +10,7 @@
3888 * ASM optimised string functions
3889 */
3890 #include <linux/linkage.h>
3891 +#include <linux/const.h>
3892 #include <asm/assembler.h>
3893 #include <asm/asm-offsets.h>
3894 #include <asm/cache.h>
3895 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3896 index d066df6..df28194 100644
3897 --- a/arch/arm/lib/copy_to_user.S
3898 +++ b/arch/arm/lib/copy_to_user.S
3899 @@ -16,7 +16,7 @@
3900 /*
3901 * Prototype:
3902 *
3903 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3904 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3905 *
3906 * Purpose:
3907 *
3908 @@ -88,11 +88,11 @@
3909 .text
3910
3911 ENTRY(__copy_to_user_std)
3912 -WEAK(__copy_to_user)
3913 +WEAK(___copy_to_user)
3914
3915 #include "copy_template.S"
3916
3917 -ENDPROC(__copy_to_user)
3918 +ENDPROC(___copy_to_user)
3919 ENDPROC(__copy_to_user_std)
3920
3921 .pushsection .fixup,"ax"
3922 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3923 index 7d08b43..f7ca7ea 100644
3924 --- a/arch/arm/lib/csumpartialcopyuser.S
3925 +++ b/arch/arm/lib/csumpartialcopyuser.S
3926 @@ -57,8 +57,8 @@
3927 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3928 */
3929
3930 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3931 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3932 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3933 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3934
3935 #include "csumpartialcopygeneric.S"
3936
3937 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3938 index 5306de3..aed6d03 100644
3939 --- a/arch/arm/lib/delay.c
3940 +++ b/arch/arm/lib/delay.c
3941 @@ -28,7 +28,7 @@
3942 /*
3943 * Default to the loop-based delay implementation.
3944 */
3945 -struct arm_delay_ops arm_delay_ops = {
3946 +struct arm_delay_ops arm_delay_ops __read_only = {
3947 .delay = __loop_delay,
3948 .const_udelay = __loop_const_udelay,
3949 .udelay = __loop_udelay,
3950 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3951 index 3e58d71..029817c 100644
3952 --- a/arch/arm/lib/uaccess_with_memcpy.c
3953 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3954 @@ -136,7 +136,7 @@ out:
3955 }
3956
3957 unsigned long
3958 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3959 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3960 {
3961 /*
3962 * This test is stubbed out of the main function above to keep
3963 @@ -190,7 +190,7 @@ out:
3964 return n;
3965 }
3966
3967 -unsigned long __clear_user(void __user *addr, unsigned long n)
3968 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3969 {
3970 /* See rational for this in __copy_to_user() above. */
3971 if (n < 64)
3972 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3973 index f7a07a5..258e1f7 100644
3974 --- a/arch/arm/mach-at91/setup.c
3975 +++ b/arch/arm/mach-at91/setup.c
3976 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3977
3978 desc->pfn = __phys_to_pfn(base);
3979 desc->length = length;
3980 - desc->type = MT_MEMORY_RWX_NONCACHED;
3981 + desc->type = MT_MEMORY_RW_NONCACHED;
3982
3983 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3984 base, length, desc->virtual);
3985 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3986 index 255f33a..507b157 100644
3987 --- a/arch/arm/mach-kirkwood/common.c
3988 +++ b/arch/arm/mach-kirkwood/common.c
3989 @@ -157,7 +157,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3990 clk_gate_ops.disable(hw);
3991 }
3992
3993 -static struct clk_ops clk_gate_fn_ops;
3994 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3995 +{
3996 + return clk_gate_ops.is_enabled(hw);
3997 +}
3998 +
3999 +static struct clk_ops clk_gate_fn_ops = {
4000 + .enable = clk_gate_fn_enable,
4001 + .disable = clk_gate_fn_disable,
4002 + .is_enabled = clk_gate_fn_is_enabled,
4003 +};
4004
4005 static struct clk __init *clk_register_gate_fn(struct device *dev,
4006 const char *name,
4007 @@ -191,14 +200,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
4008 gate_fn->fn_en = fn_en;
4009 gate_fn->fn_dis = fn_dis;
4010
4011 - /* ops is the gate ops, but with our enable/disable functions */
4012 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
4013 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
4014 - clk_gate_fn_ops = clk_gate_ops;
4015 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
4016 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
4017 - }
4018 -
4019 clk = clk_register(dev, &gate_fn->gate.hw);
4020
4021 if (IS_ERR(clk))
4022 diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
4023 index 2bdc323..cf1c607 100644
4024 --- a/arch/arm/mach-mvebu/coherency.c
4025 +++ b/arch/arm/mach-mvebu/coherency.c
4026 @@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
4027
4028 /*
4029 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
4030 - * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
4031 + * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
4032 * is needed as a workaround for a deadlock issue between the PCIe
4033 * interface and the cache controller.
4034 */
4035 @@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
4036 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
4037
4038 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
4039 - mtype = MT_UNCACHED;
4040 + mtype = MT_UNCACHED_RW;
4041
4042 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
4043 }
4044 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
4045 index aead77a..a2253fa 100644
4046 --- a/arch/arm/mach-omap2/board-n8x0.c
4047 +++ b/arch/arm/mach-omap2/board-n8x0.c
4048 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
4049 }
4050 #endif
4051
4052 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
4053 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
4054 .late_init = n8x0_menelaus_late_init,
4055 };
4056
4057 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
4058 index 8bc1338..8b28b69 100644
4059 --- a/arch/arm/mach-omap2/gpmc.c
4060 +++ b/arch/arm/mach-omap2/gpmc.c
4061 @@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
4062 };
4063
4064 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
4065 -static struct irq_chip gpmc_irq_chip;
4066 static int gpmc_irq_start;
4067
4068 static struct resource gpmc_mem_root;
4069 @@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
4070
4071 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
4072
4073 +static struct irq_chip gpmc_irq_chip = {
4074 + .name = "gpmc",
4075 + .irq_startup = gpmc_irq_noop_ret,
4076 + .irq_enable = gpmc_irq_enable,
4077 + .irq_disable = gpmc_irq_disable,
4078 + .irq_shutdown = gpmc_irq_noop,
4079 + .irq_ack = gpmc_irq_noop,
4080 + .irq_mask = gpmc_irq_noop,
4081 + .irq_unmask = gpmc_irq_noop,
4082 +
4083 +};
4084 +
4085 static int gpmc_setup_irq(void)
4086 {
4087 int i;
4088 @@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
4089 return gpmc_irq_start;
4090 }
4091
4092 - gpmc_irq_chip.name = "gpmc";
4093 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
4094 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
4095 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
4096 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
4097 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
4098 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
4099 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
4100 -
4101 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
4102 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
4103
4104 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
4105 index 4001325..b14e2a0 100644
4106 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
4107 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
4108 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
4109 int (*finish_suspend)(unsigned long cpu_state);
4110 void (*resume)(void);
4111 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
4112 -};
4113 +} __no_const;
4114
4115 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
4116 static struct powerdomain *mpuss_pd;
4117 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
4118 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
4119 {}
4120
4121 -struct cpu_pm_ops omap_pm_ops = {
4122 +static struct cpu_pm_ops omap_pm_ops __read_only = {
4123 .finish_suspend = default_finish_suspend,
4124 .resume = dummy_cpu_resume,
4125 .scu_prepare = dummy_scu_prepare,
4126 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
4127 index 37843a7..a98df13 100644
4128 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
4129 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
4130 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
4131 return NOTIFY_OK;
4132 }
4133
4134 -static struct notifier_block __refdata irq_hotplug_notifier = {
4135 +static struct notifier_block irq_hotplug_notifier = {
4136 .notifier_call = irq_cpu_hotplug_notify,
4137 };
4138
4139 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
4140 index 01ef59d..32ae28a8 100644
4141 --- a/arch/arm/mach-omap2/omap_device.c
4142 +++ b/arch/arm/mach-omap2/omap_device.c
4143 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
4144 struct platform_device __init *omap_device_build(const char *pdev_name,
4145 int pdev_id,
4146 struct omap_hwmod *oh,
4147 - void *pdata, int pdata_len)
4148 + const void *pdata, int pdata_len)
4149 {
4150 struct omap_hwmod *ohs[] = { oh };
4151
4152 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
4153 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
4154 int pdev_id,
4155 struct omap_hwmod **ohs,
4156 - int oh_cnt, void *pdata,
4157 + int oh_cnt, const void *pdata,
4158 int pdata_len)
4159 {
4160 int ret = -ENOMEM;
4161 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
4162 index 78c02b3..c94109a 100644
4163 --- a/arch/arm/mach-omap2/omap_device.h
4164 +++ b/arch/arm/mach-omap2/omap_device.h
4165 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
4166 /* Core code interface */
4167
4168 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
4169 - struct omap_hwmod *oh, void *pdata,
4170 + struct omap_hwmod *oh, const void *pdata,
4171 int pdata_len);
4172
4173 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
4174 struct omap_hwmod **oh, int oh_cnt,
4175 - void *pdata, int pdata_len);
4176 + const void *pdata, int pdata_len);
4177
4178 struct omap_device *omap_device_alloc(struct platform_device *pdev,
4179 struct omap_hwmod **ohs, int oh_cnt);
4180 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
4181 index da1b256..ab2a327 100644
4182 --- a/arch/arm/mach-omap2/omap_hwmod.c
4183 +++ b/arch/arm/mach-omap2/omap_hwmod.c
4184 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
4185 int (*init_clkdm)(struct omap_hwmod *oh);
4186 void (*update_context_lost)(struct omap_hwmod *oh);
4187 int (*get_context_lost)(struct omap_hwmod *oh);
4188 -};
4189 +} __no_const;
4190
4191 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
4192 -static struct omap_hwmod_soc_ops soc_ops;
4193 +static struct omap_hwmod_soc_ops soc_ops __read_only;
4194
4195 /* omap_hwmod_list contains all registered struct omap_hwmods */
4196 static LIST_HEAD(omap_hwmod_list);
4197 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
4198 index 95fee54..cfa9cf1 100644
4199 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
4200 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
4201 @@ -10,6 +10,7 @@
4202
4203 #include <linux/kernel.h>
4204 #include <linux/init.h>
4205 +#include <asm/pgtable.h>
4206
4207 #include "powerdomain.h"
4208
4209 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
4210
4211 void __init am43xx_powerdomains_init(void)
4212 {
4213 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
4214 + pax_open_kernel();
4215 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
4216 + pax_close_kernel();
4217 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
4218 pwrdm_register_pwrdms(powerdomains_am43xx);
4219 pwrdm_complete_init();
4220 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
4221 index 97d6607..8429d14 100644
4222 --- a/arch/arm/mach-omap2/wd_timer.c
4223 +++ b/arch/arm/mach-omap2/wd_timer.c
4224 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
4225 struct omap_hwmod *oh;
4226 char *oh_name = "wd_timer2";
4227 char *dev_name = "omap_wdt";
4228 - struct omap_wd_timer_platform_data pdata;
4229 + static struct omap_wd_timer_platform_data pdata = {
4230 + .read_reset_sources = prm_read_reset_sources
4231 + };
4232
4233 if (!cpu_class_is_omap2() || of_have_populated_dt())
4234 return 0;
4235 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
4236 return -EINVAL;
4237 }
4238
4239 - pdata.read_reset_sources = prm_read_reset_sources;
4240 -
4241 pdev = omap_device_build(dev_name, id, oh, &pdata,
4242 sizeof(struct omap_wd_timer_platform_data));
4243 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
4244 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
4245 index b82dcae..44ee5b6 100644
4246 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
4247 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
4248 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
4249 bool entered_lp2 = false;
4250
4251 if (tegra_pending_sgi())
4252 - ACCESS_ONCE(abort_flag) = true;
4253 + ACCESS_ONCE_RW(abort_flag) = true;
4254
4255 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
4256
4257 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
4258 index 2dea8b5..6499da2 100644
4259 --- a/arch/arm/mach-ux500/setup.h
4260 +++ b/arch/arm/mach-ux500/setup.h
4261 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
4262 .type = MT_DEVICE, \
4263 }
4264
4265 -#define __MEM_DEV_DESC(x, sz) { \
4266 - .virtual = IO_ADDRESS(x), \
4267 - .pfn = __phys_to_pfn(x), \
4268 - .length = sz, \
4269 - .type = MT_MEMORY_RWX, \
4270 -}
4271 -
4272 extern struct smp_operations ux500_smp_ops;
4273 extern void ux500_cpu_die(unsigned int cpu);
4274
4275 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
4276 index c348eae..456a1a4 100644
4277 --- a/arch/arm/mm/Kconfig
4278 +++ b/arch/arm/mm/Kconfig
4279 @@ -446,6 +446,7 @@ config CPU_32v5
4280
4281 config CPU_32v6
4282 bool
4283 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
4284 select TLS_REG_EMUL if !CPU_32v6K && !MMU
4285
4286 config CPU_32v6K
4287 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
4288
4289 config CPU_USE_DOMAINS
4290 bool
4291 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
4292 help
4293 This option enables or disables the use of domain switching
4294 via the set_fs() function.
4295 @@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
4296 config KUSER_HELPERS
4297 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
4298 default y
4299 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
4300 help
4301 Warning: disabling this option may break user programs.
4302
4303 @@ -811,7 +814,7 @@ config KUSER_HELPERS
4304 See Documentation/arm/kernel_user_helpers.txt for details.
4305
4306 However, the fixed address nature of these helpers can be used
4307 - by ROP (return orientated programming) authors when creating
4308 + by ROP (Return Oriented Programming) authors when creating
4309 exploits.
4310
4311 If all of the binaries and libraries which run on your platform
4312 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
4313 index b8cb1a2..6a5624a 100644
4314 --- a/arch/arm/mm/alignment.c
4315 +++ b/arch/arm/mm/alignment.c
4316 @@ -214,10 +214,12 @@ union offset_union {
4317 #define __get16_unaligned_check(ins,val,addr) \
4318 do { \
4319 unsigned int err = 0, v, a = addr; \
4320 + pax_open_userland(); \
4321 __get8_unaligned_check(ins,v,a,err); \
4322 val = v << ((BE) ? 8 : 0); \
4323 __get8_unaligned_check(ins,v,a,err); \
4324 val |= v << ((BE) ? 0 : 8); \
4325 + pax_close_userland(); \
4326 if (err) \
4327 goto fault; \
4328 } while (0)
4329 @@ -231,6 +233,7 @@ union offset_union {
4330 #define __get32_unaligned_check(ins,val,addr) \
4331 do { \
4332 unsigned int err = 0, v, a = addr; \
4333 + pax_open_userland(); \
4334 __get8_unaligned_check(ins,v,a,err); \
4335 val = v << ((BE) ? 24 : 0); \
4336 __get8_unaligned_check(ins,v,a,err); \
4337 @@ -239,6 +242,7 @@ union offset_union {
4338 val |= v << ((BE) ? 8 : 16); \
4339 __get8_unaligned_check(ins,v,a,err); \
4340 val |= v << ((BE) ? 0 : 24); \
4341 + pax_close_userland(); \
4342 if (err) \
4343 goto fault; \
4344 } while (0)
4345 @@ -252,6 +256,7 @@ union offset_union {
4346 #define __put16_unaligned_check(ins,val,addr) \
4347 do { \
4348 unsigned int err = 0, v = val, a = addr; \
4349 + pax_open_userland(); \
4350 __asm__( FIRST_BYTE_16 \
4351 ARM( "1: "ins" %1, [%2], #1\n" ) \
4352 THUMB( "1: "ins" %1, [%2]\n" ) \
4353 @@ -271,6 +276,7 @@ union offset_union {
4354 " .popsection\n" \
4355 : "=r" (err), "=&r" (v), "=&r" (a) \
4356 : "0" (err), "1" (v), "2" (a)); \
4357 + pax_close_userland(); \
4358 if (err) \
4359 goto fault; \
4360 } while (0)
4361 @@ -284,6 +290,7 @@ union offset_union {
4362 #define __put32_unaligned_check(ins,val,addr) \
4363 do { \
4364 unsigned int err = 0, v = val, a = addr; \
4365 + pax_open_userland(); \
4366 __asm__( FIRST_BYTE_32 \
4367 ARM( "1: "ins" %1, [%2], #1\n" ) \
4368 THUMB( "1: "ins" %1, [%2]\n" ) \
4369 @@ -313,6 +320,7 @@ union offset_union {
4370 " .popsection\n" \
4371 : "=r" (err), "=&r" (v), "=&r" (a) \
4372 : "0" (err), "1" (v), "2" (a)); \
4373 + pax_close_userland(); \
4374 if (err) \
4375 goto fault; \
4376 } while (0)
4377 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
4378 index 7c3fb41..bfb87d8 100644
4379 --- a/arch/arm/mm/cache-l2x0.c
4380 +++ b/arch/arm/mm/cache-l2x0.c
4381 @@ -41,7 +41,7 @@ struct l2c_init_data {
4382 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
4383 void (*save)(void __iomem *);
4384 struct outer_cache_fns outer_cache;
4385 -};
4386 +} __do_const;
4387
4388 #define CACHE_LINE_SIZE 32
4389
4390 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
4391 index 6eb97b3..ac509f6 100644
4392 --- a/arch/arm/mm/context.c
4393 +++ b/arch/arm/mm/context.c
4394 @@ -43,7 +43,7 @@
4395 #define NUM_USER_ASIDS ASID_FIRST_VERSION
4396
4397 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
4398 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4399 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4400 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
4401
4402 static DEFINE_PER_CPU(atomic64_t, active_asids);
4403 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4404 {
4405 static u32 cur_idx = 1;
4406 u64 asid = atomic64_read(&mm->context.id);
4407 - u64 generation = atomic64_read(&asid_generation);
4408 + u64 generation = atomic64_read_unchecked(&asid_generation);
4409
4410 if (asid != 0 && is_reserved_asid(asid)) {
4411 /*
4412 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4413 */
4414 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
4415 if (asid == NUM_USER_ASIDS) {
4416 - generation = atomic64_add_return(ASID_FIRST_VERSION,
4417 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
4418 &asid_generation);
4419 flush_context(cpu);
4420 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
4421 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
4422 cpu_set_reserved_ttbr0();
4423
4424 asid = atomic64_read(&mm->context.id);
4425 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
4426 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
4427 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
4428 goto switch_mm_fastpath;
4429
4430 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
4431 /* Check that our ASID belongs to the current generation. */
4432 asid = atomic64_read(&mm->context.id);
4433 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
4434 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
4435 asid = new_context(mm, cpu);
4436 atomic64_set(&mm->context.id, asid);
4437 }
4438 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
4439 index eb8830a..5360ce7 100644
4440 --- a/arch/arm/mm/fault.c
4441 +++ b/arch/arm/mm/fault.c
4442 @@ -25,6 +25,7 @@
4443 #include <asm/system_misc.h>
4444 #include <asm/system_info.h>
4445 #include <asm/tlbflush.h>
4446 +#include <asm/sections.h>
4447
4448 #include "fault.h"
4449
4450 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
4451 if (fixup_exception(regs))
4452 return;
4453
4454 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4455 + if (addr < TASK_SIZE) {
4456 + if (current->signal->curr_ip)
4457 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4458 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4459 + else
4460 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4461 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4462 + }
4463 +#endif
4464 +
4465 +#ifdef CONFIG_PAX_KERNEXEC
4466 + if ((fsr & FSR_WRITE) &&
4467 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
4468 + (MODULES_VADDR <= addr && addr < MODULES_END)))
4469 + {
4470 + if (current->signal->curr_ip)
4471 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4472 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4473 + else
4474 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
4475 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4476 + }
4477 +#endif
4478 +
4479 /*
4480 * No handler, we'll have to terminate things with extreme prejudice.
4481 */
4482 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
4483 }
4484 #endif
4485
4486 +#ifdef CONFIG_PAX_PAGEEXEC
4487 + if (fsr & FSR_LNX_PF) {
4488 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
4489 + do_group_exit(SIGKILL);
4490 + }
4491 +#endif
4492 +
4493 tsk->thread.address = addr;
4494 tsk->thread.error_code = fsr;
4495 tsk->thread.trap_no = 14;
4496 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4497 }
4498 #endif /* CONFIG_MMU */
4499
4500 +#ifdef CONFIG_PAX_PAGEEXEC
4501 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4502 +{
4503 + long i;
4504 +
4505 + printk(KERN_ERR "PAX: bytes at PC: ");
4506 + for (i = 0; i < 20; i++) {
4507 + unsigned char c;
4508 + if (get_user(c, (__force unsigned char __user *)pc+i))
4509 + printk(KERN_CONT "?? ");
4510 + else
4511 + printk(KERN_CONT "%02x ", c);
4512 + }
4513 + printk("\n");
4514 +
4515 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4516 + for (i = -1; i < 20; i++) {
4517 + unsigned long c;
4518 + if (get_user(c, (__force unsigned long __user *)sp+i))
4519 + printk(KERN_CONT "???????? ");
4520 + else
4521 + printk(KERN_CONT "%08lx ", c);
4522 + }
4523 + printk("\n");
4524 +}
4525 +#endif
4526 +
4527 /*
4528 * First Level Translation Fault Handler
4529 *
4530 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4531 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4532 struct siginfo info;
4533
4534 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4535 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4536 + if (current->signal->curr_ip)
4537 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4538 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4539 + else
4540 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4541 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4542 + goto die;
4543 + }
4544 +#endif
4545 +
4546 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4547 return;
4548
4549 +die:
4550 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4551 inf->name, fsr, addr);
4552
4553 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4554 ifsr_info[nr].name = name;
4555 }
4556
4557 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4558 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4559 +
4560 asmlinkage void __exception
4561 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4562 {
4563 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4564 struct siginfo info;
4565 + unsigned long pc = instruction_pointer(regs);
4566 +
4567 + if (user_mode(regs)) {
4568 + unsigned long sigpage = current->mm->context.sigpage;
4569 +
4570 + if (sigpage <= pc && pc < sigpage + 7*4) {
4571 + if (pc < sigpage + 3*4)
4572 + sys_sigreturn(regs);
4573 + else
4574 + sys_rt_sigreturn(regs);
4575 + return;
4576 + }
4577 + if (pc == 0xffff0f60UL) {
4578 + /*
4579 + * PaX: __kuser_cmpxchg64 emulation
4580 + */
4581 + // TODO
4582 + //regs->ARM_pc = regs->ARM_lr;
4583 + //return;
4584 + }
4585 + if (pc == 0xffff0fa0UL) {
4586 + /*
4587 + * PaX: __kuser_memory_barrier emulation
4588 + */
4589 + // dmb(); implied by the exception
4590 + regs->ARM_pc = regs->ARM_lr;
4591 + return;
4592 + }
4593 + if (pc == 0xffff0fc0UL) {
4594 + /*
4595 + * PaX: __kuser_cmpxchg emulation
4596 + */
4597 + // TODO
4598 + //long new;
4599 + //int op;
4600 +
4601 + //op = FUTEX_OP_SET << 28;
4602 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4603 + //regs->ARM_r0 = old != new;
4604 + //regs->ARM_pc = regs->ARM_lr;
4605 + //return;
4606 + }
4607 + if (pc == 0xffff0fe0UL) {
4608 + /*
4609 + * PaX: __kuser_get_tls emulation
4610 + */
4611 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4612 + regs->ARM_pc = regs->ARM_lr;
4613 + return;
4614 + }
4615 + }
4616 +
4617 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4618 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4619 + if (current->signal->curr_ip)
4620 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4621 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4622 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4623 + else
4624 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4625 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4626 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4627 + goto die;
4628 + }
4629 +#endif
4630 +
4631 +#ifdef CONFIG_PAX_REFCOUNT
4632 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4633 + unsigned int bkpt;
4634 +
4635 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4636 + current->thread.error_code = ifsr;
4637 + current->thread.trap_no = 0;
4638 + pax_report_refcount_overflow(regs);
4639 + fixup_exception(regs);
4640 + return;
4641 + }
4642 + }
4643 +#endif
4644
4645 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4646 return;
4647
4648 +die:
4649 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4650 inf->name, ifsr, addr);
4651
4652 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4653 index cf08bdf..772656c 100644
4654 --- a/arch/arm/mm/fault.h
4655 +++ b/arch/arm/mm/fault.h
4656 @@ -3,6 +3,7 @@
4657
4658 /*
4659 * Fault status register encodings. We steal bit 31 for our own purposes.
4660 + * Set when the FSR value is from an instruction fault.
4661 */
4662 #define FSR_LNX_PF (1 << 31)
4663 #define FSR_WRITE (1 << 11)
4664 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4665 }
4666 #endif
4667
4668 +/* valid for LPAE and !LPAE */
4669 +static inline int is_xn_fault(unsigned int fsr)
4670 +{
4671 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4672 +}
4673 +
4674 +static inline int is_domain_fault(unsigned int fsr)
4675 +{
4676 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4677 +}
4678 +
4679 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4680 unsigned long search_exception_table(unsigned long addr);
4681
4682 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4683 index 659c75d..6f8c029 100644
4684 --- a/arch/arm/mm/init.c
4685 +++ b/arch/arm/mm/init.c
4686 @@ -31,6 +31,8 @@
4687 #include <asm/setup.h>
4688 #include <asm/tlb.h>
4689 #include <asm/fixmap.h>
4690 +#include <asm/system_info.h>
4691 +#include <asm/cp15.h>
4692
4693 #include <asm/mach/arch.h>
4694 #include <asm/mach/map.h>
4695 @@ -619,7 +621,46 @@ void free_initmem(void)
4696 {
4697 #ifdef CONFIG_HAVE_TCM
4698 extern char __tcm_start, __tcm_end;
4699 +#endif
4700
4701 +#ifdef CONFIG_PAX_KERNEXEC
4702 + unsigned long addr;
4703 + pgd_t *pgd;
4704 + pud_t *pud;
4705 + pmd_t *pmd;
4706 + int cpu_arch = cpu_architecture();
4707 + unsigned int cr = get_cr();
4708 +
4709 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4710 + /* make pages tables, etc before .text NX */
4711 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4712 + pgd = pgd_offset_k(addr);
4713 + pud = pud_offset(pgd, addr);
4714 + pmd = pmd_offset(pud, addr);
4715 + __section_update(pmd, addr, PMD_SECT_XN);
4716 + }
4717 + /* make init NX */
4718 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4719 + pgd = pgd_offset_k(addr);
4720 + pud = pud_offset(pgd, addr);
4721 + pmd = pmd_offset(pud, addr);
4722 + __section_update(pmd, addr, PMD_SECT_XN);
4723 + }
4724 + /* make kernel code/rodata RX */
4725 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4726 + pgd = pgd_offset_k(addr);
4727 + pud = pud_offset(pgd, addr);
4728 + pmd = pmd_offset(pud, addr);
4729 +#ifdef CONFIG_ARM_LPAE
4730 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4731 +#else
4732 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4733 +#endif
4734 + }
4735 + }
4736 +#endif
4737 +
4738 +#ifdef CONFIG_HAVE_TCM
4739 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4740 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4741 #endif
4742 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4743 index d1e5ad7..84dcbf2 100644
4744 --- a/arch/arm/mm/ioremap.c
4745 +++ b/arch/arm/mm/ioremap.c
4746 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4747 unsigned int mtype;
4748
4749 if (cached)
4750 - mtype = MT_MEMORY_RWX;
4751 + mtype = MT_MEMORY_RX;
4752 else
4753 - mtype = MT_MEMORY_RWX_NONCACHED;
4754 + mtype = MT_MEMORY_RX_NONCACHED;
4755
4756 return __arm_ioremap_caller(phys_addr, size, mtype,
4757 __builtin_return_address(0));
4758 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4759 index 5e85ed3..b10a7ed 100644
4760 --- a/arch/arm/mm/mmap.c
4761 +++ b/arch/arm/mm/mmap.c
4762 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4763 struct vm_area_struct *vma;
4764 int do_align = 0;
4765 int aliasing = cache_is_vipt_aliasing();
4766 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4767 struct vm_unmapped_area_info info;
4768
4769 /*
4770 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4771 if (len > TASK_SIZE)
4772 return -ENOMEM;
4773
4774 +#ifdef CONFIG_PAX_RANDMMAP
4775 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4776 +#endif
4777 +
4778 if (addr) {
4779 if (do_align)
4780 addr = COLOUR_ALIGN(addr, pgoff);
4781 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4782 addr = PAGE_ALIGN(addr);
4783
4784 vma = find_vma(mm, addr);
4785 - if (TASK_SIZE - len >= addr &&
4786 - (!vma || addr + len <= vma->vm_start))
4787 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4788 return addr;
4789 }
4790
4791 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4792 info.high_limit = TASK_SIZE;
4793 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4794 info.align_offset = pgoff << PAGE_SHIFT;
4795 + info.threadstack_offset = offset;
4796 return vm_unmapped_area(&info);
4797 }
4798
4799 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4800 unsigned long addr = addr0;
4801 int do_align = 0;
4802 int aliasing = cache_is_vipt_aliasing();
4803 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4804 struct vm_unmapped_area_info info;
4805
4806 /*
4807 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4808 return addr;
4809 }
4810
4811 +#ifdef CONFIG_PAX_RANDMMAP
4812 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4813 +#endif
4814 +
4815 /* requesting a specific address */
4816 if (addr) {
4817 if (do_align)
4818 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4819 else
4820 addr = PAGE_ALIGN(addr);
4821 vma = find_vma(mm, addr);
4822 - if (TASK_SIZE - len >= addr &&
4823 - (!vma || addr + len <= vma->vm_start))
4824 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4825 return addr;
4826 }
4827
4828 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4829 info.high_limit = mm->mmap_base;
4830 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4831 info.align_offset = pgoff << PAGE_SHIFT;
4832 + info.threadstack_offset = offset;
4833 addr = vm_unmapped_area(&info);
4834
4835 /*
4836 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4837 {
4838 unsigned long random_factor = 0UL;
4839
4840 +#ifdef CONFIG_PAX_RANDMMAP
4841 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4842 +#endif
4843 +
4844 /* 8 bits of randomness in 20 address space bits */
4845 if ((current->flags & PF_RANDOMIZE) &&
4846 !(current->personality & ADDR_NO_RANDOMIZE))
4847 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4848
4849 if (mmap_is_legacy()) {
4850 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4851 +
4852 +#ifdef CONFIG_PAX_RANDMMAP
4853 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4854 + mm->mmap_base += mm->delta_mmap;
4855 +#endif
4856 +
4857 mm->get_unmapped_area = arch_get_unmapped_area;
4858 } else {
4859 mm->mmap_base = mmap_base(random_factor);
4860 +
4861 +#ifdef CONFIG_PAX_RANDMMAP
4862 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4863 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4864 +#endif
4865 +
4866 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4867 }
4868 }
4869 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4870 index 6e3ba8d..9cbb4d7 100644
4871 --- a/arch/arm/mm/mmu.c
4872 +++ b/arch/arm/mm/mmu.c
4873 @@ -40,6 +40,22 @@
4874 #include "mm.h"
4875 #include "tcm.h"
4876
4877 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4878 +void modify_domain(unsigned int dom, unsigned int type)
4879 +{
4880 + struct thread_info *thread = current_thread_info();
4881 + unsigned int domain = thread->cpu_domain;
4882 + /*
4883 + * DOMAIN_MANAGER might be defined to some other value,
4884 + * use the arch-defined constant
4885 + */
4886 + domain &= ~domain_val(dom, 3);
4887 + thread->cpu_domain = domain | domain_val(dom, type);
4888 + set_domain(thread->cpu_domain);
4889 +}
4890 +EXPORT_SYMBOL(modify_domain);
4891 +#endif
4892 +
4893 /*
4894 * empty_zero_page is a special page that is used for
4895 * zero-initialized data and COW.
4896 @@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4897 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4898 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4899
4900 -static struct mem_type mem_types[] = {
4901 +#ifdef CONFIG_PAX_KERNEXEC
4902 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4903 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4904 +#else
4905 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4906 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4907 +#endif
4908 +
4909 +static struct mem_type mem_types[] __read_only = {
4910 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4911 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4912 L_PTE_SHARED,
4913 @@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4914 .prot_sect = PROT_SECT_DEVICE,
4915 .domain = DOMAIN_IO,
4916 },
4917 - [MT_UNCACHED] = {
4918 + [MT_UNCACHED_RW] = {
4919 .prot_pte = PROT_PTE_DEVICE,
4920 .prot_l1 = PMD_TYPE_TABLE,
4921 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4922 .domain = DOMAIN_IO,
4923 },
4924 - [MT_CACHECLEAN] = {
4925 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4926 + [MT_CACHECLEAN_RO] = {
4927 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4928 .domain = DOMAIN_KERNEL,
4929 },
4930 #ifndef CONFIG_ARM_LPAE
4931 - [MT_MINICLEAN] = {
4932 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4933 + [MT_MINICLEAN_RO] = {
4934 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4935 .domain = DOMAIN_KERNEL,
4936 },
4937 #endif
4938 @@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4939 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4940 L_PTE_RDONLY,
4941 .prot_l1 = PMD_TYPE_TABLE,
4942 - .domain = DOMAIN_USER,
4943 + .domain = DOMAIN_VECTORS,
4944 },
4945 [MT_HIGH_VECTORS] = {
4946 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4947 L_PTE_USER | L_PTE_RDONLY,
4948 .prot_l1 = PMD_TYPE_TABLE,
4949 - .domain = DOMAIN_USER,
4950 + .domain = DOMAIN_VECTORS,
4951 },
4952 - [MT_MEMORY_RWX] = {
4953 + [__MT_MEMORY_RWX] = {
4954 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4955 .prot_l1 = PMD_TYPE_TABLE,
4956 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4957 @@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4958 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4959 .domain = DOMAIN_KERNEL,
4960 },
4961 - [MT_ROM] = {
4962 - .prot_sect = PMD_TYPE_SECT,
4963 + [MT_MEMORY_RX] = {
4964 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4965 + .prot_l1 = PMD_TYPE_TABLE,
4966 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4967 + .domain = DOMAIN_KERNEL,
4968 + },
4969 + [MT_ROM_RX] = {
4970 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4971 .domain = DOMAIN_KERNEL,
4972 },
4973 - [MT_MEMORY_RWX_NONCACHED] = {
4974 + [MT_MEMORY_RW_NONCACHED] = {
4975 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4976 L_PTE_MT_BUFFERABLE,
4977 .prot_l1 = PMD_TYPE_TABLE,
4978 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4979 .domain = DOMAIN_KERNEL,
4980 },
4981 + [MT_MEMORY_RX_NONCACHED] = {
4982 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4983 + L_PTE_MT_BUFFERABLE,
4984 + .prot_l1 = PMD_TYPE_TABLE,
4985 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4986 + .domain = DOMAIN_KERNEL,
4987 + },
4988 [MT_MEMORY_RW_DTCM] = {
4989 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4990 L_PTE_XN,
4991 @@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4992 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4993 .domain = DOMAIN_KERNEL,
4994 },
4995 - [MT_MEMORY_RWX_ITCM] = {
4996 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4997 + [MT_MEMORY_RX_ITCM] = {
4998 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4999 .prot_l1 = PMD_TYPE_TABLE,
5000 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
5001 .domain = DOMAIN_KERNEL,
5002 },
5003 [MT_MEMORY_RW_SO] = {
5004 @@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
5005 * Mark cache clean areas and XIP ROM read only
5006 * from SVC mode and no access from userspace.
5007 */
5008 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5009 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5010 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5011 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5012 +#ifdef CONFIG_PAX_KERNEXEC
5013 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5014 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5015 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5016 +#endif
5017 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5018 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5019 #endif
5020
5021 /*
5022 @@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
5023 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
5024 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
5025 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
5026 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
5027 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
5028 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
5029 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
5030 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
5031 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
5032 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
5033 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
5034 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
5035 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
5036 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
5037 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
5038 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
5039 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
5040 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
5041 }
5042 }
5043
5044 @@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
5045 if (cpu_arch >= CPU_ARCH_ARMv6) {
5046 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
5047 /* Non-cacheable Normal is XCB = 001 */
5048 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
5049 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
5050 + PMD_SECT_BUFFERED;
5051 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
5052 PMD_SECT_BUFFERED;
5053 } else {
5054 /* For both ARMv6 and non-TEX-remapping ARMv7 */
5055 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
5056 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
5057 + PMD_SECT_TEX(1);
5058 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
5059 PMD_SECT_TEX(1);
5060 }
5061 } else {
5062 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
5063 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
5064 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
5065 }
5066
5067 #ifdef CONFIG_ARM_LPAE
5068 @@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
5069 vecs_pgprot |= PTE_EXT_AF;
5070 #endif
5071
5072 + user_pgprot |= __supported_pte_mask;
5073 +
5074 for (i = 0; i < 16; i++) {
5075 pteval_t v = pgprot_val(protection_map[i]);
5076 protection_map[i] = __pgprot(v | user_pgprot);
5077 @@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
5078
5079 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
5080 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
5081 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
5082 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
5083 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
5084 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
5085 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
5086 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
5087 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
5088 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
5089 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
5090 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
5091 - mem_types[MT_ROM].prot_sect |= cp->pmd;
5092 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
5093 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
5094 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
5095
5096 switch (cp->pmd) {
5097 case PMD_SECT_WT:
5098 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
5099 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
5100 break;
5101 case PMD_SECT_WB:
5102 case PMD_SECT_WBWA:
5103 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
5104 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
5105 break;
5106 }
5107 pr_info("Memory policy: %sData cache %s\n",
5108 @@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
5109 return;
5110 }
5111
5112 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
5113 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
5114 md->virtual >= PAGE_OFFSET &&
5115 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
5116 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
5117 @@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
5118 * called function. This means you can't use any function or debugging
5119 * method which may touch any device, otherwise the kernel _will_ crash.
5120 */
5121 +
5122 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
5123 +
5124 static void __init devicemaps_init(const struct machine_desc *mdesc)
5125 {
5126 struct map_desc map;
5127 unsigned long addr;
5128 - void *vectors;
5129
5130 - /*
5131 - * Allocate the vector page early.
5132 - */
5133 - vectors = early_alloc(PAGE_SIZE * 2);
5134 -
5135 - early_trap_init(vectors);
5136 + early_trap_init(&vectors);
5137
5138 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
5139 pmd_clear(pmd_off_k(addr));
5140 @@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
5141 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
5142 map.virtual = MODULES_VADDR;
5143 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
5144 - map.type = MT_ROM;
5145 + map.type = MT_ROM_RX;
5146 create_mapping(&map);
5147 #endif
5148
5149 @@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
5150 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
5151 map.virtual = FLUSH_BASE;
5152 map.length = SZ_1M;
5153 - map.type = MT_CACHECLEAN;
5154 + map.type = MT_CACHECLEAN_RO;
5155 create_mapping(&map);
5156 #endif
5157 #ifdef FLUSH_BASE_MINICACHE
5158 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
5159 map.virtual = FLUSH_BASE_MINICACHE;
5160 map.length = SZ_1M;
5161 - map.type = MT_MINICLEAN;
5162 + map.type = MT_MINICLEAN_RO;
5163 create_mapping(&map);
5164 #endif
5165
5166 @@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
5167 * location (0xffff0000). If we aren't using high-vectors, also
5168 * create a mapping at the low-vectors virtual address.
5169 */
5170 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
5171 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
5172 map.virtual = 0xffff0000;
5173 map.length = PAGE_SIZE;
5174 #ifdef CONFIG_KUSER_HELPERS
5175 @@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
5176 static void __init map_lowmem(void)
5177 {
5178 struct memblock_region *reg;
5179 +#ifndef CONFIG_PAX_KERNEXEC
5180 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
5181 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
5182 +#endif
5183
5184 /* Map all the lowmem memory banks. */
5185 for_each_memblock(memory, reg) {
5186 @@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
5187 if (start >= end)
5188 break;
5189
5190 +#ifdef CONFIG_PAX_KERNEXEC
5191 + map.pfn = __phys_to_pfn(start);
5192 + map.virtual = __phys_to_virt(start);
5193 + map.length = end - start;
5194 +
5195 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
5196 + struct map_desc kernel;
5197 + struct map_desc initmap;
5198 +
5199 + /* when freeing initmem we will make this RW */
5200 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
5201 + initmap.virtual = (unsigned long)__init_begin;
5202 + initmap.length = _sdata - __init_begin;
5203 + initmap.type = __MT_MEMORY_RWX;
5204 + create_mapping(&initmap);
5205 +
5206 + /* when freeing initmem we will make this RX */
5207 + kernel.pfn = __phys_to_pfn(__pa(_stext));
5208 + kernel.virtual = (unsigned long)_stext;
5209 + kernel.length = __init_begin - _stext;
5210 + kernel.type = __MT_MEMORY_RWX;
5211 + create_mapping(&kernel);
5212 +
5213 + if (map.virtual < (unsigned long)_stext) {
5214 + map.length = (unsigned long)_stext - map.virtual;
5215 + map.type = __MT_MEMORY_RWX;
5216 + create_mapping(&map);
5217 + }
5218 +
5219 + map.pfn = __phys_to_pfn(__pa(_sdata));
5220 + map.virtual = (unsigned long)_sdata;
5221 + map.length = end - __pa(_sdata);
5222 + }
5223 +
5224 + map.type = MT_MEMORY_RW;
5225 + create_mapping(&map);
5226 +#else
5227 if (end < kernel_x_start || start >= kernel_x_end) {
5228 map.pfn = __phys_to_pfn(start);
5229 map.virtual = __phys_to_virt(start);
5230 map.length = end - start;
5231 - map.type = MT_MEMORY_RWX;
5232 + map.type = __MT_MEMORY_RWX;
5233
5234 create_mapping(&map);
5235 } else {
5236 @@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
5237 map.pfn = __phys_to_pfn(kernel_x_start);
5238 map.virtual = __phys_to_virt(kernel_x_start);
5239 map.length = kernel_x_end - kernel_x_start;
5240 - map.type = MT_MEMORY_RWX;
5241 + map.type = __MT_MEMORY_RWX;
5242
5243 create_mapping(&map);
5244
5245 @@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
5246 create_mapping(&map);
5247 }
5248 }
5249 +#endif
5250 }
5251 }
5252
5253 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
5254 index 5b217f4..c23f40e 100644
5255 --- a/arch/arm/plat-iop/setup.c
5256 +++ b/arch/arm/plat-iop/setup.c
5257 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
5258 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
5259 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
5260 .length = IOP3XX_PERIPHERAL_SIZE,
5261 - .type = MT_UNCACHED,
5262 + .type = MT_UNCACHED_RW,
5263 },
5264 };
5265
5266 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
5267 index a5bc92d..0bb4730 100644
5268 --- a/arch/arm/plat-omap/sram.c
5269 +++ b/arch/arm/plat-omap/sram.c
5270 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
5271 * Looks like we need to preserve some bootloader code at the
5272 * beginning of SRAM for jumping to flash for reboot to work...
5273 */
5274 + pax_open_kernel();
5275 memset_io(omap_sram_base + omap_sram_skip, 0,
5276 omap_sram_size - omap_sram_skip);
5277 + pax_close_kernel();
5278 }
5279 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
5280 index ce6d763..cfea917 100644
5281 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
5282 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
5283 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
5284 int (*started)(unsigned ch);
5285 int (*flush)(unsigned ch);
5286 int (*stop)(unsigned ch);
5287 -};
5288 +} __no_const;
5289
5290 extern void *samsung_dmadev_get_ops(void);
5291 extern void *s3c_dma_get_ops(void);
5292 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
5293 index 6389d60..b5d3bdd 100644
5294 --- a/arch/arm64/include/asm/barrier.h
5295 +++ b/arch/arm64/include/asm/barrier.h
5296 @@ -41,7 +41,7 @@
5297 do { \
5298 compiletime_assert_atomic_type(*p); \
5299 barrier(); \
5300 - ACCESS_ONCE(*p) = (v); \
5301 + ACCESS_ONCE_RW(*p) = (v); \
5302 } while (0)
5303
5304 #define smp_load_acquire(p) \
5305 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
5306 index 3bf8f4e..5dd5491 100644
5307 --- a/arch/arm64/include/asm/uaccess.h
5308 +++ b/arch/arm64/include/asm/uaccess.h
5309 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
5310 flag; \
5311 })
5312
5313 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5314 #define access_ok(type, addr, size) __range_ok(addr, size)
5315 #define user_addr_max get_fs
5316
5317 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
5318 index c3a58a1..78fbf54 100644
5319 --- a/arch/avr32/include/asm/cache.h
5320 +++ b/arch/avr32/include/asm/cache.h
5321 @@ -1,8 +1,10 @@
5322 #ifndef __ASM_AVR32_CACHE_H
5323 #define __ASM_AVR32_CACHE_H
5324
5325 +#include <linux/const.h>
5326 +
5327 #define L1_CACHE_SHIFT 5
5328 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5329 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5330
5331 /*
5332 * Memory returned by kmalloc() may be used for DMA, so we must make
5333 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
5334 index d232888..87c8df1 100644
5335 --- a/arch/avr32/include/asm/elf.h
5336 +++ b/arch/avr32/include/asm/elf.h
5337 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
5338 the loader. We need to make sure that it is out of the way of the program
5339 that it will "exec", and that there is sufficient room for the brk. */
5340
5341 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
5342 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5343
5344 +#ifdef CONFIG_PAX_ASLR
5345 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
5346 +
5347 +#define PAX_DELTA_MMAP_LEN 15
5348 +#define PAX_DELTA_STACK_LEN 15
5349 +#endif
5350
5351 /* This yields a mask that user programs can use to figure out what
5352 instruction set this CPU supports. This could be done in user space,
5353 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
5354 index 479330b..53717a8 100644
5355 --- a/arch/avr32/include/asm/kmap_types.h
5356 +++ b/arch/avr32/include/asm/kmap_types.h
5357 @@ -2,9 +2,9 @@
5358 #define __ASM_AVR32_KMAP_TYPES_H
5359
5360 #ifdef CONFIG_DEBUG_HIGHMEM
5361 -# define KM_TYPE_NR 29
5362 +# define KM_TYPE_NR 30
5363 #else
5364 -# define KM_TYPE_NR 14
5365 +# define KM_TYPE_NR 15
5366 #endif
5367
5368 #endif /* __ASM_AVR32_KMAP_TYPES_H */
5369 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
5370 index 0eca933..eb78c7b 100644
5371 --- a/arch/avr32/mm/fault.c
5372 +++ b/arch/avr32/mm/fault.c
5373 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
5374
5375 int exception_trace = 1;
5376
5377 +#ifdef CONFIG_PAX_PAGEEXEC
5378 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5379 +{
5380 + unsigned long i;
5381 +
5382 + printk(KERN_ERR "PAX: bytes at PC: ");
5383 + for (i = 0; i < 20; i++) {
5384 + unsigned char c;
5385 + if (get_user(c, (unsigned char *)pc+i))
5386 + printk(KERN_CONT "???????? ");
5387 + else
5388 + printk(KERN_CONT "%02x ", c);
5389 + }
5390 + printk("\n");
5391 +}
5392 +#endif
5393 +
5394 /*
5395 * This routine handles page faults. It determines the address and the
5396 * problem, and then passes it off to one of the appropriate routines.
5397 @@ -176,6 +193,16 @@ bad_area:
5398 up_read(&mm->mmap_sem);
5399
5400 if (user_mode(regs)) {
5401 +
5402 +#ifdef CONFIG_PAX_PAGEEXEC
5403 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5404 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
5405 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
5406 + do_group_exit(SIGKILL);
5407 + }
5408 + }
5409 +#endif
5410 +
5411 if (exception_trace && printk_ratelimit())
5412 printk("%s%s[%d]: segfault at %08lx pc %08lx "
5413 "sp %08lx ecr %lu\n",
5414 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
5415 index 568885a..f8008df 100644
5416 --- a/arch/blackfin/include/asm/cache.h
5417 +++ b/arch/blackfin/include/asm/cache.h
5418 @@ -7,6 +7,7 @@
5419 #ifndef __ARCH_BLACKFIN_CACHE_H
5420 #define __ARCH_BLACKFIN_CACHE_H
5421
5422 +#include <linux/const.h>
5423 #include <linux/linkage.h> /* for asmlinkage */
5424
5425 /*
5426 @@ -14,7 +15,7 @@
5427 * Blackfin loads 32 bytes for cache
5428 */
5429 #define L1_CACHE_SHIFT 5
5430 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5431 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5432 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5433
5434 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5435 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
5436 index aea2718..3639a60 100644
5437 --- a/arch/cris/include/arch-v10/arch/cache.h
5438 +++ b/arch/cris/include/arch-v10/arch/cache.h
5439 @@ -1,8 +1,9 @@
5440 #ifndef _ASM_ARCH_CACHE_H
5441 #define _ASM_ARCH_CACHE_H
5442
5443 +#include <linux/const.h>
5444 /* Etrax 100LX have 32-byte cache-lines. */
5445 -#define L1_CACHE_BYTES 32
5446 #define L1_CACHE_SHIFT 5
5447 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5448
5449 #endif /* _ASM_ARCH_CACHE_H */
5450 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
5451 index 7caf25d..ee65ac5 100644
5452 --- a/arch/cris/include/arch-v32/arch/cache.h
5453 +++ b/arch/cris/include/arch-v32/arch/cache.h
5454 @@ -1,11 +1,12 @@
5455 #ifndef _ASM_CRIS_ARCH_CACHE_H
5456 #define _ASM_CRIS_ARCH_CACHE_H
5457
5458 +#include <linux/const.h>
5459 #include <arch/hwregs/dma.h>
5460
5461 /* A cache-line is 32 bytes. */
5462 -#define L1_CACHE_BYTES 32
5463 #define L1_CACHE_SHIFT 5
5464 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5465
5466 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5467
5468 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5469 index f6c3a16..cd422a4 100644
5470 --- a/arch/frv/include/asm/atomic.h
5471 +++ b/arch/frv/include/asm/atomic.h
5472 @@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5473 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5474 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5475
5476 +#define atomic64_read_unchecked(v) atomic64_read(v)
5477 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5478 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5479 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5480 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5481 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5482 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5483 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5484 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5485 +
5486 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5487 {
5488 int c, old;
5489 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5490 index 2797163..c2a401d 100644
5491 --- a/arch/frv/include/asm/cache.h
5492 +++ b/arch/frv/include/asm/cache.h
5493 @@ -12,10 +12,11 @@
5494 #ifndef __ASM_CACHE_H
5495 #define __ASM_CACHE_H
5496
5497 +#include <linux/const.h>
5498
5499 /* bytes per L1 cache line */
5500 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5501 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5502 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5503
5504 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5505 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5506 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5507 index 43901f2..0d8b865 100644
5508 --- a/arch/frv/include/asm/kmap_types.h
5509 +++ b/arch/frv/include/asm/kmap_types.h
5510 @@ -2,6 +2,6 @@
5511 #ifndef _ASM_KMAP_TYPES_H
5512 #define _ASM_KMAP_TYPES_H
5513
5514 -#define KM_TYPE_NR 17
5515 +#define KM_TYPE_NR 18
5516
5517 #endif
5518 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5519 index 836f147..4cf23f5 100644
5520 --- a/arch/frv/mm/elf-fdpic.c
5521 +++ b/arch/frv/mm/elf-fdpic.c
5522 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5523 {
5524 struct vm_area_struct *vma;
5525 struct vm_unmapped_area_info info;
5526 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5527
5528 if (len > TASK_SIZE)
5529 return -ENOMEM;
5530 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5531 if (addr) {
5532 addr = PAGE_ALIGN(addr);
5533 vma = find_vma(current->mm, addr);
5534 - if (TASK_SIZE - len >= addr &&
5535 - (!vma || addr + len <= vma->vm_start))
5536 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5537 goto success;
5538 }
5539
5540 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5541 info.high_limit = (current->mm->start_stack - 0x00200000);
5542 info.align_mask = 0;
5543 info.align_offset = 0;
5544 + info.threadstack_offset = offset;
5545 addr = vm_unmapped_area(&info);
5546 if (!(addr & ~PAGE_MASK))
5547 goto success;
5548 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5549 index f4ca594..adc72fd6 100644
5550 --- a/arch/hexagon/include/asm/cache.h
5551 +++ b/arch/hexagon/include/asm/cache.h
5552 @@ -21,9 +21,11 @@
5553 #ifndef __ASM_CACHE_H
5554 #define __ASM_CACHE_H
5555
5556 +#include <linux/const.h>
5557 +
5558 /* Bytes per L1 cache line */
5559 -#define L1_CACHE_SHIFT (5)
5560 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5561 +#define L1_CACHE_SHIFT 5
5562 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5563
5564 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5565 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5566 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5567 index 2f3abcf..e63c7fa 100644
5568 --- a/arch/ia64/Kconfig
5569 +++ b/arch/ia64/Kconfig
5570 @@ -547,6 +547,7 @@ source "drivers/sn/Kconfig"
5571 config KEXEC
5572 bool "kexec system call"
5573 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5574 + depends on !GRKERNSEC_KMEM
5575 help
5576 kexec is a system call that implements the ability to shutdown your
5577 current kernel, and to start another kernel. It is like a reboot
5578 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5579 index 0f8bf48..40ea950 100644
5580 --- a/arch/ia64/include/asm/atomic.h
5581 +++ b/arch/ia64/include/asm/atomic.h
5582 @@ -209,4 +209,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5583 #define atomic64_inc(v) atomic64_add(1, (v))
5584 #define atomic64_dec(v) atomic64_sub(1, (v))
5585
5586 +#define atomic64_read_unchecked(v) atomic64_read(v)
5587 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5588 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5589 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5590 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5591 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5592 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5593 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5594 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5595 +
5596 #endif /* _ASM_IA64_ATOMIC_H */
5597 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5598 index a48957c..e097b56 100644
5599 --- a/arch/ia64/include/asm/barrier.h
5600 +++ b/arch/ia64/include/asm/barrier.h
5601 @@ -67,7 +67,7 @@
5602 do { \
5603 compiletime_assert_atomic_type(*p); \
5604 barrier(); \
5605 - ACCESS_ONCE(*p) = (v); \
5606 + ACCESS_ONCE_RW(*p) = (v); \
5607 } while (0)
5608
5609 #define smp_load_acquire(p) \
5610 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5611 index 988254a..e1ee885 100644
5612 --- a/arch/ia64/include/asm/cache.h
5613 +++ b/arch/ia64/include/asm/cache.h
5614 @@ -1,6 +1,7 @@
5615 #ifndef _ASM_IA64_CACHE_H
5616 #define _ASM_IA64_CACHE_H
5617
5618 +#include <linux/const.h>
5619
5620 /*
5621 * Copyright (C) 1998-2000 Hewlett-Packard Co
5622 @@ -9,7 +10,7 @@
5623
5624 /* Bytes per L1 (data) cache line. */
5625 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5626 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5627 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5628
5629 #ifdef CONFIG_SMP
5630 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5631 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5632 index 5a83c5c..4d7f553 100644
5633 --- a/arch/ia64/include/asm/elf.h
5634 +++ b/arch/ia64/include/asm/elf.h
5635 @@ -42,6 +42,13 @@
5636 */
5637 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5638
5639 +#ifdef CONFIG_PAX_ASLR
5640 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5641 +
5642 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5643 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5644 +#endif
5645 +
5646 #define PT_IA_64_UNWIND 0x70000001
5647
5648 /* IA-64 relocations: */
5649 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5650 index 5767cdf..7462574 100644
5651 --- a/arch/ia64/include/asm/pgalloc.h
5652 +++ b/arch/ia64/include/asm/pgalloc.h
5653 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5654 pgd_val(*pgd_entry) = __pa(pud);
5655 }
5656
5657 +static inline void
5658 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5659 +{
5660 + pgd_populate(mm, pgd_entry, pud);
5661 +}
5662 +
5663 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5664 {
5665 return quicklist_alloc(0, GFP_KERNEL, NULL);
5666 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5667 pud_val(*pud_entry) = __pa(pmd);
5668 }
5669
5670 +static inline void
5671 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5672 +{
5673 + pud_populate(mm, pud_entry, pmd);
5674 +}
5675 +
5676 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5677 {
5678 return quicklist_alloc(0, GFP_KERNEL, NULL);
5679 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5680 index 7935115..c0eca6a 100644
5681 --- a/arch/ia64/include/asm/pgtable.h
5682 +++ b/arch/ia64/include/asm/pgtable.h
5683 @@ -12,7 +12,7 @@
5684 * David Mosberger-Tang <davidm@hpl.hp.com>
5685 */
5686
5687 -
5688 +#include <linux/const.h>
5689 #include <asm/mman.h>
5690 #include <asm/page.h>
5691 #include <asm/processor.h>
5692 @@ -142,6 +142,17 @@
5693 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5694 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5695 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5696 +
5697 +#ifdef CONFIG_PAX_PAGEEXEC
5698 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5699 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5700 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5701 +#else
5702 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5703 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5704 +# define PAGE_COPY_NOEXEC PAGE_COPY
5705 +#endif
5706 +
5707 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5708 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5709 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5710 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5711 index 45698cd..e8e2dbc 100644
5712 --- a/arch/ia64/include/asm/spinlock.h
5713 +++ b/arch/ia64/include/asm/spinlock.h
5714 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5715 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5716
5717 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5718 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5719 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5720 }
5721
5722 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5723 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5724 index 449c8c0..3d4b1e9 100644
5725 --- a/arch/ia64/include/asm/uaccess.h
5726 +++ b/arch/ia64/include/asm/uaccess.h
5727 @@ -70,6 +70,7 @@
5728 && ((segment).seg == KERNEL_DS.seg \
5729 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5730 })
5731 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5732 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5733
5734 /*
5735 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5736 static inline unsigned long
5737 __copy_to_user (void __user *to, const void *from, unsigned long count)
5738 {
5739 + if (count > INT_MAX)
5740 + return count;
5741 +
5742 + if (!__builtin_constant_p(count))
5743 + check_object_size(from, count, true);
5744 +
5745 return __copy_user(to, (__force void __user *) from, count);
5746 }
5747
5748 static inline unsigned long
5749 __copy_from_user (void *to, const void __user *from, unsigned long count)
5750 {
5751 + if (count > INT_MAX)
5752 + return count;
5753 +
5754 + if (!__builtin_constant_p(count))
5755 + check_object_size(to, count, false);
5756 +
5757 return __copy_user((__force void __user *) to, from, count);
5758 }
5759
5760 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5761 ({ \
5762 void __user *__cu_to = (to); \
5763 const void *__cu_from = (from); \
5764 - long __cu_len = (n); \
5765 + unsigned long __cu_len = (n); \
5766 \
5767 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5768 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5769 + if (!__builtin_constant_p(n)) \
5770 + check_object_size(__cu_from, __cu_len, true); \
5771 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5772 + } \
5773 __cu_len; \
5774 })
5775
5776 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5777 ({ \
5778 void *__cu_to = (to); \
5779 const void __user *__cu_from = (from); \
5780 - long __cu_len = (n); \
5781 + unsigned long __cu_len = (n); \
5782 \
5783 __chk_user_ptr(__cu_from); \
5784 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5785 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5786 + if (!__builtin_constant_p(n)) \
5787 + check_object_size(__cu_to, __cu_len, false); \
5788 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5789 + } \
5790 __cu_len; \
5791 })
5792
5793 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5794 index 24603be..948052d 100644
5795 --- a/arch/ia64/kernel/module.c
5796 +++ b/arch/ia64/kernel/module.c
5797 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5798 void
5799 module_free (struct module *mod, void *module_region)
5800 {
5801 - if (mod && mod->arch.init_unw_table &&
5802 - module_region == mod->module_init) {
5803 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5804 unw_remove_unwind_table(mod->arch.init_unw_table);
5805 mod->arch.init_unw_table = NULL;
5806 }
5807 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5808 }
5809
5810 static inline int
5811 +in_init_rx (const struct module *mod, uint64_t addr)
5812 +{
5813 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5814 +}
5815 +
5816 +static inline int
5817 +in_init_rw (const struct module *mod, uint64_t addr)
5818 +{
5819 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5820 +}
5821 +
5822 +static inline int
5823 in_init (const struct module *mod, uint64_t addr)
5824 {
5825 - return addr - (uint64_t) mod->module_init < mod->init_size;
5826 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5827 +}
5828 +
5829 +static inline int
5830 +in_core_rx (const struct module *mod, uint64_t addr)
5831 +{
5832 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5833 +}
5834 +
5835 +static inline int
5836 +in_core_rw (const struct module *mod, uint64_t addr)
5837 +{
5838 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5839 }
5840
5841 static inline int
5842 in_core (const struct module *mod, uint64_t addr)
5843 {
5844 - return addr - (uint64_t) mod->module_core < mod->core_size;
5845 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5846 }
5847
5848 static inline int
5849 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5850 break;
5851
5852 case RV_BDREL:
5853 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5854 + if (in_init_rx(mod, val))
5855 + val -= (uint64_t) mod->module_init_rx;
5856 + else if (in_init_rw(mod, val))
5857 + val -= (uint64_t) mod->module_init_rw;
5858 + else if (in_core_rx(mod, val))
5859 + val -= (uint64_t) mod->module_core_rx;
5860 + else if (in_core_rw(mod, val))
5861 + val -= (uint64_t) mod->module_core_rw;
5862 break;
5863
5864 case RV_LTV:
5865 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5866 * addresses have been selected...
5867 */
5868 uint64_t gp;
5869 - if (mod->core_size > MAX_LTOFF)
5870 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5871 /*
5872 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5873 * at the end of the module.
5874 */
5875 - gp = mod->core_size - MAX_LTOFF / 2;
5876 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5877 else
5878 - gp = mod->core_size / 2;
5879 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5880 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5881 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5882 mod->arch.gp = gp;
5883 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5884 }
5885 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5886 index c39c3cd..3c77738 100644
5887 --- a/arch/ia64/kernel/palinfo.c
5888 +++ b/arch/ia64/kernel/palinfo.c
5889 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5890 return NOTIFY_OK;
5891 }
5892
5893 -static struct notifier_block __refdata palinfo_cpu_notifier =
5894 +static struct notifier_block palinfo_cpu_notifier =
5895 {
5896 .notifier_call = palinfo_cpu_callback,
5897 .priority = 0,
5898 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5899 index 41e33f8..65180b2a 100644
5900 --- a/arch/ia64/kernel/sys_ia64.c
5901 +++ b/arch/ia64/kernel/sys_ia64.c
5902 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5903 unsigned long align_mask = 0;
5904 struct mm_struct *mm = current->mm;
5905 struct vm_unmapped_area_info info;
5906 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5907
5908 if (len > RGN_MAP_LIMIT)
5909 return -ENOMEM;
5910 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5911 if (REGION_NUMBER(addr) == RGN_HPAGE)
5912 addr = 0;
5913 #endif
5914 +
5915 +#ifdef CONFIG_PAX_RANDMMAP
5916 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5917 + addr = mm->free_area_cache;
5918 + else
5919 +#endif
5920 +
5921 if (!addr)
5922 addr = TASK_UNMAPPED_BASE;
5923
5924 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5925 info.high_limit = TASK_SIZE;
5926 info.align_mask = align_mask;
5927 info.align_offset = 0;
5928 + info.threadstack_offset = offset;
5929 return vm_unmapped_area(&info);
5930 }
5931
5932 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5933 index 84f8a52..7c76178 100644
5934 --- a/arch/ia64/kernel/vmlinux.lds.S
5935 +++ b/arch/ia64/kernel/vmlinux.lds.S
5936 @@ -192,7 +192,7 @@ SECTIONS {
5937 /* Per-cpu data: */
5938 . = ALIGN(PERCPU_PAGE_SIZE);
5939 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5940 - __phys_per_cpu_start = __per_cpu_load;
5941 + __phys_per_cpu_start = per_cpu_load;
5942 /*
5943 * ensure percpu data fits
5944 * into percpu page size
5945 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5946 index 7225dad..2a7c8256 100644
5947 --- a/arch/ia64/mm/fault.c
5948 +++ b/arch/ia64/mm/fault.c
5949 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5950 return pte_present(pte);
5951 }
5952
5953 +#ifdef CONFIG_PAX_PAGEEXEC
5954 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5955 +{
5956 + unsigned long i;
5957 +
5958 + printk(KERN_ERR "PAX: bytes at PC: ");
5959 + for (i = 0; i < 8; i++) {
5960 + unsigned int c;
5961 + if (get_user(c, (unsigned int *)pc+i))
5962 + printk(KERN_CONT "???????? ");
5963 + else
5964 + printk(KERN_CONT "%08x ", c);
5965 + }
5966 + printk("\n");
5967 +}
5968 +#endif
5969 +
5970 # define VM_READ_BIT 0
5971 # define VM_WRITE_BIT 1
5972 # define VM_EXEC_BIT 2
5973 @@ -151,8 +168,21 @@ retry:
5974 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5975 goto bad_area;
5976
5977 - if ((vma->vm_flags & mask) != mask)
5978 + if ((vma->vm_flags & mask) != mask) {
5979 +
5980 +#ifdef CONFIG_PAX_PAGEEXEC
5981 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5982 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5983 + goto bad_area;
5984 +
5985 + up_read(&mm->mmap_sem);
5986 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5987 + do_group_exit(SIGKILL);
5988 + }
5989 +#endif
5990 +
5991 goto bad_area;
5992 + }
5993
5994 /*
5995 * If for any reason at all we couldn't handle the fault, make
5996 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5997 index 76069c1..c2aa816 100644
5998 --- a/arch/ia64/mm/hugetlbpage.c
5999 +++ b/arch/ia64/mm/hugetlbpage.c
6000 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
6001 unsigned long pgoff, unsigned long flags)
6002 {
6003 struct vm_unmapped_area_info info;
6004 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
6005
6006 if (len > RGN_MAP_LIMIT)
6007 return -ENOMEM;
6008 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
6009 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
6010 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
6011 info.align_offset = 0;
6012 + info.threadstack_offset = offset;
6013 return vm_unmapped_area(&info);
6014 }
6015
6016 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
6017 index 25c3502..560dae7 100644
6018 --- a/arch/ia64/mm/init.c
6019 +++ b/arch/ia64/mm/init.c
6020 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
6021 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
6022 vma->vm_end = vma->vm_start + PAGE_SIZE;
6023 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
6024 +
6025 +#ifdef CONFIG_PAX_PAGEEXEC
6026 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
6027 + vma->vm_flags &= ~VM_EXEC;
6028 +
6029 +#ifdef CONFIG_PAX_MPROTECT
6030 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
6031 + vma->vm_flags &= ~VM_MAYEXEC;
6032 +#endif
6033 +
6034 + }
6035 +#endif
6036 +
6037 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6038 down_write(&current->mm->mmap_sem);
6039 if (insert_vm_struct(current->mm, vma)) {
6040 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
6041 index 40b3ee9..8c2c112 100644
6042 --- a/arch/m32r/include/asm/cache.h
6043 +++ b/arch/m32r/include/asm/cache.h
6044 @@ -1,8 +1,10 @@
6045 #ifndef _ASM_M32R_CACHE_H
6046 #define _ASM_M32R_CACHE_H
6047
6048 +#include <linux/const.h>
6049 +
6050 /* L1 cache line size */
6051 #define L1_CACHE_SHIFT 4
6052 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6053 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6054
6055 #endif /* _ASM_M32R_CACHE_H */
6056 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
6057 index 82abd15..d95ae5d 100644
6058 --- a/arch/m32r/lib/usercopy.c
6059 +++ b/arch/m32r/lib/usercopy.c
6060 @@ -14,6 +14,9 @@
6061 unsigned long
6062 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
6063 {
6064 + if ((long)n < 0)
6065 + return n;
6066 +
6067 prefetch(from);
6068 if (access_ok(VERIFY_WRITE, to, n))
6069 __copy_user(to,from,n);
6070 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
6071 unsigned long
6072 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
6073 {
6074 + if ((long)n < 0)
6075 + return n;
6076 +
6077 prefetchw(to);
6078 if (access_ok(VERIFY_READ, from, n))
6079 __copy_user_zeroing(to,from,n);
6080 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
6081 index 0395c51..5f26031 100644
6082 --- a/arch/m68k/include/asm/cache.h
6083 +++ b/arch/m68k/include/asm/cache.h
6084 @@ -4,9 +4,11 @@
6085 #ifndef __ARCH_M68K_CACHE_H
6086 #define __ARCH_M68K_CACHE_H
6087
6088 +#include <linux/const.h>
6089 +
6090 /* bytes per L1 cache line */
6091 #define L1_CACHE_SHIFT 4
6092 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
6093 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6094
6095 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
6096
6097 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
6098 index c7591e8..ecef036 100644
6099 --- a/arch/metag/include/asm/barrier.h
6100 +++ b/arch/metag/include/asm/barrier.h
6101 @@ -89,7 +89,7 @@ static inline void fence(void)
6102 do { \
6103 compiletime_assert_atomic_type(*p); \
6104 smp_mb(); \
6105 - ACCESS_ONCE(*p) = (v); \
6106 + ACCESS_ONCE_RW(*p) = (v); \
6107 } while (0)
6108
6109 #define smp_load_acquire(p) \
6110 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
6111 index 3c52fa6..11b2ad8 100644
6112 --- a/arch/metag/mm/hugetlbpage.c
6113 +++ b/arch/metag/mm/hugetlbpage.c
6114 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
6115 info.high_limit = TASK_SIZE;
6116 info.align_mask = PAGE_MASK & HUGEPT_MASK;
6117 info.align_offset = 0;
6118 + info.threadstack_offset = 0;
6119 return vm_unmapped_area(&info);
6120 }
6121
6122 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
6123 index 4efe96a..60e8699 100644
6124 --- a/arch/microblaze/include/asm/cache.h
6125 +++ b/arch/microblaze/include/asm/cache.h
6126 @@ -13,11 +13,12 @@
6127 #ifndef _ASM_MICROBLAZE_CACHE_H
6128 #define _ASM_MICROBLAZE_CACHE_H
6129
6130 +#include <linux/const.h>
6131 #include <asm/registers.h>
6132
6133 #define L1_CACHE_SHIFT 5
6134 /* word-granular cache in microblaze */
6135 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6136 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6137
6138 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6139
6140 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
6141 index 4e238e6..7c9ed92 100644
6142 --- a/arch/mips/Kconfig
6143 +++ b/arch/mips/Kconfig
6144 @@ -2392,6 +2392,7 @@ source "kernel/Kconfig.preempt"
6145
6146 config KEXEC
6147 bool "Kexec system call"
6148 + depends on !GRKERNSEC_KMEM
6149 help
6150 kexec is a system call that implements the ability to shutdown your
6151 current kernel, and to start another kernel. It is like a reboot
6152 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
6153 index 02f2444..506969c 100644
6154 --- a/arch/mips/cavium-octeon/dma-octeon.c
6155 +++ b/arch/mips/cavium-octeon/dma-octeon.c
6156 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
6157 if (dma_release_from_coherent(dev, order, vaddr))
6158 return;
6159
6160 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
6161 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
6162 }
6163
6164 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
6165 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
6166 index 37b2bef..02122b8 100644
6167 --- a/arch/mips/include/asm/atomic.h
6168 +++ b/arch/mips/include/asm/atomic.h
6169 @@ -21,15 +21,39 @@
6170 #include <asm/cmpxchg.h>
6171 #include <asm/war.h>
6172
6173 +#ifdef CONFIG_GENERIC_ATOMIC64
6174 +#include <asm-generic/atomic64.h>
6175 +#endif
6176 +
6177 #define ATOMIC_INIT(i) { (i) }
6178
6179 +#ifdef CONFIG_64BIT
6180 +#define _ASM_EXTABLE(from, to) \
6181 +" .section __ex_table,\"a\"\n" \
6182 +" .dword " #from ", " #to"\n" \
6183 +" .previous\n"
6184 +#else
6185 +#define _ASM_EXTABLE(from, to) \
6186 +" .section __ex_table,\"a\"\n" \
6187 +" .word " #from ", " #to"\n" \
6188 +" .previous\n"
6189 +#endif
6190 +
6191 /*
6192 * atomic_read - read atomic variable
6193 * @v: pointer of type atomic_t
6194 *
6195 * Atomically reads the value of @v.
6196 */
6197 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
6198 +static inline int atomic_read(const atomic_t *v)
6199 +{
6200 + return (*(volatile const int *) &v->counter);
6201 +}
6202 +
6203 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6204 +{
6205 + return (*(volatile const int *) &v->counter);
6206 +}
6207
6208 /*
6209 * atomic_set - set atomic variable
6210 @@ -38,7 +62,15 @@
6211 *
6212 * Atomically sets the value of @v to @i.
6213 */
6214 -#define atomic_set(v, i) ((v)->counter = (i))
6215 +static inline void atomic_set(atomic_t *v, int i)
6216 +{
6217 + v->counter = i;
6218 +}
6219 +
6220 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6221 +{
6222 + v->counter = i;
6223 +}
6224
6225 /*
6226 * atomic_add - add integer to atomic variable
6227 @@ -47,7 +79,67 @@
6228 *
6229 * Atomically adds @i to @v.
6230 */
6231 -static __inline__ void atomic_add(int i, atomic_t * v)
6232 +static __inline__ void atomic_add(int i, atomic_t *v)
6233 +{
6234 + int temp;
6235 +
6236 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6237 + __asm__ __volatile__(
6238 + " .set mips3 \n"
6239 + "1: ll %0, %1 # atomic_add \n"
6240 +#ifdef CONFIG_PAX_REFCOUNT
6241 + /* Exception on overflow. */
6242 + "2: add %0, %2 \n"
6243 +#else
6244 + " addu %0, %2 \n"
6245 +#endif
6246 + " sc %0, %1 \n"
6247 + " beqzl %0, 1b \n"
6248 +#ifdef CONFIG_PAX_REFCOUNT
6249 + "3: \n"
6250 + _ASM_EXTABLE(2b, 3b)
6251 +#endif
6252 + " .set mips0 \n"
6253 + : "=&r" (temp), "+m" (v->counter)
6254 + : "Ir" (i));
6255 + } else if (kernel_uses_llsc) {
6256 + __asm__ __volatile__(
6257 + " .set mips3 \n"
6258 + "1: ll %0, %1 # atomic_add \n"
6259 +#ifdef CONFIG_PAX_REFCOUNT
6260 + /* Exception on overflow. */
6261 + "2: add %0, %2 \n"
6262 +#else
6263 + " addu %0, %2 \n"
6264 +#endif
6265 + " sc %0, %1 \n"
6266 + " beqz %0, 1b \n"
6267 +#ifdef CONFIG_PAX_REFCOUNT
6268 + "3: \n"
6269 + _ASM_EXTABLE(2b, 3b)
6270 +#endif
6271 + " .set mips0 \n"
6272 + : "=&r" (temp), "+m" (v->counter)
6273 + : "Ir" (i));
6274 + } else {
6275 + unsigned long flags;
6276 +
6277 + raw_local_irq_save(flags);
6278 + __asm__ __volatile__(
6279 +#ifdef CONFIG_PAX_REFCOUNT
6280 + /* Exception on overflow. */
6281 + "1: add %0, %1 \n"
6282 + "2: \n"
6283 + _ASM_EXTABLE(1b, 2b)
6284 +#else
6285 + " addu %0, %1 \n"
6286 +#endif
6287 + : "+r" (v->counter) : "Ir" (i));
6288 + raw_local_irq_restore(flags);
6289 + }
6290 +}
6291 +
6292 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
6293 {
6294 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6295 int temp;
6296 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
6297 *
6298 * Atomically subtracts @i from @v.
6299 */
6300 -static __inline__ void atomic_sub(int i, atomic_t * v)
6301 +static __inline__ void atomic_sub(int i, atomic_t *v)
6302 +{
6303 + int temp;
6304 +
6305 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6306 + __asm__ __volatile__(
6307 + " .set mips3 \n"
6308 + "1: ll %0, %1 # atomic64_sub \n"
6309 +#ifdef CONFIG_PAX_REFCOUNT
6310 + /* Exception on overflow. */
6311 + "2: sub %0, %2 \n"
6312 +#else
6313 + " subu %0, %2 \n"
6314 +#endif
6315 + " sc %0, %1 \n"
6316 + " beqzl %0, 1b \n"
6317 +#ifdef CONFIG_PAX_REFCOUNT
6318 + "3: \n"
6319 + _ASM_EXTABLE(2b, 3b)
6320 +#endif
6321 + " .set mips0 \n"
6322 + : "=&r" (temp), "+m" (v->counter)
6323 + : "Ir" (i));
6324 + } else if (kernel_uses_llsc) {
6325 + __asm__ __volatile__(
6326 + " .set mips3 \n"
6327 + "1: ll %0, %1 # atomic64_sub \n"
6328 +#ifdef CONFIG_PAX_REFCOUNT
6329 + /* Exception on overflow. */
6330 + "2: sub %0, %2 \n"
6331 +#else
6332 + " subu %0, %2 \n"
6333 +#endif
6334 + " sc %0, %1 \n"
6335 + " beqz %0, 1b \n"
6336 +#ifdef CONFIG_PAX_REFCOUNT
6337 + "3: \n"
6338 + _ASM_EXTABLE(2b, 3b)
6339 +#endif
6340 + " .set mips0 \n"
6341 + : "=&r" (temp), "+m" (v->counter)
6342 + : "Ir" (i));
6343 + } else {
6344 + unsigned long flags;
6345 +
6346 + raw_local_irq_save(flags);
6347 + __asm__ __volatile__(
6348 +#ifdef CONFIG_PAX_REFCOUNT
6349 + /* Exception on overflow. */
6350 + "1: sub %0, %1 \n"
6351 + "2: \n"
6352 + _ASM_EXTABLE(1b, 2b)
6353 +#else
6354 + " subu %0, %1 \n"
6355 +#endif
6356 + : "+r" (v->counter) : "Ir" (i));
6357 + raw_local_irq_restore(flags);
6358 + }
6359 +}
6360 +
6361 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
6362 {
6363 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6364 int temp;
6365 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
6366 /*
6367 * Same as above, but return the result value
6368 */
6369 -static __inline__ int atomic_add_return(int i, atomic_t * v)
6370 +static __inline__ int atomic_add_return(int i, atomic_t *v)
6371 +{
6372 + int result;
6373 + int temp;
6374 +
6375 + smp_mb__before_llsc();
6376 +
6377 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6378 + __asm__ __volatile__(
6379 + " .set mips3 \n"
6380 + "1: ll %1, %2 # atomic_add_return \n"
6381 +#ifdef CONFIG_PAX_REFCOUNT
6382 + "2: add %0, %1, %3 \n"
6383 +#else
6384 + " addu %0, %1, %3 \n"
6385 +#endif
6386 + " sc %0, %2 \n"
6387 + " beqzl %0, 1b \n"
6388 +#ifdef CONFIG_PAX_REFCOUNT
6389 + " b 4f \n"
6390 + " .set noreorder \n"
6391 + "3: b 5f \n"
6392 + " move %0, %1 \n"
6393 + " .set reorder \n"
6394 + _ASM_EXTABLE(2b, 3b)
6395 +#endif
6396 + "4: addu %0, %1, %3 \n"
6397 +#ifdef CONFIG_PAX_REFCOUNT
6398 + "5: \n"
6399 +#endif
6400 + " .set mips0 \n"
6401 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6402 + : "Ir" (i));
6403 + } else if (kernel_uses_llsc) {
6404 + __asm__ __volatile__(
6405 + " .set mips3 \n"
6406 + "1: ll %1, %2 # atomic_add_return \n"
6407 +#ifdef CONFIG_PAX_REFCOUNT
6408 + "2: add %0, %1, %3 \n"
6409 +#else
6410 + " addu %0, %1, %3 \n"
6411 +#endif
6412 + " sc %0, %2 \n"
6413 + " bnez %0, 4f \n"
6414 + " b 1b \n"
6415 +#ifdef CONFIG_PAX_REFCOUNT
6416 + " .set noreorder \n"
6417 + "3: b 5f \n"
6418 + " move %0, %1 \n"
6419 + " .set reorder \n"
6420 + _ASM_EXTABLE(2b, 3b)
6421 +#endif
6422 + "4: addu %0, %1, %3 \n"
6423 +#ifdef CONFIG_PAX_REFCOUNT
6424 + "5: \n"
6425 +#endif
6426 + " .set mips0 \n"
6427 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6428 + : "Ir" (i));
6429 + } else {
6430 + unsigned long flags;
6431 +
6432 + raw_local_irq_save(flags);
6433 + __asm__ __volatile__(
6434 + " lw %0, %1 \n"
6435 +#ifdef CONFIG_PAX_REFCOUNT
6436 + /* Exception on overflow. */
6437 + "1: add %0, %2 \n"
6438 +#else
6439 + " addu %0, %2 \n"
6440 +#endif
6441 + " sw %0, %1 \n"
6442 +#ifdef CONFIG_PAX_REFCOUNT
6443 + /* Note: Dest reg is not modified on overflow */
6444 + "2: \n"
6445 + _ASM_EXTABLE(1b, 2b)
6446 +#endif
6447 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6448 + raw_local_irq_restore(flags);
6449 + }
6450 +
6451 + smp_llsc_mb();
6452 +
6453 + return result;
6454 +}
6455 +
6456 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6457 {
6458 int result;
6459
6460 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
6461 return result;
6462 }
6463
6464 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
6465 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
6466 +{
6467 + int result;
6468 + int temp;
6469 +
6470 + smp_mb__before_llsc();
6471 +
6472 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6473 + __asm__ __volatile__(
6474 + " .set mips3 \n"
6475 + "1: ll %1, %2 # atomic_sub_return \n"
6476 +#ifdef CONFIG_PAX_REFCOUNT
6477 + "2: sub %0, %1, %3 \n"
6478 +#else
6479 + " subu %0, %1, %3 \n"
6480 +#endif
6481 + " sc %0, %2 \n"
6482 + " beqzl %0, 1b \n"
6483 +#ifdef CONFIG_PAX_REFCOUNT
6484 + " b 4f \n"
6485 + " .set noreorder \n"
6486 + "3: b 5f \n"
6487 + " move %0, %1 \n"
6488 + " .set reorder \n"
6489 + _ASM_EXTABLE(2b, 3b)
6490 +#endif
6491 + "4: subu %0, %1, %3 \n"
6492 +#ifdef CONFIG_PAX_REFCOUNT
6493 + "5: \n"
6494 +#endif
6495 + " .set mips0 \n"
6496 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6497 + : "Ir" (i), "m" (v->counter)
6498 + : "memory");
6499 + } else if (kernel_uses_llsc) {
6500 + __asm__ __volatile__(
6501 + " .set mips3 \n"
6502 + "1: ll %1, %2 # atomic_sub_return \n"
6503 +#ifdef CONFIG_PAX_REFCOUNT
6504 + "2: sub %0, %1, %3 \n"
6505 +#else
6506 + " subu %0, %1, %3 \n"
6507 +#endif
6508 + " sc %0, %2 \n"
6509 + " bnez %0, 4f \n"
6510 + " b 1b \n"
6511 +#ifdef CONFIG_PAX_REFCOUNT
6512 + " .set noreorder \n"
6513 + "3: b 5f \n"
6514 + " move %0, %1 \n"
6515 + " .set reorder \n"
6516 + _ASM_EXTABLE(2b, 3b)
6517 +#endif
6518 + "4: subu %0, %1, %3 \n"
6519 +#ifdef CONFIG_PAX_REFCOUNT
6520 + "5: \n"
6521 +#endif
6522 + " .set mips0 \n"
6523 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6524 + : "Ir" (i));
6525 + } else {
6526 + unsigned long flags;
6527 +
6528 + raw_local_irq_save(flags);
6529 + __asm__ __volatile__(
6530 + " lw %0, %1 \n"
6531 +#ifdef CONFIG_PAX_REFCOUNT
6532 + /* Exception on overflow. */
6533 + "1: sub %0, %2 \n"
6534 +#else
6535 + " subu %0, %2 \n"
6536 +#endif
6537 + " sw %0, %1 \n"
6538 +#ifdef CONFIG_PAX_REFCOUNT
6539 + /* Note: Dest reg is not modified on overflow */
6540 + "2: \n"
6541 + _ASM_EXTABLE(1b, 2b)
6542 +#endif
6543 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6544 + raw_local_irq_restore(flags);
6545 + }
6546 +
6547 + smp_llsc_mb();
6548 +
6549 + return result;
6550 +}
6551 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6552 {
6553 int result;
6554
6555 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6556 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6557 * The function returns the old value of @v minus @i.
6558 */
6559 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6560 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6561 {
6562 int result;
6563
6564 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6565 return result;
6566 }
6567
6568 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6569 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6570 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6571 +{
6572 + return cmpxchg(&v->counter, old, new);
6573 +}
6574 +
6575 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6576 + int new)
6577 +{
6578 + return cmpxchg(&(v->counter), old, new);
6579 +}
6580 +
6581 +static inline int atomic_xchg(atomic_t *v, int new)
6582 +{
6583 + return xchg(&v->counter, new);
6584 +}
6585 +
6586 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6587 +{
6588 + return xchg(&(v->counter), new);
6589 +}
6590
6591 /**
6592 * __atomic_add_unless - add unless the number is a given value
6593 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6594
6595 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6596 #define atomic_inc_return(v) atomic_add_return(1, (v))
6597 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6598 +{
6599 + return atomic_add_return_unchecked(1, v);
6600 +}
6601
6602 /*
6603 * atomic_sub_and_test - subtract value from variable and test result
6604 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6605 * other cases.
6606 */
6607 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6608 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6609 +{
6610 + return atomic_add_return_unchecked(1, v) == 0;
6611 +}
6612
6613 /*
6614 * atomic_dec_and_test - decrement by 1 and test
6615 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6616 * Atomically increments @v by 1.
6617 */
6618 #define atomic_inc(v) atomic_add(1, (v))
6619 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6620 +{
6621 + atomic_add_unchecked(1, v);
6622 +}
6623
6624 /*
6625 * atomic_dec - decrement and test
6626 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6627 * Atomically decrements @v by 1.
6628 */
6629 #define atomic_dec(v) atomic_sub(1, (v))
6630 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6631 +{
6632 + atomic_sub_unchecked(1, v);
6633 +}
6634
6635 /*
6636 * atomic_add_negative - add and test if negative
6637 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6638 * @v: pointer of type atomic64_t
6639 *
6640 */
6641 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6642 +static inline long atomic64_read(const atomic64_t *v)
6643 +{
6644 + return (*(volatile const long *) &v->counter);
6645 +}
6646 +
6647 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6648 +{
6649 + return (*(volatile const long *) &v->counter);
6650 +}
6651
6652 /*
6653 * atomic64_set - set atomic variable
6654 * @v: pointer of type atomic64_t
6655 * @i: required value
6656 */
6657 -#define atomic64_set(v, i) ((v)->counter = (i))
6658 +static inline void atomic64_set(atomic64_t *v, long i)
6659 +{
6660 + v->counter = i;
6661 +}
6662 +
6663 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6664 +{
6665 + v->counter = i;
6666 +}
6667
6668 /*
6669 * atomic64_add - add integer to atomic variable
6670 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6671 *
6672 * Atomically adds @i to @v.
6673 */
6674 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6675 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6676 +{
6677 + long temp;
6678 +
6679 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6680 + __asm__ __volatile__(
6681 + " .set mips3 \n"
6682 + "1: lld %0, %1 # atomic64_add \n"
6683 +#ifdef CONFIG_PAX_REFCOUNT
6684 + /* Exception on overflow. */
6685 + "2: dadd %0, %2 \n"
6686 +#else
6687 + " daddu %0, %2 \n"
6688 +#endif
6689 + " scd %0, %1 \n"
6690 + " beqzl %0, 1b \n"
6691 +#ifdef CONFIG_PAX_REFCOUNT
6692 + "3: \n"
6693 + _ASM_EXTABLE(2b, 3b)
6694 +#endif
6695 + " .set mips0 \n"
6696 + : "=&r" (temp), "+m" (v->counter)
6697 + : "Ir" (i));
6698 + } else if (kernel_uses_llsc) {
6699 + __asm__ __volatile__(
6700 + " .set mips3 \n"
6701 + "1: lld %0, %1 # atomic64_add \n"
6702 +#ifdef CONFIG_PAX_REFCOUNT
6703 + /* Exception on overflow. */
6704 + "2: dadd %0, %2 \n"
6705 +#else
6706 + " daddu %0, %2 \n"
6707 +#endif
6708 + " scd %0, %1 \n"
6709 + " beqz %0, 1b \n"
6710 +#ifdef CONFIG_PAX_REFCOUNT
6711 + "3: \n"
6712 + _ASM_EXTABLE(2b, 3b)
6713 +#endif
6714 + " .set mips0 \n"
6715 + : "=&r" (temp), "+m" (v->counter)
6716 + : "Ir" (i));
6717 + } else {
6718 + unsigned long flags;
6719 +
6720 + raw_local_irq_save(flags);
6721 + __asm__ __volatile__(
6722 +#ifdef CONFIG_PAX_REFCOUNT
6723 + /* Exception on overflow. */
6724 + "1: dadd %0, %1 \n"
6725 + "2: \n"
6726 + _ASM_EXTABLE(1b, 2b)
6727 +#else
6728 + " daddu %0, %1 \n"
6729 +#endif
6730 + : "+r" (v->counter) : "Ir" (i));
6731 + raw_local_irq_restore(flags);
6732 + }
6733 +}
6734 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6735 {
6736 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6737 long temp;
6738 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6739 *
6740 * Atomically subtracts @i from @v.
6741 */
6742 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6743 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6744 +{
6745 + long temp;
6746 +
6747 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6748 + __asm__ __volatile__(
6749 + " .set mips3 \n"
6750 + "1: lld %0, %1 # atomic64_sub \n"
6751 +#ifdef CONFIG_PAX_REFCOUNT
6752 + /* Exception on overflow. */
6753 + "2: dsub %0, %2 \n"
6754 +#else
6755 + " dsubu %0, %2 \n"
6756 +#endif
6757 + " scd %0, %1 \n"
6758 + " beqzl %0, 1b \n"
6759 +#ifdef CONFIG_PAX_REFCOUNT
6760 + "3: \n"
6761 + _ASM_EXTABLE(2b, 3b)
6762 +#endif
6763 + " .set mips0 \n"
6764 + : "=&r" (temp), "+m" (v->counter)
6765 + : "Ir" (i));
6766 + } else if (kernel_uses_llsc) {
6767 + __asm__ __volatile__(
6768 + " .set mips3 \n"
6769 + "1: lld %0, %1 # atomic64_sub \n"
6770 +#ifdef CONFIG_PAX_REFCOUNT
6771 + /* Exception on overflow. */
6772 + "2: dsub %0, %2 \n"
6773 +#else
6774 + " dsubu %0, %2 \n"
6775 +#endif
6776 + " scd %0, %1 \n"
6777 + " beqz %0, 1b \n"
6778 +#ifdef CONFIG_PAX_REFCOUNT
6779 + "3: \n"
6780 + _ASM_EXTABLE(2b, 3b)
6781 +#endif
6782 + " .set mips0 \n"
6783 + : "=&r" (temp), "+m" (v->counter)
6784 + : "Ir" (i));
6785 + } else {
6786 + unsigned long flags;
6787 +
6788 + raw_local_irq_save(flags);
6789 + __asm__ __volatile__(
6790 +#ifdef CONFIG_PAX_REFCOUNT
6791 + /* Exception on overflow. */
6792 + "1: dsub %0, %1 \n"
6793 + "2: \n"
6794 + _ASM_EXTABLE(1b, 2b)
6795 +#else
6796 + " dsubu %0, %1 \n"
6797 +#endif
6798 + : "+r" (v->counter) : "Ir" (i));
6799 + raw_local_irq_restore(flags);
6800 + }
6801 +}
6802 +
6803 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6804 {
6805 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6806 long temp;
6807 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6808 /*
6809 * Same as above, but return the result value
6810 */
6811 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6812 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6813 +{
6814 + long result;
6815 + long temp;
6816 +
6817 + smp_mb__before_llsc();
6818 +
6819 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6820 + __asm__ __volatile__(
6821 + " .set mips3 \n"
6822 + "1: lld %1, %2 # atomic64_add_return \n"
6823 +#ifdef CONFIG_PAX_REFCOUNT
6824 + "2: dadd %0, %1, %3 \n"
6825 +#else
6826 + " daddu %0, %1, %3 \n"
6827 +#endif
6828 + " scd %0, %2 \n"
6829 + " beqzl %0, 1b \n"
6830 +#ifdef CONFIG_PAX_REFCOUNT
6831 + " b 4f \n"
6832 + " .set noreorder \n"
6833 + "3: b 5f \n"
6834 + " move %0, %1 \n"
6835 + " .set reorder \n"
6836 + _ASM_EXTABLE(2b, 3b)
6837 +#endif
6838 + "4: daddu %0, %1, %3 \n"
6839 +#ifdef CONFIG_PAX_REFCOUNT
6840 + "5: \n"
6841 +#endif
6842 + " .set mips0 \n"
6843 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6844 + : "Ir" (i));
6845 + } else if (kernel_uses_llsc) {
6846 + __asm__ __volatile__(
6847 + " .set mips3 \n"
6848 + "1: lld %1, %2 # atomic64_add_return \n"
6849 +#ifdef CONFIG_PAX_REFCOUNT
6850 + "2: dadd %0, %1, %3 \n"
6851 +#else
6852 + " daddu %0, %1, %3 \n"
6853 +#endif
6854 + " scd %0, %2 \n"
6855 + " bnez %0, 4f \n"
6856 + " b 1b \n"
6857 +#ifdef CONFIG_PAX_REFCOUNT
6858 + " .set noreorder \n"
6859 + "3: b 5f \n"
6860 + " move %0, %1 \n"
6861 + " .set reorder \n"
6862 + _ASM_EXTABLE(2b, 3b)
6863 +#endif
6864 + "4: daddu %0, %1, %3 \n"
6865 +#ifdef CONFIG_PAX_REFCOUNT
6866 + "5: \n"
6867 +#endif
6868 + " .set mips0 \n"
6869 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6870 + : "Ir" (i), "m" (v->counter)
6871 + : "memory");
6872 + } else {
6873 + unsigned long flags;
6874 +
6875 + raw_local_irq_save(flags);
6876 + __asm__ __volatile__(
6877 + " ld %0, %1 \n"
6878 +#ifdef CONFIG_PAX_REFCOUNT
6879 + /* Exception on overflow. */
6880 + "1: dadd %0, %2 \n"
6881 +#else
6882 + " daddu %0, %2 \n"
6883 +#endif
6884 + " sd %0, %1 \n"
6885 +#ifdef CONFIG_PAX_REFCOUNT
6886 + /* Note: Dest reg is not modified on overflow */
6887 + "2: \n"
6888 + _ASM_EXTABLE(1b, 2b)
6889 +#endif
6890 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6891 + raw_local_irq_restore(flags);
6892 + }
6893 +
6894 + smp_llsc_mb();
6895 +
6896 + return result;
6897 +}
6898 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6899 {
6900 long result;
6901
6902 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6903 return result;
6904 }
6905
6906 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6907 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6908 +{
6909 + long result;
6910 + long temp;
6911 +
6912 + smp_mb__before_llsc();
6913 +
6914 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6915 + long temp;
6916 +
6917 + __asm__ __volatile__(
6918 + " .set mips3 \n"
6919 + "1: lld %1, %2 # atomic64_sub_return \n"
6920 +#ifdef CONFIG_PAX_REFCOUNT
6921 + "2: dsub %0, %1, %3 \n"
6922 +#else
6923 + " dsubu %0, %1, %3 \n"
6924 +#endif
6925 + " scd %0, %2 \n"
6926 + " beqzl %0, 1b \n"
6927 +#ifdef CONFIG_PAX_REFCOUNT
6928 + " b 4f \n"
6929 + " .set noreorder \n"
6930 + "3: b 5f \n"
6931 + " move %0, %1 \n"
6932 + " .set reorder \n"
6933 + _ASM_EXTABLE(2b, 3b)
6934 +#endif
6935 + "4: dsubu %0, %1, %3 \n"
6936 +#ifdef CONFIG_PAX_REFCOUNT
6937 + "5: \n"
6938 +#endif
6939 + " .set mips0 \n"
6940 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6941 + : "Ir" (i), "m" (v->counter)
6942 + : "memory");
6943 + } else if (kernel_uses_llsc) {
6944 + __asm__ __volatile__(
6945 + " .set mips3 \n"
6946 + "1: lld %1, %2 # atomic64_sub_return \n"
6947 +#ifdef CONFIG_PAX_REFCOUNT
6948 + "2: dsub %0, %1, %3 \n"
6949 +#else
6950 + " dsubu %0, %1, %3 \n"
6951 +#endif
6952 + " scd %0, %2 \n"
6953 + " bnez %0, 4f \n"
6954 + " b 1b \n"
6955 +#ifdef CONFIG_PAX_REFCOUNT
6956 + " .set noreorder \n"
6957 + "3: b 5f \n"
6958 + " move %0, %1 \n"
6959 + " .set reorder \n"
6960 + _ASM_EXTABLE(2b, 3b)
6961 +#endif
6962 + "4: dsubu %0, %1, %3 \n"
6963 +#ifdef CONFIG_PAX_REFCOUNT
6964 + "5: \n"
6965 +#endif
6966 + " .set mips0 \n"
6967 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6968 + : "Ir" (i), "m" (v->counter)
6969 + : "memory");
6970 + } else {
6971 + unsigned long flags;
6972 +
6973 + raw_local_irq_save(flags);
6974 + __asm__ __volatile__(
6975 + " ld %0, %1 \n"
6976 +#ifdef CONFIG_PAX_REFCOUNT
6977 + /* Exception on overflow. */
6978 + "1: dsub %0, %2 \n"
6979 +#else
6980 + " dsubu %0, %2 \n"
6981 +#endif
6982 + " sd %0, %1 \n"
6983 +#ifdef CONFIG_PAX_REFCOUNT
6984 + /* Note: Dest reg is not modified on overflow */
6985 + "2: \n"
6986 + _ASM_EXTABLE(1b, 2b)
6987 +#endif
6988 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6989 + raw_local_irq_restore(flags);
6990 + }
6991 +
6992 + smp_llsc_mb();
6993 +
6994 + return result;
6995 +}
6996 +
6997 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6998 {
6999 long result;
7000
7001 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
7002 * Atomically test @v and subtract @i if @v is greater or equal than @i.
7003 * The function returns the old value of @v minus @i.
7004 */
7005 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
7006 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
7007 {
7008 long result;
7009
7010 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
7011 return result;
7012 }
7013
7014 -#define atomic64_cmpxchg(v, o, n) \
7015 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7016 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
7017 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
7018 +{
7019 + return cmpxchg(&v->counter, old, new);
7020 +}
7021 +
7022 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
7023 + long new)
7024 +{
7025 + return cmpxchg(&(v->counter), old, new);
7026 +}
7027 +
7028 +static inline long atomic64_xchg(atomic64_t *v, long new)
7029 +{
7030 + return xchg(&v->counter, new);
7031 +}
7032 +
7033 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7034 +{
7035 + return xchg(&(v->counter), new);
7036 +}
7037
7038 /**
7039 * atomic64_add_unless - add unless the number is a given value
7040 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7041
7042 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
7043 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
7044 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
7045
7046 /*
7047 * atomic64_sub_and_test - subtract value from variable and test result
7048 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7049 * other cases.
7050 */
7051 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7052 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
7053
7054 /*
7055 * atomic64_dec_and_test - decrement by 1 and test
7056 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7057 * Atomically increments @v by 1.
7058 */
7059 #define atomic64_inc(v) atomic64_add(1, (v))
7060 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
7061
7062 /*
7063 * atomic64_dec - decrement and test
7064 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7065 * Atomically decrements @v by 1.
7066 */
7067 #define atomic64_dec(v) atomic64_sub(1, (v))
7068 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
7069
7070 /*
7071 * atomic64_add_negative - add and test if negative
7072 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
7073 index d0101dd..266982c 100644
7074 --- a/arch/mips/include/asm/barrier.h
7075 +++ b/arch/mips/include/asm/barrier.h
7076 @@ -184,7 +184,7 @@
7077 do { \
7078 compiletime_assert_atomic_type(*p); \
7079 smp_mb(); \
7080 - ACCESS_ONCE(*p) = (v); \
7081 + ACCESS_ONCE_RW(*p) = (v); \
7082 } while (0)
7083
7084 #define smp_load_acquire(p) \
7085 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
7086 index b4db69f..8f3b093 100644
7087 --- a/arch/mips/include/asm/cache.h
7088 +++ b/arch/mips/include/asm/cache.h
7089 @@ -9,10 +9,11 @@
7090 #ifndef _ASM_CACHE_H
7091 #define _ASM_CACHE_H
7092
7093 +#include <linux/const.h>
7094 #include <kmalloc.h>
7095
7096 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
7097 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7098 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7099
7100 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
7101 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7102 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
7103 index d414405..6bb4ba2 100644
7104 --- a/arch/mips/include/asm/elf.h
7105 +++ b/arch/mips/include/asm/elf.h
7106 @@ -398,13 +398,16 @@ extern const char *__elf_platform;
7107 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
7108 #endif
7109
7110 +#ifdef CONFIG_PAX_ASLR
7111 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7112 +
7113 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7114 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7115 +#endif
7116 +
7117 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7118 struct linux_binprm;
7119 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7120 int uses_interp);
7121
7122 -struct mm_struct;
7123 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7124 -#define arch_randomize_brk arch_randomize_brk
7125 -
7126 #endif /* _ASM_ELF_H */
7127 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
7128 index c1f6afa..38cc6e9 100644
7129 --- a/arch/mips/include/asm/exec.h
7130 +++ b/arch/mips/include/asm/exec.h
7131 @@ -12,6 +12,6 @@
7132 #ifndef _ASM_EXEC_H
7133 #define _ASM_EXEC_H
7134
7135 -extern unsigned long arch_align_stack(unsigned long sp);
7136 +#define arch_align_stack(x) ((x) & ~0xfUL)
7137
7138 #endif /* _ASM_EXEC_H */
7139 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
7140 index 9e8ef59..1139d6b 100644
7141 --- a/arch/mips/include/asm/hw_irq.h
7142 +++ b/arch/mips/include/asm/hw_irq.h
7143 @@ -10,7 +10,7 @@
7144
7145 #include <linux/atomic.h>
7146
7147 -extern atomic_t irq_err_count;
7148 +extern atomic_unchecked_t irq_err_count;
7149
7150 /*
7151 * interrupt-retrigger: NOP for now. This may not be appropriate for all
7152 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
7153 index 46dfc3c..a16b13a 100644
7154 --- a/arch/mips/include/asm/local.h
7155 +++ b/arch/mips/include/asm/local.h
7156 @@ -12,15 +12,25 @@ typedef struct
7157 atomic_long_t a;
7158 } local_t;
7159
7160 +typedef struct {
7161 + atomic_long_unchecked_t a;
7162 +} local_unchecked_t;
7163 +
7164 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
7165
7166 #define local_read(l) atomic_long_read(&(l)->a)
7167 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
7168 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
7169 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
7170
7171 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
7172 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
7173 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
7174 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
7175 #define local_inc(l) atomic_long_inc(&(l)->a)
7176 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
7177 #define local_dec(l) atomic_long_dec(&(l)->a)
7178 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
7179
7180 /*
7181 * Same as above, but return the result value
7182 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
7183 return result;
7184 }
7185
7186 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
7187 +{
7188 + unsigned long result;
7189 +
7190 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
7191 + unsigned long temp;
7192 +
7193 + __asm__ __volatile__(
7194 + " .set mips3 \n"
7195 + "1:" __LL "%1, %2 # local_add_return \n"
7196 + " addu %0, %1, %3 \n"
7197 + __SC "%0, %2 \n"
7198 + " beqzl %0, 1b \n"
7199 + " addu %0, %1, %3 \n"
7200 + " .set mips0 \n"
7201 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
7202 + : "Ir" (i), "m" (l->a.counter)
7203 + : "memory");
7204 + } else if (kernel_uses_llsc) {
7205 + unsigned long temp;
7206 +
7207 + __asm__ __volatile__(
7208 + " .set mips3 \n"
7209 + "1:" __LL "%1, %2 # local_add_return \n"
7210 + " addu %0, %1, %3 \n"
7211 + __SC "%0, %2 \n"
7212 + " beqz %0, 1b \n"
7213 + " addu %0, %1, %3 \n"
7214 + " .set mips0 \n"
7215 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
7216 + : "Ir" (i), "m" (l->a.counter)
7217 + : "memory");
7218 + } else {
7219 + unsigned long flags;
7220 +
7221 + local_irq_save(flags);
7222 + result = l->a.counter;
7223 + result += i;
7224 + l->a.counter = result;
7225 + local_irq_restore(flags);
7226 + }
7227 +
7228 + return result;
7229 +}
7230 +
7231 static __inline__ long local_sub_return(long i, local_t * l)
7232 {
7233 unsigned long result;
7234 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
7235
7236 #define local_cmpxchg(l, o, n) \
7237 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
7238 +#define local_cmpxchg_unchecked(l, o, n) \
7239 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
7240 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
7241
7242 /**
7243 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
7244 index 5699ec3..95def83 100644
7245 --- a/arch/mips/include/asm/page.h
7246 +++ b/arch/mips/include/asm/page.h
7247 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
7248 #ifdef CONFIG_CPU_MIPS32
7249 typedef struct { unsigned long pte_low, pte_high; } pte_t;
7250 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
7251 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
7252 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
7253 #else
7254 typedef struct { unsigned long long pte; } pte_t;
7255 #define pte_val(x) ((x).pte)
7256 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
7257 index b336037..5b874cc 100644
7258 --- a/arch/mips/include/asm/pgalloc.h
7259 +++ b/arch/mips/include/asm/pgalloc.h
7260 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7261 {
7262 set_pud(pud, __pud((unsigned long)pmd));
7263 }
7264 +
7265 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7266 +{
7267 + pud_populate(mm, pud, pmd);
7268 +}
7269 #endif
7270
7271 /*
7272 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
7273 index 539ddd1..8783f9a 100644
7274 --- a/arch/mips/include/asm/pgtable.h
7275 +++ b/arch/mips/include/asm/pgtable.h
7276 @@ -20,6 +20,9 @@
7277 #include <asm/io.h>
7278 #include <asm/pgtable-bits.h>
7279
7280 +#define ktla_ktva(addr) (addr)
7281 +#define ktva_ktla(addr) (addr)
7282 +
7283 struct mm_struct;
7284 struct vm_area_struct;
7285
7286 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
7287 index 7de8658..c109224 100644
7288 --- a/arch/mips/include/asm/thread_info.h
7289 +++ b/arch/mips/include/asm/thread_info.h
7290 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
7291 #define TIF_SECCOMP 4 /* secure computing */
7292 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
7293 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
7294 +/* li takes a 32bit immediate */
7295 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
7296 +
7297 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
7298 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
7299 #define TIF_NOHZ 19 /* in adaptive nohz mode */
7300 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
7301 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
7302 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
7303 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7304 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7305
7306 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
7307 _TIF_SYSCALL_AUDIT | \
7308 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
7309 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
7310 + _TIF_GRSEC_SETXID)
7311
7312 /* work to do in syscall_trace_leave() */
7313 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
7314 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
7315 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7316
7317 /* work to do on interrupt/exception return */
7318 #define _TIF_WORK_MASK \
7319 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
7320 /* work to do on any return to u-space */
7321 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
7322 _TIF_WORK_SYSCALL_EXIT | \
7323 - _TIF_SYSCALL_TRACEPOINT)
7324 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7325
7326 /*
7327 * We stash processor id into a COP0 register to retrieve it fast
7328 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
7329 index a109510..94ee3f6 100644
7330 --- a/arch/mips/include/asm/uaccess.h
7331 +++ b/arch/mips/include/asm/uaccess.h
7332 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
7333 __ok == 0; \
7334 })
7335
7336 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
7337 #define access_ok(type, addr, size) \
7338 likely(__access_ok((addr), (size), __access_mask))
7339
7340 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
7341 index 1188e00..41cf144 100644
7342 --- a/arch/mips/kernel/binfmt_elfn32.c
7343 +++ b/arch/mips/kernel/binfmt_elfn32.c
7344 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7345 #undef ELF_ET_DYN_BASE
7346 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7347
7348 +#ifdef CONFIG_PAX_ASLR
7349 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7350 +
7351 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7352 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7353 +#endif
7354 +
7355 #include <asm/processor.h>
7356 #include <linux/module.h>
7357 #include <linux/elfcore.h>
7358 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
7359 index 7faf5f2..f3d3cf4 100644
7360 --- a/arch/mips/kernel/binfmt_elfo32.c
7361 +++ b/arch/mips/kernel/binfmt_elfo32.c
7362 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7363 #undef ELF_ET_DYN_BASE
7364 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7365
7366 +#ifdef CONFIG_PAX_ASLR
7367 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7368 +
7369 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7370 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7371 +#endif
7372 +
7373 #include <asm/processor.h>
7374
7375 /*
7376 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
7377 index 50b3648..c2f3cec 100644
7378 --- a/arch/mips/kernel/i8259.c
7379 +++ b/arch/mips/kernel/i8259.c
7380 @@ -201,7 +201,7 @@ spurious_8259A_irq:
7381 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
7382 spurious_irq_mask |= irqmask;
7383 }
7384 - atomic_inc(&irq_err_count);
7385 + atomic_inc_unchecked(&irq_err_count);
7386 /*
7387 * Theoretically we do not have to handle this IRQ,
7388 * but in Linux this does not cause problems and is
7389 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
7390 index 44a1f79..2bd6aa3 100644
7391 --- a/arch/mips/kernel/irq-gt641xx.c
7392 +++ b/arch/mips/kernel/irq-gt641xx.c
7393 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
7394 }
7395 }
7396
7397 - atomic_inc(&irq_err_count);
7398 + atomic_inc_unchecked(&irq_err_count);
7399 }
7400
7401 void __init gt641xx_irq_init(void)
7402 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
7403 index d2bfbc2..a8eacd2 100644
7404 --- a/arch/mips/kernel/irq.c
7405 +++ b/arch/mips/kernel/irq.c
7406 @@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
7407 printk("unexpected IRQ # %d\n", irq);
7408 }
7409
7410 -atomic_t irq_err_count;
7411 +atomic_unchecked_t irq_err_count;
7412
7413 int arch_show_interrupts(struct seq_file *p, int prec)
7414 {
7415 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
7416 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
7417 return 0;
7418 }
7419
7420 asmlinkage void spurious_interrupt(void)
7421 {
7422 - atomic_inc(&irq_err_count);
7423 + atomic_inc_unchecked(&irq_err_count);
7424 }
7425
7426 void __init init_IRQ(void)
7427 @@ -109,7 +109,10 @@ void __init init_IRQ(void)
7428 #endif
7429 }
7430
7431 +
7432 #ifdef DEBUG_STACKOVERFLOW
7433 +extern void gr_handle_kernel_exploit(void);
7434 +
7435 static inline void check_stack_overflow(void)
7436 {
7437 unsigned long sp;
7438 @@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
7439 printk("do_IRQ: stack overflow: %ld\n",
7440 sp - sizeof(struct thread_info));
7441 dump_stack();
7442 + gr_handle_kernel_exploit();
7443 }
7444 }
7445 #else
7446 diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
7447 index c4c2069..bde8051 100644
7448 --- a/arch/mips/kernel/pm-cps.c
7449 +++ b/arch/mips/kernel/pm-cps.c
7450 @@ -168,7 +168,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
7451 nc_core_ready_count = nc_addr;
7452
7453 /* Ensure ready_count is zero-initialised before the assembly runs */
7454 - ACCESS_ONCE(*nc_core_ready_count) = 0;
7455 + ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
7456 coupled_barrier(&per_cpu(pm_barrier, core), online);
7457
7458 /* Run the generated entry code */
7459 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
7460 index 0a1ec0f..d9e93b6 100644
7461 --- a/arch/mips/kernel/process.c
7462 +++ b/arch/mips/kernel/process.c
7463 @@ -572,15 +572,3 @@ unsigned long get_wchan(struct task_struct *task)
7464 out:
7465 return pc;
7466 }
7467 -
7468 -/*
7469 - * Don't forget that the stack pointer must be aligned on a 8 bytes
7470 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
7471 - */
7472 -unsigned long arch_align_stack(unsigned long sp)
7473 -{
7474 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7475 - sp -= get_random_int() & ~PAGE_MASK;
7476 -
7477 - return sp & ALMASK;
7478 -}
7479 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
7480 index f639ccd..e4b110d 100644
7481 --- a/arch/mips/kernel/ptrace.c
7482 +++ b/arch/mips/kernel/ptrace.c
7483 @@ -630,6 +630,10 @@ long arch_ptrace(struct task_struct *child, long request,
7484 return ret;
7485 }
7486
7487 +#ifdef CONFIG_GRKERNSEC_SETXID
7488 +extern void gr_delayed_cred_worker(void);
7489 +#endif
7490 +
7491 /*
7492 * Notification of system call entry/exit
7493 * - triggered by current->work.syscall_trace
7494 @@ -646,6 +650,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
7495 tracehook_report_syscall_entry(regs))
7496 ret = -1;
7497
7498 +#ifdef CONFIG_GRKERNSEC_SETXID
7499 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7500 + gr_delayed_cred_worker();
7501 +#endif
7502 +
7503 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7504 trace_sys_enter(regs, regs->regs[2]);
7505
7506 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
7507 index 07fc524..b9d7f28 100644
7508 --- a/arch/mips/kernel/reset.c
7509 +++ b/arch/mips/kernel/reset.c
7510 @@ -13,6 +13,7 @@
7511 #include <linux/reboot.h>
7512
7513 #include <asm/reboot.h>
7514 +#include <asm/bug.h>
7515
7516 /*
7517 * Urgs ... Too many MIPS machines to handle this in a generic way.
7518 @@ -29,16 +30,19 @@ void machine_restart(char *command)
7519 {
7520 if (_machine_restart)
7521 _machine_restart(command);
7522 + BUG();
7523 }
7524
7525 void machine_halt(void)
7526 {
7527 if (_machine_halt)
7528 _machine_halt();
7529 + BUG();
7530 }
7531
7532 void machine_power_off(void)
7533 {
7534 if (pm_power_off)
7535 pm_power_off();
7536 + BUG();
7537 }
7538 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7539 index 2242bdd..b284048 100644
7540 --- a/arch/mips/kernel/sync-r4k.c
7541 +++ b/arch/mips/kernel/sync-r4k.c
7542 @@ -18,8 +18,8 @@
7543 #include <asm/mipsregs.h>
7544
7545 static atomic_t count_start_flag = ATOMIC_INIT(0);
7546 -static atomic_t count_count_start = ATOMIC_INIT(0);
7547 -static atomic_t count_count_stop = ATOMIC_INIT(0);
7548 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7549 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7550 static atomic_t count_reference = ATOMIC_INIT(0);
7551
7552 #define COUNTON 100
7553 @@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
7554
7555 for (i = 0; i < NR_LOOPS; i++) {
7556 /* slaves loop on '!= 2' */
7557 - while (atomic_read(&count_count_start) != 1)
7558 + while (atomic_read_unchecked(&count_count_start) != 1)
7559 mb();
7560 - atomic_set(&count_count_stop, 0);
7561 + atomic_set_unchecked(&count_count_stop, 0);
7562 smp_wmb();
7563
7564 /* this lets the slaves write their count register */
7565 - atomic_inc(&count_count_start);
7566 + atomic_inc_unchecked(&count_count_start);
7567
7568 /*
7569 * Everyone initialises count in the last loop:
7570 @@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
7571 /*
7572 * Wait for all slaves to leave the synchronization point:
7573 */
7574 - while (atomic_read(&count_count_stop) != 1)
7575 + while (atomic_read_unchecked(&count_count_stop) != 1)
7576 mb();
7577 - atomic_set(&count_count_start, 0);
7578 + atomic_set_unchecked(&count_count_start, 0);
7579 smp_wmb();
7580 - atomic_inc(&count_count_stop);
7581 + atomic_inc_unchecked(&count_count_stop);
7582 }
7583 /* Arrange for an interrupt in a short while */
7584 write_c0_compare(read_c0_count() + COUNTON);
7585 @@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
7586 initcount = atomic_read(&count_reference);
7587
7588 for (i = 0; i < NR_LOOPS; i++) {
7589 - atomic_inc(&count_count_start);
7590 - while (atomic_read(&count_count_start) != 2)
7591 + atomic_inc_unchecked(&count_count_start);
7592 + while (atomic_read_unchecked(&count_count_start) != 2)
7593 mb();
7594
7595 /*
7596 @@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
7597 if (i == NR_LOOPS-1)
7598 write_c0_count(initcount);
7599
7600 - atomic_inc(&count_count_stop);
7601 - while (atomic_read(&count_count_stop) != 2)
7602 + atomic_inc_unchecked(&count_count_stop);
7603 + while (atomic_read_unchecked(&count_count_stop) != 2)
7604 mb();
7605 }
7606 /* Arrange for an interrupt in a short while */
7607 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7608 index 51706d6..ec1178c 100644
7609 --- a/arch/mips/kernel/traps.c
7610 +++ b/arch/mips/kernel/traps.c
7611 @@ -687,7 +687,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7612 siginfo_t info;
7613
7614 prev_state = exception_enter();
7615 - die_if_kernel("Integer overflow", regs);
7616 + if (unlikely(!user_mode(regs))) {
7617 +
7618 +#ifdef CONFIG_PAX_REFCOUNT
7619 + if (fixup_exception(regs)) {
7620 + pax_report_refcount_overflow(regs);
7621 + exception_exit(prev_state);
7622 + return;
7623 + }
7624 +#endif
7625 +
7626 + die("Integer overflow", regs);
7627 + }
7628
7629 info.si_code = FPE_INTOVF;
7630 info.si_signo = SIGFPE;
7631 diff --git a/arch/mips/kvm/kvm_mips.c b/arch/mips/kvm/kvm_mips.c
7632 index f3c56a1..6a2f01c 100644
7633 --- a/arch/mips/kvm/kvm_mips.c
7634 +++ b/arch/mips/kvm/kvm_mips.c
7635 @@ -841,7 +841,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
7636 return r;
7637 }
7638
7639 -int kvm_arch_init(void *opaque)
7640 +int kvm_arch_init(const void *opaque)
7641 {
7642 int ret;
7643
7644 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7645 index becc42b..9e43d4b 100644
7646 --- a/arch/mips/mm/fault.c
7647 +++ b/arch/mips/mm/fault.c
7648 @@ -28,6 +28,23 @@
7649 #include <asm/highmem.h> /* For VMALLOC_END */
7650 #include <linux/kdebug.h>
7651
7652 +#ifdef CONFIG_PAX_PAGEEXEC
7653 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7654 +{
7655 + unsigned long i;
7656 +
7657 + printk(KERN_ERR "PAX: bytes at PC: ");
7658 + for (i = 0; i < 5; i++) {
7659 + unsigned int c;
7660 + if (get_user(c, (unsigned int *)pc+i))
7661 + printk(KERN_CONT "???????? ");
7662 + else
7663 + printk(KERN_CONT "%08x ", c);
7664 + }
7665 + printk("\n");
7666 +}
7667 +#endif
7668 +
7669 /*
7670 * This routine handles page faults. It determines the address,
7671 * and the problem, and then passes it off to one of the appropriate
7672 @@ -199,6 +216,14 @@ bad_area:
7673 bad_area_nosemaphore:
7674 /* User mode accesses just cause a SIGSEGV */
7675 if (user_mode(regs)) {
7676 +
7677 +#ifdef CONFIG_PAX_PAGEEXEC
7678 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7679 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7680 + do_group_exit(SIGKILL);
7681 + }
7682 +#endif
7683 +
7684 tsk->thread.cp0_badvaddr = address;
7685 tsk->thread.error_code = write;
7686 #if 0
7687 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7688 index f1baadd..5472dca 100644
7689 --- a/arch/mips/mm/mmap.c
7690 +++ b/arch/mips/mm/mmap.c
7691 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7692 struct vm_area_struct *vma;
7693 unsigned long addr = addr0;
7694 int do_color_align;
7695 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7696 struct vm_unmapped_area_info info;
7697
7698 if (unlikely(len > TASK_SIZE))
7699 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7700 do_color_align = 1;
7701
7702 /* requesting a specific address */
7703 +
7704 +#ifdef CONFIG_PAX_RANDMMAP
7705 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7706 +#endif
7707 +
7708 if (addr) {
7709 if (do_color_align)
7710 addr = COLOUR_ALIGN(addr, pgoff);
7711 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7712 addr = PAGE_ALIGN(addr);
7713
7714 vma = find_vma(mm, addr);
7715 - if (TASK_SIZE - len >= addr &&
7716 - (!vma || addr + len <= vma->vm_start))
7717 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7718 return addr;
7719 }
7720
7721 info.length = len;
7722 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7723 info.align_offset = pgoff << PAGE_SHIFT;
7724 + info.threadstack_offset = offset;
7725
7726 if (dir == DOWN) {
7727 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7728 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7729 {
7730 unsigned long random_factor = 0UL;
7731
7732 +#ifdef CONFIG_PAX_RANDMMAP
7733 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7734 +#endif
7735 +
7736 if (current->flags & PF_RANDOMIZE) {
7737 random_factor = get_random_int();
7738 random_factor = random_factor << PAGE_SHIFT;
7739 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7740
7741 if (mmap_is_legacy()) {
7742 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7743 +
7744 +#ifdef CONFIG_PAX_RANDMMAP
7745 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7746 + mm->mmap_base += mm->delta_mmap;
7747 +#endif
7748 +
7749 mm->get_unmapped_area = arch_get_unmapped_area;
7750 } else {
7751 mm->mmap_base = mmap_base(random_factor);
7752 +
7753 +#ifdef CONFIG_PAX_RANDMMAP
7754 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7755 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7756 +#endif
7757 +
7758 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7759 }
7760 }
7761
7762 -static inline unsigned long brk_rnd(void)
7763 -{
7764 - unsigned long rnd = get_random_int();
7765 -
7766 - rnd = rnd << PAGE_SHIFT;
7767 - /* 8MB for 32bit, 256MB for 64bit */
7768 - if (TASK_IS_32BIT_ADDR)
7769 - rnd = rnd & 0x7ffffful;
7770 - else
7771 - rnd = rnd & 0xffffffful;
7772 -
7773 - return rnd;
7774 -}
7775 -
7776 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7777 -{
7778 - unsigned long base = mm->brk;
7779 - unsigned long ret;
7780 -
7781 - ret = PAGE_ALIGN(base + brk_rnd());
7782 -
7783 - if (ret < mm->brk)
7784 - return mm->brk;
7785 -
7786 - return ret;
7787 -}
7788 -
7789 int __virt_addr_valid(const volatile void *kaddr)
7790 {
7791 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7792 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7793 index 59cccd9..f39ac2f 100644
7794 --- a/arch/mips/pci/pci-octeon.c
7795 +++ b/arch/mips/pci/pci-octeon.c
7796 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7797
7798
7799 static struct pci_ops octeon_pci_ops = {
7800 - octeon_read_config,
7801 - octeon_write_config,
7802 + .read = octeon_read_config,
7803 + .write = octeon_write_config,
7804 };
7805
7806 static struct resource octeon_pci_mem_resource = {
7807 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7808 index 5e36c33..eb4a17b 100644
7809 --- a/arch/mips/pci/pcie-octeon.c
7810 +++ b/arch/mips/pci/pcie-octeon.c
7811 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7812 }
7813
7814 static struct pci_ops octeon_pcie0_ops = {
7815 - octeon_pcie0_read_config,
7816 - octeon_pcie0_write_config,
7817 + .read = octeon_pcie0_read_config,
7818 + .write = octeon_pcie0_write_config,
7819 };
7820
7821 static struct resource octeon_pcie0_mem_resource = {
7822 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7823 };
7824
7825 static struct pci_ops octeon_pcie1_ops = {
7826 - octeon_pcie1_read_config,
7827 - octeon_pcie1_write_config,
7828 + .read = octeon_pcie1_read_config,
7829 + .write = octeon_pcie1_write_config,
7830 };
7831
7832 static struct resource octeon_pcie1_mem_resource = {
7833 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7834 };
7835
7836 static struct pci_ops octeon_dummy_ops = {
7837 - octeon_dummy_read_config,
7838 - octeon_dummy_write_config,
7839 + .read = octeon_dummy_read_config,
7840 + .write = octeon_dummy_write_config,
7841 };
7842
7843 static struct resource octeon_dummy_mem_resource = {
7844 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7845 index a2358b4..7cead4f 100644
7846 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7847 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7848 @@ -187,9 +187,9 @@ void
7849 cont_nmi_dump(void)
7850 {
7851 #ifndef REAL_NMI_SIGNAL
7852 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7853 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7854
7855 - atomic_inc(&nmied_cpus);
7856 + atomic_inc_unchecked(&nmied_cpus);
7857 #endif
7858 /*
7859 * Only allow 1 cpu to proceed
7860 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7861 udelay(10000);
7862 }
7863 #else
7864 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7865 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7866 #endif
7867
7868 /*
7869 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7870 index a046b30..6799527 100644
7871 --- a/arch/mips/sni/rm200.c
7872 +++ b/arch/mips/sni/rm200.c
7873 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7874 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7875 spurious_irq_mask |= irqmask;
7876 }
7877 - atomic_inc(&irq_err_count);
7878 + atomic_inc_unchecked(&irq_err_count);
7879 /*
7880 * Theoretically we do not have to handle this IRQ,
7881 * but in Linux this does not cause problems and is
7882 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7883 index 41e873b..34d33a7 100644
7884 --- a/arch/mips/vr41xx/common/icu.c
7885 +++ b/arch/mips/vr41xx/common/icu.c
7886 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7887
7888 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7889
7890 - atomic_inc(&irq_err_count);
7891 + atomic_inc_unchecked(&irq_err_count);
7892
7893 return -1;
7894 }
7895 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7896 index ae0e4ee..e8f0692 100644
7897 --- a/arch/mips/vr41xx/common/irq.c
7898 +++ b/arch/mips/vr41xx/common/irq.c
7899 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7900 irq_cascade_t *cascade;
7901
7902 if (irq >= NR_IRQS) {
7903 - atomic_inc(&irq_err_count);
7904 + atomic_inc_unchecked(&irq_err_count);
7905 return;
7906 }
7907
7908 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7909 ret = cascade->get_irq(irq);
7910 irq = ret;
7911 if (ret < 0)
7912 - atomic_inc(&irq_err_count);
7913 + atomic_inc_unchecked(&irq_err_count);
7914 else
7915 irq_dispatch(irq);
7916 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7917 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7918 index 967d144..db12197 100644
7919 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7920 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7921 @@ -11,12 +11,14 @@
7922 #ifndef _ASM_PROC_CACHE_H
7923 #define _ASM_PROC_CACHE_H
7924
7925 +#include <linux/const.h>
7926 +
7927 /* L1 cache */
7928
7929 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7930 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7931 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7932 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7933 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7934 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7935
7936 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7937 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7938 index bcb5df2..84fabd2 100644
7939 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7940 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7941 @@ -16,13 +16,15 @@
7942 #ifndef _ASM_PROC_CACHE_H
7943 #define _ASM_PROC_CACHE_H
7944
7945 +#include <linux/const.h>
7946 +
7947 /*
7948 * L1 cache
7949 */
7950 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7951 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7952 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7953 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7954 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7955 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7956
7957 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7958 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7959 index 4ce7a01..449202a 100644
7960 --- a/arch/openrisc/include/asm/cache.h
7961 +++ b/arch/openrisc/include/asm/cache.h
7962 @@ -19,11 +19,13 @@
7963 #ifndef __ASM_OPENRISC_CACHE_H
7964 #define __ASM_OPENRISC_CACHE_H
7965
7966 +#include <linux/const.h>
7967 +
7968 /* FIXME: How can we replace these with values from the CPU...
7969 * they shouldn't be hard-coded!
7970 */
7971
7972 -#define L1_CACHE_BYTES 16
7973 #define L1_CACHE_SHIFT 4
7974 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7975
7976 #endif /* __ASM_OPENRISC_CACHE_H */
7977 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7978 index 0be2db2..1b0f26d 100644
7979 --- a/arch/parisc/include/asm/atomic.h
7980 +++ b/arch/parisc/include/asm/atomic.h
7981 @@ -248,6 +248,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7982 return dec;
7983 }
7984
7985 +#define atomic64_read_unchecked(v) atomic64_read(v)
7986 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7987 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7988 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7989 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7990 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7991 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7992 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7993 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7994 +
7995 #endif /* !CONFIG_64BIT */
7996
7997
7998 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7999 index 47f11c7..3420df2 100644
8000 --- a/arch/parisc/include/asm/cache.h
8001 +++ b/arch/parisc/include/asm/cache.h
8002 @@ -5,6 +5,7 @@
8003 #ifndef __ARCH_PARISC_CACHE_H
8004 #define __ARCH_PARISC_CACHE_H
8005
8006 +#include <linux/const.h>
8007
8008 /*
8009 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
8010 @@ -15,13 +16,13 @@
8011 * just ruin performance.
8012 */
8013 #ifdef CONFIG_PA20
8014 -#define L1_CACHE_BYTES 64
8015 #define L1_CACHE_SHIFT 6
8016 #else
8017 -#define L1_CACHE_BYTES 32
8018 #define L1_CACHE_SHIFT 5
8019 #endif
8020
8021 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8022 +
8023 #ifndef __ASSEMBLY__
8024
8025 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8026 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
8027 index 3391d06..c23a2cc 100644
8028 --- a/arch/parisc/include/asm/elf.h
8029 +++ b/arch/parisc/include/asm/elf.h
8030 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
8031
8032 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
8033
8034 +#ifdef CONFIG_PAX_ASLR
8035 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
8036 +
8037 +#define PAX_DELTA_MMAP_LEN 16
8038 +#define PAX_DELTA_STACK_LEN 16
8039 +#endif
8040 +
8041 /* This yields a mask that user programs can use to figure out what
8042 instruction set this CPU supports. This could be done in user space,
8043 but it's not easy, and we've already done it here. */
8044 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
8045 index f213f5b..0af3e8e 100644
8046 --- a/arch/parisc/include/asm/pgalloc.h
8047 +++ b/arch/parisc/include/asm/pgalloc.h
8048 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
8049 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
8050 }
8051
8052 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
8053 +{
8054 + pgd_populate(mm, pgd, pmd);
8055 +}
8056 +
8057 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
8058 {
8059 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
8060 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
8061 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
8062 #define pmd_free(mm, x) do { } while (0)
8063 #define pgd_populate(mm, pmd, pte) BUG()
8064 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
8065
8066 #endif
8067
8068 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
8069 index 22b89d1..ce34230 100644
8070 --- a/arch/parisc/include/asm/pgtable.h
8071 +++ b/arch/parisc/include/asm/pgtable.h
8072 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
8073 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
8074 #define PAGE_COPY PAGE_EXECREAD
8075 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
8076 +
8077 +#ifdef CONFIG_PAX_PAGEEXEC
8078 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
8079 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
8080 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
8081 +#else
8082 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
8083 +# define PAGE_COPY_NOEXEC PAGE_COPY
8084 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
8085 +#endif
8086 +
8087 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
8088 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
8089 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
8090 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
8091 index 4006964..fcb3cc2 100644
8092 --- a/arch/parisc/include/asm/uaccess.h
8093 +++ b/arch/parisc/include/asm/uaccess.h
8094 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
8095 const void __user *from,
8096 unsigned long n)
8097 {
8098 - int sz = __compiletime_object_size(to);
8099 + size_t sz = __compiletime_object_size(to);
8100 int ret = -EFAULT;
8101
8102 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
8103 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
8104 ret = __copy_from_user(to, from, n);
8105 else
8106 copy_from_user_overflow();
8107 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
8108 index 50dfafc..b9fc230 100644
8109 --- a/arch/parisc/kernel/module.c
8110 +++ b/arch/parisc/kernel/module.c
8111 @@ -98,16 +98,38 @@
8112
8113 /* three functions to determine where in the module core
8114 * or init pieces the location is */
8115 +static inline int in_init_rx(struct module *me, void *loc)
8116 +{
8117 + return (loc >= me->module_init_rx &&
8118 + loc < (me->module_init_rx + me->init_size_rx));
8119 +}
8120 +
8121 +static inline int in_init_rw(struct module *me, void *loc)
8122 +{
8123 + return (loc >= me->module_init_rw &&
8124 + loc < (me->module_init_rw + me->init_size_rw));
8125 +}
8126 +
8127 static inline int in_init(struct module *me, void *loc)
8128 {
8129 - return (loc >= me->module_init &&
8130 - loc <= (me->module_init + me->init_size));
8131 + return in_init_rx(me, loc) || in_init_rw(me, loc);
8132 +}
8133 +
8134 +static inline int in_core_rx(struct module *me, void *loc)
8135 +{
8136 + return (loc >= me->module_core_rx &&
8137 + loc < (me->module_core_rx + me->core_size_rx));
8138 +}
8139 +
8140 +static inline int in_core_rw(struct module *me, void *loc)
8141 +{
8142 + return (loc >= me->module_core_rw &&
8143 + loc < (me->module_core_rw + me->core_size_rw));
8144 }
8145
8146 static inline int in_core(struct module *me, void *loc)
8147 {
8148 - return (loc >= me->module_core &&
8149 - loc <= (me->module_core + me->core_size));
8150 + return in_core_rx(me, loc) || in_core_rw(me, loc);
8151 }
8152
8153 static inline int in_local(struct module *me, void *loc)
8154 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
8155 }
8156
8157 /* align things a bit */
8158 - me->core_size = ALIGN(me->core_size, 16);
8159 - me->arch.got_offset = me->core_size;
8160 - me->core_size += gots * sizeof(struct got_entry);
8161 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
8162 + me->arch.got_offset = me->core_size_rw;
8163 + me->core_size_rw += gots * sizeof(struct got_entry);
8164
8165 - me->core_size = ALIGN(me->core_size, 16);
8166 - me->arch.fdesc_offset = me->core_size;
8167 - me->core_size += fdescs * sizeof(Elf_Fdesc);
8168 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
8169 + me->arch.fdesc_offset = me->core_size_rw;
8170 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
8171
8172 me->arch.got_max = gots;
8173 me->arch.fdesc_max = fdescs;
8174 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
8175
8176 BUG_ON(value == 0);
8177
8178 - got = me->module_core + me->arch.got_offset;
8179 + got = me->module_core_rw + me->arch.got_offset;
8180 for (i = 0; got[i].addr; i++)
8181 if (got[i].addr == value)
8182 goto out;
8183 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
8184 #ifdef CONFIG_64BIT
8185 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
8186 {
8187 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
8188 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
8189
8190 if (!value) {
8191 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
8192 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
8193
8194 /* Create new one */
8195 fdesc->addr = value;
8196 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
8197 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
8198 return (Elf_Addr)fdesc;
8199 }
8200 #endif /* CONFIG_64BIT */
8201 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
8202
8203 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
8204 end = table + sechdrs[me->arch.unwind_section].sh_size;
8205 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
8206 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
8207
8208 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
8209 me->arch.unwind_section, table, end, gp);
8210 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
8211 index e1ffea2..46ed66e 100644
8212 --- a/arch/parisc/kernel/sys_parisc.c
8213 +++ b/arch/parisc/kernel/sys_parisc.c
8214 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8215 unsigned long task_size = TASK_SIZE;
8216 int do_color_align, last_mmap;
8217 struct vm_unmapped_area_info info;
8218 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
8219
8220 if (len > task_size)
8221 return -ENOMEM;
8222 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8223 goto found_addr;
8224 }
8225
8226 +#ifdef CONFIG_PAX_RANDMMAP
8227 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8228 +#endif
8229 +
8230 if (addr) {
8231 if (do_color_align && last_mmap)
8232 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
8233 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8234 info.high_limit = mmap_upper_limit();
8235 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
8236 info.align_offset = shared_align_offset(last_mmap, pgoff);
8237 + info.threadstack_offset = offset;
8238 addr = vm_unmapped_area(&info);
8239
8240 found_addr:
8241 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8242 unsigned long addr = addr0;
8243 int do_color_align, last_mmap;
8244 struct vm_unmapped_area_info info;
8245 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
8246
8247 #ifdef CONFIG_64BIT
8248 /* This should only ever run for 32-bit processes. */
8249 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8250 }
8251
8252 /* requesting a specific address */
8253 +#ifdef CONFIG_PAX_RANDMMAP
8254 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8255 +#endif
8256 +
8257 if (addr) {
8258 if (do_color_align && last_mmap)
8259 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
8260 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8261 info.high_limit = mm->mmap_base;
8262 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
8263 info.align_offset = shared_align_offset(last_mmap, pgoff);
8264 + info.threadstack_offset = offset;
8265 addr = vm_unmapped_area(&info);
8266 if (!(addr & ~PAGE_MASK))
8267 goto found_addr;
8268 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8269 mm->mmap_legacy_base = mmap_legacy_base();
8270 mm->mmap_base = mmap_upper_limit();
8271
8272 +#ifdef CONFIG_PAX_RANDMMAP
8273 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
8274 + mm->mmap_legacy_base += mm->delta_mmap;
8275 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8276 + }
8277 +#endif
8278 +
8279 if (mmap_is_legacy()) {
8280 mm->mmap_base = mm->mmap_legacy_base;
8281 mm->get_unmapped_area = arch_get_unmapped_area;
8282 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
8283 index 47ee620..1107387 100644
8284 --- a/arch/parisc/kernel/traps.c
8285 +++ b/arch/parisc/kernel/traps.c
8286 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
8287
8288 down_read(&current->mm->mmap_sem);
8289 vma = find_vma(current->mm,regs->iaoq[0]);
8290 - if (vma && (regs->iaoq[0] >= vma->vm_start)
8291 - && (vma->vm_flags & VM_EXEC)) {
8292 -
8293 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
8294 fault_address = regs->iaoq[0];
8295 fault_space = regs->iasq[0];
8296
8297 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
8298 index 3ca9c11..d163ef7 100644
8299 --- a/arch/parisc/mm/fault.c
8300 +++ b/arch/parisc/mm/fault.c
8301 @@ -15,6 +15,7 @@
8302 #include <linux/sched.h>
8303 #include <linux/interrupt.h>
8304 #include <linux/module.h>
8305 +#include <linux/unistd.h>
8306
8307 #include <asm/uaccess.h>
8308 #include <asm/traps.h>
8309 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
8310 static unsigned long
8311 parisc_acctyp(unsigned long code, unsigned int inst)
8312 {
8313 - if (code == 6 || code == 16)
8314 + if (code == 6 || code == 7 || code == 16)
8315 return VM_EXEC;
8316
8317 switch (inst & 0xf0000000) {
8318 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
8319 }
8320 #endif
8321
8322 +#ifdef CONFIG_PAX_PAGEEXEC
8323 +/*
8324 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
8325 + *
8326 + * returns 1 when task should be killed
8327 + * 2 when rt_sigreturn trampoline was detected
8328 + * 3 when unpatched PLT trampoline was detected
8329 + */
8330 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8331 +{
8332 +
8333 +#ifdef CONFIG_PAX_EMUPLT
8334 + int err;
8335 +
8336 + do { /* PaX: unpatched PLT emulation */
8337 + unsigned int bl, depwi;
8338 +
8339 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
8340 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
8341 +
8342 + if (err)
8343 + break;
8344 +
8345 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
8346 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
8347 +
8348 + err = get_user(ldw, (unsigned int *)addr);
8349 + err |= get_user(bv, (unsigned int *)(addr+4));
8350 + err |= get_user(ldw2, (unsigned int *)(addr+8));
8351 +
8352 + if (err)
8353 + break;
8354 +
8355 + if (ldw == 0x0E801096U &&
8356 + bv == 0xEAC0C000U &&
8357 + ldw2 == 0x0E881095U)
8358 + {
8359 + unsigned int resolver, map;
8360 +
8361 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
8362 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
8363 + if (err)
8364 + break;
8365 +
8366 + regs->gr[20] = instruction_pointer(regs)+8;
8367 + regs->gr[21] = map;
8368 + regs->gr[22] = resolver;
8369 + regs->iaoq[0] = resolver | 3UL;
8370 + regs->iaoq[1] = regs->iaoq[0] + 4;
8371 + return 3;
8372 + }
8373 + }
8374 + } while (0);
8375 +#endif
8376 +
8377 +#ifdef CONFIG_PAX_EMUTRAMP
8378 +
8379 +#ifndef CONFIG_PAX_EMUSIGRT
8380 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
8381 + return 1;
8382 +#endif
8383 +
8384 + do { /* PaX: rt_sigreturn emulation */
8385 + unsigned int ldi1, ldi2, bel, nop;
8386 +
8387 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
8388 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
8389 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
8390 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
8391 +
8392 + if (err)
8393 + break;
8394 +
8395 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
8396 + ldi2 == 0x3414015AU &&
8397 + bel == 0xE4008200U &&
8398 + nop == 0x08000240U)
8399 + {
8400 + regs->gr[25] = (ldi1 & 2) >> 1;
8401 + regs->gr[20] = __NR_rt_sigreturn;
8402 + regs->gr[31] = regs->iaoq[1] + 16;
8403 + regs->sr[0] = regs->iasq[1];
8404 + regs->iaoq[0] = 0x100UL;
8405 + regs->iaoq[1] = regs->iaoq[0] + 4;
8406 + regs->iasq[0] = regs->sr[2];
8407 + regs->iasq[1] = regs->sr[2];
8408 + return 2;
8409 + }
8410 + } while (0);
8411 +#endif
8412 +
8413 + return 1;
8414 +}
8415 +
8416 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8417 +{
8418 + unsigned long i;
8419 +
8420 + printk(KERN_ERR "PAX: bytes at PC: ");
8421 + for (i = 0; i < 5; i++) {
8422 + unsigned int c;
8423 + if (get_user(c, (unsigned int *)pc+i))
8424 + printk(KERN_CONT "???????? ");
8425 + else
8426 + printk(KERN_CONT "%08x ", c);
8427 + }
8428 + printk("\n");
8429 +}
8430 +#endif
8431 +
8432 int fixup_exception(struct pt_regs *regs)
8433 {
8434 const struct exception_table_entry *fix;
8435 @@ -234,8 +345,33 @@ retry:
8436
8437 good_area:
8438
8439 - if ((vma->vm_flags & acc_type) != acc_type)
8440 + if ((vma->vm_flags & acc_type) != acc_type) {
8441 +
8442 +#ifdef CONFIG_PAX_PAGEEXEC
8443 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
8444 + (address & ~3UL) == instruction_pointer(regs))
8445 + {
8446 + up_read(&mm->mmap_sem);
8447 + switch (pax_handle_fetch_fault(regs)) {
8448 +
8449 +#ifdef CONFIG_PAX_EMUPLT
8450 + case 3:
8451 + return;
8452 +#endif
8453 +
8454 +#ifdef CONFIG_PAX_EMUTRAMP
8455 + case 2:
8456 + return;
8457 +#endif
8458 +
8459 + }
8460 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
8461 + do_group_exit(SIGKILL);
8462 + }
8463 +#endif
8464 +
8465 goto bad_area;
8466 + }
8467
8468 /*
8469 * If for any reason at all we couldn't handle the fault, make
8470 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
8471 index 80b94b0..a3274fb 100644
8472 --- a/arch/powerpc/Kconfig
8473 +++ b/arch/powerpc/Kconfig
8474 @@ -398,6 +398,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
8475 config KEXEC
8476 bool "kexec system call"
8477 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8478 + depends on !GRKERNSEC_KMEM
8479 help
8480 kexec is a system call that implements the ability to shutdown your
8481 current kernel, and to start another kernel. It is like a reboot
8482 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8483 index 28992d0..c797b20 100644
8484 --- a/arch/powerpc/include/asm/atomic.h
8485 +++ b/arch/powerpc/include/asm/atomic.h
8486 @@ -519,6 +519,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
8487 return t1;
8488 }
8489
8490 +#define atomic64_read_unchecked(v) atomic64_read(v)
8491 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8492 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8493 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8494 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8495 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8496 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8497 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8498 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8499 +
8500 #endif /* __powerpc64__ */
8501
8502 #endif /* __KERNEL__ */
8503 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8504 index bab79a1..4a3eabc 100644
8505 --- a/arch/powerpc/include/asm/barrier.h
8506 +++ b/arch/powerpc/include/asm/barrier.h
8507 @@ -73,7 +73,7 @@
8508 do { \
8509 compiletime_assert_atomic_type(*p); \
8510 __lwsync(); \
8511 - ACCESS_ONCE(*p) = (v); \
8512 + ACCESS_ONCE_RW(*p) = (v); \
8513 } while (0)
8514
8515 #define smp_load_acquire(p) \
8516 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8517 index ed0afc1..0332825 100644
8518 --- a/arch/powerpc/include/asm/cache.h
8519 +++ b/arch/powerpc/include/asm/cache.h
8520 @@ -3,6 +3,7 @@
8521
8522 #ifdef __KERNEL__
8523
8524 +#include <linux/const.h>
8525
8526 /* bytes per L1 cache line */
8527 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8528 @@ -22,7 +23,7 @@
8529 #define L1_CACHE_SHIFT 7
8530 #endif
8531
8532 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8533 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8534
8535 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8536
8537 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8538 index 888d8f3..66f581c 100644
8539 --- a/arch/powerpc/include/asm/elf.h
8540 +++ b/arch/powerpc/include/asm/elf.h
8541 @@ -28,8 +28,19 @@
8542 the loader. We need to make sure that it is out of the way of the program
8543 that it will "exec", and that there is sufficient room for the brk. */
8544
8545 -extern unsigned long randomize_et_dyn(unsigned long base);
8546 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8547 +#define ELF_ET_DYN_BASE (0x20000000)
8548 +
8549 +#ifdef CONFIG_PAX_ASLR
8550 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8551 +
8552 +#ifdef __powerpc64__
8553 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8554 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8555 +#else
8556 +#define PAX_DELTA_MMAP_LEN 15
8557 +#define PAX_DELTA_STACK_LEN 15
8558 +#endif
8559 +#endif
8560
8561 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8562
8563 @@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8564 (0x7ff >> (PAGE_SHIFT - 12)) : \
8565 (0x3ffff >> (PAGE_SHIFT - 12)))
8566
8567 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8568 -#define arch_randomize_brk arch_randomize_brk
8569 -
8570 -
8571 #ifdef CONFIG_SPU_BASE
8572 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8573 #define NT_SPU 1
8574 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8575 index 8196e9c..d83a9f3 100644
8576 --- a/arch/powerpc/include/asm/exec.h
8577 +++ b/arch/powerpc/include/asm/exec.h
8578 @@ -4,6 +4,6 @@
8579 #ifndef _ASM_POWERPC_EXEC_H
8580 #define _ASM_POWERPC_EXEC_H
8581
8582 -extern unsigned long arch_align_stack(unsigned long sp);
8583 +#define arch_align_stack(x) ((x) & ~0xfUL)
8584
8585 #endif /* _ASM_POWERPC_EXEC_H */
8586 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8587 index 5acabbd..7ea14fa 100644
8588 --- a/arch/powerpc/include/asm/kmap_types.h
8589 +++ b/arch/powerpc/include/asm/kmap_types.h
8590 @@ -10,7 +10,7 @@
8591 * 2 of the License, or (at your option) any later version.
8592 */
8593
8594 -#define KM_TYPE_NR 16
8595 +#define KM_TYPE_NR 17
8596
8597 #endif /* __KERNEL__ */
8598 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8599 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8600 index b8da913..60b608a 100644
8601 --- a/arch/powerpc/include/asm/local.h
8602 +++ b/arch/powerpc/include/asm/local.h
8603 @@ -9,15 +9,26 @@ typedef struct
8604 atomic_long_t a;
8605 } local_t;
8606
8607 +typedef struct
8608 +{
8609 + atomic_long_unchecked_t a;
8610 +} local_unchecked_t;
8611 +
8612 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8613
8614 #define local_read(l) atomic_long_read(&(l)->a)
8615 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8616 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8617 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8618
8619 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8620 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8621 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8622 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8623 #define local_inc(l) atomic_long_inc(&(l)->a)
8624 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8625 #define local_dec(l) atomic_long_dec(&(l)->a)
8626 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8627
8628 static __inline__ long local_add_return(long a, local_t *l)
8629 {
8630 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8631
8632 return t;
8633 }
8634 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8635
8636 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8637
8638 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8639
8640 return t;
8641 }
8642 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8643
8644 static __inline__ long local_inc_return(local_t *l)
8645 {
8646 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8647
8648 #define local_cmpxchg(l, o, n) \
8649 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8650 +#define local_cmpxchg_unchecked(l, o, n) \
8651 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8652 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8653
8654 /**
8655 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8656 index 8565c25..2865190 100644
8657 --- a/arch/powerpc/include/asm/mman.h
8658 +++ b/arch/powerpc/include/asm/mman.h
8659 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8660 }
8661 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8662
8663 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8664 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8665 {
8666 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8667 }
8668 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8669 index 32e4e21..62afb12 100644
8670 --- a/arch/powerpc/include/asm/page.h
8671 +++ b/arch/powerpc/include/asm/page.h
8672 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8673 * and needs to be executable. This means the whole heap ends
8674 * up being executable.
8675 */
8676 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8677 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8678 +#define VM_DATA_DEFAULT_FLAGS32 \
8679 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8680 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8681
8682 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8683 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8684 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8685 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8686 #endif
8687
8688 +#define ktla_ktva(addr) (addr)
8689 +#define ktva_ktla(addr) (addr)
8690 +
8691 #ifndef CONFIG_PPC_BOOK3S_64
8692 /*
8693 * Use the top bit of the higher-level page table entries to indicate whether
8694 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8695 index 88693ce..ac6f9ab 100644
8696 --- a/arch/powerpc/include/asm/page_64.h
8697 +++ b/arch/powerpc/include/asm/page_64.h
8698 @@ -153,15 +153,18 @@ do { \
8699 * stack by default, so in the absence of a PT_GNU_STACK program header
8700 * we turn execute permission off.
8701 */
8702 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8703 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8704 +#define VM_STACK_DEFAULT_FLAGS32 \
8705 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8706 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8707
8708 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8709 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8710
8711 +#ifndef CONFIG_PAX_PAGEEXEC
8712 #define VM_STACK_DEFAULT_FLAGS \
8713 (is_32bit_task() ? \
8714 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8715 +#endif
8716
8717 #include <asm-generic/getorder.h>
8718
8719 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8720 index 4b0be20..c15a27d 100644
8721 --- a/arch/powerpc/include/asm/pgalloc-64.h
8722 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8723 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8724 #ifndef CONFIG_PPC_64K_PAGES
8725
8726 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8727 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8728
8729 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8730 {
8731 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8732 pud_set(pud, (unsigned long)pmd);
8733 }
8734
8735 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8736 +{
8737 + pud_populate(mm, pud, pmd);
8738 +}
8739 +
8740 #define pmd_populate(mm, pmd, pte_page) \
8741 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8742 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8743 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8744 #endif
8745
8746 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8747 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8748
8749 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8750 pte_t *pte)
8751 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8752 index d98c1ec..9f61569 100644
8753 --- a/arch/powerpc/include/asm/pgtable.h
8754 +++ b/arch/powerpc/include/asm/pgtable.h
8755 @@ -2,6 +2,7 @@
8756 #define _ASM_POWERPC_PGTABLE_H
8757 #ifdef __KERNEL__
8758
8759 +#include <linux/const.h>
8760 #ifndef __ASSEMBLY__
8761 #include <linux/mmdebug.h>
8762 #include <asm/processor.h> /* For TASK_SIZE */
8763 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8764 index 4aad413..85d86bf 100644
8765 --- a/arch/powerpc/include/asm/pte-hash32.h
8766 +++ b/arch/powerpc/include/asm/pte-hash32.h
8767 @@ -21,6 +21,7 @@
8768 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8769 #define _PAGE_USER 0x004 /* usermode access allowed */
8770 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8771 +#define _PAGE_EXEC _PAGE_GUARDED
8772 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8773 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8774 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8775 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8776 index bffd89d..a6641ed 100644
8777 --- a/arch/powerpc/include/asm/reg.h
8778 +++ b/arch/powerpc/include/asm/reg.h
8779 @@ -251,6 +251,7 @@
8780 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8781 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8782 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8783 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8784 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8785 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8786 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8787 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8788 index 5a6614a..d89995d1 100644
8789 --- a/arch/powerpc/include/asm/smp.h
8790 +++ b/arch/powerpc/include/asm/smp.h
8791 @@ -51,7 +51,7 @@ struct smp_ops_t {
8792 int (*cpu_disable)(void);
8793 void (*cpu_die)(unsigned int nr);
8794 int (*cpu_bootable)(unsigned int nr);
8795 -};
8796 +} __no_const;
8797
8798 extern void smp_send_debugger_break(void);
8799 extern void start_secondary_resume(void);
8800 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8801 index b034ecd..af7e31f 100644
8802 --- a/arch/powerpc/include/asm/thread_info.h
8803 +++ b/arch/powerpc/include/asm/thread_info.h
8804 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8805 #if defined(CONFIG_PPC64)
8806 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8807 #endif
8808 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8809 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8810
8811 /* as above, but as bit values */
8812 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8813 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8814 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8815 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8816 #define _TIF_NOHZ (1<<TIF_NOHZ)
8817 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8818 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8819 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8820 - _TIF_NOHZ)
8821 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8822
8823 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8824 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8825 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8826 index 9485b43..3bd3c16 100644
8827 --- a/arch/powerpc/include/asm/uaccess.h
8828 +++ b/arch/powerpc/include/asm/uaccess.h
8829 @@ -58,6 +58,7 @@
8830
8831 #endif
8832
8833 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8834 #define access_ok(type, addr, size) \
8835 (__chk_user_ptr(addr), \
8836 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8837 @@ -318,52 +319,6 @@ do { \
8838 extern unsigned long __copy_tofrom_user(void __user *to,
8839 const void __user *from, unsigned long size);
8840
8841 -#ifndef __powerpc64__
8842 -
8843 -static inline unsigned long copy_from_user(void *to,
8844 - const void __user *from, unsigned long n)
8845 -{
8846 - unsigned long over;
8847 -
8848 - if (access_ok(VERIFY_READ, from, n))
8849 - return __copy_tofrom_user((__force void __user *)to, from, n);
8850 - if ((unsigned long)from < TASK_SIZE) {
8851 - over = (unsigned long)from + n - TASK_SIZE;
8852 - return __copy_tofrom_user((__force void __user *)to, from,
8853 - n - over) + over;
8854 - }
8855 - return n;
8856 -}
8857 -
8858 -static inline unsigned long copy_to_user(void __user *to,
8859 - const void *from, unsigned long n)
8860 -{
8861 - unsigned long over;
8862 -
8863 - if (access_ok(VERIFY_WRITE, to, n))
8864 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8865 - if ((unsigned long)to < TASK_SIZE) {
8866 - over = (unsigned long)to + n - TASK_SIZE;
8867 - return __copy_tofrom_user(to, (__force void __user *)from,
8868 - n - over) + over;
8869 - }
8870 - return n;
8871 -}
8872 -
8873 -#else /* __powerpc64__ */
8874 -
8875 -#define __copy_in_user(to, from, size) \
8876 - __copy_tofrom_user((to), (from), (size))
8877 -
8878 -extern unsigned long copy_from_user(void *to, const void __user *from,
8879 - unsigned long n);
8880 -extern unsigned long copy_to_user(void __user *to, const void *from,
8881 - unsigned long n);
8882 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8883 - unsigned long n);
8884 -
8885 -#endif /* __powerpc64__ */
8886 -
8887 static inline unsigned long __copy_from_user_inatomic(void *to,
8888 const void __user *from, unsigned long n)
8889 {
8890 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8891 if (ret == 0)
8892 return 0;
8893 }
8894 +
8895 + if (!__builtin_constant_p(n))
8896 + check_object_size(to, n, false);
8897 +
8898 return __copy_tofrom_user((__force void __user *)to, from, n);
8899 }
8900
8901 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8902 if (ret == 0)
8903 return 0;
8904 }
8905 +
8906 + if (!__builtin_constant_p(n))
8907 + check_object_size(from, n, true);
8908 +
8909 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8910 }
8911
8912 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8913 return __copy_to_user_inatomic(to, from, size);
8914 }
8915
8916 +#ifndef __powerpc64__
8917 +
8918 +static inline unsigned long __must_check copy_from_user(void *to,
8919 + const void __user *from, unsigned long n)
8920 +{
8921 + unsigned long over;
8922 +
8923 + if ((long)n < 0)
8924 + return n;
8925 +
8926 + if (access_ok(VERIFY_READ, from, n)) {
8927 + if (!__builtin_constant_p(n))
8928 + check_object_size(to, n, false);
8929 + return __copy_tofrom_user((__force void __user *)to, from, n);
8930 + }
8931 + if ((unsigned long)from < TASK_SIZE) {
8932 + over = (unsigned long)from + n - TASK_SIZE;
8933 + if (!__builtin_constant_p(n - over))
8934 + check_object_size(to, n - over, false);
8935 + return __copy_tofrom_user((__force void __user *)to, from,
8936 + n - over) + over;
8937 + }
8938 + return n;
8939 +}
8940 +
8941 +static inline unsigned long __must_check copy_to_user(void __user *to,
8942 + const void *from, unsigned long n)
8943 +{
8944 + unsigned long over;
8945 +
8946 + if ((long)n < 0)
8947 + return n;
8948 +
8949 + if (access_ok(VERIFY_WRITE, to, n)) {
8950 + if (!__builtin_constant_p(n))
8951 + check_object_size(from, n, true);
8952 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8953 + }
8954 + if ((unsigned long)to < TASK_SIZE) {
8955 + over = (unsigned long)to + n - TASK_SIZE;
8956 + if (!__builtin_constant_p(n))
8957 + check_object_size(from, n - over, true);
8958 + return __copy_tofrom_user(to, (__force void __user *)from,
8959 + n - over) + over;
8960 + }
8961 + return n;
8962 +}
8963 +
8964 +#else /* __powerpc64__ */
8965 +
8966 +#define __copy_in_user(to, from, size) \
8967 + __copy_tofrom_user((to), (from), (size))
8968 +
8969 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8970 +{
8971 + if ((long)n < 0 || n > INT_MAX)
8972 + return n;
8973 +
8974 + if (!__builtin_constant_p(n))
8975 + check_object_size(to, n, false);
8976 +
8977 + if (likely(access_ok(VERIFY_READ, from, n)))
8978 + n = __copy_from_user(to, from, n);
8979 + else
8980 + memset(to, 0, n);
8981 + return n;
8982 +}
8983 +
8984 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8985 +{
8986 + if ((long)n < 0 || n > INT_MAX)
8987 + return n;
8988 +
8989 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8990 + if (!__builtin_constant_p(n))
8991 + check_object_size(from, n, true);
8992 + n = __copy_to_user(to, from, n);
8993 + }
8994 + return n;
8995 +}
8996 +
8997 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8998 + unsigned long n);
8999 +
9000 +#endif /* __powerpc64__ */
9001 +
9002 extern unsigned long __clear_user(void __user *addr, unsigned long size);
9003
9004 static inline unsigned long clear_user(void __user *addr, unsigned long size)
9005 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
9006 index 670c312..60c2b52 100644
9007 --- a/arch/powerpc/kernel/Makefile
9008 +++ b/arch/powerpc/kernel/Makefile
9009 @@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
9010 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
9011 endif
9012
9013 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
9014 +
9015 obj-y := cputable.o ptrace.o syscalls.o \
9016 irq.o align.o signal_32.o pmc.o vdso.o \
9017 process.o systbl.o idle.o \
9018 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
9019 index bb9cac6..5181202 100644
9020 --- a/arch/powerpc/kernel/exceptions-64e.S
9021 +++ b/arch/powerpc/kernel/exceptions-64e.S
9022 @@ -1010,6 +1010,7 @@ storage_fault_common:
9023 std r14,_DAR(r1)
9024 std r15,_DSISR(r1)
9025 addi r3,r1,STACK_FRAME_OVERHEAD
9026 + bl save_nvgprs
9027 mr r4,r14
9028 mr r5,r15
9029 ld r14,PACA_EXGEN+EX_R14(r13)
9030 @@ -1018,8 +1019,7 @@ storage_fault_common:
9031 cmpdi r3,0
9032 bne- 1f
9033 b ret_from_except_lite
9034 -1: bl save_nvgprs
9035 - mr r5,r3
9036 +1: mr r5,r3
9037 addi r3,r1,STACK_FRAME_OVERHEAD
9038 ld r4,_DAR(r1)
9039 bl bad_page_fault
9040 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
9041 index a7d36b1..53af150 100644
9042 --- a/arch/powerpc/kernel/exceptions-64s.S
9043 +++ b/arch/powerpc/kernel/exceptions-64s.S
9044 @@ -1637,10 +1637,10 @@ handle_page_fault:
9045 11: ld r4,_DAR(r1)
9046 ld r5,_DSISR(r1)
9047 addi r3,r1,STACK_FRAME_OVERHEAD
9048 + bl save_nvgprs
9049 bl do_page_fault
9050 cmpdi r3,0
9051 beq+ 12f
9052 - bl save_nvgprs
9053 mr r5,r3
9054 addi r3,r1,STACK_FRAME_OVERHEAD
9055 lwz r4,_DAR(r1)
9056 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
9057 index 248ee7e..1eb60dd 100644
9058 --- a/arch/powerpc/kernel/irq.c
9059 +++ b/arch/powerpc/kernel/irq.c
9060 @@ -447,6 +447,8 @@ void migrate_irqs(void)
9061 }
9062 #endif
9063
9064 +extern void gr_handle_kernel_exploit(void);
9065 +
9066 static inline void check_stack_overflow(void)
9067 {
9068 #ifdef CONFIG_DEBUG_STACKOVERFLOW
9069 @@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
9070 printk("do_IRQ: stack overflow: %ld\n",
9071 sp - sizeof(struct thread_info));
9072 dump_stack();
9073 + gr_handle_kernel_exploit();
9074 }
9075 #endif
9076 }
9077 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
9078 index 6cff040..74ac5d1b 100644
9079 --- a/arch/powerpc/kernel/module_32.c
9080 +++ b/arch/powerpc/kernel/module_32.c
9081 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
9082 me->arch.core_plt_section = i;
9083 }
9084 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
9085 - printk("Module doesn't contain .plt or .init.plt sections.\n");
9086 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
9087 return -ENOEXEC;
9088 }
9089
9090 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
9091
9092 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
9093 /* Init, or core PLT? */
9094 - if (location >= mod->module_core
9095 - && location < mod->module_core + mod->core_size)
9096 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
9097 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
9098 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
9099 - else
9100 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
9101 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
9102 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
9103 + else {
9104 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
9105 + return ~0UL;
9106 + }
9107
9108 /* Find this entry, or if that fails, the next avail. entry */
9109 while (entry->jump[0]) {
9110 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
9111 }
9112 #ifdef CONFIG_DYNAMIC_FTRACE
9113 module->arch.tramp =
9114 - do_plt_call(module->module_core,
9115 + do_plt_call(module->module_core_rx,
9116 (unsigned long)ftrace_caller,
9117 sechdrs, module);
9118 #endif
9119 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
9120 index be99774..9879c82 100644
9121 --- a/arch/powerpc/kernel/process.c
9122 +++ b/arch/powerpc/kernel/process.c
9123 @@ -1039,8 +1039,8 @@ void show_regs(struct pt_regs * regs)
9124 * Lookup NIP late so we have the best change of getting the
9125 * above info out without failing
9126 */
9127 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
9128 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
9129 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
9130 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
9131 #endif
9132 show_stack(current, (unsigned long *) regs->gpr[1]);
9133 if (!user_mode(regs))
9134 @@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9135 newsp = stack[0];
9136 ip = stack[STACK_FRAME_LR_SAVE];
9137 if (!firstframe || ip != lr) {
9138 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
9139 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
9140 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9141 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
9142 - printk(" (%pS)",
9143 + printk(" (%pA)",
9144 (void *)current->ret_stack[curr_frame].ret);
9145 curr_frame--;
9146 }
9147 @@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9148 struct pt_regs *regs = (struct pt_regs *)
9149 (sp + STACK_FRAME_OVERHEAD);
9150 lr = regs->link;
9151 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
9152 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
9153 regs->trap, (void *)regs->nip, (void *)lr);
9154 firstframe = 1;
9155 }
9156 @@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
9157 mtspr(SPRN_CTRLT, ctrl);
9158 }
9159 #endif /* CONFIG_PPC64 */
9160 -
9161 -unsigned long arch_align_stack(unsigned long sp)
9162 -{
9163 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9164 - sp -= get_random_int() & ~PAGE_MASK;
9165 - return sp & ~0xf;
9166 -}
9167 -
9168 -static inline unsigned long brk_rnd(void)
9169 -{
9170 - unsigned long rnd = 0;
9171 -
9172 - /* 8MB for 32bit, 1GB for 64bit */
9173 - if (is_32bit_task())
9174 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
9175 - else
9176 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
9177 -
9178 - return rnd << PAGE_SHIFT;
9179 -}
9180 -
9181 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9182 -{
9183 - unsigned long base = mm->brk;
9184 - unsigned long ret;
9185 -
9186 -#ifdef CONFIG_PPC_STD_MMU_64
9187 - /*
9188 - * If we are using 1TB segments and we are allowed to randomise
9189 - * the heap, we can put it above 1TB so it is backed by a 1TB
9190 - * segment. Otherwise the heap will be in the bottom 1TB
9191 - * which always uses 256MB segments and this may result in a
9192 - * performance penalty.
9193 - */
9194 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9195 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9196 -#endif
9197 -
9198 - ret = PAGE_ALIGN(base + brk_rnd());
9199 -
9200 - if (ret < mm->brk)
9201 - return mm->brk;
9202 -
9203 - return ret;
9204 -}
9205 -
9206 -unsigned long randomize_et_dyn(unsigned long base)
9207 -{
9208 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9209 -
9210 - if (ret < base)
9211 - return base;
9212 -
9213 - return ret;
9214 -}
9215 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9216 index 2e3d2bf..35df241 100644
9217 --- a/arch/powerpc/kernel/ptrace.c
9218 +++ b/arch/powerpc/kernel/ptrace.c
9219 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9220 return ret;
9221 }
9222
9223 +#ifdef CONFIG_GRKERNSEC_SETXID
9224 +extern void gr_delayed_cred_worker(void);
9225 +#endif
9226 +
9227 /*
9228 * We must return the syscall number to actually look up in the table.
9229 * This can be -1L to skip running any syscall at all.
9230 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9231
9232 secure_computing_strict(regs->gpr[0]);
9233
9234 +#ifdef CONFIG_GRKERNSEC_SETXID
9235 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9236 + gr_delayed_cred_worker();
9237 +#endif
9238 +
9239 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9240 tracehook_report_syscall_entry(regs))
9241 /*
9242 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9243 {
9244 int step;
9245
9246 +#ifdef CONFIG_GRKERNSEC_SETXID
9247 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9248 + gr_delayed_cred_worker();
9249 +#endif
9250 +
9251 audit_syscall_exit(regs);
9252
9253 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9254 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9255 index 1bc5a17..910d3f3 100644
9256 --- a/arch/powerpc/kernel/signal_32.c
9257 +++ b/arch/powerpc/kernel/signal_32.c
9258 @@ -1012,7 +1012,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
9259 /* Save user registers on the stack */
9260 frame = &rt_sf->uc.uc_mcontext;
9261 addr = frame;
9262 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9263 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9264 sigret = 0;
9265 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9266 } else {
9267 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9268 index 97c1e4b..f427f81 100644
9269 --- a/arch/powerpc/kernel/signal_64.c
9270 +++ b/arch/powerpc/kernel/signal_64.c
9271 @@ -755,7 +755,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
9272 current->thread.fp_state.fpscr = 0;
9273
9274 /* Set up to return from userspace. */
9275 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9276 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9277 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9278 } else {
9279 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9280 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9281 index 239f1cd..5359f76 100644
9282 --- a/arch/powerpc/kernel/traps.c
9283 +++ b/arch/powerpc/kernel/traps.c
9284 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9285 return flags;
9286 }
9287
9288 +extern void gr_handle_kernel_exploit(void);
9289 +
9290 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9291 int signr)
9292 {
9293 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9294 panic("Fatal exception in interrupt");
9295 if (panic_on_oops)
9296 panic("Fatal exception");
9297 +
9298 + gr_handle_kernel_exploit();
9299 +
9300 do_exit(signr);
9301 }
9302
9303 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9304 index ce74c33..0803371 100644
9305 --- a/arch/powerpc/kernel/vdso.c
9306 +++ b/arch/powerpc/kernel/vdso.c
9307 @@ -35,6 +35,7 @@
9308 #include <asm/vdso.h>
9309 #include <asm/vdso_datapage.h>
9310 #include <asm/setup.h>
9311 +#include <asm/mman.h>
9312
9313 #undef DEBUG
9314
9315 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9316 vdso_base = VDSO32_MBASE;
9317 #endif
9318
9319 - current->mm->context.vdso_base = 0;
9320 + current->mm->context.vdso_base = ~0UL;
9321
9322 /* vDSO has a problem and was disabled, just don't "enable" it for the
9323 * process
9324 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9325 vdso_base = get_unmapped_area(NULL, vdso_base,
9326 (vdso_pages << PAGE_SHIFT) +
9327 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9328 - 0, 0);
9329 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
9330 if (IS_ERR_VALUE(vdso_base)) {
9331 rc = vdso_base;
9332 goto fail_mmapsem;
9333 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9334 index 61c738a..b1092d6 100644
9335 --- a/arch/powerpc/kvm/powerpc.c
9336 +++ b/arch/powerpc/kvm/powerpc.c
9337 @@ -1195,7 +1195,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9338 }
9339 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9340
9341 -int kvm_arch_init(void *opaque)
9342 +int kvm_arch_init(const void *opaque)
9343 {
9344 return 0;
9345 }
9346 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9347 index 5eea6f3..5d10396 100644
9348 --- a/arch/powerpc/lib/usercopy_64.c
9349 +++ b/arch/powerpc/lib/usercopy_64.c
9350 @@ -9,22 +9,6 @@
9351 #include <linux/module.h>
9352 #include <asm/uaccess.h>
9353
9354 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9355 -{
9356 - if (likely(access_ok(VERIFY_READ, from, n)))
9357 - n = __copy_from_user(to, from, n);
9358 - else
9359 - memset(to, 0, n);
9360 - return n;
9361 -}
9362 -
9363 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9364 -{
9365 - if (likely(access_ok(VERIFY_WRITE, to, n)))
9366 - n = __copy_to_user(to, from, n);
9367 - return n;
9368 -}
9369 -
9370 unsigned long copy_in_user(void __user *to, const void __user *from,
9371 unsigned long n)
9372 {
9373 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9374 return n;
9375 }
9376
9377 -EXPORT_SYMBOL(copy_from_user);
9378 -EXPORT_SYMBOL(copy_to_user);
9379 EXPORT_SYMBOL(copy_in_user);
9380
9381 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9382 index 51ab9e7..7d3c78b 100644
9383 --- a/arch/powerpc/mm/fault.c
9384 +++ b/arch/powerpc/mm/fault.c
9385 @@ -33,6 +33,10 @@
9386 #include <linux/magic.h>
9387 #include <linux/ratelimit.h>
9388 #include <linux/context_tracking.h>
9389 +#include <linux/slab.h>
9390 +#include <linux/pagemap.h>
9391 +#include <linux/compiler.h>
9392 +#include <linux/unistd.h>
9393
9394 #include <asm/firmware.h>
9395 #include <asm/page.h>
9396 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9397 }
9398 #endif
9399
9400 +#ifdef CONFIG_PAX_PAGEEXEC
9401 +/*
9402 + * PaX: decide what to do with offenders (regs->nip = fault address)
9403 + *
9404 + * returns 1 when task should be killed
9405 + */
9406 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9407 +{
9408 + return 1;
9409 +}
9410 +
9411 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9412 +{
9413 + unsigned long i;
9414 +
9415 + printk(KERN_ERR "PAX: bytes at PC: ");
9416 + for (i = 0; i < 5; i++) {
9417 + unsigned int c;
9418 + if (get_user(c, (unsigned int __user *)pc+i))
9419 + printk(KERN_CONT "???????? ");
9420 + else
9421 + printk(KERN_CONT "%08x ", c);
9422 + }
9423 + printk("\n");
9424 +}
9425 +#endif
9426 +
9427 /*
9428 * Check whether the instruction at regs->nip is a store using
9429 * an update addressing form which will update r1.
9430 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9431 * indicate errors in DSISR but can validly be set in SRR1.
9432 */
9433 if (trap == 0x400)
9434 - error_code &= 0x48200000;
9435 + error_code &= 0x58200000;
9436 else
9437 is_write = error_code & DSISR_ISSTORE;
9438 #else
9439 @@ -378,7 +409,7 @@ good_area:
9440 * "undefined". Of those that can be set, this is the only
9441 * one which seems bad.
9442 */
9443 - if (error_code & 0x10000000)
9444 + if (error_code & DSISR_GUARDED)
9445 /* Guarded storage error. */
9446 goto bad_area;
9447 #endif /* CONFIG_8xx */
9448 @@ -393,7 +424,7 @@ good_area:
9449 * processors use the same I/D cache coherency mechanism
9450 * as embedded.
9451 */
9452 - if (error_code & DSISR_PROTFAULT)
9453 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9454 goto bad_area;
9455 #endif /* CONFIG_PPC_STD_MMU */
9456
9457 @@ -483,6 +514,23 @@ bad_area:
9458 bad_area_nosemaphore:
9459 /* User mode accesses cause a SIGSEGV */
9460 if (user_mode(regs)) {
9461 +
9462 +#ifdef CONFIG_PAX_PAGEEXEC
9463 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9464 +#ifdef CONFIG_PPC_STD_MMU
9465 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9466 +#else
9467 + if (is_exec && regs->nip == address) {
9468 +#endif
9469 + switch (pax_handle_fetch_fault(regs)) {
9470 + }
9471 +
9472 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9473 + do_group_exit(SIGKILL);
9474 + }
9475 + }
9476 +#endif
9477 +
9478 _exception(SIGSEGV, regs, code, address);
9479 goto bail;
9480 }
9481 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9482 index cb8bdbe..cde4bc7 100644
9483 --- a/arch/powerpc/mm/mmap.c
9484 +++ b/arch/powerpc/mm/mmap.c
9485 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9486 return sysctl_legacy_va_layout;
9487 }
9488
9489 -static unsigned long mmap_rnd(void)
9490 +static unsigned long mmap_rnd(struct mm_struct *mm)
9491 {
9492 unsigned long rnd = 0;
9493
9494 +#ifdef CONFIG_PAX_RANDMMAP
9495 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9496 +#endif
9497 +
9498 if (current->flags & PF_RANDOMIZE) {
9499 /* 8MB for 32bit, 1GB for 64bit */
9500 if (is_32bit_task())
9501 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9502 return rnd << PAGE_SHIFT;
9503 }
9504
9505 -static inline unsigned long mmap_base(void)
9506 +static inline unsigned long mmap_base(struct mm_struct *mm)
9507 {
9508 unsigned long gap = rlimit(RLIMIT_STACK);
9509
9510 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9511 else if (gap > MAX_GAP)
9512 gap = MAX_GAP;
9513
9514 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9515 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9516 }
9517
9518 /*
9519 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9520 */
9521 if (mmap_is_legacy()) {
9522 mm->mmap_base = TASK_UNMAPPED_BASE;
9523 +
9524 +#ifdef CONFIG_PAX_RANDMMAP
9525 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9526 + mm->mmap_base += mm->delta_mmap;
9527 +#endif
9528 +
9529 mm->get_unmapped_area = arch_get_unmapped_area;
9530 } else {
9531 - mm->mmap_base = mmap_base();
9532 + mm->mmap_base = mmap_base(mm);
9533 +
9534 +#ifdef CONFIG_PAX_RANDMMAP
9535 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9536 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9537 +#endif
9538 +
9539 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9540 }
9541 }
9542 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9543 index b0c75cc..ef7fb93 100644
9544 --- a/arch/powerpc/mm/slice.c
9545 +++ b/arch/powerpc/mm/slice.c
9546 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9547 if ((mm->task_size - len) < addr)
9548 return 0;
9549 vma = find_vma(mm, addr);
9550 - return (!vma || (addr + len) <= vma->vm_start);
9551 + return check_heap_stack_gap(vma, addr, len, 0);
9552 }
9553
9554 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9555 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9556 info.align_offset = 0;
9557
9558 addr = TASK_UNMAPPED_BASE;
9559 +
9560 +#ifdef CONFIG_PAX_RANDMMAP
9561 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9562 + addr += mm->delta_mmap;
9563 +#endif
9564 +
9565 while (addr < TASK_SIZE) {
9566 info.low_limit = addr;
9567 if (!slice_scan_available(addr, available, 1, &addr))
9568 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9569 if (fixed && addr > (mm->task_size - len))
9570 return -ENOMEM;
9571
9572 +#ifdef CONFIG_PAX_RANDMMAP
9573 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9574 + addr = 0;
9575 +#endif
9576 +
9577 /* If hint, make sure it matches our alignment restrictions */
9578 if (!fixed && addr) {
9579 addr = _ALIGN_UP(addr, 1ul << pshift);
9580 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9581 index 4278acf..67fd0e6 100644
9582 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9583 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9584 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9585 }
9586
9587 static struct pci_ops scc_pciex_pci_ops = {
9588 - scc_pciex_read_config,
9589 - scc_pciex_write_config,
9590 + .read = scc_pciex_read_config,
9591 + .write = scc_pciex_write_config,
9592 };
9593
9594 static void pciex_clear_intr_all(unsigned int __iomem *base)
9595 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9596 index 9098692..3d54cd1 100644
9597 --- a/arch/powerpc/platforms/cell/spufs/file.c
9598 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9599 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9600 return VM_FAULT_NOPAGE;
9601 }
9602
9603 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9604 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9605 unsigned long address,
9606 - void *buf, int len, int write)
9607 + void *buf, size_t len, int write)
9608 {
9609 struct spu_context *ctx = vma->vm_file->private_data;
9610 unsigned long offset = address - vma->vm_start;
9611 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9612 index fa934fe..c296056 100644
9613 --- a/arch/s390/include/asm/atomic.h
9614 +++ b/arch/s390/include/asm/atomic.h
9615 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9616 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9617 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9618
9619 +#define atomic64_read_unchecked(v) atomic64_read(v)
9620 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9621 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9622 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9623 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9624 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9625 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9626 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9627 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9628 +
9629 #endif /* __ARCH_S390_ATOMIC__ */
9630 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9631 index 19ff956..8d39cb1 100644
9632 --- a/arch/s390/include/asm/barrier.h
9633 +++ b/arch/s390/include/asm/barrier.h
9634 @@ -37,7 +37,7 @@
9635 do { \
9636 compiletime_assert_atomic_type(*p); \
9637 barrier(); \
9638 - ACCESS_ONCE(*p) = (v); \
9639 + ACCESS_ONCE_RW(*p) = (v); \
9640 } while (0)
9641
9642 #define smp_load_acquire(p) \
9643 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9644 index 4d7ccac..d03d0ad 100644
9645 --- a/arch/s390/include/asm/cache.h
9646 +++ b/arch/s390/include/asm/cache.h
9647 @@ -9,8 +9,10 @@
9648 #ifndef __ARCH_S390_CACHE_H
9649 #define __ARCH_S390_CACHE_H
9650
9651 -#define L1_CACHE_BYTES 256
9652 +#include <linux/const.h>
9653 +
9654 #define L1_CACHE_SHIFT 8
9655 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9656 #define NET_SKB_PAD 32
9657
9658 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9659 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9660 index 78f4f87..598ce39 100644
9661 --- a/arch/s390/include/asm/elf.h
9662 +++ b/arch/s390/include/asm/elf.h
9663 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9664 the loader. We need to make sure that it is out of the way of the program
9665 that it will "exec", and that there is sufficient room for the brk. */
9666
9667 -extern unsigned long randomize_et_dyn(unsigned long base);
9668 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9669 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9670 +
9671 +#ifdef CONFIG_PAX_ASLR
9672 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9673 +
9674 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9675 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9676 +#endif
9677
9678 /* This yields a mask that user programs can use to figure out what
9679 instruction set this CPU supports. */
9680 @@ -222,9 +228,6 @@ struct linux_binprm;
9681 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9682 int arch_setup_additional_pages(struct linux_binprm *, int);
9683
9684 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9685 -#define arch_randomize_brk arch_randomize_brk
9686 -
9687 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9688
9689 #endif
9690 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9691 index c4a93d6..4d2a9b4 100644
9692 --- a/arch/s390/include/asm/exec.h
9693 +++ b/arch/s390/include/asm/exec.h
9694 @@ -7,6 +7,6 @@
9695 #ifndef __ASM_EXEC_H
9696 #define __ASM_EXEC_H
9697
9698 -extern unsigned long arch_align_stack(unsigned long sp);
9699 +#define arch_align_stack(x) ((x) & ~0xfUL)
9700
9701 #endif /* __ASM_EXEC_H */
9702 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9703 index cd4c68e..6764641 100644
9704 --- a/arch/s390/include/asm/uaccess.h
9705 +++ b/arch/s390/include/asm/uaccess.h
9706 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9707 __range_ok((unsigned long)(addr), (size)); \
9708 })
9709
9710 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9711 #define access_ok(type, addr, size) __access_ok(addr, size)
9712
9713 /*
9714 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
9715 copy_to_user(void __user *to, const void *from, unsigned long n)
9716 {
9717 might_fault();
9718 +
9719 + if ((long)n < 0)
9720 + return n;
9721 +
9722 return __copy_to_user(to, from, n);
9723 }
9724
9725 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9726 static inline unsigned long __must_check
9727 copy_from_user(void *to, const void __user *from, unsigned long n)
9728 {
9729 - unsigned int sz = __compiletime_object_size(to);
9730 + size_t sz = __compiletime_object_size(to);
9731
9732 might_fault();
9733 - if (unlikely(sz != -1 && sz < n)) {
9734 +
9735 + if ((long)n < 0)
9736 + return n;
9737 +
9738 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9739 copy_from_user_overflow();
9740 return n;
9741 }
9742 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9743 index b89b591..fd9609d 100644
9744 --- a/arch/s390/kernel/module.c
9745 +++ b/arch/s390/kernel/module.c
9746 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9747
9748 /* Increase core size by size of got & plt and set start
9749 offsets for got and plt. */
9750 - me->core_size = ALIGN(me->core_size, 4);
9751 - me->arch.got_offset = me->core_size;
9752 - me->core_size += me->arch.got_size;
9753 - me->arch.plt_offset = me->core_size;
9754 - me->core_size += me->arch.plt_size;
9755 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9756 + me->arch.got_offset = me->core_size_rw;
9757 + me->core_size_rw += me->arch.got_size;
9758 + me->arch.plt_offset = me->core_size_rx;
9759 + me->core_size_rx += me->arch.plt_size;
9760 return 0;
9761 }
9762
9763 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9764 if (info->got_initialized == 0) {
9765 Elf_Addr *gotent;
9766
9767 - gotent = me->module_core + me->arch.got_offset +
9768 + gotent = me->module_core_rw + me->arch.got_offset +
9769 info->got_offset;
9770 *gotent = val;
9771 info->got_initialized = 1;
9772 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9773 rc = apply_rela_bits(loc, val, 0, 64, 0);
9774 else if (r_type == R_390_GOTENT ||
9775 r_type == R_390_GOTPLTENT) {
9776 - val += (Elf_Addr) me->module_core - loc;
9777 + val += (Elf_Addr) me->module_core_rw - loc;
9778 rc = apply_rela_bits(loc, val, 1, 32, 1);
9779 }
9780 break;
9781 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9782 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9783 if (info->plt_initialized == 0) {
9784 unsigned int *ip;
9785 - ip = me->module_core + me->arch.plt_offset +
9786 + ip = me->module_core_rx + me->arch.plt_offset +
9787 info->plt_offset;
9788 #ifndef CONFIG_64BIT
9789 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9790 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9791 val - loc + 0xffffUL < 0x1ffffeUL) ||
9792 (r_type == R_390_PLT32DBL &&
9793 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9794 - val = (Elf_Addr) me->module_core +
9795 + val = (Elf_Addr) me->module_core_rx +
9796 me->arch.plt_offset +
9797 info->plt_offset;
9798 val += rela->r_addend - loc;
9799 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9800 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9801 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9802 val = val + rela->r_addend -
9803 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9804 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9805 if (r_type == R_390_GOTOFF16)
9806 rc = apply_rela_bits(loc, val, 0, 16, 0);
9807 else if (r_type == R_390_GOTOFF32)
9808 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9809 break;
9810 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9811 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9812 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9813 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9814 rela->r_addend - loc;
9815 if (r_type == R_390_GOTPC)
9816 rc = apply_rela_bits(loc, val, 1, 32, 0);
9817 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9818 index 93b9ca4..4ea1454 100644
9819 --- a/arch/s390/kernel/process.c
9820 +++ b/arch/s390/kernel/process.c
9821 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9822 }
9823 return 0;
9824 }
9825 -
9826 -unsigned long arch_align_stack(unsigned long sp)
9827 -{
9828 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9829 - sp -= get_random_int() & ~PAGE_MASK;
9830 - return sp & ~0xf;
9831 -}
9832 -
9833 -static inline unsigned long brk_rnd(void)
9834 -{
9835 - /* 8MB for 32bit, 1GB for 64bit */
9836 - if (is_32bit_task())
9837 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9838 - else
9839 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9840 -}
9841 -
9842 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9843 -{
9844 - unsigned long ret;
9845 -
9846 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9847 - return (ret > mm->brk) ? ret : mm->brk;
9848 -}
9849 -
9850 -unsigned long randomize_et_dyn(unsigned long base)
9851 -{
9852 - unsigned long ret;
9853 -
9854 - if (!(current->flags & PF_RANDOMIZE))
9855 - return base;
9856 - ret = PAGE_ALIGN(base + brk_rnd());
9857 - return (ret > base) ? ret : base;
9858 -}
9859 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9860 index 9b436c2..54fbf0a 100644
9861 --- a/arch/s390/mm/mmap.c
9862 +++ b/arch/s390/mm/mmap.c
9863 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9864 */
9865 if (mmap_is_legacy()) {
9866 mm->mmap_base = mmap_base_legacy();
9867 +
9868 +#ifdef CONFIG_PAX_RANDMMAP
9869 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9870 + mm->mmap_base += mm->delta_mmap;
9871 +#endif
9872 +
9873 mm->get_unmapped_area = arch_get_unmapped_area;
9874 } else {
9875 mm->mmap_base = mmap_base();
9876 +
9877 +#ifdef CONFIG_PAX_RANDMMAP
9878 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9879 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9880 +#endif
9881 +
9882 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9883 }
9884 }
9885 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9886 */
9887 if (mmap_is_legacy()) {
9888 mm->mmap_base = mmap_base_legacy();
9889 +
9890 +#ifdef CONFIG_PAX_RANDMMAP
9891 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9892 + mm->mmap_base += mm->delta_mmap;
9893 +#endif
9894 +
9895 mm->get_unmapped_area = s390_get_unmapped_area;
9896 } else {
9897 mm->mmap_base = mmap_base();
9898 +
9899 +#ifdef CONFIG_PAX_RANDMMAP
9900 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9901 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9902 +#endif
9903 +
9904 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9905 }
9906 }
9907 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9908 index ae3d59f..f65f075 100644
9909 --- a/arch/score/include/asm/cache.h
9910 +++ b/arch/score/include/asm/cache.h
9911 @@ -1,7 +1,9 @@
9912 #ifndef _ASM_SCORE_CACHE_H
9913 #define _ASM_SCORE_CACHE_H
9914
9915 +#include <linux/const.h>
9916 +
9917 #define L1_CACHE_SHIFT 4
9918 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9919 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9920
9921 #endif /* _ASM_SCORE_CACHE_H */
9922 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9923 index f9f3cd5..58ff438 100644
9924 --- a/arch/score/include/asm/exec.h
9925 +++ b/arch/score/include/asm/exec.h
9926 @@ -1,6 +1,6 @@
9927 #ifndef _ASM_SCORE_EXEC_H
9928 #define _ASM_SCORE_EXEC_H
9929
9930 -extern unsigned long arch_align_stack(unsigned long sp);
9931 +#define arch_align_stack(x) (x)
9932
9933 #endif /* _ASM_SCORE_EXEC_H */
9934 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9935 index a1519ad3..e8ac1ff 100644
9936 --- a/arch/score/kernel/process.c
9937 +++ b/arch/score/kernel/process.c
9938 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9939
9940 return task_pt_regs(task)->cp0_epc;
9941 }
9942 -
9943 -unsigned long arch_align_stack(unsigned long sp)
9944 -{
9945 - return sp;
9946 -}
9947 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9948 index ef9e555..331bd29 100644
9949 --- a/arch/sh/include/asm/cache.h
9950 +++ b/arch/sh/include/asm/cache.h
9951 @@ -9,10 +9,11 @@
9952 #define __ASM_SH_CACHE_H
9953 #ifdef __KERNEL__
9954
9955 +#include <linux/const.h>
9956 #include <linux/init.h>
9957 #include <cpu/cache.h>
9958
9959 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9960 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9961
9962 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9963
9964 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9965 index 6777177..cb5e44f 100644
9966 --- a/arch/sh/mm/mmap.c
9967 +++ b/arch/sh/mm/mmap.c
9968 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9969 struct mm_struct *mm = current->mm;
9970 struct vm_area_struct *vma;
9971 int do_colour_align;
9972 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9973 struct vm_unmapped_area_info info;
9974
9975 if (flags & MAP_FIXED) {
9976 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9977 if (filp || (flags & MAP_SHARED))
9978 do_colour_align = 1;
9979
9980 +#ifdef CONFIG_PAX_RANDMMAP
9981 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9982 +#endif
9983 +
9984 if (addr) {
9985 if (do_colour_align)
9986 addr = COLOUR_ALIGN(addr, pgoff);
9987 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9988 addr = PAGE_ALIGN(addr);
9989
9990 vma = find_vma(mm, addr);
9991 - if (TASK_SIZE - len >= addr &&
9992 - (!vma || addr + len <= vma->vm_start))
9993 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9994 return addr;
9995 }
9996
9997 info.flags = 0;
9998 info.length = len;
9999 - info.low_limit = TASK_UNMAPPED_BASE;
10000 + info.low_limit = mm->mmap_base;
10001 info.high_limit = TASK_SIZE;
10002 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
10003 info.align_offset = pgoff << PAGE_SHIFT;
10004 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10005 struct mm_struct *mm = current->mm;
10006 unsigned long addr = addr0;
10007 int do_colour_align;
10008 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10009 struct vm_unmapped_area_info info;
10010
10011 if (flags & MAP_FIXED) {
10012 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10013 if (filp || (flags & MAP_SHARED))
10014 do_colour_align = 1;
10015
10016 +#ifdef CONFIG_PAX_RANDMMAP
10017 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10018 +#endif
10019 +
10020 /* requesting a specific address */
10021 if (addr) {
10022 if (do_colour_align)
10023 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10024 addr = PAGE_ALIGN(addr);
10025
10026 vma = find_vma(mm, addr);
10027 - if (TASK_SIZE - len >= addr &&
10028 - (!vma || addr + len <= vma->vm_start))
10029 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10030 return addr;
10031 }
10032
10033 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10034 VM_BUG_ON(addr != -ENOMEM);
10035 info.flags = 0;
10036 info.low_limit = TASK_UNMAPPED_BASE;
10037 +
10038 +#ifdef CONFIG_PAX_RANDMMAP
10039 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10040 + info.low_limit += mm->delta_mmap;
10041 +#endif
10042 +
10043 info.high_limit = TASK_SIZE;
10044 addr = vm_unmapped_area(&info);
10045 }
10046 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
10047 index bb894c8..8141d5c 100644
10048 --- a/arch/sparc/include/asm/atomic_64.h
10049 +++ b/arch/sparc/include/asm/atomic_64.h
10050 @@ -15,18 +15,40 @@
10051 #define ATOMIC64_INIT(i) { (i) }
10052
10053 #define atomic_read(v) (*(volatile int *)&(v)->counter)
10054 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10055 +{
10056 + return v->counter;
10057 +}
10058 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
10059 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10060 +{
10061 + return v->counter;
10062 +}
10063
10064 #define atomic_set(v, i) (((v)->counter) = i)
10065 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10066 +{
10067 + v->counter = i;
10068 +}
10069 #define atomic64_set(v, i) (((v)->counter) = i)
10070 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10071 +{
10072 + v->counter = i;
10073 +}
10074
10075 void atomic_add(int, atomic_t *);
10076 +void atomic_add_unchecked(int, atomic_unchecked_t *);
10077 void atomic64_add(long, atomic64_t *);
10078 +void atomic64_add_unchecked(long, atomic64_unchecked_t *);
10079 void atomic_sub(int, atomic_t *);
10080 +void atomic_sub_unchecked(int, atomic_unchecked_t *);
10081 void atomic64_sub(long, atomic64_t *);
10082 +void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
10083
10084 int atomic_add_ret(int, atomic_t *);
10085 +int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
10086 long atomic64_add_ret(long, atomic64_t *);
10087 +long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
10088 int atomic_sub_ret(int, atomic_t *);
10089 long atomic64_sub_ret(long, atomic64_t *);
10090
10091 @@ -34,13 +56,29 @@ long atomic64_sub_ret(long, atomic64_t *);
10092 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
10093
10094 #define atomic_inc_return(v) atomic_add_ret(1, v)
10095 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10096 +{
10097 + return atomic_add_ret_unchecked(1, v);
10098 +}
10099 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
10100 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10101 +{
10102 + return atomic64_add_ret_unchecked(1, v);
10103 +}
10104
10105 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
10106 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
10107
10108 #define atomic_add_return(i, v) atomic_add_ret(i, v)
10109 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10110 +{
10111 + return atomic_add_ret_unchecked(i, v);
10112 +}
10113 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
10114 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10115 +{
10116 + return atomic64_add_ret_unchecked(i, v);
10117 +}
10118
10119 /*
10120 * atomic_inc_and_test - increment and test
10121 @@ -51,6 +89,10 @@ long atomic64_sub_ret(long, atomic64_t *);
10122 * other cases.
10123 */
10124 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
10125 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10126 +{
10127 + return atomic_inc_return_unchecked(v) == 0;
10128 +}
10129 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
10130
10131 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
10132 @@ -60,25 +102,60 @@ long atomic64_sub_ret(long, atomic64_t *);
10133 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
10134
10135 #define atomic_inc(v) atomic_add(1, v)
10136 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10137 +{
10138 + atomic_add_unchecked(1, v);
10139 +}
10140 #define atomic64_inc(v) atomic64_add(1, v)
10141 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10142 +{
10143 + atomic64_add_unchecked(1, v);
10144 +}
10145
10146 #define atomic_dec(v) atomic_sub(1, v)
10147 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10148 +{
10149 + atomic_sub_unchecked(1, v);
10150 +}
10151 #define atomic64_dec(v) atomic64_sub(1, v)
10152 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10153 +{
10154 + atomic64_sub_unchecked(1, v);
10155 +}
10156
10157 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
10158 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
10159
10160 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10161 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10162 +{
10163 + return cmpxchg(&v->counter, old, new);
10164 +}
10165 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10166 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10167 +{
10168 + return xchg(&v->counter, new);
10169 +}
10170
10171 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10172 {
10173 - int c, old;
10174 + int c, old, new;
10175 c = atomic_read(v);
10176 for (;;) {
10177 - if (unlikely(c == (u)))
10178 + if (unlikely(c == u))
10179 break;
10180 - old = atomic_cmpxchg((v), c, c + (a));
10181 +
10182 + asm volatile("addcc %2, %0, %0\n"
10183 +
10184 +#ifdef CONFIG_PAX_REFCOUNT
10185 + "tvs %%icc, 6\n"
10186 +#endif
10187 +
10188 + : "=r" (new)
10189 + : "0" (c), "ir" (a)
10190 + : "cc");
10191 +
10192 + old = atomic_cmpxchg(v, c, new);
10193 if (likely(old == c))
10194 break;
10195 c = old;
10196 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10197 #define atomic64_cmpxchg(v, o, n) \
10198 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10199 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10200 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10201 +{
10202 + return xchg(&v->counter, new);
10203 +}
10204
10205 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10206 {
10207 - long c, old;
10208 + long c, old, new;
10209 c = atomic64_read(v);
10210 for (;;) {
10211 - if (unlikely(c == (u)))
10212 + if (unlikely(c == u))
10213 break;
10214 - old = atomic64_cmpxchg((v), c, c + (a));
10215 +
10216 + asm volatile("addcc %2, %0, %0\n"
10217 +
10218 +#ifdef CONFIG_PAX_REFCOUNT
10219 + "tvs %%xcc, 6\n"
10220 +#endif
10221 +
10222 + : "=r" (new)
10223 + : "0" (c), "ir" (a)
10224 + : "cc");
10225 +
10226 + old = atomic64_cmpxchg(v, c, new);
10227 if (likely(old == c))
10228 break;
10229 c = old;
10230 }
10231 - return c != (u);
10232 + return c != u;
10233 }
10234
10235 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10236 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10237 index 305dcc3..7835030 100644
10238 --- a/arch/sparc/include/asm/barrier_64.h
10239 +++ b/arch/sparc/include/asm/barrier_64.h
10240 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10241 do { \
10242 compiletime_assert_atomic_type(*p); \
10243 barrier(); \
10244 - ACCESS_ONCE(*p) = (v); \
10245 + ACCESS_ONCE_RW(*p) = (v); \
10246 } while (0)
10247
10248 #define smp_load_acquire(p) \
10249 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10250 index 5bb6991..5c2132e 100644
10251 --- a/arch/sparc/include/asm/cache.h
10252 +++ b/arch/sparc/include/asm/cache.h
10253 @@ -7,10 +7,12 @@
10254 #ifndef _SPARC_CACHE_H
10255 #define _SPARC_CACHE_H
10256
10257 +#include <linux/const.h>
10258 +
10259 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10260
10261 #define L1_CACHE_SHIFT 5
10262 -#define L1_CACHE_BYTES 32
10263 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10264
10265 #ifdef CONFIG_SPARC32
10266 #define SMP_CACHE_BYTES_SHIFT 5
10267 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10268 index a24e41f..47677ff 100644
10269 --- a/arch/sparc/include/asm/elf_32.h
10270 +++ b/arch/sparc/include/asm/elf_32.h
10271 @@ -114,6 +114,13 @@ typedef struct {
10272
10273 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10274
10275 +#ifdef CONFIG_PAX_ASLR
10276 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
10277 +
10278 +#define PAX_DELTA_MMAP_LEN 16
10279 +#define PAX_DELTA_STACK_LEN 16
10280 +#endif
10281 +
10282 /* This yields a mask that user programs can use to figure out what
10283 instruction set this cpu supports. This can NOT be done in userspace
10284 on Sparc. */
10285 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10286 index 370ca1e..d4f4a98 100644
10287 --- a/arch/sparc/include/asm/elf_64.h
10288 +++ b/arch/sparc/include/asm/elf_64.h
10289 @@ -189,6 +189,13 @@ typedef struct {
10290 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10291 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10292
10293 +#ifdef CONFIG_PAX_ASLR
10294 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10295 +
10296 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10297 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10298 +#endif
10299 +
10300 extern unsigned long sparc64_elf_hwcap;
10301 #define ELF_HWCAP sparc64_elf_hwcap
10302
10303 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10304 index a3890da..f6a408e 100644
10305 --- a/arch/sparc/include/asm/pgalloc_32.h
10306 +++ b/arch/sparc/include/asm/pgalloc_32.h
10307 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10308 }
10309
10310 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10311 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10312
10313 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10314 unsigned long address)
10315 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10316 index 39a7ac4..2c9b586 100644
10317 --- a/arch/sparc/include/asm/pgalloc_64.h
10318 +++ b/arch/sparc/include/asm/pgalloc_64.h
10319 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
10320 }
10321
10322 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
10323 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10324
10325 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
10326 {
10327 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10328 index 59ba6f6..4518128 100644
10329 --- a/arch/sparc/include/asm/pgtable.h
10330 +++ b/arch/sparc/include/asm/pgtable.h
10331 @@ -5,4 +5,8 @@
10332 #else
10333 #include <asm/pgtable_32.h>
10334 #endif
10335 +
10336 +#define ktla_ktva(addr) (addr)
10337 +#define ktva_ktla(addr) (addr)
10338 +
10339 #endif
10340 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10341 index b9b91ae..950b91e 100644
10342 --- a/arch/sparc/include/asm/pgtable_32.h
10343 +++ b/arch/sparc/include/asm/pgtable_32.h
10344 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10345 #define PAGE_SHARED SRMMU_PAGE_SHARED
10346 #define PAGE_COPY SRMMU_PAGE_COPY
10347 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10348 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10349 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10350 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10351 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10352
10353 /* Top-level page directory - dummy used by init-mm.
10354 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10355
10356 /* xwr */
10357 #define __P000 PAGE_NONE
10358 -#define __P001 PAGE_READONLY
10359 -#define __P010 PAGE_COPY
10360 -#define __P011 PAGE_COPY
10361 +#define __P001 PAGE_READONLY_NOEXEC
10362 +#define __P010 PAGE_COPY_NOEXEC
10363 +#define __P011 PAGE_COPY_NOEXEC
10364 #define __P100 PAGE_READONLY
10365 #define __P101 PAGE_READONLY
10366 #define __P110 PAGE_COPY
10367 #define __P111 PAGE_COPY
10368
10369 #define __S000 PAGE_NONE
10370 -#define __S001 PAGE_READONLY
10371 -#define __S010 PAGE_SHARED
10372 -#define __S011 PAGE_SHARED
10373 +#define __S001 PAGE_READONLY_NOEXEC
10374 +#define __S010 PAGE_SHARED_NOEXEC
10375 +#define __S011 PAGE_SHARED_NOEXEC
10376 #define __S100 PAGE_READONLY
10377 #define __S101 PAGE_READONLY
10378 #define __S110 PAGE_SHARED
10379 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10380 index 79da178..c2eede8 100644
10381 --- a/arch/sparc/include/asm/pgtsrmmu.h
10382 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10383 @@ -115,6 +115,11 @@
10384 SRMMU_EXEC | SRMMU_REF)
10385 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10386 SRMMU_EXEC | SRMMU_REF)
10387 +
10388 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10389 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10390 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10391 +
10392 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10393 SRMMU_DIRTY | SRMMU_REF)
10394
10395 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10396 index f5fffd8..a0669f0 100644
10397 --- a/arch/sparc/include/asm/setup.h
10398 +++ b/arch/sparc/include/asm/setup.h
10399 @@ -53,8 +53,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10400 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10401
10402 /* init_64.c */
10403 -extern atomic_t dcpage_flushes;
10404 -extern atomic_t dcpage_flushes_xcall;
10405 +extern atomic_unchecked_t dcpage_flushes;
10406 +extern atomic_unchecked_t dcpage_flushes_xcall;
10407
10408 extern int sysctl_tsb_ratio;
10409 #endif
10410 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10411 index 9689176..63c18ea 100644
10412 --- a/arch/sparc/include/asm/spinlock_64.h
10413 +++ b/arch/sparc/include/asm/spinlock_64.h
10414 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10415
10416 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10417
10418 -static void inline arch_read_lock(arch_rwlock_t *lock)
10419 +static inline void arch_read_lock(arch_rwlock_t *lock)
10420 {
10421 unsigned long tmp1, tmp2;
10422
10423 __asm__ __volatile__ (
10424 "1: ldsw [%2], %0\n"
10425 " brlz,pn %0, 2f\n"
10426 -"4: add %0, 1, %1\n"
10427 +"4: addcc %0, 1, %1\n"
10428 +
10429 +#ifdef CONFIG_PAX_REFCOUNT
10430 +" tvs %%icc, 6\n"
10431 +#endif
10432 +
10433 " cas [%2], %0, %1\n"
10434 " cmp %0, %1\n"
10435 " bne,pn %%icc, 1b\n"
10436 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10437 " .previous"
10438 : "=&r" (tmp1), "=&r" (tmp2)
10439 : "r" (lock)
10440 - : "memory");
10441 + : "memory", "cc");
10442 }
10443
10444 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10445 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10446 {
10447 int tmp1, tmp2;
10448
10449 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10450 "1: ldsw [%2], %0\n"
10451 " brlz,a,pn %0, 2f\n"
10452 " mov 0, %0\n"
10453 -" add %0, 1, %1\n"
10454 +" addcc %0, 1, %1\n"
10455 +
10456 +#ifdef CONFIG_PAX_REFCOUNT
10457 +" tvs %%icc, 6\n"
10458 +#endif
10459 +
10460 " cas [%2], %0, %1\n"
10461 " cmp %0, %1\n"
10462 " bne,pn %%icc, 1b\n"
10463 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10464 return tmp1;
10465 }
10466
10467 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10468 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10469 {
10470 unsigned long tmp1, tmp2;
10471
10472 __asm__ __volatile__(
10473 "1: lduw [%2], %0\n"
10474 -" sub %0, 1, %1\n"
10475 +" subcc %0, 1, %1\n"
10476 +
10477 +#ifdef CONFIG_PAX_REFCOUNT
10478 +" tvs %%icc, 6\n"
10479 +#endif
10480 +
10481 " cas [%2], %0, %1\n"
10482 " cmp %0, %1\n"
10483 " bne,pn %%xcc, 1b\n"
10484 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10485 : "memory");
10486 }
10487
10488 -static void inline arch_write_lock(arch_rwlock_t *lock)
10489 +static inline void arch_write_lock(arch_rwlock_t *lock)
10490 {
10491 unsigned long mask, tmp1, tmp2;
10492
10493 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10494 : "memory");
10495 }
10496
10497 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10498 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10499 {
10500 __asm__ __volatile__(
10501 " stw %%g0, [%0]"
10502 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10503 : "memory");
10504 }
10505
10506 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10507 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10508 {
10509 unsigned long mask, tmp1, tmp2, result;
10510
10511 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10512 index 96efa7a..16858bf 100644
10513 --- a/arch/sparc/include/asm/thread_info_32.h
10514 +++ b/arch/sparc/include/asm/thread_info_32.h
10515 @@ -49,6 +49,8 @@ struct thread_info {
10516 unsigned long w_saved;
10517
10518 struct restart_block restart_block;
10519 +
10520 + unsigned long lowest_stack;
10521 };
10522
10523 /*
10524 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10525 index a5f01ac..703b554 100644
10526 --- a/arch/sparc/include/asm/thread_info_64.h
10527 +++ b/arch/sparc/include/asm/thread_info_64.h
10528 @@ -63,6 +63,8 @@ struct thread_info {
10529 struct pt_regs *kern_una_regs;
10530 unsigned int kern_una_insn;
10531
10532 + unsigned long lowest_stack;
10533 +
10534 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10535 };
10536
10537 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10538 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10539 /* flag bit 4 is available */
10540 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10541 -/* flag bit 6 is available */
10542 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10543 #define TIF_32BIT 7 /* 32-bit binary */
10544 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10545 #define TIF_SECCOMP 9 /* secure computing */
10546 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10547 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10548 +
10549 /* NOTE: Thread flags >= 12 should be ones we have no interest
10550 * in using in assembly, else we can't use the mask as
10551 * an immediate value in instructions such as andcc.
10552 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10553 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10554 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10555 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10556 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10557
10558 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10559 _TIF_DO_NOTIFY_RESUME_MASK | \
10560 _TIF_NEED_RESCHED)
10561 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10562
10563 +#define _TIF_WORK_SYSCALL \
10564 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10565 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10566 +
10567 +
10568 /*
10569 * Thread-synchronous status.
10570 *
10571 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10572 index bd56c28..4b63d83 100644
10573 --- a/arch/sparc/include/asm/uaccess.h
10574 +++ b/arch/sparc/include/asm/uaccess.h
10575 @@ -1,5 +1,6 @@
10576 #ifndef ___ASM_SPARC_UACCESS_H
10577 #define ___ASM_SPARC_UACCESS_H
10578 +
10579 #if defined(__sparc__) && defined(__arch64__)
10580 #include <asm/uaccess_64.h>
10581 #else
10582 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10583 index 9634d08..f55fe4f 100644
10584 --- a/arch/sparc/include/asm/uaccess_32.h
10585 +++ b/arch/sparc/include/asm/uaccess_32.h
10586 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10587
10588 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10589 {
10590 - if (n && __access_ok((unsigned long) to, n))
10591 + if ((long)n < 0)
10592 + return n;
10593 +
10594 + if (n && __access_ok((unsigned long) to, n)) {
10595 + if (!__builtin_constant_p(n))
10596 + check_object_size(from, n, true);
10597 return __copy_user(to, (__force void __user *) from, n);
10598 - else
10599 + } else
10600 return n;
10601 }
10602
10603 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10604 {
10605 + if ((long)n < 0)
10606 + return n;
10607 +
10608 + if (!__builtin_constant_p(n))
10609 + check_object_size(from, n, true);
10610 +
10611 return __copy_user(to, (__force void __user *) from, n);
10612 }
10613
10614 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10615 {
10616 - if (n && __access_ok((unsigned long) from, n))
10617 + if ((long)n < 0)
10618 + return n;
10619 +
10620 + if (n && __access_ok((unsigned long) from, n)) {
10621 + if (!__builtin_constant_p(n))
10622 + check_object_size(to, n, false);
10623 return __copy_user((__force void __user *) to, from, n);
10624 - else
10625 + } else
10626 return n;
10627 }
10628
10629 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10630 {
10631 + if ((long)n < 0)
10632 + return n;
10633 +
10634 return __copy_user((__force void __user *) to, from, n);
10635 }
10636
10637 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10638 index c990a5e..f17b9c1 100644
10639 --- a/arch/sparc/include/asm/uaccess_64.h
10640 +++ b/arch/sparc/include/asm/uaccess_64.h
10641 @@ -10,6 +10,7 @@
10642 #include <linux/compiler.h>
10643 #include <linux/string.h>
10644 #include <linux/thread_info.h>
10645 +#include <linux/kernel.h>
10646 #include <asm/asi.h>
10647 #include <asm/spitfire.h>
10648 #include <asm-generic/uaccess-unaligned.h>
10649 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10650 static inline unsigned long __must_check
10651 copy_from_user(void *to, const void __user *from, unsigned long size)
10652 {
10653 - unsigned long ret = ___copy_from_user(to, from, size);
10654 + unsigned long ret;
10655
10656 + if ((long)size < 0 || size > INT_MAX)
10657 + return size;
10658 +
10659 + if (!__builtin_constant_p(size))
10660 + check_object_size(to, size, false);
10661 +
10662 + ret = ___copy_from_user(to, from, size);
10663 if (unlikely(ret))
10664 ret = copy_from_user_fixup(to, from, size);
10665
10666 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10667 static inline unsigned long __must_check
10668 copy_to_user(void __user *to, const void *from, unsigned long size)
10669 {
10670 - unsigned long ret = ___copy_to_user(to, from, size);
10671 + unsigned long ret;
10672
10673 + if ((long)size < 0 || size > INT_MAX)
10674 + return size;
10675 +
10676 + if (!__builtin_constant_p(size))
10677 + check_object_size(from, size, true);
10678 +
10679 + ret = ___copy_to_user(to, from, size);
10680 if (unlikely(ret))
10681 ret = copy_to_user_fixup(to, from, size);
10682 return ret;
10683 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10684 index 7cf9c6e..6206648 100644
10685 --- a/arch/sparc/kernel/Makefile
10686 +++ b/arch/sparc/kernel/Makefile
10687 @@ -4,7 +4,7 @@
10688 #
10689
10690 asflags-y := -ansi
10691 -ccflags-y := -Werror
10692 +#ccflags-y := -Werror
10693
10694 extra-y := head_$(BITS).o
10695
10696 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10697 index 50e7b62..79fae35 100644
10698 --- a/arch/sparc/kernel/process_32.c
10699 +++ b/arch/sparc/kernel/process_32.c
10700 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10701
10702 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10703 r->psr, r->pc, r->npc, r->y, print_tainted());
10704 - printk("PC: <%pS>\n", (void *) r->pc);
10705 + printk("PC: <%pA>\n", (void *) r->pc);
10706 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10707 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10708 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10709 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10710 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10711 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10712 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10713 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10714
10715 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10716 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10717 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10718 rw = (struct reg_window32 *) fp;
10719 pc = rw->ins[7];
10720 printk("[%08lx : ", pc);
10721 - printk("%pS ] ", (void *) pc);
10722 + printk("%pA ] ", (void *) pc);
10723 fp = rw->ins[6];
10724 } while (++count < 16);
10725 printk("\n");
10726 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10727 index 027e099..6d4178f 100644
10728 --- a/arch/sparc/kernel/process_64.c
10729 +++ b/arch/sparc/kernel/process_64.c
10730 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10731 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10732 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10733 if (regs->tstate & TSTATE_PRIV)
10734 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10735 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10736 }
10737
10738 void show_regs(struct pt_regs *regs)
10739 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10740
10741 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10742 regs->tpc, regs->tnpc, regs->y, print_tainted());
10743 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10744 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10745 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10746 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10747 regs->u_regs[3]);
10748 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10749 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10750 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10751 regs->u_regs[15]);
10752 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10753 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10754 show_regwindow(regs);
10755 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10756 }
10757 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10758 ((tp && tp->task) ? tp->task->pid : -1));
10759
10760 if (gp->tstate & TSTATE_PRIV) {
10761 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10762 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10763 (void *) gp->tpc,
10764 (void *) gp->o7,
10765 (void *) gp->i7,
10766 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10767 index 79cc0d1..ec62734 100644
10768 --- a/arch/sparc/kernel/prom_common.c
10769 +++ b/arch/sparc/kernel/prom_common.c
10770 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10771
10772 unsigned int prom_early_allocated __initdata;
10773
10774 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10775 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10776 .nextprop = prom_common_nextprop,
10777 .getproplen = prom_getproplen,
10778 .getproperty = prom_getproperty,
10779 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10780 index c13c9f2..d572c34 100644
10781 --- a/arch/sparc/kernel/ptrace_64.c
10782 +++ b/arch/sparc/kernel/ptrace_64.c
10783 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10784 return ret;
10785 }
10786
10787 +#ifdef CONFIG_GRKERNSEC_SETXID
10788 +extern void gr_delayed_cred_worker(void);
10789 +#endif
10790 +
10791 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10792 {
10793 int ret = 0;
10794 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10795 if (test_thread_flag(TIF_NOHZ))
10796 user_exit();
10797
10798 +#ifdef CONFIG_GRKERNSEC_SETXID
10799 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10800 + gr_delayed_cred_worker();
10801 +#endif
10802 +
10803 if (test_thread_flag(TIF_SYSCALL_TRACE))
10804 ret = tracehook_report_syscall_entry(regs);
10805
10806 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10807 if (test_thread_flag(TIF_NOHZ))
10808 user_exit();
10809
10810 +#ifdef CONFIG_GRKERNSEC_SETXID
10811 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10812 + gr_delayed_cred_worker();
10813 +#endif
10814 +
10815 audit_syscall_exit(regs);
10816
10817 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10818 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10819 index 41aa247..eadfb74 100644
10820 --- a/arch/sparc/kernel/smp_64.c
10821 +++ b/arch/sparc/kernel/smp_64.c
10822 @@ -883,7 +883,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10823 return;
10824
10825 #ifdef CONFIG_DEBUG_DCFLUSH
10826 - atomic_inc(&dcpage_flushes);
10827 + atomic_inc_unchecked(&dcpage_flushes);
10828 #endif
10829
10830 this_cpu = get_cpu();
10831 @@ -907,7 +907,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10832 xcall_deliver(data0, __pa(pg_addr),
10833 (u64) pg_addr, cpumask_of(cpu));
10834 #ifdef CONFIG_DEBUG_DCFLUSH
10835 - atomic_inc(&dcpage_flushes_xcall);
10836 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10837 #endif
10838 }
10839 }
10840 @@ -926,7 +926,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10841 preempt_disable();
10842
10843 #ifdef CONFIG_DEBUG_DCFLUSH
10844 - atomic_inc(&dcpage_flushes);
10845 + atomic_inc_unchecked(&dcpage_flushes);
10846 #endif
10847 data0 = 0;
10848 pg_addr = page_address(page);
10849 @@ -943,7 +943,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10850 xcall_deliver(data0, __pa(pg_addr),
10851 (u64) pg_addr, cpu_online_mask);
10852 #ifdef CONFIG_DEBUG_DCFLUSH
10853 - atomic_inc(&dcpage_flushes_xcall);
10854 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10855 #endif
10856 }
10857 __local_flush_dcache_page(page);
10858 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10859 index 646988d..b88905f 100644
10860 --- a/arch/sparc/kernel/sys_sparc_32.c
10861 +++ b/arch/sparc/kernel/sys_sparc_32.c
10862 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10863 if (len > TASK_SIZE - PAGE_SIZE)
10864 return -ENOMEM;
10865 if (!addr)
10866 - addr = TASK_UNMAPPED_BASE;
10867 + addr = current->mm->mmap_base;
10868
10869 info.flags = 0;
10870 info.length = len;
10871 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10872 index c85403d..6af95c9 100644
10873 --- a/arch/sparc/kernel/sys_sparc_64.c
10874 +++ b/arch/sparc/kernel/sys_sparc_64.c
10875 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10876 struct vm_area_struct * vma;
10877 unsigned long task_size = TASK_SIZE;
10878 int do_color_align;
10879 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10880 struct vm_unmapped_area_info info;
10881
10882 if (flags & MAP_FIXED) {
10883 /* We do not accept a shared mapping if it would violate
10884 * cache aliasing constraints.
10885 */
10886 - if ((flags & MAP_SHARED) &&
10887 + if ((filp || (flags & MAP_SHARED)) &&
10888 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10889 return -EINVAL;
10890 return addr;
10891 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10892 if (filp || (flags & MAP_SHARED))
10893 do_color_align = 1;
10894
10895 +#ifdef CONFIG_PAX_RANDMMAP
10896 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10897 +#endif
10898 +
10899 if (addr) {
10900 if (do_color_align)
10901 addr = COLOR_ALIGN(addr, pgoff);
10902 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10903 addr = PAGE_ALIGN(addr);
10904
10905 vma = find_vma(mm, addr);
10906 - if (task_size - len >= addr &&
10907 - (!vma || addr + len <= vma->vm_start))
10908 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10909 return addr;
10910 }
10911
10912 info.flags = 0;
10913 info.length = len;
10914 - info.low_limit = TASK_UNMAPPED_BASE;
10915 + info.low_limit = mm->mmap_base;
10916 info.high_limit = min(task_size, VA_EXCLUDE_START);
10917 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10918 info.align_offset = pgoff << PAGE_SHIFT;
10919 + info.threadstack_offset = offset;
10920 addr = vm_unmapped_area(&info);
10921
10922 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10923 VM_BUG_ON(addr != -ENOMEM);
10924 info.low_limit = VA_EXCLUDE_END;
10925 +
10926 +#ifdef CONFIG_PAX_RANDMMAP
10927 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10928 + info.low_limit += mm->delta_mmap;
10929 +#endif
10930 +
10931 info.high_limit = task_size;
10932 addr = vm_unmapped_area(&info);
10933 }
10934 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10935 unsigned long task_size = STACK_TOP32;
10936 unsigned long addr = addr0;
10937 int do_color_align;
10938 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10939 struct vm_unmapped_area_info info;
10940
10941 /* This should only ever run for 32-bit processes. */
10942 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10943 /* We do not accept a shared mapping if it would violate
10944 * cache aliasing constraints.
10945 */
10946 - if ((flags & MAP_SHARED) &&
10947 + if ((filp || (flags & MAP_SHARED)) &&
10948 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10949 return -EINVAL;
10950 return addr;
10951 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10952 if (filp || (flags & MAP_SHARED))
10953 do_color_align = 1;
10954
10955 +#ifdef CONFIG_PAX_RANDMMAP
10956 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10957 +#endif
10958 +
10959 /* requesting a specific address */
10960 if (addr) {
10961 if (do_color_align)
10962 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10963 addr = PAGE_ALIGN(addr);
10964
10965 vma = find_vma(mm, addr);
10966 - if (task_size - len >= addr &&
10967 - (!vma || addr + len <= vma->vm_start))
10968 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10969 return addr;
10970 }
10971
10972 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10973 info.high_limit = mm->mmap_base;
10974 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10975 info.align_offset = pgoff << PAGE_SHIFT;
10976 + info.threadstack_offset = offset;
10977 addr = vm_unmapped_area(&info);
10978
10979 /*
10980 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10981 VM_BUG_ON(addr != -ENOMEM);
10982 info.flags = 0;
10983 info.low_limit = TASK_UNMAPPED_BASE;
10984 +
10985 +#ifdef CONFIG_PAX_RANDMMAP
10986 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10987 + info.low_limit += mm->delta_mmap;
10988 +#endif
10989 +
10990 info.high_limit = STACK_TOP32;
10991 addr = vm_unmapped_area(&info);
10992 }
10993 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10994 EXPORT_SYMBOL(get_fb_unmapped_area);
10995
10996 /* Essentially the same as PowerPC. */
10997 -static unsigned long mmap_rnd(void)
10998 +static unsigned long mmap_rnd(struct mm_struct *mm)
10999 {
11000 unsigned long rnd = 0UL;
11001
11002 +#ifdef CONFIG_PAX_RANDMMAP
11003 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11004 +#endif
11005 +
11006 if (current->flags & PF_RANDOMIZE) {
11007 unsigned long val = get_random_int();
11008 if (test_thread_flag(TIF_32BIT))
11009 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
11010
11011 void arch_pick_mmap_layout(struct mm_struct *mm)
11012 {
11013 - unsigned long random_factor = mmap_rnd();
11014 + unsigned long random_factor = mmap_rnd(mm);
11015 unsigned long gap;
11016
11017 /*
11018 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11019 gap == RLIM_INFINITY ||
11020 sysctl_legacy_va_layout) {
11021 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
11022 +
11023 +#ifdef CONFIG_PAX_RANDMMAP
11024 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11025 + mm->mmap_base += mm->delta_mmap;
11026 +#endif
11027 +
11028 mm->get_unmapped_area = arch_get_unmapped_area;
11029 } else {
11030 /* We know it's 32-bit */
11031 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11032 gap = (task_size / 6 * 5);
11033
11034 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
11035 +
11036 +#ifdef CONFIG_PAX_RANDMMAP
11037 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11038 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11039 +#endif
11040 +
11041 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11042 }
11043 }
11044 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
11045 index 33a17e7..d87fb1f 100644
11046 --- a/arch/sparc/kernel/syscalls.S
11047 +++ b/arch/sparc/kernel/syscalls.S
11048 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
11049 #endif
11050 .align 32
11051 1: ldx [%g6 + TI_FLAGS], %l5
11052 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11053 + andcc %l5, _TIF_WORK_SYSCALL, %g0
11054 be,pt %icc, rtrap
11055 nop
11056 call syscall_trace_leave
11057 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
11058
11059 srl %i3, 0, %o3 ! IEU0
11060 srl %i2, 0, %o2 ! IEU0 Group
11061 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11062 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11063 bne,pn %icc, linux_syscall_trace32 ! CTI
11064 mov %i0, %l5 ! IEU1
11065 5: call %l7 ! CTI Group brk forced
11066 @@ -208,7 +208,7 @@ linux_sparc_syscall:
11067
11068 mov %i3, %o3 ! IEU1
11069 mov %i4, %o4 ! IEU0 Group
11070 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11071 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11072 bne,pn %icc, linux_syscall_trace ! CTI Group
11073 mov %i0, %l5 ! IEU0
11074 2: call %l7 ! CTI Group brk forced
11075 @@ -223,7 +223,7 @@ ret_sys_call:
11076
11077 cmp %o0, -ERESTART_RESTARTBLOCK
11078 bgeu,pn %xcc, 1f
11079 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11080 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11081 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
11082
11083 2:
11084 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
11085 index 6fd386c5..6907d81 100644
11086 --- a/arch/sparc/kernel/traps_32.c
11087 +++ b/arch/sparc/kernel/traps_32.c
11088 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
11089 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
11090 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
11091
11092 +extern void gr_handle_kernel_exploit(void);
11093 +
11094 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11095 {
11096 static int die_counter;
11097 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11098 count++ < 30 &&
11099 (((unsigned long) rw) >= PAGE_OFFSET) &&
11100 !(((unsigned long) rw) & 0x7)) {
11101 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
11102 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
11103 (void *) rw->ins[7]);
11104 rw = (struct reg_window32 *)rw->ins[6];
11105 }
11106 }
11107 printk("Instruction DUMP:");
11108 instruction_dump ((unsigned long *) regs->pc);
11109 - if(regs->psr & PSR_PS)
11110 + if(regs->psr & PSR_PS) {
11111 + gr_handle_kernel_exploit();
11112 do_exit(SIGKILL);
11113 + }
11114 do_exit(SIGSEGV);
11115 }
11116
11117 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
11118 index fb6640e..2daada8 100644
11119 --- a/arch/sparc/kernel/traps_64.c
11120 +++ b/arch/sparc/kernel/traps_64.c
11121 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
11122 i + 1,
11123 p->trapstack[i].tstate, p->trapstack[i].tpc,
11124 p->trapstack[i].tnpc, p->trapstack[i].tt);
11125 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
11126 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
11127 }
11128 }
11129
11130 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
11131
11132 lvl -= 0x100;
11133 if (regs->tstate & TSTATE_PRIV) {
11134 +
11135 +#ifdef CONFIG_PAX_REFCOUNT
11136 + if (lvl == 6)
11137 + pax_report_refcount_overflow(regs);
11138 +#endif
11139 +
11140 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11141 die_if_kernel(buffer, regs);
11142 }
11143 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11144 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11145 {
11146 char buffer[32];
11147 -
11148 +
11149 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11150 0, lvl, SIGTRAP) == NOTIFY_STOP)
11151 return;
11152
11153 +#ifdef CONFIG_PAX_REFCOUNT
11154 + if (lvl == 6)
11155 + pax_report_refcount_overflow(regs);
11156 +#endif
11157 +
11158 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11159
11160 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11161 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11162 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11163 printk("%s" "ERROR(%d): ",
11164 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11165 - printk("TPC<%pS>\n", (void *) regs->tpc);
11166 + printk("TPC<%pA>\n", (void *) regs->tpc);
11167 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11168 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11169 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11170 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11171 smp_processor_id(),
11172 (type & 0x1) ? 'I' : 'D',
11173 regs->tpc);
11174 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11175 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11176 panic("Irrecoverable Cheetah+ parity error.");
11177 }
11178
11179 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11180 smp_processor_id(),
11181 (type & 0x1) ? 'I' : 'D',
11182 regs->tpc);
11183 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11184 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11185 }
11186
11187 struct sun4v_error_entry {
11188 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11189 /*0x38*/u64 reserved_5;
11190 };
11191
11192 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11193 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11194 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11195 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11196
11197 static const char *sun4v_err_type_to_str(u8 type)
11198 {
11199 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11200 }
11201
11202 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11203 - int cpu, const char *pfx, atomic_t *ocnt)
11204 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11205 {
11206 u64 *raw_ptr = (u64 *) ent;
11207 u32 attrs;
11208 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11209
11210 show_regs(regs);
11211
11212 - if ((cnt = atomic_read(ocnt)) != 0) {
11213 - atomic_set(ocnt, 0);
11214 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11215 + atomic_set_unchecked(ocnt, 0);
11216 wmb();
11217 printk("%s: Queue overflowed %d times.\n",
11218 pfx, cnt);
11219 @@ -2048,7 +2059,7 @@ out:
11220 */
11221 void sun4v_resum_overflow(struct pt_regs *regs)
11222 {
11223 - atomic_inc(&sun4v_resum_oflow_cnt);
11224 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11225 }
11226
11227 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11228 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11229 /* XXX Actually even this can make not that much sense. Perhaps
11230 * XXX we should just pull the plug and panic directly from here?
11231 */
11232 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11233 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11234 }
11235
11236 unsigned long sun4v_err_itlb_vaddr;
11237 @@ -2116,9 +2127,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11238
11239 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11240 regs->tpc, tl);
11241 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11242 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11243 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11244 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11245 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11246 (void *) regs->u_regs[UREG_I7]);
11247 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11248 "pte[%lx] error[%lx]\n",
11249 @@ -2140,9 +2151,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11250
11251 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11252 regs->tpc, tl);
11253 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11254 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11255 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11256 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11257 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11258 (void *) regs->u_regs[UREG_I7]);
11259 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11260 "pte[%lx] error[%lx]\n",
11261 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11262 fp = (unsigned long)sf->fp + STACK_BIAS;
11263 }
11264
11265 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11266 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11267 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11268 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11269 int index = tsk->curr_ret_stack;
11270 if (tsk->ret_stack && index >= graph) {
11271 pc = tsk->ret_stack[index - graph].ret;
11272 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11273 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11274 graph++;
11275 }
11276 }
11277 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11278 return (struct reg_window *) (fp + STACK_BIAS);
11279 }
11280
11281 +extern void gr_handle_kernel_exploit(void);
11282 +
11283 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11284 {
11285 static int die_counter;
11286 @@ -2411,7 +2424,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11287 while (rw &&
11288 count++ < 30 &&
11289 kstack_valid(tp, (unsigned long) rw)) {
11290 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11291 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11292 (void *) rw->ins[7]);
11293
11294 rw = kernel_stack_up(rw);
11295 @@ -2424,8 +2437,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11296 }
11297 user_instruction_dump ((unsigned int __user *) regs->tpc);
11298 }
11299 - if (regs->tstate & TSTATE_PRIV)
11300 + if (regs->tstate & TSTATE_PRIV) {
11301 + gr_handle_kernel_exploit();
11302 do_exit(SIGKILL);
11303 + }
11304 do_exit(SIGSEGV);
11305 }
11306 EXPORT_SYMBOL(die_if_kernel);
11307 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11308 index 62098a8..547ab2c 100644
11309 --- a/arch/sparc/kernel/unaligned_64.c
11310 +++ b/arch/sparc/kernel/unaligned_64.c
11311 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11312 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11313
11314 if (__ratelimit(&ratelimit)) {
11315 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11316 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11317 regs->tpc, (void *) regs->tpc);
11318 }
11319 }
11320 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11321 index 3269b02..64f5231 100644
11322 --- a/arch/sparc/lib/Makefile
11323 +++ b/arch/sparc/lib/Makefile
11324 @@ -2,7 +2,7 @@
11325 #
11326
11327 asflags-y := -ansi -DST_DIV0=0x02
11328 -ccflags-y := -Werror
11329 +#ccflags-y := -Werror
11330
11331 lib-$(CONFIG_SPARC32) += ashrdi3.o
11332 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11333 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11334 index 85c233d..68500e0 100644
11335 --- a/arch/sparc/lib/atomic_64.S
11336 +++ b/arch/sparc/lib/atomic_64.S
11337 @@ -17,7 +17,12 @@
11338 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11339 BACKOFF_SETUP(%o2)
11340 1: lduw [%o1], %g1
11341 - add %g1, %o0, %g7
11342 + addcc %g1, %o0, %g7
11343 +
11344 +#ifdef CONFIG_PAX_REFCOUNT
11345 + tvs %icc, 6
11346 +#endif
11347 +
11348 cas [%o1], %g1, %g7
11349 cmp %g1, %g7
11350 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11351 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11352 2: BACKOFF_SPIN(%o2, %o3, 1b)
11353 ENDPROC(atomic_add)
11354
11355 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11356 + BACKOFF_SETUP(%o2)
11357 +1: lduw [%o1], %g1
11358 + add %g1, %o0, %g7
11359 + cas [%o1], %g1, %g7
11360 + cmp %g1, %g7
11361 + bne,pn %icc, 2f
11362 + nop
11363 + retl
11364 + nop
11365 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11366 +ENDPROC(atomic_add_unchecked)
11367 +
11368 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11369 BACKOFF_SETUP(%o2)
11370 1: lduw [%o1], %g1
11371 - sub %g1, %o0, %g7
11372 + subcc %g1, %o0, %g7
11373 +
11374 +#ifdef CONFIG_PAX_REFCOUNT
11375 + tvs %icc, 6
11376 +#endif
11377 +
11378 cas [%o1], %g1, %g7
11379 cmp %g1, %g7
11380 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11381 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11382 2: BACKOFF_SPIN(%o2, %o3, 1b)
11383 ENDPROC(atomic_sub)
11384
11385 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11386 + BACKOFF_SETUP(%o2)
11387 +1: lduw [%o1], %g1
11388 + sub %g1, %o0, %g7
11389 + cas [%o1], %g1, %g7
11390 + cmp %g1, %g7
11391 + bne,pn %icc, 2f
11392 + nop
11393 + retl
11394 + nop
11395 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11396 +ENDPROC(atomic_sub_unchecked)
11397 +
11398 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11399 BACKOFF_SETUP(%o2)
11400 1: lduw [%o1], %g1
11401 - add %g1, %o0, %g7
11402 + addcc %g1, %o0, %g7
11403 +
11404 +#ifdef CONFIG_PAX_REFCOUNT
11405 + tvs %icc, 6
11406 +#endif
11407 +
11408 cas [%o1], %g1, %g7
11409 cmp %g1, %g7
11410 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11411 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11412 2: BACKOFF_SPIN(%o2, %o3, 1b)
11413 ENDPROC(atomic_add_ret)
11414
11415 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11416 + BACKOFF_SETUP(%o2)
11417 +1: lduw [%o1], %g1
11418 + addcc %g1, %o0, %g7
11419 + cas [%o1], %g1, %g7
11420 + cmp %g1, %g7
11421 + bne,pn %icc, 2f
11422 + add %g7, %o0, %g7
11423 + sra %g7, 0, %o0
11424 + retl
11425 + nop
11426 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11427 +ENDPROC(atomic_add_ret_unchecked)
11428 +
11429 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11430 BACKOFF_SETUP(%o2)
11431 1: lduw [%o1], %g1
11432 - sub %g1, %o0, %g7
11433 + subcc %g1, %o0, %g7
11434 +
11435 +#ifdef CONFIG_PAX_REFCOUNT
11436 + tvs %icc, 6
11437 +#endif
11438 +
11439 cas [%o1], %g1, %g7
11440 cmp %g1, %g7
11441 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11442 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11443 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11444 BACKOFF_SETUP(%o2)
11445 1: ldx [%o1], %g1
11446 - add %g1, %o0, %g7
11447 + addcc %g1, %o0, %g7
11448 +
11449 +#ifdef CONFIG_PAX_REFCOUNT
11450 + tvs %xcc, 6
11451 +#endif
11452 +
11453 casx [%o1], %g1, %g7
11454 cmp %g1, %g7
11455 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11456 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11457 2: BACKOFF_SPIN(%o2, %o3, 1b)
11458 ENDPROC(atomic64_add)
11459
11460 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11461 + BACKOFF_SETUP(%o2)
11462 +1: ldx [%o1], %g1
11463 + addcc %g1, %o0, %g7
11464 + casx [%o1], %g1, %g7
11465 + cmp %g1, %g7
11466 + bne,pn %xcc, 2f
11467 + nop
11468 + retl
11469 + nop
11470 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11471 +ENDPROC(atomic64_add_unchecked)
11472 +
11473 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11474 BACKOFF_SETUP(%o2)
11475 1: ldx [%o1], %g1
11476 - sub %g1, %o0, %g7
11477 + subcc %g1, %o0, %g7
11478 +
11479 +#ifdef CONFIG_PAX_REFCOUNT
11480 + tvs %xcc, 6
11481 +#endif
11482 +
11483 casx [%o1], %g1, %g7
11484 cmp %g1, %g7
11485 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11486 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11487 2: BACKOFF_SPIN(%o2, %o3, 1b)
11488 ENDPROC(atomic64_sub)
11489
11490 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11491 + BACKOFF_SETUP(%o2)
11492 +1: ldx [%o1], %g1
11493 + subcc %g1, %o0, %g7
11494 + casx [%o1], %g1, %g7
11495 + cmp %g1, %g7
11496 + bne,pn %xcc, 2f
11497 + nop
11498 + retl
11499 + nop
11500 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11501 +ENDPROC(atomic64_sub_unchecked)
11502 +
11503 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11504 BACKOFF_SETUP(%o2)
11505 1: ldx [%o1], %g1
11506 - add %g1, %o0, %g7
11507 + addcc %g1, %o0, %g7
11508 +
11509 +#ifdef CONFIG_PAX_REFCOUNT
11510 + tvs %xcc, 6
11511 +#endif
11512 +
11513 casx [%o1], %g1, %g7
11514 cmp %g1, %g7
11515 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11516 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11517 2: BACKOFF_SPIN(%o2, %o3, 1b)
11518 ENDPROC(atomic64_add_ret)
11519
11520 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11521 + BACKOFF_SETUP(%o2)
11522 +1: ldx [%o1], %g1
11523 + addcc %g1, %o0, %g7
11524 + casx [%o1], %g1, %g7
11525 + cmp %g1, %g7
11526 + bne,pn %xcc, 2f
11527 + add %g7, %o0, %g7
11528 + mov %g7, %o0
11529 + retl
11530 + nop
11531 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11532 +ENDPROC(atomic64_add_ret_unchecked)
11533 +
11534 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11535 BACKOFF_SETUP(%o2)
11536 1: ldx [%o1], %g1
11537 - sub %g1, %o0, %g7
11538 + subcc %g1, %o0, %g7
11539 +
11540 +#ifdef CONFIG_PAX_REFCOUNT
11541 + tvs %xcc, 6
11542 +#endif
11543 +
11544 casx [%o1], %g1, %g7
11545 cmp %g1, %g7
11546 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11547 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11548 index 323335b..ed85ea2 100644
11549 --- a/arch/sparc/lib/ksyms.c
11550 +++ b/arch/sparc/lib/ksyms.c
11551 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11552
11553 /* Atomic counter implementation. */
11554 EXPORT_SYMBOL(atomic_add);
11555 +EXPORT_SYMBOL(atomic_add_unchecked);
11556 EXPORT_SYMBOL(atomic_add_ret);
11557 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11558 EXPORT_SYMBOL(atomic_sub);
11559 +EXPORT_SYMBOL(atomic_sub_unchecked);
11560 EXPORT_SYMBOL(atomic_sub_ret);
11561 EXPORT_SYMBOL(atomic64_add);
11562 +EXPORT_SYMBOL(atomic64_add_unchecked);
11563 EXPORT_SYMBOL(atomic64_add_ret);
11564 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11565 EXPORT_SYMBOL(atomic64_sub);
11566 +EXPORT_SYMBOL(atomic64_sub_unchecked);
11567 EXPORT_SYMBOL(atomic64_sub_ret);
11568 EXPORT_SYMBOL(atomic64_dec_if_positive);
11569
11570 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11571 index 30c3ecc..736f015 100644
11572 --- a/arch/sparc/mm/Makefile
11573 +++ b/arch/sparc/mm/Makefile
11574 @@ -2,7 +2,7 @@
11575 #
11576
11577 asflags-y := -ansi
11578 -ccflags-y := -Werror
11579 +#ccflags-y := -Werror
11580
11581 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11582 obj-y += fault_$(BITS).o
11583 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11584 index 908e8c1..1524793 100644
11585 --- a/arch/sparc/mm/fault_32.c
11586 +++ b/arch/sparc/mm/fault_32.c
11587 @@ -21,6 +21,9 @@
11588 #include <linux/perf_event.h>
11589 #include <linux/interrupt.h>
11590 #include <linux/kdebug.h>
11591 +#include <linux/slab.h>
11592 +#include <linux/pagemap.h>
11593 +#include <linux/compiler.h>
11594
11595 #include <asm/page.h>
11596 #include <asm/pgtable.h>
11597 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11598 return safe_compute_effective_address(regs, insn);
11599 }
11600
11601 +#ifdef CONFIG_PAX_PAGEEXEC
11602 +#ifdef CONFIG_PAX_DLRESOLVE
11603 +static void pax_emuplt_close(struct vm_area_struct *vma)
11604 +{
11605 + vma->vm_mm->call_dl_resolve = 0UL;
11606 +}
11607 +
11608 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11609 +{
11610 + unsigned int *kaddr;
11611 +
11612 + vmf->page = alloc_page(GFP_HIGHUSER);
11613 + if (!vmf->page)
11614 + return VM_FAULT_OOM;
11615 +
11616 + kaddr = kmap(vmf->page);
11617 + memset(kaddr, 0, PAGE_SIZE);
11618 + kaddr[0] = 0x9DE3BFA8U; /* save */
11619 + flush_dcache_page(vmf->page);
11620 + kunmap(vmf->page);
11621 + return VM_FAULT_MAJOR;
11622 +}
11623 +
11624 +static const struct vm_operations_struct pax_vm_ops = {
11625 + .close = pax_emuplt_close,
11626 + .fault = pax_emuplt_fault
11627 +};
11628 +
11629 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11630 +{
11631 + int ret;
11632 +
11633 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11634 + vma->vm_mm = current->mm;
11635 + vma->vm_start = addr;
11636 + vma->vm_end = addr + PAGE_SIZE;
11637 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11638 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11639 + vma->vm_ops = &pax_vm_ops;
11640 +
11641 + ret = insert_vm_struct(current->mm, vma);
11642 + if (ret)
11643 + return ret;
11644 +
11645 + ++current->mm->total_vm;
11646 + return 0;
11647 +}
11648 +#endif
11649 +
11650 +/*
11651 + * PaX: decide what to do with offenders (regs->pc = fault address)
11652 + *
11653 + * returns 1 when task should be killed
11654 + * 2 when patched PLT trampoline was detected
11655 + * 3 when unpatched PLT trampoline was detected
11656 + */
11657 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11658 +{
11659 +
11660 +#ifdef CONFIG_PAX_EMUPLT
11661 + int err;
11662 +
11663 + do { /* PaX: patched PLT emulation #1 */
11664 + unsigned int sethi1, sethi2, jmpl;
11665 +
11666 + err = get_user(sethi1, (unsigned int *)regs->pc);
11667 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11668 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11669 +
11670 + if (err)
11671 + break;
11672 +
11673 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11674 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11675 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11676 + {
11677 + unsigned int addr;
11678 +
11679 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11680 + addr = regs->u_regs[UREG_G1];
11681 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11682 + regs->pc = addr;
11683 + regs->npc = addr+4;
11684 + return 2;
11685 + }
11686 + } while (0);
11687 +
11688 + do { /* PaX: patched PLT emulation #2 */
11689 + unsigned int ba;
11690 +
11691 + err = get_user(ba, (unsigned int *)regs->pc);
11692 +
11693 + if (err)
11694 + break;
11695 +
11696 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11697 + unsigned int addr;
11698 +
11699 + if ((ba & 0xFFC00000U) == 0x30800000U)
11700 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11701 + else
11702 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11703 + regs->pc = addr;
11704 + regs->npc = addr+4;
11705 + return 2;
11706 + }
11707 + } while (0);
11708 +
11709 + do { /* PaX: patched PLT emulation #3 */
11710 + unsigned int sethi, bajmpl, nop;
11711 +
11712 + err = get_user(sethi, (unsigned int *)regs->pc);
11713 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11714 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11715 +
11716 + if (err)
11717 + break;
11718 +
11719 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11720 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11721 + nop == 0x01000000U)
11722 + {
11723 + unsigned int addr;
11724 +
11725 + addr = (sethi & 0x003FFFFFU) << 10;
11726 + regs->u_regs[UREG_G1] = addr;
11727 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11728 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11729 + else
11730 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11731 + regs->pc = addr;
11732 + regs->npc = addr+4;
11733 + return 2;
11734 + }
11735 + } while (0);
11736 +
11737 + do { /* PaX: unpatched PLT emulation step 1 */
11738 + unsigned int sethi, ba, nop;
11739 +
11740 + err = get_user(sethi, (unsigned int *)regs->pc);
11741 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11742 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11743 +
11744 + if (err)
11745 + break;
11746 +
11747 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11748 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11749 + nop == 0x01000000U)
11750 + {
11751 + unsigned int addr, save, call;
11752 +
11753 + if ((ba & 0xFFC00000U) == 0x30800000U)
11754 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11755 + else
11756 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11757 +
11758 + err = get_user(save, (unsigned int *)addr);
11759 + err |= get_user(call, (unsigned int *)(addr+4));
11760 + err |= get_user(nop, (unsigned int *)(addr+8));
11761 + if (err)
11762 + break;
11763 +
11764 +#ifdef CONFIG_PAX_DLRESOLVE
11765 + if (save == 0x9DE3BFA8U &&
11766 + (call & 0xC0000000U) == 0x40000000U &&
11767 + nop == 0x01000000U)
11768 + {
11769 + struct vm_area_struct *vma;
11770 + unsigned long call_dl_resolve;
11771 +
11772 + down_read(&current->mm->mmap_sem);
11773 + call_dl_resolve = current->mm->call_dl_resolve;
11774 + up_read(&current->mm->mmap_sem);
11775 + if (likely(call_dl_resolve))
11776 + goto emulate;
11777 +
11778 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11779 +
11780 + down_write(&current->mm->mmap_sem);
11781 + if (current->mm->call_dl_resolve) {
11782 + call_dl_resolve = current->mm->call_dl_resolve;
11783 + up_write(&current->mm->mmap_sem);
11784 + if (vma)
11785 + kmem_cache_free(vm_area_cachep, vma);
11786 + goto emulate;
11787 + }
11788 +
11789 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11790 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11791 + up_write(&current->mm->mmap_sem);
11792 + if (vma)
11793 + kmem_cache_free(vm_area_cachep, vma);
11794 + return 1;
11795 + }
11796 +
11797 + if (pax_insert_vma(vma, call_dl_resolve)) {
11798 + up_write(&current->mm->mmap_sem);
11799 + kmem_cache_free(vm_area_cachep, vma);
11800 + return 1;
11801 + }
11802 +
11803 + current->mm->call_dl_resolve = call_dl_resolve;
11804 + up_write(&current->mm->mmap_sem);
11805 +
11806 +emulate:
11807 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11808 + regs->pc = call_dl_resolve;
11809 + regs->npc = addr+4;
11810 + return 3;
11811 + }
11812 +#endif
11813 +
11814 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11815 + if ((save & 0xFFC00000U) == 0x05000000U &&
11816 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11817 + nop == 0x01000000U)
11818 + {
11819 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11820 + regs->u_regs[UREG_G2] = addr + 4;
11821 + addr = (save & 0x003FFFFFU) << 10;
11822 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11823 + regs->pc = addr;
11824 + regs->npc = addr+4;
11825 + return 3;
11826 + }
11827 + }
11828 + } while (0);
11829 +
11830 + do { /* PaX: unpatched PLT emulation step 2 */
11831 + unsigned int save, call, nop;
11832 +
11833 + err = get_user(save, (unsigned int *)(regs->pc-4));
11834 + err |= get_user(call, (unsigned int *)regs->pc);
11835 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11836 + if (err)
11837 + break;
11838 +
11839 + if (save == 0x9DE3BFA8U &&
11840 + (call & 0xC0000000U) == 0x40000000U &&
11841 + nop == 0x01000000U)
11842 + {
11843 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11844 +
11845 + regs->u_regs[UREG_RETPC] = regs->pc;
11846 + regs->pc = dl_resolve;
11847 + regs->npc = dl_resolve+4;
11848 + return 3;
11849 + }
11850 + } while (0);
11851 +#endif
11852 +
11853 + return 1;
11854 +}
11855 +
11856 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11857 +{
11858 + unsigned long i;
11859 +
11860 + printk(KERN_ERR "PAX: bytes at PC: ");
11861 + for (i = 0; i < 8; i++) {
11862 + unsigned int c;
11863 + if (get_user(c, (unsigned int *)pc+i))
11864 + printk(KERN_CONT "???????? ");
11865 + else
11866 + printk(KERN_CONT "%08x ", c);
11867 + }
11868 + printk("\n");
11869 +}
11870 +#endif
11871 +
11872 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11873 int text_fault)
11874 {
11875 @@ -226,6 +500,24 @@ good_area:
11876 if (!(vma->vm_flags & VM_WRITE))
11877 goto bad_area;
11878 } else {
11879 +
11880 +#ifdef CONFIG_PAX_PAGEEXEC
11881 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11882 + up_read(&mm->mmap_sem);
11883 + switch (pax_handle_fetch_fault(regs)) {
11884 +
11885 +#ifdef CONFIG_PAX_EMUPLT
11886 + case 2:
11887 + case 3:
11888 + return;
11889 +#endif
11890 +
11891 + }
11892 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11893 + do_group_exit(SIGKILL);
11894 + }
11895 +#endif
11896 +
11897 /* Allow reads even for write-only mappings */
11898 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11899 goto bad_area;
11900 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11901 index 587cd05..fbdf17a 100644
11902 --- a/arch/sparc/mm/fault_64.c
11903 +++ b/arch/sparc/mm/fault_64.c
11904 @@ -22,6 +22,9 @@
11905 #include <linux/kdebug.h>
11906 #include <linux/percpu.h>
11907 #include <linux/context_tracking.h>
11908 +#include <linux/slab.h>
11909 +#include <linux/pagemap.h>
11910 +#include <linux/compiler.h>
11911
11912 #include <asm/page.h>
11913 #include <asm/pgtable.h>
11914 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11915 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11916 regs->tpc);
11917 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11918 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11919 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11920 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11921 dump_stack();
11922 unhandled_fault(regs->tpc, current, regs);
11923 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11924 show_regs(regs);
11925 }
11926
11927 +#ifdef CONFIG_PAX_PAGEEXEC
11928 +#ifdef CONFIG_PAX_DLRESOLVE
11929 +static void pax_emuplt_close(struct vm_area_struct *vma)
11930 +{
11931 + vma->vm_mm->call_dl_resolve = 0UL;
11932 +}
11933 +
11934 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11935 +{
11936 + unsigned int *kaddr;
11937 +
11938 + vmf->page = alloc_page(GFP_HIGHUSER);
11939 + if (!vmf->page)
11940 + return VM_FAULT_OOM;
11941 +
11942 + kaddr = kmap(vmf->page);
11943 + memset(kaddr, 0, PAGE_SIZE);
11944 + kaddr[0] = 0x9DE3BFA8U; /* save */
11945 + flush_dcache_page(vmf->page);
11946 + kunmap(vmf->page);
11947 + return VM_FAULT_MAJOR;
11948 +}
11949 +
11950 +static const struct vm_operations_struct pax_vm_ops = {
11951 + .close = pax_emuplt_close,
11952 + .fault = pax_emuplt_fault
11953 +};
11954 +
11955 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11956 +{
11957 + int ret;
11958 +
11959 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11960 + vma->vm_mm = current->mm;
11961 + vma->vm_start = addr;
11962 + vma->vm_end = addr + PAGE_SIZE;
11963 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11964 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11965 + vma->vm_ops = &pax_vm_ops;
11966 +
11967 + ret = insert_vm_struct(current->mm, vma);
11968 + if (ret)
11969 + return ret;
11970 +
11971 + ++current->mm->total_vm;
11972 + return 0;
11973 +}
11974 +#endif
11975 +
11976 +/*
11977 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11978 + *
11979 + * returns 1 when task should be killed
11980 + * 2 when patched PLT trampoline was detected
11981 + * 3 when unpatched PLT trampoline was detected
11982 + */
11983 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11984 +{
11985 +
11986 +#ifdef CONFIG_PAX_EMUPLT
11987 + int err;
11988 +
11989 + do { /* PaX: patched PLT emulation #1 */
11990 + unsigned int sethi1, sethi2, jmpl;
11991 +
11992 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11993 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11994 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11995 +
11996 + if (err)
11997 + break;
11998 +
11999 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12000 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
12001 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
12002 + {
12003 + unsigned long addr;
12004 +
12005 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12006 + addr = regs->u_regs[UREG_G1];
12007 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12008 +
12009 + if (test_thread_flag(TIF_32BIT))
12010 + addr &= 0xFFFFFFFFUL;
12011 +
12012 + regs->tpc = addr;
12013 + regs->tnpc = addr+4;
12014 + return 2;
12015 + }
12016 + } while (0);
12017 +
12018 + do { /* PaX: patched PLT emulation #2 */
12019 + unsigned int ba;
12020 +
12021 + err = get_user(ba, (unsigned int *)regs->tpc);
12022 +
12023 + if (err)
12024 + break;
12025 +
12026 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12027 + unsigned long addr;
12028 +
12029 + if ((ba & 0xFFC00000U) == 0x30800000U)
12030 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12031 + else
12032 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12033 +
12034 + if (test_thread_flag(TIF_32BIT))
12035 + addr &= 0xFFFFFFFFUL;
12036 +
12037 + regs->tpc = addr;
12038 + regs->tnpc = addr+4;
12039 + return 2;
12040 + }
12041 + } while (0);
12042 +
12043 + do { /* PaX: patched PLT emulation #3 */
12044 + unsigned int sethi, bajmpl, nop;
12045 +
12046 + err = get_user(sethi, (unsigned int *)regs->tpc);
12047 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
12048 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12049 +
12050 + if (err)
12051 + break;
12052 +
12053 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12054 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12055 + nop == 0x01000000U)
12056 + {
12057 + unsigned long addr;
12058 +
12059 + addr = (sethi & 0x003FFFFFU) << 10;
12060 + regs->u_regs[UREG_G1] = addr;
12061 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12062 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12063 + else
12064 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12065 +
12066 + if (test_thread_flag(TIF_32BIT))
12067 + addr &= 0xFFFFFFFFUL;
12068 +
12069 + regs->tpc = addr;
12070 + regs->tnpc = addr+4;
12071 + return 2;
12072 + }
12073 + } while (0);
12074 +
12075 + do { /* PaX: patched PLT emulation #4 */
12076 + unsigned int sethi, mov1, call, mov2;
12077 +
12078 + err = get_user(sethi, (unsigned int *)regs->tpc);
12079 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
12080 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
12081 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
12082 +
12083 + if (err)
12084 + break;
12085 +
12086 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12087 + mov1 == 0x8210000FU &&
12088 + (call & 0xC0000000U) == 0x40000000U &&
12089 + mov2 == 0x9E100001U)
12090 + {
12091 + unsigned long addr;
12092 +
12093 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
12094 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12095 +
12096 + if (test_thread_flag(TIF_32BIT))
12097 + addr &= 0xFFFFFFFFUL;
12098 +
12099 + regs->tpc = addr;
12100 + regs->tnpc = addr+4;
12101 + return 2;
12102 + }
12103 + } while (0);
12104 +
12105 + do { /* PaX: patched PLT emulation #5 */
12106 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
12107 +
12108 + err = get_user(sethi, (unsigned int *)regs->tpc);
12109 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12110 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12111 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
12112 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
12113 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
12114 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
12115 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
12116 +
12117 + if (err)
12118 + break;
12119 +
12120 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12121 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12122 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12123 + (or1 & 0xFFFFE000U) == 0x82106000U &&
12124 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12125 + sllx == 0x83287020U &&
12126 + jmpl == 0x81C04005U &&
12127 + nop == 0x01000000U)
12128 + {
12129 + unsigned long addr;
12130 +
12131 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12132 + regs->u_regs[UREG_G1] <<= 32;
12133 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12134 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12135 + regs->tpc = addr;
12136 + regs->tnpc = addr+4;
12137 + return 2;
12138 + }
12139 + } while (0);
12140 +
12141 + do { /* PaX: patched PLT emulation #6 */
12142 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
12143 +
12144 + err = get_user(sethi, (unsigned int *)regs->tpc);
12145 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12146 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12147 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
12148 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
12149 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
12150 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
12151 +
12152 + if (err)
12153 + break;
12154 +
12155 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12156 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12157 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12158 + sllx == 0x83287020U &&
12159 + (or & 0xFFFFE000U) == 0x8A116000U &&
12160 + jmpl == 0x81C04005U &&
12161 + nop == 0x01000000U)
12162 + {
12163 + unsigned long addr;
12164 +
12165 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
12166 + regs->u_regs[UREG_G1] <<= 32;
12167 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
12168 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12169 + regs->tpc = addr;
12170 + regs->tnpc = addr+4;
12171 + return 2;
12172 + }
12173 + } while (0);
12174 +
12175 + do { /* PaX: unpatched PLT emulation step 1 */
12176 + unsigned int sethi, ba, nop;
12177 +
12178 + err = get_user(sethi, (unsigned int *)regs->tpc);
12179 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12180 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12181 +
12182 + if (err)
12183 + break;
12184 +
12185 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12186 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12187 + nop == 0x01000000U)
12188 + {
12189 + unsigned long addr;
12190 + unsigned int save, call;
12191 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
12192 +
12193 + if ((ba & 0xFFC00000U) == 0x30800000U)
12194 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12195 + else
12196 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12197 +
12198 + if (test_thread_flag(TIF_32BIT))
12199 + addr &= 0xFFFFFFFFUL;
12200 +
12201 + err = get_user(save, (unsigned int *)addr);
12202 + err |= get_user(call, (unsigned int *)(addr+4));
12203 + err |= get_user(nop, (unsigned int *)(addr+8));
12204 + if (err)
12205 + break;
12206 +
12207 +#ifdef CONFIG_PAX_DLRESOLVE
12208 + if (save == 0x9DE3BFA8U &&
12209 + (call & 0xC0000000U) == 0x40000000U &&
12210 + nop == 0x01000000U)
12211 + {
12212 + struct vm_area_struct *vma;
12213 + unsigned long call_dl_resolve;
12214 +
12215 + down_read(&current->mm->mmap_sem);
12216 + call_dl_resolve = current->mm->call_dl_resolve;
12217 + up_read(&current->mm->mmap_sem);
12218 + if (likely(call_dl_resolve))
12219 + goto emulate;
12220 +
12221 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12222 +
12223 + down_write(&current->mm->mmap_sem);
12224 + if (current->mm->call_dl_resolve) {
12225 + call_dl_resolve = current->mm->call_dl_resolve;
12226 + up_write(&current->mm->mmap_sem);
12227 + if (vma)
12228 + kmem_cache_free(vm_area_cachep, vma);
12229 + goto emulate;
12230 + }
12231 +
12232 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12233 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12234 + up_write(&current->mm->mmap_sem);
12235 + if (vma)
12236 + kmem_cache_free(vm_area_cachep, vma);
12237 + return 1;
12238 + }
12239 +
12240 + if (pax_insert_vma(vma, call_dl_resolve)) {
12241 + up_write(&current->mm->mmap_sem);
12242 + kmem_cache_free(vm_area_cachep, vma);
12243 + return 1;
12244 + }
12245 +
12246 + current->mm->call_dl_resolve = call_dl_resolve;
12247 + up_write(&current->mm->mmap_sem);
12248 +
12249 +emulate:
12250 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12251 + regs->tpc = call_dl_resolve;
12252 + regs->tnpc = addr+4;
12253 + return 3;
12254 + }
12255 +#endif
12256 +
12257 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12258 + if ((save & 0xFFC00000U) == 0x05000000U &&
12259 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12260 + nop == 0x01000000U)
12261 + {
12262 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12263 + regs->u_regs[UREG_G2] = addr + 4;
12264 + addr = (save & 0x003FFFFFU) << 10;
12265 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12266 +
12267 + if (test_thread_flag(TIF_32BIT))
12268 + addr &= 0xFFFFFFFFUL;
12269 +
12270 + regs->tpc = addr;
12271 + regs->tnpc = addr+4;
12272 + return 3;
12273 + }
12274 +
12275 + /* PaX: 64-bit PLT stub */
12276 + err = get_user(sethi1, (unsigned int *)addr);
12277 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12278 + err |= get_user(or1, (unsigned int *)(addr+8));
12279 + err |= get_user(or2, (unsigned int *)(addr+12));
12280 + err |= get_user(sllx, (unsigned int *)(addr+16));
12281 + err |= get_user(add, (unsigned int *)(addr+20));
12282 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12283 + err |= get_user(nop, (unsigned int *)(addr+28));
12284 + if (err)
12285 + break;
12286 +
12287 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12288 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12289 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12290 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12291 + sllx == 0x89293020U &&
12292 + add == 0x8A010005U &&
12293 + jmpl == 0x89C14000U &&
12294 + nop == 0x01000000U)
12295 + {
12296 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12297 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12298 + regs->u_regs[UREG_G4] <<= 32;
12299 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12300 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12301 + regs->u_regs[UREG_G4] = addr + 24;
12302 + addr = regs->u_regs[UREG_G5];
12303 + regs->tpc = addr;
12304 + regs->tnpc = addr+4;
12305 + return 3;
12306 + }
12307 + }
12308 + } while (0);
12309 +
12310 +#ifdef CONFIG_PAX_DLRESOLVE
12311 + do { /* PaX: unpatched PLT emulation step 2 */
12312 + unsigned int save, call, nop;
12313 +
12314 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12315 + err |= get_user(call, (unsigned int *)regs->tpc);
12316 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12317 + if (err)
12318 + break;
12319 +
12320 + if (save == 0x9DE3BFA8U &&
12321 + (call & 0xC0000000U) == 0x40000000U &&
12322 + nop == 0x01000000U)
12323 + {
12324 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12325 +
12326 + if (test_thread_flag(TIF_32BIT))
12327 + dl_resolve &= 0xFFFFFFFFUL;
12328 +
12329 + regs->u_regs[UREG_RETPC] = regs->tpc;
12330 + regs->tpc = dl_resolve;
12331 + regs->tnpc = dl_resolve+4;
12332 + return 3;
12333 + }
12334 + } while (0);
12335 +#endif
12336 +
12337 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12338 + unsigned int sethi, ba, nop;
12339 +
12340 + err = get_user(sethi, (unsigned int *)regs->tpc);
12341 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12342 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12343 +
12344 + if (err)
12345 + break;
12346 +
12347 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12348 + (ba & 0xFFF00000U) == 0x30600000U &&
12349 + nop == 0x01000000U)
12350 + {
12351 + unsigned long addr;
12352 +
12353 + addr = (sethi & 0x003FFFFFU) << 10;
12354 + regs->u_regs[UREG_G1] = addr;
12355 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12356 +
12357 + if (test_thread_flag(TIF_32BIT))
12358 + addr &= 0xFFFFFFFFUL;
12359 +
12360 + regs->tpc = addr;
12361 + regs->tnpc = addr+4;
12362 + return 2;
12363 + }
12364 + } while (0);
12365 +
12366 +#endif
12367 +
12368 + return 1;
12369 +}
12370 +
12371 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12372 +{
12373 + unsigned long i;
12374 +
12375 + printk(KERN_ERR "PAX: bytes at PC: ");
12376 + for (i = 0; i < 8; i++) {
12377 + unsigned int c;
12378 + if (get_user(c, (unsigned int *)pc+i))
12379 + printk(KERN_CONT "???????? ");
12380 + else
12381 + printk(KERN_CONT "%08x ", c);
12382 + }
12383 + printk("\n");
12384 +}
12385 +#endif
12386 +
12387 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12388 {
12389 enum ctx_state prev_state = exception_enter();
12390 @@ -350,6 +813,29 @@ retry:
12391 if (!vma)
12392 goto bad_area;
12393
12394 +#ifdef CONFIG_PAX_PAGEEXEC
12395 + /* PaX: detect ITLB misses on non-exec pages */
12396 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12397 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12398 + {
12399 + if (address != regs->tpc)
12400 + goto good_area;
12401 +
12402 + up_read(&mm->mmap_sem);
12403 + switch (pax_handle_fetch_fault(regs)) {
12404 +
12405 +#ifdef CONFIG_PAX_EMUPLT
12406 + case 2:
12407 + case 3:
12408 + return;
12409 +#endif
12410 +
12411 + }
12412 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12413 + do_group_exit(SIGKILL);
12414 + }
12415 +#endif
12416 +
12417 /* Pure DTLB misses do not tell us whether the fault causing
12418 * load/store/atomic was a write or not, it only says that there
12419 * was no match. So in such a case we (carefully) read the
12420 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12421 index d329537..2c3746a 100644
12422 --- a/arch/sparc/mm/hugetlbpage.c
12423 +++ b/arch/sparc/mm/hugetlbpage.c
12424 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12425 unsigned long addr,
12426 unsigned long len,
12427 unsigned long pgoff,
12428 - unsigned long flags)
12429 + unsigned long flags,
12430 + unsigned long offset)
12431 {
12432 + struct mm_struct *mm = current->mm;
12433 unsigned long task_size = TASK_SIZE;
12434 struct vm_unmapped_area_info info;
12435
12436 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12437
12438 info.flags = 0;
12439 info.length = len;
12440 - info.low_limit = TASK_UNMAPPED_BASE;
12441 + info.low_limit = mm->mmap_base;
12442 info.high_limit = min(task_size, VA_EXCLUDE_START);
12443 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12444 info.align_offset = 0;
12445 + info.threadstack_offset = offset;
12446 addr = vm_unmapped_area(&info);
12447
12448 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12449 VM_BUG_ON(addr != -ENOMEM);
12450 info.low_limit = VA_EXCLUDE_END;
12451 +
12452 +#ifdef CONFIG_PAX_RANDMMAP
12453 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12454 + info.low_limit += mm->delta_mmap;
12455 +#endif
12456 +
12457 info.high_limit = task_size;
12458 addr = vm_unmapped_area(&info);
12459 }
12460 @@ -55,7 +64,8 @@ static unsigned long
12461 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12462 const unsigned long len,
12463 const unsigned long pgoff,
12464 - const unsigned long flags)
12465 + const unsigned long flags,
12466 + const unsigned long offset)
12467 {
12468 struct mm_struct *mm = current->mm;
12469 unsigned long addr = addr0;
12470 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12471 info.high_limit = mm->mmap_base;
12472 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12473 info.align_offset = 0;
12474 + info.threadstack_offset = offset;
12475 addr = vm_unmapped_area(&info);
12476
12477 /*
12478 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12479 VM_BUG_ON(addr != -ENOMEM);
12480 info.flags = 0;
12481 info.low_limit = TASK_UNMAPPED_BASE;
12482 +
12483 +#ifdef CONFIG_PAX_RANDMMAP
12484 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12485 + info.low_limit += mm->delta_mmap;
12486 +#endif
12487 +
12488 info.high_limit = STACK_TOP32;
12489 addr = vm_unmapped_area(&info);
12490 }
12491 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12492 struct mm_struct *mm = current->mm;
12493 struct vm_area_struct *vma;
12494 unsigned long task_size = TASK_SIZE;
12495 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12496
12497 if (test_thread_flag(TIF_32BIT))
12498 task_size = STACK_TOP32;
12499 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12500 return addr;
12501 }
12502
12503 +#ifdef CONFIG_PAX_RANDMMAP
12504 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12505 +#endif
12506 +
12507 if (addr) {
12508 addr = ALIGN(addr, HPAGE_SIZE);
12509 vma = find_vma(mm, addr);
12510 - if (task_size - len >= addr &&
12511 - (!vma || addr + len <= vma->vm_start))
12512 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12513 return addr;
12514 }
12515 if (mm->get_unmapped_area == arch_get_unmapped_area)
12516 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12517 - pgoff, flags);
12518 + pgoff, flags, offset);
12519 else
12520 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12521 - pgoff, flags);
12522 + pgoff, flags, offset);
12523 }
12524
12525 pte_t *huge_pte_alloc(struct mm_struct *mm,
12526 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12527 index 2cfb0f2..e917d9f 100644
12528 --- a/arch/sparc/mm/init_64.c
12529 +++ b/arch/sparc/mm/init_64.c
12530 @@ -189,9 +189,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12531 int num_kernel_image_mappings;
12532
12533 #ifdef CONFIG_DEBUG_DCFLUSH
12534 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12535 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12536 #ifdef CONFIG_SMP
12537 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12538 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12539 #endif
12540 #endif
12541
12542 @@ -199,7 +199,7 @@ inline void flush_dcache_page_impl(struct page *page)
12543 {
12544 BUG_ON(tlb_type == hypervisor);
12545 #ifdef CONFIG_DEBUG_DCFLUSH
12546 - atomic_inc(&dcpage_flushes);
12547 + atomic_inc_unchecked(&dcpage_flushes);
12548 #endif
12549
12550 #ifdef DCACHE_ALIASING_POSSIBLE
12551 @@ -471,10 +471,10 @@ void mmu_info(struct seq_file *m)
12552
12553 #ifdef CONFIG_DEBUG_DCFLUSH
12554 seq_printf(m, "DCPageFlushes\t: %d\n",
12555 - atomic_read(&dcpage_flushes));
12556 + atomic_read_unchecked(&dcpage_flushes));
12557 #ifdef CONFIG_SMP
12558 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12559 - atomic_read(&dcpage_flushes_xcall));
12560 + atomic_read_unchecked(&dcpage_flushes_xcall));
12561 #endif /* CONFIG_SMP */
12562 #endif /* CONFIG_DEBUG_DCFLUSH */
12563 }
12564 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12565 index 4f3006b..453f625f 100644
12566 --- a/arch/tile/Kconfig
12567 +++ b/arch/tile/Kconfig
12568 @@ -192,6 +192,7 @@ source "kernel/Kconfig.hz"
12569
12570 config KEXEC
12571 bool "kexec system call"
12572 + depends on !GRKERNSEC_KMEM
12573 ---help---
12574 kexec is a system call that implements the ability to shutdown your
12575 current kernel, and to start another kernel. It is like a reboot
12576 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12577 index 7b11c5f..755a026 100644
12578 --- a/arch/tile/include/asm/atomic_64.h
12579 +++ b/arch/tile/include/asm/atomic_64.h
12580 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12581
12582 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12583
12584 +#define atomic64_read_unchecked(v) atomic64_read(v)
12585 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12586 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12587 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12588 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12589 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12590 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12591 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12592 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12593 +
12594 /* Define this to indicate that cmpxchg is an efficient operation. */
12595 #define __HAVE_ARCH_CMPXCHG
12596
12597 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12598 index 6160761..00cac88 100644
12599 --- a/arch/tile/include/asm/cache.h
12600 +++ b/arch/tile/include/asm/cache.h
12601 @@ -15,11 +15,12 @@
12602 #ifndef _ASM_TILE_CACHE_H
12603 #define _ASM_TILE_CACHE_H
12604
12605 +#include <linux/const.h>
12606 #include <arch/chip.h>
12607
12608 /* bytes per L1 data cache line */
12609 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12610 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12611 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12612
12613 /* bytes per L2 cache line */
12614 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12615 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12616 index b6cde32..c0cb736 100644
12617 --- a/arch/tile/include/asm/uaccess.h
12618 +++ b/arch/tile/include/asm/uaccess.h
12619 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12620 const void __user *from,
12621 unsigned long n)
12622 {
12623 - int sz = __compiletime_object_size(to);
12624 + size_t sz = __compiletime_object_size(to);
12625
12626 - if (likely(sz == -1 || sz >= n))
12627 + if (likely(sz == (size_t)-1 || sz >= n))
12628 n = _copy_from_user(to, from, n);
12629 else
12630 copy_from_user_overflow();
12631 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12632 index e514899..f8743c4 100644
12633 --- a/arch/tile/mm/hugetlbpage.c
12634 +++ b/arch/tile/mm/hugetlbpage.c
12635 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12636 info.high_limit = TASK_SIZE;
12637 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12638 info.align_offset = 0;
12639 + info.threadstack_offset = 0;
12640 return vm_unmapped_area(&info);
12641 }
12642
12643 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12644 info.high_limit = current->mm->mmap_base;
12645 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12646 info.align_offset = 0;
12647 + info.threadstack_offset = 0;
12648 addr = vm_unmapped_area(&info);
12649
12650 /*
12651 diff --git a/arch/um/Makefile b/arch/um/Makefile
12652 index e4b1a96..16162f8 100644
12653 --- a/arch/um/Makefile
12654 +++ b/arch/um/Makefile
12655 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12656 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12657 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12658
12659 +ifdef CONSTIFY_PLUGIN
12660 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12661 +endif
12662 +
12663 #This will adjust *FLAGS accordingly to the platform.
12664 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12665
12666 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12667 index 19e1bdd..3665b77 100644
12668 --- a/arch/um/include/asm/cache.h
12669 +++ b/arch/um/include/asm/cache.h
12670 @@ -1,6 +1,7 @@
12671 #ifndef __UM_CACHE_H
12672 #define __UM_CACHE_H
12673
12674 +#include <linux/const.h>
12675
12676 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12677 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12678 @@ -12,6 +13,6 @@
12679 # define L1_CACHE_SHIFT 5
12680 #endif
12681
12682 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12683 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12684
12685 #endif
12686 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12687 index 2e0a6b1..a64d0f5 100644
12688 --- a/arch/um/include/asm/kmap_types.h
12689 +++ b/arch/um/include/asm/kmap_types.h
12690 @@ -8,6 +8,6 @@
12691
12692 /* No more #include "asm/arch/kmap_types.h" ! */
12693
12694 -#define KM_TYPE_NR 14
12695 +#define KM_TYPE_NR 15
12696
12697 #endif
12698 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12699 index 5ff53d9..5850cdf 100644
12700 --- a/arch/um/include/asm/page.h
12701 +++ b/arch/um/include/asm/page.h
12702 @@ -14,6 +14,9 @@
12703 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12704 #define PAGE_MASK (~(PAGE_SIZE-1))
12705
12706 +#define ktla_ktva(addr) (addr)
12707 +#define ktva_ktla(addr) (addr)
12708 +
12709 #ifndef __ASSEMBLY__
12710
12711 struct page;
12712 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12713 index 0032f92..cd151e0 100644
12714 --- a/arch/um/include/asm/pgtable-3level.h
12715 +++ b/arch/um/include/asm/pgtable-3level.h
12716 @@ -58,6 +58,7 @@
12717 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12718 #define pud_populate(mm, pud, pmd) \
12719 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12720 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12721
12722 #ifdef CONFIG_64BIT
12723 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12724 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12725 index f17bca8..48adb87 100644
12726 --- a/arch/um/kernel/process.c
12727 +++ b/arch/um/kernel/process.c
12728 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12729 return 2;
12730 }
12731
12732 -/*
12733 - * Only x86 and x86_64 have an arch_align_stack().
12734 - * All other arches have "#define arch_align_stack(x) (x)"
12735 - * in their asm/exec.h
12736 - * As this is included in UML from asm-um/system-generic.h,
12737 - * we can use it to behave as the subarch does.
12738 - */
12739 -#ifndef arch_align_stack
12740 -unsigned long arch_align_stack(unsigned long sp)
12741 -{
12742 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12743 - sp -= get_random_int() % 8192;
12744 - return sp & ~0xf;
12745 -}
12746 -#endif
12747 -
12748 unsigned long get_wchan(struct task_struct *p)
12749 {
12750 unsigned long stack_page, sp, ip;
12751 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12752 index ad8f795..2c7eec6 100644
12753 --- a/arch/unicore32/include/asm/cache.h
12754 +++ b/arch/unicore32/include/asm/cache.h
12755 @@ -12,8 +12,10 @@
12756 #ifndef __UNICORE_CACHE_H__
12757 #define __UNICORE_CACHE_H__
12758
12759 -#define L1_CACHE_SHIFT (5)
12760 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12761 +#include <linux/const.h>
12762 +
12763 +#define L1_CACHE_SHIFT 5
12764 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12765
12766 /*
12767 * Memory returned by kmalloc() may be used for DMA, so we must make
12768 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12769 index 27adfd9..bc3551d 100644
12770 --- a/arch/x86/Kconfig
12771 +++ b/arch/x86/Kconfig
12772 @@ -128,7 +128,7 @@ config X86
12773 select RTC_LIB
12774 select HAVE_DEBUG_STACKOVERFLOW
12775 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12776 - select HAVE_CC_STACKPROTECTOR
12777 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12778 select GENERIC_CPU_AUTOPROBE
12779 select HAVE_ARCH_AUDITSYSCALL
12780 select ARCH_SUPPORTS_ATOMIC_RMW
12781 @@ -253,7 +253,7 @@ config X86_HT
12782
12783 config X86_32_LAZY_GS
12784 def_bool y
12785 - depends on X86_32 && !CC_STACKPROTECTOR
12786 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12787
12788 config ARCH_HWEIGHT_CFLAGS
12789 string
12790 @@ -549,6 +549,7 @@ config SCHED_OMIT_FRAME_POINTER
12791
12792 menuconfig HYPERVISOR_GUEST
12793 bool "Linux guest support"
12794 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12795 ---help---
12796 Say Y here to enable options for running Linux under various hyper-
12797 visors. This option enables basic hypervisor detection and platform
12798 @@ -1076,6 +1077,7 @@ choice
12799
12800 config NOHIGHMEM
12801 bool "off"
12802 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12803 ---help---
12804 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12805 However, the address space of 32-bit x86 processors is only 4
12806 @@ -1112,6 +1114,7 @@ config NOHIGHMEM
12807
12808 config HIGHMEM4G
12809 bool "4GB"
12810 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12811 ---help---
12812 Select this if you have a 32-bit processor and between 1 and 4
12813 gigabytes of physical RAM.
12814 @@ -1164,7 +1167,7 @@ config PAGE_OFFSET
12815 hex
12816 default 0xB0000000 if VMSPLIT_3G_OPT
12817 default 0x80000000 if VMSPLIT_2G
12818 - default 0x78000000 if VMSPLIT_2G_OPT
12819 + default 0x70000000 if VMSPLIT_2G_OPT
12820 default 0x40000000 if VMSPLIT_1G
12821 default 0xC0000000
12822 depends on X86_32
12823 @@ -1578,6 +1581,7 @@ source kernel/Kconfig.hz
12824
12825 config KEXEC
12826 bool "kexec system call"
12827 + depends on !GRKERNSEC_KMEM
12828 ---help---
12829 kexec is a system call that implements the ability to shutdown your
12830 current kernel, and to start another kernel. It is like a reboot
12831 @@ -1728,7 +1732,9 @@ config X86_NEED_RELOCS
12832
12833 config PHYSICAL_ALIGN
12834 hex "Alignment value to which kernel should be aligned"
12835 - default "0x200000"
12836 + default "0x1000000"
12837 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12838 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12839 range 0x2000 0x1000000 if X86_32
12840 range 0x200000 0x1000000 if X86_64
12841 ---help---
12842 @@ -1811,6 +1817,7 @@ config COMPAT_VDSO
12843 def_bool n
12844 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12845 depends on X86_32 || IA32_EMULATION
12846 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12847 ---help---
12848 Certain buggy versions of glibc will crash if they are
12849 presented with a 32-bit vDSO that is not mapped at the address
12850 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12851 index 6983314..54ad7e8 100644
12852 --- a/arch/x86/Kconfig.cpu
12853 +++ b/arch/x86/Kconfig.cpu
12854 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12855
12856 config X86_F00F_BUG
12857 def_bool y
12858 - depends on M586MMX || M586TSC || M586 || M486
12859 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12860
12861 config X86_INVD_BUG
12862 def_bool y
12863 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12864
12865 config X86_ALIGNMENT_16
12866 def_bool y
12867 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12868 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12869
12870 config X86_INTEL_USERCOPY
12871 def_bool y
12872 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12873 # generates cmov.
12874 config X86_CMOV
12875 def_bool y
12876 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12877 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12878
12879 config X86_MINIMUM_CPU_FAMILY
12880 int
12881 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12882 index 61bd2ad..50b625d 100644
12883 --- a/arch/x86/Kconfig.debug
12884 +++ b/arch/x86/Kconfig.debug
12885 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12886 config DEBUG_RODATA
12887 bool "Write protect kernel read-only data structures"
12888 default y
12889 - depends on DEBUG_KERNEL
12890 + depends on DEBUG_KERNEL && BROKEN
12891 ---help---
12892 Mark the kernel read-only data as write-protected in the pagetables,
12893 in order to catch accidental (and incorrect) writes to such const
12894 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12895
12896 config DEBUG_SET_MODULE_RONX
12897 bool "Set loadable kernel module data as NX and text as RO"
12898 - depends on MODULES
12899 + depends on MODULES && BROKEN
12900 ---help---
12901 This option helps catch unintended modifications to loadable
12902 kernel module's text and read-only data. It also prevents execution
12903 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12904 index 33f71b0..c2cefa2 100644
12905 --- a/arch/x86/Makefile
12906 +++ b/arch/x86/Makefile
12907 @@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12908 # CPU-specific tuning. Anything which can be shared with UML should go here.
12909 include $(srctree)/arch/x86/Makefile_32.cpu
12910 KBUILD_CFLAGS += $(cflags-y)
12911 -
12912 - # temporary until string.h is fixed
12913 - KBUILD_CFLAGS += -ffreestanding
12914 else
12915 BITS := 64
12916 UTS_MACHINE := x86_64
12917 @@ -114,6 +111,9 @@ else
12918 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12919 endif
12920
12921 +# temporary until string.h is fixed
12922 +KBUILD_CFLAGS += -ffreestanding
12923 +
12924 # Make sure compiler does not have buggy stack-protector support.
12925 ifdef CONFIG_CC_STACKPROTECTOR
12926 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12927 @@ -271,3 +271,12 @@ define archhelp
12928 echo ' FDINITRD=file initrd for the booted kernel'
12929 echo ' kvmconfig - Enable additional options for guest kernel support'
12930 endef
12931 +
12932 +define OLD_LD
12933 +
12934 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12935 +*** Please upgrade your binutils to 2.18 or newer
12936 +endef
12937 +
12938 +archprepare:
12939 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12940 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12941 index dbe8dd2..2f0a98f 100644
12942 --- a/arch/x86/boot/Makefile
12943 +++ b/arch/x86/boot/Makefile
12944 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12945 # ---------------------------------------------------------------------------
12946
12947 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12948 +ifdef CONSTIFY_PLUGIN
12949 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12950 +endif
12951 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12952 GCOV_PROFILE := n
12953
12954 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12955 index 878e4b9..20537ab 100644
12956 --- a/arch/x86/boot/bitops.h
12957 +++ b/arch/x86/boot/bitops.h
12958 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12959 u8 v;
12960 const u32 *p = (const u32 *)addr;
12961
12962 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12963 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12964 return v;
12965 }
12966
12967 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12968
12969 static inline void set_bit(int nr, void *addr)
12970 {
12971 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12972 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12973 }
12974
12975 #endif /* BOOT_BITOPS_H */
12976 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12977 index bd49ec6..94c7f58 100644
12978 --- a/arch/x86/boot/boot.h
12979 +++ b/arch/x86/boot/boot.h
12980 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12981 static inline u16 ds(void)
12982 {
12983 u16 seg;
12984 - asm("movw %%ds,%0" : "=rm" (seg));
12985 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12986 return seg;
12987 }
12988
12989 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12990 index 0fcd913..3bb5c42 100644
12991 --- a/arch/x86/boot/compressed/Makefile
12992 +++ b/arch/x86/boot/compressed/Makefile
12993 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12994 KBUILD_CFLAGS += -mno-mmx -mno-sse
12995 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12996 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12997 +ifdef CONSTIFY_PLUGIN
12998 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12999 +endif
13000
13001 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13002 GCOV_PROFILE := n
13003 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
13004 index a53440e..c3dbf1e 100644
13005 --- a/arch/x86/boot/compressed/efi_stub_32.S
13006 +++ b/arch/x86/boot/compressed/efi_stub_32.S
13007 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
13008 * parameter 2, ..., param n. To make things easy, we save the return
13009 * address of efi_call_phys in a global variable.
13010 */
13011 - popl %ecx
13012 - movl %ecx, saved_return_addr(%edx)
13013 - /* get the function pointer into ECX*/
13014 - popl %ecx
13015 - movl %ecx, efi_rt_function_ptr(%edx)
13016 + popl saved_return_addr(%edx)
13017 + popl efi_rt_function_ptr(%edx)
13018
13019 /*
13020 * 3. Call the physical function.
13021 */
13022 - call *%ecx
13023 + call *efi_rt_function_ptr(%edx)
13024
13025 /*
13026 * 4. Balance the stack. And because EAX contain the return value,
13027 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
13028 1: popl %edx
13029 subl $1b, %edx
13030
13031 - movl efi_rt_function_ptr(%edx), %ecx
13032 - pushl %ecx
13033 + pushl efi_rt_function_ptr(%edx)
13034
13035 /*
13036 * 10. Push the saved return address onto the stack and return.
13037 */
13038 - movl saved_return_addr(%edx), %ecx
13039 - pushl %ecx
13040 - ret
13041 + jmpl *saved_return_addr(%edx)
13042 ENDPROC(efi_call_phys)
13043 .previous
13044
13045 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
13046 index cbed140..5f2ca57 100644
13047 --- a/arch/x86/boot/compressed/head_32.S
13048 +++ b/arch/x86/boot/compressed/head_32.S
13049 @@ -140,10 +140,10 @@ preferred_addr:
13050 addl %eax, %ebx
13051 notl %eax
13052 andl %eax, %ebx
13053 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13054 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13055 jge 1f
13056 #endif
13057 - movl $LOAD_PHYSICAL_ADDR, %ebx
13058 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13059 1:
13060
13061 /* Target address to relocate to for decompression */
13062 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
13063 index 2884e0c..904a2f7 100644
13064 --- a/arch/x86/boot/compressed/head_64.S
13065 +++ b/arch/x86/boot/compressed/head_64.S
13066 @@ -94,10 +94,10 @@ ENTRY(startup_32)
13067 addl %eax, %ebx
13068 notl %eax
13069 andl %eax, %ebx
13070 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13071 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13072 jge 1f
13073 #endif
13074 - movl $LOAD_PHYSICAL_ADDR, %ebx
13075 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13076 1:
13077
13078 /* Target address to relocate to for decompression */
13079 @@ -322,10 +322,10 @@ preferred_addr:
13080 addq %rax, %rbp
13081 notq %rax
13082 andq %rax, %rbp
13083 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
13084 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
13085 jge 1f
13086 #endif
13087 - movq $LOAD_PHYSICAL_ADDR, %rbp
13088 + movq $____LOAD_PHYSICAL_ADDR, %rbp
13089 1:
13090
13091 /* Target address to relocate to for decompression */
13092 @@ -431,8 +431,8 @@ gdt:
13093 .long gdt
13094 .word 0
13095 .quad 0x0000000000000000 /* NULL descriptor */
13096 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
13097 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
13098 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
13099 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
13100 .quad 0x0080890000000000 /* TS descriptor */
13101 .quad 0x0000000000000000 /* TS continued */
13102 gdt_end:
13103 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
13104 index 57ab74d..7c52182 100644
13105 --- a/arch/x86/boot/compressed/misc.c
13106 +++ b/arch/x86/boot/compressed/misc.c
13107 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
13108 * Calculate the delta between where vmlinux was linked to load
13109 * and where it was actually loaded.
13110 */
13111 - delta = min_addr - LOAD_PHYSICAL_ADDR;
13112 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
13113 if (!delta) {
13114 debug_putstr("No relocation needed... ");
13115 return;
13116 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
13117 Elf32_Ehdr ehdr;
13118 Elf32_Phdr *phdrs, *phdr;
13119 #endif
13120 - void *dest;
13121 + void *dest, *prev;
13122 int i;
13123
13124 memcpy(&ehdr, output, sizeof(ehdr));
13125 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
13126 case PT_LOAD:
13127 #ifdef CONFIG_RELOCATABLE
13128 dest = output;
13129 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
13130 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
13131 #else
13132 dest = (void *)(phdr->p_paddr);
13133 #endif
13134 memcpy(dest,
13135 output + phdr->p_offset,
13136 phdr->p_filesz);
13137 + if (i)
13138 + memset(prev, 0xff, dest - prev);
13139 + prev = dest + phdr->p_filesz;
13140 break;
13141 default: /* Ignore other PT_* */ break;
13142 }
13143 @@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
13144 error("Destination address too large");
13145 #endif
13146 #ifndef CONFIG_RELOCATABLE
13147 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
13148 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
13149 error("Wrong destination address");
13150 #endif
13151
13152 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
13153 index 1fd7d57..0f7d096 100644
13154 --- a/arch/x86/boot/cpucheck.c
13155 +++ b/arch/x86/boot/cpucheck.c
13156 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13157 u32 ecx = MSR_K7_HWCR;
13158 u32 eax, edx;
13159
13160 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13161 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13162 eax &= ~(1 << 15);
13163 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13164 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13165
13166 get_cpuflags(); /* Make sure it really did something */
13167 err = check_cpuflags();
13168 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13169 u32 ecx = MSR_VIA_FCR;
13170 u32 eax, edx;
13171
13172 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13173 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13174 eax |= (1<<1)|(1<<7);
13175 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13176 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13177
13178 set_bit(X86_FEATURE_CX8, cpu.flags);
13179 err = check_cpuflags();
13180 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13181 u32 eax, edx;
13182 u32 level = 1;
13183
13184 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13185 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13186 - asm("cpuid"
13187 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13188 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13189 + asm volatile("cpuid"
13190 : "+a" (level), "=d" (cpu.flags[0])
13191 : : "ecx", "ebx");
13192 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13193 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13194
13195 err = check_cpuflags();
13196 } else if (err == 0x01 &&
13197 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13198 index 7a6d43a..edf6e40 100644
13199 --- a/arch/x86/boot/header.S
13200 +++ b/arch/x86/boot/header.S
13201 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13202 # single linked list of
13203 # struct setup_data
13204
13205 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13206 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13207
13208 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13209 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13210 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13211 +#else
13212 #define VO_INIT_SIZE (VO__end - VO__text)
13213 +#endif
13214 #if ZO_INIT_SIZE > VO_INIT_SIZE
13215 #define INIT_SIZE ZO_INIT_SIZE
13216 #else
13217 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13218 index db75d07..8e6d0af 100644
13219 --- a/arch/x86/boot/memory.c
13220 +++ b/arch/x86/boot/memory.c
13221 @@ -19,7 +19,7 @@
13222
13223 static int detect_memory_e820(void)
13224 {
13225 - int count = 0;
13226 + unsigned int count = 0;
13227 struct biosregs ireg, oreg;
13228 struct e820entry *desc = boot_params.e820_map;
13229 static struct e820entry buf; /* static so it is zeroed */
13230 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13231 index ba3e100..6501b8f 100644
13232 --- a/arch/x86/boot/video-vesa.c
13233 +++ b/arch/x86/boot/video-vesa.c
13234 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13235
13236 boot_params.screen_info.vesapm_seg = oreg.es;
13237 boot_params.screen_info.vesapm_off = oreg.di;
13238 + boot_params.screen_info.vesapm_size = oreg.cx;
13239 }
13240
13241 /*
13242 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13243 index 43eda28..5ab5fdb 100644
13244 --- a/arch/x86/boot/video.c
13245 +++ b/arch/x86/boot/video.c
13246 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13247 static unsigned int get_entry(void)
13248 {
13249 char entry_buf[4];
13250 - int i, len = 0;
13251 + unsigned int i, len = 0;
13252 int key;
13253 unsigned int v;
13254
13255 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13256 index 9105655..41779c1 100644
13257 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13258 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13259 @@ -8,6 +8,8 @@
13260 * including this sentence is retained in full.
13261 */
13262
13263 +#include <asm/alternative-asm.h>
13264 +
13265 .extern crypto_ft_tab
13266 .extern crypto_it_tab
13267 .extern crypto_fl_tab
13268 @@ -70,6 +72,8 @@
13269 je B192; \
13270 leaq 32(r9),r9;
13271
13272 +#define ret pax_force_retaddr; ret
13273 +
13274 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13275 movq r1,r2; \
13276 movq r3,r4; \
13277 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13278 index 477e9d7..c92c7d8 100644
13279 --- a/arch/x86/crypto/aesni-intel_asm.S
13280 +++ b/arch/x86/crypto/aesni-intel_asm.S
13281 @@ -31,6 +31,7 @@
13282
13283 #include <linux/linkage.h>
13284 #include <asm/inst.h>
13285 +#include <asm/alternative-asm.h>
13286
13287 #ifdef __x86_64__
13288 .data
13289 @@ -205,7 +206,7 @@ enc: .octa 0x2
13290 * num_initial_blocks = b mod 4
13291 * encrypt the initial num_initial_blocks blocks and apply ghash on
13292 * the ciphertext
13293 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13294 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13295 * are clobbered
13296 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13297 */
13298 @@ -214,8 +215,8 @@ enc: .octa 0x2
13299 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13300 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13301 mov arg7, %r10 # %r10 = AAD
13302 - mov arg8, %r12 # %r12 = aadLen
13303 - mov %r12, %r11
13304 + mov arg8, %r15 # %r15 = aadLen
13305 + mov %r15, %r11
13306 pxor %xmm\i, %xmm\i
13307 _get_AAD_loop\num_initial_blocks\operation:
13308 movd (%r10), \TMP1
13309 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13310 psrldq $4, %xmm\i
13311 pxor \TMP1, %xmm\i
13312 add $4, %r10
13313 - sub $4, %r12
13314 + sub $4, %r15
13315 jne _get_AAD_loop\num_initial_blocks\operation
13316 cmp $16, %r11
13317 je _get_AAD_loop2_done\num_initial_blocks\operation
13318 - mov $16, %r12
13319 + mov $16, %r15
13320 _get_AAD_loop2\num_initial_blocks\operation:
13321 psrldq $4, %xmm\i
13322 - sub $4, %r12
13323 - cmp %r11, %r12
13324 + sub $4, %r15
13325 + cmp %r11, %r15
13326 jne _get_AAD_loop2\num_initial_blocks\operation
13327 _get_AAD_loop2_done\num_initial_blocks\operation:
13328 movdqa SHUF_MASK(%rip), %xmm14
13329 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13330 * num_initial_blocks = b mod 4
13331 * encrypt the initial num_initial_blocks blocks and apply ghash on
13332 * the ciphertext
13333 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13334 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13335 * are clobbered
13336 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13337 */
13338 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13339 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13340 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13341 mov arg7, %r10 # %r10 = AAD
13342 - mov arg8, %r12 # %r12 = aadLen
13343 - mov %r12, %r11
13344 + mov arg8, %r15 # %r15 = aadLen
13345 + mov %r15, %r11
13346 pxor %xmm\i, %xmm\i
13347 _get_AAD_loop\num_initial_blocks\operation:
13348 movd (%r10), \TMP1
13349 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13350 psrldq $4, %xmm\i
13351 pxor \TMP1, %xmm\i
13352 add $4, %r10
13353 - sub $4, %r12
13354 + sub $4, %r15
13355 jne _get_AAD_loop\num_initial_blocks\operation
13356 cmp $16, %r11
13357 je _get_AAD_loop2_done\num_initial_blocks\operation
13358 - mov $16, %r12
13359 + mov $16, %r15
13360 _get_AAD_loop2\num_initial_blocks\operation:
13361 psrldq $4, %xmm\i
13362 - sub $4, %r12
13363 - cmp %r11, %r12
13364 + sub $4, %r15
13365 + cmp %r11, %r15
13366 jne _get_AAD_loop2\num_initial_blocks\operation
13367 _get_AAD_loop2_done\num_initial_blocks\operation:
13368 movdqa SHUF_MASK(%rip), %xmm14
13369 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13370 *
13371 *****************************************************************************/
13372 ENTRY(aesni_gcm_dec)
13373 - push %r12
13374 + push %r15
13375 push %r13
13376 push %r14
13377 mov %rsp, %r14
13378 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13379 */
13380 sub $VARIABLE_OFFSET, %rsp
13381 and $~63, %rsp # align rsp to 64 bytes
13382 - mov %arg6, %r12
13383 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13384 + mov %arg6, %r15
13385 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13386 movdqa SHUF_MASK(%rip), %xmm2
13387 PSHUFB_XMM %xmm2, %xmm13
13388
13389 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13390 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13391 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13392 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13393 - mov %r13, %r12
13394 - and $(3<<4), %r12
13395 + mov %r13, %r15
13396 + and $(3<<4), %r15
13397 jz _initial_num_blocks_is_0_decrypt
13398 - cmp $(2<<4), %r12
13399 + cmp $(2<<4), %r15
13400 jb _initial_num_blocks_is_1_decrypt
13401 je _initial_num_blocks_is_2_decrypt
13402 _initial_num_blocks_is_3_decrypt:
13403 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13404 sub $16, %r11
13405 add %r13, %r11
13406 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13407 - lea SHIFT_MASK+16(%rip), %r12
13408 - sub %r13, %r12
13409 + lea SHIFT_MASK+16(%rip), %r15
13410 + sub %r13, %r15
13411 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13412 # (%r13 is the number of bytes in plaintext mod 16)
13413 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13414 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13415 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13416
13417 movdqa %xmm1, %xmm2
13418 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13419 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13420 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13421 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13422 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13423 pand %xmm1, %xmm2
13424 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13425 sub $1, %r13
13426 jne _less_than_8_bytes_left_decrypt
13427 _multiple_of_16_bytes_decrypt:
13428 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13429 - shl $3, %r12 # convert into number of bits
13430 - movd %r12d, %xmm15 # len(A) in %xmm15
13431 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13432 + shl $3, %r15 # convert into number of bits
13433 + movd %r15d, %xmm15 # len(A) in %xmm15
13434 shl $3, %arg4 # len(C) in bits (*128)
13435 MOVQ_R64_XMM %arg4, %xmm1
13436 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13437 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13438 mov %r14, %rsp
13439 pop %r14
13440 pop %r13
13441 - pop %r12
13442 + pop %r15
13443 + pax_force_retaddr
13444 ret
13445 ENDPROC(aesni_gcm_dec)
13446
13447 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13448 * poly = x^128 + x^127 + x^126 + x^121 + 1
13449 ***************************************************************************/
13450 ENTRY(aesni_gcm_enc)
13451 - push %r12
13452 + push %r15
13453 push %r13
13454 push %r14
13455 mov %rsp, %r14
13456 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13457 #
13458 sub $VARIABLE_OFFSET, %rsp
13459 and $~63, %rsp
13460 - mov %arg6, %r12
13461 - movdqu (%r12), %xmm13
13462 + mov %arg6, %r15
13463 + movdqu (%r15), %xmm13
13464 movdqa SHUF_MASK(%rip), %xmm2
13465 PSHUFB_XMM %xmm2, %xmm13
13466
13467 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13468 movdqa %xmm13, HashKey(%rsp)
13469 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13470 and $-16, %r13
13471 - mov %r13, %r12
13472 + mov %r13, %r15
13473
13474 # Encrypt first few blocks
13475
13476 - and $(3<<4), %r12
13477 + and $(3<<4), %r15
13478 jz _initial_num_blocks_is_0_encrypt
13479 - cmp $(2<<4), %r12
13480 + cmp $(2<<4), %r15
13481 jb _initial_num_blocks_is_1_encrypt
13482 je _initial_num_blocks_is_2_encrypt
13483 _initial_num_blocks_is_3_encrypt:
13484 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13485 sub $16, %r11
13486 add %r13, %r11
13487 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13488 - lea SHIFT_MASK+16(%rip), %r12
13489 - sub %r13, %r12
13490 + lea SHIFT_MASK+16(%rip), %r15
13491 + sub %r13, %r15
13492 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13493 # (%r13 is the number of bytes in plaintext mod 16)
13494 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13495 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13496 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13497 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13498 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13499 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13500 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13501 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13502 movdqa SHUF_MASK(%rip), %xmm10
13503 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13504 sub $1, %r13
13505 jne _less_than_8_bytes_left_encrypt
13506 _multiple_of_16_bytes_encrypt:
13507 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13508 - shl $3, %r12
13509 - movd %r12d, %xmm15 # len(A) in %xmm15
13510 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13511 + shl $3, %r15
13512 + movd %r15d, %xmm15 # len(A) in %xmm15
13513 shl $3, %arg4 # len(C) in bits (*128)
13514 MOVQ_R64_XMM %arg4, %xmm1
13515 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13516 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13517 mov %r14, %rsp
13518 pop %r14
13519 pop %r13
13520 - pop %r12
13521 + pop %r15
13522 + pax_force_retaddr
13523 ret
13524 ENDPROC(aesni_gcm_enc)
13525
13526 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13527 pxor %xmm1, %xmm0
13528 movaps %xmm0, (TKEYP)
13529 add $0x10, TKEYP
13530 + pax_force_retaddr
13531 ret
13532 ENDPROC(_key_expansion_128)
13533 ENDPROC(_key_expansion_256a)
13534 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13535 shufps $0b01001110, %xmm2, %xmm1
13536 movaps %xmm1, 0x10(TKEYP)
13537 add $0x20, TKEYP
13538 + pax_force_retaddr
13539 ret
13540 ENDPROC(_key_expansion_192a)
13541
13542 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13543
13544 movaps %xmm0, (TKEYP)
13545 add $0x10, TKEYP
13546 + pax_force_retaddr
13547 ret
13548 ENDPROC(_key_expansion_192b)
13549
13550 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13551 pxor %xmm1, %xmm2
13552 movaps %xmm2, (TKEYP)
13553 add $0x10, TKEYP
13554 + pax_force_retaddr
13555 ret
13556 ENDPROC(_key_expansion_256b)
13557
13558 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13559 #ifndef __x86_64__
13560 popl KEYP
13561 #endif
13562 + pax_force_retaddr
13563 ret
13564 ENDPROC(aesni_set_key)
13565
13566 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13567 popl KLEN
13568 popl KEYP
13569 #endif
13570 + pax_force_retaddr
13571 ret
13572 ENDPROC(aesni_enc)
13573
13574 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13575 AESENC KEY STATE
13576 movaps 0x70(TKEYP), KEY
13577 AESENCLAST KEY STATE
13578 + pax_force_retaddr
13579 ret
13580 ENDPROC(_aesni_enc1)
13581
13582 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13583 AESENCLAST KEY STATE2
13584 AESENCLAST KEY STATE3
13585 AESENCLAST KEY STATE4
13586 + pax_force_retaddr
13587 ret
13588 ENDPROC(_aesni_enc4)
13589
13590 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13591 popl KLEN
13592 popl KEYP
13593 #endif
13594 + pax_force_retaddr
13595 ret
13596 ENDPROC(aesni_dec)
13597
13598 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13599 AESDEC KEY STATE
13600 movaps 0x70(TKEYP), KEY
13601 AESDECLAST KEY STATE
13602 + pax_force_retaddr
13603 ret
13604 ENDPROC(_aesni_dec1)
13605
13606 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13607 AESDECLAST KEY STATE2
13608 AESDECLAST KEY STATE3
13609 AESDECLAST KEY STATE4
13610 + pax_force_retaddr
13611 ret
13612 ENDPROC(_aesni_dec4)
13613
13614 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13615 popl KEYP
13616 popl LEN
13617 #endif
13618 + pax_force_retaddr
13619 ret
13620 ENDPROC(aesni_ecb_enc)
13621
13622 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13623 popl KEYP
13624 popl LEN
13625 #endif
13626 + pax_force_retaddr
13627 ret
13628 ENDPROC(aesni_ecb_dec)
13629
13630 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13631 popl LEN
13632 popl IVP
13633 #endif
13634 + pax_force_retaddr
13635 ret
13636 ENDPROC(aesni_cbc_enc)
13637
13638 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13639 popl LEN
13640 popl IVP
13641 #endif
13642 + pax_force_retaddr
13643 ret
13644 ENDPROC(aesni_cbc_dec)
13645
13646 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13647 mov $1, TCTR_LOW
13648 MOVQ_R64_XMM TCTR_LOW INC
13649 MOVQ_R64_XMM CTR TCTR_LOW
13650 + pax_force_retaddr
13651 ret
13652 ENDPROC(_aesni_inc_init)
13653
13654 @@ -2579,6 +2598,7 @@ _aesni_inc:
13655 .Linc_low:
13656 movaps CTR, IV
13657 PSHUFB_XMM BSWAP_MASK IV
13658 + pax_force_retaddr
13659 ret
13660 ENDPROC(_aesni_inc)
13661
13662 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13663 .Lctr_enc_ret:
13664 movups IV, (IVP)
13665 .Lctr_enc_just_ret:
13666 + pax_force_retaddr
13667 ret
13668 ENDPROC(aesni_ctr_enc)
13669
13670 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13671 pxor INC, STATE4
13672 movdqu STATE4, 0x70(OUTP)
13673
13674 + pax_force_retaddr
13675 ret
13676 ENDPROC(aesni_xts_crypt8)
13677
13678 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13679 index 246c670..466e2d6 100644
13680 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13681 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13682 @@ -21,6 +21,7 @@
13683 */
13684
13685 #include <linux/linkage.h>
13686 +#include <asm/alternative-asm.h>
13687
13688 .file "blowfish-x86_64-asm.S"
13689 .text
13690 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13691 jnz .L__enc_xor;
13692
13693 write_block();
13694 + pax_force_retaddr
13695 ret;
13696 .L__enc_xor:
13697 xor_block();
13698 + pax_force_retaddr
13699 ret;
13700 ENDPROC(__blowfish_enc_blk)
13701
13702 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13703
13704 movq %r11, %rbp;
13705
13706 + pax_force_retaddr
13707 ret;
13708 ENDPROC(blowfish_dec_blk)
13709
13710 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13711
13712 popq %rbx;
13713 popq %rbp;
13714 + pax_force_retaddr
13715 ret;
13716
13717 .L__enc_xor4:
13718 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13719
13720 popq %rbx;
13721 popq %rbp;
13722 + pax_force_retaddr
13723 ret;
13724 ENDPROC(__blowfish_enc_blk_4way)
13725
13726 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13727 popq %rbx;
13728 popq %rbp;
13729
13730 + pax_force_retaddr
13731 ret;
13732 ENDPROC(blowfish_dec_blk_4way)
13733 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13734 index ce71f92..1dce7ec 100644
13735 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13736 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13737 @@ -16,6 +16,7 @@
13738 */
13739
13740 #include <linux/linkage.h>
13741 +#include <asm/alternative-asm.h>
13742
13743 #define CAMELLIA_TABLE_BYTE_LEN 272
13744
13745 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13746 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13747 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13748 %rcx, (%r9));
13749 + pax_force_retaddr
13750 ret;
13751 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13752
13753 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13754 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13755 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13756 %rax, (%r9));
13757 + pax_force_retaddr
13758 ret;
13759 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13760
13761 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13762 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13763 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13764
13765 + pax_force_retaddr
13766 ret;
13767
13768 .align 8
13769 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13770 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13771 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13772
13773 + pax_force_retaddr
13774 ret;
13775
13776 .align 8
13777 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13778 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13779 %xmm8, %rsi);
13780
13781 + pax_force_retaddr
13782 ret;
13783 ENDPROC(camellia_ecb_enc_16way)
13784
13785 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13786 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13787 %xmm8, %rsi);
13788
13789 + pax_force_retaddr
13790 ret;
13791 ENDPROC(camellia_ecb_dec_16way)
13792
13793 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13794 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13795 %xmm8, %rsi);
13796
13797 + pax_force_retaddr
13798 ret;
13799 ENDPROC(camellia_cbc_dec_16way)
13800
13801 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13802 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13803 %xmm8, %rsi);
13804
13805 + pax_force_retaddr
13806 ret;
13807 ENDPROC(camellia_ctr_16way)
13808
13809 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13810 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13811 %xmm8, %rsi);
13812
13813 + pax_force_retaddr
13814 ret;
13815 ENDPROC(camellia_xts_crypt_16way)
13816
13817 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13818 index 0e0b886..5a3123c 100644
13819 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13820 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13821 @@ -11,6 +11,7 @@
13822 */
13823
13824 #include <linux/linkage.h>
13825 +#include <asm/alternative-asm.h>
13826
13827 #define CAMELLIA_TABLE_BYTE_LEN 272
13828
13829 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13830 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13831 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13832 %rcx, (%r9));
13833 + pax_force_retaddr
13834 ret;
13835 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13836
13837 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13838 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13839 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13840 %rax, (%r9));
13841 + pax_force_retaddr
13842 ret;
13843 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13844
13845 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13846 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13847 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13848
13849 + pax_force_retaddr
13850 ret;
13851
13852 .align 8
13853 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13854 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13855 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13856
13857 + pax_force_retaddr
13858 ret;
13859
13860 .align 8
13861 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13862
13863 vzeroupper;
13864
13865 + pax_force_retaddr
13866 ret;
13867 ENDPROC(camellia_ecb_enc_32way)
13868
13869 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13870
13871 vzeroupper;
13872
13873 + pax_force_retaddr
13874 ret;
13875 ENDPROC(camellia_ecb_dec_32way)
13876
13877 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13878
13879 vzeroupper;
13880
13881 + pax_force_retaddr
13882 ret;
13883 ENDPROC(camellia_cbc_dec_32way)
13884
13885 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13886
13887 vzeroupper;
13888
13889 + pax_force_retaddr
13890 ret;
13891 ENDPROC(camellia_ctr_32way)
13892
13893 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13894
13895 vzeroupper;
13896
13897 + pax_force_retaddr
13898 ret;
13899 ENDPROC(camellia_xts_crypt_32way)
13900
13901 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13902 index 310319c..db3d7b5 100644
13903 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13904 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13905 @@ -21,6 +21,7 @@
13906 */
13907
13908 #include <linux/linkage.h>
13909 +#include <asm/alternative-asm.h>
13910
13911 .file "camellia-x86_64-asm_64.S"
13912 .text
13913 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13914 enc_outunpack(mov, RT1);
13915
13916 movq RRBP, %rbp;
13917 + pax_force_retaddr
13918 ret;
13919
13920 .L__enc_xor:
13921 enc_outunpack(xor, RT1);
13922
13923 movq RRBP, %rbp;
13924 + pax_force_retaddr
13925 ret;
13926 ENDPROC(__camellia_enc_blk)
13927
13928 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13929 dec_outunpack();
13930
13931 movq RRBP, %rbp;
13932 + pax_force_retaddr
13933 ret;
13934 ENDPROC(camellia_dec_blk)
13935
13936 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13937
13938 movq RRBP, %rbp;
13939 popq %rbx;
13940 + pax_force_retaddr
13941 ret;
13942
13943 .L__enc2_xor:
13944 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13945
13946 movq RRBP, %rbp;
13947 popq %rbx;
13948 + pax_force_retaddr
13949 ret;
13950 ENDPROC(__camellia_enc_blk_2way)
13951
13952 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13953
13954 movq RRBP, %rbp;
13955 movq RXOR, %rbx;
13956 + pax_force_retaddr
13957 ret;
13958 ENDPROC(camellia_dec_blk_2way)
13959 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13960 index c35fd5d..2d8c7db 100644
13961 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13962 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13963 @@ -24,6 +24,7 @@
13964 */
13965
13966 #include <linux/linkage.h>
13967 +#include <asm/alternative-asm.h>
13968
13969 .file "cast5-avx-x86_64-asm_64.S"
13970
13971 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13972 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13973 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13974
13975 + pax_force_retaddr
13976 ret;
13977 ENDPROC(__cast5_enc_blk16)
13978
13979 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13980 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13981 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13982
13983 + pax_force_retaddr
13984 ret;
13985
13986 .L__skip_dec:
13987 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13988 vmovdqu RR4, (6*4*4)(%r11);
13989 vmovdqu RL4, (7*4*4)(%r11);
13990
13991 + pax_force_retaddr
13992 ret;
13993 ENDPROC(cast5_ecb_enc_16way)
13994
13995 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13996 vmovdqu RR4, (6*4*4)(%r11);
13997 vmovdqu RL4, (7*4*4)(%r11);
13998
13999 + pax_force_retaddr
14000 ret;
14001 ENDPROC(cast5_ecb_dec_16way)
14002
14003 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
14004 * %rdx: src
14005 */
14006
14007 - pushq %r12;
14008 + pushq %r14;
14009
14010 movq %rsi, %r11;
14011 - movq %rdx, %r12;
14012 + movq %rdx, %r14;
14013
14014 vmovdqu (0*16)(%rdx), RL1;
14015 vmovdqu (1*16)(%rdx), RR1;
14016 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
14017 call __cast5_dec_blk16;
14018
14019 /* xor with src */
14020 - vmovq (%r12), RX;
14021 + vmovq (%r14), RX;
14022 vpshufd $0x4f, RX, RX;
14023 vpxor RX, RR1, RR1;
14024 - vpxor 0*16+8(%r12), RL1, RL1;
14025 - vpxor 1*16+8(%r12), RR2, RR2;
14026 - vpxor 2*16+8(%r12), RL2, RL2;
14027 - vpxor 3*16+8(%r12), RR3, RR3;
14028 - vpxor 4*16+8(%r12), RL3, RL3;
14029 - vpxor 5*16+8(%r12), RR4, RR4;
14030 - vpxor 6*16+8(%r12), RL4, RL4;
14031 + vpxor 0*16+8(%r14), RL1, RL1;
14032 + vpxor 1*16+8(%r14), RR2, RR2;
14033 + vpxor 2*16+8(%r14), RL2, RL2;
14034 + vpxor 3*16+8(%r14), RR3, RR3;
14035 + vpxor 4*16+8(%r14), RL3, RL3;
14036 + vpxor 5*16+8(%r14), RR4, RR4;
14037 + vpxor 6*16+8(%r14), RL4, RL4;
14038
14039 vmovdqu RR1, (0*16)(%r11);
14040 vmovdqu RL1, (1*16)(%r11);
14041 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
14042 vmovdqu RR4, (6*16)(%r11);
14043 vmovdqu RL4, (7*16)(%r11);
14044
14045 - popq %r12;
14046 + popq %r14;
14047
14048 + pax_force_retaddr
14049 ret;
14050 ENDPROC(cast5_cbc_dec_16way)
14051
14052 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
14053 * %rcx: iv (big endian, 64bit)
14054 */
14055
14056 - pushq %r12;
14057 + pushq %r14;
14058
14059 movq %rsi, %r11;
14060 - movq %rdx, %r12;
14061 + movq %rdx, %r14;
14062
14063 vpcmpeqd RTMP, RTMP, RTMP;
14064 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
14065 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
14066 call __cast5_enc_blk16;
14067
14068 /* dst = src ^ iv */
14069 - vpxor (0*16)(%r12), RR1, RR1;
14070 - vpxor (1*16)(%r12), RL1, RL1;
14071 - vpxor (2*16)(%r12), RR2, RR2;
14072 - vpxor (3*16)(%r12), RL2, RL2;
14073 - vpxor (4*16)(%r12), RR3, RR3;
14074 - vpxor (5*16)(%r12), RL3, RL3;
14075 - vpxor (6*16)(%r12), RR4, RR4;
14076 - vpxor (7*16)(%r12), RL4, RL4;
14077 + vpxor (0*16)(%r14), RR1, RR1;
14078 + vpxor (1*16)(%r14), RL1, RL1;
14079 + vpxor (2*16)(%r14), RR2, RR2;
14080 + vpxor (3*16)(%r14), RL2, RL2;
14081 + vpxor (4*16)(%r14), RR3, RR3;
14082 + vpxor (5*16)(%r14), RL3, RL3;
14083 + vpxor (6*16)(%r14), RR4, RR4;
14084 + vpxor (7*16)(%r14), RL4, RL4;
14085 vmovdqu RR1, (0*16)(%r11);
14086 vmovdqu RL1, (1*16)(%r11);
14087 vmovdqu RR2, (2*16)(%r11);
14088 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
14089 vmovdqu RR4, (6*16)(%r11);
14090 vmovdqu RL4, (7*16)(%r11);
14091
14092 - popq %r12;
14093 + popq %r14;
14094
14095 + pax_force_retaddr
14096 ret;
14097 ENDPROC(cast5_ctr_16way)
14098 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14099 index e3531f8..e123f35 100644
14100 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14101 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14102 @@ -24,6 +24,7 @@
14103 */
14104
14105 #include <linux/linkage.h>
14106 +#include <asm/alternative-asm.h>
14107 #include "glue_helper-asm-avx.S"
14108
14109 .file "cast6-avx-x86_64-asm_64.S"
14110 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
14111 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14112 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14113
14114 + pax_force_retaddr
14115 ret;
14116 ENDPROC(__cast6_enc_blk8)
14117
14118 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
14119 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14120 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14121
14122 + pax_force_retaddr
14123 ret;
14124 ENDPROC(__cast6_dec_blk8)
14125
14126 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
14127
14128 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14129
14130 + pax_force_retaddr
14131 ret;
14132 ENDPROC(cast6_ecb_enc_8way)
14133
14134 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
14135
14136 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14137
14138 + pax_force_retaddr
14139 ret;
14140 ENDPROC(cast6_ecb_dec_8way)
14141
14142 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
14143 * %rdx: src
14144 */
14145
14146 - pushq %r12;
14147 + pushq %r14;
14148
14149 movq %rsi, %r11;
14150 - movq %rdx, %r12;
14151 + movq %rdx, %r14;
14152
14153 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14154
14155 call __cast6_dec_blk8;
14156
14157 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14158 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14159
14160 - popq %r12;
14161 + popq %r14;
14162
14163 + pax_force_retaddr
14164 ret;
14165 ENDPROC(cast6_cbc_dec_8way)
14166
14167 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
14168 * %rcx: iv (little endian, 128bit)
14169 */
14170
14171 - pushq %r12;
14172 + pushq %r14;
14173
14174 movq %rsi, %r11;
14175 - movq %rdx, %r12;
14176 + movq %rdx, %r14;
14177
14178 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14179 RD2, RX, RKR, RKM);
14180
14181 call __cast6_enc_blk8;
14182
14183 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14184 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14185
14186 - popq %r12;
14187 + popq %r14;
14188
14189 + pax_force_retaddr
14190 ret;
14191 ENDPROC(cast6_ctr_8way)
14192
14193 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14194 /* dst <= regs xor IVs(in dst) */
14195 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14196
14197 + pax_force_retaddr
14198 ret;
14199 ENDPROC(cast6_xts_enc_8way)
14200
14201 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14202 /* dst <= regs xor IVs(in dst) */
14203 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14204
14205 + pax_force_retaddr
14206 ret;
14207 ENDPROC(cast6_xts_dec_8way)
14208 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14209 index dbc4339..de6e120 100644
14210 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14211 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14212 @@ -45,6 +45,7 @@
14213
14214 #include <asm/inst.h>
14215 #include <linux/linkage.h>
14216 +#include <asm/alternative-asm.h>
14217
14218 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14219
14220 @@ -312,6 +313,7 @@ do_return:
14221 popq %rsi
14222 popq %rdi
14223 popq %rbx
14224 + pax_force_retaddr
14225 ret
14226
14227 ################################################################
14228 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14229 index 5d1e007..098cb4f 100644
14230 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14231 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14232 @@ -18,6 +18,7 @@
14233
14234 #include <linux/linkage.h>
14235 #include <asm/inst.h>
14236 +#include <asm/alternative-asm.h>
14237
14238 .data
14239
14240 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14241 psrlq $1, T2
14242 pxor T2, T1
14243 pxor T1, DATA
14244 + pax_force_retaddr
14245 ret
14246 ENDPROC(__clmul_gf128mul_ble)
14247
14248 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14249 call __clmul_gf128mul_ble
14250 PSHUFB_XMM BSWAP DATA
14251 movups DATA, (%rdi)
14252 + pax_force_retaddr
14253 ret
14254 ENDPROC(clmul_ghash_mul)
14255
14256 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14257 PSHUFB_XMM BSWAP DATA
14258 movups DATA, (%rdi)
14259 .Lupdate_just_ret:
14260 + pax_force_retaddr
14261 ret
14262 ENDPROC(clmul_ghash_update)
14263 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14264 index 9279e0b..c4b3d2c 100644
14265 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14266 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14267 @@ -1,4 +1,5 @@
14268 #include <linux/linkage.h>
14269 +#include <asm/alternative-asm.h>
14270
14271 # enter salsa20_encrypt_bytes
14272 ENTRY(salsa20_encrypt_bytes)
14273 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14274 add %r11,%rsp
14275 mov %rdi,%rax
14276 mov %rsi,%rdx
14277 + pax_force_retaddr
14278 ret
14279 # bytesatleast65:
14280 ._bytesatleast65:
14281 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14282 add %r11,%rsp
14283 mov %rdi,%rax
14284 mov %rsi,%rdx
14285 + pax_force_retaddr
14286 ret
14287 ENDPROC(salsa20_keysetup)
14288
14289 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14290 add %r11,%rsp
14291 mov %rdi,%rax
14292 mov %rsi,%rdx
14293 + pax_force_retaddr
14294 ret
14295 ENDPROC(salsa20_ivsetup)
14296 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14297 index 2f202f4..d9164d6 100644
14298 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14299 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14300 @@ -24,6 +24,7 @@
14301 */
14302
14303 #include <linux/linkage.h>
14304 +#include <asm/alternative-asm.h>
14305 #include "glue_helper-asm-avx.S"
14306
14307 .file "serpent-avx-x86_64-asm_64.S"
14308 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14309 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14310 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14311
14312 + pax_force_retaddr
14313 ret;
14314 ENDPROC(__serpent_enc_blk8_avx)
14315
14316 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14317 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14318 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14319
14320 + pax_force_retaddr
14321 ret;
14322 ENDPROC(__serpent_dec_blk8_avx)
14323
14324 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14325
14326 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14327
14328 + pax_force_retaddr
14329 ret;
14330 ENDPROC(serpent_ecb_enc_8way_avx)
14331
14332 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14333
14334 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14335
14336 + pax_force_retaddr
14337 ret;
14338 ENDPROC(serpent_ecb_dec_8way_avx)
14339
14340 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14341
14342 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14343
14344 + pax_force_retaddr
14345 ret;
14346 ENDPROC(serpent_cbc_dec_8way_avx)
14347
14348 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14349
14350 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14351
14352 + pax_force_retaddr
14353 ret;
14354 ENDPROC(serpent_ctr_8way_avx)
14355
14356 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14357 /* dst <= regs xor IVs(in dst) */
14358 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14359
14360 + pax_force_retaddr
14361 ret;
14362 ENDPROC(serpent_xts_enc_8way_avx)
14363
14364 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14365 /* dst <= regs xor IVs(in dst) */
14366 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14367
14368 + pax_force_retaddr
14369 ret;
14370 ENDPROC(serpent_xts_dec_8way_avx)
14371 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14372 index b222085..abd483c 100644
14373 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14374 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14375 @@ -15,6 +15,7 @@
14376 */
14377
14378 #include <linux/linkage.h>
14379 +#include <asm/alternative-asm.h>
14380 #include "glue_helper-asm-avx2.S"
14381
14382 .file "serpent-avx2-asm_64.S"
14383 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14384 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14385 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14386
14387 + pax_force_retaddr
14388 ret;
14389 ENDPROC(__serpent_enc_blk16)
14390
14391 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14392 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14393 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14394
14395 + pax_force_retaddr
14396 ret;
14397 ENDPROC(__serpent_dec_blk16)
14398
14399 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14400
14401 vzeroupper;
14402
14403 + pax_force_retaddr
14404 ret;
14405 ENDPROC(serpent_ecb_enc_16way)
14406
14407 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14408
14409 vzeroupper;
14410
14411 + pax_force_retaddr
14412 ret;
14413 ENDPROC(serpent_ecb_dec_16way)
14414
14415 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14416
14417 vzeroupper;
14418
14419 + pax_force_retaddr
14420 ret;
14421 ENDPROC(serpent_cbc_dec_16way)
14422
14423 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14424
14425 vzeroupper;
14426
14427 + pax_force_retaddr
14428 ret;
14429 ENDPROC(serpent_ctr_16way)
14430
14431 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14432
14433 vzeroupper;
14434
14435 + pax_force_retaddr
14436 ret;
14437 ENDPROC(serpent_xts_enc_16way)
14438
14439 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14440
14441 vzeroupper;
14442
14443 + pax_force_retaddr
14444 ret;
14445 ENDPROC(serpent_xts_dec_16way)
14446 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14447 index acc066c..1559cc4 100644
14448 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14449 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14450 @@ -25,6 +25,7 @@
14451 */
14452
14453 #include <linux/linkage.h>
14454 +#include <asm/alternative-asm.h>
14455
14456 .file "serpent-sse2-x86_64-asm_64.S"
14457 .text
14458 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14459 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14460 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14461
14462 + pax_force_retaddr
14463 ret;
14464
14465 .L__enc_xor8:
14466 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14467 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14468
14469 + pax_force_retaddr
14470 ret;
14471 ENDPROC(__serpent_enc_blk_8way)
14472
14473 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14474 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14475 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14476
14477 + pax_force_retaddr
14478 ret;
14479 ENDPROC(serpent_dec_blk_8way)
14480 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14481 index a410950..9dfe7ad 100644
14482 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14483 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14484 @@ -29,6 +29,7 @@
14485 */
14486
14487 #include <linux/linkage.h>
14488 +#include <asm/alternative-asm.h>
14489
14490 #define CTX %rdi // arg1
14491 #define BUF %rsi // arg2
14492 @@ -75,9 +76,9 @@
14493
14494 push %rbx
14495 push %rbp
14496 - push %r12
14497 + push %r14
14498
14499 - mov %rsp, %r12
14500 + mov %rsp, %r14
14501 sub $64, %rsp # allocate workspace
14502 and $~15, %rsp # align stack
14503
14504 @@ -99,11 +100,12 @@
14505 xor %rax, %rax
14506 rep stosq
14507
14508 - mov %r12, %rsp # deallocate workspace
14509 + mov %r14, %rsp # deallocate workspace
14510
14511 - pop %r12
14512 + pop %r14
14513 pop %rbp
14514 pop %rbx
14515 + pax_force_retaddr
14516 ret
14517
14518 ENDPROC(\name)
14519 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14520 index 642f156..51a513c 100644
14521 --- a/arch/x86/crypto/sha256-avx-asm.S
14522 +++ b/arch/x86/crypto/sha256-avx-asm.S
14523 @@ -49,6 +49,7 @@
14524
14525 #ifdef CONFIG_AS_AVX
14526 #include <linux/linkage.h>
14527 +#include <asm/alternative-asm.h>
14528
14529 ## assume buffers not aligned
14530 #define VMOVDQ vmovdqu
14531 @@ -460,6 +461,7 @@ done_hash:
14532 popq %r13
14533 popq %rbp
14534 popq %rbx
14535 + pax_force_retaddr
14536 ret
14537 ENDPROC(sha256_transform_avx)
14538
14539 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14540 index 9e86944..3795e6a 100644
14541 --- a/arch/x86/crypto/sha256-avx2-asm.S
14542 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14543 @@ -50,6 +50,7 @@
14544
14545 #ifdef CONFIG_AS_AVX2
14546 #include <linux/linkage.h>
14547 +#include <asm/alternative-asm.h>
14548
14549 ## assume buffers not aligned
14550 #define VMOVDQ vmovdqu
14551 @@ -720,6 +721,7 @@ done_hash:
14552 popq %r12
14553 popq %rbp
14554 popq %rbx
14555 + pax_force_retaddr
14556 ret
14557 ENDPROC(sha256_transform_rorx)
14558
14559 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14560 index f833b74..8c62a9e 100644
14561 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14562 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14563 @@ -47,6 +47,7 @@
14564 ########################################################################
14565
14566 #include <linux/linkage.h>
14567 +#include <asm/alternative-asm.h>
14568
14569 ## assume buffers not aligned
14570 #define MOVDQ movdqu
14571 @@ -471,6 +472,7 @@ done_hash:
14572 popq %rbp
14573 popq %rbx
14574
14575 + pax_force_retaddr
14576 ret
14577 ENDPROC(sha256_transform_ssse3)
14578
14579 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14580 index 974dde9..a823ff9 100644
14581 --- a/arch/x86/crypto/sha512-avx-asm.S
14582 +++ b/arch/x86/crypto/sha512-avx-asm.S
14583 @@ -49,6 +49,7 @@
14584
14585 #ifdef CONFIG_AS_AVX
14586 #include <linux/linkage.h>
14587 +#include <asm/alternative-asm.h>
14588
14589 .text
14590
14591 @@ -364,6 +365,7 @@ updateblock:
14592 mov frame_RSPSAVE(%rsp), %rsp
14593
14594 nowork:
14595 + pax_force_retaddr
14596 ret
14597 ENDPROC(sha512_transform_avx)
14598
14599 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14600 index 568b961..ed20c37 100644
14601 --- a/arch/x86/crypto/sha512-avx2-asm.S
14602 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14603 @@ -51,6 +51,7 @@
14604
14605 #ifdef CONFIG_AS_AVX2
14606 #include <linux/linkage.h>
14607 +#include <asm/alternative-asm.h>
14608
14609 .text
14610
14611 @@ -678,6 +679,7 @@ done_hash:
14612
14613 # Restore Stack Pointer
14614 mov frame_RSPSAVE(%rsp), %rsp
14615 + pax_force_retaddr
14616 ret
14617 ENDPROC(sha512_transform_rorx)
14618
14619 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14620 index fb56855..6edd768 100644
14621 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14622 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14623 @@ -48,6 +48,7 @@
14624 ########################################################################
14625
14626 #include <linux/linkage.h>
14627 +#include <asm/alternative-asm.h>
14628
14629 .text
14630
14631 @@ -363,6 +364,7 @@ updateblock:
14632 mov frame_RSPSAVE(%rsp), %rsp
14633
14634 nowork:
14635 + pax_force_retaddr
14636 ret
14637 ENDPROC(sha512_transform_ssse3)
14638
14639 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14640 index 0505813..b067311 100644
14641 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14642 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14643 @@ -24,6 +24,7 @@
14644 */
14645
14646 #include <linux/linkage.h>
14647 +#include <asm/alternative-asm.h>
14648 #include "glue_helper-asm-avx.S"
14649
14650 .file "twofish-avx-x86_64-asm_64.S"
14651 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14652 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14653 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14654
14655 + pax_force_retaddr
14656 ret;
14657 ENDPROC(__twofish_enc_blk8)
14658
14659 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14660 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14661 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14662
14663 + pax_force_retaddr
14664 ret;
14665 ENDPROC(__twofish_dec_blk8)
14666
14667 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14668
14669 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14670
14671 + pax_force_retaddr
14672 ret;
14673 ENDPROC(twofish_ecb_enc_8way)
14674
14675 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14676
14677 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14678
14679 + pax_force_retaddr
14680 ret;
14681 ENDPROC(twofish_ecb_dec_8way)
14682
14683 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14684 * %rdx: src
14685 */
14686
14687 - pushq %r12;
14688 + pushq %r14;
14689
14690 movq %rsi, %r11;
14691 - movq %rdx, %r12;
14692 + movq %rdx, %r14;
14693
14694 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14695
14696 call __twofish_dec_blk8;
14697
14698 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14699 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14700
14701 - popq %r12;
14702 + popq %r14;
14703
14704 + pax_force_retaddr
14705 ret;
14706 ENDPROC(twofish_cbc_dec_8way)
14707
14708 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14709 * %rcx: iv (little endian, 128bit)
14710 */
14711
14712 - pushq %r12;
14713 + pushq %r14;
14714
14715 movq %rsi, %r11;
14716 - movq %rdx, %r12;
14717 + movq %rdx, %r14;
14718
14719 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14720 RD2, RX0, RX1, RY0);
14721
14722 call __twofish_enc_blk8;
14723
14724 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14725 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14726
14727 - popq %r12;
14728 + popq %r14;
14729
14730 + pax_force_retaddr
14731 ret;
14732 ENDPROC(twofish_ctr_8way)
14733
14734 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14735 /* dst <= regs xor IVs(in dst) */
14736 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14737
14738 + pax_force_retaddr
14739 ret;
14740 ENDPROC(twofish_xts_enc_8way)
14741
14742 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14743 /* dst <= regs xor IVs(in dst) */
14744 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14745
14746 + pax_force_retaddr
14747 ret;
14748 ENDPROC(twofish_xts_dec_8way)
14749 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14750 index 1c3b7ce..02f578d 100644
14751 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14752 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14753 @@ -21,6 +21,7 @@
14754 */
14755
14756 #include <linux/linkage.h>
14757 +#include <asm/alternative-asm.h>
14758
14759 .file "twofish-x86_64-asm-3way.S"
14760 .text
14761 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14762 popq %r13;
14763 popq %r14;
14764 popq %r15;
14765 + pax_force_retaddr
14766 ret;
14767
14768 .L__enc_xor3:
14769 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14770 popq %r13;
14771 popq %r14;
14772 popq %r15;
14773 + pax_force_retaddr
14774 ret;
14775 ENDPROC(__twofish_enc_blk_3way)
14776
14777 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14778 popq %r13;
14779 popq %r14;
14780 popq %r15;
14781 + pax_force_retaddr
14782 ret;
14783 ENDPROC(twofish_dec_blk_3way)
14784 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14785 index a039d21..524b8b2 100644
14786 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14787 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14788 @@ -22,6 +22,7 @@
14789
14790 #include <linux/linkage.h>
14791 #include <asm/asm-offsets.h>
14792 +#include <asm/alternative-asm.h>
14793
14794 #define a_offset 0
14795 #define b_offset 4
14796 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14797
14798 popq R1
14799 movq $1,%rax
14800 + pax_force_retaddr
14801 ret
14802 ENDPROC(twofish_enc_blk)
14803
14804 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14805
14806 popq R1
14807 movq $1,%rax
14808 + pax_force_retaddr
14809 ret
14810 ENDPROC(twofish_dec_blk)
14811 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14812 index d21ff89..6da8e6e 100644
14813 --- a/arch/x86/ia32/ia32_aout.c
14814 +++ b/arch/x86/ia32/ia32_aout.c
14815 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14816 unsigned long dump_start, dump_size;
14817 struct user32 dump;
14818
14819 + memset(&dump, 0, sizeof(dump));
14820 +
14821 fs = get_fs();
14822 set_fs(KERNEL_DS);
14823 has_dumped = 1;
14824 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14825 index f9e181a..b0df8b3 100644
14826 --- a/arch/x86/ia32/ia32_signal.c
14827 +++ b/arch/x86/ia32/ia32_signal.c
14828 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14829 if (__get_user(set.sig[0], &frame->sc.oldmask)
14830 || (_COMPAT_NSIG_WORDS > 1
14831 && __copy_from_user((((char *) &set.sig) + 4),
14832 - &frame->extramask,
14833 + frame->extramask,
14834 sizeof(frame->extramask))))
14835 goto badframe;
14836
14837 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14838 sp -= frame_size;
14839 /* Align the stack pointer according to the i386 ABI,
14840 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14841 - sp = ((sp + 4) & -16ul) - 4;
14842 + sp = ((sp - 12) & -16ul) - 4;
14843 return (void __user *) sp;
14844 }
14845
14846 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14847 restorer = current->mm->context.vdso +
14848 selected_vdso32->sym___kernel_sigreturn;
14849 else
14850 - restorer = &frame->retcode;
14851 + restorer = frame->retcode;
14852 }
14853
14854 put_user_try {
14855 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14856 * These are actually not used anymore, but left because some
14857 * gdb versions depend on them as a marker.
14858 */
14859 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14860 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14861 } put_user_catch(err);
14862
14863 if (err)
14864 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14865 0xb8,
14866 __NR_ia32_rt_sigreturn,
14867 0x80cd,
14868 - 0,
14869 + 0
14870 };
14871
14872 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14873 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14874
14875 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14876 restorer = ksig->ka.sa.sa_restorer;
14877 - else
14878 + else if (current->mm->context.vdso)
14879 + /* Return stub is in 32bit vsyscall page */
14880 restorer = current->mm->context.vdso +
14881 selected_vdso32->sym___kernel_rt_sigreturn;
14882 + else
14883 + restorer = frame->retcode;
14884 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14885
14886 /*
14887 * Not actually used anymore, but left because some gdb
14888 * versions need it.
14889 */
14890 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14891 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14892 } put_user_catch(err);
14893
14894 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14895 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14896 index 4299eb0..fefe70e 100644
14897 --- a/arch/x86/ia32/ia32entry.S
14898 +++ b/arch/x86/ia32/ia32entry.S
14899 @@ -15,8 +15,10 @@
14900 #include <asm/irqflags.h>
14901 #include <asm/asm.h>
14902 #include <asm/smap.h>
14903 +#include <asm/pgtable.h>
14904 #include <linux/linkage.h>
14905 #include <linux/err.h>
14906 +#include <asm/alternative-asm.h>
14907
14908 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14909 #include <linux/elf-em.h>
14910 @@ -62,12 +64,12 @@
14911 */
14912 .macro LOAD_ARGS32 offset, _r9=0
14913 .if \_r9
14914 - movl \offset+16(%rsp),%r9d
14915 + movl \offset+R9(%rsp),%r9d
14916 .endif
14917 - movl \offset+40(%rsp),%ecx
14918 - movl \offset+48(%rsp),%edx
14919 - movl \offset+56(%rsp),%esi
14920 - movl \offset+64(%rsp),%edi
14921 + movl \offset+RCX(%rsp),%ecx
14922 + movl \offset+RDX(%rsp),%edx
14923 + movl \offset+RSI(%rsp),%esi
14924 + movl \offset+RDI(%rsp),%edi
14925 movl %eax,%eax /* zero extension */
14926 .endm
14927
14928 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14929 ENDPROC(native_irq_enable_sysexit)
14930 #endif
14931
14932 + .macro pax_enter_kernel_user
14933 + pax_set_fptr_mask
14934 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14935 + call pax_enter_kernel_user
14936 +#endif
14937 + .endm
14938 +
14939 + .macro pax_exit_kernel_user
14940 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14941 + call pax_exit_kernel_user
14942 +#endif
14943 +#ifdef CONFIG_PAX_RANDKSTACK
14944 + pushq %rax
14945 + pushq %r11
14946 + call pax_randomize_kstack
14947 + popq %r11
14948 + popq %rax
14949 +#endif
14950 + .endm
14951 +
14952 + .macro pax_erase_kstack
14953 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14954 + call pax_erase_kstack
14955 +#endif
14956 + .endm
14957 +
14958 /*
14959 * 32bit SYSENTER instruction entry.
14960 *
14961 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14962 CFI_REGISTER rsp,rbp
14963 SWAPGS_UNSAFE_STACK
14964 movq PER_CPU_VAR(kernel_stack), %rsp
14965 - addq $(KERNEL_STACK_OFFSET),%rsp
14966 - /*
14967 - * No need to follow this irqs on/off section: the syscall
14968 - * disabled irqs, here we enable it straight after entry:
14969 - */
14970 - ENABLE_INTERRUPTS(CLBR_NONE)
14971 movl %ebp,%ebp /* zero extension */
14972 pushq_cfi $__USER32_DS
14973 /*CFI_REL_OFFSET ss,0*/
14974 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14975 CFI_REL_OFFSET rsp,0
14976 pushfq_cfi
14977 /*CFI_REL_OFFSET rflags,0*/
14978 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14979 - CFI_REGISTER rip,r10
14980 + orl $X86_EFLAGS_IF,(%rsp)
14981 + GET_THREAD_INFO(%r11)
14982 + movl TI_sysenter_return(%r11), %r11d
14983 + CFI_REGISTER rip,r11
14984 pushq_cfi $__USER32_CS
14985 /*CFI_REL_OFFSET cs,0*/
14986 movl %eax, %eax
14987 - pushq_cfi %r10
14988 + pushq_cfi %r11
14989 CFI_REL_OFFSET rip,0
14990 pushq_cfi %rax
14991 cld
14992 SAVE_ARGS 0,1,0
14993 + pax_enter_kernel_user
14994 +
14995 +#ifdef CONFIG_PAX_RANDKSTACK
14996 + pax_erase_kstack
14997 +#endif
14998 +
14999 + /*
15000 + * No need to follow this irqs on/off section: the syscall
15001 + * disabled irqs, here we enable it straight after entry:
15002 + */
15003 + ENABLE_INTERRUPTS(CLBR_NONE)
15004 /* no need to do an access_ok check here because rbp has been
15005 32bit zero extended */
15006 +
15007 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15008 + addq pax_user_shadow_base,%rbp
15009 + ASM_PAX_OPEN_USERLAND
15010 +#endif
15011 +
15012 ASM_STAC
15013 1: movl (%rbp),%ebp
15014 _ASM_EXTABLE(1b,ia32_badarg)
15015 ASM_CLAC
15016 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15017 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15018 +
15019 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15020 + ASM_PAX_CLOSE_USERLAND
15021 +#endif
15022 +
15023 + GET_THREAD_INFO(%r11)
15024 + orl $TS_COMPAT,TI_status(%r11)
15025 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15026 CFI_REMEMBER_STATE
15027 jnz sysenter_tracesys
15028 cmpq $(IA32_NR_syscalls-1),%rax
15029 @@ -162,15 +209,18 @@ sysenter_do_call:
15030 sysenter_dispatch:
15031 call *ia32_sys_call_table(,%rax,8)
15032 movq %rax,RAX-ARGOFFSET(%rsp)
15033 + GET_THREAD_INFO(%r11)
15034 DISABLE_INTERRUPTS(CLBR_NONE)
15035 TRACE_IRQS_OFF
15036 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15037 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15038 jnz sysexit_audit
15039 sysexit_from_sys_call:
15040 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15041 + pax_exit_kernel_user
15042 + pax_erase_kstack
15043 + andl $~TS_COMPAT,TI_status(%r11)
15044 /* clear IF, that popfq doesn't enable interrupts early */
15045 - andl $~0x200,EFLAGS-R11(%rsp)
15046 - movl RIP-R11(%rsp),%edx /* User %eip */
15047 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
15048 + movl RIP(%rsp),%edx /* User %eip */
15049 CFI_REGISTER rip,rdx
15050 RESTORE_ARGS 0,24,0,0,0,0
15051 xorq %r8,%r8
15052 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
15053 movl %eax,%esi /* 2nd arg: syscall number */
15054 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
15055 call __audit_syscall_entry
15056 +
15057 + pax_erase_kstack
15058 +
15059 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
15060 cmpq $(IA32_NR_syscalls-1),%rax
15061 ja ia32_badsys
15062 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
15063 .endm
15064
15065 .macro auditsys_exit exit
15066 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15067 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15068 jnz ia32_ret_from_sys_call
15069 TRACE_IRQS_ON
15070 ENABLE_INTERRUPTS(CLBR_NONE)
15071 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
15072 1: setbe %al /* 1 if error, 0 if not */
15073 movzbl %al,%edi /* zero-extend that into %edi */
15074 call __audit_syscall_exit
15075 + GET_THREAD_INFO(%r11)
15076 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
15077 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
15078 DISABLE_INTERRUPTS(CLBR_NONE)
15079 TRACE_IRQS_OFF
15080 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15081 + testl %edi,TI_flags(%r11)
15082 jz \exit
15083 CLEAR_RREGS -ARGOFFSET
15084 jmp int_with_check
15085 @@ -237,7 +291,7 @@ sysexit_audit:
15086
15087 sysenter_tracesys:
15088 #ifdef CONFIG_AUDITSYSCALL
15089 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15090 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15091 jz sysenter_auditsys
15092 #endif
15093 SAVE_REST
15094 @@ -249,6 +303,9 @@ sysenter_tracesys:
15095 RESTORE_REST
15096 cmpq $(IA32_NR_syscalls-1),%rax
15097 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
15098 +
15099 + pax_erase_kstack
15100 +
15101 jmp sysenter_do_call
15102 CFI_ENDPROC
15103 ENDPROC(ia32_sysenter_target)
15104 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
15105 ENTRY(ia32_cstar_target)
15106 CFI_STARTPROC32 simple
15107 CFI_SIGNAL_FRAME
15108 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15109 + CFI_DEF_CFA rsp,0
15110 CFI_REGISTER rip,rcx
15111 /*CFI_REGISTER rflags,r11*/
15112 SWAPGS_UNSAFE_STACK
15113 movl %esp,%r8d
15114 CFI_REGISTER rsp,r8
15115 movq PER_CPU_VAR(kernel_stack),%rsp
15116 + SAVE_ARGS 8*6,0,0
15117 + pax_enter_kernel_user
15118 +
15119 +#ifdef CONFIG_PAX_RANDKSTACK
15120 + pax_erase_kstack
15121 +#endif
15122 +
15123 /*
15124 * No need to follow this irqs on/off section: the syscall
15125 * disabled irqs and here we enable it straight after entry:
15126 */
15127 ENABLE_INTERRUPTS(CLBR_NONE)
15128 - SAVE_ARGS 8,0,0
15129 movl %eax,%eax /* zero extension */
15130 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15131 movq %rcx,RIP-ARGOFFSET(%rsp)
15132 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
15133 /* no need to do an access_ok check here because r8 has been
15134 32bit zero extended */
15135 /* hardware stack frame is complete now */
15136 +
15137 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15138 + ASM_PAX_OPEN_USERLAND
15139 + movq pax_user_shadow_base,%r8
15140 + addq RSP-ARGOFFSET(%rsp),%r8
15141 +#endif
15142 +
15143 ASM_STAC
15144 1: movl (%r8),%r9d
15145 _ASM_EXTABLE(1b,ia32_badarg)
15146 ASM_CLAC
15147 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15148 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15149 +
15150 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15151 + ASM_PAX_CLOSE_USERLAND
15152 +#endif
15153 +
15154 + GET_THREAD_INFO(%r11)
15155 + orl $TS_COMPAT,TI_status(%r11)
15156 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15157 CFI_REMEMBER_STATE
15158 jnz cstar_tracesys
15159 cmpq $IA32_NR_syscalls-1,%rax
15160 @@ -319,13 +395,16 @@ cstar_do_call:
15161 cstar_dispatch:
15162 call *ia32_sys_call_table(,%rax,8)
15163 movq %rax,RAX-ARGOFFSET(%rsp)
15164 + GET_THREAD_INFO(%r11)
15165 DISABLE_INTERRUPTS(CLBR_NONE)
15166 TRACE_IRQS_OFF
15167 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15168 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15169 jnz sysretl_audit
15170 sysretl_from_sys_call:
15171 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15172 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15173 + pax_exit_kernel_user
15174 + pax_erase_kstack
15175 + andl $~TS_COMPAT,TI_status(%r11)
15176 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15177 movl RIP-ARGOFFSET(%rsp),%ecx
15178 CFI_REGISTER rip,rcx
15179 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15180 @@ -352,7 +431,7 @@ sysretl_audit:
15181
15182 cstar_tracesys:
15183 #ifdef CONFIG_AUDITSYSCALL
15184 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15185 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15186 jz cstar_auditsys
15187 #endif
15188 xchgl %r9d,%ebp
15189 @@ -366,11 +445,19 @@ cstar_tracesys:
15190 xchgl %ebp,%r9d
15191 cmpq $(IA32_NR_syscalls-1),%rax
15192 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15193 +
15194 + pax_erase_kstack
15195 +
15196 jmp cstar_do_call
15197 END(ia32_cstar_target)
15198
15199 ia32_badarg:
15200 ASM_CLAC
15201 +
15202 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15203 + ASM_PAX_CLOSE_USERLAND
15204 +#endif
15205 +
15206 movq $-EFAULT,%rax
15207 jmp ia32_sysret
15208 CFI_ENDPROC
15209 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
15210 CFI_REL_OFFSET rip,RIP-RIP
15211 PARAVIRT_ADJUST_EXCEPTION_FRAME
15212 SWAPGS
15213 - /*
15214 - * No need to follow this irqs on/off section: the syscall
15215 - * disabled irqs and here we enable it straight after entry:
15216 - */
15217 - ENABLE_INTERRUPTS(CLBR_NONE)
15218 movl %eax,%eax
15219 pushq_cfi %rax
15220 cld
15221 /* note the registers are not zero extended to the sf.
15222 this could be a problem. */
15223 SAVE_ARGS 0,1,0
15224 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15225 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15226 + pax_enter_kernel_user
15227 +
15228 +#ifdef CONFIG_PAX_RANDKSTACK
15229 + pax_erase_kstack
15230 +#endif
15231 +
15232 + /*
15233 + * No need to follow this irqs on/off section: the syscall
15234 + * disabled irqs and here we enable it straight after entry:
15235 + */
15236 + ENABLE_INTERRUPTS(CLBR_NONE)
15237 + GET_THREAD_INFO(%r11)
15238 + orl $TS_COMPAT,TI_status(%r11)
15239 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15240 jnz ia32_tracesys
15241 cmpq $(IA32_NR_syscalls-1),%rax
15242 ja ia32_badsys
15243 @@ -442,6 +536,9 @@ ia32_tracesys:
15244 RESTORE_REST
15245 cmpq $(IA32_NR_syscalls-1),%rax
15246 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15247 +
15248 + pax_erase_kstack
15249 +
15250 jmp ia32_do_call
15251 END(ia32_syscall)
15252
15253 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15254 index 8e0ceec..af13504 100644
15255 --- a/arch/x86/ia32/sys_ia32.c
15256 +++ b/arch/x86/ia32/sys_ia32.c
15257 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15258 */
15259 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15260 {
15261 - typeof(ubuf->st_uid) uid = 0;
15262 - typeof(ubuf->st_gid) gid = 0;
15263 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15264 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15265 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15266 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15267 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15268 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15269 index 372231c..51b537d 100644
15270 --- a/arch/x86/include/asm/alternative-asm.h
15271 +++ b/arch/x86/include/asm/alternative-asm.h
15272 @@ -18,6 +18,45 @@
15273 .endm
15274 #endif
15275
15276 +#ifdef KERNEXEC_PLUGIN
15277 + .macro pax_force_retaddr_bts rip=0
15278 + btsq $63,\rip(%rsp)
15279 + .endm
15280 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15281 + .macro pax_force_retaddr rip=0, reload=0
15282 + btsq $63,\rip(%rsp)
15283 + .endm
15284 + .macro pax_force_fptr ptr
15285 + btsq $63,\ptr
15286 + .endm
15287 + .macro pax_set_fptr_mask
15288 + .endm
15289 +#endif
15290 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15291 + .macro pax_force_retaddr rip=0, reload=0
15292 + .if \reload
15293 + pax_set_fptr_mask
15294 + .endif
15295 + orq %r12,\rip(%rsp)
15296 + .endm
15297 + .macro pax_force_fptr ptr
15298 + orq %r12,\ptr
15299 + .endm
15300 + .macro pax_set_fptr_mask
15301 + movabs $0x8000000000000000,%r12
15302 + .endm
15303 +#endif
15304 +#else
15305 + .macro pax_force_retaddr rip=0, reload=0
15306 + .endm
15307 + .macro pax_force_fptr ptr
15308 + .endm
15309 + .macro pax_force_retaddr_bts rip=0
15310 + .endm
15311 + .macro pax_set_fptr_mask
15312 + .endm
15313 +#endif
15314 +
15315 .macro altinstruction_entry orig alt feature orig_len alt_len
15316 .long \orig - .
15317 .long \alt - .
15318 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15319 index 0a3f9c9..c9d081d 100644
15320 --- a/arch/x86/include/asm/alternative.h
15321 +++ b/arch/x86/include/asm/alternative.h
15322 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15323 ".pushsection .discard,\"aw\",@progbits\n" \
15324 DISCARD_ENTRY(1) \
15325 ".popsection\n" \
15326 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15327 + ".pushsection .altinstr_replacement, \"a\"\n" \
15328 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15329 ".popsection"
15330
15331 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15332 DISCARD_ENTRY(1) \
15333 DISCARD_ENTRY(2) \
15334 ".popsection\n" \
15335 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15336 + ".pushsection .altinstr_replacement, \"a\"\n" \
15337 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15338 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15339 ".popsection"
15340 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15341 index 19b0eba..12254cd 100644
15342 --- a/arch/x86/include/asm/apic.h
15343 +++ b/arch/x86/include/asm/apic.h
15344 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15345
15346 #ifdef CONFIG_X86_LOCAL_APIC
15347
15348 -extern unsigned int apic_verbosity;
15349 +extern int apic_verbosity;
15350 extern int local_apic_timer_c2_ok;
15351
15352 extern int disable_apic;
15353 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15354 index 20370c6..a2eb9b0 100644
15355 --- a/arch/x86/include/asm/apm.h
15356 +++ b/arch/x86/include/asm/apm.h
15357 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15358 __asm__ __volatile__(APM_DO_ZERO_SEGS
15359 "pushl %%edi\n\t"
15360 "pushl %%ebp\n\t"
15361 - "lcall *%%cs:apm_bios_entry\n\t"
15362 + "lcall *%%ss:apm_bios_entry\n\t"
15363 "setc %%al\n\t"
15364 "popl %%ebp\n\t"
15365 "popl %%edi\n\t"
15366 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15367 __asm__ __volatile__(APM_DO_ZERO_SEGS
15368 "pushl %%edi\n\t"
15369 "pushl %%ebp\n\t"
15370 - "lcall *%%cs:apm_bios_entry\n\t"
15371 + "lcall *%%ss:apm_bios_entry\n\t"
15372 "setc %%bl\n\t"
15373 "popl %%ebp\n\t"
15374 "popl %%edi\n\t"
15375 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15376 index 6dd1c7dd..2edd216 100644
15377 --- a/arch/x86/include/asm/atomic.h
15378 +++ b/arch/x86/include/asm/atomic.h
15379 @@ -24,7 +24,18 @@
15380 */
15381 static inline int atomic_read(const atomic_t *v)
15382 {
15383 - return (*(volatile int *)&(v)->counter);
15384 + return (*(volatile const int *)&(v)->counter);
15385 +}
15386 +
15387 +/**
15388 + * atomic_read_unchecked - read atomic variable
15389 + * @v: pointer of type atomic_unchecked_t
15390 + *
15391 + * Atomically reads the value of @v.
15392 + */
15393 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15394 +{
15395 + return (*(volatile const int *)&(v)->counter);
15396 }
15397
15398 /**
15399 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15400 }
15401
15402 /**
15403 + * atomic_set_unchecked - set atomic variable
15404 + * @v: pointer of type atomic_unchecked_t
15405 + * @i: required value
15406 + *
15407 + * Atomically sets the value of @v to @i.
15408 + */
15409 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15410 +{
15411 + v->counter = i;
15412 +}
15413 +
15414 +/**
15415 * atomic_add - add integer to atomic variable
15416 * @i: integer value to add
15417 * @v: pointer of type atomic_t
15418 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15419 */
15420 static inline void atomic_add(int i, atomic_t *v)
15421 {
15422 - asm volatile(LOCK_PREFIX "addl %1,%0"
15423 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15424 +
15425 +#ifdef CONFIG_PAX_REFCOUNT
15426 + "jno 0f\n"
15427 + LOCK_PREFIX "subl %1,%0\n"
15428 + "int $4\n0:\n"
15429 + _ASM_EXTABLE(0b, 0b)
15430 +#endif
15431 +
15432 + : "+m" (v->counter)
15433 + : "ir" (i));
15434 +}
15435 +
15436 +/**
15437 + * atomic_add_unchecked - add integer to atomic variable
15438 + * @i: integer value to add
15439 + * @v: pointer of type atomic_unchecked_t
15440 + *
15441 + * Atomically adds @i to @v.
15442 + */
15443 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15444 +{
15445 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15446 : "+m" (v->counter)
15447 : "ir" (i));
15448 }
15449 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15450 */
15451 static inline void atomic_sub(int i, atomic_t *v)
15452 {
15453 - asm volatile(LOCK_PREFIX "subl %1,%0"
15454 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15455 +
15456 +#ifdef CONFIG_PAX_REFCOUNT
15457 + "jno 0f\n"
15458 + LOCK_PREFIX "addl %1,%0\n"
15459 + "int $4\n0:\n"
15460 + _ASM_EXTABLE(0b, 0b)
15461 +#endif
15462 +
15463 + : "+m" (v->counter)
15464 + : "ir" (i));
15465 +}
15466 +
15467 +/**
15468 + * atomic_sub_unchecked - subtract integer from atomic variable
15469 + * @i: integer value to subtract
15470 + * @v: pointer of type atomic_unchecked_t
15471 + *
15472 + * Atomically subtracts @i from @v.
15473 + */
15474 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15475 +{
15476 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15477 : "+m" (v->counter)
15478 : "ir" (i));
15479 }
15480 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15481 */
15482 static inline int atomic_sub_and_test(int i, atomic_t *v)
15483 {
15484 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15485 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15486 }
15487
15488 /**
15489 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15490 */
15491 static inline void atomic_inc(atomic_t *v)
15492 {
15493 - asm volatile(LOCK_PREFIX "incl %0"
15494 + asm volatile(LOCK_PREFIX "incl %0\n"
15495 +
15496 +#ifdef CONFIG_PAX_REFCOUNT
15497 + "jno 0f\n"
15498 + LOCK_PREFIX "decl %0\n"
15499 + "int $4\n0:\n"
15500 + _ASM_EXTABLE(0b, 0b)
15501 +#endif
15502 +
15503 + : "+m" (v->counter));
15504 +}
15505 +
15506 +/**
15507 + * atomic_inc_unchecked - increment atomic variable
15508 + * @v: pointer of type atomic_unchecked_t
15509 + *
15510 + * Atomically increments @v by 1.
15511 + */
15512 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15513 +{
15514 + asm volatile(LOCK_PREFIX "incl %0\n"
15515 : "+m" (v->counter));
15516 }
15517
15518 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15519 */
15520 static inline void atomic_dec(atomic_t *v)
15521 {
15522 - asm volatile(LOCK_PREFIX "decl %0"
15523 + asm volatile(LOCK_PREFIX "decl %0\n"
15524 +
15525 +#ifdef CONFIG_PAX_REFCOUNT
15526 + "jno 0f\n"
15527 + LOCK_PREFIX "incl %0\n"
15528 + "int $4\n0:\n"
15529 + _ASM_EXTABLE(0b, 0b)
15530 +#endif
15531 +
15532 + : "+m" (v->counter));
15533 +}
15534 +
15535 +/**
15536 + * atomic_dec_unchecked - decrement atomic variable
15537 + * @v: pointer of type atomic_unchecked_t
15538 + *
15539 + * Atomically decrements @v by 1.
15540 + */
15541 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15542 +{
15543 + asm volatile(LOCK_PREFIX "decl %0\n"
15544 : "+m" (v->counter));
15545 }
15546
15547 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15548 */
15549 static inline int atomic_dec_and_test(atomic_t *v)
15550 {
15551 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15552 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15553 }
15554
15555 /**
15556 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15557 */
15558 static inline int atomic_inc_and_test(atomic_t *v)
15559 {
15560 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15561 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15562 +}
15563 +
15564 +/**
15565 + * atomic_inc_and_test_unchecked - increment and test
15566 + * @v: pointer of type atomic_unchecked_t
15567 + *
15568 + * Atomically increments @v by 1
15569 + * and returns true if the result is zero, or false for all
15570 + * other cases.
15571 + */
15572 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15573 +{
15574 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15575 }
15576
15577 /**
15578 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15579 */
15580 static inline int atomic_add_negative(int i, atomic_t *v)
15581 {
15582 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15583 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15584 }
15585
15586 /**
15587 @@ -154,6 +274,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15588 */
15589 static inline int atomic_add_return(int i, atomic_t *v)
15590 {
15591 + return i + xadd_check_overflow(&v->counter, i);
15592 +}
15593 +
15594 +/**
15595 + * atomic_add_return_unchecked - add integer and return
15596 + * @i: integer value to add
15597 + * @v: pointer of type atomic_unchecked_t
15598 + *
15599 + * Atomically adds @i to @v and returns @i + @v
15600 + */
15601 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15602 +{
15603 return i + xadd(&v->counter, i);
15604 }
15605
15606 @@ -170,9 +302,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15607 }
15608
15609 #define atomic_inc_return(v) (atomic_add_return(1, v))
15610 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15611 +{
15612 + return atomic_add_return_unchecked(1, v);
15613 +}
15614 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15615
15616 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15617 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15618 +{
15619 + return cmpxchg(&v->counter, old, new);
15620 +}
15621 +
15622 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15623 {
15624 return cmpxchg(&v->counter, old, new);
15625 }
15626 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15627 return xchg(&v->counter, new);
15628 }
15629
15630 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15631 +{
15632 + return xchg(&v->counter, new);
15633 +}
15634 +
15635 /**
15636 * __atomic_add_unless - add unless the number is already a given value
15637 * @v: pointer of type atomic_t
15638 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15639 * Atomically adds @a to @v, so long as @v was not already @u.
15640 * Returns the old value of @v.
15641 */
15642 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15643 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15644 {
15645 - int c, old;
15646 + int c, old, new;
15647 c = atomic_read(v);
15648 for (;;) {
15649 - if (unlikely(c == (u)))
15650 + if (unlikely(c == u))
15651 break;
15652 - old = atomic_cmpxchg((v), c, c + (a));
15653 +
15654 + asm volatile("addl %2,%0\n"
15655 +
15656 +#ifdef CONFIG_PAX_REFCOUNT
15657 + "jno 0f\n"
15658 + "subl %2,%0\n"
15659 + "int $4\n0:\n"
15660 + _ASM_EXTABLE(0b, 0b)
15661 +#endif
15662 +
15663 + : "=r" (new)
15664 + : "0" (c), "ir" (a));
15665 +
15666 + old = atomic_cmpxchg(v, c, new);
15667 if (likely(old == c))
15668 break;
15669 c = old;
15670 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15671 }
15672
15673 /**
15674 + * atomic_inc_not_zero_hint - increment if not null
15675 + * @v: pointer of type atomic_t
15676 + * @hint: probable value of the atomic before the increment
15677 + *
15678 + * This version of atomic_inc_not_zero() gives a hint of probable
15679 + * value of the atomic. This helps processor to not read the memory
15680 + * before doing the atomic read/modify/write cycle, lowering
15681 + * number of bus transactions on some arches.
15682 + *
15683 + * Returns: 0 if increment was not done, 1 otherwise.
15684 + */
15685 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15686 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15687 +{
15688 + int val, c = hint, new;
15689 +
15690 + /* sanity test, should be removed by compiler if hint is a constant */
15691 + if (!hint)
15692 + return __atomic_add_unless(v, 1, 0);
15693 +
15694 + do {
15695 + asm volatile("incl %0\n"
15696 +
15697 +#ifdef CONFIG_PAX_REFCOUNT
15698 + "jno 0f\n"
15699 + "decl %0\n"
15700 + "int $4\n0:\n"
15701 + _ASM_EXTABLE(0b, 0b)
15702 +#endif
15703 +
15704 + : "=r" (new)
15705 + : "0" (c));
15706 +
15707 + val = atomic_cmpxchg(v, c, new);
15708 + if (val == c)
15709 + return 1;
15710 + c = val;
15711 + } while (c);
15712 +
15713 + return 0;
15714 +}
15715 +
15716 +/**
15717 * atomic_inc_short - increment of a short integer
15718 * @v: pointer to type int
15719 *
15720 @@ -235,14 +437,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15721 #endif
15722
15723 /* These are x86-specific, used by some header files */
15724 -#define atomic_clear_mask(mask, addr) \
15725 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15726 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15727 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15728 +{
15729 + asm volatile(LOCK_PREFIX "andl %1,%0"
15730 + : "+m" (v->counter)
15731 + : "r" (~(mask))
15732 + : "memory");
15733 +}
15734
15735 -#define atomic_set_mask(mask, addr) \
15736 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15737 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15738 - : "memory")
15739 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15740 +{
15741 + asm volatile(LOCK_PREFIX "andl %1,%0"
15742 + : "+m" (v->counter)
15743 + : "r" (~(mask))
15744 + : "memory");
15745 +}
15746 +
15747 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15748 +{
15749 + asm volatile(LOCK_PREFIX "orl %1,%0"
15750 + : "+m" (v->counter)
15751 + : "r" (mask)
15752 + : "memory");
15753 +}
15754 +
15755 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15756 +{
15757 + asm volatile(LOCK_PREFIX "orl %1,%0"
15758 + : "+m" (v->counter)
15759 + : "r" (mask)
15760 + : "memory");
15761 +}
15762
15763 #ifdef CONFIG_X86_32
15764 # include <asm/atomic64_32.h>
15765 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15766 index b154de7..bf18a5a 100644
15767 --- a/arch/x86/include/asm/atomic64_32.h
15768 +++ b/arch/x86/include/asm/atomic64_32.h
15769 @@ -12,6 +12,14 @@ typedef struct {
15770 u64 __aligned(8) counter;
15771 } atomic64_t;
15772
15773 +#ifdef CONFIG_PAX_REFCOUNT
15774 +typedef struct {
15775 + u64 __aligned(8) counter;
15776 +} atomic64_unchecked_t;
15777 +#else
15778 +typedef atomic64_t atomic64_unchecked_t;
15779 +#endif
15780 +
15781 #define ATOMIC64_INIT(val) { (val) }
15782
15783 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15784 @@ -37,21 +45,31 @@ typedef struct {
15785 ATOMIC64_DECL_ONE(sym##_386)
15786
15787 ATOMIC64_DECL_ONE(add_386);
15788 +ATOMIC64_DECL_ONE(add_unchecked_386);
15789 ATOMIC64_DECL_ONE(sub_386);
15790 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15791 ATOMIC64_DECL_ONE(inc_386);
15792 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15793 ATOMIC64_DECL_ONE(dec_386);
15794 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15795 #endif
15796
15797 #define alternative_atomic64(f, out, in...) \
15798 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15799
15800 ATOMIC64_DECL(read);
15801 +ATOMIC64_DECL(read_unchecked);
15802 ATOMIC64_DECL(set);
15803 +ATOMIC64_DECL(set_unchecked);
15804 ATOMIC64_DECL(xchg);
15805 ATOMIC64_DECL(add_return);
15806 +ATOMIC64_DECL(add_return_unchecked);
15807 ATOMIC64_DECL(sub_return);
15808 +ATOMIC64_DECL(sub_return_unchecked);
15809 ATOMIC64_DECL(inc_return);
15810 +ATOMIC64_DECL(inc_return_unchecked);
15811 ATOMIC64_DECL(dec_return);
15812 +ATOMIC64_DECL(dec_return_unchecked);
15813 ATOMIC64_DECL(dec_if_positive);
15814 ATOMIC64_DECL(inc_not_zero);
15815 ATOMIC64_DECL(add_unless);
15816 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15817 }
15818
15819 /**
15820 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15821 + * @p: pointer to type atomic64_unchecked_t
15822 + * @o: expected value
15823 + * @n: new value
15824 + *
15825 + * Atomically sets @v to @n if it was equal to @o and returns
15826 + * the old value.
15827 + */
15828 +
15829 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15830 +{
15831 + return cmpxchg64(&v->counter, o, n);
15832 +}
15833 +
15834 +/**
15835 * atomic64_xchg - xchg atomic64 variable
15836 * @v: pointer to type atomic64_t
15837 * @n: value to assign
15838 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15839 }
15840
15841 /**
15842 + * atomic64_set_unchecked - set atomic64 variable
15843 + * @v: pointer to type atomic64_unchecked_t
15844 + * @n: value to assign
15845 + *
15846 + * Atomically sets the value of @v to @n.
15847 + */
15848 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15849 +{
15850 + unsigned high = (unsigned)(i >> 32);
15851 + unsigned low = (unsigned)i;
15852 + alternative_atomic64(set, /* no output */,
15853 + "S" (v), "b" (low), "c" (high)
15854 + : "eax", "edx", "memory");
15855 +}
15856 +
15857 +/**
15858 * atomic64_read - read atomic64 variable
15859 * @v: pointer to type atomic64_t
15860 *
15861 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15862 }
15863
15864 /**
15865 + * atomic64_read_unchecked - read atomic64 variable
15866 + * @v: pointer to type atomic64_unchecked_t
15867 + *
15868 + * Atomically reads the value of @v and returns it.
15869 + */
15870 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15871 +{
15872 + long long r;
15873 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15874 + return r;
15875 + }
15876 +
15877 +/**
15878 * atomic64_add_return - add and return
15879 * @i: integer value to add
15880 * @v: pointer to type atomic64_t
15881 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15882 return i;
15883 }
15884
15885 +/**
15886 + * atomic64_add_return_unchecked - add and return
15887 + * @i: integer value to add
15888 + * @v: pointer to type atomic64_unchecked_t
15889 + *
15890 + * Atomically adds @i to @v and returns @i + *@v
15891 + */
15892 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15893 +{
15894 + alternative_atomic64(add_return_unchecked,
15895 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15896 + ASM_NO_INPUT_CLOBBER("memory"));
15897 + return i;
15898 +}
15899 +
15900 /*
15901 * Other variants with different arithmetic operators:
15902 */
15903 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15904 return a;
15905 }
15906
15907 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15908 +{
15909 + long long a;
15910 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15911 + "S" (v) : "memory", "ecx");
15912 + return a;
15913 +}
15914 +
15915 static inline long long atomic64_dec_return(atomic64_t *v)
15916 {
15917 long long a;
15918 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15919 }
15920
15921 /**
15922 + * atomic64_add_unchecked - add integer to atomic64 variable
15923 + * @i: integer value to add
15924 + * @v: pointer to type atomic64_unchecked_t
15925 + *
15926 + * Atomically adds @i to @v.
15927 + */
15928 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15929 +{
15930 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15931 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15932 + ASM_NO_INPUT_CLOBBER("memory"));
15933 + return i;
15934 +}
15935 +
15936 +/**
15937 * atomic64_sub - subtract the atomic64 variable
15938 * @i: integer value to subtract
15939 * @v: pointer to type atomic64_t
15940 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15941 index 46e9052..ae45136 100644
15942 --- a/arch/x86/include/asm/atomic64_64.h
15943 +++ b/arch/x86/include/asm/atomic64_64.h
15944 @@ -18,7 +18,19 @@
15945 */
15946 static inline long atomic64_read(const atomic64_t *v)
15947 {
15948 - return (*(volatile long *)&(v)->counter);
15949 + return (*(volatile const long *)&(v)->counter);
15950 +}
15951 +
15952 +/**
15953 + * atomic64_read_unchecked - read atomic64 variable
15954 + * @v: pointer of type atomic64_unchecked_t
15955 + *
15956 + * Atomically reads the value of @v.
15957 + * Doesn't imply a read memory barrier.
15958 + */
15959 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15960 +{
15961 + return (*(volatile const long *)&(v)->counter);
15962 }
15963
15964 /**
15965 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15966 }
15967
15968 /**
15969 + * atomic64_set_unchecked - set atomic64 variable
15970 + * @v: pointer to type atomic64_unchecked_t
15971 + * @i: required value
15972 + *
15973 + * Atomically sets the value of @v to @i.
15974 + */
15975 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15976 +{
15977 + v->counter = i;
15978 +}
15979 +
15980 +/**
15981 * atomic64_add - add integer to atomic64 variable
15982 * @i: integer value to add
15983 * @v: pointer to type atomic64_t
15984 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15985 */
15986 static inline void atomic64_add(long i, atomic64_t *v)
15987 {
15988 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15989 +
15990 +#ifdef CONFIG_PAX_REFCOUNT
15991 + "jno 0f\n"
15992 + LOCK_PREFIX "subq %1,%0\n"
15993 + "int $4\n0:\n"
15994 + _ASM_EXTABLE(0b, 0b)
15995 +#endif
15996 +
15997 + : "=m" (v->counter)
15998 + : "er" (i), "m" (v->counter));
15999 +}
16000 +
16001 +/**
16002 + * atomic64_add_unchecked - add integer to atomic64 variable
16003 + * @i: integer value to add
16004 + * @v: pointer to type atomic64_unchecked_t
16005 + *
16006 + * Atomically adds @i to @v.
16007 + */
16008 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
16009 +{
16010 asm volatile(LOCK_PREFIX "addq %1,%0"
16011 : "=m" (v->counter)
16012 : "er" (i), "m" (v->counter));
16013 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
16014 */
16015 static inline void atomic64_sub(long i, atomic64_t *v)
16016 {
16017 - asm volatile(LOCK_PREFIX "subq %1,%0"
16018 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16019 +
16020 +#ifdef CONFIG_PAX_REFCOUNT
16021 + "jno 0f\n"
16022 + LOCK_PREFIX "addq %1,%0\n"
16023 + "int $4\n0:\n"
16024 + _ASM_EXTABLE(0b, 0b)
16025 +#endif
16026 +
16027 + : "=m" (v->counter)
16028 + : "er" (i), "m" (v->counter));
16029 +}
16030 +
16031 +/**
16032 + * atomic64_sub_unchecked - subtract the atomic64 variable
16033 + * @i: integer value to subtract
16034 + * @v: pointer to type atomic64_unchecked_t
16035 + *
16036 + * Atomically subtracts @i from @v.
16037 + */
16038 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
16039 +{
16040 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16041 : "=m" (v->counter)
16042 : "er" (i), "m" (v->counter));
16043 }
16044 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
16045 */
16046 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16047 {
16048 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
16049 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
16050 }
16051
16052 /**
16053 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16054 */
16055 static inline void atomic64_inc(atomic64_t *v)
16056 {
16057 + asm volatile(LOCK_PREFIX "incq %0\n"
16058 +
16059 +#ifdef CONFIG_PAX_REFCOUNT
16060 + "jno 0f\n"
16061 + LOCK_PREFIX "decq %0\n"
16062 + "int $4\n0:\n"
16063 + _ASM_EXTABLE(0b, 0b)
16064 +#endif
16065 +
16066 + : "=m" (v->counter)
16067 + : "m" (v->counter));
16068 +}
16069 +
16070 +/**
16071 + * atomic64_inc_unchecked - increment atomic64 variable
16072 + * @v: pointer to type atomic64_unchecked_t
16073 + *
16074 + * Atomically increments @v by 1.
16075 + */
16076 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
16077 +{
16078 asm volatile(LOCK_PREFIX "incq %0"
16079 : "=m" (v->counter)
16080 : "m" (v->counter));
16081 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
16082 */
16083 static inline void atomic64_dec(atomic64_t *v)
16084 {
16085 - asm volatile(LOCK_PREFIX "decq %0"
16086 + asm volatile(LOCK_PREFIX "decq %0\n"
16087 +
16088 +#ifdef CONFIG_PAX_REFCOUNT
16089 + "jno 0f\n"
16090 + LOCK_PREFIX "incq %0\n"
16091 + "int $4\n0:\n"
16092 + _ASM_EXTABLE(0b, 0b)
16093 +#endif
16094 +
16095 + : "=m" (v->counter)
16096 + : "m" (v->counter));
16097 +}
16098 +
16099 +/**
16100 + * atomic64_dec_unchecked - decrement atomic64 variable
16101 + * @v: pointer to type atomic64_t
16102 + *
16103 + * Atomically decrements @v by 1.
16104 + */
16105 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
16106 +{
16107 + asm volatile(LOCK_PREFIX "decq %0\n"
16108 : "=m" (v->counter)
16109 : "m" (v->counter));
16110 }
16111 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
16112 */
16113 static inline int atomic64_dec_and_test(atomic64_t *v)
16114 {
16115 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
16116 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
16117 }
16118
16119 /**
16120 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
16121 */
16122 static inline int atomic64_inc_and_test(atomic64_t *v)
16123 {
16124 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
16125 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
16126 }
16127
16128 /**
16129 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
16130 */
16131 static inline int atomic64_add_negative(long i, atomic64_t *v)
16132 {
16133 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
16134 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
16135 }
16136
16137 /**
16138 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
16139 */
16140 static inline long atomic64_add_return(long i, atomic64_t *v)
16141 {
16142 + return i + xadd_check_overflow(&v->counter, i);
16143 +}
16144 +
16145 +/**
16146 + * atomic64_add_return_unchecked - add and return
16147 + * @i: integer value to add
16148 + * @v: pointer to type atomic64_unchecked_t
16149 + *
16150 + * Atomically adds @i to @v and returns @i + @v
16151 + */
16152 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
16153 +{
16154 return i + xadd(&v->counter, i);
16155 }
16156
16157 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
16158 }
16159
16160 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
16161 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16162 +{
16163 + return atomic64_add_return_unchecked(1, v);
16164 +}
16165 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16166
16167 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16168 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16169 return cmpxchg(&v->counter, old, new);
16170 }
16171
16172 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16173 +{
16174 + return cmpxchg(&v->counter, old, new);
16175 +}
16176 +
16177 static inline long atomic64_xchg(atomic64_t *v, long new)
16178 {
16179 return xchg(&v->counter, new);
16180 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16181 */
16182 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16183 {
16184 - long c, old;
16185 + long c, old, new;
16186 c = atomic64_read(v);
16187 for (;;) {
16188 - if (unlikely(c == (u)))
16189 + if (unlikely(c == u))
16190 break;
16191 - old = atomic64_cmpxchg((v), c, c + (a));
16192 +
16193 + asm volatile("add %2,%0\n"
16194 +
16195 +#ifdef CONFIG_PAX_REFCOUNT
16196 + "jno 0f\n"
16197 + "sub %2,%0\n"
16198 + "int $4\n0:\n"
16199 + _ASM_EXTABLE(0b, 0b)
16200 +#endif
16201 +
16202 + : "=r" (new)
16203 + : "0" (c), "ir" (a));
16204 +
16205 + old = atomic64_cmpxchg(v, c, new);
16206 if (likely(old == c))
16207 break;
16208 c = old;
16209 }
16210 - return c != (u);
16211 + return c != u;
16212 }
16213
16214 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16215 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16216 index 5c7198c..44180b5 100644
16217 --- a/arch/x86/include/asm/barrier.h
16218 +++ b/arch/x86/include/asm/barrier.h
16219 @@ -107,7 +107,7 @@
16220 do { \
16221 compiletime_assert_atomic_type(*p); \
16222 smp_mb(); \
16223 - ACCESS_ONCE(*p) = (v); \
16224 + ACCESS_ONCE_RW(*p) = (v); \
16225 } while (0)
16226
16227 #define smp_load_acquire(p) \
16228 @@ -124,7 +124,7 @@ do { \
16229 do { \
16230 compiletime_assert_atomic_type(*p); \
16231 barrier(); \
16232 - ACCESS_ONCE(*p) = (v); \
16233 + ACCESS_ONCE_RW(*p) = (v); \
16234 } while (0)
16235
16236 #define smp_load_acquire(p) \
16237 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16238 index afcd35d..141b32d 100644
16239 --- a/arch/x86/include/asm/bitops.h
16240 +++ b/arch/x86/include/asm/bitops.h
16241 @@ -50,7 +50,7 @@
16242 * a mask operation on a byte.
16243 */
16244 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16245 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16246 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16247 #define CONST_MASK(nr) (1 << ((nr) & 7))
16248
16249 /**
16250 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16251 */
16252 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16253 {
16254 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16255 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16256 }
16257
16258 /**
16259 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16260 */
16261 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16262 {
16263 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16264 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16265 }
16266
16267 /**
16268 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16269 */
16270 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16271 {
16272 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16273 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16274 }
16275
16276 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16277 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16278 *
16279 * Undefined if no bit exists, so code should check against 0 first.
16280 */
16281 -static inline unsigned long __ffs(unsigned long word)
16282 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16283 {
16284 asm("rep; bsf %1,%0"
16285 : "=r" (word)
16286 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16287 *
16288 * Undefined if no zero exists, so code should check against ~0UL first.
16289 */
16290 -static inline unsigned long ffz(unsigned long word)
16291 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16292 {
16293 asm("rep; bsf %1,%0"
16294 : "=r" (word)
16295 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16296 *
16297 * Undefined if no set bit exists, so code should check against 0 first.
16298 */
16299 -static inline unsigned long __fls(unsigned long word)
16300 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16301 {
16302 asm("bsr %1,%0"
16303 : "=r" (word)
16304 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16305 * set bit if value is nonzero. The last (most significant) bit is
16306 * at position 32.
16307 */
16308 -static inline int fls(int x)
16309 +static inline int __intentional_overflow(-1) fls(int x)
16310 {
16311 int r;
16312
16313 @@ -476,7 +476,7 @@ static inline int fls(int x)
16314 * at position 64.
16315 */
16316 #ifdef CONFIG_X86_64
16317 -static __always_inline int fls64(__u64 x)
16318 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16319 {
16320 int bitpos = -1;
16321 /*
16322 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16323 index 4fa687a..60f2d39 100644
16324 --- a/arch/x86/include/asm/boot.h
16325 +++ b/arch/x86/include/asm/boot.h
16326 @@ -6,10 +6,15 @@
16327 #include <uapi/asm/boot.h>
16328
16329 /* Physical address where kernel should be loaded. */
16330 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16331 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16332 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16333 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16334
16335 +#ifndef __ASSEMBLY__
16336 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16337 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16338 +#endif
16339 +
16340 /* Minimum kernel alignment, as a power of two */
16341 #ifdef CONFIG_X86_64
16342 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16343 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16344 index 48f99f1..d78ebf9 100644
16345 --- a/arch/x86/include/asm/cache.h
16346 +++ b/arch/x86/include/asm/cache.h
16347 @@ -5,12 +5,13 @@
16348
16349 /* L1 cache line size */
16350 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16351 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16352 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16353
16354 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16355 +#define __read_only __attribute__((__section__(".data..read_only")))
16356
16357 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16358 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16359 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16360
16361 #ifdef CONFIG_X86_VSMP
16362 #ifdef CONFIG_SMP
16363 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16364 index 9863ee3..4a1f8e1 100644
16365 --- a/arch/x86/include/asm/cacheflush.h
16366 +++ b/arch/x86/include/asm/cacheflush.h
16367 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16368 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16369
16370 if (pg_flags == _PGMT_DEFAULT)
16371 - return -1;
16372 + return ~0UL;
16373 else if (pg_flags == _PGMT_WC)
16374 return _PAGE_CACHE_WC;
16375 else if (pg_flags == _PGMT_UC_MINUS)
16376 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16377 index cb4c73b..c473c29 100644
16378 --- a/arch/x86/include/asm/calling.h
16379 +++ b/arch/x86/include/asm/calling.h
16380 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16381 #define RSP 152
16382 #define SS 160
16383
16384 -#define ARGOFFSET R11
16385 -#define SWFRAME ORIG_RAX
16386 +#define ARGOFFSET R15
16387
16388 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16389 - subq $9*8+\addskip, %rsp
16390 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16391 - movq_cfi rdi, 8*8
16392 - movq_cfi rsi, 7*8
16393 - movq_cfi rdx, 6*8
16394 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16395 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16396 + movq_cfi rdi, RDI
16397 + movq_cfi rsi, RSI
16398 + movq_cfi rdx, RDX
16399
16400 .if \save_rcx
16401 - movq_cfi rcx, 5*8
16402 + movq_cfi rcx, RCX
16403 .endif
16404
16405 - movq_cfi rax, 4*8
16406 + movq_cfi rax, RAX
16407
16408 .if \save_r891011
16409 - movq_cfi r8, 3*8
16410 - movq_cfi r9, 2*8
16411 - movq_cfi r10, 1*8
16412 - movq_cfi r11, 0*8
16413 + movq_cfi r8, R8
16414 + movq_cfi r9, R9
16415 + movq_cfi r10, R10
16416 + movq_cfi r11, R11
16417 .endif
16418
16419 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16420 + movq_cfi r12, R12
16421 +#endif
16422 +
16423 .endm
16424
16425 -#define ARG_SKIP (9*8)
16426 +#define ARG_SKIP ORIG_RAX
16427
16428 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16429 rstor_r8910=1, rstor_rdx=1
16430 +
16431 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16432 + movq_cfi_restore R12, r12
16433 +#endif
16434 +
16435 .if \rstor_r11
16436 - movq_cfi_restore 0*8, r11
16437 + movq_cfi_restore R11, r11
16438 .endif
16439
16440 .if \rstor_r8910
16441 - movq_cfi_restore 1*8, r10
16442 - movq_cfi_restore 2*8, r9
16443 - movq_cfi_restore 3*8, r8
16444 + movq_cfi_restore R10, r10
16445 + movq_cfi_restore R9, r9
16446 + movq_cfi_restore R8, r8
16447 .endif
16448
16449 .if \rstor_rax
16450 - movq_cfi_restore 4*8, rax
16451 + movq_cfi_restore RAX, rax
16452 .endif
16453
16454 .if \rstor_rcx
16455 - movq_cfi_restore 5*8, rcx
16456 + movq_cfi_restore RCX, rcx
16457 .endif
16458
16459 .if \rstor_rdx
16460 - movq_cfi_restore 6*8, rdx
16461 + movq_cfi_restore RDX, rdx
16462 .endif
16463
16464 - movq_cfi_restore 7*8, rsi
16465 - movq_cfi_restore 8*8, rdi
16466 + movq_cfi_restore RSI, rsi
16467 + movq_cfi_restore RDI, rdi
16468
16469 - .if ARG_SKIP+\addskip > 0
16470 - addq $ARG_SKIP+\addskip, %rsp
16471 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16472 + .if ORIG_RAX+\addskip > 0
16473 + addq $ORIG_RAX+\addskip, %rsp
16474 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16475 .endif
16476 .endm
16477
16478 - .macro LOAD_ARGS offset, skiprax=0
16479 - movq \offset(%rsp), %r11
16480 - movq \offset+8(%rsp), %r10
16481 - movq \offset+16(%rsp), %r9
16482 - movq \offset+24(%rsp), %r8
16483 - movq \offset+40(%rsp), %rcx
16484 - movq \offset+48(%rsp), %rdx
16485 - movq \offset+56(%rsp), %rsi
16486 - movq \offset+64(%rsp), %rdi
16487 + .macro LOAD_ARGS skiprax=0
16488 + movq R11(%rsp), %r11
16489 + movq R10(%rsp), %r10
16490 + movq R9(%rsp), %r9
16491 + movq R8(%rsp), %r8
16492 + movq RCX(%rsp), %rcx
16493 + movq RDX(%rsp), %rdx
16494 + movq RSI(%rsp), %rsi
16495 + movq RDI(%rsp), %rdi
16496 .if \skiprax
16497 .else
16498 - movq \offset+72(%rsp), %rax
16499 + movq RAX(%rsp), %rax
16500 .endif
16501 .endm
16502
16503 -#define REST_SKIP (6*8)
16504 -
16505 .macro SAVE_REST
16506 - subq $REST_SKIP, %rsp
16507 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16508 - movq_cfi rbx, 5*8
16509 - movq_cfi rbp, 4*8
16510 - movq_cfi r12, 3*8
16511 - movq_cfi r13, 2*8
16512 - movq_cfi r14, 1*8
16513 - movq_cfi r15, 0*8
16514 + movq_cfi rbx, RBX
16515 + movq_cfi rbp, RBP
16516 +
16517 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16518 + movq_cfi r12, R12
16519 +#endif
16520 +
16521 + movq_cfi r13, R13
16522 + movq_cfi r14, R14
16523 + movq_cfi r15, R15
16524 .endm
16525
16526 .macro RESTORE_REST
16527 - movq_cfi_restore 0*8, r15
16528 - movq_cfi_restore 1*8, r14
16529 - movq_cfi_restore 2*8, r13
16530 - movq_cfi_restore 3*8, r12
16531 - movq_cfi_restore 4*8, rbp
16532 - movq_cfi_restore 5*8, rbx
16533 - addq $REST_SKIP, %rsp
16534 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16535 + movq_cfi_restore R15, r15
16536 + movq_cfi_restore R14, r14
16537 + movq_cfi_restore R13, r13
16538 +
16539 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16540 + movq_cfi_restore R12, r12
16541 +#endif
16542 +
16543 + movq_cfi_restore RBP, rbp
16544 + movq_cfi_restore RBX, rbx
16545 .endm
16546
16547 .macro SAVE_ALL
16548 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16549 index f50de69..2b0a458 100644
16550 --- a/arch/x86/include/asm/checksum_32.h
16551 +++ b/arch/x86/include/asm/checksum_32.h
16552 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16553 int len, __wsum sum,
16554 int *src_err_ptr, int *dst_err_ptr);
16555
16556 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16557 + int len, __wsum sum,
16558 + int *src_err_ptr, int *dst_err_ptr);
16559 +
16560 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16561 + int len, __wsum sum,
16562 + int *src_err_ptr, int *dst_err_ptr);
16563 +
16564 /*
16565 * Note: when you get a NULL pointer exception here this means someone
16566 * passed in an incorrect kernel address to one of these functions.
16567 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16568
16569 might_sleep();
16570 stac();
16571 - ret = csum_partial_copy_generic((__force void *)src, dst,
16572 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16573 len, sum, err_ptr, NULL);
16574 clac();
16575
16576 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16577 might_sleep();
16578 if (access_ok(VERIFY_WRITE, dst, len)) {
16579 stac();
16580 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16581 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16582 len, sum, NULL, err_ptr);
16583 clac();
16584 return ret;
16585 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16586 index d47786a..2d8883e 100644
16587 --- a/arch/x86/include/asm/cmpxchg.h
16588 +++ b/arch/x86/include/asm/cmpxchg.h
16589 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16590 __compiletime_error("Bad argument size for cmpxchg");
16591 extern void __xadd_wrong_size(void)
16592 __compiletime_error("Bad argument size for xadd");
16593 +extern void __xadd_check_overflow_wrong_size(void)
16594 + __compiletime_error("Bad argument size for xadd_check_overflow");
16595 extern void __add_wrong_size(void)
16596 __compiletime_error("Bad argument size for add");
16597 +extern void __add_check_overflow_wrong_size(void)
16598 + __compiletime_error("Bad argument size for add_check_overflow");
16599
16600 /*
16601 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16602 @@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16603 __ret; \
16604 })
16605
16606 +#ifdef CONFIG_PAX_REFCOUNT
16607 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16608 + ({ \
16609 + __typeof__ (*(ptr)) __ret = (arg); \
16610 + switch (sizeof(*(ptr))) { \
16611 + case __X86_CASE_L: \
16612 + asm volatile (lock #op "l %0, %1\n" \
16613 + "jno 0f\n" \
16614 + "mov %0,%1\n" \
16615 + "int $4\n0:\n" \
16616 + _ASM_EXTABLE(0b, 0b) \
16617 + : "+r" (__ret), "+m" (*(ptr)) \
16618 + : : "memory", "cc"); \
16619 + break; \
16620 + case __X86_CASE_Q: \
16621 + asm volatile (lock #op "q %q0, %1\n" \
16622 + "jno 0f\n" \
16623 + "mov %0,%1\n" \
16624 + "int $4\n0:\n" \
16625 + _ASM_EXTABLE(0b, 0b) \
16626 + : "+r" (__ret), "+m" (*(ptr)) \
16627 + : : "memory", "cc"); \
16628 + break; \
16629 + default: \
16630 + __ ## op ## _check_overflow_wrong_size(); \
16631 + } \
16632 + __ret; \
16633 + })
16634 +#else
16635 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16636 +#endif
16637 +
16638 /*
16639 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16640 * Since this is generally used to protect other memory information, we
16641 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16642 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16643 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16644
16645 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16646 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16647 +
16648 #define __add(ptr, inc, lock) \
16649 ({ \
16650 __typeof__ (*(ptr)) __ret = (inc); \
16651 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16652 index 59c6c40..5e0b22c 100644
16653 --- a/arch/x86/include/asm/compat.h
16654 +++ b/arch/x86/include/asm/compat.h
16655 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16656 typedef u32 compat_uint_t;
16657 typedef u32 compat_ulong_t;
16658 typedef u64 __attribute__((aligned(4))) compat_u64;
16659 -typedef u32 compat_uptr_t;
16660 +typedef u32 __user compat_uptr_t;
16661
16662 struct compat_timespec {
16663 compat_time_t tv_sec;
16664 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16665 index e265ff9..72c253b 100644
16666 --- a/arch/x86/include/asm/cpufeature.h
16667 +++ b/arch/x86/include/asm/cpufeature.h
16668 @@ -203,7 +203,7 @@
16669 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16670 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16671 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16672 -
16673 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16674
16675 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16676 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16677 @@ -211,7 +211,7 @@
16678 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16679 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16680 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16681 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16682 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16683 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16684 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16685 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16686 @@ -359,6 +359,7 @@ extern const char * const x86_power_flags[32];
16687 #undef cpu_has_centaur_mcr
16688 #define cpu_has_centaur_mcr 0
16689
16690 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16691 #endif /* CONFIG_X86_64 */
16692
16693 #if __GNUC__ >= 4
16694 @@ -411,7 +412,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16695
16696 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16697 t_warn:
16698 - warn_pre_alternatives();
16699 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16700 + warn_pre_alternatives();
16701 return false;
16702 #endif
16703
16704 @@ -431,7 +433,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16705 ".section .discard,\"aw\",@progbits\n"
16706 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16707 ".previous\n"
16708 - ".section .altinstr_replacement,\"ax\"\n"
16709 + ".section .altinstr_replacement,\"a\"\n"
16710 "3: movb $1,%0\n"
16711 "4:\n"
16712 ".previous\n"
16713 @@ -468,7 +470,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16714 " .byte 2b - 1b\n" /* src len */
16715 " .byte 4f - 3f\n" /* repl len */
16716 ".previous\n"
16717 - ".section .altinstr_replacement,\"ax\"\n"
16718 + ".section .altinstr_replacement,\"a\"\n"
16719 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16720 "4:\n"
16721 ".previous\n"
16722 @@ -501,7 +503,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16723 ".section .discard,\"aw\",@progbits\n"
16724 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16725 ".previous\n"
16726 - ".section .altinstr_replacement,\"ax\"\n"
16727 + ".section .altinstr_replacement,\"a\"\n"
16728 "3: movb $0,%0\n"
16729 "4:\n"
16730 ".previous\n"
16731 @@ -515,7 +517,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16732 ".section .discard,\"aw\",@progbits\n"
16733 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16734 ".previous\n"
16735 - ".section .altinstr_replacement,\"ax\"\n"
16736 + ".section .altinstr_replacement,\"a\"\n"
16737 "5: movb $1,%0\n"
16738 "6:\n"
16739 ".previous\n"
16740 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16741 index 50d033a..37deb26 100644
16742 --- a/arch/x86/include/asm/desc.h
16743 +++ b/arch/x86/include/asm/desc.h
16744 @@ -4,6 +4,7 @@
16745 #include <asm/desc_defs.h>
16746 #include <asm/ldt.h>
16747 #include <asm/mmu.h>
16748 +#include <asm/pgtable.h>
16749
16750 #include <linux/smp.h>
16751 #include <linux/percpu.h>
16752 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16753
16754 desc->type = (info->read_exec_only ^ 1) << 1;
16755 desc->type |= info->contents << 2;
16756 + desc->type |= info->seg_not_present ^ 1;
16757
16758 desc->s = 1;
16759 desc->dpl = 0x3;
16760 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16761 }
16762
16763 extern struct desc_ptr idt_descr;
16764 -extern gate_desc idt_table[];
16765 -extern struct desc_ptr debug_idt_descr;
16766 -extern gate_desc debug_idt_table[];
16767 -
16768 -struct gdt_page {
16769 - struct desc_struct gdt[GDT_ENTRIES];
16770 -} __attribute__((aligned(PAGE_SIZE)));
16771 -
16772 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16773 +extern gate_desc idt_table[IDT_ENTRIES];
16774 +extern const struct desc_ptr debug_idt_descr;
16775 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16776
16777 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16778 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16779 {
16780 - return per_cpu(gdt_page, cpu).gdt;
16781 + return cpu_gdt_table[cpu];
16782 }
16783
16784 #ifdef CONFIG_X86_64
16785 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16786 unsigned long base, unsigned dpl, unsigned flags,
16787 unsigned short seg)
16788 {
16789 - gate->a = (seg << 16) | (base & 0xffff);
16790 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16791 + gate->gate.offset_low = base;
16792 + gate->gate.seg = seg;
16793 + gate->gate.reserved = 0;
16794 + gate->gate.type = type;
16795 + gate->gate.s = 0;
16796 + gate->gate.dpl = dpl;
16797 + gate->gate.p = 1;
16798 + gate->gate.offset_high = base >> 16;
16799 }
16800
16801 #endif
16802 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16803
16804 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16805 {
16806 + pax_open_kernel();
16807 memcpy(&idt[entry], gate, sizeof(*gate));
16808 + pax_close_kernel();
16809 }
16810
16811 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16812 {
16813 + pax_open_kernel();
16814 memcpy(&ldt[entry], desc, 8);
16815 + pax_close_kernel();
16816 }
16817
16818 static inline void
16819 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16820 default: size = sizeof(*gdt); break;
16821 }
16822
16823 + pax_open_kernel();
16824 memcpy(&gdt[entry], desc, size);
16825 + pax_close_kernel();
16826 }
16827
16828 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16829 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16830
16831 static inline void native_load_tr_desc(void)
16832 {
16833 + pax_open_kernel();
16834 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16835 + pax_close_kernel();
16836 }
16837
16838 static inline void native_load_gdt(const struct desc_ptr *dtr)
16839 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16840 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16841 unsigned int i;
16842
16843 + pax_open_kernel();
16844 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16845 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16846 + pax_close_kernel();
16847 }
16848
16849 #define _LDT_empty(info) \
16850 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16851 preempt_enable();
16852 }
16853
16854 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16855 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16856 {
16857 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16858 }
16859 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16860 }
16861
16862 #ifdef CONFIG_X86_64
16863 -static inline void set_nmi_gate(int gate, void *addr)
16864 +static inline void set_nmi_gate(int gate, const void *addr)
16865 {
16866 gate_desc s;
16867
16868 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16869 #endif
16870
16871 #ifdef CONFIG_TRACING
16872 -extern struct desc_ptr trace_idt_descr;
16873 -extern gate_desc trace_idt_table[];
16874 +extern const struct desc_ptr trace_idt_descr;
16875 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16876 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16877 {
16878 write_idt_entry(trace_idt_table, entry, gate);
16879 }
16880
16881 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16882 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16883 unsigned dpl, unsigned ist, unsigned seg)
16884 {
16885 gate_desc s;
16886 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16887 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16888 #endif
16889
16890 -static inline void _set_gate(int gate, unsigned type, void *addr,
16891 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16892 unsigned dpl, unsigned ist, unsigned seg)
16893 {
16894 gate_desc s;
16895 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16896 #define set_intr_gate(n, addr) \
16897 do { \
16898 BUG_ON((unsigned)n > 0xFF); \
16899 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16900 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16901 __KERNEL_CS); \
16902 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16903 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16904 0, 0, __KERNEL_CS); \
16905 } while (0)
16906
16907 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16908 /*
16909 * This routine sets up an interrupt gate at directory privilege level 3.
16910 */
16911 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16912 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16913 {
16914 BUG_ON((unsigned)n > 0xFF);
16915 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16916 }
16917
16918 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16919 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16920 {
16921 BUG_ON((unsigned)n > 0xFF);
16922 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16923 }
16924
16925 -static inline void set_trap_gate(unsigned int n, void *addr)
16926 +static inline void set_trap_gate(unsigned int n, const void *addr)
16927 {
16928 BUG_ON((unsigned)n > 0xFF);
16929 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16930 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16931 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16932 {
16933 BUG_ON((unsigned)n > 0xFF);
16934 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16935 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16936 }
16937
16938 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16939 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16940 {
16941 BUG_ON((unsigned)n > 0xFF);
16942 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16943 }
16944
16945 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16946 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16947 {
16948 BUG_ON((unsigned)n > 0xFF);
16949 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16950 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16951 else
16952 load_idt((const struct desc_ptr *)&idt_descr);
16953 }
16954 +
16955 +#ifdef CONFIG_X86_32
16956 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16957 +{
16958 + struct desc_struct d;
16959 +
16960 + if (likely(limit))
16961 + limit = (limit - 1UL) >> PAGE_SHIFT;
16962 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16963 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16964 +}
16965 +#endif
16966 +
16967 #endif /* _ASM_X86_DESC_H */
16968 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16969 index 278441f..b95a174 100644
16970 --- a/arch/x86/include/asm/desc_defs.h
16971 +++ b/arch/x86/include/asm/desc_defs.h
16972 @@ -31,6 +31,12 @@ struct desc_struct {
16973 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16974 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16975 };
16976 + struct {
16977 + u16 offset_low;
16978 + u16 seg;
16979 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16980 + unsigned offset_high: 16;
16981 + } gate;
16982 };
16983 } __attribute__((packed));
16984
16985 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16986 index ced283a..ffe04cc 100644
16987 --- a/arch/x86/include/asm/div64.h
16988 +++ b/arch/x86/include/asm/div64.h
16989 @@ -39,7 +39,7 @@
16990 __mod; \
16991 })
16992
16993 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16994 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16995 {
16996 union {
16997 u64 v64;
16998 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16999 index 1a055c8..a1701de 100644
17000 --- a/arch/x86/include/asm/elf.h
17001 +++ b/arch/x86/include/asm/elf.h
17002 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
17003
17004 #include <asm/vdso.h>
17005
17006 -#ifdef CONFIG_X86_64
17007 -extern unsigned int vdso64_enabled;
17008 -#endif
17009 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
17010 extern unsigned int vdso32_enabled;
17011 #endif
17012 @@ -248,7 +245,25 @@ extern int force_personality32;
17013 the loader. We need to make sure that it is out of the way of the program
17014 that it will "exec", and that there is sufficient room for the brk. */
17015
17016 +#ifdef CONFIG_PAX_SEGMEXEC
17017 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
17018 +#else
17019 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
17020 +#endif
17021 +
17022 +#ifdef CONFIG_PAX_ASLR
17023 +#ifdef CONFIG_X86_32
17024 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
17025 +
17026 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17027 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17028 +#else
17029 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
17030 +
17031 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17032 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17033 +#endif
17034 +#endif
17035
17036 /* This yields a mask that user programs can use to figure out what
17037 instruction set this CPU supports. This could be done in user space,
17038 @@ -297,17 +312,13 @@ do { \
17039
17040 #define ARCH_DLINFO \
17041 do { \
17042 - if (vdso64_enabled) \
17043 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17044 - (unsigned long __force)current->mm->context.vdso); \
17045 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17046 } while (0)
17047
17048 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
17049 #define ARCH_DLINFO_X32 \
17050 do { \
17051 - if (vdso64_enabled) \
17052 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17053 - (unsigned long __force)current->mm->context.vdso); \
17054 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17055 } while (0)
17056
17057 #define AT_SYSINFO 32
17058 @@ -322,10 +333,10 @@ else \
17059
17060 #endif /* !CONFIG_X86_32 */
17061
17062 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
17063 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
17064
17065 #define VDSO_ENTRY \
17066 - ((unsigned long)current->mm->context.vdso + \
17067 + (current->mm->context.vdso + \
17068 selected_vdso32->sym___kernel_vsyscall)
17069
17070 struct linux_binprm;
17071 @@ -337,9 +348,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
17072 int uses_interp);
17073 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
17074
17075 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
17076 -#define arch_randomize_brk arch_randomize_brk
17077 -
17078 /*
17079 * True on X86_32 or when emulating IA32 on X86_64
17080 */
17081 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
17082 index 77a99ac..39ff7f5 100644
17083 --- a/arch/x86/include/asm/emergency-restart.h
17084 +++ b/arch/x86/include/asm/emergency-restart.h
17085 @@ -1,6 +1,6 @@
17086 #ifndef _ASM_X86_EMERGENCY_RESTART_H
17087 #define _ASM_X86_EMERGENCY_RESTART_H
17088
17089 -extern void machine_emergency_restart(void);
17090 +extern void machine_emergency_restart(void) __noreturn;
17091
17092 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
17093 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
17094 index 1c7eefe..d0e4702 100644
17095 --- a/arch/x86/include/asm/floppy.h
17096 +++ b/arch/x86/include/asm/floppy.h
17097 @@ -229,18 +229,18 @@ static struct fd_routine_l {
17098 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
17099 } fd_routine[] = {
17100 {
17101 - request_dma,
17102 - free_dma,
17103 - get_dma_residue,
17104 - dma_mem_alloc,
17105 - hard_dma_setup
17106 + ._request_dma = request_dma,
17107 + ._free_dma = free_dma,
17108 + ._get_dma_residue = get_dma_residue,
17109 + ._dma_mem_alloc = dma_mem_alloc,
17110 + ._dma_setup = hard_dma_setup
17111 },
17112 {
17113 - vdma_request_dma,
17114 - vdma_nop,
17115 - vdma_get_dma_residue,
17116 - vdma_mem_alloc,
17117 - vdma_dma_setup
17118 + ._request_dma = vdma_request_dma,
17119 + ._free_dma = vdma_nop,
17120 + ._get_dma_residue = vdma_get_dma_residue,
17121 + ._dma_mem_alloc = vdma_mem_alloc,
17122 + ._dma_setup = vdma_dma_setup
17123 }
17124 };
17125
17126 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
17127 index 115e368..76ecf6c 100644
17128 --- a/arch/x86/include/asm/fpu-internal.h
17129 +++ b/arch/x86/include/asm/fpu-internal.h
17130 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17131 #define user_insn(insn, output, input...) \
17132 ({ \
17133 int err; \
17134 + pax_open_userland(); \
17135 asm volatile(ASM_STAC "\n" \
17136 - "1:" #insn "\n\t" \
17137 + "1:" \
17138 + __copyuser_seg \
17139 + #insn "\n\t" \
17140 "2: " ASM_CLAC "\n" \
17141 ".section .fixup,\"ax\"\n" \
17142 "3: movl $-1,%[err]\n" \
17143 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17144 _ASM_EXTABLE(1b, 3b) \
17145 : [err] "=r" (err), output \
17146 : "0"(0), input); \
17147 + pax_close_userland(); \
17148 err; \
17149 })
17150
17151 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
17152 "fnclex\n\t"
17153 "emms\n\t"
17154 "fildl %P[addr]" /* set F?P to defined value */
17155 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
17156 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
17157 }
17158
17159 return fpu_restore_checking(&tsk->thread.fpu);
17160 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17161 index b4c1f54..e290c08 100644
17162 --- a/arch/x86/include/asm/futex.h
17163 +++ b/arch/x86/include/asm/futex.h
17164 @@ -12,6 +12,7 @@
17165 #include <asm/smap.h>
17166
17167 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17168 + typecheck(u32 __user *, uaddr); \
17169 asm volatile("\t" ASM_STAC "\n" \
17170 "1:\t" insn "\n" \
17171 "2:\t" ASM_CLAC "\n" \
17172 @@ -20,15 +21,16 @@
17173 "\tjmp\t2b\n" \
17174 "\t.previous\n" \
17175 _ASM_EXTABLE(1b, 3b) \
17176 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17177 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17178 : "i" (-EFAULT), "0" (oparg), "1" (0))
17179
17180 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17181 + typecheck(u32 __user *, uaddr); \
17182 asm volatile("\t" ASM_STAC "\n" \
17183 "1:\tmovl %2, %0\n" \
17184 "\tmovl\t%0, %3\n" \
17185 "\t" insn "\n" \
17186 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17187 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17188 "\tjnz\t1b\n" \
17189 "3:\t" ASM_CLAC "\n" \
17190 "\t.section .fixup,\"ax\"\n" \
17191 @@ -38,7 +40,7 @@
17192 _ASM_EXTABLE(1b, 4b) \
17193 _ASM_EXTABLE(2b, 4b) \
17194 : "=&a" (oldval), "=&r" (ret), \
17195 - "+m" (*uaddr), "=&r" (tem) \
17196 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17197 : "r" (oparg), "i" (-EFAULT), "1" (0))
17198
17199 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17200 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17201
17202 pagefault_disable();
17203
17204 + pax_open_userland();
17205 switch (op) {
17206 case FUTEX_OP_SET:
17207 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17208 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17209 break;
17210 case FUTEX_OP_ADD:
17211 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17212 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17213 uaddr, oparg);
17214 break;
17215 case FUTEX_OP_OR:
17216 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17217 default:
17218 ret = -ENOSYS;
17219 }
17220 + pax_close_userland();
17221
17222 pagefault_enable();
17223
17224 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17225 index 4615906..788c817 100644
17226 --- a/arch/x86/include/asm/hw_irq.h
17227 +++ b/arch/x86/include/asm/hw_irq.h
17228 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17229 extern void enable_IO_APIC(void);
17230
17231 /* Statistics */
17232 -extern atomic_t irq_err_count;
17233 -extern atomic_t irq_mis_count;
17234 +extern atomic_unchecked_t irq_err_count;
17235 +extern atomic_unchecked_t irq_mis_count;
17236
17237 /* EISA */
17238 extern void eisa_set_level_irq(unsigned int irq);
17239 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17240 index a203659..9889f1c 100644
17241 --- a/arch/x86/include/asm/i8259.h
17242 +++ b/arch/x86/include/asm/i8259.h
17243 @@ -62,7 +62,7 @@ struct legacy_pic {
17244 void (*init)(int auto_eoi);
17245 int (*irq_pending)(unsigned int irq);
17246 void (*make_irq)(unsigned int irq);
17247 -};
17248 +} __do_const;
17249
17250 extern struct legacy_pic *legacy_pic;
17251 extern struct legacy_pic null_legacy_pic;
17252 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17253 index b8237d8..3e8864e 100644
17254 --- a/arch/x86/include/asm/io.h
17255 +++ b/arch/x86/include/asm/io.h
17256 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17257 "m" (*(volatile type __force *)addr) barrier); }
17258
17259 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17260 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17261 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17262 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17263 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17264
17265 build_mmio_read(__readb, "b", unsigned char, "=q", )
17266 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17267 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17268 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17269 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17270
17271 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17272 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17273 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17274 * this function
17275 */
17276
17277 -static inline phys_addr_t virt_to_phys(volatile void *address)
17278 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17279 {
17280 return __pa(address);
17281 }
17282 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17283 return ioremap_nocache(offset, size);
17284 }
17285
17286 -extern void iounmap(volatile void __iomem *addr);
17287 +extern void iounmap(const volatile void __iomem *addr);
17288
17289 extern void set_iounmap_nonlazy(void);
17290
17291 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17292
17293 #include <linux/vmalloc.h>
17294
17295 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17296 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17297 +{
17298 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17299 +}
17300 +
17301 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17302 +{
17303 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17304 +}
17305 +
17306 /*
17307 * Convert a virtual cached pointer to an uncached pointer
17308 */
17309 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17310 index 0a8b519..80e7d5b 100644
17311 --- a/arch/x86/include/asm/irqflags.h
17312 +++ b/arch/x86/include/asm/irqflags.h
17313 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17314 sti; \
17315 sysexit
17316
17317 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17318 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17319 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17320 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17321 +
17322 #else
17323 #define INTERRUPT_RETURN iret
17324 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17325 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17326 index 53cdfb2..d1369e6 100644
17327 --- a/arch/x86/include/asm/kprobes.h
17328 +++ b/arch/x86/include/asm/kprobes.h
17329 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17330 #define RELATIVEJUMP_SIZE 5
17331 #define RELATIVECALL_OPCODE 0xe8
17332 #define RELATIVE_ADDR_SIZE 4
17333 -#define MAX_STACK_SIZE 64
17334 -#define MIN_STACK_SIZE(ADDR) \
17335 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17336 - THREAD_SIZE - (unsigned long)(ADDR))) \
17337 - ? (MAX_STACK_SIZE) \
17338 - : (((unsigned long)current_thread_info()) + \
17339 - THREAD_SIZE - (unsigned long)(ADDR)))
17340 +#define MAX_STACK_SIZE 64UL
17341 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17342
17343 #define flush_insn_slot(p) do { } while (0)
17344
17345 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17346 index 4ad6560..75c7bdd 100644
17347 --- a/arch/x86/include/asm/local.h
17348 +++ b/arch/x86/include/asm/local.h
17349 @@ -10,33 +10,97 @@ typedef struct {
17350 atomic_long_t a;
17351 } local_t;
17352
17353 +typedef struct {
17354 + atomic_long_unchecked_t a;
17355 +} local_unchecked_t;
17356 +
17357 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17358
17359 #define local_read(l) atomic_long_read(&(l)->a)
17360 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17361 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17362 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17363
17364 static inline void local_inc(local_t *l)
17365 {
17366 - asm volatile(_ASM_INC "%0"
17367 + asm volatile(_ASM_INC "%0\n"
17368 +
17369 +#ifdef CONFIG_PAX_REFCOUNT
17370 + "jno 0f\n"
17371 + _ASM_DEC "%0\n"
17372 + "int $4\n0:\n"
17373 + _ASM_EXTABLE(0b, 0b)
17374 +#endif
17375 +
17376 + : "+m" (l->a.counter));
17377 +}
17378 +
17379 +static inline void local_inc_unchecked(local_unchecked_t *l)
17380 +{
17381 + asm volatile(_ASM_INC "%0\n"
17382 : "+m" (l->a.counter));
17383 }
17384
17385 static inline void local_dec(local_t *l)
17386 {
17387 - asm volatile(_ASM_DEC "%0"
17388 + asm volatile(_ASM_DEC "%0\n"
17389 +
17390 +#ifdef CONFIG_PAX_REFCOUNT
17391 + "jno 0f\n"
17392 + _ASM_INC "%0\n"
17393 + "int $4\n0:\n"
17394 + _ASM_EXTABLE(0b, 0b)
17395 +#endif
17396 +
17397 + : "+m" (l->a.counter));
17398 +}
17399 +
17400 +static inline void local_dec_unchecked(local_unchecked_t *l)
17401 +{
17402 + asm volatile(_ASM_DEC "%0\n"
17403 : "+m" (l->a.counter));
17404 }
17405
17406 static inline void local_add(long i, local_t *l)
17407 {
17408 - asm volatile(_ASM_ADD "%1,%0"
17409 + asm volatile(_ASM_ADD "%1,%0\n"
17410 +
17411 +#ifdef CONFIG_PAX_REFCOUNT
17412 + "jno 0f\n"
17413 + _ASM_SUB "%1,%0\n"
17414 + "int $4\n0:\n"
17415 + _ASM_EXTABLE(0b, 0b)
17416 +#endif
17417 +
17418 + : "+m" (l->a.counter)
17419 + : "ir" (i));
17420 +}
17421 +
17422 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17423 +{
17424 + asm volatile(_ASM_ADD "%1,%0\n"
17425 : "+m" (l->a.counter)
17426 : "ir" (i));
17427 }
17428
17429 static inline void local_sub(long i, local_t *l)
17430 {
17431 - asm volatile(_ASM_SUB "%1,%0"
17432 + asm volatile(_ASM_SUB "%1,%0\n"
17433 +
17434 +#ifdef CONFIG_PAX_REFCOUNT
17435 + "jno 0f\n"
17436 + _ASM_ADD "%1,%0\n"
17437 + "int $4\n0:\n"
17438 + _ASM_EXTABLE(0b, 0b)
17439 +#endif
17440 +
17441 + : "+m" (l->a.counter)
17442 + : "ir" (i));
17443 +}
17444 +
17445 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17446 +{
17447 + asm volatile(_ASM_SUB "%1,%0\n"
17448 : "+m" (l->a.counter)
17449 : "ir" (i));
17450 }
17451 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17452 */
17453 static inline int local_sub_and_test(long i, local_t *l)
17454 {
17455 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17456 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17457 }
17458
17459 /**
17460 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17461 */
17462 static inline int local_dec_and_test(local_t *l)
17463 {
17464 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17465 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17466 }
17467
17468 /**
17469 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17470 */
17471 static inline int local_inc_and_test(local_t *l)
17472 {
17473 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17474 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17475 }
17476
17477 /**
17478 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17479 */
17480 static inline int local_add_negative(long i, local_t *l)
17481 {
17482 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17483 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17484 }
17485
17486 /**
17487 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17488 static inline long local_add_return(long i, local_t *l)
17489 {
17490 long __i = i;
17491 + asm volatile(_ASM_XADD "%0, %1\n"
17492 +
17493 +#ifdef CONFIG_PAX_REFCOUNT
17494 + "jno 0f\n"
17495 + _ASM_MOV "%0,%1\n"
17496 + "int $4\n0:\n"
17497 + _ASM_EXTABLE(0b, 0b)
17498 +#endif
17499 +
17500 + : "+r" (i), "+m" (l->a.counter)
17501 + : : "memory");
17502 + return i + __i;
17503 +}
17504 +
17505 +/**
17506 + * local_add_return_unchecked - add and return
17507 + * @i: integer value to add
17508 + * @l: pointer to type local_unchecked_t
17509 + *
17510 + * Atomically adds @i to @l and returns @i + @l
17511 + */
17512 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17513 +{
17514 + long __i = i;
17515 asm volatile(_ASM_XADD "%0, %1;"
17516 : "+r" (i), "+m" (l->a.counter)
17517 : : "memory");
17518 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17519
17520 #define local_cmpxchg(l, o, n) \
17521 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17522 +#define local_cmpxchg_unchecked(l, o, n) \
17523 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17524 /* Always has a lock prefix */
17525 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17526
17527 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17528 new file mode 100644
17529 index 0000000..2bfd3ba
17530 --- /dev/null
17531 +++ b/arch/x86/include/asm/mman.h
17532 @@ -0,0 +1,15 @@
17533 +#ifndef _X86_MMAN_H
17534 +#define _X86_MMAN_H
17535 +
17536 +#include <uapi/asm/mman.h>
17537 +
17538 +#ifdef __KERNEL__
17539 +#ifndef __ASSEMBLY__
17540 +#ifdef CONFIG_X86_32
17541 +#define arch_mmap_check i386_mmap_check
17542 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17543 +#endif
17544 +#endif
17545 +#endif
17546 +
17547 +#endif /* X86_MMAN_H */
17548 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17549 index 876e74e..e20bfb1 100644
17550 --- a/arch/x86/include/asm/mmu.h
17551 +++ b/arch/x86/include/asm/mmu.h
17552 @@ -9,7 +9,7 @@
17553 * we put the segment information here.
17554 */
17555 typedef struct {
17556 - void *ldt;
17557 + struct desc_struct *ldt;
17558 int size;
17559
17560 #ifdef CONFIG_X86_64
17561 @@ -18,7 +18,19 @@ typedef struct {
17562 #endif
17563
17564 struct mutex lock;
17565 - void __user *vdso;
17566 + unsigned long vdso;
17567 +
17568 +#ifdef CONFIG_X86_32
17569 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17570 + unsigned long user_cs_base;
17571 + unsigned long user_cs_limit;
17572 +
17573 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17574 + cpumask_t cpu_user_cs_mask;
17575 +#endif
17576 +
17577 +#endif
17578 +#endif
17579 } mm_context_t;
17580
17581 #ifdef CONFIG_SMP
17582 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17583 index be12c53..07fd3ca 100644
17584 --- a/arch/x86/include/asm/mmu_context.h
17585 +++ b/arch/x86/include/asm/mmu_context.h
17586 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17587
17588 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17589 {
17590 +
17591 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17592 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17593 + unsigned int i;
17594 + pgd_t *pgd;
17595 +
17596 + pax_open_kernel();
17597 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17598 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17599 + set_pgd_batched(pgd+i, native_make_pgd(0));
17600 + pax_close_kernel();
17601 + }
17602 +#endif
17603 +
17604 #ifdef CONFIG_SMP
17605 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17606 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17607 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17608 struct task_struct *tsk)
17609 {
17610 unsigned cpu = smp_processor_id();
17611 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17612 + int tlbstate = TLBSTATE_OK;
17613 +#endif
17614
17615 if (likely(prev != next)) {
17616 #ifdef CONFIG_SMP
17617 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17618 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17619 +#endif
17620 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17621 this_cpu_write(cpu_tlbstate.active_mm, next);
17622 #endif
17623 cpumask_set_cpu(cpu, mm_cpumask(next));
17624
17625 /* Re-load page tables */
17626 +#ifdef CONFIG_PAX_PER_CPU_PGD
17627 + pax_open_kernel();
17628 +
17629 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17630 + if (static_cpu_has(X86_FEATURE_PCID))
17631 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17632 + else
17633 +#endif
17634 +
17635 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17636 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17637 + pax_close_kernel();
17638 + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
17639 +
17640 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17641 + if (static_cpu_has(X86_FEATURE_PCID)) {
17642 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17643 + u64 descriptor[2];
17644 + descriptor[0] = PCID_USER;
17645 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17646 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17647 + descriptor[0] = PCID_KERNEL;
17648 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17649 + }
17650 + } else {
17651 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17652 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17653 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17654 + else
17655 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17656 + }
17657 + } else
17658 +#endif
17659 +
17660 + load_cr3(get_cpu_pgd(cpu, kernel));
17661 +#else
17662 load_cr3(next->pgd);
17663 +#endif
17664
17665 /* Stop flush ipis for the previous mm */
17666 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17667 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17668 /* Load the LDT, if the LDT is different: */
17669 if (unlikely(prev->context.ldt != next->context.ldt))
17670 load_LDT_nolock(&next->context);
17671 +
17672 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17673 + if (!(__supported_pte_mask & _PAGE_NX)) {
17674 + smp_mb__before_atomic();
17675 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17676 + smp_mb__after_atomic();
17677 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17678 + }
17679 +#endif
17680 +
17681 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17682 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17683 + prev->context.user_cs_limit != next->context.user_cs_limit))
17684 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17685 +#ifdef CONFIG_SMP
17686 + else if (unlikely(tlbstate != TLBSTATE_OK))
17687 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17688 +#endif
17689 +#endif
17690 +
17691 }
17692 + else {
17693 +
17694 +#ifdef CONFIG_PAX_PER_CPU_PGD
17695 + pax_open_kernel();
17696 +
17697 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17698 + if (static_cpu_has(X86_FEATURE_PCID))
17699 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17700 + else
17701 +#endif
17702 +
17703 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17704 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17705 + pax_close_kernel();
17706 + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
17707 +
17708 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17709 + if (static_cpu_has(X86_FEATURE_PCID)) {
17710 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17711 + u64 descriptor[2];
17712 + descriptor[0] = PCID_USER;
17713 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17714 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17715 + descriptor[0] = PCID_KERNEL;
17716 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17717 + }
17718 + } else {
17719 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17720 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17721 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17722 + else
17723 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17724 + }
17725 + } else
17726 +#endif
17727 +
17728 + load_cr3(get_cpu_pgd(cpu, kernel));
17729 +#endif
17730 +
17731 #ifdef CONFIG_SMP
17732 - else {
17733 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17734 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17735
17736 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17737 * tlb flush IPI delivery. We must reload CR3
17738 * to make sure to use no freed page tables.
17739 */
17740 +
17741 +#ifndef CONFIG_PAX_PER_CPU_PGD
17742 load_cr3(next->pgd);
17743 +#endif
17744 +
17745 load_LDT_nolock(&next->context);
17746 +
17747 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17748 + if (!(__supported_pte_mask & _PAGE_NX))
17749 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17750 +#endif
17751 +
17752 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17753 +#ifdef CONFIG_PAX_PAGEEXEC
17754 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17755 +#endif
17756 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17757 +#endif
17758 +
17759 }
17760 +#endif
17761 }
17762 -#endif
17763 }
17764
17765 #define activate_mm(prev, next) \
17766 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17767 index e3b7819..b257c64 100644
17768 --- a/arch/x86/include/asm/module.h
17769 +++ b/arch/x86/include/asm/module.h
17770 @@ -5,6 +5,7 @@
17771
17772 #ifdef CONFIG_X86_64
17773 /* X86_64 does not define MODULE_PROC_FAMILY */
17774 +#define MODULE_PROC_FAMILY ""
17775 #elif defined CONFIG_M486
17776 #define MODULE_PROC_FAMILY "486 "
17777 #elif defined CONFIG_M586
17778 @@ -57,8 +58,20 @@
17779 #error unknown processor family
17780 #endif
17781
17782 -#ifdef CONFIG_X86_32
17783 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17784 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17785 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17786 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17787 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17788 +#else
17789 +#define MODULE_PAX_KERNEXEC ""
17790 #endif
17791
17792 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17793 +#define MODULE_PAX_UDEREF "UDEREF "
17794 +#else
17795 +#define MODULE_PAX_UDEREF ""
17796 +#endif
17797 +
17798 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17799 +
17800 #endif /* _ASM_X86_MODULE_H */
17801 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17802 index 5f2fc44..106caa6 100644
17803 --- a/arch/x86/include/asm/nmi.h
17804 +++ b/arch/x86/include/asm/nmi.h
17805 @@ -36,26 +36,35 @@ enum {
17806
17807 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17808
17809 +struct nmiaction;
17810 +
17811 +struct nmiwork {
17812 + const struct nmiaction *action;
17813 + u64 max_duration;
17814 + struct irq_work irq_work;
17815 +};
17816 +
17817 struct nmiaction {
17818 struct list_head list;
17819 nmi_handler_t handler;
17820 - u64 max_duration;
17821 - struct irq_work irq_work;
17822 unsigned long flags;
17823 const char *name;
17824 -};
17825 + struct nmiwork *work;
17826 +} __do_const;
17827
17828 #define register_nmi_handler(t, fn, fg, n, init...) \
17829 ({ \
17830 - static struct nmiaction init fn##_na = { \
17831 + static struct nmiwork fn##_nw; \
17832 + static const struct nmiaction init fn##_na = { \
17833 .handler = (fn), \
17834 .name = (n), \
17835 .flags = (fg), \
17836 + .work = &fn##_nw, \
17837 }; \
17838 __register_nmi_handler((t), &fn##_na); \
17839 })
17840
17841 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17842 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17843
17844 void unregister_nmi_handler(unsigned int, const char *);
17845
17846 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17847 index 775873d..04cd306 100644
17848 --- a/arch/x86/include/asm/page.h
17849 +++ b/arch/x86/include/asm/page.h
17850 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17851 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17852
17853 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17854 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17855
17856 #define __boot_va(x) __va(x)
17857 #define __boot_pa(x) __pa(x)
17858 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17859 * virt_to_page(kaddr) returns a valid pointer if and only if
17860 * virt_addr_valid(kaddr) returns true.
17861 */
17862 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17863 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17864 extern bool __virt_addr_valid(unsigned long kaddr);
17865 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17866
17867 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17868 +#define virt_to_page(kaddr) \
17869 + ({ \
17870 + const void *__kaddr = (const void *)(kaddr); \
17871 + BUG_ON(!virt_addr_valid(__kaddr)); \
17872 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17873 + })
17874 +#else
17875 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17876 +#endif
17877 +
17878 #endif /* __ASSEMBLY__ */
17879
17880 #include <asm-generic/memory_model.h>
17881 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17882 index 0f1ddee..e2fc3d1 100644
17883 --- a/arch/x86/include/asm/page_64.h
17884 +++ b/arch/x86/include/asm/page_64.h
17885 @@ -7,9 +7,9 @@
17886
17887 /* duplicated to the one in bootmem.h */
17888 extern unsigned long max_pfn;
17889 -extern unsigned long phys_base;
17890 +extern const unsigned long phys_base;
17891
17892 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17893 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17894 {
17895 unsigned long y = x - __START_KERNEL_map;
17896
17897 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17898 index cd6e1610..70f4418 100644
17899 --- a/arch/x86/include/asm/paravirt.h
17900 +++ b/arch/x86/include/asm/paravirt.h
17901 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17902 return (pmd_t) { ret };
17903 }
17904
17905 -static inline pmdval_t pmd_val(pmd_t pmd)
17906 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17907 {
17908 pmdval_t ret;
17909
17910 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17911 val);
17912 }
17913
17914 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17915 +{
17916 + pgdval_t val = native_pgd_val(pgd);
17917 +
17918 + if (sizeof(pgdval_t) > sizeof(long))
17919 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17920 + val, (u64)val >> 32);
17921 + else
17922 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17923 + val);
17924 +}
17925 +
17926 static inline void pgd_clear(pgd_t *pgdp)
17927 {
17928 set_pgd(pgdp, __pgd(0));
17929 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17930 pv_mmu_ops.set_fixmap(idx, phys, flags);
17931 }
17932
17933 +#ifdef CONFIG_PAX_KERNEXEC
17934 +static inline unsigned long pax_open_kernel(void)
17935 +{
17936 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17937 +}
17938 +
17939 +static inline unsigned long pax_close_kernel(void)
17940 +{
17941 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17942 +}
17943 +#else
17944 +static inline unsigned long pax_open_kernel(void) { return 0; }
17945 +static inline unsigned long pax_close_kernel(void) { return 0; }
17946 +#endif
17947 +
17948 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17949
17950 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17951 @@ -906,7 +933,7 @@ extern void default_banner(void);
17952
17953 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17954 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17955 -#define PARA_INDIRECT(addr) *%cs:addr
17956 +#define PARA_INDIRECT(addr) *%ss:addr
17957 #endif
17958
17959 #define INTERRUPT_RETURN \
17960 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17961 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17962 CLBR_NONE, \
17963 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17964 +
17965 +#define GET_CR0_INTO_RDI \
17966 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17967 + mov %rax,%rdi
17968 +
17969 +#define SET_RDI_INTO_CR0 \
17970 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17971 +
17972 +#define GET_CR3_INTO_RDI \
17973 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17974 + mov %rax,%rdi
17975 +
17976 +#define SET_RDI_INTO_CR3 \
17977 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17978 +
17979 #endif /* CONFIG_X86_32 */
17980
17981 #endif /* __ASSEMBLY__ */
17982 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17983 index 7549b8b..f0edfda 100644
17984 --- a/arch/x86/include/asm/paravirt_types.h
17985 +++ b/arch/x86/include/asm/paravirt_types.h
17986 @@ -84,7 +84,7 @@ struct pv_init_ops {
17987 */
17988 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17989 unsigned long addr, unsigned len);
17990 -};
17991 +} __no_const __no_randomize_layout;
17992
17993
17994 struct pv_lazy_ops {
17995 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17996 void (*enter)(void);
17997 void (*leave)(void);
17998 void (*flush)(void);
17999 -};
18000 +} __no_randomize_layout;
18001
18002 struct pv_time_ops {
18003 unsigned long long (*sched_clock)(void);
18004 unsigned long long (*steal_clock)(int cpu);
18005 unsigned long (*get_tsc_khz)(void);
18006 -};
18007 +} __no_const __no_randomize_layout;
18008
18009 struct pv_cpu_ops {
18010 /* hooks for various privileged instructions */
18011 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
18012
18013 void (*start_context_switch)(struct task_struct *prev);
18014 void (*end_context_switch)(struct task_struct *next);
18015 -};
18016 +} __no_const __no_randomize_layout;
18017
18018 struct pv_irq_ops {
18019 /*
18020 @@ -215,7 +215,7 @@ struct pv_irq_ops {
18021 #ifdef CONFIG_X86_64
18022 void (*adjust_exception_frame)(void);
18023 #endif
18024 -};
18025 +} __no_randomize_layout;
18026
18027 struct pv_apic_ops {
18028 #ifdef CONFIG_X86_LOCAL_APIC
18029 @@ -223,7 +223,7 @@ struct pv_apic_ops {
18030 unsigned long start_eip,
18031 unsigned long start_esp);
18032 #endif
18033 -};
18034 +} __no_const __no_randomize_layout;
18035
18036 struct pv_mmu_ops {
18037 unsigned long (*read_cr2)(void);
18038 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
18039 struct paravirt_callee_save make_pud;
18040
18041 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
18042 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
18043 #endif /* PAGETABLE_LEVELS == 4 */
18044 #endif /* PAGETABLE_LEVELS >= 3 */
18045
18046 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
18047 an mfn. We can tell which is which from the index. */
18048 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
18049 phys_addr_t phys, pgprot_t flags);
18050 -};
18051 +
18052 +#ifdef CONFIG_PAX_KERNEXEC
18053 + unsigned long (*pax_open_kernel)(void);
18054 + unsigned long (*pax_close_kernel)(void);
18055 +#endif
18056 +
18057 +} __no_randomize_layout;
18058
18059 struct arch_spinlock;
18060 #ifdef CONFIG_SMP
18061 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
18062 struct pv_lock_ops {
18063 struct paravirt_callee_save lock_spinning;
18064 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
18065 -};
18066 +} __no_randomize_layout;
18067
18068 /* This contains all the paravirt structures: we get a convenient
18069 * number for each function using the offset which we use to indicate
18070 - * what to patch. */
18071 + * what to patch.
18072 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
18073 + */
18074 +
18075 struct paravirt_patch_template {
18076 struct pv_init_ops pv_init_ops;
18077 struct pv_time_ops pv_time_ops;
18078 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
18079 struct pv_apic_ops pv_apic_ops;
18080 struct pv_mmu_ops pv_mmu_ops;
18081 struct pv_lock_ops pv_lock_ops;
18082 -};
18083 +} __no_randomize_layout;
18084
18085 extern struct pv_info pv_info;
18086 extern struct pv_init_ops pv_init_ops;
18087 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
18088 index c4412e9..90e88c5 100644
18089 --- a/arch/x86/include/asm/pgalloc.h
18090 +++ b/arch/x86/include/asm/pgalloc.h
18091 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
18092 pmd_t *pmd, pte_t *pte)
18093 {
18094 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18095 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
18096 +}
18097 +
18098 +static inline void pmd_populate_user(struct mm_struct *mm,
18099 + pmd_t *pmd, pte_t *pte)
18100 +{
18101 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18102 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
18103 }
18104
18105 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
18106
18107 #ifdef CONFIG_X86_PAE
18108 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
18109 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18110 +{
18111 + pud_populate(mm, pudp, pmd);
18112 +}
18113 #else /* !CONFIG_X86_PAE */
18114 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18115 {
18116 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18117 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
18118 }
18119 +
18120 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18121 +{
18122 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18123 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
18124 +}
18125 #endif /* CONFIG_X86_PAE */
18126
18127 #if PAGETABLE_LEVELS > 3
18128 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18129 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
18130 }
18131
18132 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18133 +{
18134 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
18135 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
18136 +}
18137 +
18138 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
18139 {
18140 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
18141 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
18142 index 206a87f..1623b06 100644
18143 --- a/arch/x86/include/asm/pgtable-2level.h
18144 +++ b/arch/x86/include/asm/pgtable-2level.h
18145 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
18146
18147 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18148 {
18149 + pax_open_kernel();
18150 *pmdp = pmd;
18151 + pax_close_kernel();
18152 }
18153
18154 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18155 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18156 index 81bb91b..9392125 100644
18157 --- a/arch/x86/include/asm/pgtable-3level.h
18158 +++ b/arch/x86/include/asm/pgtable-3level.h
18159 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18160
18161 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18162 {
18163 + pax_open_kernel();
18164 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18165 + pax_close_kernel();
18166 }
18167
18168 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18169 {
18170 + pax_open_kernel();
18171 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18172 + pax_close_kernel();
18173 }
18174
18175 /*
18176 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18177 index aa97a07..f169e5b 100644
18178 --- a/arch/x86/include/asm/pgtable.h
18179 +++ b/arch/x86/include/asm/pgtable.h
18180 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18181
18182 #ifndef __PAGETABLE_PUD_FOLDED
18183 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18184 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18185 #define pgd_clear(pgd) native_pgd_clear(pgd)
18186 #endif
18187
18188 @@ -83,12 +84,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18189
18190 #define arch_end_context_switch(prev) do {} while(0)
18191
18192 +#define pax_open_kernel() native_pax_open_kernel()
18193 +#define pax_close_kernel() native_pax_close_kernel()
18194 #endif /* CONFIG_PARAVIRT */
18195
18196 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18197 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18198 +
18199 +#ifdef CONFIG_PAX_KERNEXEC
18200 +static inline unsigned long native_pax_open_kernel(void)
18201 +{
18202 + unsigned long cr0;
18203 +
18204 + preempt_disable();
18205 + barrier();
18206 + cr0 = read_cr0() ^ X86_CR0_WP;
18207 + BUG_ON(cr0 & X86_CR0_WP);
18208 + write_cr0(cr0);
18209 + return cr0 ^ X86_CR0_WP;
18210 +}
18211 +
18212 +static inline unsigned long native_pax_close_kernel(void)
18213 +{
18214 + unsigned long cr0;
18215 +
18216 + cr0 = read_cr0() ^ X86_CR0_WP;
18217 + BUG_ON(!(cr0 & X86_CR0_WP));
18218 + write_cr0(cr0);
18219 + barrier();
18220 + preempt_enable_no_resched();
18221 + return cr0 ^ X86_CR0_WP;
18222 +}
18223 +#else
18224 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18225 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18226 +#endif
18227 +
18228 /*
18229 * The following only work if pte_present() is true.
18230 * Undefined behaviour if not..
18231 */
18232 +static inline int pte_user(pte_t pte)
18233 +{
18234 + return pte_val(pte) & _PAGE_USER;
18235 +}
18236 +
18237 static inline int pte_dirty(pte_t pte)
18238 {
18239 return pte_flags(pte) & _PAGE_DIRTY;
18240 @@ -155,6 +195,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18241 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18242 }
18243
18244 +static inline unsigned long pgd_pfn(pgd_t pgd)
18245 +{
18246 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18247 +}
18248 +
18249 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18250
18251 static inline int pmd_large(pmd_t pte)
18252 @@ -208,9 +253,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18253 return pte_clear_flags(pte, _PAGE_RW);
18254 }
18255
18256 +static inline pte_t pte_mkread(pte_t pte)
18257 +{
18258 + return __pte(pte_val(pte) | _PAGE_USER);
18259 +}
18260 +
18261 static inline pte_t pte_mkexec(pte_t pte)
18262 {
18263 - return pte_clear_flags(pte, _PAGE_NX);
18264 +#ifdef CONFIG_X86_PAE
18265 + if (__supported_pte_mask & _PAGE_NX)
18266 + return pte_clear_flags(pte, _PAGE_NX);
18267 + else
18268 +#endif
18269 + return pte_set_flags(pte, _PAGE_USER);
18270 +}
18271 +
18272 +static inline pte_t pte_exprotect(pte_t pte)
18273 +{
18274 +#ifdef CONFIG_X86_PAE
18275 + if (__supported_pte_mask & _PAGE_NX)
18276 + return pte_set_flags(pte, _PAGE_NX);
18277 + else
18278 +#endif
18279 + return pte_clear_flags(pte, _PAGE_USER);
18280 }
18281
18282 static inline pte_t pte_mkdirty(pte_t pte)
18283 @@ -440,6 +505,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18284 #endif
18285
18286 #ifndef __ASSEMBLY__
18287 +
18288 +#ifdef CONFIG_PAX_PER_CPU_PGD
18289 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18290 +enum cpu_pgd_type {kernel = 0, user = 1};
18291 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18292 +{
18293 + return cpu_pgd[cpu][type];
18294 +}
18295 +#endif
18296 +
18297 #include <linux/mm_types.h>
18298 #include <linux/mmdebug.h>
18299 #include <linux/log2.h>
18300 @@ -586,7 +661,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18301 * Currently stuck as a macro due to indirect forward reference to
18302 * linux/mmzone.h's __section_mem_map_addr() definition:
18303 */
18304 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18305 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18306
18307 /* Find an entry in the second-level page table.. */
18308 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18309 @@ -626,7 +701,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18310 * Currently stuck as a macro due to indirect forward reference to
18311 * linux/mmzone.h's __section_mem_map_addr() definition:
18312 */
18313 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18314 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18315
18316 /* to find an entry in a page-table-directory. */
18317 static inline unsigned long pud_index(unsigned long address)
18318 @@ -641,7 +716,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18319
18320 static inline int pgd_bad(pgd_t pgd)
18321 {
18322 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18323 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18324 }
18325
18326 static inline int pgd_none(pgd_t pgd)
18327 @@ -664,7 +739,12 @@ static inline int pgd_none(pgd_t pgd)
18328 * pgd_offset() returns a (pgd_t *)
18329 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18330 */
18331 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18332 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18333 +
18334 +#ifdef CONFIG_PAX_PER_CPU_PGD
18335 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18336 +#endif
18337 +
18338 /*
18339 * a shortcut which implies the use of the kernel's pgd, instead
18340 * of a process's
18341 @@ -675,6 +755,23 @@ static inline int pgd_none(pgd_t pgd)
18342 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18343 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18344
18345 +#ifdef CONFIG_X86_32
18346 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18347 +#else
18348 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18349 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18350 +
18351 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18352 +#ifdef __ASSEMBLY__
18353 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18354 +#else
18355 +extern unsigned long pax_user_shadow_base;
18356 +extern pgdval_t clone_pgd_mask;
18357 +#endif
18358 +#endif
18359 +
18360 +#endif
18361 +
18362 #ifndef __ASSEMBLY__
18363
18364 extern int direct_gbpages;
18365 @@ -841,11 +938,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18366 * dst and src can be on the same page, but the range must not overlap,
18367 * and must not cross a page boundary.
18368 */
18369 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18370 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18371 {
18372 - memcpy(dst, src, count * sizeof(pgd_t));
18373 + pax_open_kernel();
18374 + while (count--)
18375 + *dst++ = *src++;
18376 + pax_close_kernel();
18377 }
18378
18379 +#ifdef CONFIG_PAX_PER_CPU_PGD
18380 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18381 +#endif
18382 +
18383 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18384 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18385 +#else
18386 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18387 +#endif
18388 +
18389 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18390 static inline int page_level_shift(enum pg_level level)
18391 {
18392 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18393 index 9ee3221..b979c6b 100644
18394 --- a/arch/x86/include/asm/pgtable_32.h
18395 +++ b/arch/x86/include/asm/pgtable_32.h
18396 @@ -25,9 +25,6 @@
18397 struct mm_struct;
18398 struct vm_area_struct;
18399
18400 -extern pgd_t swapper_pg_dir[1024];
18401 -extern pgd_t initial_page_table[1024];
18402 -
18403 static inline void pgtable_cache_init(void) { }
18404 static inline void check_pgt_cache(void) { }
18405 void paging_init(void);
18406 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18407 # include <asm/pgtable-2level.h>
18408 #endif
18409
18410 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18411 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18412 +#ifdef CONFIG_X86_PAE
18413 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18414 +#endif
18415 +
18416 #if defined(CONFIG_HIGHPTE)
18417 #define pte_offset_map(dir, address) \
18418 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18419 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18420 /* Clear a kernel PTE and flush it from the TLB */
18421 #define kpte_clear_flush(ptep, vaddr) \
18422 do { \
18423 + pax_open_kernel(); \
18424 pte_clear(&init_mm, (vaddr), (ptep)); \
18425 + pax_close_kernel(); \
18426 __flush_tlb_one((vaddr)); \
18427 } while (0)
18428
18429 #endif /* !__ASSEMBLY__ */
18430
18431 +#define HAVE_ARCH_UNMAPPED_AREA
18432 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18433 +
18434 /*
18435 * kern_addr_valid() is (1) for FLATMEM and (0) for
18436 * SPARSEMEM and DISCONTIGMEM
18437 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18438 index ed5903b..c7fe163 100644
18439 --- a/arch/x86/include/asm/pgtable_32_types.h
18440 +++ b/arch/x86/include/asm/pgtable_32_types.h
18441 @@ -8,7 +8,7 @@
18442 */
18443 #ifdef CONFIG_X86_PAE
18444 # include <asm/pgtable-3level_types.h>
18445 -# define PMD_SIZE (1UL << PMD_SHIFT)
18446 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18447 # define PMD_MASK (~(PMD_SIZE - 1))
18448 #else
18449 # include <asm/pgtable-2level_types.h>
18450 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18451 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18452 #endif
18453
18454 +#ifdef CONFIG_PAX_KERNEXEC
18455 +#ifndef __ASSEMBLY__
18456 +extern unsigned char MODULES_EXEC_VADDR[];
18457 +extern unsigned char MODULES_EXEC_END[];
18458 +#endif
18459 +#include <asm/boot.h>
18460 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18461 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18462 +#else
18463 +#define ktla_ktva(addr) (addr)
18464 +#define ktva_ktla(addr) (addr)
18465 +#endif
18466 +
18467 #define MODULES_VADDR VMALLOC_START
18468 #define MODULES_END VMALLOC_END
18469 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18470 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18471 index 5be9063..d62185b 100644
18472 --- a/arch/x86/include/asm/pgtable_64.h
18473 +++ b/arch/x86/include/asm/pgtable_64.h
18474 @@ -16,10 +16,14 @@
18475
18476 extern pud_t level3_kernel_pgt[512];
18477 extern pud_t level3_ident_pgt[512];
18478 +extern pud_t level3_vmalloc_start_pgt[512];
18479 +extern pud_t level3_vmalloc_end_pgt[512];
18480 +extern pud_t level3_vmemmap_pgt[512];
18481 +extern pud_t level2_vmemmap_pgt[512];
18482 extern pmd_t level2_kernel_pgt[512];
18483 extern pmd_t level2_fixmap_pgt[512];
18484 -extern pmd_t level2_ident_pgt[512];
18485 -extern pgd_t init_level4_pgt[];
18486 +extern pmd_t level2_ident_pgt[512*2];
18487 +extern pgd_t init_level4_pgt[512];
18488
18489 #define swapper_pg_dir init_level4_pgt
18490
18491 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18492
18493 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18494 {
18495 + pax_open_kernel();
18496 *pmdp = pmd;
18497 + pax_close_kernel();
18498 }
18499
18500 static inline void native_pmd_clear(pmd_t *pmd)
18501 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18502
18503 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18504 {
18505 + pax_open_kernel();
18506 *pudp = pud;
18507 + pax_close_kernel();
18508 }
18509
18510 static inline void native_pud_clear(pud_t *pud)
18511 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18512
18513 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18514 {
18515 + pax_open_kernel();
18516 + *pgdp = pgd;
18517 + pax_close_kernel();
18518 +}
18519 +
18520 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18521 +{
18522 *pgdp = pgd;
18523 }
18524
18525 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18526 index 7166e25..baaa6fe 100644
18527 --- a/arch/x86/include/asm/pgtable_64_types.h
18528 +++ b/arch/x86/include/asm/pgtable_64_types.h
18529 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18530 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18531 #define MODULES_END _AC(0xffffffffff000000, UL)
18532 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18533 +#define MODULES_EXEC_VADDR MODULES_VADDR
18534 +#define MODULES_EXEC_END MODULES_END
18535 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18536 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18537
18538 +#define ktla_ktva(addr) (addr)
18539 +#define ktva_ktla(addr) (addr)
18540 +
18541 #define EARLY_DYNAMIC_PAGE_TABLES 64
18542
18543 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18544 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18545 index f216963..6bd7c21 100644
18546 --- a/arch/x86/include/asm/pgtable_types.h
18547 +++ b/arch/x86/include/asm/pgtable_types.h
18548 @@ -111,8 +111,10 @@
18549
18550 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18551 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18552 -#else
18553 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18554 #define _PAGE_NX (_AT(pteval_t, 0))
18555 +#else
18556 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18557 #endif
18558
18559 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18560 @@ -151,6 +153,9 @@
18561 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18562 _PAGE_ACCESSED)
18563
18564 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18565 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18566 +
18567 #define __PAGE_KERNEL_EXEC \
18568 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18569 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18570 @@ -161,7 +166,7 @@
18571 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18572 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18573 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18574 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18575 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18576 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18577 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18578 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18579 @@ -218,7 +223,7 @@
18580 #ifdef CONFIG_X86_64
18581 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18582 #else
18583 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18584 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18585 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18586 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18587 #endif
18588 @@ -257,7 +262,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18589 {
18590 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18591 }
18592 +#endif
18593
18594 +#if PAGETABLE_LEVELS == 3
18595 +#include <asm-generic/pgtable-nopud.h>
18596 +#endif
18597 +
18598 +#if PAGETABLE_LEVELS == 2
18599 +#include <asm-generic/pgtable-nopmd.h>
18600 +#endif
18601 +
18602 +#ifndef __ASSEMBLY__
18603 #if PAGETABLE_LEVELS > 3
18604 typedef struct { pudval_t pud; } pud_t;
18605
18606 @@ -271,8 +286,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18607 return pud.pud;
18608 }
18609 #else
18610 -#include <asm-generic/pgtable-nopud.h>
18611 -
18612 static inline pudval_t native_pud_val(pud_t pud)
18613 {
18614 return native_pgd_val(pud.pgd);
18615 @@ -292,8 +305,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18616 return pmd.pmd;
18617 }
18618 #else
18619 -#include <asm-generic/pgtable-nopmd.h>
18620 -
18621 static inline pmdval_t native_pmd_val(pmd_t pmd)
18622 {
18623 return native_pgd_val(pmd.pud.pgd);
18624 @@ -333,7 +344,6 @@ typedef struct page *pgtable_t;
18625
18626 extern pteval_t __supported_pte_mask;
18627 extern void set_nx(void);
18628 -extern int nx_enabled;
18629
18630 #define pgprot_writecombine pgprot_writecombine
18631 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18632 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18633 index 7024c12..71c46b9 100644
18634 --- a/arch/x86/include/asm/preempt.h
18635 +++ b/arch/x86/include/asm/preempt.h
18636 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18637 */
18638 static __always_inline bool __preempt_count_dec_and_test(void)
18639 {
18640 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18641 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18642 }
18643
18644 /*
18645 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18646 index a4ea023..33aa874 100644
18647 --- a/arch/x86/include/asm/processor.h
18648 +++ b/arch/x86/include/asm/processor.h
18649 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18650 /* Index into per_cpu list: */
18651 u16 cpu_index;
18652 u32 microcode;
18653 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18654 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18655
18656 #define X86_VENDOR_INTEL 0
18657 #define X86_VENDOR_CYRIX 1
18658 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18659 : "memory");
18660 }
18661
18662 +/* invpcid (%rdx),%rax */
18663 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18664 +
18665 +#define INVPCID_SINGLE_ADDRESS 0UL
18666 +#define INVPCID_SINGLE_CONTEXT 1UL
18667 +#define INVPCID_ALL_GLOBAL 2UL
18668 +#define INVPCID_ALL_MONGLOBAL 3UL
18669 +
18670 +#define PCID_KERNEL 0UL
18671 +#define PCID_USER 1UL
18672 +#define PCID_NOFLUSH (1UL << 63)
18673 +
18674 static inline void load_cr3(pgd_t *pgdir)
18675 {
18676 - write_cr3(__pa(pgdir));
18677 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18678 }
18679
18680 #ifdef CONFIG_X86_32
18681 @@ -283,7 +295,7 @@ struct tss_struct {
18682
18683 } ____cacheline_aligned;
18684
18685 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18686 +extern struct tss_struct init_tss[NR_CPUS];
18687
18688 /*
18689 * Save the original ist values for checking stack pointers during debugging
18690 @@ -479,6 +491,7 @@ struct thread_struct {
18691 unsigned short ds;
18692 unsigned short fsindex;
18693 unsigned short gsindex;
18694 + unsigned short ss;
18695 #endif
18696 #ifdef CONFIG_X86_32
18697 unsigned long ip;
18698 @@ -588,29 +601,8 @@ static inline void load_sp0(struct tss_struct *tss,
18699 extern unsigned long mmu_cr4_features;
18700 extern u32 *trampoline_cr4_features;
18701
18702 -static inline void set_in_cr4(unsigned long mask)
18703 -{
18704 - unsigned long cr4;
18705 -
18706 - mmu_cr4_features |= mask;
18707 - if (trampoline_cr4_features)
18708 - *trampoline_cr4_features = mmu_cr4_features;
18709 - cr4 = read_cr4();
18710 - cr4 |= mask;
18711 - write_cr4(cr4);
18712 -}
18713 -
18714 -static inline void clear_in_cr4(unsigned long mask)
18715 -{
18716 - unsigned long cr4;
18717 -
18718 - mmu_cr4_features &= ~mask;
18719 - if (trampoline_cr4_features)
18720 - *trampoline_cr4_features = mmu_cr4_features;
18721 - cr4 = read_cr4();
18722 - cr4 &= ~mask;
18723 - write_cr4(cr4);
18724 -}
18725 +extern void set_in_cr4(unsigned long mask);
18726 +extern void clear_in_cr4(unsigned long mask);
18727
18728 typedef struct {
18729 unsigned long seg;
18730 @@ -836,11 +828,18 @@ static inline void spin_lock_prefetch(const void *x)
18731 */
18732 #define TASK_SIZE PAGE_OFFSET
18733 #define TASK_SIZE_MAX TASK_SIZE
18734 +
18735 +#ifdef CONFIG_PAX_SEGMEXEC
18736 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18737 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18738 +#else
18739 #define STACK_TOP TASK_SIZE
18740 -#define STACK_TOP_MAX STACK_TOP
18741 +#endif
18742 +
18743 +#define STACK_TOP_MAX TASK_SIZE
18744
18745 #define INIT_THREAD { \
18746 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18747 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18748 .vm86_info = NULL, \
18749 .sysenter_cs = __KERNEL_CS, \
18750 .io_bitmap_ptr = NULL, \
18751 @@ -854,7 +853,7 @@ static inline void spin_lock_prefetch(const void *x)
18752 */
18753 #define INIT_TSS { \
18754 .x86_tss = { \
18755 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18756 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18757 .ss0 = __KERNEL_DS, \
18758 .ss1 = __KERNEL_CS, \
18759 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18760 @@ -865,11 +864,7 @@ static inline void spin_lock_prefetch(const void *x)
18761 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18762
18763 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18764 -#define KSTK_TOP(info) \
18765 -({ \
18766 - unsigned long *__ptr = (unsigned long *)(info); \
18767 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18768 -})
18769 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18770
18771 /*
18772 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18773 @@ -884,7 +879,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18774 #define task_pt_regs(task) \
18775 ({ \
18776 struct pt_regs *__regs__; \
18777 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18778 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18779 __regs__ - 1; \
18780 })
18781
18782 @@ -894,13 +889,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18783 /*
18784 * User space process size. 47bits minus one guard page.
18785 */
18786 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18787 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18788
18789 /* This decides where the kernel will search for a free chunk of vm
18790 * space during mmap's.
18791 */
18792 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18793 - 0xc0000000 : 0xFFFFe000)
18794 + 0xc0000000 : 0xFFFFf000)
18795
18796 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18797 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18798 @@ -911,11 +906,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18799 #define STACK_TOP_MAX TASK_SIZE_MAX
18800
18801 #define INIT_THREAD { \
18802 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18803 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18804 }
18805
18806 #define INIT_TSS { \
18807 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18808 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18809 }
18810
18811 /*
18812 @@ -943,6 +938,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18813 */
18814 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18815
18816 +#ifdef CONFIG_PAX_SEGMEXEC
18817 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18818 +#endif
18819 +
18820 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18821
18822 /* Get/set a process' ability to use the timestamp counter instruction */
18823 @@ -969,7 +968,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18824 return 0;
18825 }
18826
18827 -extern unsigned long arch_align_stack(unsigned long sp);
18828 +#define arch_align_stack(x) ((x) & ~0xfUL)
18829 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18830
18831 void default_idle(void);
18832 @@ -979,6 +978,6 @@ bool xen_set_default_idle(void);
18833 #define xen_set_default_idle 0
18834 #endif
18835
18836 -void stop_this_cpu(void *dummy);
18837 +void stop_this_cpu(void *dummy) __noreturn;
18838 void df_debug(struct pt_regs *regs, long error_code);
18839 #endif /* _ASM_X86_PROCESSOR_H */
18840 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18841 index 6205f0c..688a3a9 100644
18842 --- a/arch/x86/include/asm/ptrace.h
18843 +++ b/arch/x86/include/asm/ptrace.h
18844 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18845 }
18846
18847 /*
18848 - * user_mode_vm(regs) determines whether a register set came from user mode.
18849 + * user_mode(regs) determines whether a register set came from user mode.
18850 * This is true if V8086 mode was enabled OR if the register set was from
18851 * protected mode with RPL-3 CS value. This tricky test checks that with
18852 * one comparison. Many places in the kernel can bypass this full check
18853 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18854 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18855 + * be used.
18856 */
18857 -static inline int user_mode(struct pt_regs *regs)
18858 +static inline int user_mode_novm(struct pt_regs *regs)
18859 {
18860 #ifdef CONFIG_X86_32
18861 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18862 #else
18863 - return !!(regs->cs & 3);
18864 + return !!(regs->cs & SEGMENT_RPL_MASK);
18865 #endif
18866 }
18867
18868 -static inline int user_mode_vm(struct pt_regs *regs)
18869 +static inline int user_mode(struct pt_regs *regs)
18870 {
18871 #ifdef CONFIG_X86_32
18872 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18873 USER_RPL;
18874 #else
18875 - return user_mode(regs);
18876 + return user_mode_novm(regs);
18877 #endif
18878 }
18879
18880 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18881 #ifdef CONFIG_X86_64
18882 static inline bool user_64bit_mode(struct pt_regs *regs)
18883 {
18884 + unsigned long cs = regs->cs & 0xffff;
18885 #ifndef CONFIG_PARAVIRT
18886 /*
18887 * On non-paravirt systems, this is the only long mode CPL 3
18888 * selector. We do not allow long mode selectors in the LDT.
18889 */
18890 - return regs->cs == __USER_CS;
18891 + return cs == __USER_CS;
18892 #else
18893 /* Headers are too twisted for this to go in paravirt.h. */
18894 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18895 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18896 #endif
18897 }
18898
18899 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18900 * Traps from the kernel do not save sp and ss.
18901 * Use the helper function to retrieve sp.
18902 */
18903 - if (offset == offsetof(struct pt_regs, sp) &&
18904 - regs->cs == __KERNEL_CS)
18905 - return kernel_stack_pointer(regs);
18906 + if (offset == offsetof(struct pt_regs, sp)) {
18907 + unsigned long cs = regs->cs & 0xffff;
18908 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18909 + return kernel_stack_pointer(regs);
18910 + }
18911 #endif
18912 return *(unsigned long *)((unsigned long)regs + offset);
18913 }
18914 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18915 index 70f46f0..adfbdb4 100644
18916 --- a/arch/x86/include/asm/qrwlock.h
18917 +++ b/arch/x86/include/asm/qrwlock.h
18918 @@ -7,8 +7,8 @@
18919 #define queue_write_unlock queue_write_unlock
18920 static inline void queue_write_unlock(struct qrwlock *lock)
18921 {
18922 - barrier();
18923 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18924 + barrier();
18925 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18926 }
18927 #endif
18928
18929 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18930 index 9c6b890..5305f53 100644
18931 --- a/arch/x86/include/asm/realmode.h
18932 +++ b/arch/x86/include/asm/realmode.h
18933 @@ -22,16 +22,14 @@ struct real_mode_header {
18934 #endif
18935 /* APM/BIOS reboot */
18936 u32 machine_real_restart_asm;
18937 -#ifdef CONFIG_X86_64
18938 u32 machine_real_restart_seg;
18939 -#endif
18940 };
18941
18942 /* This must match data at trampoline_32/64.S */
18943 struct trampoline_header {
18944 #ifdef CONFIG_X86_32
18945 u32 start;
18946 - u16 gdt_pad;
18947 + u16 boot_cs;
18948 u16 gdt_limit;
18949 u32 gdt_base;
18950 #else
18951 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18952 index a82c4f1..ac45053 100644
18953 --- a/arch/x86/include/asm/reboot.h
18954 +++ b/arch/x86/include/asm/reboot.h
18955 @@ -6,13 +6,13 @@
18956 struct pt_regs;
18957
18958 struct machine_ops {
18959 - void (*restart)(char *cmd);
18960 - void (*halt)(void);
18961 - void (*power_off)(void);
18962 + void (* __noreturn restart)(char *cmd);
18963 + void (* __noreturn halt)(void);
18964 + void (* __noreturn power_off)(void);
18965 void (*shutdown)(void);
18966 void (*crash_shutdown)(struct pt_regs *);
18967 - void (*emergency_restart)(void);
18968 -};
18969 + void (* __noreturn emergency_restart)(void);
18970 +} __no_const;
18971
18972 extern struct machine_ops machine_ops;
18973
18974 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18975 index 8f7866a..e442f20 100644
18976 --- a/arch/x86/include/asm/rmwcc.h
18977 +++ b/arch/x86/include/asm/rmwcc.h
18978 @@ -3,7 +3,34 @@
18979
18980 #ifdef CC_HAVE_ASM_GOTO
18981
18982 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18983 +#ifdef CONFIG_PAX_REFCOUNT
18984 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18985 +do { \
18986 + asm_volatile_goto (fullop \
18987 + ";jno 0f\n" \
18988 + fullantiop \
18989 + ";int $4\n0:\n" \
18990 + _ASM_EXTABLE(0b, 0b) \
18991 + ";j" cc " %l[cc_label]" \
18992 + : : "m" (var), ## __VA_ARGS__ \
18993 + : "memory" : cc_label); \
18994 + return 0; \
18995 +cc_label: \
18996 + return 1; \
18997 +} while (0)
18998 +#else
18999 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19000 +do { \
19001 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
19002 + : : "m" (var), ## __VA_ARGS__ \
19003 + : "memory" : cc_label); \
19004 + return 0; \
19005 +cc_label: \
19006 + return 1; \
19007 +} while (0)
19008 +#endif
19009 +
19010 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19011 do { \
19012 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
19013 : : "m" (var), ## __VA_ARGS__ \
19014 @@ -13,15 +40,46 @@ cc_label: \
19015 return 1; \
19016 } while (0)
19017
19018 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19019 - __GEN_RMWcc(op " " arg0, var, cc)
19020 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19021 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19022
19023 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19024 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
19025 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19026 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19027 +
19028 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19029 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
19030 +
19031 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19032 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
19033
19034 #else /* !CC_HAVE_ASM_GOTO */
19035
19036 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19037 +#ifdef CONFIG_PAX_REFCOUNT
19038 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19039 +do { \
19040 + char c; \
19041 + asm volatile (fullop \
19042 + ";jno 0f\n" \
19043 + fullantiop \
19044 + ";int $4\n0:\n" \
19045 + _ASM_EXTABLE(0b, 0b) \
19046 + "; set" cc " %1" \
19047 + : "+m" (var), "=qm" (c) \
19048 + : __VA_ARGS__ : "memory"); \
19049 + return c != 0; \
19050 +} while (0)
19051 +#else
19052 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19053 +do { \
19054 + char c; \
19055 + asm volatile (fullop "; set" cc " %1" \
19056 + : "+m" (var), "=qm" (c) \
19057 + : __VA_ARGS__ : "memory"); \
19058 + return c != 0; \
19059 +} while (0)
19060 +#endif
19061 +
19062 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19063 do { \
19064 char c; \
19065 asm volatile (fullop "; set" cc " %1" \
19066 @@ -30,11 +88,17 @@ do { \
19067 return c != 0; \
19068 } while (0)
19069
19070 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19071 - __GEN_RMWcc(op " " arg0, var, cc)
19072 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19073 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19074 +
19075 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19076 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19077 +
19078 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19079 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
19080
19081 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19082 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
19083 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19084 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
19085
19086 #endif /* CC_HAVE_ASM_GOTO */
19087
19088 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
19089 index cad82c9..2e5c5c1 100644
19090 --- a/arch/x86/include/asm/rwsem.h
19091 +++ b/arch/x86/include/asm/rwsem.h
19092 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
19093 {
19094 asm volatile("# beginning down_read\n\t"
19095 LOCK_PREFIX _ASM_INC "(%1)\n\t"
19096 +
19097 +#ifdef CONFIG_PAX_REFCOUNT
19098 + "jno 0f\n"
19099 + LOCK_PREFIX _ASM_DEC "(%1)\n"
19100 + "int $4\n0:\n"
19101 + _ASM_EXTABLE(0b, 0b)
19102 +#endif
19103 +
19104 /* adds 0x00000001 */
19105 " jns 1f\n"
19106 " call call_rwsem_down_read_failed\n"
19107 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
19108 "1:\n\t"
19109 " mov %1,%2\n\t"
19110 " add %3,%2\n\t"
19111 +
19112 +#ifdef CONFIG_PAX_REFCOUNT
19113 + "jno 0f\n"
19114 + "sub %3,%2\n"
19115 + "int $4\n0:\n"
19116 + _ASM_EXTABLE(0b, 0b)
19117 +#endif
19118 +
19119 " jle 2f\n\t"
19120 LOCK_PREFIX " cmpxchg %2,%0\n\t"
19121 " jnz 1b\n\t"
19122 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
19123 long tmp;
19124 asm volatile("# beginning down_write\n\t"
19125 LOCK_PREFIX " xadd %1,(%2)\n\t"
19126 +
19127 +#ifdef CONFIG_PAX_REFCOUNT
19128 + "jno 0f\n"
19129 + "mov %1,(%2)\n"
19130 + "int $4\n0:\n"
19131 + _ASM_EXTABLE(0b, 0b)
19132 +#endif
19133 +
19134 /* adds 0xffff0001, returns the old value */
19135 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
19136 /* was the active mask 0 before? */
19137 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
19138 long tmp;
19139 asm volatile("# beginning __up_read\n\t"
19140 LOCK_PREFIX " xadd %1,(%2)\n\t"
19141 +
19142 +#ifdef CONFIG_PAX_REFCOUNT
19143 + "jno 0f\n"
19144 + "mov %1,(%2)\n"
19145 + "int $4\n0:\n"
19146 + _ASM_EXTABLE(0b, 0b)
19147 +#endif
19148 +
19149 /* subtracts 1, returns the old value */
19150 " jns 1f\n\t"
19151 " call call_rwsem_wake\n" /* expects old value in %edx */
19152 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19153 long tmp;
19154 asm volatile("# beginning __up_write\n\t"
19155 LOCK_PREFIX " xadd %1,(%2)\n\t"
19156 +
19157 +#ifdef CONFIG_PAX_REFCOUNT
19158 + "jno 0f\n"
19159 + "mov %1,(%2)\n"
19160 + "int $4\n0:\n"
19161 + _ASM_EXTABLE(0b, 0b)
19162 +#endif
19163 +
19164 /* subtracts 0xffff0001, returns the old value */
19165 " jns 1f\n\t"
19166 " call call_rwsem_wake\n" /* expects old value in %edx */
19167 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19168 {
19169 asm volatile("# beginning __downgrade_write\n\t"
19170 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19171 +
19172 +#ifdef CONFIG_PAX_REFCOUNT
19173 + "jno 0f\n"
19174 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19175 + "int $4\n0:\n"
19176 + _ASM_EXTABLE(0b, 0b)
19177 +#endif
19178 +
19179 /*
19180 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19181 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19182 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19183 */
19184 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19185 {
19186 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19187 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19188 +
19189 +#ifdef CONFIG_PAX_REFCOUNT
19190 + "jno 0f\n"
19191 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19192 + "int $4\n0:\n"
19193 + _ASM_EXTABLE(0b, 0b)
19194 +#endif
19195 +
19196 : "+m" (sem->count)
19197 : "er" (delta));
19198 }
19199 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19200 */
19201 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19202 {
19203 - return delta + xadd(&sem->count, delta);
19204 + return delta + xadd_check_overflow(&sem->count, delta);
19205 }
19206
19207 #endif /* __KERNEL__ */
19208 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19209 index 6f1c3a8..7744f19 100644
19210 --- a/arch/x86/include/asm/segment.h
19211 +++ b/arch/x86/include/asm/segment.h
19212 @@ -64,10 +64,15 @@
19213 * 26 - ESPFIX small SS
19214 * 27 - per-cpu [ offset to per-cpu data area ]
19215 * 28 - stack_canary-20 [ for stack protector ]
19216 - * 29 - unused
19217 - * 30 - unused
19218 + * 29 - PCI BIOS CS
19219 + * 30 - PCI BIOS DS
19220 * 31 - TSS for double fault handler
19221 */
19222 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19223 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19224 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19225 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19226 +
19227 #define GDT_ENTRY_TLS_MIN 6
19228 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19229
19230 @@ -79,6 +84,8 @@
19231
19232 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19233
19234 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19235 +
19236 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19237
19238 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19239 @@ -104,6 +111,12 @@
19240 #define __KERNEL_STACK_CANARY 0
19241 #endif
19242
19243 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19244 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19245 +
19246 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19247 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19248 +
19249 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19250
19251 /*
19252 @@ -141,7 +154,7 @@
19253 */
19254
19255 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19256 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19257 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19258
19259
19260 #else
19261 @@ -165,6 +178,8 @@
19262 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19263 #define __USER32_DS __USER_DS
19264
19265 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19266 +
19267 #define GDT_ENTRY_TSS 8 /* needs two entries */
19268 #define GDT_ENTRY_LDT 10 /* needs two entries */
19269 #define GDT_ENTRY_TLS_MIN 12
19270 @@ -173,6 +188,8 @@
19271 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19272 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19273
19274 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19275 +
19276 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19277 #define FS_TLS 0
19278 #define GS_TLS 1
19279 @@ -180,12 +197,14 @@
19280 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19281 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19282
19283 -#define GDT_ENTRIES 16
19284 +#define GDT_ENTRIES 17
19285
19286 #endif
19287
19288 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19289 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19290 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19291 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19292 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19293 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19294 #ifndef CONFIG_PARAVIRT
19295 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19296 {
19297 unsigned long __limit;
19298 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19299 - return __limit + 1;
19300 + return __limit;
19301 }
19302
19303 #endif /* !__ASSEMBLY__ */
19304 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19305 index 8d3120f..352b440 100644
19306 --- a/arch/x86/include/asm/smap.h
19307 +++ b/arch/x86/include/asm/smap.h
19308 @@ -25,11 +25,40 @@
19309
19310 #include <asm/alternative-asm.h>
19311
19312 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19313 +#define ASM_PAX_OPEN_USERLAND \
19314 + 661: jmp 663f; \
19315 + .pushsection .altinstr_replacement, "a" ; \
19316 + 662: pushq %rax; nop; \
19317 + .popsection ; \
19318 + .pushsection .altinstructions, "a" ; \
19319 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19320 + .popsection ; \
19321 + call __pax_open_userland; \
19322 + popq %rax; \
19323 + 663:
19324 +
19325 +#define ASM_PAX_CLOSE_USERLAND \
19326 + 661: jmp 663f; \
19327 + .pushsection .altinstr_replacement, "a" ; \
19328 + 662: pushq %rax; nop; \
19329 + .popsection; \
19330 + .pushsection .altinstructions, "a" ; \
19331 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19332 + .popsection; \
19333 + call __pax_close_userland; \
19334 + popq %rax; \
19335 + 663:
19336 +#else
19337 +#define ASM_PAX_OPEN_USERLAND
19338 +#define ASM_PAX_CLOSE_USERLAND
19339 +#endif
19340 +
19341 #ifdef CONFIG_X86_SMAP
19342
19343 #define ASM_CLAC \
19344 661: ASM_NOP3 ; \
19345 - .pushsection .altinstr_replacement, "ax" ; \
19346 + .pushsection .altinstr_replacement, "a" ; \
19347 662: __ASM_CLAC ; \
19348 .popsection ; \
19349 .pushsection .altinstructions, "a" ; \
19350 @@ -38,7 +67,7 @@
19351
19352 #define ASM_STAC \
19353 661: ASM_NOP3 ; \
19354 - .pushsection .altinstr_replacement, "ax" ; \
19355 + .pushsection .altinstr_replacement, "a" ; \
19356 662: __ASM_STAC ; \
19357 .popsection ; \
19358 .pushsection .altinstructions, "a" ; \
19359 @@ -56,6 +85,37 @@
19360
19361 #include <asm/alternative.h>
19362
19363 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19364 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19365 +
19366 +extern void __pax_open_userland(void);
19367 +static __always_inline unsigned long pax_open_userland(void)
19368 +{
19369 +
19370 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19371 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19372 + :
19373 + : [open] "i" (__pax_open_userland)
19374 + : "memory", "rax");
19375 +#endif
19376 +
19377 + return 0;
19378 +}
19379 +
19380 +extern void __pax_close_userland(void);
19381 +static __always_inline unsigned long pax_close_userland(void)
19382 +{
19383 +
19384 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19385 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19386 + :
19387 + : [close] "i" (__pax_close_userland)
19388 + : "memory", "rax");
19389 +#endif
19390 +
19391 + return 0;
19392 +}
19393 +
19394 #ifdef CONFIG_X86_SMAP
19395
19396 static __always_inline void clac(void)
19397 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19398 index 8cd27e0..7f05ec8 100644
19399 --- a/arch/x86/include/asm/smp.h
19400 +++ b/arch/x86/include/asm/smp.h
19401 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19402 /* cpus sharing the last level cache: */
19403 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19404 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19405 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19406 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19407
19408 static inline struct cpumask *cpu_sibling_mask(int cpu)
19409 {
19410 @@ -78,7 +78,7 @@ struct smp_ops {
19411
19412 void (*send_call_func_ipi)(const struct cpumask *mask);
19413 void (*send_call_func_single_ipi)(int cpu);
19414 -};
19415 +} __no_const;
19416
19417 /* Globals due to paravirt */
19418 extern void set_cpu_sibling_map(int cpu);
19419 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19420 extern int safe_smp_processor_id(void);
19421
19422 #elif defined(CONFIG_X86_64_SMP)
19423 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19424 -
19425 -#define stack_smp_processor_id() \
19426 -({ \
19427 - struct thread_info *ti; \
19428 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19429 - ti->cpu; \
19430 -})
19431 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19432 +#define stack_smp_processor_id() raw_smp_processor_id()
19433 #define safe_smp_processor_id() smp_processor_id()
19434
19435 #endif
19436 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19437 index 54f1c80..39362a5 100644
19438 --- a/arch/x86/include/asm/spinlock.h
19439 +++ b/arch/x86/include/asm/spinlock.h
19440 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19441 static inline void arch_read_lock(arch_rwlock_t *rw)
19442 {
19443 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19444 +
19445 +#ifdef CONFIG_PAX_REFCOUNT
19446 + "jno 0f\n"
19447 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19448 + "int $4\n0:\n"
19449 + _ASM_EXTABLE(0b, 0b)
19450 +#endif
19451 +
19452 "jns 1f\n"
19453 "call __read_lock_failed\n\t"
19454 "1:\n"
19455 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19456 static inline void arch_write_lock(arch_rwlock_t *rw)
19457 {
19458 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19459 +
19460 +#ifdef CONFIG_PAX_REFCOUNT
19461 + "jno 0f\n"
19462 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19463 + "int $4\n0:\n"
19464 + _ASM_EXTABLE(0b, 0b)
19465 +#endif
19466 +
19467 "jz 1f\n"
19468 "call __write_lock_failed\n\t"
19469 "1:\n"
19470 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19471
19472 static inline void arch_read_unlock(arch_rwlock_t *rw)
19473 {
19474 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19475 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19476 +
19477 +#ifdef CONFIG_PAX_REFCOUNT
19478 + "jno 0f\n"
19479 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19480 + "int $4\n0:\n"
19481 + _ASM_EXTABLE(0b, 0b)
19482 +#endif
19483 +
19484 :"+m" (rw->lock) : : "memory");
19485 }
19486
19487 static inline void arch_write_unlock(arch_rwlock_t *rw)
19488 {
19489 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19490 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19491 +
19492 +#ifdef CONFIG_PAX_REFCOUNT
19493 + "jno 0f\n"
19494 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19495 + "int $4\n0:\n"
19496 + _ASM_EXTABLE(0b, 0b)
19497 +#endif
19498 +
19499 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19500 }
19501 #else
19502 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19503 index 6a99859..03cb807 100644
19504 --- a/arch/x86/include/asm/stackprotector.h
19505 +++ b/arch/x86/include/asm/stackprotector.h
19506 @@ -47,7 +47,7 @@
19507 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19508 */
19509 #define GDT_STACK_CANARY_INIT \
19510 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19511 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19512
19513 /*
19514 * Initialize the stackprotector canary value.
19515 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19516
19517 static inline void load_stack_canary_segment(void)
19518 {
19519 -#ifdef CONFIG_X86_32
19520 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19521 asm volatile ("mov %0, %%gs" : : "r" (0));
19522 #endif
19523 }
19524 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19525 index 70bbe39..4ae2bd4 100644
19526 --- a/arch/x86/include/asm/stacktrace.h
19527 +++ b/arch/x86/include/asm/stacktrace.h
19528 @@ -11,28 +11,20 @@
19529
19530 extern int kstack_depth_to_print;
19531
19532 -struct thread_info;
19533 +struct task_struct;
19534 struct stacktrace_ops;
19535
19536 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19537 - unsigned long *stack,
19538 - unsigned long bp,
19539 - const struct stacktrace_ops *ops,
19540 - void *data,
19541 - unsigned long *end,
19542 - int *graph);
19543 +typedef unsigned long walk_stack_t(struct task_struct *task,
19544 + void *stack_start,
19545 + unsigned long *stack,
19546 + unsigned long bp,
19547 + const struct stacktrace_ops *ops,
19548 + void *data,
19549 + unsigned long *end,
19550 + int *graph);
19551
19552 -extern unsigned long
19553 -print_context_stack(struct thread_info *tinfo,
19554 - unsigned long *stack, unsigned long bp,
19555 - const struct stacktrace_ops *ops, void *data,
19556 - unsigned long *end, int *graph);
19557 -
19558 -extern unsigned long
19559 -print_context_stack_bp(struct thread_info *tinfo,
19560 - unsigned long *stack, unsigned long bp,
19561 - const struct stacktrace_ops *ops, void *data,
19562 - unsigned long *end, int *graph);
19563 +extern walk_stack_t print_context_stack;
19564 +extern walk_stack_t print_context_stack_bp;
19565
19566 /* Generic stack tracer with callbacks */
19567
19568 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19569 void (*address)(void *data, unsigned long address, int reliable);
19570 /* On negative return stop dumping */
19571 int (*stack)(void *data, char *name);
19572 - walk_stack_t walk_stack;
19573 + walk_stack_t *walk_stack;
19574 };
19575
19576 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19577 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19578 index d7f3b3b..3cc39f1 100644
19579 --- a/arch/x86/include/asm/switch_to.h
19580 +++ b/arch/x86/include/asm/switch_to.h
19581 @@ -108,7 +108,7 @@ do { \
19582 "call __switch_to\n\t" \
19583 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19584 __switch_canary \
19585 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19586 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19587 "movq %%rax,%%rdi\n\t" \
19588 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19589 "jnz ret_from_fork\n\t" \
19590 @@ -119,7 +119,7 @@ do { \
19591 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19592 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19593 [_tif_fork] "i" (_TIF_FORK), \
19594 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19595 + [thread_info] "m" (current_tinfo), \
19596 [current_task] "m" (current_task) \
19597 __switch_canary_iparam \
19598 : "memory", "cc" __EXTRA_CLOBBER)
19599 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19600 index 8540538..4b0b5e9 100644
19601 --- a/arch/x86/include/asm/thread_info.h
19602 +++ b/arch/x86/include/asm/thread_info.h
19603 @@ -24,7 +24,6 @@ struct exec_domain;
19604 #include <linux/atomic.h>
19605
19606 struct thread_info {
19607 - struct task_struct *task; /* main task structure */
19608 struct exec_domain *exec_domain; /* execution domain */
19609 __u32 flags; /* low level flags */
19610 __u32 status; /* thread synchronous flags */
19611 @@ -33,13 +32,13 @@ struct thread_info {
19612 mm_segment_t addr_limit;
19613 struct restart_block restart_block;
19614 void __user *sysenter_return;
19615 + unsigned long lowest_stack;
19616 unsigned int sig_on_uaccess_error:1;
19617 unsigned int uaccess_err:1; /* uaccess failed */
19618 };
19619
19620 -#define INIT_THREAD_INFO(tsk) \
19621 +#define INIT_THREAD_INFO \
19622 { \
19623 - .task = &tsk, \
19624 .exec_domain = &default_exec_domain, \
19625 .flags = 0, \
19626 .cpu = 0, \
19627 @@ -50,7 +49,7 @@ struct thread_info {
19628 }, \
19629 }
19630
19631 -#define init_thread_info (init_thread_union.thread_info)
19632 +#define init_thread_info (init_thread_union.stack)
19633 #define init_stack (init_thread_union.stack)
19634
19635 #else /* !__ASSEMBLY__ */
19636 @@ -91,6 +90,7 @@ struct thread_info {
19637 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19638 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19639 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19640 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19641
19642 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19643 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19644 @@ -115,17 +115,18 @@ struct thread_info {
19645 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19646 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19647 #define _TIF_X32 (1 << TIF_X32)
19648 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19649
19650 /* work to do in syscall_trace_enter() */
19651 #define _TIF_WORK_SYSCALL_ENTRY \
19652 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19653 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19654 - _TIF_NOHZ)
19655 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19656
19657 /* work to do in syscall_trace_leave() */
19658 #define _TIF_WORK_SYSCALL_EXIT \
19659 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19660 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19661 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19662
19663 /* work to do on interrupt/exception return */
19664 #define _TIF_WORK_MASK \
19665 @@ -136,7 +137,7 @@ struct thread_info {
19666 /* work to do on any return to user space */
19667 #define _TIF_ALLWORK_MASK \
19668 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19669 - _TIF_NOHZ)
19670 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19671
19672 /* Only used for 64 bit */
19673 #define _TIF_DO_NOTIFY_MASK \
19674 @@ -151,7 +152,6 @@ struct thread_info {
19675 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19676
19677 #define STACK_WARN (THREAD_SIZE/8)
19678 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19679
19680 /*
19681 * macros/functions for gaining access to the thread information structure
19682 @@ -162,26 +162,18 @@ struct thread_info {
19683
19684 DECLARE_PER_CPU(unsigned long, kernel_stack);
19685
19686 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19687 +
19688 static inline struct thread_info *current_thread_info(void)
19689 {
19690 - struct thread_info *ti;
19691 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19692 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19693 - return ti;
19694 + return this_cpu_read_stable(current_tinfo);
19695 }
19696
19697 #else /* !__ASSEMBLY__ */
19698
19699 /* how to get the thread information struct from ASM */
19700 #define GET_THREAD_INFO(reg) \
19701 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19702 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19703 -
19704 -/*
19705 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19706 - * a certain register (to be used in assembler memory operands).
19707 - */
19708 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19709 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19710
19711 #endif
19712
19713 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19714 extern void arch_task_cache_init(void);
19715 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19716 extern void arch_release_task_struct(struct task_struct *tsk);
19717 +
19718 +#define __HAVE_THREAD_FUNCTIONS
19719 +#define task_thread_info(task) (&(task)->tinfo)
19720 +#define task_stack_page(task) ((task)->stack)
19721 +#define setup_thread_stack(p, org) do {} while (0)
19722 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19723 +
19724 #endif
19725 #endif /* _ASM_X86_THREAD_INFO_H */
19726 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19727 index 04905bf..49203ca 100644
19728 --- a/arch/x86/include/asm/tlbflush.h
19729 +++ b/arch/x86/include/asm/tlbflush.h
19730 @@ -17,18 +17,44 @@
19731
19732 static inline void __native_flush_tlb(void)
19733 {
19734 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19735 + u64 descriptor[2];
19736 +
19737 + descriptor[0] = PCID_KERNEL;
19738 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19739 + return;
19740 + }
19741 +
19742 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19743 + if (static_cpu_has(X86_FEATURE_PCID)) {
19744 + unsigned int cpu = raw_get_cpu();
19745 +
19746 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19747 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19748 + raw_put_cpu_no_resched();
19749 + return;
19750 + }
19751 +#endif
19752 +
19753 native_write_cr3(native_read_cr3());
19754 }
19755
19756 static inline void __native_flush_tlb_global_irq_disabled(void)
19757 {
19758 - unsigned long cr4;
19759 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19760 + u64 descriptor[2];
19761
19762 - cr4 = native_read_cr4();
19763 - /* clear PGE */
19764 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19765 - /* write old PGE again and flush TLBs */
19766 - native_write_cr4(cr4);
19767 + descriptor[0] = PCID_KERNEL;
19768 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19769 + } else {
19770 + unsigned long cr4;
19771 +
19772 + cr4 = native_read_cr4();
19773 + /* clear PGE */
19774 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19775 + /* write old PGE again and flush TLBs */
19776 + native_write_cr4(cr4);
19777 + }
19778 }
19779
19780 static inline void __native_flush_tlb_global(void)
19781 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19782
19783 static inline void __native_flush_tlb_single(unsigned long addr)
19784 {
19785 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19786 + u64 descriptor[2];
19787 +
19788 + descriptor[0] = PCID_KERNEL;
19789 + descriptor[1] = addr;
19790 +
19791 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19792 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19793 + if (addr < TASK_SIZE_MAX)
19794 + descriptor[1] += pax_user_shadow_base;
19795 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19796 + }
19797 +
19798 + descriptor[0] = PCID_USER;
19799 + descriptor[1] = addr;
19800 +#endif
19801 +
19802 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19803 + return;
19804 + }
19805 +
19806 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19807 + if (static_cpu_has(X86_FEATURE_PCID)) {
19808 + unsigned int cpu = raw_get_cpu();
19809 +
19810 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19811 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19812 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19813 + raw_put_cpu_no_resched();
19814 +
19815 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19816 + addr += pax_user_shadow_base;
19817 + }
19818 +#endif
19819 +
19820 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19821 }
19822
19823 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19824 index 0d592e0..526f797 100644
19825 --- a/arch/x86/include/asm/uaccess.h
19826 +++ b/arch/x86/include/asm/uaccess.h
19827 @@ -7,6 +7,7 @@
19828 #include <linux/compiler.h>
19829 #include <linux/thread_info.h>
19830 #include <linux/string.h>
19831 +#include <linux/spinlock.h>
19832 #include <asm/asm.h>
19833 #include <asm/page.h>
19834 #include <asm/smap.h>
19835 @@ -29,7 +30,12 @@
19836
19837 #define get_ds() (KERNEL_DS)
19838 #define get_fs() (current_thread_info()->addr_limit)
19839 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19840 +void __set_fs(mm_segment_t x);
19841 +void set_fs(mm_segment_t x);
19842 +#else
19843 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19844 +#endif
19845
19846 #define segment_eq(a, b) ((a).seg == (b).seg)
19847
19848 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19849 * checks that the pointer is in the user space range - after calling
19850 * this function, memory access functions may still return -EFAULT.
19851 */
19852 -#define access_ok(type, addr, size) \
19853 - likely(!__range_not_ok(addr, size, user_addr_max()))
19854 +extern int _cond_resched(void);
19855 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19856 +#define access_ok(type, addr, size) \
19857 +({ \
19858 + unsigned long __size = size; \
19859 + unsigned long __addr = (unsigned long)addr; \
19860 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19861 + if (__ret_ao && __size) { \
19862 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19863 + unsigned long __end_ao = __addr + __size - 1; \
19864 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19865 + while (__addr_ao <= __end_ao) { \
19866 + char __c_ao; \
19867 + __addr_ao += PAGE_SIZE; \
19868 + if (__size > PAGE_SIZE) \
19869 + _cond_resched(); \
19870 + if (__get_user(__c_ao, (char __user *)__addr)) \
19871 + break; \
19872 + if (type != VERIFY_WRITE) { \
19873 + __addr = __addr_ao; \
19874 + continue; \
19875 + } \
19876 + if (__put_user(__c_ao, (char __user *)__addr)) \
19877 + break; \
19878 + __addr = __addr_ao; \
19879 + } \
19880 + } \
19881 + } \
19882 + __ret_ao; \
19883 +})
19884
19885 /*
19886 * The exception table consists of pairs of addresses relative to the
19887 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19888 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19889 __chk_user_ptr(ptr); \
19890 might_fault(); \
19891 + pax_open_userland(); \
19892 asm volatile("call __get_user_%P3" \
19893 : "=a" (__ret_gu), "=r" (__val_gu) \
19894 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19895 (x) = (__typeof__(*(ptr))) __val_gu; \
19896 + pax_close_userland(); \
19897 __ret_gu; \
19898 })
19899
19900 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19901 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19902 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19903
19904 -
19905 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19906 +#define __copyuser_seg "gs;"
19907 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19908 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19909 +#else
19910 +#define __copyuser_seg
19911 +#define __COPYUSER_SET_ES
19912 +#define __COPYUSER_RESTORE_ES
19913 +#endif
19914
19915 #ifdef CONFIG_X86_32
19916 #define __put_user_asm_u64(x, addr, err, errret) \
19917 asm volatile(ASM_STAC "\n" \
19918 - "1: movl %%eax,0(%2)\n" \
19919 - "2: movl %%edx,4(%2)\n" \
19920 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19921 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19922 "3: " ASM_CLAC "\n" \
19923 ".section .fixup,\"ax\"\n" \
19924 "4: movl %3,%0\n" \
19925 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19926
19927 #define __put_user_asm_ex_u64(x, addr) \
19928 asm volatile(ASM_STAC "\n" \
19929 - "1: movl %%eax,0(%1)\n" \
19930 - "2: movl %%edx,4(%1)\n" \
19931 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19932 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19933 "3: " ASM_CLAC "\n" \
19934 _ASM_EXTABLE_EX(1b, 2b) \
19935 _ASM_EXTABLE_EX(2b, 3b) \
19936 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19937 __typeof__(*(ptr)) __pu_val; \
19938 __chk_user_ptr(ptr); \
19939 might_fault(); \
19940 - __pu_val = x; \
19941 + __pu_val = (x); \
19942 + pax_open_userland(); \
19943 switch (sizeof(*(ptr))) { \
19944 case 1: \
19945 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19946 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19947 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19948 break; \
19949 } \
19950 + pax_close_userland(); \
19951 __ret_pu; \
19952 })
19953
19954 @@ -355,8 +401,10 @@ do { \
19955 } while (0)
19956
19957 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19958 +do { \
19959 + pax_open_userland(); \
19960 asm volatile(ASM_STAC "\n" \
19961 - "1: mov"itype" %2,%"rtype"1\n" \
19962 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19963 "2: " ASM_CLAC "\n" \
19964 ".section .fixup,\"ax\"\n" \
19965 "3: mov %3,%0\n" \
19966 @@ -364,8 +412,10 @@ do { \
19967 " jmp 2b\n" \
19968 ".previous\n" \
19969 _ASM_EXTABLE(1b, 3b) \
19970 - : "=r" (err), ltype(x) \
19971 - : "m" (__m(addr)), "i" (errret), "0" (err))
19972 + : "=r" (err), ltype (x) \
19973 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19974 + pax_close_userland(); \
19975 +} while (0)
19976
19977 #define __get_user_size_ex(x, ptr, size) \
19978 do { \
19979 @@ -389,7 +439,7 @@ do { \
19980 } while (0)
19981
19982 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19983 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19984 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19985 "2:\n" \
19986 _ASM_EXTABLE_EX(1b, 2b) \
19987 : ltype(x) : "m" (__m(addr)))
19988 @@ -406,13 +456,24 @@ do { \
19989 int __gu_err; \
19990 unsigned long __gu_val; \
19991 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19992 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19993 + (x) = (__typeof__(*(ptr)))__gu_val; \
19994 __gu_err; \
19995 })
19996
19997 /* FIXME: this hack is definitely wrong -AK */
19998 struct __large_struct { unsigned long buf[100]; };
19999 -#define __m(x) (*(struct __large_struct __user *)(x))
20000 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20001 +#define ____m(x) \
20002 +({ \
20003 + unsigned long ____x = (unsigned long)(x); \
20004 + if (____x < pax_user_shadow_base) \
20005 + ____x += pax_user_shadow_base; \
20006 + (typeof(x))____x; \
20007 +})
20008 +#else
20009 +#define ____m(x) (x)
20010 +#endif
20011 +#define __m(x) (*(struct __large_struct __user *)____m(x))
20012
20013 /*
20014 * Tell gcc we read from memory instead of writing: this is because
20015 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
20016 * aliasing issues.
20017 */
20018 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20019 +do { \
20020 + pax_open_userland(); \
20021 asm volatile(ASM_STAC "\n" \
20022 - "1: mov"itype" %"rtype"1,%2\n" \
20023 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
20024 "2: " ASM_CLAC "\n" \
20025 ".section .fixup,\"ax\"\n" \
20026 "3: mov %3,%0\n" \
20027 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
20028 ".previous\n" \
20029 _ASM_EXTABLE(1b, 3b) \
20030 : "=r"(err) \
20031 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
20032 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
20033 + pax_close_userland(); \
20034 +} while (0)
20035
20036 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
20037 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
20038 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
20039 "2:\n" \
20040 _ASM_EXTABLE_EX(1b, 2b) \
20041 : : ltype(x), "m" (__m(addr)))
20042 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
20043 */
20044 #define uaccess_try do { \
20045 current_thread_info()->uaccess_err = 0; \
20046 + pax_open_userland(); \
20047 stac(); \
20048 barrier();
20049
20050 #define uaccess_catch(err) \
20051 clac(); \
20052 + pax_close_userland(); \
20053 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
20054 } while (0)
20055
20056 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
20057 * On error, the variable @x is set to zero.
20058 */
20059
20060 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20061 +#define __get_user(x, ptr) get_user((x), (ptr))
20062 +#else
20063 #define __get_user(x, ptr) \
20064 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
20065 +#endif
20066
20067 /**
20068 * __put_user: - Write a simple value into user space, with less checking.
20069 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
20070 * Returns zero on success, or -EFAULT on error.
20071 */
20072
20073 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20074 +#define __put_user(x, ptr) put_user((x), (ptr))
20075 +#else
20076 #define __put_user(x, ptr) \
20077 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
20078 +#endif
20079
20080 #define __get_user_unaligned __get_user
20081 #define __put_user_unaligned __put_user
20082 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
20083 #define get_user_ex(x, ptr) do { \
20084 unsigned long __gue_val; \
20085 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
20086 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
20087 + (x) = (__typeof__(*(ptr)))__gue_val; \
20088 } while (0)
20089
20090 #define put_user_try uaccess_try
20091 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
20092 __typeof__(ptr) __uval = (uval); \
20093 __typeof__(*(ptr)) __old = (old); \
20094 __typeof__(*(ptr)) __new = (new); \
20095 + pax_open_userland(); \
20096 switch (size) { \
20097 case 1: \
20098 { \
20099 asm volatile("\t" ASM_STAC "\n" \
20100 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
20101 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
20102 "2:\t" ASM_CLAC "\n" \
20103 "\t.section .fixup, \"ax\"\n" \
20104 "3:\tmov %3, %0\n" \
20105 "\tjmp 2b\n" \
20106 "\t.previous\n" \
20107 _ASM_EXTABLE(1b, 3b) \
20108 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20109 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20110 : "i" (-EFAULT), "q" (__new), "1" (__old) \
20111 : "memory" \
20112 ); \
20113 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
20114 case 2: \
20115 { \
20116 asm volatile("\t" ASM_STAC "\n" \
20117 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
20118 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
20119 "2:\t" ASM_CLAC "\n" \
20120 "\t.section .fixup, \"ax\"\n" \
20121 "3:\tmov %3, %0\n" \
20122 "\tjmp 2b\n" \
20123 "\t.previous\n" \
20124 _ASM_EXTABLE(1b, 3b) \
20125 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20126 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20127 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20128 : "memory" \
20129 ); \
20130 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
20131 case 4: \
20132 { \
20133 asm volatile("\t" ASM_STAC "\n" \
20134 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
20135 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
20136 "2:\t" ASM_CLAC "\n" \
20137 "\t.section .fixup, \"ax\"\n" \
20138 "3:\tmov %3, %0\n" \
20139 "\tjmp 2b\n" \
20140 "\t.previous\n" \
20141 _ASM_EXTABLE(1b, 3b) \
20142 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20143 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20144 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20145 : "memory" \
20146 ); \
20147 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
20148 __cmpxchg_wrong_size(); \
20149 \
20150 asm volatile("\t" ASM_STAC "\n" \
20151 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
20152 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
20153 "2:\t" ASM_CLAC "\n" \
20154 "\t.section .fixup, \"ax\"\n" \
20155 "3:\tmov %3, %0\n" \
20156 "\tjmp 2b\n" \
20157 "\t.previous\n" \
20158 _ASM_EXTABLE(1b, 3b) \
20159 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20160 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20161 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20162 : "memory" \
20163 ); \
20164 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
20165 default: \
20166 __cmpxchg_wrong_size(); \
20167 } \
20168 + pax_close_userland(); \
20169 *__uval = __old; \
20170 __ret; \
20171 })
20172 @@ -636,17 +713,6 @@ extern struct movsl_mask {
20173
20174 #define ARCH_HAS_NOCACHE_UACCESS 1
20175
20176 -#ifdef CONFIG_X86_32
20177 -# include <asm/uaccess_32.h>
20178 -#else
20179 -# include <asm/uaccess_64.h>
20180 -#endif
20181 -
20182 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
20183 - unsigned n);
20184 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20185 - unsigned n);
20186 -
20187 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
20188 # define copy_user_diag __compiletime_error
20189 #else
20190 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20191 extern void copy_user_diag("copy_from_user() buffer size is too small")
20192 copy_from_user_overflow(void);
20193 extern void copy_user_diag("copy_to_user() buffer size is too small")
20194 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20195 +copy_to_user_overflow(void);
20196
20197 #undef copy_user_diag
20198
20199 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
20200
20201 extern void
20202 __compiletime_warning("copy_to_user() buffer size is not provably correct")
20203 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20204 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
20205 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
20206
20207 #else
20208 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
20209
20210 #endif
20211
20212 +#ifdef CONFIG_X86_32
20213 +# include <asm/uaccess_32.h>
20214 +#else
20215 +# include <asm/uaccess_64.h>
20216 +#endif
20217 +
20218 static inline unsigned long __must_check
20219 copy_from_user(void *to, const void __user *from, unsigned long n)
20220 {
20221 - int sz = __compiletime_object_size(to);
20222 + size_t sz = __compiletime_object_size(to);
20223
20224 might_fault();
20225
20226 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20227 * case, and do only runtime checking for non-constant sizes.
20228 */
20229
20230 - if (likely(sz < 0 || sz >= n))
20231 - n = _copy_from_user(to, from, n);
20232 - else if(__builtin_constant_p(n))
20233 - copy_from_user_overflow();
20234 - else
20235 - __copy_from_user_overflow(sz, n);
20236 + if (likely(sz != (size_t)-1 && sz < n)) {
20237 + if(__builtin_constant_p(n))
20238 + copy_from_user_overflow();
20239 + else
20240 + __copy_from_user_overflow(sz, n);
20241 + } else if (access_ok(VERIFY_READ, from, n))
20242 + n = __copy_from_user(to, from, n);
20243 + else if ((long)n > 0)
20244 + memset(to, 0, n);
20245
20246 return n;
20247 }
20248 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20249 static inline unsigned long __must_check
20250 copy_to_user(void __user *to, const void *from, unsigned long n)
20251 {
20252 - int sz = __compiletime_object_size(from);
20253 + size_t sz = __compiletime_object_size(from);
20254
20255 might_fault();
20256
20257 /* See the comment in copy_from_user() above. */
20258 - if (likely(sz < 0 || sz >= n))
20259 - n = _copy_to_user(to, from, n);
20260 - else if(__builtin_constant_p(n))
20261 - copy_to_user_overflow();
20262 - else
20263 - __copy_to_user_overflow(sz, n);
20264 + if (likely(sz != (size_t)-1 && sz < n)) {
20265 + if(__builtin_constant_p(n))
20266 + copy_to_user_overflow();
20267 + else
20268 + __copy_to_user_overflow(sz, n);
20269 + } else if (access_ok(VERIFY_WRITE, to, n))
20270 + n = __copy_to_user(to, from, n);
20271
20272 return n;
20273 }
20274 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20275 index 3c03a5d..1071638 100644
20276 --- a/arch/x86/include/asm/uaccess_32.h
20277 +++ b/arch/x86/include/asm/uaccess_32.h
20278 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20279 static __always_inline unsigned long __must_check
20280 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20281 {
20282 + if ((long)n < 0)
20283 + return n;
20284 +
20285 + check_object_size(from, n, true);
20286 +
20287 if (__builtin_constant_p(n)) {
20288 unsigned long ret;
20289
20290 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20291 __copy_to_user(void __user *to, const void *from, unsigned long n)
20292 {
20293 might_fault();
20294 +
20295 return __copy_to_user_inatomic(to, from, n);
20296 }
20297
20298 static __always_inline unsigned long
20299 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20300 {
20301 + if ((long)n < 0)
20302 + return n;
20303 +
20304 /* Avoid zeroing the tail if the copy fails..
20305 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20306 * but as the zeroing behaviour is only significant when n is not
20307 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20308 __copy_from_user(void *to, const void __user *from, unsigned long n)
20309 {
20310 might_fault();
20311 +
20312 + if ((long)n < 0)
20313 + return n;
20314 +
20315 + check_object_size(to, n, false);
20316 +
20317 if (__builtin_constant_p(n)) {
20318 unsigned long ret;
20319
20320 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20321 const void __user *from, unsigned long n)
20322 {
20323 might_fault();
20324 +
20325 + if ((long)n < 0)
20326 + return n;
20327 +
20328 if (__builtin_constant_p(n)) {
20329 unsigned long ret;
20330
20331 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20332 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20333 unsigned long n)
20334 {
20335 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20336 + if ((long)n < 0)
20337 + return n;
20338 +
20339 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20340 }
20341
20342 #endif /* _ASM_X86_UACCESS_32_H */
20343 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20344 index 12a26b9..206c200 100644
20345 --- a/arch/x86/include/asm/uaccess_64.h
20346 +++ b/arch/x86/include/asm/uaccess_64.h
20347 @@ -10,6 +10,9 @@
20348 #include <asm/alternative.h>
20349 #include <asm/cpufeature.h>
20350 #include <asm/page.h>
20351 +#include <asm/pgtable.h>
20352 +
20353 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20354
20355 /*
20356 * Copy To/From Userspace
20357 @@ -17,14 +20,14 @@
20358
20359 /* Handles exceptions in both to and from, but doesn't do access_ok */
20360 __must_check unsigned long
20361 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20362 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20363 __must_check unsigned long
20364 -copy_user_generic_string(void *to, const void *from, unsigned len);
20365 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20366 __must_check unsigned long
20367 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20368 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20369
20370 static __always_inline __must_check unsigned long
20371 -copy_user_generic(void *to, const void *from, unsigned len)
20372 +copy_user_generic(void *to, const void *from, unsigned long len)
20373 {
20374 unsigned ret;
20375
20376 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20377 }
20378
20379 __must_check unsigned long
20380 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20381 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20382
20383 static __always_inline __must_check
20384 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20385 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20386 {
20387 - int ret = 0;
20388 + size_t sz = __compiletime_object_size(dst);
20389 + unsigned ret = 0;
20390 +
20391 + if (size > INT_MAX)
20392 + return size;
20393 +
20394 + check_object_size(dst, size, false);
20395 +
20396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20397 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20398 + return size;
20399 +#endif
20400 +
20401 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20402 + if(__builtin_constant_p(size))
20403 + copy_from_user_overflow();
20404 + else
20405 + __copy_from_user_overflow(sz, size);
20406 + return size;
20407 + }
20408
20409 if (!__builtin_constant_p(size))
20410 - return copy_user_generic(dst, (__force void *)src, size);
20411 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20412 switch (size) {
20413 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20414 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20415 ret, "b", "b", "=q", 1);
20416 return ret;
20417 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20418 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20419 ret, "w", "w", "=r", 2);
20420 return ret;
20421 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20422 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20423 ret, "l", "k", "=r", 4);
20424 return ret;
20425 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20426 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20427 ret, "q", "", "=r", 8);
20428 return ret;
20429 case 10:
20430 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20431 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20432 ret, "q", "", "=r", 10);
20433 if (unlikely(ret))
20434 return ret;
20435 __get_user_asm(*(u16 *)(8 + (char *)dst),
20436 - (u16 __user *)(8 + (char __user *)src),
20437 + (const u16 __user *)(8 + (const char __user *)src),
20438 ret, "w", "w", "=r", 2);
20439 return ret;
20440 case 16:
20441 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20442 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20443 ret, "q", "", "=r", 16);
20444 if (unlikely(ret))
20445 return ret;
20446 __get_user_asm(*(u64 *)(8 + (char *)dst),
20447 - (u64 __user *)(8 + (char __user *)src),
20448 + (const u64 __user *)(8 + (const char __user *)src),
20449 ret, "q", "", "=r", 8);
20450 return ret;
20451 default:
20452 - return copy_user_generic(dst, (__force void *)src, size);
20453 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20454 }
20455 }
20456
20457 static __always_inline __must_check
20458 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20459 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20460 {
20461 might_fault();
20462 return __copy_from_user_nocheck(dst, src, size);
20463 }
20464
20465 static __always_inline __must_check
20466 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20467 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20468 {
20469 - int ret = 0;
20470 + size_t sz = __compiletime_object_size(src);
20471 + unsigned ret = 0;
20472 +
20473 + if (size > INT_MAX)
20474 + return size;
20475 +
20476 + check_object_size(src, size, true);
20477 +
20478 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20479 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20480 + return size;
20481 +#endif
20482 +
20483 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20484 + if(__builtin_constant_p(size))
20485 + copy_to_user_overflow();
20486 + else
20487 + __copy_to_user_overflow(sz, size);
20488 + return size;
20489 + }
20490
20491 if (!__builtin_constant_p(size))
20492 - return copy_user_generic((__force void *)dst, src, size);
20493 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20494 switch (size) {
20495 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20496 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20497 ret, "b", "b", "iq", 1);
20498 return ret;
20499 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20500 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20501 ret, "w", "w", "ir", 2);
20502 return ret;
20503 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20504 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20505 ret, "l", "k", "ir", 4);
20506 return ret;
20507 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20508 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20509 ret, "q", "", "er", 8);
20510 return ret;
20511 case 10:
20512 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20513 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20514 ret, "q", "", "er", 10);
20515 if (unlikely(ret))
20516 return ret;
20517 asm("":::"memory");
20518 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20519 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20520 ret, "w", "w", "ir", 2);
20521 return ret;
20522 case 16:
20523 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20524 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20525 ret, "q", "", "er", 16);
20526 if (unlikely(ret))
20527 return ret;
20528 asm("":::"memory");
20529 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20530 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20531 ret, "q", "", "er", 8);
20532 return ret;
20533 default:
20534 - return copy_user_generic((__force void *)dst, src, size);
20535 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20536 }
20537 }
20538
20539 static __always_inline __must_check
20540 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20541 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20542 {
20543 might_fault();
20544 return __copy_to_user_nocheck(dst, src, size);
20545 }
20546
20547 static __always_inline __must_check
20548 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20549 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20550 {
20551 - int ret = 0;
20552 + unsigned ret = 0;
20553
20554 might_fault();
20555 +
20556 + if (size > INT_MAX)
20557 + return size;
20558 +
20559 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20560 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20561 + return size;
20562 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20563 + return size;
20564 +#endif
20565 +
20566 if (!__builtin_constant_p(size))
20567 - return copy_user_generic((__force void *)dst,
20568 - (__force void *)src, size);
20569 + return copy_user_generic((__force_kernel void *)____m(dst),
20570 + (__force_kernel const void *)____m(src), size);
20571 switch (size) {
20572 case 1: {
20573 u8 tmp;
20574 - __get_user_asm(tmp, (u8 __user *)src,
20575 + __get_user_asm(tmp, (const u8 __user *)src,
20576 ret, "b", "b", "=q", 1);
20577 if (likely(!ret))
20578 __put_user_asm(tmp, (u8 __user *)dst,
20579 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20580 }
20581 case 2: {
20582 u16 tmp;
20583 - __get_user_asm(tmp, (u16 __user *)src,
20584 + __get_user_asm(tmp, (const u16 __user *)src,
20585 ret, "w", "w", "=r", 2);
20586 if (likely(!ret))
20587 __put_user_asm(tmp, (u16 __user *)dst,
20588 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20589
20590 case 4: {
20591 u32 tmp;
20592 - __get_user_asm(tmp, (u32 __user *)src,
20593 + __get_user_asm(tmp, (const u32 __user *)src,
20594 ret, "l", "k", "=r", 4);
20595 if (likely(!ret))
20596 __put_user_asm(tmp, (u32 __user *)dst,
20597 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20598 }
20599 case 8: {
20600 u64 tmp;
20601 - __get_user_asm(tmp, (u64 __user *)src,
20602 + __get_user_asm(tmp, (const u64 __user *)src,
20603 ret, "q", "", "=r", 8);
20604 if (likely(!ret))
20605 __put_user_asm(tmp, (u64 __user *)dst,
20606 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20607 return ret;
20608 }
20609 default:
20610 - return copy_user_generic((__force void *)dst,
20611 - (__force void *)src, size);
20612 + return copy_user_generic((__force_kernel void *)____m(dst),
20613 + (__force_kernel const void *)____m(src), size);
20614 }
20615 }
20616
20617 -static __must_check __always_inline int
20618 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20619 +static __must_check __always_inline unsigned long
20620 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20621 {
20622 return __copy_from_user_nocheck(dst, src, size);
20623 }
20624
20625 -static __must_check __always_inline int
20626 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20627 +static __must_check __always_inline unsigned long
20628 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20629 {
20630 return __copy_to_user_nocheck(dst, src, size);
20631 }
20632
20633 -extern long __copy_user_nocache(void *dst, const void __user *src,
20634 - unsigned size, int zerorest);
20635 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20636 + unsigned long size, int zerorest);
20637
20638 -static inline int
20639 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20640 +static inline unsigned long
20641 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20642 {
20643 might_fault();
20644 +
20645 + if (size > INT_MAX)
20646 + return size;
20647 +
20648 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20649 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20650 + return size;
20651 +#endif
20652 +
20653 return __copy_user_nocache(dst, src, size, 1);
20654 }
20655
20656 -static inline int
20657 +static inline unsigned long
20658 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20659 - unsigned size)
20660 + unsigned long size)
20661 {
20662 + if (size > INT_MAX)
20663 + return size;
20664 +
20665 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20666 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20667 + return size;
20668 +#endif
20669 +
20670 return __copy_user_nocache(dst, src, size, 0);
20671 }
20672
20673 unsigned long
20674 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20675 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20676
20677 #endif /* _ASM_X86_UACCESS_64_H */
20678 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20679 index 5b238981..77fdd78 100644
20680 --- a/arch/x86/include/asm/word-at-a-time.h
20681 +++ b/arch/x86/include/asm/word-at-a-time.h
20682 @@ -11,7 +11,7 @@
20683 * and shift, for example.
20684 */
20685 struct word_at_a_time {
20686 - const unsigned long one_bits, high_bits;
20687 + unsigned long one_bits, high_bits;
20688 };
20689
20690 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20691 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20692 index e45e4da..44e8572 100644
20693 --- a/arch/x86/include/asm/x86_init.h
20694 +++ b/arch/x86/include/asm/x86_init.h
20695 @@ -129,7 +129,7 @@ struct x86_init_ops {
20696 struct x86_init_timers timers;
20697 struct x86_init_iommu iommu;
20698 struct x86_init_pci pci;
20699 -};
20700 +} __no_const;
20701
20702 /**
20703 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20704 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20705 void (*setup_percpu_clockev)(void);
20706 void (*early_percpu_clock_init)(void);
20707 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20708 -};
20709 +} __no_const;
20710
20711 struct timespec;
20712
20713 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20714 void (*save_sched_clock_state)(void);
20715 void (*restore_sched_clock_state)(void);
20716 void (*apic_post_init)(void);
20717 -};
20718 +} __no_const;
20719
20720 struct pci_dev;
20721 struct msi_msg;
20722 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20723 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20724 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20725 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20726 -};
20727 +} __no_const;
20728
20729 struct IO_APIC_route_entry;
20730 struct io_apic_irq_attr;
20731 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20732 unsigned int destination, int vector,
20733 struct io_apic_irq_attr *attr);
20734 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20735 -};
20736 +} __no_const;
20737
20738 extern struct x86_init_ops x86_init;
20739 extern struct x86_cpuinit_ops x86_cpuinit;
20740 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20741 index c949923..c22bfa4 100644
20742 --- a/arch/x86/include/asm/xen/page.h
20743 +++ b/arch/x86/include/asm/xen/page.h
20744 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20745 extern struct page *m2p_find_override(unsigned long mfn);
20746 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20747
20748 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20749 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20750 {
20751 unsigned long mfn;
20752
20753 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20754 index d949ef2..479b9d1 100644
20755 --- a/arch/x86/include/asm/xsave.h
20756 +++ b/arch/x86/include/asm/xsave.h
20757 @@ -82,8 +82,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20758 if (unlikely(err))
20759 return -EFAULT;
20760
20761 + pax_open_userland();
20762 __asm__ __volatile__(ASM_STAC "\n"
20763 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20764 + "1:"
20765 + __copyuser_seg
20766 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20767 "2: " ASM_CLAC "\n"
20768 ".section .fixup,\"ax\"\n"
20769 "3: movl $-1,%[err]\n"
20770 @@ -93,18 +96,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20771 : [err] "=r" (err)
20772 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20773 : "memory");
20774 + pax_close_userland();
20775 return err;
20776 }
20777
20778 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20779 {
20780 int err;
20781 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20782 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20783 u32 lmask = mask;
20784 u32 hmask = mask >> 32;
20785
20786 + pax_open_userland();
20787 __asm__ __volatile__(ASM_STAC "\n"
20788 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20789 + "1:"
20790 + __copyuser_seg
20791 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20792 "2: " ASM_CLAC "\n"
20793 ".section .fixup,\"ax\"\n"
20794 "3: movl $-1,%[err]\n"
20795 @@ -114,6 +121,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20796 : [err] "=r" (err)
20797 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20798 : "memory"); /* memory required? */
20799 + pax_close_userland();
20800 return err;
20801 }
20802
20803 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20804 index bbae024..e1528f9 100644
20805 --- a/arch/x86/include/uapi/asm/e820.h
20806 +++ b/arch/x86/include/uapi/asm/e820.h
20807 @@ -63,7 +63,7 @@ struct e820map {
20808 #define ISA_START_ADDRESS 0xa0000
20809 #define ISA_END_ADDRESS 0x100000
20810
20811 -#define BIOS_BEGIN 0x000a0000
20812 +#define BIOS_BEGIN 0x000c0000
20813 #define BIOS_END 0x00100000
20814
20815 #define BIOS_ROM_BASE 0xffe00000
20816 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20817 index 7b0a55a..ad115bf 100644
20818 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20819 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20820 @@ -49,7 +49,6 @@
20821 #define EFLAGS 144
20822 #define RSP 152
20823 #define SS 160
20824 -#define ARGOFFSET R11
20825 #endif /* __ASSEMBLY__ */
20826
20827 /* top of stack page */
20828 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20829 index 047f9ff..4ba5ea6 100644
20830 --- a/arch/x86/kernel/Makefile
20831 +++ b/arch/x86/kernel/Makefile
20832 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20833 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20834 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20835 obj-y += probe_roms.o
20836 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20837 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20838 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20839 obj-$(CONFIG_X86_64) += mcount_64.o
20840 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20841 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20842 index 86281ff..e046fc2 100644
20843 --- a/arch/x86/kernel/acpi/boot.c
20844 +++ b/arch/x86/kernel/acpi/boot.c
20845 @@ -1296,7 +1296,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20846 * If your system is blacklisted here, but you find that acpi=force
20847 * works for you, please contact linux-acpi@vger.kernel.org
20848 */
20849 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20850 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20851 /*
20852 * Boxes that need ACPI disabled
20853 */
20854 @@ -1371,7 +1371,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20855 };
20856
20857 /* second table for DMI checks that should run after early-quirks */
20858 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20859 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20860 /*
20861 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20862 * which includes some code which overrides all temperature
20863 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20864 index 3136820..e2c6577 100644
20865 --- a/arch/x86/kernel/acpi/sleep.c
20866 +++ b/arch/x86/kernel/acpi/sleep.c
20867 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20868 #else /* CONFIG_64BIT */
20869 #ifdef CONFIG_SMP
20870 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20871 +
20872 + pax_open_kernel();
20873 early_gdt_descr.address =
20874 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20875 + pax_close_kernel();
20876 +
20877 initial_gs = per_cpu_offset(smp_processor_id());
20878 #endif
20879 initial_code = (unsigned long)wakeup_long64;
20880 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20881 index 665c6b7..eae4d56 100644
20882 --- a/arch/x86/kernel/acpi/wakeup_32.S
20883 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20884 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20885 # and restore the stack ... but you need gdt for this to work
20886 movl saved_context_esp, %esp
20887
20888 - movl %cs:saved_magic, %eax
20889 - cmpl $0x12345678, %eax
20890 + cmpl $0x12345678, saved_magic
20891 jne bogus_magic
20892
20893 # jump to place where we left off
20894 - movl saved_eip, %eax
20895 - jmp *%eax
20896 + jmp *(saved_eip)
20897
20898 bogus_magic:
20899 jmp bogus_magic
20900 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20901 index 703130f..27a155d 100644
20902 --- a/arch/x86/kernel/alternative.c
20903 +++ b/arch/x86/kernel/alternative.c
20904 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20905 */
20906 for (a = start; a < end; a++) {
20907 instr = (u8 *)&a->instr_offset + a->instr_offset;
20908 +
20909 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20910 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20911 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20912 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20913 +#endif
20914 +
20915 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20916 BUG_ON(a->replacementlen > a->instrlen);
20917 BUG_ON(a->instrlen > sizeof(insnbuf));
20918 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20919 add_nops(insnbuf + a->replacementlen,
20920 a->instrlen - a->replacementlen);
20921
20922 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20923 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20924 + instr = ktva_ktla(instr);
20925 +#endif
20926 +
20927 text_poke_early(instr, insnbuf, a->instrlen);
20928 }
20929 }
20930 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20931 for (poff = start; poff < end; poff++) {
20932 u8 *ptr = (u8 *)poff + *poff;
20933
20934 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20935 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20936 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20937 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20938 +#endif
20939 +
20940 if (!*poff || ptr < text || ptr >= text_end)
20941 continue;
20942 /* turn DS segment override prefix into lock prefix */
20943 - if (*ptr == 0x3e)
20944 + if (*ktla_ktva(ptr) == 0x3e)
20945 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20946 }
20947 mutex_unlock(&text_mutex);
20948 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20949 for (poff = start; poff < end; poff++) {
20950 u8 *ptr = (u8 *)poff + *poff;
20951
20952 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20953 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20954 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20955 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20956 +#endif
20957 +
20958 if (!*poff || ptr < text || ptr >= text_end)
20959 continue;
20960 /* turn lock prefix into DS segment override prefix */
20961 - if (*ptr == 0xf0)
20962 + if (*ktla_ktva(ptr) == 0xf0)
20963 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20964 }
20965 mutex_unlock(&text_mutex);
20966 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20967
20968 BUG_ON(p->len > MAX_PATCH_LEN);
20969 /* prep the buffer with the original instructions */
20970 - memcpy(insnbuf, p->instr, p->len);
20971 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20972 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20973 (unsigned long)p->instr, p->len);
20974
20975 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
20976 if (!uniproc_patched || num_possible_cpus() == 1)
20977 free_init_pages("SMP alternatives",
20978 (unsigned long)__smp_locks,
20979 - (unsigned long)__smp_locks_end);
20980 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20981 #endif
20982
20983 apply_paravirt(__parainstructions, __parainstructions_end);
20984 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
20985 * instructions. And on the local CPU you need to be protected again NMI or MCE
20986 * handlers seeing an inconsistent instruction while you patch.
20987 */
20988 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20989 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20990 size_t len)
20991 {
20992 unsigned long flags;
20993 local_irq_save(flags);
20994 - memcpy(addr, opcode, len);
20995 +
20996 + pax_open_kernel();
20997 + memcpy(ktla_ktva(addr), opcode, len);
20998 sync_core();
20999 + pax_close_kernel();
21000 +
21001 local_irq_restore(flags);
21002 /* Could also do a CLFLUSH here to speed up CPU recovery; but
21003 that causes hangs on some VIA CPUs. */
21004 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
21005 */
21006 void *text_poke(void *addr, const void *opcode, size_t len)
21007 {
21008 - unsigned long flags;
21009 - char *vaddr;
21010 + unsigned char *vaddr = ktla_ktva(addr);
21011 struct page *pages[2];
21012 - int i;
21013 + size_t i;
21014
21015 if (!core_kernel_text((unsigned long)addr)) {
21016 - pages[0] = vmalloc_to_page(addr);
21017 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
21018 + pages[0] = vmalloc_to_page(vaddr);
21019 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
21020 } else {
21021 - pages[0] = virt_to_page(addr);
21022 + pages[0] = virt_to_page(vaddr);
21023 WARN_ON(!PageReserved(pages[0]));
21024 - pages[1] = virt_to_page(addr + PAGE_SIZE);
21025 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
21026 }
21027 BUG_ON(!pages[0]);
21028 - local_irq_save(flags);
21029 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
21030 - if (pages[1])
21031 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
21032 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
21033 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
21034 - clear_fixmap(FIX_TEXT_POKE0);
21035 - if (pages[1])
21036 - clear_fixmap(FIX_TEXT_POKE1);
21037 - local_flush_tlb();
21038 - sync_core();
21039 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
21040 - that causes hangs on some VIA CPUs. */
21041 + text_poke_early(addr, opcode, len);
21042 for (i = 0; i < len; i++)
21043 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
21044 - local_irq_restore(flags);
21045 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
21046 return addr;
21047 }
21048
21049 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
21050 if (likely(!bp_patching_in_progress))
21051 return 0;
21052
21053 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
21054 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
21055 return 0;
21056
21057 /* set up the specified breakpoint handler */
21058 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
21059 */
21060 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
21061 {
21062 - unsigned char int3 = 0xcc;
21063 + const unsigned char int3 = 0xcc;
21064
21065 bp_int3_handler = handler;
21066 bp_int3_addr = (u8 *)addr + sizeof(int3);
21067 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
21068 index ad28db7..c538b2c 100644
21069 --- a/arch/x86/kernel/apic/apic.c
21070 +++ b/arch/x86/kernel/apic/apic.c
21071 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
21072 /*
21073 * Debug level, exported for io_apic.c
21074 */
21075 -unsigned int apic_verbosity;
21076 +int apic_verbosity;
21077
21078 int pic_mode;
21079
21080 @@ -2000,7 +2000,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
21081 apic_write(APIC_ESR, 0);
21082 v = apic_read(APIC_ESR);
21083 ack_APIC_irq();
21084 - atomic_inc(&irq_err_count);
21085 + atomic_inc_unchecked(&irq_err_count);
21086
21087 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
21088 smp_processor_id(), v);
21089 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
21090 index 7c1b294..e71d27f 100644
21091 --- a/arch/x86/kernel/apic/apic_flat_64.c
21092 +++ b/arch/x86/kernel/apic/apic_flat_64.c
21093 @@ -154,7 +154,7 @@ static int flat_probe(void)
21094 return 1;
21095 }
21096
21097 -static struct apic apic_flat = {
21098 +static struct apic apic_flat __read_only = {
21099 .name = "flat",
21100 .probe = flat_probe,
21101 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
21102 @@ -268,7 +268,7 @@ static int physflat_probe(void)
21103 return 0;
21104 }
21105
21106 -static struct apic apic_physflat = {
21107 +static struct apic apic_physflat __read_only = {
21108
21109 .name = "physical flat",
21110 .probe = physflat_probe,
21111 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
21112 index 8c7c982..a225910 100644
21113 --- a/arch/x86/kernel/apic/apic_noop.c
21114 +++ b/arch/x86/kernel/apic/apic_noop.c
21115 @@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
21116 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
21117 }
21118
21119 -struct apic apic_noop = {
21120 +struct apic apic_noop __read_only = {
21121 .name = "noop",
21122 .probe = noop_probe,
21123 .acpi_madt_oem_check = NULL,
21124 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
21125 index e4840aa..e7d9dac 100644
21126 --- a/arch/x86/kernel/apic/bigsmp_32.c
21127 +++ b/arch/x86/kernel/apic/bigsmp_32.c
21128 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
21129 return dmi_bigsmp;
21130 }
21131
21132 -static struct apic apic_bigsmp = {
21133 +static struct apic apic_bigsmp __read_only = {
21134
21135 .name = "bigsmp",
21136 .probe = probe_bigsmp,
21137 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
21138 index 81e08ef..abc77e5 100644
21139 --- a/arch/x86/kernel/apic/io_apic.c
21140 +++ b/arch/x86/kernel/apic/io_apic.c
21141 @@ -1042,7 +1042,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
21142 }
21143 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
21144
21145 -void lock_vector_lock(void)
21146 +void lock_vector_lock(void) __acquires(vector_lock)
21147 {
21148 /* Used to the online set of cpus does not change
21149 * during assign_irq_vector.
21150 @@ -1050,7 +1050,7 @@ void lock_vector_lock(void)
21151 raw_spin_lock(&vector_lock);
21152 }
21153
21154 -void unlock_vector_lock(void)
21155 +void unlock_vector_lock(void) __releases(vector_lock)
21156 {
21157 raw_spin_unlock(&vector_lock);
21158 }
21159 @@ -2349,7 +2349,7 @@ static void ack_apic_edge(struct irq_data *data)
21160 ack_APIC_irq();
21161 }
21162
21163 -atomic_t irq_mis_count;
21164 +atomic_unchecked_t irq_mis_count;
21165
21166 #ifdef CONFIG_GENERIC_PENDING_IRQ
21167 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
21168 @@ -2490,7 +2490,7 @@ static void ack_apic_level(struct irq_data *data)
21169 * at the cpu.
21170 */
21171 if (!(v & (1 << (i & 0x1f)))) {
21172 - atomic_inc(&irq_mis_count);
21173 + atomic_inc_unchecked(&irq_mis_count);
21174
21175 eoi_ioapic_irq(irq, cfg);
21176 }
21177 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
21178 index cceb352..a635fd8 100644
21179 --- a/arch/x86/kernel/apic/probe_32.c
21180 +++ b/arch/x86/kernel/apic/probe_32.c
21181 @@ -72,7 +72,7 @@ static int probe_default(void)
21182 return 1;
21183 }
21184
21185 -static struct apic apic_default = {
21186 +static struct apic apic_default __read_only = {
21187
21188 .name = "default",
21189 .probe = probe_default,
21190 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21191 index e66766b..1c008ba 100644
21192 --- a/arch/x86/kernel/apic/x2apic_cluster.c
21193 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
21194 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21195 return notifier_from_errno(err);
21196 }
21197
21198 -static struct notifier_block __refdata x2apic_cpu_notifier = {
21199 +static struct notifier_block x2apic_cpu_notifier = {
21200 .notifier_call = update_clusterinfo,
21201 };
21202
21203 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21204 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21205 }
21206
21207 -static struct apic apic_x2apic_cluster = {
21208 +static struct apic apic_x2apic_cluster __read_only = {
21209
21210 .name = "cluster x2apic",
21211 .probe = x2apic_cluster_probe,
21212 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21213 index 6d600eb..0300c00 100644
21214 --- a/arch/x86/kernel/apic/x2apic_phys.c
21215 +++ b/arch/x86/kernel/apic/x2apic_phys.c
21216 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21217 return apic == &apic_x2apic_phys;
21218 }
21219
21220 -static struct apic apic_x2apic_phys = {
21221 +static struct apic apic_x2apic_phys __read_only = {
21222
21223 .name = "physical x2apic",
21224 .probe = x2apic_phys_probe,
21225 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21226 index 293b41d..4df25fd 100644
21227 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
21228 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21229 @@ -350,7 +350,7 @@ static int uv_probe(void)
21230 return apic == &apic_x2apic_uv_x;
21231 }
21232
21233 -static struct apic __refdata apic_x2apic_uv_x = {
21234 +static struct apic apic_x2apic_uv_x __read_only = {
21235
21236 .name = "UV large system",
21237 .probe = uv_probe,
21238 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21239 index 5848744..56cb598 100644
21240 --- a/arch/x86/kernel/apm_32.c
21241 +++ b/arch/x86/kernel/apm_32.c
21242 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21243 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21244 * even though they are called in protected mode.
21245 */
21246 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21247 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21248 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21249
21250 static const char driver_version[] = "1.16ac"; /* no spaces */
21251 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21252 BUG_ON(cpu != 0);
21253 gdt = get_cpu_gdt_table(cpu);
21254 save_desc_40 = gdt[0x40 / 8];
21255 +
21256 + pax_open_kernel();
21257 gdt[0x40 / 8] = bad_bios_desc;
21258 + pax_close_kernel();
21259
21260 apm_irq_save(flags);
21261 APM_DO_SAVE_SEGS;
21262 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21263 &call->esi);
21264 APM_DO_RESTORE_SEGS;
21265 apm_irq_restore(flags);
21266 +
21267 + pax_open_kernel();
21268 gdt[0x40 / 8] = save_desc_40;
21269 + pax_close_kernel();
21270 +
21271 put_cpu();
21272
21273 return call->eax & 0xff;
21274 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21275 BUG_ON(cpu != 0);
21276 gdt = get_cpu_gdt_table(cpu);
21277 save_desc_40 = gdt[0x40 / 8];
21278 +
21279 + pax_open_kernel();
21280 gdt[0x40 / 8] = bad_bios_desc;
21281 + pax_close_kernel();
21282
21283 apm_irq_save(flags);
21284 APM_DO_SAVE_SEGS;
21285 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21286 &call->eax);
21287 APM_DO_RESTORE_SEGS;
21288 apm_irq_restore(flags);
21289 +
21290 + pax_open_kernel();
21291 gdt[0x40 / 8] = save_desc_40;
21292 + pax_close_kernel();
21293 +
21294 put_cpu();
21295 return error;
21296 }
21297 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21298 * code to that CPU.
21299 */
21300 gdt = get_cpu_gdt_table(0);
21301 +
21302 + pax_open_kernel();
21303 set_desc_base(&gdt[APM_CS >> 3],
21304 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21305 set_desc_base(&gdt[APM_CS_16 >> 3],
21306 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21307 set_desc_base(&gdt[APM_DS >> 3],
21308 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21309 + pax_close_kernel();
21310
21311 proc_create("apm", 0, NULL, &apm_file_ops);
21312
21313 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21314 index 9f6b934..cf5ffb3 100644
21315 --- a/arch/x86/kernel/asm-offsets.c
21316 +++ b/arch/x86/kernel/asm-offsets.c
21317 @@ -32,6 +32,8 @@ void common(void) {
21318 OFFSET(TI_flags, thread_info, flags);
21319 OFFSET(TI_status, thread_info, status);
21320 OFFSET(TI_addr_limit, thread_info, addr_limit);
21321 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21322 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21323
21324 BLANK();
21325 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21326 @@ -52,8 +54,26 @@ void common(void) {
21327 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21328 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21329 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21330 +
21331 +#ifdef CONFIG_PAX_KERNEXEC
21332 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21333 #endif
21334
21335 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21336 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21337 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21338 +#ifdef CONFIG_X86_64
21339 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21340 +#endif
21341 +#endif
21342 +
21343 +#endif
21344 +
21345 + BLANK();
21346 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21347 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21348 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21349 +
21350 #ifdef CONFIG_XEN
21351 BLANK();
21352 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21353 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21354 index e7c798b..2b2019b 100644
21355 --- a/arch/x86/kernel/asm-offsets_64.c
21356 +++ b/arch/x86/kernel/asm-offsets_64.c
21357 @@ -77,6 +77,7 @@ int main(void)
21358 BLANK();
21359 #undef ENTRY
21360
21361 + DEFINE(TSS_size, sizeof(struct tss_struct));
21362 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21363 BLANK();
21364
21365 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21366 index 7fd54f0..0691410 100644
21367 --- a/arch/x86/kernel/cpu/Makefile
21368 +++ b/arch/x86/kernel/cpu/Makefile
21369 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21370 CFLAGS_REMOVE_perf_event.o = -pg
21371 endif
21372
21373 -# Make sure load_percpu_segment has no stackprotector
21374 -nostackp := $(call cc-option, -fno-stack-protector)
21375 -CFLAGS_common.o := $(nostackp)
21376 -
21377 obj-y := intel_cacheinfo.o scattered.o topology.o
21378 obj-y += proc.o capflags.o powerflags.o common.o
21379 obj-y += rdrand.o
21380 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21381 index ce8b8ff..d7d8851 100644
21382 --- a/arch/x86/kernel/cpu/amd.c
21383 +++ b/arch/x86/kernel/cpu/amd.c
21384 @@ -728,7 +728,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21385 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21386 {
21387 /* AMD errata T13 (order #21922) */
21388 - if ((c->x86 == 6)) {
21389 + if (c->x86 == 6) {
21390 /* Duron Rev A0 */
21391 if (c->x86_model == 3 && c->x86_mask == 0)
21392 size = 64;
21393 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21394 index ef1b93f..150db65 100644
21395 --- a/arch/x86/kernel/cpu/common.c
21396 +++ b/arch/x86/kernel/cpu/common.c
21397 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21398
21399 static const struct cpu_dev *this_cpu = &default_cpu;
21400
21401 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21402 -#ifdef CONFIG_X86_64
21403 - /*
21404 - * We need valid kernel segments for data and code in long mode too
21405 - * IRET will check the segment types kkeil 2000/10/28
21406 - * Also sysret mandates a special GDT layout
21407 - *
21408 - * TLS descriptors are currently at a different place compared to i386.
21409 - * Hopefully nobody expects them at a fixed place (Wine?)
21410 - */
21411 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21412 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21413 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21414 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21415 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21416 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21417 -#else
21418 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21419 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21420 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21421 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21422 - /*
21423 - * Segments used for calling PnP BIOS have byte granularity.
21424 - * They code segments and data segments have fixed 64k limits,
21425 - * the transfer segment sizes are set at run time.
21426 - */
21427 - /* 32-bit code */
21428 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21429 - /* 16-bit code */
21430 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21431 - /* 16-bit data */
21432 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21433 - /* 16-bit data */
21434 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21435 - /* 16-bit data */
21436 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21437 - /*
21438 - * The APM segments have byte granularity and their bases
21439 - * are set at run time. All have 64k limits.
21440 - */
21441 - /* 32-bit code */
21442 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21443 - /* 16-bit code */
21444 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21445 - /* data */
21446 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21447 -
21448 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21449 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21450 - GDT_STACK_CANARY_INIT
21451 -#endif
21452 -} };
21453 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21454 -
21455 static int __init x86_xsave_setup(char *s)
21456 {
21457 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21458 @@ -295,6 +241,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21459 }
21460 }
21461
21462 +#ifdef CONFIG_X86_64
21463 +static __init int setup_disable_pcid(char *arg)
21464 +{
21465 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21466 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21467 +
21468 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21469 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21470 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21471 +#endif
21472 +
21473 + return 1;
21474 +}
21475 +__setup("nopcid", setup_disable_pcid);
21476 +
21477 +static void setup_pcid(struct cpuinfo_x86 *c)
21478 +{
21479 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21480 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21481 +
21482 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21483 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21484 + pax_open_kernel();
21485 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21486 + pax_close_kernel();
21487 + printk("PAX: slow and weak UDEREF enabled\n");
21488 + } else
21489 + printk("PAX: UDEREF disabled\n");
21490 +#endif
21491 +
21492 + return;
21493 + }
21494 +
21495 + printk("PAX: PCID detected\n");
21496 + set_in_cr4(X86_CR4_PCIDE);
21497 +
21498 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21499 + pax_open_kernel();
21500 + clone_pgd_mask = ~(pgdval_t)0UL;
21501 + pax_close_kernel();
21502 + if (pax_user_shadow_base)
21503 + printk("PAX: weak UDEREF enabled\n");
21504 + else {
21505 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21506 + printk("PAX: strong UDEREF enabled\n");
21507 + }
21508 +#endif
21509 +
21510 + if (cpu_has(c, X86_FEATURE_INVPCID))
21511 + printk("PAX: INVPCID detected\n");
21512 +}
21513 +#endif
21514 +
21515 /*
21516 * Some CPU features depend on higher CPUID levels, which may not always
21517 * be available due to CPUID level capping or broken virtualization
21518 @@ -395,7 +394,7 @@ void switch_to_new_gdt(int cpu)
21519 {
21520 struct desc_ptr gdt_descr;
21521
21522 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21523 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21524 gdt_descr.size = GDT_SIZE - 1;
21525 load_gdt(&gdt_descr);
21526 /* Reload the per-cpu base */
21527 @@ -885,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21528 setup_smep(c);
21529 setup_smap(c);
21530
21531 +#ifdef CONFIG_X86_64
21532 + setup_pcid(c);
21533 +#endif
21534 +
21535 /*
21536 * The vendor-specific functions might have changed features.
21537 * Now we do "generic changes."
21538 @@ -893,6 +896,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21539 /* Filter out anything that depends on CPUID levels we don't have */
21540 filter_cpuid_features(c, true);
21541
21542 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21543 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21544 +#endif
21545 +
21546 /* If the model name is still unset, do table lookup. */
21547 if (!c->x86_model_id[0]) {
21548 const char *p;
21549 @@ -973,7 +980,7 @@ static void syscall32_cpu_init(void)
21550 void enable_sep_cpu(void)
21551 {
21552 int cpu = get_cpu();
21553 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21554 + struct tss_struct *tss = init_tss + cpu;
21555
21556 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21557 put_cpu();
21558 @@ -1113,14 +1120,16 @@ static __init int setup_disablecpuid(char *arg)
21559 }
21560 __setup("clearcpuid=", setup_disablecpuid);
21561
21562 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21563 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21564 +
21565 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21566 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21567 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21568 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21569
21570 #ifdef CONFIG_X86_64
21571 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21572 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21573 - (unsigned long) debug_idt_table };
21574 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21575 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21576
21577 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21578 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21579 @@ -1283,7 +1292,7 @@ void cpu_init(void)
21580 load_ucode_ap();
21581
21582 cpu = stack_smp_processor_id();
21583 - t = &per_cpu(init_tss, cpu);
21584 + t = init_tss + cpu;
21585 oist = &per_cpu(orig_ist, cpu);
21586
21587 #ifdef CONFIG_NUMA
21588 @@ -1318,7 +1327,6 @@ void cpu_init(void)
21589 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21590 barrier();
21591
21592 - x86_configure_nx();
21593 enable_x2apic();
21594
21595 /*
21596 @@ -1370,7 +1378,7 @@ void cpu_init(void)
21597 {
21598 int cpu = smp_processor_id();
21599 struct task_struct *curr = current;
21600 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21601 + struct tss_struct *t = init_tss + cpu;
21602 struct thread_struct *thread = &curr->thread;
21603
21604 show_ucode_info_early();
21605 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21606 index 9c8f739..902a9c5 100644
21607 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21608 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21609 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21610 };
21611
21612 #ifdef CONFIG_AMD_NB
21613 +static struct attribute *default_attrs_amd_nb[] = {
21614 + &type.attr,
21615 + &level.attr,
21616 + &coherency_line_size.attr,
21617 + &physical_line_partition.attr,
21618 + &ways_of_associativity.attr,
21619 + &number_of_sets.attr,
21620 + &size.attr,
21621 + &shared_cpu_map.attr,
21622 + &shared_cpu_list.attr,
21623 + NULL,
21624 + NULL,
21625 + NULL,
21626 + NULL
21627 +};
21628 +
21629 static struct attribute **amd_l3_attrs(void)
21630 {
21631 static struct attribute **attrs;
21632 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21633
21634 n = ARRAY_SIZE(default_attrs);
21635
21636 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21637 - n += 2;
21638 -
21639 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21640 - n += 1;
21641 -
21642 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21643 - if (attrs == NULL)
21644 - return attrs = default_attrs;
21645 -
21646 - for (n = 0; default_attrs[n]; n++)
21647 - attrs[n] = default_attrs[n];
21648 + attrs = default_attrs_amd_nb;
21649
21650 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21651 attrs[n++] = &cache_disable_0.attr;
21652 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21653 .default_attrs = default_attrs,
21654 };
21655
21656 +#ifdef CONFIG_AMD_NB
21657 +static struct kobj_type ktype_cache_amd_nb = {
21658 + .sysfs_ops = &sysfs_ops,
21659 + .default_attrs = default_attrs_amd_nb,
21660 +};
21661 +#endif
21662 +
21663 static struct kobj_type ktype_percpu_entry = {
21664 .sysfs_ops = &sysfs_ops,
21665 };
21666 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21667 return retval;
21668 }
21669
21670 +#ifdef CONFIG_AMD_NB
21671 + amd_l3_attrs();
21672 +#endif
21673 +
21674 for (i = 0; i < num_cache_leaves; i++) {
21675 + struct kobj_type *ktype;
21676 +
21677 this_object = INDEX_KOBJECT_PTR(cpu, i);
21678 this_object->cpu = cpu;
21679 this_object->index = i;
21680
21681 this_leaf = CPUID4_INFO_IDX(cpu, i);
21682
21683 - ktype_cache.default_attrs = default_attrs;
21684 + ktype = &ktype_cache;
21685 #ifdef CONFIG_AMD_NB
21686 if (this_leaf->base.nb)
21687 - ktype_cache.default_attrs = amd_l3_attrs();
21688 + ktype = &ktype_cache_amd_nb;
21689 #endif
21690 retval = kobject_init_and_add(&(this_object->kobj),
21691 - &ktype_cache,
21692 + ktype,
21693 per_cpu(ici_cache_kobject, cpu),
21694 "index%1lu", i);
21695 if (unlikely(retval)) {
21696 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21697 index 9a79c8d..158c2f1 100644
21698 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21699 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21700 @@ -45,6 +45,7 @@
21701 #include <asm/processor.h>
21702 #include <asm/mce.h>
21703 #include <asm/msr.h>
21704 +#include <asm/local.h>
21705
21706 #include "mce-internal.h"
21707
21708 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21709 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21710 m->cs, m->ip);
21711
21712 - if (m->cs == __KERNEL_CS)
21713 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21714 print_symbol("{%s}", m->ip);
21715 pr_cont("\n");
21716 }
21717 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21718
21719 #define PANIC_TIMEOUT 5 /* 5 seconds */
21720
21721 -static atomic_t mce_paniced;
21722 +static atomic_unchecked_t mce_paniced;
21723
21724 static int fake_panic;
21725 -static atomic_t mce_fake_paniced;
21726 +static atomic_unchecked_t mce_fake_paniced;
21727
21728 /* Panic in progress. Enable interrupts and wait for final IPI */
21729 static void wait_for_panic(void)
21730 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21731 /*
21732 * Make sure only one CPU runs in machine check panic
21733 */
21734 - if (atomic_inc_return(&mce_paniced) > 1)
21735 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21736 wait_for_panic();
21737 barrier();
21738
21739 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21740 console_verbose();
21741 } else {
21742 /* Don't log too much for fake panic */
21743 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21744 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21745 return;
21746 }
21747 /* First print corrected ones that are still unlogged */
21748 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21749 if (!fake_panic) {
21750 if (panic_timeout == 0)
21751 panic_timeout = mca_cfg.panic_timeout;
21752 - panic(msg);
21753 + panic("%s", msg);
21754 } else
21755 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21756 }
21757 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21758 * might have been modified by someone else.
21759 */
21760 rmb();
21761 - if (atomic_read(&mce_paniced))
21762 + if (atomic_read_unchecked(&mce_paniced))
21763 wait_for_panic();
21764 if (!mca_cfg.monarch_timeout)
21765 goto out;
21766 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21767 }
21768
21769 /* Call the installed machine check handler for this CPU setup. */
21770 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21771 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21772 unexpected_machine_check;
21773
21774 /*
21775 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21776 return;
21777 }
21778
21779 + pax_open_kernel();
21780 machine_check_vector = do_machine_check;
21781 + pax_close_kernel();
21782
21783 __mcheck_cpu_init_generic();
21784 __mcheck_cpu_init_vendor(c);
21785 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21786 */
21787
21788 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21789 -static int mce_chrdev_open_count; /* #times opened */
21790 +static local_t mce_chrdev_open_count; /* #times opened */
21791 static int mce_chrdev_open_exclu; /* already open exclusive? */
21792
21793 static int mce_chrdev_open(struct inode *inode, struct file *file)
21794 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21795 spin_lock(&mce_chrdev_state_lock);
21796
21797 if (mce_chrdev_open_exclu ||
21798 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21799 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21800 spin_unlock(&mce_chrdev_state_lock);
21801
21802 return -EBUSY;
21803 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21804
21805 if (file->f_flags & O_EXCL)
21806 mce_chrdev_open_exclu = 1;
21807 - mce_chrdev_open_count++;
21808 + local_inc(&mce_chrdev_open_count);
21809
21810 spin_unlock(&mce_chrdev_state_lock);
21811
21812 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21813 {
21814 spin_lock(&mce_chrdev_state_lock);
21815
21816 - mce_chrdev_open_count--;
21817 + local_dec(&mce_chrdev_open_count);
21818 mce_chrdev_open_exclu = 0;
21819
21820 spin_unlock(&mce_chrdev_state_lock);
21821 @@ -2414,7 +2417,7 @@ static __init void mce_init_banks(void)
21822
21823 for (i = 0; i < mca_cfg.banks; i++) {
21824 struct mce_bank *b = &mce_banks[i];
21825 - struct device_attribute *a = &b->attr;
21826 + device_attribute_no_const *a = &b->attr;
21827
21828 sysfs_attr_init(&a->attr);
21829 a->attr.name = b->attrname;
21830 @@ -2521,7 +2524,7 @@ struct dentry *mce_get_debugfs_dir(void)
21831 static void mce_reset(void)
21832 {
21833 cpu_missing = 0;
21834 - atomic_set(&mce_fake_paniced, 0);
21835 + atomic_set_unchecked(&mce_fake_paniced, 0);
21836 atomic_set(&mce_executing, 0);
21837 atomic_set(&mce_callin, 0);
21838 atomic_set(&global_nwo, 0);
21839 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21840 index a304298..49b6d06 100644
21841 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21842 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21843 @@ -10,6 +10,7 @@
21844 #include <asm/processor.h>
21845 #include <asm/mce.h>
21846 #include <asm/msr.h>
21847 +#include <asm/pgtable.h>
21848
21849 /* By default disabled */
21850 int mce_p5_enabled __read_mostly;
21851 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21852 if (!cpu_has(c, X86_FEATURE_MCE))
21853 return;
21854
21855 + pax_open_kernel();
21856 machine_check_vector = pentium_machine_check;
21857 + pax_close_kernel();
21858 /* Make sure the vector pointer is visible before we enable MCEs: */
21859 wmb();
21860
21861 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21862 index 7dc5564..1273569 100644
21863 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21864 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21865 @@ -9,6 +9,7 @@
21866 #include <asm/processor.h>
21867 #include <asm/mce.h>
21868 #include <asm/msr.h>
21869 +#include <asm/pgtable.h>
21870
21871 /* Machine check handler for WinChip C6: */
21872 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21873 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21874 {
21875 u32 lo, hi;
21876
21877 + pax_open_kernel();
21878 machine_check_vector = winchip_machine_check;
21879 + pax_close_kernel();
21880 /* Make sure the vector pointer is visible before we enable MCEs: */
21881 wmb();
21882
21883 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21884 index dd9d619..86e1d81 100644
21885 --- a/arch/x86/kernel/cpu/microcode/core.c
21886 +++ b/arch/x86/kernel/cpu/microcode/core.c
21887 @@ -516,7 +516,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21888 return NOTIFY_OK;
21889 }
21890
21891 -static struct notifier_block __refdata mc_cpu_notifier = {
21892 +static struct notifier_block mc_cpu_notifier = {
21893 .notifier_call = mc_cpu_callback,
21894 };
21895
21896 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21897 index a276fa7..e66810f 100644
21898 --- a/arch/x86/kernel/cpu/microcode/intel.c
21899 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21900 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21901
21902 static int get_ucode_user(void *to, const void *from, size_t n)
21903 {
21904 - return copy_from_user(to, from, n);
21905 + return copy_from_user(to, (const void __force_user *)from, n);
21906 }
21907
21908 static enum ucode_state
21909 request_microcode_user(int cpu, const void __user *buf, size_t size)
21910 {
21911 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21912 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21913 }
21914
21915 static void microcode_fini_cpu(int cpu)
21916 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21917 index f961de9..8a9d332 100644
21918 --- a/arch/x86/kernel/cpu/mtrr/main.c
21919 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21920 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21921 u64 size_or_mask, size_and_mask;
21922 static bool mtrr_aps_delayed_init;
21923
21924 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21925 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21926
21927 const struct mtrr_ops *mtrr_if;
21928
21929 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21930 index df5e41f..816c719 100644
21931 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21932 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21933 @@ -25,7 +25,7 @@ struct mtrr_ops {
21934 int (*validate_add_page)(unsigned long base, unsigned long size,
21935 unsigned int type);
21936 int (*have_wrcomb)(void);
21937 -};
21938 +} __do_const;
21939
21940 extern int generic_get_free_region(unsigned long base, unsigned long size,
21941 int replace_reg);
21942 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21943 index 2879ecd..bb8c80b 100644
21944 --- a/arch/x86/kernel/cpu/perf_event.c
21945 +++ b/arch/x86/kernel/cpu/perf_event.c
21946 @@ -1372,7 +1372,7 @@ static void __init pmu_check_apic(void)
21947
21948 }
21949
21950 -static struct attribute_group x86_pmu_format_group = {
21951 +static attribute_group_no_const x86_pmu_format_group = {
21952 .name = "format",
21953 .attrs = NULL,
21954 };
21955 @@ -1471,7 +1471,7 @@ static struct attribute *events_attr[] = {
21956 NULL,
21957 };
21958
21959 -static struct attribute_group x86_pmu_events_group = {
21960 +static attribute_group_no_const x86_pmu_events_group = {
21961 .name = "events",
21962 .attrs = events_attr,
21963 };
21964 @@ -1995,7 +1995,7 @@ static unsigned long get_segment_base(unsigned int segment)
21965 if (idx > GDT_ENTRIES)
21966 return 0;
21967
21968 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21969 + desc = get_cpu_gdt_table(smp_processor_id());
21970 }
21971
21972 return get_desc_base(desc + idx);
21973 @@ -2085,7 +2085,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21974 break;
21975
21976 perf_callchain_store(entry, frame.return_address);
21977 - fp = frame.next_frame;
21978 + fp = (const void __force_user *)frame.next_frame;
21979 }
21980 }
21981
21982 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21983 index 639d128..e92d7e5 100644
21984 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21985 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21986 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21987 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21988 {
21989 struct attribute **attrs;
21990 - struct attribute_group *attr_group;
21991 + attribute_group_no_const *attr_group;
21992 int i = 0, j;
21993
21994 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21995 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21996 index 2502d0d..e5cc05c 100644
21997 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21998 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21999 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
22000 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
22001
22002 if (boot_cpu_has(X86_FEATURE_PDCM)) {
22003 - u64 capabilities;
22004 + u64 capabilities = x86_pmu.intel_cap.capabilities;
22005
22006 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
22007 - x86_pmu.intel_cap.capabilities = capabilities;
22008 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
22009 + x86_pmu.intel_cap.capabilities = capabilities;
22010 }
22011
22012 intel_ds_init();
22013 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22014 index 619f769..d510008 100644
22015 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22016 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22017 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
22018 NULL,
22019 };
22020
22021 -static struct attribute_group rapl_pmu_events_group = {
22022 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
22023 .name = "events",
22024 .attrs = NULL, /* patched at runtime */
22025 };
22026 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22027 index ae6552a..b5be2d3 100644
22028 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22029 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22030 @@ -3694,7 +3694,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
22031 static int __init uncore_type_init(struct intel_uncore_type *type)
22032 {
22033 struct intel_uncore_pmu *pmus;
22034 - struct attribute_group *attr_group;
22035 + attribute_group_no_const *attr_group;
22036 struct attribute **attrs;
22037 int i, j;
22038
22039 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22040 index 90236f0..54cb20d 100644
22041 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22042 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22043 @@ -503,7 +503,7 @@ struct intel_uncore_box {
22044 struct uncore_event_desc {
22045 struct kobj_attribute attr;
22046 const char *config;
22047 -};
22048 +} __do_const;
22049
22050 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
22051 { \
22052 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
22053 index 3225ae6c..ee3c6db 100644
22054 --- a/arch/x86/kernel/cpuid.c
22055 +++ b/arch/x86/kernel/cpuid.c
22056 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
22057 return notifier_from_errno(err);
22058 }
22059
22060 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
22061 +static struct notifier_block cpuid_class_cpu_notifier =
22062 {
22063 .notifier_call = cpuid_class_cpu_callback,
22064 };
22065 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
22066 index 507de80..ebaae2a 100644
22067 --- a/arch/x86/kernel/crash.c
22068 +++ b/arch/x86/kernel/crash.c
22069 @@ -58,7 +58,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
22070 #ifdef CONFIG_X86_32
22071 struct pt_regs fixed_regs;
22072
22073 - if (!user_mode_vm(regs)) {
22074 + if (!user_mode(regs)) {
22075 crash_fixup_ss_esp(&fixed_regs, regs);
22076 regs = &fixed_regs;
22077 }
22078 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
22079 index afa64ad..dce67dd 100644
22080 --- a/arch/x86/kernel/crash_dump_64.c
22081 +++ b/arch/x86/kernel/crash_dump_64.c
22082 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
22083 return -ENOMEM;
22084
22085 if (userbuf) {
22086 - if (copy_to_user(buf, vaddr + offset, csize)) {
22087 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
22088 iounmap(vaddr);
22089 return -EFAULT;
22090 }
22091 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
22092 index f6dfd93..892ade4 100644
22093 --- a/arch/x86/kernel/doublefault.c
22094 +++ b/arch/x86/kernel/doublefault.c
22095 @@ -12,7 +12,7 @@
22096
22097 #define DOUBLEFAULT_STACKSIZE (1024)
22098 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
22099 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
22100 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
22101
22102 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
22103
22104 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
22105 unsigned long gdt, tss;
22106
22107 native_store_gdt(&gdt_desc);
22108 - gdt = gdt_desc.address;
22109 + gdt = (unsigned long)gdt_desc.address;
22110
22111 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
22112
22113 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
22114 /* 0x2 bit is always set */
22115 .flags = X86_EFLAGS_SF | 0x2,
22116 .sp = STACK_START,
22117 - .es = __USER_DS,
22118 + .es = __KERNEL_DS,
22119 .cs = __KERNEL_CS,
22120 .ss = __KERNEL_DS,
22121 - .ds = __USER_DS,
22122 + .ds = __KERNEL_DS,
22123 .fs = __KERNEL_PERCPU,
22124
22125 .__cr3 = __pa_nodebug(swapper_pg_dir),
22126 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
22127 index b74ebc7..6dbb0c5 100644
22128 --- a/arch/x86/kernel/dumpstack.c
22129 +++ b/arch/x86/kernel/dumpstack.c
22130 @@ -2,6 +2,9 @@
22131 * Copyright (C) 1991, 1992 Linus Torvalds
22132 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
22133 */
22134 +#ifdef CONFIG_GRKERNSEC_HIDESYM
22135 +#define __INCLUDED_BY_HIDESYM 1
22136 +#endif
22137 #include <linux/kallsyms.h>
22138 #include <linux/kprobes.h>
22139 #include <linux/uaccess.h>
22140 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
22141 static void
22142 print_ftrace_graph_addr(unsigned long addr, void *data,
22143 const struct stacktrace_ops *ops,
22144 - struct thread_info *tinfo, int *graph)
22145 + struct task_struct *task, int *graph)
22146 {
22147 - struct task_struct *task;
22148 unsigned long ret_addr;
22149 int index;
22150
22151 if (addr != (unsigned long)return_to_handler)
22152 return;
22153
22154 - task = tinfo->task;
22155 index = task->curr_ret_stack;
22156
22157 if (!task->ret_stack || index < *graph)
22158 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22159 static inline void
22160 print_ftrace_graph_addr(unsigned long addr, void *data,
22161 const struct stacktrace_ops *ops,
22162 - struct thread_info *tinfo, int *graph)
22163 + struct task_struct *task, int *graph)
22164 { }
22165 #endif
22166
22167 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22168 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
22169 */
22170
22171 -static inline int valid_stack_ptr(struct thread_info *tinfo,
22172 - void *p, unsigned int size, void *end)
22173 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
22174 {
22175 - void *t = tinfo;
22176 if (end) {
22177 if (p < end && p >= (end-THREAD_SIZE))
22178 return 1;
22179 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
22180 }
22181
22182 unsigned long
22183 -print_context_stack(struct thread_info *tinfo,
22184 +print_context_stack(struct task_struct *task, void *stack_start,
22185 unsigned long *stack, unsigned long bp,
22186 const struct stacktrace_ops *ops, void *data,
22187 unsigned long *end, int *graph)
22188 {
22189 struct stack_frame *frame = (struct stack_frame *)bp;
22190
22191 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22192 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22193 unsigned long addr;
22194
22195 addr = *stack;
22196 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22197 } else {
22198 ops->address(data, addr, 0);
22199 }
22200 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22201 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22202 }
22203 stack++;
22204 }
22205 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22206 EXPORT_SYMBOL_GPL(print_context_stack);
22207
22208 unsigned long
22209 -print_context_stack_bp(struct thread_info *tinfo,
22210 +print_context_stack_bp(struct task_struct *task, void *stack_start,
22211 unsigned long *stack, unsigned long bp,
22212 const struct stacktrace_ops *ops, void *data,
22213 unsigned long *end, int *graph)
22214 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22215 struct stack_frame *frame = (struct stack_frame *)bp;
22216 unsigned long *ret_addr = &frame->return_address;
22217
22218 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22219 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22220 unsigned long addr = *ret_addr;
22221
22222 if (!__kernel_text_address(addr))
22223 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22224 ops->address(data, addr, 1);
22225 frame = frame->next_frame;
22226 ret_addr = &frame->return_address;
22227 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22228 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22229 }
22230
22231 return (unsigned long)frame;
22232 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22233 static void print_trace_address(void *data, unsigned long addr, int reliable)
22234 {
22235 touch_nmi_watchdog();
22236 - printk(data);
22237 + printk("%s", (char *)data);
22238 printk_stack_address(addr, reliable);
22239 }
22240
22241 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22242 EXPORT_SYMBOL_GPL(oops_begin);
22243 NOKPROBE_SYMBOL(oops_begin);
22244
22245 +extern void gr_handle_kernel_exploit(void);
22246 +
22247 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22248 {
22249 if (regs && kexec_should_crash(current))
22250 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22251 panic("Fatal exception in interrupt");
22252 if (panic_on_oops)
22253 panic("Fatal exception");
22254 - do_exit(signr);
22255 +
22256 + gr_handle_kernel_exploit();
22257 +
22258 + do_group_exit(signr);
22259 }
22260 NOKPROBE_SYMBOL(oops_end);
22261
22262 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22263 print_modules();
22264 show_regs(regs);
22265 #ifdef CONFIG_X86_32
22266 - if (user_mode_vm(regs)) {
22267 + if (user_mode(regs)) {
22268 sp = regs->sp;
22269 ss = regs->ss & 0xffff;
22270 } else {
22271 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22272 unsigned long flags = oops_begin();
22273 int sig = SIGSEGV;
22274
22275 - if (!user_mode_vm(regs))
22276 + if (!user_mode(regs))
22277 report_bug(regs->ip, regs);
22278
22279 if (__die(str, regs, err))
22280 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22281 index 5abd4cd..c65733b 100644
22282 --- a/arch/x86/kernel/dumpstack_32.c
22283 +++ b/arch/x86/kernel/dumpstack_32.c
22284 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22285 bp = stack_frame(task, regs);
22286
22287 for (;;) {
22288 - struct thread_info *context;
22289 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22290 void *end_stack;
22291
22292 end_stack = is_hardirq_stack(stack, cpu);
22293 if (!end_stack)
22294 end_stack = is_softirq_stack(stack, cpu);
22295
22296 - context = task_thread_info(task);
22297 - bp = ops->walk_stack(context, stack, bp, ops, data,
22298 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22299 end_stack, &graph);
22300
22301 /* Stop if not on irq stack */
22302 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22303 int i;
22304
22305 show_regs_print_info(KERN_EMERG);
22306 - __show_regs(regs, !user_mode_vm(regs));
22307 + __show_regs(regs, !user_mode(regs));
22308
22309 /*
22310 * When in-kernel, we also print out the stack and code at the
22311 * time of the fault..
22312 */
22313 - if (!user_mode_vm(regs)) {
22314 + if (!user_mode(regs)) {
22315 unsigned int code_prologue = code_bytes * 43 / 64;
22316 unsigned int code_len = code_bytes;
22317 unsigned char c;
22318 u8 *ip;
22319 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22320
22321 pr_emerg("Stack:\n");
22322 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22323
22324 pr_emerg("Code:");
22325
22326 - ip = (u8 *)regs->ip - code_prologue;
22327 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22328 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22329 /* try starting at IP */
22330 - ip = (u8 *)regs->ip;
22331 + ip = (u8 *)regs->ip + cs_base;
22332 code_len = code_len - code_prologue + 1;
22333 }
22334 for (i = 0; i < code_len; i++, ip++) {
22335 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22336 pr_cont(" Bad EIP value.");
22337 break;
22338 }
22339 - if (ip == (u8 *)regs->ip)
22340 + if (ip == (u8 *)regs->ip + cs_base)
22341 pr_cont(" <%02x>", c);
22342 else
22343 pr_cont(" %02x", c);
22344 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22345 {
22346 unsigned short ud2;
22347
22348 + ip = ktla_ktva(ip);
22349 if (ip < PAGE_OFFSET)
22350 return 0;
22351 if (probe_kernel_address((unsigned short *)ip, ud2))
22352 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22353
22354 return ud2 == 0x0b0f;
22355 }
22356 +
22357 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22358 +void pax_check_alloca(unsigned long size)
22359 +{
22360 + unsigned long sp = (unsigned long)&sp, stack_left;
22361 +
22362 + /* all kernel stacks are of the same size */
22363 + stack_left = sp & (THREAD_SIZE - 1);
22364 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22365 +}
22366 +EXPORT_SYMBOL(pax_check_alloca);
22367 +#endif
22368 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22369 index 1abcb50..6c8d702 100644
22370 --- a/arch/x86/kernel/dumpstack_64.c
22371 +++ b/arch/x86/kernel/dumpstack_64.c
22372 @@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22373 const struct stacktrace_ops *ops, void *data)
22374 {
22375 const unsigned cpu = get_cpu();
22376 - struct thread_info *tinfo;
22377 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22378 unsigned long dummy;
22379 unsigned used = 0;
22380 int graph = 0;
22381 int done = 0;
22382 + void *stack_start;
22383
22384 if (!task)
22385 task = current;
22386 @@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22387 * current stack address. If the stacks consist of nested
22388 * exceptions
22389 */
22390 - tinfo = task_thread_info(task);
22391 while (!done) {
22392 unsigned long *stack_end;
22393 enum stack_type stype;
22394 @@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22395 if (ops->stack(data, id) < 0)
22396 break;
22397
22398 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22399 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22400 data, stack_end, &graph);
22401 ops->stack(data, "<EOE>");
22402 /*
22403 @@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22404 * second-to-last pointer (index -2 to end) in the
22405 * exception stack:
22406 */
22407 + if ((u16)stack_end[-1] != __KERNEL_DS)
22408 + goto out;
22409 stack = (unsigned long *) stack_end[-2];
22410 done = 0;
22411 break;
22412 @@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22413
22414 if (ops->stack(data, "IRQ") < 0)
22415 break;
22416 - bp = ops->walk_stack(tinfo, stack, bp,
22417 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22418 ops, data, stack_end, &graph);
22419 /*
22420 * We link to the next stack (which would be
22421 @@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22422 /*
22423 * This handles the process stack:
22424 */
22425 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22426 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22427 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22428 +out:
22429 put_cpu();
22430 }
22431 EXPORT_SYMBOL(dump_trace);
22432 @@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
22433
22434 return ud2 == 0x0b0f;
22435 }
22436 +
22437 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22438 +void pax_check_alloca(unsigned long size)
22439 +{
22440 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22441 + unsigned cpu, used;
22442 + char *id;
22443 +
22444 + /* check the process stack first */
22445 + stack_start = (unsigned long)task_stack_page(current);
22446 + stack_end = stack_start + THREAD_SIZE;
22447 + if (likely(stack_start <= sp && sp < stack_end)) {
22448 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22449 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22450 + return;
22451 + }
22452 +
22453 + cpu = get_cpu();
22454 +
22455 + /* check the irq stacks */
22456 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22457 + stack_start = stack_end - IRQ_STACK_SIZE;
22458 + if (stack_start <= sp && sp < stack_end) {
22459 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22460 + put_cpu();
22461 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22462 + return;
22463 + }
22464 +
22465 + /* check the exception stacks */
22466 + used = 0;
22467 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22468 + stack_start = stack_end - EXCEPTION_STKSZ;
22469 + if (stack_end && stack_start <= sp && sp < stack_end) {
22470 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22471 + put_cpu();
22472 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22473 + return;
22474 + }
22475 +
22476 + put_cpu();
22477 +
22478 + /* unknown stack */
22479 + BUG();
22480 +}
22481 +EXPORT_SYMBOL(pax_check_alloca);
22482 +#endif
22483 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22484 index 988c00a..4f673b6 100644
22485 --- a/arch/x86/kernel/e820.c
22486 +++ b/arch/x86/kernel/e820.c
22487 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22488
22489 static void early_panic(char *msg)
22490 {
22491 - early_printk(msg);
22492 - panic(msg);
22493 + early_printk("%s", msg);
22494 + panic("%s", msg);
22495 }
22496
22497 static int userdef __initdata;
22498 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22499 index 01d1c18..8073693 100644
22500 --- a/arch/x86/kernel/early_printk.c
22501 +++ b/arch/x86/kernel/early_printk.c
22502 @@ -7,6 +7,7 @@
22503 #include <linux/pci_regs.h>
22504 #include <linux/pci_ids.h>
22505 #include <linux/errno.h>
22506 +#include <linux/sched.h>
22507 #include <asm/io.h>
22508 #include <asm/processor.h>
22509 #include <asm/fcntl.h>
22510 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22511 index 0d0c9d4..f65b4f6 100644
22512 --- a/arch/x86/kernel/entry_32.S
22513 +++ b/arch/x86/kernel/entry_32.S
22514 @@ -177,13 +177,153 @@
22515 /*CFI_REL_OFFSET gs, PT_GS*/
22516 .endm
22517 .macro SET_KERNEL_GS reg
22518 +
22519 +#ifdef CONFIG_CC_STACKPROTECTOR
22520 movl $(__KERNEL_STACK_CANARY), \reg
22521 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22522 + movl $(__USER_DS), \reg
22523 +#else
22524 + xorl \reg, \reg
22525 +#endif
22526 +
22527 movl \reg, %gs
22528 .endm
22529
22530 #endif /* CONFIG_X86_32_LAZY_GS */
22531
22532 -.macro SAVE_ALL
22533 +.macro pax_enter_kernel
22534 +#ifdef CONFIG_PAX_KERNEXEC
22535 + call pax_enter_kernel
22536 +#endif
22537 +.endm
22538 +
22539 +.macro pax_exit_kernel
22540 +#ifdef CONFIG_PAX_KERNEXEC
22541 + call pax_exit_kernel
22542 +#endif
22543 +.endm
22544 +
22545 +#ifdef CONFIG_PAX_KERNEXEC
22546 +ENTRY(pax_enter_kernel)
22547 +#ifdef CONFIG_PARAVIRT
22548 + pushl %eax
22549 + pushl %ecx
22550 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22551 + mov %eax, %esi
22552 +#else
22553 + mov %cr0, %esi
22554 +#endif
22555 + bts $16, %esi
22556 + jnc 1f
22557 + mov %cs, %esi
22558 + cmp $__KERNEL_CS, %esi
22559 + jz 3f
22560 + ljmp $__KERNEL_CS, $3f
22561 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22562 +2:
22563 +#ifdef CONFIG_PARAVIRT
22564 + mov %esi, %eax
22565 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22566 +#else
22567 + mov %esi, %cr0
22568 +#endif
22569 +3:
22570 +#ifdef CONFIG_PARAVIRT
22571 + popl %ecx
22572 + popl %eax
22573 +#endif
22574 + ret
22575 +ENDPROC(pax_enter_kernel)
22576 +
22577 +ENTRY(pax_exit_kernel)
22578 +#ifdef CONFIG_PARAVIRT
22579 + pushl %eax
22580 + pushl %ecx
22581 +#endif
22582 + mov %cs, %esi
22583 + cmp $__KERNEXEC_KERNEL_CS, %esi
22584 + jnz 2f
22585 +#ifdef CONFIG_PARAVIRT
22586 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22587 + mov %eax, %esi
22588 +#else
22589 + mov %cr0, %esi
22590 +#endif
22591 + btr $16, %esi
22592 + ljmp $__KERNEL_CS, $1f
22593 +1:
22594 +#ifdef CONFIG_PARAVIRT
22595 + mov %esi, %eax
22596 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22597 +#else
22598 + mov %esi, %cr0
22599 +#endif
22600 +2:
22601 +#ifdef CONFIG_PARAVIRT
22602 + popl %ecx
22603 + popl %eax
22604 +#endif
22605 + ret
22606 +ENDPROC(pax_exit_kernel)
22607 +#endif
22608 +
22609 + .macro pax_erase_kstack
22610 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22611 + call pax_erase_kstack
22612 +#endif
22613 + .endm
22614 +
22615 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22616 +/*
22617 + * ebp: thread_info
22618 + */
22619 +ENTRY(pax_erase_kstack)
22620 + pushl %edi
22621 + pushl %ecx
22622 + pushl %eax
22623 +
22624 + mov TI_lowest_stack(%ebp), %edi
22625 + mov $-0xBEEF, %eax
22626 + std
22627 +
22628 +1: mov %edi, %ecx
22629 + and $THREAD_SIZE_asm - 1, %ecx
22630 + shr $2, %ecx
22631 + repne scasl
22632 + jecxz 2f
22633 +
22634 + cmp $2*16, %ecx
22635 + jc 2f
22636 +
22637 + mov $2*16, %ecx
22638 + repe scasl
22639 + jecxz 2f
22640 + jne 1b
22641 +
22642 +2: cld
22643 + mov %esp, %ecx
22644 + sub %edi, %ecx
22645 +
22646 + cmp $THREAD_SIZE_asm, %ecx
22647 + jb 3f
22648 + ud2
22649 +3:
22650 +
22651 + shr $2, %ecx
22652 + rep stosl
22653 +
22654 + mov TI_task_thread_sp0(%ebp), %edi
22655 + sub $128, %edi
22656 + mov %edi, TI_lowest_stack(%ebp)
22657 +
22658 + popl %eax
22659 + popl %ecx
22660 + popl %edi
22661 + ret
22662 +ENDPROC(pax_erase_kstack)
22663 +#endif
22664 +
22665 +.macro __SAVE_ALL _DS
22666 cld
22667 PUSH_GS
22668 pushl_cfi %fs
22669 @@ -206,7 +346,7 @@
22670 CFI_REL_OFFSET ecx, 0
22671 pushl_cfi %ebx
22672 CFI_REL_OFFSET ebx, 0
22673 - movl $(__USER_DS), %edx
22674 + movl $\_DS, %edx
22675 movl %edx, %ds
22676 movl %edx, %es
22677 movl $(__KERNEL_PERCPU), %edx
22678 @@ -214,6 +354,15 @@
22679 SET_KERNEL_GS %edx
22680 .endm
22681
22682 +.macro SAVE_ALL
22683 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22684 + __SAVE_ALL __KERNEL_DS
22685 + pax_enter_kernel
22686 +#else
22687 + __SAVE_ALL __USER_DS
22688 +#endif
22689 +.endm
22690 +
22691 .macro RESTORE_INT_REGS
22692 popl_cfi %ebx
22693 CFI_RESTORE ebx
22694 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22695 popfl_cfi
22696 jmp syscall_exit
22697 CFI_ENDPROC
22698 -END(ret_from_fork)
22699 +ENDPROC(ret_from_fork)
22700
22701 ENTRY(ret_from_kernel_thread)
22702 CFI_STARTPROC
22703 @@ -340,7 +489,15 @@ ret_from_intr:
22704 andl $SEGMENT_RPL_MASK, %eax
22705 #endif
22706 cmpl $USER_RPL, %eax
22707 +
22708 +#ifdef CONFIG_PAX_KERNEXEC
22709 + jae resume_userspace
22710 +
22711 + pax_exit_kernel
22712 + jmp resume_kernel
22713 +#else
22714 jb resume_kernel # not returning to v8086 or userspace
22715 +#endif
22716
22717 ENTRY(resume_userspace)
22718 LOCKDEP_SYS_EXIT
22719 @@ -352,8 +509,8 @@ ENTRY(resume_userspace)
22720 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22721 # int/exception return?
22722 jne work_pending
22723 - jmp restore_all
22724 -END(ret_from_exception)
22725 + jmp restore_all_pax
22726 +ENDPROC(ret_from_exception)
22727
22728 #ifdef CONFIG_PREEMPT
22729 ENTRY(resume_kernel)
22730 @@ -365,7 +522,7 @@ need_resched:
22731 jz restore_all
22732 call preempt_schedule_irq
22733 jmp need_resched
22734 -END(resume_kernel)
22735 +ENDPROC(resume_kernel)
22736 #endif
22737 CFI_ENDPROC
22738
22739 @@ -395,30 +552,45 @@ sysenter_past_esp:
22740 /*CFI_REL_OFFSET cs, 0*/
22741 /*
22742 * Push current_thread_info()->sysenter_return to the stack.
22743 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22744 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22745 */
22746 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22747 + pushl_cfi $0
22748 CFI_REL_OFFSET eip, 0
22749
22750 pushl_cfi %eax
22751 SAVE_ALL
22752 + GET_THREAD_INFO(%ebp)
22753 + movl TI_sysenter_return(%ebp),%ebp
22754 + movl %ebp,PT_EIP(%esp)
22755 ENABLE_INTERRUPTS(CLBR_NONE)
22756
22757 /*
22758 * Load the potential sixth argument from user stack.
22759 * Careful about security.
22760 */
22761 + movl PT_OLDESP(%esp),%ebp
22762 +
22763 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22764 + mov PT_OLDSS(%esp),%ds
22765 +1: movl %ds:(%ebp),%ebp
22766 + push %ss
22767 + pop %ds
22768 +#else
22769 cmpl $__PAGE_OFFSET-3,%ebp
22770 jae syscall_fault
22771 ASM_STAC
22772 1: movl (%ebp),%ebp
22773 ASM_CLAC
22774 +#endif
22775 +
22776 movl %ebp,PT_EBP(%esp)
22777 _ASM_EXTABLE(1b,syscall_fault)
22778
22779 GET_THREAD_INFO(%ebp)
22780
22781 +#ifdef CONFIG_PAX_RANDKSTACK
22782 + pax_erase_kstack
22783 +#endif
22784 +
22785 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22786 jnz sysenter_audit
22787 sysenter_do_call:
22788 @@ -434,12 +606,24 @@ sysenter_after_call:
22789 testl $_TIF_ALLWORK_MASK, %ecx
22790 jne sysexit_audit
22791 sysenter_exit:
22792 +
22793 +#ifdef CONFIG_PAX_RANDKSTACK
22794 + pushl_cfi %eax
22795 + movl %esp, %eax
22796 + call pax_randomize_kstack
22797 + popl_cfi %eax
22798 +#endif
22799 +
22800 + pax_erase_kstack
22801 +
22802 /* if something modifies registers it must also disable sysexit */
22803 movl PT_EIP(%esp), %edx
22804 movl PT_OLDESP(%esp), %ecx
22805 xorl %ebp,%ebp
22806 TRACE_IRQS_ON
22807 1: mov PT_FS(%esp), %fs
22808 +2: mov PT_DS(%esp), %ds
22809 +3: mov PT_ES(%esp), %es
22810 PTGS_TO_GS
22811 ENABLE_INTERRUPTS_SYSEXIT
22812
22813 @@ -456,6 +640,9 @@ sysenter_audit:
22814 movl %eax,%edx /* 2nd arg: syscall number */
22815 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22816 call __audit_syscall_entry
22817 +
22818 + pax_erase_kstack
22819 +
22820 pushl_cfi %ebx
22821 movl PT_EAX(%esp),%eax /* reload syscall number */
22822 jmp sysenter_do_call
22823 @@ -481,10 +668,16 @@ sysexit_audit:
22824
22825 CFI_ENDPROC
22826 .pushsection .fixup,"ax"
22827 -2: movl $0,PT_FS(%esp)
22828 +4: movl $0,PT_FS(%esp)
22829 + jmp 1b
22830 +5: movl $0,PT_DS(%esp)
22831 + jmp 1b
22832 +6: movl $0,PT_ES(%esp)
22833 jmp 1b
22834 .popsection
22835 - _ASM_EXTABLE(1b,2b)
22836 + _ASM_EXTABLE(1b,4b)
22837 + _ASM_EXTABLE(2b,5b)
22838 + _ASM_EXTABLE(3b,6b)
22839 PTGS_TO_GS_EX
22840 ENDPROC(ia32_sysenter_target)
22841
22842 @@ -495,6 +688,11 @@ ENTRY(system_call)
22843 pushl_cfi %eax # save orig_eax
22844 SAVE_ALL
22845 GET_THREAD_INFO(%ebp)
22846 +
22847 +#ifdef CONFIG_PAX_RANDKSTACK
22848 + pax_erase_kstack
22849 +#endif
22850 +
22851 # system call tracing in operation / emulation
22852 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22853 jnz syscall_trace_entry
22854 @@ -514,6 +712,15 @@ syscall_exit:
22855 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22856 jne syscall_exit_work
22857
22858 +restore_all_pax:
22859 +
22860 +#ifdef CONFIG_PAX_RANDKSTACK
22861 + movl %esp, %eax
22862 + call pax_randomize_kstack
22863 +#endif
22864 +
22865 + pax_erase_kstack
22866 +
22867 restore_all:
22868 TRACE_IRQS_IRET
22869 restore_all_notrace:
22870 @@ -568,14 +775,34 @@ ldt_ss:
22871 * compensating for the offset by changing to the ESPFIX segment with
22872 * a base address that matches for the difference.
22873 */
22874 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22875 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22876 mov %esp, %edx /* load kernel esp */
22877 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22878 mov %dx, %ax /* eax: new kernel esp */
22879 sub %eax, %edx /* offset (low word is 0) */
22880 +#ifdef CONFIG_SMP
22881 + movl PER_CPU_VAR(cpu_number), %ebx
22882 + shll $PAGE_SHIFT_asm, %ebx
22883 + addl $cpu_gdt_table, %ebx
22884 +#else
22885 + movl $cpu_gdt_table, %ebx
22886 +#endif
22887 shr $16, %edx
22888 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22889 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22890 +
22891 +#ifdef CONFIG_PAX_KERNEXEC
22892 + mov %cr0, %esi
22893 + btr $16, %esi
22894 + mov %esi, %cr0
22895 +#endif
22896 +
22897 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22898 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22899 +
22900 +#ifdef CONFIG_PAX_KERNEXEC
22901 + bts $16, %esi
22902 + mov %esi, %cr0
22903 +#endif
22904 +
22905 pushl_cfi $__ESPFIX_SS
22906 pushl_cfi %eax /* new kernel esp */
22907 /* Disable interrupts, but do not irqtrace this section: we
22908 @@ -605,20 +832,18 @@ work_resched:
22909 movl TI_flags(%ebp), %ecx
22910 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22911 # than syscall tracing?
22912 - jz restore_all
22913 + jz restore_all_pax
22914 testb $_TIF_NEED_RESCHED, %cl
22915 jnz work_resched
22916
22917 work_notifysig: # deal with pending signals and
22918 # notify-resume requests
22919 + movl %esp, %eax
22920 #ifdef CONFIG_VM86
22921 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22922 - movl %esp, %eax
22923 jne work_notifysig_v86 # returning to kernel-space or
22924 # vm86-space
22925 1:
22926 -#else
22927 - movl %esp, %eax
22928 #endif
22929 TRACE_IRQS_ON
22930 ENABLE_INTERRUPTS(CLBR_NONE)
22931 @@ -639,7 +864,7 @@ work_notifysig_v86:
22932 movl %eax, %esp
22933 jmp 1b
22934 #endif
22935 -END(work_pending)
22936 +ENDPROC(work_pending)
22937
22938 # perform syscall exit tracing
22939 ALIGN
22940 @@ -647,11 +872,14 @@ syscall_trace_entry:
22941 movl $-ENOSYS,PT_EAX(%esp)
22942 movl %esp, %eax
22943 call syscall_trace_enter
22944 +
22945 + pax_erase_kstack
22946 +
22947 /* What it returned is what we'll actually use. */
22948 cmpl $(NR_syscalls), %eax
22949 jnae syscall_call
22950 jmp syscall_exit
22951 -END(syscall_trace_entry)
22952 +ENDPROC(syscall_trace_entry)
22953
22954 # perform syscall exit tracing
22955 ALIGN
22956 @@ -664,26 +892,30 @@ syscall_exit_work:
22957 movl %esp, %eax
22958 call syscall_trace_leave
22959 jmp resume_userspace
22960 -END(syscall_exit_work)
22961 +ENDPROC(syscall_exit_work)
22962 CFI_ENDPROC
22963
22964 RING0_INT_FRAME # can't unwind into user space anyway
22965 syscall_fault:
22966 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22967 + push %ss
22968 + pop %ds
22969 +#endif
22970 ASM_CLAC
22971 GET_THREAD_INFO(%ebp)
22972 movl $-EFAULT,PT_EAX(%esp)
22973 jmp resume_userspace
22974 -END(syscall_fault)
22975 +ENDPROC(syscall_fault)
22976
22977 syscall_badsys:
22978 movl $-ENOSYS,%eax
22979 jmp syscall_after_call
22980 -END(syscall_badsys)
22981 +ENDPROC(syscall_badsys)
22982
22983 sysenter_badsys:
22984 movl $-ENOSYS,%eax
22985 jmp sysenter_after_call
22986 -END(syscall_badsys)
22987 +ENDPROC(sysenter_badsys)
22988 CFI_ENDPROC
22989
22990 .macro FIXUP_ESPFIX_STACK
22991 @@ -696,8 +928,15 @@ END(syscall_badsys)
22992 */
22993 #ifdef CONFIG_X86_ESPFIX32
22994 /* fixup the stack */
22995 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22996 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22997 +#ifdef CONFIG_SMP
22998 + movl PER_CPU_VAR(cpu_number), %ebx
22999 + shll $PAGE_SHIFT_asm, %ebx
23000 + addl $cpu_gdt_table, %ebx
23001 +#else
23002 + movl $cpu_gdt_table, %ebx
23003 +#endif
23004 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
23005 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
23006 shl $16, %eax
23007 addl %esp, %eax /* the adjusted stack pointer */
23008 pushl_cfi $__KERNEL_DS
23009 @@ -753,7 +992,7 @@ vector=vector+1
23010 .endr
23011 2: jmp common_interrupt
23012 .endr
23013 -END(irq_entries_start)
23014 +ENDPROC(irq_entries_start)
23015
23016 .previous
23017 END(interrupt)
23018 @@ -810,7 +1049,7 @@ ENTRY(coprocessor_error)
23019 pushl_cfi $do_coprocessor_error
23020 jmp error_code
23021 CFI_ENDPROC
23022 -END(coprocessor_error)
23023 +ENDPROC(coprocessor_error)
23024
23025 ENTRY(simd_coprocessor_error)
23026 RING0_INT_FRAME
23027 @@ -823,7 +1062,7 @@ ENTRY(simd_coprocessor_error)
23028 .section .altinstructions,"a"
23029 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
23030 .previous
23031 -.section .altinstr_replacement,"ax"
23032 +.section .altinstr_replacement,"a"
23033 663: pushl $do_simd_coprocessor_error
23034 664:
23035 .previous
23036 @@ -832,7 +1071,7 @@ ENTRY(simd_coprocessor_error)
23037 #endif
23038 jmp error_code
23039 CFI_ENDPROC
23040 -END(simd_coprocessor_error)
23041 +ENDPROC(simd_coprocessor_error)
23042
23043 ENTRY(device_not_available)
23044 RING0_INT_FRAME
23045 @@ -841,18 +1080,18 @@ ENTRY(device_not_available)
23046 pushl_cfi $do_device_not_available
23047 jmp error_code
23048 CFI_ENDPROC
23049 -END(device_not_available)
23050 +ENDPROC(device_not_available)
23051
23052 #ifdef CONFIG_PARAVIRT
23053 ENTRY(native_iret)
23054 iret
23055 _ASM_EXTABLE(native_iret, iret_exc)
23056 -END(native_iret)
23057 +ENDPROC(native_iret)
23058
23059 ENTRY(native_irq_enable_sysexit)
23060 sti
23061 sysexit
23062 -END(native_irq_enable_sysexit)
23063 +ENDPROC(native_irq_enable_sysexit)
23064 #endif
23065
23066 ENTRY(overflow)
23067 @@ -862,7 +1101,7 @@ ENTRY(overflow)
23068 pushl_cfi $do_overflow
23069 jmp error_code
23070 CFI_ENDPROC
23071 -END(overflow)
23072 +ENDPROC(overflow)
23073
23074 ENTRY(bounds)
23075 RING0_INT_FRAME
23076 @@ -871,7 +1110,7 @@ ENTRY(bounds)
23077 pushl_cfi $do_bounds
23078 jmp error_code
23079 CFI_ENDPROC
23080 -END(bounds)
23081 +ENDPROC(bounds)
23082
23083 ENTRY(invalid_op)
23084 RING0_INT_FRAME
23085 @@ -880,7 +1119,7 @@ ENTRY(invalid_op)
23086 pushl_cfi $do_invalid_op
23087 jmp error_code
23088 CFI_ENDPROC
23089 -END(invalid_op)
23090 +ENDPROC(invalid_op)
23091
23092 ENTRY(coprocessor_segment_overrun)
23093 RING0_INT_FRAME
23094 @@ -889,7 +1128,7 @@ ENTRY(coprocessor_segment_overrun)
23095 pushl_cfi $do_coprocessor_segment_overrun
23096 jmp error_code
23097 CFI_ENDPROC
23098 -END(coprocessor_segment_overrun)
23099 +ENDPROC(coprocessor_segment_overrun)
23100
23101 ENTRY(invalid_TSS)
23102 RING0_EC_FRAME
23103 @@ -897,7 +1136,7 @@ ENTRY(invalid_TSS)
23104 pushl_cfi $do_invalid_TSS
23105 jmp error_code
23106 CFI_ENDPROC
23107 -END(invalid_TSS)
23108 +ENDPROC(invalid_TSS)
23109
23110 ENTRY(segment_not_present)
23111 RING0_EC_FRAME
23112 @@ -905,7 +1144,7 @@ ENTRY(segment_not_present)
23113 pushl_cfi $do_segment_not_present
23114 jmp error_code
23115 CFI_ENDPROC
23116 -END(segment_not_present)
23117 +ENDPROC(segment_not_present)
23118
23119 ENTRY(stack_segment)
23120 RING0_EC_FRAME
23121 @@ -913,7 +1152,7 @@ ENTRY(stack_segment)
23122 pushl_cfi $do_stack_segment
23123 jmp error_code
23124 CFI_ENDPROC
23125 -END(stack_segment)
23126 +ENDPROC(stack_segment)
23127
23128 ENTRY(alignment_check)
23129 RING0_EC_FRAME
23130 @@ -921,7 +1160,7 @@ ENTRY(alignment_check)
23131 pushl_cfi $do_alignment_check
23132 jmp error_code
23133 CFI_ENDPROC
23134 -END(alignment_check)
23135 +ENDPROC(alignment_check)
23136
23137 ENTRY(divide_error)
23138 RING0_INT_FRAME
23139 @@ -930,7 +1169,7 @@ ENTRY(divide_error)
23140 pushl_cfi $do_divide_error
23141 jmp error_code
23142 CFI_ENDPROC
23143 -END(divide_error)
23144 +ENDPROC(divide_error)
23145
23146 #ifdef CONFIG_X86_MCE
23147 ENTRY(machine_check)
23148 @@ -940,7 +1179,7 @@ ENTRY(machine_check)
23149 pushl_cfi machine_check_vector
23150 jmp error_code
23151 CFI_ENDPROC
23152 -END(machine_check)
23153 +ENDPROC(machine_check)
23154 #endif
23155
23156 ENTRY(spurious_interrupt_bug)
23157 @@ -950,7 +1189,7 @@ ENTRY(spurious_interrupt_bug)
23158 pushl_cfi $do_spurious_interrupt_bug
23159 jmp error_code
23160 CFI_ENDPROC
23161 -END(spurious_interrupt_bug)
23162 +ENDPROC(spurious_interrupt_bug)
23163
23164 #ifdef CONFIG_XEN
23165 /* Xen doesn't set %esp to be precisely what the normal sysenter
23166 @@ -1056,7 +1295,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
23167
23168 ENTRY(mcount)
23169 ret
23170 -END(mcount)
23171 +ENDPROC(mcount)
23172
23173 ENTRY(ftrace_caller)
23174 cmpl $0, function_trace_stop
23175 @@ -1089,7 +1328,7 @@ ftrace_graph_call:
23176 .globl ftrace_stub
23177 ftrace_stub:
23178 ret
23179 -END(ftrace_caller)
23180 +ENDPROC(ftrace_caller)
23181
23182 ENTRY(ftrace_regs_caller)
23183 pushf /* push flags before compare (in cs location) */
23184 @@ -1193,7 +1432,7 @@ trace:
23185 popl %ecx
23186 popl %eax
23187 jmp ftrace_stub
23188 -END(mcount)
23189 +ENDPROC(mcount)
23190 #endif /* CONFIG_DYNAMIC_FTRACE */
23191 #endif /* CONFIG_FUNCTION_TRACER */
23192
23193 @@ -1211,7 +1450,7 @@ ENTRY(ftrace_graph_caller)
23194 popl %ecx
23195 popl %eax
23196 ret
23197 -END(ftrace_graph_caller)
23198 +ENDPROC(ftrace_graph_caller)
23199
23200 .globl return_to_handler
23201 return_to_handler:
23202 @@ -1272,15 +1511,18 @@ error_code:
23203 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23204 REG_TO_PTGS %ecx
23205 SET_KERNEL_GS %ecx
23206 - movl $(__USER_DS), %ecx
23207 + movl $(__KERNEL_DS), %ecx
23208 movl %ecx, %ds
23209 movl %ecx, %es
23210 +
23211 + pax_enter_kernel
23212 +
23213 TRACE_IRQS_OFF
23214 movl %esp,%eax # pt_regs pointer
23215 call *%edi
23216 jmp ret_from_exception
23217 CFI_ENDPROC
23218 -END(page_fault)
23219 +ENDPROC(page_fault)
23220
23221 /*
23222 * Debug traps and NMI can happen at the one SYSENTER instruction
23223 @@ -1323,7 +1565,7 @@ debug_stack_correct:
23224 call do_debug
23225 jmp ret_from_exception
23226 CFI_ENDPROC
23227 -END(debug)
23228 +ENDPROC(debug)
23229
23230 /*
23231 * NMI is doubly nasty. It can happen _while_ we're handling
23232 @@ -1363,6 +1605,9 @@ nmi_stack_correct:
23233 xorl %edx,%edx # zero error code
23234 movl %esp,%eax # pt_regs pointer
23235 call do_nmi
23236 +
23237 + pax_exit_kernel
23238 +
23239 jmp restore_all_notrace
23240 CFI_ENDPROC
23241
23242 @@ -1400,13 +1645,16 @@ nmi_espfix_stack:
23243 FIXUP_ESPFIX_STACK # %eax == %esp
23244 xorl %edx,%edx # zero error code
23245 call do_nmi
23246 +
23247 + pax_exit_kernel
23248 +
23249 RESTORE_REGS
23250 lss 12+4(%esp), %esp # back to espfix stack
23251 CFI_ADJUST_CFA_OFFSET -24
23252 jmp irq_return
23253 #endif
23254 CFI_ENDPROC
23255 -END(nmi)
23256 +ENDPROC(nmi)
23257
23258 ENTRY(int3)
23259 RING0_INT_FRAME
23260 @@ -1419,14 +1667,14 @@ ENTRY(int3)
23261 call do_int3
23262 jmp ret_from_exception
23263 CFI_ENDPROC
23264 -END(int3)
23265 +ENDPROC(int3)
23266
23267 ENTRY(general_protection)
23268 RING0_EC_FRAME
23269 pushl_cfi $do_general_protection
23270 jmp error_code
23271 CFI_ENDPROC
23272 -END(general_protection)
23273 +ENDPROC(general_protection)
23274
23275 #ifdef CONFIG_KVM_GUEST
23276 ENTRY(async_page_fault)
23277 @@ -1435,6 +1683,6 @@ ENTRY(async_page_fault)
23278 pushl_cfi $do_async_page_fault
23279 jmp error_code
23280 CFI_ENDPROC
23281 -END(async_page_fault)
23282 +ENDPROC(async_page_fault)
23283 #endif
23284
23285 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23286 index c844f08..b07ea0e 100644
23287 --- a/arch/x86/kernel/entry_64.S
23288 +++ b/arch/x86/kernel/entry_64.S
23289 @@ -59,6 +59,8 @@
23290 #include <asm/smap.h>
23291 #include <asm/pgtable_types.h>
23292 #include <linux/err.h>
23293 +#include <asm/pgtable.h>
23294 +#include <asm/alternative-asm.h>
23295
23296 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23297 #include <linux/elf-em.h>
23298 @@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23299 ENDPROC(native_usergs_sysret64)
23300 #endif /* CONFIG_PARAVIRT */
23301
23302 + .macro ljmpq sel, off
23303 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23304 + .byte 0x48; ljmp *1234f(%rip)
23305 + .pushsection .rodata
23306 + .align 16
23307 + 1234: .quad \off; .word \sel
23308 + .popsection
23309 +#else
23310 + pushq $\sel
23311 + pushq $\off
23312 + lretq
23313 +#endif
23314 + .endm
23315 +
23316 + .macro pax_enter_kernel
23317 + pax_set_fptr_mask
23318 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23319 + call pax_enter_kernel
23320 +#endif
23321 + .endm
23322 +
23323 + .macro pax_exit_kernel
23324 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23325 + call pax_exit_kernel
23326 +#endif
23327 +
23328 + .endm
23329 +
23330 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23331 +ENTRY(pax_enter_kernel)
23332 + pushq %rdi
23333 +
23334 +#ifdef CONFIG_PARAVIRT
23335 + PV_SAVE_REGS(CLBR_RDI)
23336 +#endif
23337 +
23338 +#ifdef CONFIG_PAX_KERNEXEC
23339 + GET_CR0_INTO_RDI
23340 + bts $16,%rdi
23341 + jnc 3f
23342 + mov %cs,%edi
23343 + cmp $__KERNEL_CS,%edi
23344 + jnz 2f
23345 +1:
23346 +#endif
23347 +
23348 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23349 + 661: jmp 111f
23350 + .pushsection .altinstr_replacement, "a"
23351 + 662: ASM_NOP2
23352 + .popsection
23353 + .pushsection .altinstructions, "a"
23354 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23355 + .popsection
23356 + GET_CR3_INTO_RDI
23357 + cmp $0,%dil
23358 + jnz 112f
23359 + mov $__KERNEL_DS,%edi
23360 + mov %edi,%ss
23361 + jmp 111f
23362 +112: cmp $1,%dil
23363 + jz 113f
23364 + ud2
23365 +113: sub $4097,%rdi
23366 + bts $63,%rdi
23367 + SET_RDI_INTO_CR3
23368 + mov $__UDEREF_KERNEL_DS,%edi
23369 + mov %edi,%ss
23370 +111:
23371 +#endif
23372 +
23373 +#ifdef CONFIG_PARAVIRT
23374 + PV_RESTORE_REGS(CLBR_RDI)
23375 +#endif
23376 +
23377 + popq %rdi
23378 + pax_force_retaddr
23379 + retq
23380 +
23381 +#ifdef CONFIG_PAX_KERNEXEC
23382 +2: ljmpq __KERNEL_CS,1b
23383 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23384 +4: SET_RDI_INTO_CR0
23385 + jmp 1b
23386 +#endif
23387 +ENDPROC(pax_enter_kernel)
23388 +
23389 +ENTRY(pax_exit_kernel)
23390 + pushq %rdi
23391 +
23392 +#ifdef CONFIG_PARAVIRT
23393 + PV_SAVE_REGS(CLBR_RDI)
23394 +#endif
23395 +
23396 +#ifdef CONFIG_PAX_KERNEXEC
23397 + mov %cs,%rdi
23398 + cmp $__KERNEXEC_KERNEL_CS,%edi
23399 + jz 2f
23400 + GET_CR0_INTO_RDI
23401 + bts $16,%rdi
23402 + jnc 4f
23403 +1:
23404 +#endif
23405 +
23406 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23407 + 661: jmp 111f
23408 + .pushsection .altinstr_replacement, "a"
23409 + 662: ASM_NOP2
23410 + .popsection
23411 + .pushsection .altinstructions, "a"
23412 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23413 + .popsection
23414 + mov %ss,%edi
23415 + cmp $__UDEREF_KERNEL_DS,%edi
23416 + jnz 111f
23417 + GET_CR3_INTO_RDI
23418 + cmp $0,%dil
23419 + jz 112f
23420 + ud2
23421 +112: add $4097,%rdi
23422 + bts $63,%rdi
23423 + SET_RDI_INTO_CR3
23424 + mov $__KERNEL_DS,%edi
23425 + mov %edi,%ss
23426 +111:
23427 +#endif
23428 +
23429 +#ifdef CONFIG_PARAVIRT
23430 + PV_RESTORE_REGS(CLBR_RDI);
23431 +#endif
23432 +
23433 + popq %rdi
23434 + pax_force_retaddr
23435 + retq
23436 +
23437 +#ifdef CONFIG_PAX_KERNEXEC
23438 +2: GET_CR0_INTO_RDI
23439 + btr $16,%rdi
23440 + jnc 4f
23441 + ljmpq __KERNEL_CS,3f
23442 +3: SET_RDI_INTO_CR0
23443 + jmp 1b
23444 +4: ud2
23445 + jmp 4b
23446 +#endif
23447 +ENDPROC(pax_exit_kernel)
23448 +#endif
23449 +
23450 + .macro pax_enter_kernel_user
23451 + pax_set_fptr_mask
23452 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23453 + call pax_enter_kernel_user
23454 +#endif
23455 + .endm
23456 +
23457 + .macro pax_exit_kernel_user
23458 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23459 + call pax_exit_kernel_user
23460 +#endif
23461 +#ifdef CONFIG_PAX_RANDKSTACK
23462 + pushq %rax
23463 + pushq %r11
23464 + call pax_randomize_kstack
23465 + popq %r11
23466 + popq %rax
23467 +#endif
23468 + .endm
23469 +
23470 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23471 +ENTRY(pax_enter_kernel_user)
23472 + pushq %rdi
23473 + pushq %rbx
23474 +
23475 +#ifdef CONFIG_PARAVIRT
23476 + PV_SAVE_REGS(CLBR_RDI)
23477 +#endif
23478 +
23479 + 661: jmp 111f
23480 + .pushsection .altinstr_replacement, "a"
23481 + 662: ASM_NOP2
23482 + .popsection
23483 + .pushsection .altinstructions, "a"
23484 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23485 + .popsection
23486 + GET_CR3_INTO_RDI
23487 + cmp $1,%dil
23488 + jnz 4f
23489 + sub $4097,%rdi
23490 + bts $63,%rdi
23491 + SET_RDI_INTO_CR3
23492 + jmp 3f
23493 +111:
23494 +
23495 + GET_CR3_INTO_RDI
23496 + mov %rdi,%rbx
23497 + add $__START_KERNEL_map,%rbx
23498 + sub phys_base(%rip),%rbx
23499 +
23500 +#ifdef CONFIG_PARAVIRT
23501 + cmpl $0, pv_info+PARAVIRT_enabled
23502 + jz 1f
23503 + pushq %rdi
23504 + i = 0
23505 + .rept USER_PGD_PTRS
23506 + mov i*8(%rbx),%rsi
23507 + mov $0,%sil
23508 + lea i*8(%rbx),%rdi
23509 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23510 + i = i + 1
23511 + .endr
23512 + popq %rdi
23513 + jmp 2f
23514 +1:
23515 +#endif
23516 +
23517 + i = 0
23518 + .rept USER_PGD_PTRS
23519 + movb $0,i*8(%rbx)
23520 + i = i + 1
23521 + .endr
23522 +
23523 +2: SET_RDI_INTO_CR3
23524 +
23525 +#ifdef CONFIG_PAX_KERNEXEC
23526 + GET_CR0_INTO_RDI
23527 + bts $16,%rdi
23528 + SET_RDI_INTO_CR0
23529 +#endif
23530 +
23531 +3:
23532 +
23533 +#ifdef CONFIG_PARAVIRT
23534 + PV_RESTORE_REGS(CLBR_RDI)
23535 +#endif
23536 +
23537 + popq %rbx
23538 + popq %rdi
23539 + pax_force_retaddr
23540 + retq
23541 +4: ud2
23542 +ENDPROC(pax_enter_kernel_user)
23543 +
23544 +ENTRY(pax_exit_kernel_user)
23545 + pushq %rdi
23546 + pushq %rbx
23547 +
23548 +#ifdef CONFIG_PARAVIRT
23549 + PV_SAVE_REGS(CLBR_RDI)
23550 +#endif
23551 +
23552 + GET_CR3_INTO_RDI
23553 + 661: jmp 1f
23554 + .pushsection .altinstr_replacement, "a"
23555 + 662: ASM_NOP2
23556 + .popsection
23557 + .pushsection .altinstructions, "a"
23558 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23559 + .popsection
23560 + cmp $0,%dil
23561 + jnz 3f
23562 + add $4097,%rdi
23563 + bts $63,%rdi
23564 + SET_RDI_INTO_CR3
23565 + jmp 2f
23566 +1:
23567 +
23568 + mov %rdi,%rbx
23569 +
23570 +#ifdef CONFIG_PAX_KERNEXEC
23571 + GET_CR0_INTO_RDI
23572 + btr $16,%rdi
23573 + jnc 3f
23574 + SET_RDI_INTO_CR0
23575 +#endif
23576 +
23577 + add $__START_KERNEL_map,%rbx
23578 + sub phys_base(%rip),%rbx
23579 +
23580 +#ifdef CONFIG_PARAVIRT
23581 + cmpl $0, pv_info+PARAVIRT_enabled
23582 + jz 1f
23583 + i = 0
23584 + .rept USER_PGD_PTRS
23585 + mov i*8(%rbx),%rsi
23586 + mov $0x67,%sil
23587 + lea i*8(%rbx),%rdi
23588 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23589 + i = i + 1
23590 + .endr
23591 + jmp 2f
23592 +1:
23593 +#endif
23594 +
23595 + i = 0
23596 + .rept USER_PGD_PTRS
23597 + movb $0x67,i*8(%rbx)
23598 + i = i + 1
23599 + .endr
23600 +2:
23601 +
23602 +#ifdef CONFIG_PARAVIRT
23603 + PV_RESTORE_REGS(CLBR_RDI)
23604 +#endif
23605 +
23606 + popq %rbx
23607 + popq %rdi
23608 + pax_force_retaddr
23609 + retq
23610 +3: ud2
23611 +ENDPROC(pax_exit_kernel_user)
23612 +#endif
23613 +
23614 + .macro pax_enter_kernel_nmi
23615 + pax_set_fptr_mask
23616 +
23617 +#ifdef CONFIG_PAX_KERNEXEC
23618 + GET_CR0_INTO_RDI
23619 + bts $16,%rdi
23620 + jc 110f
23621 + SET_RDI_INTO_CR0
23622 + or $2,%ebx
23623 +110:
23624 +#endif
23625 +
23626 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23627 + 661: jmp 111f
23628 + .pushsection .altinstr_replacement, "a"
23629 + 662: ASM_NOP2
23630 + .popsection
23631 + .pushsection .altinstructions, "a"
23632 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23633 + .popsection
23634 + GET_CR3_INTO_RDI
23635 + cmp $0,%dil
23636 + jz 111f
23637 + sub $4097,%rdi
23638 + or $4,%ebx
23639 + bts $63,%rdi
23640 + SET_RDI_INTO_CR3
23641 + mov $__UDEREF_KERNEL_DS,%edi
23642 + mov %edi,%ss
23643 +111:
23644 +#endif
23645 + .endm
23646 +
23647 + .macro pax_exit_kernel_nmi
23648 +#ifdef CONFIG_PAX_KERNEXEC
23649 + btr $1,%ebx
23650 + jnc 110f
23651 + GET_CR0_INTO_RDI
23652 + btr $16,%rdi
23653 + SET_RDI_INTO_CR0
23654 +110:
23655 +#endif
23656 +
23657 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23658 + btr $2,%ebx
23659 + jnc 111f
23660 + GET_CR3_INTO_RDI
23661 + add $4097,%rdi
23662 + bts $63,%rdi
23663 + SET_RDI_INTO_CR3
23664 + mov $__KERNEL_DS,%edi
23665 + mov %edi,%ss
23666 +111:
23667 +#endif
23668 + .endm
23669 +
23670 + .macro pax_erase_kstack
23671 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23672 + call pax_erase_kstack
23673 +#endif
23674 + .endm
23675 +
23676 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23677 +ENTRY(pax_erase_kstack)
23678 + pushq %rdi
23679 + pushq %rcx
23680 + pushq %rax
23681 + pushq %r11
23682 +
23683 + GET_THREAD_INFO(%r11)
23684 + mov TI_lowest_stack(%r11), %rdi
23685 + mov $-0xBEEF, %rax
23686 + std
23687 +
23688 +1: mov %edi, %ecx
23689 + and $THREAD_SIZE_asm - 1, %ecx
23690 + shr $3, %ecx
23691 + repne scasq
23692 + jecxz 2f
23693 +
23694 + cmp $2*8, %ecx
23695 + jc 2f
23696 +
23697 + mov $2*8, %ecx
23698 + repe scasq
23699 + jecxz 2f
23700 + jne 1b
23701 +
23702 +2: cld
23703 + mov %esp, %ecx
23704 + sub %edi, %ecx
23705 +
23706 + cmp $THREAD_SIZE_asm, %rcx
23707 + jb 3f
23708 + ud2
23709 +3:
23710 +
23711 + shr $3, %ecx
23712 + rep stosq
23713 +
23714 + mov TI_task_thread_sp0(%r11), %rdi
23715 + sub $256, %rdi
23716 + mov %rdi, TI_lowest_stack(%r11)
23717 +
23718 + popq %r11
23719 + popq %rax
23720 + popq %rcx
23721 + popq %rdi
23722 + pax_force_retaddr
23723 + ret
23724 +ENDPROC(pax_erase_kstack)
23725 +#endif
23726
23727 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23728 #ifdef CONFIG_TRACE_IRQFLAGS
23729 @@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
23730 .endm
23731
23732 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23733 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23734 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23735 jnc 1f
23736 TRACE_IRQS_ON_DEBUG
23737 1:
23738 @@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
23739 movq \tmp,R11+\offset(%rsp)
23740 .endm
23741
23742 - .macro FAKE_STACK_FRAME child_rip
23743 - /* push in order ss, rsp, eflags, cs, rip */
23744 - xorl %eax, %eax
23745 - pushq_cfi $__KERNEL_DS /* ss */
23746 - /*CFI_REL_OFFSET ss,0*/
23747 - pushq_cfi %rax /* rsp */
23748 - CFI_REL_OFFSET rsp,0
23749 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23750 - /*CFI_REL_OFFSET rflags,0*/
23751 - pushq_cfi $__KERNEL_CS /* cs */
23752 - /*CFI_REL_OFFSET cs,0*/
23753 - pushq_cfi \child_rip /* rip */
23754 - CFI_REL_OFFSET rip,0
23755 - pushq_cfi %rax /* orig rax */
23756 - .endm
23757 -
23758 - .macro UNFAKE_STACK_FRAME
23759 - addq $8*6, %rsp
23760 - CFI_ADJUST_CFA_OFFSET -(6*8)
23761 - .endm
23762 -
23763 /*
23764 * initial frame state for interrupts (and exceptions without error code)
23765 */
23766 @@ -242,25 +647,26 @@ ENDPROC(native_usergs_sysret64)
23767 /* save partial stack frame */
23768 .macro SAVE_ARGS_IRQ
23769 cld
23770 - /* start from rbp in pt_regs and jump over */
23771 - movq_cfi rdi, (RDI-RBP)
23772 - movq_cfi rsi, (RSI-RBP)
23773 - movq_cfi rdx, (RDX-RBP)
23774 - movq_cfi rcx, (RCX-RBP)
23775 - movq_cfi rax, (RAX-RBP)
23776 - movq_cfi r8, (R8-RBP)
23777 - movq_cfi r9, (R9-RBP)
23778 - movq_cfi r10, (R10-RBP)
23779 - movq_cfi r11, (R11-RBP)
23780 + /* start from r15 in pt_regs and jump over */
23781 + movq_cfi rdi, RDI
23782 + movq_cfi rsi, RSI
23783 + movq_cfi rdx, RDX
23784 + movq_cfi rcx, RCX
23785 + movq_cfi rax, RAX
23786 + movq_cfi r8, R8
23787 + movq_cfi r9, R9
23788 + movq_cfi r10, R10
23789 + movq_cfi r11, R11
23790 + movq_cfi r12, R12
23791
23792 /* Save rbp so that we can unwind from get_irq_regs() */
23793 - movq_cfi rbp, 0
23794 + movq_cfi rbp, RBP
23795
23796 /* Save previous stack value */
23797 movq %rsp, %rsi
23798
23799 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23800 - testl $3, CS-RBP(%rsi)
23801 + movq %rsp,%rdi /* arg1 for handler */
23802 + testb $3, CS(%rsi)
23803 je 1f
23804 SWAPGS
23805 /*
23806 @@ -280,6 +686,18 @@ ENDPROC(native_usergs_sysret64)
23807 0x06 /* DW_OP_deref */, \
23808 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23809 0x22 /* DW_OP_plus */
23810 +
23811 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23812 + testb $3, CS(%rdi)
23813 + jnz 1f
23814 + pax_enter_kernel
23815 + jmp 2f
23816 +1: pax_enter_kernel_user
23817 +2:
23818 +#else
23819 + pax_enter_kernel
23820 +#endif
23821 +
23822 /* We entered an interrupt context - irqs are off: */
23823 TRACE_IRQS_OFF
23824 .endm
23825 @@ -309,9 +727,52 @@ ENTRY(save_paranoid)
23826 js 1f /* negative -> in kernel */
23827 SWAPGS
23828 xorl %ebx,%ebx
23829 -1: ret
23830 +1:
23831 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23832 + testb $3, CS+8(%rsp)
23833 + jnz 1f
23834 + pax_enter_kernel
23835 + jmp 2f
23836 +1: pax_enter_kernel_user
23837 +2:
23838 +#else
23839 + pax_enter_kernel
23840 +#endif
23841 + pax_force_retaddr
23842 + ret
23843 CFI_ENDPROC
23844 -END(save_paranoid)
23845 +ENDPROC(save_paranoid)
23846 +
23847 +ENTRY(save_paranoid_nmi)
23848 + XCPT_FRAME 1 RDI+8
23849 + cld
23850 + movq_cfi rdi, RDI+8
23851 + movq_cfi rsi, RSI+8
23852 + movq_cfi rdx, RDX+8
23853 + movq_cfi rcx, RCX+8
23854 + movq_cfi rax, RAX+8
23855 + movq_cfi r8, R8+8
23856 + movq_cfi r9, R9+8
23857 + movq_cfi r10, R10+8
23858 + movq_cfi r11, R11+8
23859 + movq_cfi rbx, RBX+8
23860 + movq_cfi rbp, RBP+8
23861 + movq_cfi r12, R12+8
23862 + movq_cfi r13, R13+8
23863 + movq_cfi r14, R14+8
23864 + movq_cfi r15, R15+8
23865 + movl $1,%ebx
23866 + movl $MSR_GS_BASE,%ecx
23867 + rdmsr
23868 + testl %edx,%edx
23869 + js 1f /* negative -> in kernel */
23870 + SWAPGS
23871 + xorl %ebx,%ebx
23872 +1: pax_enter_kernel_nmi
23873 + pax_force_retaddr
23874 + ret
23875 + CFI_ENDPROC
23876 +ENDPROC(save_paranoid_nmi)
23877
23878 /*
23879 * A newly forked process directly context switches into this address.
23880 @@ -332,7 +793,7 @@ ENTRY(ret_from_fork)
23881
23882 RESTORE_REST
23883
23884 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23885 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23886 jz 1f
23887
23888 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23889 @@ -342,15 +803,13 @@ ENTRY(ret_from_fork)
23890 jmp ret_from_sys_call # go to the SYSRET fastpath
23891
23892 1:
23893 - subq $REST_SKIP, %rsp # leave space for volatiles
23894 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23895 movq %rbp, %rdi
23896 call *%rbx
23897 movl $0, RAX(%rsp)
23898 RESTORE_REST
23899 jmp int_ret_from_sys_call
23900 CFI_ENDPROC
23901 -END(ret_from_fork)
23902 +ENDPROC(ret_from_fork)
23903
23904 /*
23905 * System call entry. Up to 6 arguments in registers are supported.
23906 @@ -387,7 +846,7 @@ END(ret_from_fork)
23907 ENTRY(system_call)
23908 CFI_STARTPROC simple
23909 CFI_SIGNAL_FRAME
23910 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23911 + CFI_DEF_CFA rsp,0
23912 CFI_REGISTER rip,rcx
23913 /*CFI_REGISTER rflags,r11*/
23914 SWAPGS_UNSAFE_STACK
23915 @@ -400,16 +859,23 @@ GLOBAL(system_call_after_swapgs)
23916
23917 movq %rsp,PER_CPU_VAR(old_rsp)
23918 movq PER_CPU_VAR(kernel_stack),%rsp
23919 + SAVE_ARGS 8*6,0
23920 + pax_enter_kernel_user
23921 +
23922 +#ifdef CONFIG_PAX_RANDKSTACK
23923 + pax_erase_kstack
23924 +#endif
23925 +
23926 /*
23927 * No need to follow this irqs off/on section - it's straight
23928 * and short:
23929 */
23930 ENABLE_INTERRUPTS(CLBR_NONE)
23931 - SAVE_ARGS 8,0
23932 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23933 movq %rcx,RIP-ARGOFFSET(%rsp)
23934 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23935 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23936 + GET_THREAD_INFO(%rcx)
23937 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23938 jnz tracesys
23939 system_call_fastpath:
23940 #if __SYSCALL_MASK == ~0
23941 @@ -433,10 +899,13 @@ sysret_check:
23942 LOCKDEP_SYS_EXIT
23943 DISABLE_INTERRUPTS(CLBR_NONE)
23944 TRACE_IRQS_OFF
23945 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23946 + GET_THREAD_INFO(%rcx)
23947 + movl TI_flags(%rcx),%edx
23948 andl %edi,%edx
23949 jnz sysret_careful
23950 CFI_REMEMBER_STATE
23951 + pax_exit_kernel_user
23952 + pax_erase_kstack
23953 /*
23954 * sysretq will re-enable interrupts:
23955 */
23956 @@ -495,6 +964,9 @@ auditsys:
23957 movq %rax,%rsi /* 2nd arg: syscall number */
23958 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23959 call __audit_syscall_entry
23960 +
23961 + pax_erase_kstack
23962 +
23963 LOAD_ARGS 0 /* reload call-clobbered registers */
23964 jmp system_call_fastpath
23965
23966 @@ -516,7 +988,7 @@ sysret_audit:
23967 /* Do syscall tracing */
23968 tracesys:
23969 #ifdef CONFIG_AUDITSYSCALL
23970 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23971 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23972 jz auditsys
23973 #endif
23974 SAVE_REST
23975 @@ -524,12 +996,15 @@ tracesys:
23976 FIXUP_TOP_OF_STACK %rdi
23977 movq %rsp,%rdi
23978 call syscall_trace_enter
23979 +
23980 + pax_erase_kstack
23981 +
23982 /*
23983 * Reload arg registers from stack in case ptrace changed them.
23984 * We don't reload %rax because syscall_trace_enter() returned
23985 * the value it wants us to use in the table lookup.
23986 */
23987 - LOAD_ARGS ARGOFFSET, 1
23988 + LOAD_ARGS 1
23989 RESTORE_REST
23990 #if __SYSCALL_MASK == ~0
23991 cmpq $__NR_syscall_max,%rax
23992 @@ -559,7 +1034,9 @@ GLOBAL(int_with_check)
23993 andl %edi,%edx
23994 jnz int_careful
23995 andl $~TS_COMPAT,TI_status(%rcx)
23996 - jmp retint_swapgs
23997 + pax_exit_kernel_user
23998 + pax_erase_kstack
23999 + jmp retint_swapgs_pax
24000
24001 /* Either reschedule or signal or syscall exit tracking needed. */
24002 /* First do a reschedule test. */
24003 @@ -605,7 +1082,7 @@ int_restore_rest:
24004 TRACE_IRQS_OFF
24005 jmp int_with_check
24006 CFI_ENDPROC
24007 -END(system_call)
24008 +ENDPROC(system_call)
24009
24010 .macro FORK_LIKE func
24011 ENTRY(stub_\func)
24012 @@ -618,9 +1095,10 @@ ENTRY(stub_\func)
24013 DEFAULT_FRAME 0 8 /* offset 8: return address */
24014 call sys_\func
24015 RESTORE_TOP_OF_STACK %r11, 8
24016 - ret $REST_SKIP /* pop extended registers */
24017 + pax_force_retaddr
24018 + ret
24019 CFI_ENDPROC
24020 -END(stub_\func)
24021 +ENDPROC(stub_\func)
24022 .endm
24023
24024 .macro FIXED_FRAME label,func
24025 @@ -630,9 +1108,10 @@ ENTRY(\label)
24026 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
24027 call \func
24028 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
24029 + pax_force_retaddr
24030 ret
24031 CFI_ENDPROC
24032 -END(\label)
24033 +ENDPROC(\label)
24034 .endm
24035
24036 FORK_LIKE clone
24037 @@ -640,19 +1119,6 @@ END(\label)
24038 FORK_LIKE vfork
24039 FIXED_FRAME stub_iopl, sys_iopl
24040
24041 -ENTRY(ptregscall_common)
24042 - DEFAULT_FRAME 1 8 /* offset 8: return address */
24043 - RESTORE_TOP_OF_STACK %r11, 8
24044 - movq_cfi_restore R15+8, r15
24045 - movq_cfi_restore R14+8, r14
24046 - movq_cfi_restore R13+8, r13
24047 - movq_cfi_restore R12+8, r12
24048 - movq_cfi_restore RBP+8, rbp
24049 - movq_cfi_restore RBX+8, rbx
24050 - ret $REST_SKIP /* pop extended registers */
24051 - CFI_ENDPROC
24052 -END(ptregscall_common)
24053 -
24054 ENTRY(stub_execve)
24055 CFI_STARTPROC
24056 addq $8, %rsp
24057 @@ -664,7 +1130,7 @@ ENTRY(stub_execve)
24058 RESTORE_REST
24059 jmp int_ret_from_sys_call
24060 CFI_ENDPROC
24061 -END(stub_execve)
24062 +ENDPROC(stub_execve)
24063
24064 /*
24065 * sigreturn is special because it needs to restore all registers on return.
24066 @@ -681,7 +1147,7 @@ ENTRY(stub_rt_sigreturn)
24067 RESTORE_REST
24068 jmp int_ret_from_sys_call
24069 CFI_ENDPROC
24070 -END(stub_rt_sigreturn)
24071 +ENDPROC(stub_rt_sigreturn)
24072
24073 #ifdef CONFIG_X86_X32_ABI
24074 ENTRY(stub_x32_rt_sigreturn)
24075 @@ -695,7 +1161,7 @@ ENTRY(stub_x32_rt_sigreturn)
24076 RESTORE_REST
24077 jmp int_ret_from_sys_call
24078 CFI_ENDPROC
24079 -END(stub_x32_rt_sigreturn)
24080 +ENDPROC(stub_x32_rt_sigreturn)
24081
24082 ENTRY(stub_x32_execve)
24083 CFI_STARTPROC
24084 @@ -709,7 +1175,7 @@ ENTRY(stub_x32_execve)
24085 RESTORE_REST
24086 jmp int_ret_from_sys_call
24087 CFI_ENDPROC
24088 -END(stub_x32_execve)
24089 +ENDPROC(stub_x32_execve)
24090
24091 #endif
24092
24093 @@ -746,7 +1212,7 @@ vector=vector+1
24094 2: jmp common_interrupt
24095 .endr
24096 CFI_ENDPROC
24097 -END(irq_entries_start)
24098 +ENDPROC(irq_entries_start)
24099
24100 .previous
24101 END(interrupt)
24102 @@ -763,8 +1229,8 @@ END(interrupt)
24103 /* 0(%rsp): ~(interrupt number) */
24104 .macro interrupt func
24105 /* reserve pt_regs for scratch regs and rbp */
24106 - subq $ORIG_RAX-RBP, %rsp
24107 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
24108 + subq $ORIG_RAX, %rsp
24109 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
24110 SAVE_ARGS_IRQ
24111 call \func
24112 .endm
24113 @@ -787,14 +1253,14 @@ ret_from_intr:
24114
24115 /* Restore saved previous stack */
24116 popq %rsi
24117 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24118 - leaq ARGOFFSET-RBP(%rsi), %rsp
24119 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24120 + movq %rsi, %rsp
24121 CFI_DEF_CFA_REGISTER rsp
24122 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24123 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24124
24125 exit_intr:
24126 GET_THREAD_INFO(%rcx)
24127 - testl $3,CS-ARGOFFSET(%rsp)
24128 + testb $3,CS-ARGOFFSET(%rsp)
24129 je retint_kernel
24130
24131 /* Interrupt came from user space */
24132 @@ -816,12 +1282,16 @@ retint_swapgs: /* return to user-space */
24133 * The iretq could re-enable interrupts:
24134 */
24135 DISABLE_INTERRUPTS(CLBR_ANY)
24136 + pax_exit_kernel_user
24137 +retint_swapgs_pax:
24138 TRACE_IRQS_IRETQ
24139 SWAPGS
24140 jmp restore_args
24141
24142 retint_restore_args: /* return to kernel space */
24143 DISABLE_INTERRUPTS(CLBR_ANY)
24144 + pax_exit_kernel
24145 + pax_force_retaddr (RIP-ARGOFFSET)
24146 /*
24147 * The iretq could re-enable interrupts:
24148 */
24149 @@ -934,7 +1404,7 @@ ENTRY(retint_kernel)
24150 jmp exit_intr
24151 #endif
24152 CFI_ENDPROC
24153 -END(common_interrupt)
24154 +ENDPROC(common_interrupt)
24155
24156 /*
24157 * If IRET takes a fault on the espfix stack, then we
24158 @@ -956,13 +1426,13 @@ __do_double_fault:
24159 cmpq $native_irq_return_iret,%rax
24160 jne do_double_fault /* This shouldn't happen... */
24161 movq PER_CPU_VAR(kernel_stack),%rax
24162 - subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */
24163 + subq $(6*8),%rax /* Reset to original stack */
24164 movq %rax,RSP(%rdi)
24165 movq $0,(%rax) /* Missing (lost) #GP error code */
24166 movq $general_protection,RIP(%rdi)
24167 retq
24168 CFI_ENDPROC
24169 -END(__do_double_fault)
24170 +ENDPROC(__do_double_fault)
24171 #else
24172 # define __do_double_fault do_double_fault
24173 #endif
24174 @@ -979,7 +1449,7 @@ ENTRY(\sym)
24175 interrupt \do_sym
24176 jmp ret_from_intr
24177 CFI_ENDPROC
24178 -END(\sym)
24179 +ENDPROC(\sym)
24180 .endm
24181
24182 #ifdef CONFIG_TRACING
24183 @@ -1052,7 +1522,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24184 /*
24185 * Exception entry points.
24186 */
24187 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24188 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24189
24190 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24191 ENTRY(\sym)
24192 @@ -1103,6 +1573,12 @@ ENTRY(\sym)
24193 .endif
24194
24195 .if \shift_ist != -1
24196 +#ifdef CONFIG_SMP
24197 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24198 + lea init_tss(%r13), %r13
24199 +#else
24200 + lea init_tss(%rip), %r13
24201 +#endif
24202 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24203 .endif
24204
24205 @@ -1119,7 +1595,7 @@ ENTRY(\sym)
24206 .endif
24207
24208 CFI_ENDPROC
24209 -END(\sym)
24210 +ENDPROC(\sym)
24211 .endm
24212
24213 #ifdef CONFIG_TRACING
24214 @@ -1160,9 +1636,10 @@ gs_change:
24215 2: mfence /* workaround */
24216 SWAPGS
24217 popfq_cfi
24218 + pax_force_retaddr
24219 ret
24220 CFI_ENDPROC
24221 -END(native_load_gs_index)
24222 +ENDPROC(native_load_gs_index)
24223
24224 _ASM_EXTABLE(gs_change,bad_gs)
24225 .section .fixup,"ax"
24226 @@ -1190,9 +1667,10 @@ ENTRY(do_softirq_own_stack)
24227 CFI_DEF_CFA_REGISTER rsp
24228 CFI_ADJUST_CFA_OFFSET -8
24229 decl PER_CPU_VAR(irq_count)
24230 + pax_force_retaddr
24231 ret
24232 CFI_ENDPROC
24233 -END(do_softirq_own_stack)
24234 +ENDPROC(do_softirq_own_stack)
24235
24236 #ifdef CONFIG_XEN
24237 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24238 @@ -1230,7 +1708,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24239 decl PER_CPU_VAR(irq_count)
24240 jmp error_exit
24241 CFI_ENDPROC
24242 -END(xen_do_hypervisor_callback)
24243 +ENDPROC(xen_do_hypervisor_callback)
24244
24245 /*
24246 * Hypervisor uses this for application faults while it executes.
24247 @@ -1289,7 +1767,7 @@ ENTRY(xen_failsafe_callback)
24248 SAVE_ALL
24249 jmp error_exit
24250 CFI_ENDPROC
24251 -END(xen_failsafe_callback)
24252 +ENDPROC(xen_failsafe_callback)
24253
24254 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24255 xen_hvm_callback_vector xen_evtchn_do_upcall
24256 @@ -1336,18 +1814,33 @@ ENTRY(paranoid_exit)
24257 DEFAULT_FRAME
24258 DISABLE_INTERRUPTS(CLBR_NONE)
24259 TRACE_IRQS_OFF_DEBUG
24260 - testl %ebx,%ebx /* swapgs needed? */
24261 + testl $1,%ebx /* swapgs needed? */
24262 jnz paranoid_restore
24263 - testl $3,CS(%rsp)
24264 + testb $3,CS(%rsp)
24265 jnz paranoid_userspace
24266 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24267 + pax_exit_kernel
24268 + TRACE_IRQS_IRETQ 0
24269 + SWAPGS_UNSAFE_STACK
24270 + RESTORE_ALL 8
24271 + pax_force_retaddr_bts
24272 + jmp irq_return
24273 +#endif
24274 paranoid_swapgs:
24275 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24276 + pax_exit_kernel_user
24277 +#else
24278 + pax_exit_kernel
24279 +#endif
24280 TRACE_IRQS_IRETQ 0
24281 SWAPGS_UNSAFE_STACK
24282 RESTORE_ALL 8
24283 jmp irq_return
24284 paranoid_restore:
24285 + pax_exit_kernel
24286 TRACE_IRQS_IRETQ_DEBUG 0
24287 RESTORE_ALL 8
24288 + pax_force_retaddr_bts
24289 jmp irq_return
24290 paranoid_userspace:
24291 GET_THREAD_INFO(%rcx)
24292 @@ -1376,7 +1869,7 @@ paranoid_schedule:
24293 TRACE_IRQS_OFF
24294 jmp paranoid_userspace
24295 CFI_ENDPROC
24296 -END(paranoid_exit)
24297 +ENDPROC(paranoid_exit)
24298
24299 /*
24300 * Exception entry point. This expects an error code/orig_rax on the stack.
24301 @@ -1403,12 +1896,23 @@ ENTRY(error_entry)
24302 movq_cfi r14, R14+8
24303 movq_cfi r15, R15+8
24304 xorl %ebx,%ebx
24305 - testl $3,CS+8(%rsp)
24306 + testb $3,CS+8(%rsp)
24307 je error_kernelspace
24308 error_swapgs:
24309 SWAPGS
24310 error_sti:
24311 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24312 + testb $3, CS+8(%rsp)
24313 + jnz 1f
24314 + pax_enter_kernel
24315 + jmp 2f
24316 +1: pax_enter_kernel_user
24317 +2:
24318 +#else
24319 + pax_enter_kernel
24320 +#endif
24321 TRACE_IRQS_OFF
24322 + pax_force_retaddr
24323 ret
24324
24325 /*
24326 @@ -1435,7 +1939,7 @@ bstep_iret:
24327 movq %rcx,RIP+8(%rsp)
24328 jmp error_swapgs
24329 CFI_ENDPROC
24330 -END(error_entry)
24331 +ENDPROC(error_entry)
24332
24333
24334 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24335 @@ -1446,7 +1950,7 @@ ENTRY(error_exit)
24336 DISABLE_INTERRUPTS(CLBR_NONE)
24337 TRACE_IRQS_OFF
24338 GET_THREAD_INFO(%rcx)
24339 - testl %eax,%eax
24340 + testl $1,%eax
24341 jne retint_kernel
24342 LOCKDEP_SYS_EXIT_IRQ
24343 movl TI_flags(%rcx),%edx
24344 @@ -1455,7 +1959,7 @@ ENTRY(error_exit)
24345 jnz retint_careful
24346 jmp retint_swapgs
24347 CFI_ENDPROC
24348 -END(error_exit)
24349 +ENDPROC(error_exit)
24350
24351 /*
24352 * Test if a given stack is an NMI stack or not.
24353 @@ -1513,9 +2017,11 @@ ENTRY(nmi)
24354 * If %cs was not the kernel segment, then the NMI triggered in user
24355 * space, which means it is definitely not nested.
24356 */
24357 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24358 + je 1f
24359 cmpl $__KERNEL_CS, 16(%rsp)
24360 jne first_nmi
24361 -
24362 +1:
24363 /*
24364 * Check the special variable on the stack to see if NMIs are
24365 * executing.
24366 @@ -1549,8 +2055,7 @@ nested_nmi:
24367
24368 1:
24369 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24370 - leaq -1*8(%rsp), %rdx
24371 - movq %rdx, %rsp
24372 + subq $8, %rsp
24373 CFI_ADJUST_CFA_OFFSET 1*8
24374 leaq -10*8(%rsp), %rdx
24375 pushq_cfi $__KERNEL_DS
24376 @@ -1568,6 +2073,7 @@ nested_nmi_out:
24377 CFI_RESTORE rdx
24378
24379 /* No need to check faults here */
24380 +# pax_force_retaddr_bts
24381 INTERRUPT_RETURN
24382
24383 CFI_RESTORE_STATE
24384 @@ -1664,13 +2170,13 @@ end_repeat_nmi:
24385 subq $ORIG_RAX-R15, %rsp
24386 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24387 /*
24388 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24389 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24390 * as we should not be calling schedule in NMI context.
24391 * Even with normal interrupts enabled. An NMI should not be
24392 * setting NEED_RESCHED or anything that normal interrupts and
24393 * exceptions might do.
24394 */
24395 - call save_paranoid
24396 + call save_paranoid_nmi
24397 DEFAULT_FRAME 0
24398
24399 /*
24400 @@ -1680,9 +2186,9 @@ end_repeat_nmi:
24401 * NMI itself takes a page fault, the page fault that was preempted
24402 * will read the information from the NMI page fault and not the
24403 * origin fault. Save it off and restore it if it changes.
24404 - * Use the r12 callee-saved register.
24405 + * Use the r13 callee-saved register.
24406 */
24407 - movq %cr2, %r12
24408 + movq %cr2, %r13
24409
24410 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24411 movq %rsp,%rdi
24412 @@ -1691,29 +2197,34 @@ end_repeat_nmi:
24413
24414 /* Did the NMI take a page fault? Restore cr2 if it did */
24415 movq %cr2, %rcx
24416 - cmpq %rcx, %r12
24417 + cmpq %rcx, %r13
24418 je 1f
24419 - movq %r12, %cr2
24420 + movq %r13, %cr2
24421 1:
24422
24423 - testl %ebx,%ebx /* swapgs needed? */
24424 + testl $1,%ebx /* swapgs needed? */
24425 jnz nmi_restore
24426 nmi_swapgs:
24427 SWAPGS_UNSAFE_STACK
24428 nmi_restore:
24429 + pax_exit_kernel_nmi
24430 /* Pop the extra iret frame at once */
24431 RESTORE_ALL 6*8
24432 + testb $3, 8(%rsp)
24433 + jnz 1f
24434 + pax_force_retaddr_bts
24435 +1:
24436
24437 /* Clear the NMI executing stack variable */
24438 movq $0, 5*8(%rsp)
24439 jmp irq_return
24440 CFI_ENDPROC
24441 -END(nmi)
24442 +ENDPROC(nmi)
24443
24444 ENTRY(ignore_sysret)
24445 CFI_STARTPROC
24446 mov $-ENOSYS,%eax
24447 sysret
24448 CFI_ENDPROC
24449 -END(ignore_sysret)
24450 +ENDPROC(ignore_sysret)
24451
24452 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24453 index 94d857f..bf1f0bf 100644
24454 --- a/arch/x86/kernel/espfix_64.c
24455 +++ b/arch/x86/kernel/espfix_64.c
24456 @@ -197,7 +197,7 @@ void init_espfix_ap(void)
24457 set_pte(&pte_p[n*PTE_STRIDE], pte);
24458
24459 /* Job is done for this CPU and any CPU which shares this page */
24460 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24461 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24462
24463 unlock_done:
24464 mutex_unlock(&espfix_init_mutex);
24465 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24466 index cbc4a91..b38ee45 100644
24467 --- a/arch/x86/kernel/ftrace.c
24468 +++ b/arch/x86/kernel/ftrace.c
24469 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24470 * kernel identity mapping to modify code.
24471 */
24472 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24473 - ip = (unsigned long)__va(__pa_symbol(ip));
24474 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24475
24476 return ip;
24477 }
24478 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24479 {
24480 unsigned char replaced[MCOUNT_INSN_SIZE];
24481
24482 + ip = ktla_ktva(ip);
24483 +
24484 /*
24485 * Note: Due to modules and __init, code can
24486 * disappear and change, we need to protect against faulting
24487 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24488 unsigned char old[MCOUNT_INSN_SIZE];
24489 int ret;
24490
24491 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24492 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24493
24494 ftrace_update_func = ip;
24495 /* Make sure the breakpoints see the ftrace_update_func update */
24496 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24497 unsigned char replaced[MCOUNT_INSN_SIZE];
24498 unsigned char brk = BREAKPOINT_INSTRUCTION;
24499
24500 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24501 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24502 return -EFAULT;
24503
24504 /* Make sure it is what we expect it to be */
24505 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24506 index eda1a86..8f6df48 100644
24507 --- a/arch/x86/kernel/head64.c
24508 +++ b/arch/x86/kernel/head64.c
24509 @@ -67,12 +67,12 @@ again:
24510 pgd = *pgd_p;
24511
24512 /*
24513 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24514 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24515 + * The use of __early_va rather than __va here is critical:
24516 + * __va would point us back into the dynamic
24517 * range and we might end up looping forever...
24518 */
24519 if (pgd)
24520 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24521 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24522 else {
24523 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24524 reset_early_page_tables();
24525 @@ -82,13 +82,13 @@ again:
24526 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24527 for (i = 0; i < PTRS_PER_PUD; i++)
24528 pud_p[i] = 0;
24529 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24530 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24531 }
24532 pud_p += pud_index(address);
24533 pud = *pud_p;
24534
24535 if (pud)
24536 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24537 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24538 else {
24539 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24540 reset_early_page_tables();
24541 @@ -98,7 +98,7 @@ again:
24542 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24543 for (i = 0; i < PTRS_PER_PMD; i++)
24544 pmd_p[i] = 0;
24545 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24546 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24547 }
24548 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24549 pmd_p[pmd_index(address)] = pmd;
24550 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24551 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24552 early_printk("Kernel alive\n");
24553
24554 - clear_page(init_level4_pgt);
24555 /* set init_level4_pgt kernel high mapping*/
24556 init_level4_pgt[511] = early_level4_pgt[511];
24557
24558 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24559 index f36bd42..0ab4474 100644
24560 --- a/arch/x86/kernel/head_32.S
24561 +++ b/arch/x86/kernel/head_32.S
24562 @@ -26,6 +26,12 @@
24563 /* Physical address */
24564 #define pa(X) ((X) - __PAGE_OFFSET)
24565
24566 +#ifdef CONFIG_PAX_KERNEXEC
24567 +#define ta(X) (X)
24568 +#else
24569 +#define ta(X) ((X) - __PAGE_OFFSET)
24570 +#endif
24571 +
24572 /*
24573 * References to members of the new_cpu_data structure.
24574 */
24575 @@ -55,11 +61,7 @@
24576 * and small than max_low_pfn, otherwise will waste some page table entries
24577 */
24578
24579 -#if PTRS_PER_PMD > 1
24580 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24581 -#else
24582 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24583 -#endif
24584 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24585
24586 /* Number of possible pages in the lowmem region */
24587 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24588 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24589 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24590
24591 /*
24592 + * Real beginning of normal "text" segment
24593 + */
24594 +ENTRY(stext)
24595 +ENTRY(_stext)
24596 +
24597 +/*
24598 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24599 * %esi points to the real-mode code as a 32-bit pointer.
24600 * CS and DS must be 4 GB flat segments, but we don't depend on
24601 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24602 * can.
24603 */
24604 __HEAD
24605 +
24606 +#ifdef CONFIG_PAX_KERNEXEC
24607 + jmp startup_32
24608 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24609 +.fill PAGE_SIZE-5,1,0xcc
24610 +#endif
24611 +
24612 ENTRY(startup_32)
24613 movl pa(stack_start),%ecx
24614
24615 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24616 2:
24617 leal -__PAGE_OFFSET(%ecx),%esp
24618
24619 +#ifdef CONFIG_SMP
24620 + movl $pa(cpu_gdt_table),%edi
24621 + movl $__per_cpu_load,%eax
24622 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24623 + rorl $16,%eax
24624 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24625 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24626 + movl $__per_cpu_end - 1,%eax
24627 + subl $__per_cpu_start,%eax
24628 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24629 +#endif
24630 +
24631 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24632 + movl $NR_CPUS,%ecx
24633 + movl $pa(cpu_gdt_table),%edi
24634 +1:
24635 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24636 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24637 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24638 + addl $PAGE_SIZE_asm,%edi
24639 + loop 1b
24640 +#endif
24641 +
24642 +#ifdef CONFIG_PAX_KERNEXEC
24643 + movl $pa(boot_gdt),%edi
24644 + movl $__LOAD_PHYSICAL_ADDR,%eax
24645 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24646 + rorl $16,%eax
24647 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24648 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24649 + rorl $16,%eax
24650 +
24651 + ljmp $(__BOOT_CS),$1f
24652 +1:
24653 +
24654 + movl $NR_CPUS,%ecx
24655 + movl $pa(cpu_gdt_table),%edi
24656 + addl $__PAGE_OFFSET,%eax
24657 +1:
24658 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24659 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24660 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24661 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24662 + rorl $16,%eax
24663 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24664 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24665 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24666 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24667 + rorl $16,%eax
24668 + addl $PAGE_SIZE_asm,%edi
24669 + loop 1b
24670 +#endif
24671 +
24672 /*
24673 * Clear BSS first so that there are no surprises...
24674 */
24675 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24676 movl %eax, pa(max_pfn_mapped)
24677
24678 /* Do early initialization of the fixmap area */
24679 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24680 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24681 +#ifdef CONFIG_COMPAT_VDSO
24682 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24683 +#else
24684 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24685 +#endif
24686 #else /* Not PAE */
24687
24688 page_pde_offset = (__PAGE_OFFSET >> 20);
24689 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24690 movl %eax, pa(max_pfn_mapped)
24691
24692 /* Do early initialization of the fixmap area */
24693 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24694 - movl %eax,pa(initial_page_table+0xffc)
24695 +#ifdef CONFIG_COMPAT_VDSO
24696 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24697 +#else
24698 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24699 +#endif
24700 #endif
24701
24702 #ifdef CONFIG_PARAVIRT
24703 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24704 cmpl $num_subarch_entries, %eax
24705 jae bad_subarch
24706
24707 - movl pa(subarch_entries)(,%eax,4), %eax
24708 - subl $__PAGE_OFFSET, %eax
24709 - jmp *%eax
24710 + jmp *pa(subarch_entries)(,%eax,4)
24711
24712 bad_subarch:
24713 WEAK(lguest_entry)
24714 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24715 __INITDATA
24716
24717 subarch_entries:
24718 - .long default_entry /* normal x86/PC */
24719 - .long lguest_entry /* lguest hypervisor */
24720 - .long xen_entry /* Xen hypervisor */
24721 - .long default_entry /* Moorestown MID */
24722 + .long ta(default_entry) /* normal x86/PC */
24723 + .long ta(lguest_entry) /* lguest hypervisor */
24724 + .long ta(xen_entry) /* Xen hypervisor */
24725 + .long ta(default_entry) /* Moorestown MID */
24726 num_subarch_entries = (. - subarch_entries) / 4
24727 .previous
24728 #else
24729 @@ -354,6 +426,7 @@ default_entry:
24730 movl pa(mmu_cr4_features),%eax
24731 movl %eax,%cr4
24732
24733 +#ifdef CONFIG_X86_PAE
24734 testb $X86_CR4_PAE, %al # check if PAE is enabled
24735 jz enable_paging
24736
24737 @@ -382,6 +455,9 @@ default_entry:
24738 /* Make changes effective */
24739 wrmsr
24740
24741 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24742 +#endif
24743 +
24744 enable_paging:
24745
24746 /*
24747 @@ -449,14 +525,20 @@ is486:
24748 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24749 movl %eax,%ss # after changing gdt.
24750
24751 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24752 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24753 movl %eax,%ds
24754 movl %eax,%es
24755
24756 movl $(__KERNEL_PERCPU), %eax
24757 movl %eax,%fs # set this cpu's percpu
24758
24759 +#ifdef CONFIG_CC_STACKPROTECTOR
24760 movl $(__KERNEL_STACK_CANARY),%eax
24761 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24762 + movl $(__USER_DS),%eax
24763 +#else
24764 + xorl %eax,%eax
24765 +#endif
24766 movl %eax,%gs
24767
24768 xorl %eax,%eax # Clear LDT
24769 @@ -512,8 +594,11 @@ setup_once:
24770 * relocation. Manually set base address in stack canary
24771 * segment descriptor.
24772 */
24773 - movl $gdt_page,%eax
24774 + movl $cpu_gdt_table,%eax
24775 movl $stack_canary,%ecx
24776 +#ifdef CONFIG_SMP
24777 + addl $__per_cpu_load,%ecx
24778 +#endif
24779 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24780 shrl $16, %ecx
24781 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24782 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24783 cmpl $2,(%esp) # X86_TRAP_NMI
24784 je is_nmi # Ignore NMI
24785
24786 - cmpl $2,%ss:early_recursion_flag
24787 + cmpl $1,%ss:early_recursion_flag
24788 je hlt_loop
24789 incl %ss:early_recursion_flag
24790
24791 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24792 pushl (20+6*4)(%esp) /* trapno */
24793 pushl $fault_msg
24794 call printk
24795 -#endif
24796 call dump_stack
24797 +#endif
24798 hlt_loop:
24799 hlt
24800 jmp hlt_loop
24801 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24802 /* This is the default interrupt "handler" :-) */
24803 ALIGN
24804 ignore_int:
24805 - cld
24806 #ifdef CONFIG_PRINTK
24807 + cmpl $2,%ss:early_recursion_flag
24808 + je hlt_loop
24809 + incl %ss:early_recursion_flag
24810 + cld
24811 pushl %eax
24812 pushl %ecx
24813 pushl %edx
24814 @@ -617,9 +705,6 @@ ignore_int:
24815 movl $(__KERNEL_DS),%eax
24816 movl %eax,%ds
24817 movl %eax,%es
24818 - cmpl $2,early_recursion_flag
24819 - je hlt_loop
24820 - incl early_recursion_flag
24821 pushl 16(%esp)
24822 pushl 24(%esp)
24823 pushl 32(%esp)
24824 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24825 /*
24826 * BSS section
24827 */
24828 -__PAGE_ALIGNED_BSS
24829 - .align PAGE_SIZE
24830 #ifdef CONFIG_X86_PAE
24831 +.section .initial_pg_pmd,"a",@progbits
24832 initial_pg_pmd:
24833 .fill 1024*KPMDS,4,0
24834 #else
24835 +.section .initial_page_table,"a",@progbits
24836 ENTRY(initial_page_table)
24837 .fill 1024,4,0
24838 #endif
24839 +.section .initial_pg_fixmap,"a",@progbits
24840 initial_pg_fixmap:
24841 .fill 1024,4,0
24842 +.section .empty_zero_page,"a",@progbits
24843 ENTRY(empty_zero_page)
24844 .fill 4096,1,0
24845 +.section .swapper_pg_dir,"a",@progbits
24846 ENTRY(swapper_pg_dir)
24847 +#ifdef CONFIG_X86_PAE
24848 + .fill 4,8,0
24849 +#else
24850 .fill 1024,4,0
24851 +#endif
24852
24853 /*
24854 * This starts the data section.
24855 */
24856 #ifdef CONFIG_X86_PAE
24857 -__PAGE_ALIGNED_DATA
24858 - /* Page-aligned for the benefit of paravirt? */
24859 - .align PAGE_SIZE
24860 +.section .initial_page_table,"a",@progbits
24861 ENTRY(initial_page_table)
24862 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24863 # if KPMDS == 3
24864 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24865 # error "Kernel PMDs should be 1, 2 or 3"
24866 # endif
24867 .align PAGE_SIZE /* needs to be page-sized too */
24868 +
24869 +#ifdef CONFIG_PAX_PER_CPU_PGD
24870 +ENTRY(cpu_pgd)
24871 + .rept 2*NR_CPUS
24872 + .fill 4,8,0
24873 + .endr
24874 +#endif
24875 +
24876 #endif
24877
24878 .data
24879 .balign 4
24880 ENTRY(stack_start)
24881 - .long init_thread_union+THREAD_SIZE
24882 + .long init_thread_union+THREAD_SIZE-8
24883
24884 __INITRODATA
24885 int_msg:
24886 @@ -727,7 +825,7 @@ fault_msg:
24887 * segment size, and 32-bit linear address value:
24888 */
24889
24890 - .data
24891 +.section .rodata,"a",@progbits
24892 .globl boot_gdt_descr
24893 .globl idt_descr
24894
24895 @@ -736,7 +834,7 @@ fault_msg:
24896 .word 0 # 32 bit align gdt_desc.address
24897 boot_gdt_descr:
24898 .word __BOOT_DS+7
24899 - .long boot_gdt - __PAGE_OFFSET
24900 + .long pa(boot_gdt)
24901
24902 .word 0 # 32-bit align idt_desc.address
24903 idt_descr:
24904 @@ -747,7 +845,7 @@ idt_descr:
24905 .word 0 # 32 bit align gdt_desc.address
24906 ENTRY(early_gdt_descr)
24907 .word GDT_ENTRIES*8-1
24908 - .long gdt_page /* Overwritten for secondary CPUs */
24909 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24910
24911 /*
24912 * The boot_gdt must mirror the equivalent in setup.S and is
24913 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24914 .align L1_CACHE_BYTES
24915 ENTRY(boot_gdt)
24916 .fill GDT_ENTRY_BOOT_CS,8,0
24917 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24918 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24919 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24920 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24921 +
24922 + .align PAGE_SIZE_asm
24923 +ENTRY(cpu_gdt_table)
24924 + .rept NR_CPUS
24925 + .quad 0x0000000000000000 /* NULL descriptor */
24926 + .quad 0x0000000000000000 /* 0x0b reserved */
24927 + .quad 0x0000000000000000 /* 0x13 reserved */
24928 + .quad 0x0000000000000000 /* 0x1b reserved */
24929 +
24930 +#ifdef CONFIG_PAX_KERNEXEC
24931 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24932 +#else
24933 + .quad 0x0000000000000000 /* 0x20 unused */
24934 +#endif
24935 +
24936 + .quad 0x0000000000000000 /* 0x28 unused */
24937 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24938 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24939 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24940 + .quad 0x0000000000000000 /* 0x4b reserved */
24941 + .quad 0x0000000000000000 /* 0x53 reserved */
24942 + .quad 0x0000000000000000 /* 0x5b reserved */
24943 +
24944 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24945 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24946 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24947 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24948 +
24949 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24950 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24951 +
24952 + /*
24953 + * Segments used for calling PnP BIOS have byte granularity.
24954 + * The code segments and data segments have fixed 64k limits,
24955 + * the transfer segment sizes are set at run time.
24956 + */
24957 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24958 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24959 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24960 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24961 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24962 +
24963 + /*
24964 + * The APM segments have byte granularity and their bases
24965 + * are set at run time. All have 64k limits.
24966 + */
24967 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24968 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24969 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24970 +
24971 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24972 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24973 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24974 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24975 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24976 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24977 +
24978 + /* Be sure this is zeroed to avoid false validations in Xen */
24979 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24980 + .endr
24981 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24982 index a468c0a..c7dec74 100644
24983 --- a/arch/x86/kernel/head_64.S
24984 +++ b/arch/x86/kernel/head_64.S
24985 @@ -20,6 +20,8 @@
24986 #include <asm/processor-flags.h>
24987 #include <asm/percpu.h>
24988 #include <asm/nops.h>
24989 +#include <asm/cpufeature.h>
24990 +#include <asm/alternative-asm.h>
24991
24992 #ifdef CONFIG_PARAVIRT
24993 #include <asm/asm-offsets.h>
24994 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24995 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24996 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24997 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24998 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24999 +L3_VMALLOC_START = pud_index(VMALLOC_START)
25000 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
25001 +L3_VMALLOC_END = pud_index(VMALLOC_END)
25002 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
25003 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
25004
25005 .text
25006 __HEAD
25007 @@ -89,11 +97,24 @@ startup_64:
25008 * Fixup the physical addresses in the page table
25009 */
25010 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
25011 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
25012 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
25013 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
25014 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
25015 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
25016
25017 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
25018 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
25019 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
25020 +#ifndef CONFIG_XEN
25021 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
25022 +#endif
25023 +
25024 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
25025 +
25026 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
25027 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
25028
25029 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
25030 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
25031
25032 /*
25033 * Set up the identity mapping for the switchover. These
25034 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
25035 movq $(init_level4_pgt - __START_KERNEL_map), %rax
25036 1:
25037
25038 - /* Enable PAE mode and PGE */
25039 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
25040 + /* Enable PAE mode and PSE/PGE */
25041 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
25042 movq %rcx, %cr4
25043
25044 /* Setup early boot stage 4 level pagetables. */
25045 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
25046 movl $MSR_EFER, %ecx
25047 rdmsr
25048 btsl $_EFER_SCE, %eax /* Enable System Call */
25049 - btl $20,%edi /* No Execute supported? */
25050 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
25051 jnc 1f
25052 btsl $_EFER_NX, %eax
25053 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
25054 +#ifndef CONFIG_EFI
25055 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
25056 +#endif
25057 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
25058 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
25059 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
25060 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
25061 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
25062 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
25063 1: wrmsr /* Make changes effective */
25064
25065 /* Setup cr0 */
25066 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
25067 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
25068 * address given in m16:64.
25069 */
25070 + pax_set_fptr_mask
25071 movq initial_code(%rip),%rax
25072 pushq $0 # fake return address to stop unwinder
25073 pushq $__KERNEL_CS # set correct cs
25074 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
25075 .quad INIT_PER_CPU_VAR(irq_stack_union)
25076
25077 GLOBAL(stack_start)
25078 - .quad init_thread_union+THREAD_SIZE-8
25079 + .quad init_thread_union+THREAD_SIZE-16
25080 .word 0
25081 __FINITDATA
25082
25083 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
25084 call dump_stack
25085 #ifdef CONFIG_KALLSYMS
25086 leaq early_idt_ripmsg(%rip),%rdi
25087 - movq 40(%rsp),%rsi # %rip again
25088 + movq 88(%rsp),%rsi # %rip again
25089 call __print_symbol
25090 #endif
25091 #endif /* EARLY_PRINTK */
25092 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
25093 early_recursion_flag:
25094 .long 0
25095
25096 + .section .rodata,"a",@progbits
25097 #ifdef CONFIG_EARLY_PRINTK
25098 early_idt_msg:
25099 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
25100 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
25101 NEXT_PAGE(early_dynamic_pgts)
25102 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25103
25104 - .data
25105 + .section .rodata,"a",@progbits
25106
25107 -#ifndef CONFIG_XEN
25108 NEXT_PAGE(init_level4_pgt)
25109 - .fill 512,8,0
25110 -#else
25111 -NEXT_PAGE(init_level4_pgt)
25112 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25113 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25114 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25115 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
25116 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25117 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
25118 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25119 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25120 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25121 .org init_level4_pgt + L4_START_KERNEL*8, 0
25122 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25123 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25124
25125 +#ifdef CONFIG_PAX_PER_CPU_PGD
25126 +NEXT_PAGE(cpu_pgd)
25127 + .rept 2*NR_CPUS
25128 + .fill 512,8,0
25129 + .endr
25130 +#endif
25131 +
25132 NEXT_PAGE(level3_ident_pgt)
25133 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25134 +#ifdef CONFIG_XEN
25135 .fill 511, 8, 0
25136 +#else
25137 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25138 + .fill 510,8,0
25139 +#endif
25140 +
25141 +NEXT_PAGE(level3_vmalloc_start_pgt)
25142 + .fill 512,8,0
25143 +
25144 +NEXT_PAGE(level3_vmalloc_end_pgt)
25145 + .fill 512,8,0
25146 +
25147 +NEXT_PAGE(level3_vmemmap_pgt)
25148 + .fill L3_VMEMMAP_START,8,0
25149 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25150 +
25151 NEXT_PAGE(level2_ident_pgt)
25152 - /* Since I easily can, map the first 1G.
25153 + /* Since I easily can, map the first 2G.
25154 * Don't set NX because code runs from these pages.
25155 */
25156 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25157 -#endif
25158 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25159
25160 NEXT_PAGE(level3_kernel_pgt)
25161 .fill L3_START_KERNEL,8,0
25162 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
25163 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25164 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25165
25166 +NEXT_PAGE(level2_vmemmap_pgt)
25167 + .fill 512,8,0
25168 +
25169 NEXT_PAGE(level2_kernel_pgt)
25170 /*
25171 * 512 MB kernel mapping. We spend a full page on this pagetable
25172 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
25173 NEXT_PAGE(level2_fixmap_pgt)
25174 .fill 506,8,0
25175 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25176 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25177 - .fill 5,8,0
25178 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25179 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25180 + .fill 4,8,0
25181
25182 NEXT_PAGE(level1_fixmap_pgt)
25183 .fill 512,8,0
25184
25185 +NEXT_PAGE(level1_vsyscall_pgt)
25186 + .fill 512,8,0
25187 +
25188 #undef PMDS
25189
25190 - .data
25191 + .align PAGE_SIZE
25192 +ENTRY(cpu_gdt_table)
25193 + .rept NR_CPUS
25194 + .quad 0x0000000000000000 /* NULL descriptor */
25195 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25196 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25197 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25198 + .quad 0x00cffb000000ffff /* __USER32_CS */
25199 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25200 + .quad 0x00affb000000ffff /* __USER_CS */
25201 +
25202 +#ifdef CONFIG_PAX_KERNEXEC
25203 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25204 +#else
25205 + .quad 0x0 /* unused */
25206 +#endif
25207 +
25208 + .quad 0,0 /* TSS */
25209 + .quad 0,0 /* LDT */
25210 + .quad 0,0,0 /* three TLS descriptors */
25211 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25212 + /* asm/segment.h:GDT_ENTRIES must match this */
25213 +
25214 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25215 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25216 +#else
25217 + .quad 0x0 /* unused */
25218 +#endif
25219 +
25220 + /* zero the remaining page */
25221 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25222 + .endr
25223 +
25224 .align 16
25225 .globl early_gdt_descr
25226 early_gdt_descr:
25227 .word GDT_ENTRIES*8-1
25228 early_gdt_descr_base:
25229 - .quad INIT_PER_CPU_VAR(gdt_page)
25230 + .quad cpu_gdt_table
25231
25232 ENTRY(phys_base)
25233 /* This must match the first entry in level2_kernel_pgt */
25234 .quad 0x0000000000000000
25235
25236 #include "../../x86/xen/xen-head.S"
25237 -
25238 - __PAGE_ALIGNED_BSS
25239 +
25240 + .section .rodata,"a",@progbits
25241 NEXT_PAGE(empty_zero_page)
25242 .skip PAGE_SIZE
25243 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25244 index 05fd74f..c3548b1 100644
25245 --- a/arch/x86/kernel/i386_ksyms_32.c
25246 +++ b/arch/x86/kernel/i386_ksyms_32.c
25247 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25248 EXPORT_SYMBOL(cmpxchg8b_emu);
25249 #endif
25250
25251 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25252 +
25253 /* Networking helper routines. */
25254 EXPORT_SYMBOL(csum_partial_copy_generic);
25255 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25256 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25257
25258 EXPORT_SYMBOL(__get_user_1);
25259 EXPORT_SYMBOL(__get_user_2);
25260 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25261 EXPORT_SYMBOL(___preempt_schedule_context);
25262 #endif
25263 #endif
25264 +
25265 +#ifdef CONFIG_PAX_KERNEXEC
25266 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25267 +#endif
25268 +
25269 +#ifdef CONFIG_PAX_PER_CPU_PGD
25270 +EXPORT_SYMBOL(cpu_pgd);
25271 +#endif
25272 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25273 index d5dd808..b6432cf 100644
25274 --- a/arch/x86/kernel/i387.c
25275 +++ b/arch/x86/kernel/i387.c
25276 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25277 static inline bool interrupted_user_mode(void)
25278 {
25279 struct pt_regs *regs = get_irq_regs();
25280 - return regs && user_mode_vm(regs);
25281 + return regs && user_mode(regs);
25282 }
25283
25284 /*
25285 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25286 index 8af8171..f8c1169 100644
25287 --- a/arch/x86/kernel/i8259.c
25288 +++ b/arch/x86/kernel/i8259.c
25289 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25290 static void make_8259A_irq(unsigned int irq)
25291 {
25292 disable_irq_nosync(irq);
25293 - io_apic_irqs &= ~(1<<irq);
25294 + io_apic_irqs &= ~(1UL<<irq);
25295 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25296 i8259A_chip.name);
25297 enable_irq(irq);
25298 @@ -209,7 +209,7 @@ spurious_8259A_irq:
25299 "spurious 8259A interrupt: IRQ%d.\n", irq);
25300 spurious_irq_mask |= irqmask;
25301 }
25302 - atomic_inc(&irq_err_count);
25303 + atomic_inc_unchecked(&irq_err_count);
25304 /*
25305 * Theoretically we do not have to handle this IRQ,
25306 * but in Linux this does not cause problems and is
25307 @@ -350,14 +350,16 @@ static void init_8259A(int auto_eoi)
25308 /* (slave's support for AEOI in flat mode is to be investigated) */
25309 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25310
25311 + pax_open_kernel();
25312 if (auto_eoi)
25313 /*
25314 * In AEOI mode we just have to mask the interrupt
25315 * when acking.
25316 */
25317 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25318 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25319 else
25320 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25321 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25322 + pax_close_kernel();
25323
25324 udelay(100); /* wait for 8259A to initialize */
25325
25326 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25327 index a979b5b..1d6db75 100644
25328 --- a/arch/x86/kernel/io_delay.c
25329 +++ b/arch/x86/kernel/io_delay.c
25330 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25331 * Quirk table for systems that misbehave (lock up, etc.) if port
25332 * 0x80 is used:
25333 */
25334 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25335 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25336 {
25337 .callback = dmi_io_delay_0xed_port,
25338 .ident = "Compaq Presario V6000",
25339 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25340 index 4ddaf66..49d5c18 100644
25341 --- a/arch/x86/kernel/ioport.c
25342 +++ b/arch/x86/kernel/ioport.c
25343 @@ -6,6 +6,7 @@
25344 #include <linux/sched.h>
25345 #include <linux/kernel.h>
25346 #include <linux/capability.h>
25347 +#include <linux/security.h>
25348 #include <linux/errno.h>
25349 #include <linux/types.h>
25350 #include <linux/ioport.h>
25351 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25352 return -EINVAL;
25353 if (turn_on && !capable(CAP_SYS_RAWIO))
25354 return -EPERM;
25355 +#ifdef CONFIG_GRKERNSEC_IO
25356 + if (turn_on && grsec_disable_privio) {
25357 + gr_handle_ioperm();
25358 + return -ENODEV;
25359 + }
25360 +#endif
25361
25362 /*
25363 * If it's the first ioperm() call in this thread's lifetime, set the
25364 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25365 * because the ->io_bitmap_max value must match the bitmap
25366 * contents:
25367 */
25368 - tss = &per_cpu(init_tss, get_cpu());
25369 + tss = init_tss + get_cpu();
25370
25371 if (turn_on)
25372 bitmap_clear(t->io_bitmap_ptr, from, num);
25373 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25374 if (level > old) {
25375 if (!capable(CAP_SYS_RAWIO))
25376 return -EPERM;
25377 +#ifdef CONFIG_GRKERNSEC_IO
25378 + if (grsec_disable_privio) {
25379 + gr_handle_iopl();
25380 + return -ENODEV;
25381 + }
25382 +#endif
25383 }
25384 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25385 t->iopl = level << 12;
25386 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25387 index 922d285..6d20692 100644
25388 --- a/arch/x86/kernel/irq.c
25389 +++ b/arch/x86/kernel/irq.c
25390 @@ -22,7 +22,7 @@
25391 #define CREATE_TRACE_POINTS
25392 #include <asm/trace/irq_vectors.h>
25393
25394 -atomic_t irq_err_count;
25395 +atomic_unchecked_t irq_err_count;
25396
25397 /* Function pointer for generic interrupt vector handling */
25398 void (*x86_platform_ipi_callback)(void) = NULL;
25399 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25400 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25401 seq_printf(p, " Hypervisor callback interrupts\n");
25402 #endif
25403 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25404 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25405 #if defined(CONFIG_X86_IO_APIC)
25406 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25407 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25408 #endif
25409 return 0;
25410 }
25411 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25412
25413 u64 arch_irq_stat(void)
25414 {
25415 - u64 sum = atomic_read(&irq_err_count);
25416 + u64 sum = atomic_read_unchecked(&irq_err_count);
25417 return sum;
25418 }
25419
25420 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25421 index 63ce838..2ea3e06 100644
25422 --- a/arch/x86/kernel/irq_32.c
25423 +++ b/arch/x86/kernel/irq_32.c
25424 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25425
25426 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25427
25428 +extern void gr_handle_kernel_exploit(void);
25429 +
25430 int sysctl_panic_on_stackoverflow __read_mostly;
25431
25432 /* Debugging check for stack overflow: is there less than 1KB free? */
25433 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25434 __asm__ __volatile__("andl %%esp,%0" :
25435 "=r" (sp) : "0" (THREAD_SIZE - 1));
25436
25437 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25438 + return sp < STACK_WARN;
25439 }
25440
25441 static void print_stack_overflow(void)
25442 {
25443 printk(KERN_WARNING "low stack detected by irq handler\n");
25444 dump_stack();
25445 + gr_handle_kernel_exploit();
25446 if (sysctl_panic_on_stackoverflow)
25447 panic("low stack detected by irq handler - check messages\n");
25448 }
25449 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25450 static inline int
25451 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25452 {
25453 - struct irq_stack *curstk, *irqstk;
25454 + struct irq_stack *irqstk;
25455 u32 *isp, *prev_esp, arg1, arg2;
25456
25457 - curstk = (struct irq_stack *) current_stack();
25458 irqstk = __this_cpu_read(hardirq_stack);
25459
25460 /*
25461 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25462 * handler) we can't do that and just have to keep using the
25463 * current stack (which is the irq stack already after all)
25464 */
25465 - if (unlikely(curstk == irqstk))
25466 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25467 return 0;
25468
25469 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25470 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25471
25472 /* Save the next esp at the bottom of the stack */
25473 prev_esp = (u32 *)irqstk;
25474 *prev_esp = current_stack_pointer;
25475
25476 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25477 + __set_fs(MAKE_MM_SEG(0));
25478 +#endif
25479 +
25480 if (unlikely(overflow))
25481 call_on_stack(print_stack_overflow, isp);
25482
25483 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25484 : "0" (irq), "1" (desc), "2" (isp),
25485 "D" (desc->handle_irq)
25486 : "memory", "cc", "ecx");
25487 +
25488 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25489 + __set_fs(current_thread_info()->addr_limit);
25490 +#endif
25491 +
25492 return 1;
25493 }
25494
25495 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25496 */
25497 void irq_ctx_init(int cpu)
25498 {
25499 - struct irq_stack *irqstk;
25500 -
25501 if (per_cpu(hardirq_stack, cpu))
25502 return;
25503
25504 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25505 - THREADINFO_GFP,
25506 - THREAD_SIZE_ORDER));
25507 - per_cpu(hardirq_stack, cpu) = irqstk;
25508 -
25509 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25510 - THREADINFO_GFP,
25511 - THREAD_SIZE_ORDER));
25512 - per_cpu(softirq_stack, cpu) = irqstk;
25513 -
25514 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25515 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25516 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25517 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25518 }
25519
25520 void do_softirq_own_stack(void)
25521 {
25522 - struct thread_info *curstk;
25523 struct irq_stack *irqstk;
25524 u32 *isp, *prev_esp;
25525
25526 - curstk = current_stack();
25527 irqstk = __this_cpu_read(softirq_stack);
25528
25529 /* build the stack frame on the softirq stack */
25530 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25531 prev_esp = (u32 *)irqstk;
25532 *prev_esp = current_stack_pointer;
25533
25534 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25535 + __set_fs(MAKE_MM_SEG(0));
25536 +#endif
25537 +
25538 call_on_stack(__do_softirq, isp);
25539 +
25540 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25541 + __set_fs(current_thread_info()->addr_limit);
25542 +#endif
25543 +
25544 }
25545
25546 bool handle_irq(unsigned irq, struct pt_regs *regs)
25547 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25548 if (unlikely(!desc))
25549 return false;
25550
25551 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25552 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25553 if (unlikely(overflow))
25554 print_stack_overflow();
25555 desc->handle_irq(irq, desc);
25556 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25557 index 4d1c746..55a22d6 100644
25558 --- a/arch/x86/kernel/irq_64.c
25559 +++ b/arch/x86/kernel/irq_64.c
25560 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25561 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25562 EXPORT_PER_CPU_SYMBOL(irq_regs);
25563
25564 +extern void gr_handle_kernel_exploit(void);
25565 +
25566 int sysctl_panic_on_stackoverflow;
25567
25568 /*
25569 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25570 u64 estack_top, estack_bottom;
25571 u64 curbase = (u64)task_stack_page(current);
25572
25573 - if (user_mode_vm(regs))
25574 + if (user_mode(regs))
25575 return;
25576
25577 if (regs->sp >= curbase + sizeof(struct thread_info) +
25578 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25579 irq_stack_top, irq_stack_bottom,
25580 estack_top, estack_bottom);
25581
25582 + gr_handle_kernel_exploit();
25583 +
25584 if (sysctl_panic_on_stackoverflow)
25585 panic("low stack detected by irq handler - check messages\n");
25586 #endif
25587 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25588 index 26d5a55..a01160a 100644
25589 --- a/arch/x86/kernel/jump_label.c
25590 +++ b/arch/x86/kernel/jump_label.c
25591 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25592 * Jump label is enabled for the first time.
25593 * So we expect a default_nop...
25594 */
25595 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25596 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25597 != 0))
25598 bug_at((void *)entry->code, __LINE__);
25599 } else {
25600 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25601 * ...otherwise expect an ideal_nop. Otherwise
25602 * something went horribly wrong.
25603 */
25604 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25605 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25606 != 0))
25607 bug_at((void *)entry->code, __LINE__);
25608 }
25609 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25610 * are converting the default nop to the ideal nop.
25611 */
25612 if (init) {
25613 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25614 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25615 bug_at((void *)entry->code, __LINE__);
25616 } else {
25617 code.jump = 0xe9;
25618 code.offset = entry->target -
25619 (entry->code + JUMP_LABEL_NOP_SIZE);
25620 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25621 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25622 bug_at((void *)entry->code, __LINE__);
25623 }
25624 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25625 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25626 index 7ec1d5f..5a7d130 100644
25627 --- a/arch/x86/kernel/kgdb.c
25628 +++ b/arch/x86/kernel/kgdb.c
25629 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25630 #ifdef CONFIG_X86_32
25631 switch (regno) {
25632 case GDB_SS:
25633 - if (!user_mode_vm(regs))
25634 + if (!user_mode(regs))
25635 *(unsigned long *)mem = __KERNEL_DS;
25636 break;
25637 case GDB_SP:
25638 - if (!user_mode_vm(regs))
25639 + if (!user_mode(regs))
25640 *(unsigned long *)mem = kernel_stack_pointer(regs);
25641 break;
25642 case GDB_GS:
25643 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25644 bp->attr.bp_addr = breakinfo[breakno].addr;
25645 bp->attr.bp_len = breakinfo[breakno].len;
25646 bp->attr.bp_type = breakinfo[breakno].type;
25647 - info->address = breakinfo[breakno].addr;
25648 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25649 + info->address = ktla_ktva(breakinfo[breakno].addr);
25650 + else
25651 + info->address = breakinfo[breakno].addr;
25652 info->len = breakinfo[breakno].len;
25653 info->type = breakinfo[breakno].type;
25654 val = arch_install_hw_breakpoint(bp);
25655 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25656 case 'k':
25657 /* clear the trace bit */
25658 linux_regs->flags &= ~X86_EFLAGS_TF;
25659 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25660 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25661
25662 /* set the trace bit if we're stepping */
25663 if (remcomInBuffer[0] == 's') {
25664 linux_regs->flags |= X86_EFLAGS_TF;
25665 - atomic_set(&kgdb_cpu_doing_single_step,
25666 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25667 raw_smp_processor_id());
25668 }
25669
25670 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25671
25672 switch (cmd) {
25673 case DIE_DEBUG:
25674 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25675 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25676 if (user_mode(regs))
25677 return single_step_cont(regs, args);
25678 break;
25679 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25680 #endif /* CONFIG_DEBUG_RODATA */
25681
25682 bpt->type = BP_BREAKPOINT;
25683 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25684 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25685 BREAK_INSTR_SIZE);
25686 if (err)
25687 return err;
25688 - err = probe_kernel_write((char *)bpt->bpt_addr,
25689 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25690 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25691 #ifdef CONFIG_DEBUG_RODATA
25692 if (!err)
25693 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25694 return -EBUSY;
25695 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25696 BREAK_INSTR_SIZE);
25697 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25698 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25699 if (err)
25700 return err;
25701 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25702 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25703 if (mutex_is_locked(&text_mutex))
25704 goto knl_write;
25705 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25706 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25707 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25708 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25709 goto knl_write;
25710 return err;
25711 knl_write:
25712 #endif /* CONFIG_DEBUG_RODATA */
25713 - return probe_kernel_write((char *)bpt->bpt_addr,
25714 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25715 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25716 }
25717
25718 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25719 index 67e6d19..731ed28 100644
25720 --- a/arch/x86/kernel/kprobes/core.c
25721 +++ b/arch/x86/kernel/kprobes/core.c
25722 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25723 s32 raddr;
25724 } __packed *insn;
25725
25726 - insn = (struct __arch_relative_insn *)from;
25727 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25728 +
25729 + pax_open_kernel();
25730 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25731 insn->op = op;
25732 + pax_close_kernel();
25733 }
25734
25735 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25736 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25737 kprobe_opcode_t opcode;
25738 kprobe_opcode_t *orig_opcodes = opcodes;
25739
25740 - if (search_exception_tables((unsigned long)opcodes))
25741 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25742 return 0; /* Page fault may occur on this address. */
25743
25744 retry:
25745 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25746 * for the first byte, we can recover the original instruction
25747 * from it and kp->opcode.
25748 */
25749 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25750 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25751 buf[0] = kp->opcode;
25752 - return (unsigned long)buf;
25753 + return ktva_ktla((unsigned long)buf);
25754 }
25755
25756 /*
25757 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25758 /* Another subsystem puts a breakpoint, failed to recover */
25759 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25760 return 0;
25761 + pax_open_kernel();
25762 memcpy(dest, insn.kaddr, insn.length);
25763 + pax_close_kernel();
25764
25765 #ifdef CONFIG_X86_64
25766 if (insn_rip_relative(&insn)) {
25767 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25768 return 0;
25769 }
25770 disp = (u8 *) dest + insn_offset_displacement(&insn);
25771 + pax_open_kernel();
25772 *(s32 *) disp = (s32) newdisp;
25773 + pax_close_kernel();
25774 }
25775 #endif
25776 return insn.length;
25777 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25778 * nor set current_kprobe, because it doesn't use single
25779 * stepping.
25780 */
25781 - regs->ip = (unsigned long)p->ainsn.insn;
25782 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25783 preempt_enable_no_resched();
25784 return;
25785 }
25786 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25787 regs->flags &= ~X86_EFLAGS_IF;
25788 /* single step inline if the instruction is an int3 */
25789 if (p->opcode == BREAKPOINT_INSTRUCTION)
25790 - regs->ip = (unsigned long)p->addr;
25791 + regs->ip = ktla_ktva((unsigned long)p->addr);
25792 else
25793 - regs->ip = (unsigned long)p->ainsn.insn;
25794 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25795 }
25796 NOKPROBE_SYMBOL(setup_singlestep);
25797
25798 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25799 struct kprobe *p;
25800 struct kprobe_ctlblk *kcb;
25801
25802 - if (user_mode_vm(regs))
25803 + if (user_mode(regs))
25804 return 0;
25805
25806 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25807 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25808 setup_singlestep(p, regs, kcb, 0);
25809 return 1;
25810 }
25811 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25812 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25813 /*
25814 * The breakpoint instruction was removed right
25815 * after we hit it. Another cpu has removed
25816 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25817 " movq %rax, 152(%rsp)\n"
25818 RESTORE_REGS_STRING
25819 " popfq\n"
25820 +#ifdef KERNEXEC_PLUGIN
25821 + " btsq $63,(%rsp)\n"
25822 +#endif
25823 #else
25824 " pushf\n"
25825 SAVE_REGS_STRING
25826 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25827 struct kprobe_ctlblk *kcb)
25828 {
25829 unsigned long *tos = stack_addr(regs);
25830 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25831 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25832 unsigned long orig_ip = (unsigned long)p->addr;
25833 kprobe_opcode_t *insn = p->ainsn.insn;
25834
25835 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25836 struct die_args *args = data;
25837 int ret = NOTIFY_DONE;
25838
25839 - if (args->regs && user_mode_vm(args->regs))
25840 + if (args->regs && user_mode(args->regs))
25841 return ret;
25842
25843 if (val == DIE_GPF) {
25844 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25845 index f304773..551e63c 100644
25846 --- a/arch/x86/kernel/kprobes/opt.c
25847 +++ b/arch/x86/kernel/kprobes/opt.c
25848 @@ -79,6 +79,7 @@ found:
25849 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25850 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25851 {
25852 + pax_open_kernel();
25853 #ifdef CONFIG_X86_64
25854 *addr++ = 0x48;
25855 *addr++ = 0xbf;
25856 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25857 *addr++ = 0xb8;
25858 #endif
25859 *(unsigned long *)addr = val;
25860 + pax_close_kernel();
25861 }
25862
25863 asm (
25864 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25865 * Verify if the address gap is in 2GB range, because this uses
25866 * a relative jump.
25867 */
25868 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25869 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25870 if (abs(rel) > 0x7fffffff)
25871 return -ERANGE;
25872
25873 @@ -352,16 +354,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25874 op->optinsn.size = ret;
25875
25876 /* Copy arch-dep-instance from template */
25877 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25878 + pax_open_kernel();
25879 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25880 + pax_close_kernel();
25881
25882 /* Set probe information */
25883 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25884
25885 /* Set probe function call */
25886 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25887 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25888
25889 /* Set returning jmp instruction at the tail of out-of-line buffer */
25890 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25891 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25892 (u8 *)op->kp.addr + op->optinsn.size);
25893
25894 flush_icache_range((unsigned long) buf,
25895 @@ -386,7 +390,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25896 WARN_ON(kprobe_disabled(&op->kp));
25897
25898 /* Backup instructions which will be replaced by jump address */
25899 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25900 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25901 RELATIVE_ADDR_SIZE);
25902
25903 insn_buf[0] = RELATIVEJUMP_OPCODE;
25904 @@ -434,7 +438,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25905 /* This kprobe is really able to run optimized path. */
25906 op = container_of(p, struct optimized_kprobe, kp);
25907 /* Detour through copied instructions */
25908 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25909 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25910 if (!reenter)
25911 reset_current_kprobe();
25912 preempt_enable_no_resched();
25913 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25914 index c2bedae..25e7ab60 100644
25915 --- a/arch/x86/kernel/ksysfs.c
25916 +++ b/arch/x86/kernel/ksysfs.c
25917 @@ -184,7 +184,7 @@ out:
25918
25919 static struct kobj_attribute type_attr = __ATTR_RO(type);
25920
25921 -static struct bin_attribute data_attr = {
25922 +static bin_attribute_no_const data_attr __read_only = {
25923 .attr = {
25924 .name = "data",
25925 .mode = S_IRUGO,
25926 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25927 index c37886d..d851d32 100644
25928 --- a/arch/x86/kernel/ldt.c
25929 +++ b/arch/x86/kernel/ldt.c
25930 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25931 if (reload) {
25932 #ifdef CONFIG_SMP
25933 preempt_disable();
25934 - load_LDT(pc);
25935 + load_LDT_nolock(pc);
25936 if (!cpumask_equal(mm_cpumask(current->mm),
25937 cpumask_of(smp_processor_id())))
25938 smp_call_function(flush_ldt, current->mm, 1);
25939 preempt_enable();
25940 #else
25941 - load_LDT(pc);
25942 + load_LDT_nolock(pc);
25943 #endif
25944 }
25945 if (oldsize) {
25946 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25947 return err;
25948
25949 for (i = 0; i < old->size; i++)
25950 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25951 + write_ldt_entry(new->ldt, i, old->ldt + i);
25952 return 0;
25953 }
25954
25955 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25956 retval = copy_ldt(&mm->context, &old_mm->context);
25957 mutex_unlock(&old_mm->context.lock);
25958 }
25959 +
25960 + if (tsk == current) {
25961 + mm->context.vdso = 0;
25962 +
25963 +#ifdef CONFIG_X86_32
25964 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25965 + mm->context.user_cs_base = 0UL;
25966 + mm->context.user_cs_limit = ~0UL;
25967 +
25968 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25969 + cpus_clear(mm->context.cpu_user_cs_mask);
25970 +#endif
25971 +
25972 +#endif
25973 +#endif
25974 +
25975 + }
25976 +
25977 return retval;
25978 }
25979
25980 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25981 }
25982 }
25983
25984 +#ifdef CONFIG_PAX_SEGMEXEC
25985 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25986 + error = -EINVAL;
25987 + goto out_unlock;
25988 + }
25989 +#endif
25990 +
25991 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25992 error = -EINVAL;
25993 goto out_unlock;
25994 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25995 index 1667b1d..16492c5 100644
25996 --- a/arch/x86/kernel/machine_kexec_32.c
25997 +++ b/arch/x86/kernel/machine_kexec_32.c
25998 @@ -25,7 +25,7 @@
25999 #include <asm/cacheflush.h>
26000 #include <asm/debugreg.h>
26001
26002 -static void set_idt(void *newidt, __u16 limit)
26003 +static void set_idt(struct desc_struct *newidt, __u16 limit)
26004 {
26005 struct desc_ptr curidt;
26006
26007 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
26008 }
26009
26010
26011 -static void set_gdt(void *newgdt, __u16 limit)
26012 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
26013 {
26014 struct desc_ptr curgdt;
26015
26016 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
26017 }
26018
26019 control_page = page_address(image->control_code_page);
26020 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
26021 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
26022
26023 relocate_kernel_ptr = control_page;
26024 page_list[PA_CONTROL_PAGE] = __pa(control_page);
26025 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
26026 index c050a01..5774072 100644
26027 --- a/arch/x86/kernel/mcount_64.S
26028 +++ b/arch/x86/kernel/mcount_64.S
26029 @@ -7,7 +7,7 @@
26030 #include <linux/linkage.h>
26031 #include <asm/ptrace.h>
26032 #include <asm/ftrace.h>
26033 -
26034 +#include <asm/alternative-asm.h>
26035
26036 .code64
26037 .section .entry.text, "ax"
26038 @@ -24,8 +24,9 @@
26039 #ifdef CONFIG_DYNAMIC_FTRACE
26040
26041 ENTRY(function_hook)
26042 + pax_force_retaddr
26043 retq
26044 -END(function_hook)
26045 +ENDPROC(function_hook)
26046
26047 /* skip is set if stack has been adjusted */
26048 .macro ftrace_caller_setup skip=0
26049 @@ -66,8 +67,9 @@ GLOBAL(ftrace_graph_call)
26050 #endif
26051
26052 GLOBAL(ftrace_stub)
26053 + pax_force_retaddr
26054 retq
26055 -END(ftrace_caller)
26056 +ENDPROC(ftrace_caller)
26057
26058 ENTRY(ftrace_regs_caller)
26059 /* Save the current flags before compare (in SS location)*/
26060 @@ -135,7 +137,7 @@ ftrace_restore_flags:
26061 popfq
26062 jmp ftrace_stub
26063
26064 -END(ftrace_regs_caller)
26065 +ENDPROC(ftrace_regs_caller)
26066
26067
26068 #else /* ! CONFIG_DYNAMIC_FTRACE */
26069 @@ -156,6 +158,7 @@ ENTRY(function_hook)
26070 #endif
26071
26072 GLOBAL(ftrace_stub)
26073 + pax_force_retaddr
26074 retq
26075
26076 trace:
26077 @@ -169,12 +172,13 @@ trace:
26078 #endif
26079 subq $MCOUNT_INSN_SIZE, %rdi
26080
26081 + pax_force_fptr ftrace_trace_function
26082 call *ftrace_trace_function
26083
26084 MCOUNT_RESTORE_FRAME
26085
26086 jmp ftrace_stub
26087 -END(function_hook)
26088 +ENDPROC(function_hook)
26089 #endif /* CONFIG_DYNAMIC_FTRACE */
26090 #endif /* CONFIG_FUNCTION_TRACER */
26091
26092 @@ -196,8 +200,9 @@ ENTRY(ftrace_graph_caller)
26093
26094 MCOUNT_RESTORE_FRAME
26095
26096 + pax_force_retaddr
26097 retq
26098 -END(ftrace_graph_caller)
26099 +ENDPROC(ftrace_graph_caller)
26100
26101 GLOBAL(return_to_handler)
26102 subq $24, %rsp
26103 @@ -213,5 +218,7 @@ GLOBAL(return_to_handler)
26104 movq 8(%rsp), %rdx
26105 movq (%rsp), %rax
26106 addq $24, %rsp
26107 + pax_force_fptr %rdi
26108 jmp *%rdi
26109 +ENDPROC(return_to_handler)
26110 #endif
26111 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26112 index e69f988..da078ea 100644
26113 --- a/arch/x86/kernel/module.c
26114 +++ b/arch/x86/kernel/module.c
26115 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
26116 }
26117 #endif
26118
26119 -void *module_alloc(unsigned long size)
26120 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26121 {
26122 - if (PAGE_ALIGN(size) > MODULES_LEN)
26123 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26124 return NULL;
26125 return __vmalloc_node_range(size, 1,
26126 MODULES_VADDR + get_module_load_offset(),
26127 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
26128 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
26129 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
26130 + prot, NUMA_NO_NODE,
26131 __builtin_return_address(0));
26132 }
26133
26134 +void *module_alloc(unsigned long size)
26135 +{
26136 +
26137 +#ifdef CONFIG_PAX_KERNEXEC
26138 + return __module_alloc(size, PAGE_KERNEL);
26139 +#else
26140 + return __module_alloc(size, PAGE_KERNEL_EXEC);
26141 +#endif
26142 +
26143 +}
26144 +
26145 +#ifdef CONFIG_PAX_KERNEXEC
26146 +#ifdef CONFIG_X86_32
26147 +void *module_alloc_exec(unsigned long size)
26148 +{
26149 + struct vm_struct *area;
26150 +
26151 + if (size == 0)
26152 + return NULL;
26153 +
26154 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26155 +return area ? area->addr : NULL;
26156 +}
26157 +EXPORT_SYMBOL(module_alloc_exec);
26158 +
26159 +void module_free_exec(struct module *mod, void *module_region)
26160 +{
26161 + vunmap(module_region);
26162 +}
26163 +EXPORT_SYMBOL(module_free_exec);
26164 +#else
26165 +void module_free_exec(struct module *mod, void *module_region)
26166 +{
26167 + module_free(mod, module_region);
26168 +}
26169 +EXPORT_SYMBOL(module_free_exec);
26170 +
26171 +void *module_alloc_exec(unsigned long size)
26172 +{
26173 + return __module_alloc(size, PAGE_KERNEL_RX);
26174 +}
26175 +EXPORT_SYMBOL(module_alloc_exec);
26176 +#endif
26177 +#endif
26178 +
26179 #ifdef CONFIG_X86_32
26180 int apply_relocate(Elf32_Shdr *sechdrs,
26181 const char *strtab,
26182 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26183 unsigned int i;
26184 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26185 Elf32_Sym *sym;
26186 - uint32_t *location;
26187 + uint32_t *plocation, location;
26188
26189 DEBUGP("Applying relocate section %u to %u\n",
26190 relsec, sechdrs[relsec].sh_info);
26191 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26192 /* This is where to make the change */
26193 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26194 - + rel[i].r_offset;
26195 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26196 + location = (uint32_t)plocation;
26197 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26198 + plocation = ktla_ktva((void *)plocation);
26199 /* This is the symbol it is referring to. Note that all
26200 undefined symbols have been resolved. */
26201 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26202 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26203 switch (ELF32_R_TYPE(rel[i].r_info)) {
26204 case R_386_32:
26205 /* We add the value into the location given */
26206 - *location += sym->st_value;
26207 + pax_open_kernel();
26208 + *plocation += sym->st_value;
26209 + pax_close_kernel();
26210 break;
26211 case R_386_PC32:
26212 /* Add the value, subtract its position */
26213 - *location += sym->st_value - (uint32_t)location;
26214 + pax_open_kernel();
26215 + *plocation += sym->st_value - location;
26216 + pax_close_kernel();
26217 break;
26218 default:
26219 pr_err("%s: Unknown relocation: %u\n",
26220 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26221 case R_X86_64_NONE:
26222 break;
26223 case R_X86_64_64:
26224 + pax_open_kernel();
26225 *(u64 *)loc = val;
26226 + pax_close_kernel();
26227 break;
26228 case R_X86_64_32:
26229 + pax_open_kernel();
26230 *(u32 *)loc = val;
26231 + pax_close_kernel();
26232 if (val != *(u32 *)loc)
26233 goto overflow;
26234 break;
26235 case R_X86_64_32S:
26236 + pax_open_kernel();
26237 *(s32 *)loc = val;
26238 + pax_close_kernel();
26239 if ((s64)val != *(s32 *)loc)
26240 goto overflow;
26241 break;
26242 case R_X86_64_PC32:
26243 val -= (u64)loc;
26244 + pax_open_kernel();
26245 *(u32 *)loc = val;
26246 + pax_close_kernel();
26247 +
26248 #if 0
26249 if ((s64)val != *(s32 *)loc)
26250 goto overflow;
26251 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26252 index c9603ac..9f88728 100644
26253 --- a/arch/x86/kernel/msr.c
26254 +++ b/arch/x86/kernel/msr.c
26255 @@ -37,6 +37,7 @@
26256 #include <linux/notifier.h>
26257 #include <linux/uaccess.h>
26258 #include <linux/gfp.h>
26259 +#include <linux/grsecurity.h>
26260
26261 #include <asm/processor.h>
26262 #include <asm/msr.h>
26263 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26264 int err = 0;
26265 ssize_t bytes = 0;
26266
26267 +#ifdef CONFIG_GRKERNSEC_KMEM
26268 + gr_handle_msr_write();
26269 + return -EPERM;
26270 +#endif
26271 +
26272 if (count % 8)
26273 return -EINVAL; /* Invalid chunk size */
26274
26275 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26276 err = -EBADF;
26277 break;
26278 }
26279 +#ifdef CONFIG_GRKERNSEC_KMEM
26280 + gr_handle_msr_write();
26281 + return -EPERM;
26282 +#endif
26283 if (copy_from_user(&regs, uregs, sizeof regs)) {
26284 err = -EFAULT;
26285 break;
26286 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26287 return notifier_from_errno(err);
26288 }
26289
26290 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26291 +static struct notifier_block msr_class_cpu_notifier = {
26292 .notifier_call = msr_class_cpu_callback,
26293 };
26294
26295 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26296 index c3e985d..110a36a 100644
26297 --- a/arch/x86/kernel/nmi.c
26298 +++ b/arch/x86/kernel/nmi.c
26299 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26300
26301 static void nmi_max_handler(struct irq_work *w)
26302 {
26303 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26304 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26305 int remainder_ns, decimal_msecs;
26306 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26307 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26308
26309 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26310 decimal_msecs = remainder_ns / 1000;
26311
26312 printk_ratelimited(KERN_INFO
26313 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26314 - a->handler, whole_msecs, decimal_msecs);
26315 + n->action->handler, whole_msecs, decimal_msecs);
26316 }
26317
26318 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26319 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26320 delta = sched_clock() - delta;
26321 trace_nmi_handler(a->handler, (int)delta, thishandled);
26322
26323 - if (delta < nmi_longest_ns || delta < a->max_duration)
26324 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26325 continue;
26326
26327 - a->max_duration = delta;
26328 - irq_work_queue(&a->irq_work);
26329 + a->work->max_duration = delta;
26330 + irq_work_queue(&a->work->irq_work);
26331 }
26332
26333 rcu_read_unlock();
26334 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26335 }
26336 NOKPROBE_SYMBOL(nmi_handle);
26337
26338 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26339 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26340 {
26341 struct nmi_desc *desc = nmi_to_desc(type);
26342 unsigned long flags;
26343 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26344 if (!action->handler)
26345 return -EINVAL;
26346
26347 - init_irq_work(&action->irq_work, nmi_max_handler);
26348 + action->work->action = action;
26349 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26350
26351 spin_lock_irqsave(&desc->lock, flags);
26352
26353 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26354 * event confuses some handlers (kdump uses this flag)
26355 */
26356 if (action->flags & NMI_FLAG_FIRST)
26357 - list_add_rcu(&action->list, &desc->head);
26358 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26359 else
26360 - list_add_tail_rcu(&action->list, &desc->head);
26361 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26362
26363 spin_unlock_irqrestore(&desc->lock, flags);
26364 return 0;
26365 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26366 if (!strcmp(n->name, name)) {
26367 WARN(in_nmi(),
26368 "Trying to free NMI (%s) from NMI context!\n", n->name);
26369 - list_del_rcu(&n->list);
26370 + pax_list_del_rcu((struct list_head *)&n->list);
26371 break;
26372 }
26373 }
26374 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26375 dotraplinkage notrace void
26376 do_nmi(struct pt_regs *regs, long error_code)
26377 {
26378 +
26379 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26380 + if (!user_mode(regs)) {
26381 + unsigned long cs = regs->cs & 0xFFFF;
26382 + unsigned long ip = ktva_ktla(regs->ip);
26383 +
26384 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26385 + regs->ip = ip;
26386 + }
26387 +#endif
26388 +
26389 nmi_nesting_preprocess(regs);
26390
26391 nmi_enter();
26392 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26393 index 6d9582e..f746287 100644
26394 --- a/arch/x86/kernel/nmi_selftest.c
26395 +++ b/arch/x86/kernel/nmi_selftest.c
26396 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26397 {
26398 /* trap all the unknown NMIs we may generate */
26399 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26400 - __initdata);
26401 + __initconst);
26402 }
26403
26404 static void __init cleanup_nmi_testsuite(void)
26405 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26406 unsigned long timeout;
26407
26408 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26409 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26410 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26411 nmi_fail = FAILURE;
26412 return;
26413 }
26414 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26415 index bbb6c73..24a58ef 100644
26416 --- a/arch/x86/kernel/paravirt-spinlocks.c
26417 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26418 @@ -8,7 +8,7 @@
26419
26420 #include <asm/paravirt.h>
26421
26422 -struct pv_lock_ops pv_lock_ops = {
26423 +struct pv_lock_ops pv_lock_ops __read_only = {
26424 #ifdef CONFIG_SMP
26425 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26426 .unlock_kick = paravirt_nop,
26427 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26428 index 548d25f..f8fb99c 100644
26429 --- a/arch/x86/kernel/paravirt.c
26430 +++ b/arch/x86/kernel/paravirt.c
26431 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26432 {
26433 return x;
26434 }
26435 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26436 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26437 +#endif
26438
26439 void __init default_banner(void)
26440 {
26441 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26442
26443 if (opfunc == NULL)
26444 /* If there's no function, patch it with a ud2a (BUG) */
26445 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26446 - else if (opfunc == _paravirt_nop)
26447 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26448 + else if (opfunc == (void *)_paravirt_nop)
26449 /* If the operation is a nop, then nop the callsite */
26450 ret = paravirt_patch_nop();
26451
26452 /* identity functions just return their single argument */
26453 - else if (opfunc == _paravirt_ident_32)
26454 + else if (opfunc == (void *)_paravirt_ident_32)
26455 ret = paravirt_patch_ident_32(insnbuf, len);
26456 - else if (opfunc == _paravirt_ident_64)
26457 + else if (opfunc == (void *)_paravirt_ident_64)
26458 ret = paravirt_patch_ident_64(insnbuf, len);
26459 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26460 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26461 + ret = paravirt_patch_ident_64(insnbuf, len);
26462 +#endif
26463
26464 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26465 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26466 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26467 if (insn_len > len || start == NULL)
26468 insn_len = len;
26469 else
26470 - memcpy(insnbuf, start, insn_len);
26471 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26472
26473 return insn_len;
26474 }
26475 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26476 return this_cpu_read(paravirt_lazy_mode);
26477 }
26478
26479 -struct pv_info pv_info = {
26480 +struct pv_info pv_info __read_only = {
26481 .name = "bare hardware",
26482 .paravirt_enabled = 0,
26483 .kernel_rpl = 0,
26484 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
26485 #endif
26486 };
26487
26488 -struct pv_init_ops pv_init_ops = {
26489 +struct pv_init_ops pv_init_ops __read_only = {
26490 .patch = native_patch,
26491 };
26492
26493 -struct pv_time_ops pv_time_ops = {
26494 +struct pv_time_ops pv_time_ops __read_only = {
26495 .sched_clock = native_sched_clock,
26496 .steal_clock = native_steal_clock,
26497 };
26498
26499 -__visible struct pv_irq_ops pv_irq_ops = {
26500 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
26501 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26502 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26503 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26504 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26505 #endif
26506 };
26507
26508 -__visible struct pv_cpu_ops pv_cpu_ops = {
26509 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26510 .cpuid = native_cpuid,
26511 .get_debugreg = native_get_debugreg,
26512 .set_debugreg = native_set_debugreg,
26513 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26514 NOKPROBE_SYMBOL(native_set_debugreg);
26515 NOKPROBE_SYMBOL(native_load_idt);
26516
26517 -struct pv_apic_ops pv_apic_ops = {
26518 +struct pv_apic_ops pv_apic_ops __read_only= {
26519 #ifdef CONFIG_X86_LOCAL_APIC
26520 .startup_ipi_hook = paravirt_nop,
26521 #endif
26522 };
26523
26524 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26525 +#ifdef CONFIG_X86_32
26526 +#ifdef CONFIG_X86_PAE
26527 +/* 64-bit pagetable entries */
26528 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26529 +#else
26530 /* 32-bit pagetable entries */
26531 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26532 +#endif
26533 #else
26534 /* 64-bit pagetable entries */
26535 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26536 #endif
26537
26538 -struct pv_mmu_ops pv_mmu_ops = {
26539 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26540
26541 .read_cr2 = native_read_cr2,
26542 .write_cr2 = native_write_cr2,
26543 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26544 .make_pud = PTE_IDENT,
26545
26546 .set_pgd = native_set_pgd,
26547 + .set_pgd_batched = native_set_pgd_batched,
26548 #endif
26549 #endif /* PAGETABLE_LEVELS >= 3 */
26550
26551 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26552 },
26553
26554 .set_fixmap = native_set_fixmap,
26555 +
26556 +#ifdef CONFIG_PAX_KERNEXEC
26557 + .pax_open_kernel = native_pax_open_kernel,
26558 + .pax_close_kernel = native_pax_close_kernel,
26559 +#endif
26560 +
26561 };
26562
26563 EXPORT_SYMBOL_GPL(pv_time_ops);
26564 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26565 index 0497f71..7186c0d 100644
26566 --- a/arch/x86/kernel/pci-calgary_64.c
26567 +++ b/arch/x86/kernel/pci-calgary_64.c
26568 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26569 tce_space = be64_to_cpu(readq(target));
26570 tce_space = tce_space & TAR_SW_BITS;
26571
26572 - tce_space = tce_space & (~specified_table_size);
26573 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26574 info->tce_space = (u64 *)__va(tce_space);
26575 }
26576 }
26577 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26578 index 35ccf75..7a15747 100644
26579 --- a/arch/x86/kernel/pci-iommu_table.c
26580 +++ b/arch/x86/kernel/pci-iommu_table.c
26581 @@ -2,7 +2,7 @@
26582 #include <asm/iommu_table.h>
26583 #include <linux/string.h>
26584 #include <linux/kallsyms.h>
26585 -
26586 +#include <linux/sched.h>
26587
26588 #define DEBUG 1
26589
26590 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26591 index 77dd0ad..9ec4723 100644
26592 --- a/arch/x86/kernel/pci-swiotlb.c
26593 +++ b/arch/x86/kernel/pci-swiotlb.c
26594 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26595 struct dma_attrs *attrs)
26596 {
26597 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26598 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26599 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26600 else
26601 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26602 }
26603 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26604 index ca7f0d5..8996469 100644
26605 --- a/arch/x86/kernel/preempt.S
26606 +++ b/arch/x86/kernel/preempt.S
26607 @@ -3,12 +3,14 @@
26608 #include <asm/dwarf2.h>
26609 #include <asm/asm.h>
26610 #include <asm/calling.h>
26611 +#include <asm/alternative-asm.h>
26612
26613 ENTRY(___preempt_schedule)
26614 CFI_STARTPROC
26615 SAVE_ALL
26616 call preempt_schedule
26617 RESTORE_ALL
26618 + pax_force_retaddr
26619 ret
26620 CFI_ENDPROC
26621
26622 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26623 SAVE_ALL
26624 call preempt_schedule_context
26625 RESTORE_ALL
26626 + pax_force_retaddr
26627 ret
26628 CFI_ENDPROC
26629
26630 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26631 index 4505e2a..ae28b0d 100644
26632 --- a/arch/x86/kernel/process.c
26633 +++ b/arch/x86/kernel/process.c
26634 @@ -36,7 +36,8 @@
26635 * section. Since TSS's are completely CPU-local, we want them
26636 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26637 */
26638 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26639 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26640 +EXPORT_SYMBOL(init_tss);
26641
26642 #ifdef CONFIG_X86_64
26643 static DEFINE_PER_CPU(unsigned char, is_idle);
26644 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26645 task_xstate_cachep =
26646 kmem_cache_create("task_xstate", xstate_size,
26647 __alignof__(union thread_xstate),
26648 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26649 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26650 }
26651
26652 /*
26653 @@ -105,7 +106,7 @@ void exit_thread(void)
26654 unsigned long *bp = t->io_bitmap_ptr;
26655
26656 if (bp) {
26657 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26658 + struct tss_struct *tss = init_tss + get_cpu();
26659
26660 t->io_bitmap_ptr = NULL;
26661 clear_thread_flag(TIF_IO_BITMAP);
26662 @@ -125,6 +126,9 @@ void flush_thread(void)
26663 {
26664 struct task_struct *tsk = current;
26665
26666 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26667 + loadsegment(gs, 0);
26668 +#endif
26669 flush_ptrace_hw_breakpoint(tsk);
26670 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26671 drop_init_fpu(tsk);
26672 @@ -271,7 +275,7 @@ static void __exit_idle(void)
26673 void exit_idle(void)
26674 {
26675 /* idle loop has pid 0 */
26676 - if (current->pid)
26677 + if (task_pid_nr(current))
26678 return;
26679 __exit_idle();
26680 }
26681 @@ -324,7 +328,7 @@ bool xen_set_default_idle(void)
26682 return ret;
26683 }
26684 #endif
26685 -void stop_this_cpu(void *dummy)
26686 +__noreturn void stop_this_cpu(void *dummy)
26687 {
26688 local_irq_disable();
26689 /*
26690 @@ -453,16 +457,37 @@ static int __init idle_setup(char *str)
26691 }
26692 early_param("idle", idle_setup);
26693
26694 -unsigned long arch_align_stack(unsigned long sp)
26695 +#ifdef CONFIG_PAX_RANDKSTACK
26696 +void pax_randomize_kstack(struct pt_regs *regs)
26697 {
26698 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26699 - sp -= get_random_int() % 8192;
26700 - return sp & ~0xf;
26701 -}
26702 + struct thread_struct *thread = &current->thread;
26703 + unsigned long time;
26704
26705 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26706 -{
26707 - unsigned long range_end = mm->brk + 0x02000000;
26708 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26709 -}
26710 + if (!randomize_va_space)
26711 + return;
26712 +
26713 + if (v8086_mode(regs))
26714 + return;
26715
26716 + rdtscl(time);
26717 +
26718 + /* P4 seems to return a 0 LSB, ignore it */
26719 +#ifdef CONFIG_MPENTIUM4
26720 + time &= 0x3EUL;
26721 + time <<= 2;
26722 +#elif defined(CONFIG_X86_64)
26723 + time &= 0xFUL;
26724 + time <<= 4;
26725 +#else
26726 + time &= 0x1FUL;
26727 + time <<= 3;
26728 +#endif
26729 +
26730 + thread->sp0 ^= time;
26731 + load_sp0(init_tss + smp_processor_id(), thread);
26732 +
26733 +#ifdef CONFIG_X86_64
26734 + this_cpu_write(kernel_stack, thread->sp0);
26735 +#endif
26736 +}
26737 +#endif
26738 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26739 index 7bc86bb..0ea06e8 100644
26740 --- a/arch/x86/kernel/process_32.c
26741 +++ b/arch/x86/kernel/process_32.c
26742 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26743 unsigned long thread_saved_pc(struct task_struct *tsk)
26744 {
26745 return ((unsigned long *)tsk->thread.sp)[3];
26746 +//XXX return tsk->thread.eip;
26747 }
26748
26749 void __show_regs(struct pt_regs *regs, int all)
26750 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26751 unsigned long sp;
26752 unsigned short ss, gs;
26753
26754 - if (user_mode_vm(regs)) {
26755 + if (user_mode(regs)) {
26756 sp = regs->sp;
26757 ss = regs->ss & 0xffff;
26758 - gs = get_user_gs(regs);
26759 } else {
26760 sp = kernel_stack_pointer(regs);
26761 savesegment(ss, ss);
26762 - savesegment(gs, gs);
26763 }
26764 + gs = get_user_gs(regs);
26765
26766 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26767 (u16)regs->cs, regs->ip, regs->flags,
26768 - smp_processor_id());
26769 + raw_smp_processor_id());
26770 print_symbol("EIP is at %s\n", regs->ip);
26771
26772 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26773 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26774 int copy_thread(unsigned long clone_flags, unsigned long sp,
26775 unsigned long arg, struct task_struct *p)
26776 {
26777 - struct pt_regs *childregs = task_pt_regs(p);
26778 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26779 struct task_struct *tsk;
26780 int err;
26781
26782 p->thread.sp = (unsigned long) childregs;
26783 p->thread.sp0 = (unsigned long) (childregs+1);
26784 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26785
26786 if (unlikely(p->flags & PF_KTHREAD)) {
26787 /* kernel thread */
26788 memset(childregs, 0, sizeof(struct pt_regs));
26789 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26790 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26791 - childregs->ds = __USER_DS;
26792 - childregs->es = __USER_DS;
26793 + savesegment(gs, childregs->gs);
26794 + childregs->ds = __KERNEL_DS;
26795 + childregs->es = __KERNEL_DS;
26796 childregs->fs = __KERNEL_PERCPU;
26797 childregs->bx = sp; /* function */
26798 childregs->bp = arg;
26799 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26800 struct thread_struct *prev = &prev_p->thread,
26801 *next = &next_p->thread;
26802 int cpu = smp_processor_id();
26803 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26804 + struct tss_struct *tss = init_tss + cpu;
26805 fpu_switch_t fpu;
26806
26807 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26808 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26809 */
26810 lazy_save_gs(prev->gs);
26811
26812 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26813 + __set_fs(task_thread_info(next_p)->addr_limit);
26814 +#endif
26815 +
26816 /*
26817 * Load the per-thread Thread-Local Storage descriptor.
26818 */
26819 @@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26820 */
26821 arch_end_context_switch(next_p);
26822
26823 - this_cpu_write(kernel_stack,
26824 - (unsigned long)task_stack_page(next_p) +
26825 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26826 + this_cpu_write(current_task, next_p);
26827 + this_cpu_write(current_tinfo, &next_p->tinfo);
26828 + this_cpu_write(kernel_stack, next->sp0);
26829
26830 /*
26831 * Restore %gs if needed (which is common)
26832 @@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26833
26834 switch_fpu_finish(next_p, fpu);
26835
26836 - this_cpu_write(current_task, next_p);
26837 -
26838 return prev_p;
26839 }
26840
26841 @@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26842 } while (count++ < 16);
26843 return 0;
26844 }
26845 -
26846 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26847 index ca5b02d..c0b2f6a 100644
26848 --- a/arch/x86/kernel/process_64.c
26849 +++ b/arch/x86/kernel/process_64.c
26850 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26851 struct pt_regs *childregs;
26852 struct task_struct *me = current;
26853
26854 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26855 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26856 childregs = task_pt_regs(p);
26857 p->thread.sp = (unsigned long) childregs;
26858 p->thread.usersp = me->thread.usersp;
26859 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26860 set_tsk_thread_flag(p, TIF_FORK);
26861 p->thread.fpu_counter = 0;
26862 p->thread.io_bitmap_ptr = NULL;
26863 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26864 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26865 savesegment(es, p->thread.es);
26866 savesegment(ds, p->thread.ds);
26867 + savesegment(ss, p->thread.ss);
26868 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26869 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26870
26871 if (unlikely(p->flags & PF_KTHREAD)) {
26872 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26873 struct thread_struct *prev = &prev_p->thread;
26874 struct thread_struct *next = &next_p->thread;
26875 int cpu = smp_processor_id();
26876 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26877 + struct tss_struct *tss = init_tss + cpu;
26878 unsigned fsindex, gsindex;
26879 fpu_switch_t fpu;
26880
26881 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26882 if (unlikely(next->ds | prev->ds))
26883 loadsegment(ds, next->ds);
26884
26885 + savesegment(ss, prev->ss);
26886 + if (unlikely(next->ss != prev->ss))
26887 + loadsegment(ss, next->ss);
26888
26889 /* We must save %fs and %gs before load_TLS() because
26890 * %fs and %gs may be cleared by load_TLS().
26891 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26892 prev->usersp = this_cpu_read(old_rsp);
26893 this_cpu_write(old_rsp, next->usersp);
26894 this_cpu_write(current_task, next_p);
26895 + this_cpu_write(current_tinfo, &next_p->tinfo);
26896
26897 /*
26898 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26899 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26900 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26901 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26902
26903 - this_cpu_write(kernel_stack,
26904 - (unsigned long)task_stack_page(next_p) +
26905 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26906 + this_cpu_write(kernel_stack, next->sp0);
26907
26908 /*
26909 * Now maybe reload the debug registers and handle I/O bitmaps
26910 @@ -443,12 +448,11 @@ unsigned long get_wchan(struct task_struct *p)
26911 if (!p || p == current || p->state == TASK_RUNNING)
26912 return 0;
26913 stack = (unsigned long)task_stack_page(p);
26914 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26915 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26916 return 0;
26917 fp = *(u64 *)(p->thread.sp);
26918 do {
26919 - if (fp < (unsigned long)stack ||
26920 - fp >= (unsigned long)stack+THREAD_SIZE)
26921 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26922 return 0;
26923 ip = *(u64 *)(fp+8);
26924 if (!in_sched_functions(ip))
26925 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26926 index 678c0ad..2fc2a7b 100644
26927 --- a/arch/x86/kernel/ptrace.c
26928 +++ b/arch/x86/kernel/ptrace.c
26929 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26930 unsigned long sp = (unsigned long)&regs->sp;
26931 u32 *prev_esp;
26932
26933 - if (context == (sp & ~(THREAD_SIZE - 1)))
26934 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26935 return sp;
26936
26937 - prev_esp = (u32 *)(context);
26938 + prev_esp = *(u32 **)(context);
26939 if (prev_esp)
26940 return (unsigned long)prev_esp;
26941
26942 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26943 if (child->thread.gs != value)
26944 return do_arch_prctl(child, ARCH_SET_GS, value);
26945 return 0;
26946 +
26947 + case offsetof(struct user_regs_struct,ip):
26948 + /*
26949 + * Protect against any attempt to set ip to an
26950 + * impossible address. There are dragons lurking if the
26951 + * address is noncanonical. (This explicitly allows
26952 + * setting ip to TASK_SIZE_MAX, because user code can do
26953 + * that all by itself by running off the end of its
26954 + * address space.
26955 + */
26956 + if (value > TASK_SIZE_MAX)
26957 + return -EIO;
26958 + break;
26959 +
26960 #endif
26961 }
26962
26963 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26964 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26965 {
26966 int i;
26967 - int dr7 = 0;
26968 + unsigned long dr7 = 0;
26969 struct arch_hw_breakpoint *info;
26970
26971 for (i = 0; i < HBP_NUM; i++) {
26972 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26973 unsigned long addr, unsigned long data)
26974 {
26975 int ret;
26976 - unsigned long __user *datap = (unsigned long __user *)data;
26977 + unsigned long __user *datap = (__force unsigned long __user *)data;
26978
26979 switch (request) {
26980 /* read the word at location addr in the USER area. */
26981 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26982 if ((int) addr < 0)
26983 return -EIO;
26984 ret = do_get_thread_area(child, addr,
26985 - (struct user_desc __user *)data);
26986 + (__force struct user_desc __user *) data);
26987 break;
26988
26989 case PTRACE_SET_THREAD_AREA:
26990 if ((int) addr < 0)
26991 return -EIO;
26992 ret = do_set_thread_area(child, addr,
26993 - (struct user_desc __user *)data, 0);
26994 + (__force struct user_desc __user *) data, 0);
26995 break;
26996 #endif
26997
26998 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26999
27000 #ifdef CONFIG_X86_64
27001
27002 -static struct user_regset x86_64_regsets[] __read_mostly = {
27003 +static user_regset_no_const x86_64_regsets[] __read_only = {
27004 [REGSET_GENERAL] = {
27005 .core_note_type = NT_PRSTATUS,
27006 .n = sizeof(struct user_regs_struct) / sizeof(long),
27007 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
27008 #endif /* CONFIG_X86_64 */
27009
27010 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
27011 -static struct user_regset x86_32_regsets[] __read_mostly = {
27012 +static user_regset_no_const x86_32_regsets[] __read_only = {
27013 [REGSET_GENERAL] = {
27014 .core_note_type = NT_PRSTATUS,
27015 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
27016 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
27017 */
27018 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
27019
27020 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27021 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27022 {
27023 #ifdef CONFIG_X86_64
27024 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
27025 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
27026 memset(info, 0, sizeof(*info));
27027 info->si_signo = SIGTRAP;
27028 info->si_code = si_code;
27029 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
27030 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
27031 }
27032
27033 void user_single_step_siginfo(struct task_struct *tsk,
27034 @@ -1450,6 +1464,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
27035 # define IS_IA32 0
27036 #endif
27037
27038 +#ifdef CONFIG_GRKERNSEC_SETXID
27039 +extern void gr_delayed_cred_worker(void);
27040 +#endif
27041 +
27042 /*
27043 * We must return the syscall number to actually look up in the table.
27044 * This can be -1L to skip running any syscall at all.
27045 @@ -1460,6 +1478,11 @@ long syscall_trace_enter(struct pt_regs *regs)
27046
27047 user_exit();
27048
27049 +#ifdef CONFIG_GRKERNSEC_SETXID
27050 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27051 + gr_delayed_cred_worker();
27052 +#endif
27053 +
27054 /*
27055 * If we stepped into a sysenter/syscall insn, it trapped in
27056 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
27057 @@ -1515,6 +1538,11 @@ void syscall_trace_leave(struct pt_regs *regs)
27058 */
27059 user_exit();
27060
27061 +#ifdef CONFIG_GRKERNSEC_SETXID
27062 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27063 + gr_delayed_cred_worker();
27064 +#endif
27065 +
27066 audit_syscall_exit(regs);
27067
27068 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
27069 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
27070 index 2f355d2..e75ed0a 100644
27071 --- a/arch/x86/kernel/pvclock.c
27072 +++ b/arch/x86/kernel/pvclock.c
27073 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
27074 reset_hung_task_detector();
27075 }
27076
27077 -static atomic64_t last_value = ATOMIC64_INIT(0);
27078 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
27079
27080 void pvclock_resume(void)
27081 {
27082 - atomic64_set(&last_value, 0);
27083 + atomic64_set_unchecked(&last_value, 0);
27084 }
27085
27086 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
27087 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
27088 * updating at the same time, and one of them could be slightly behind,
27089 * making the assumption that last_value always go forward fail to hold.
27090 */
27091 - last = atomic64_read(&last_value);
27092 + last = atomic64_read_unchecked(&last_value);
27093 do {
27094 if (ret < last)
27095 return last;
27096 - last = atomic64_cmpxchg(&last_value, last, ret);
27097 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
27098 } while (unlikely(last != ret));
27099
27100 return ret;
27101 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
27102 index 52b1157..c6e67c4 100644
27103 --- a/arch/x86/kernel/reboot.c
27104 +++ b/arch/x86/kernel/reboot.c
27105 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
27106
27107 void __noreturn machine_real_restart(unsigned int type)
27108 {
27109 +
27110 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
27111 + struct desc_struct *gdt;
27112 +#endif
27113 +
27114 local_irq_disable();
27115
27116 /*
27117 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
27118
27119 /* Jump to the identity-mapped low memory code */
27120 #ifdef CONFIG_X86_32
27121 - asm volatile("jmpl *%0" : :
27122 +
27123 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27124 + gdt = get_cpu_gdt_table(smp_processor_id());
27125 + pax_open_kernel();
27126 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27127 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27128 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27129 + loadsegment(ds, __KERNEL_DS);
27130 + loadsegment(es, __KERNEL_DS);
27131 + loadsegment(ss, __KERNEL_DS);
27132 +#endif
27133 +#ifdef CONFIG_PAX_KERNEXEC
27134 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27135 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27136 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27137 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27138 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27139 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27140 +#endif
27141 + pax_close_kernel();
27142 +#endif
27143 +
27144 + asm volatile("ljmpl *%0" : :
27145 "rm" (real_mode_header->machine_real_restart_asm),
27146 "a" (type));
27147 #else
27148 @@ -486,7 +513,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27149 * This means that this function can never return, it can misbehave
27150 * by not rebooting properly and hanging.
27151 */
27152 -static void native_machine_emergency_restart(void)
27153 +static void __noreturn native_machine_emergency_restart(void)
27154 {
27155 int i;
27156 int attempt = 0;
27157 @@ -610,13 +637,13 @@ void native_machine_shutdown(void)
27158 #endif
27159 }
27160
27161 -static void __machine_emergency_restart(int emergency)
27162 +static void __noreturn __machine_emergency_restart(int emergency)
27163 {
27164 reboot_emergency = emergency;
27165 machine_ops.emergency_restart();
27166 }
27167
27168 -static void native_machine_restart(char *__unused)
27169 +static void __noreturn native_machine_restart(char *__unused)
27170 {
27171 pr_notice("machine restart\n");
27172
27173 @@ -625,7 +652,7 @@ static void native_machine_restart(char *__unused)
27174 __machine_emergency_restart(0);
27175 }
27176
27177 -static void native_machine_halt(void)
27178 +static void __noreturn native_machine_halt(void)
27179 {
27180 /* Stop other cpus and apics */
27181 machine_shutdown();
27182 @@ -635,7 +662,7 @@ static void native_machine_halt(void)
27183 stop_this_cpu(NULL);
27184 }
27185
27186 -static void native_machine_power_off(void)
27187 +static void __noreturn native_machine_power_off(void)
27188 {
27189 if (pm_power_off) {
27190 if (!reboot_force)
27191 @@ -644,9 +671,10 @@ static void native_machine_power_off(void)
27192 }
27193 /* A fallback in case there is no PM info available */
27194 tboot_shutdown(TB_SHUTDOWN_HALT);
27195 + unreachable();
27196 }
27197
27198 -struct machine_ops machine_ops = {
27199 +struct machine_ops machine_ops __read_only = {
27200 .power_off = native_machine_power_off,
27201 .shutdown = native_machine_shutdown,
27202 .emergency_restart = native_machine_emergency_restart,
27203 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27204 index c8e41e9..64049ef 100644
27205 --- a/arch/x86/kernel/reboot_fixups_32.c
27206 +++ b/arch/x86/kernel/reboot_fixups_32.c
27207 @@ -57,7 +57,7 @@ struct device_fixup {
27208 unsigned int vendor;
27209 unsigned int device;
27210 void (*reboot_fixup)(struct pci_dev *);
27211 -};
27212 +} __do_const;
27213
27214 /*
27215 * PCI ids solely used for fixups_table go here
27216 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27217 index 3fd2c69..a444264 100644
27218 --- a/arch/x86/kernel/relocate_kernel_64.S
27219 +++ b/arch/x86/kernel/relocate_kernel_64.S
27220 @@ -96,8 +96,7 @@ relocate_kernel:
27221
27222 /* jump to identity mapped page */
27223 addq $(identity_mapped - relocate_kernel), %r8
27224 - pushq %r8
27225 - ret
27226 + jmp *%r8
27227
27228 identity_mapped:
27229 /* set return address to 0 if not preserving context */
27230 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27231 index 78a0e62..5c2e510 100644
27232 --- a/arch/x86/kernel/setup.c
27233 +++ b/arch/x86/kernel/setup.c
27234 @@ -110,6 +110,7 @@
27235 #include <asm/mce.h>
27236 #include <asm/alternative.h>
27237 #include <asm/prom.h>
27238 +#include <asm/boot.h>
27239
27240 /*
27241 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27242 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27243 #endif
27244
27245
27246 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27247 -__visible unsigned long mmu_cr4_features;
27248 +#ifdef CONFIG_X86_64
27249 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27250 +#elif defined(CONFIG_X86_PAE)
27251 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27252 #else
27253 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27254 +__visible unsigned long mmu_cr4_features __read_only;
27255 #endif
27256
27257 +void set_in_cr4(unsigned long mask)
27258 +{
27259 + unsigned long cr4 = read_cr4();
27260 +
27261 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27262 + return;
27263 +
27264 + pax_open_kernel();
27265 + mmu_cr4_features |= mask;
27266 + pax_close_kernel();
27267 +
27268 + if (trampoline_cr4_features)
27269 + *trampoline_cr4_features = mmu_cr4_features;
27270 + cr4 |= mask;
27271 + write_cr4(cr4);
27272 +}
27273 +EXPORT_SYMBOL(set_in_cr4);
27274 +
27275 +void clear_in_cr4(unsigned long mask)
27276 +{
27277 + unsigned long cr4 = read_cr4();
27278 +
27279 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27280 + return;
27281 +
27282 + pax_open_kernel();
27283 + mmu_cr4_features &= ~mask;
27284 + pax_close_kernel();
27285 +
27286 + if (trampoline_cr4_features)
27287 + *trampoline_cr4_features = mmu_cr4_features;
27288 + cr4 &= ~mask;
27289 + write_cr4(cr4);
27290 +}
27291 +EXPORT_SYMBOL(clear_in_cr4);
27292 +
27293 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27294 int bootloader_type, bootloader_version;
27295
27296 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27297 * area (640->1Mb) as ram even though it is not.
27298 * take them out.
27299 */
27300 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27301 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27302
27303 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27304 }
27305 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27306 /* called before trim_bios_range() to spare extra sanitize */
27307 static void __init e820_add_kernel_range(void)
27308 {
27309 - u64 start = __pa_symbol(_text);
27310 + u64 start = __pa_symbol(ktla_ktva(_text));
27311 u64 size = __pa_symbol(_end) - start;
27312
27313 /*
27314 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27315
27316 void __init setup_arch(char **cmdline_p)
27317 {
27318 +#ifdef CONFIG_X86_32
27319 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27320 +#else
27321 memblock_reserve(__pa_symbol(_text),
27322 (unsigned long)__bss_stop - (unsigned long)_text);
27323 +#endif
27324
27325 early_reserve_initrd();
27326
27327 @@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
27328
27329 if (!boot_params.hdr.root_flags)
27330 root_mountflags &= ~MS_RDONLY;
27331 - init_mm.start_code = (unsigned long) _text;
27332 - init_mm.end_code = (unsigned long) _etext;
27333 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27334 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27335 init_mm.end_data = (unsigned long) _edata;
27336 init_mm.brk = _brk_end;
27337
27338 - code_resource.start = __pa_symbol(_text);
27339 - code_resource.end = __pa_symbol(_etext)-1;
27340 - data_resource.start = __pa_symbol(_etext);
27341 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27342 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27343 + data_resource.start = __pa_symbol(_sdata);
27344 data_resource.end = __pa_symbol(_edata)-1;
27345 bss_resource.start = __pa_symbol(__bss_start);
27346 bss_resource.end = __pa_symbol(__bss_stop)-1;
27347 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27348 index 5cdff03..80fa283 100644
27349 --- a/arch/x86/kernel/setup_percpu.c
27350 +++ b/arch/x86/kernel/setup_percpu.c
27351 @@ -21,19 +21,17 @@
27352 #include <asm/cpu.h>
27353 #include <asm/stackprotector.h>
27354
27355 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27356 +#ifdef CONFIG_SMP
27357 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27358 EXPORT_PER_CPU_SYMBOL(cpu_number);
27359 +#endif
27360
27361 -#ifdef CONFIG_X86_64
27362 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27363 -#else
27364 -#define BOOT_PERCPU_OFFSET 0
27365 -#endif
27366
27367 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27368 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27369
27370 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27371 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27372 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27373 };
27374 EXPORT_SYMBOL(__per_cpu_offset);
27375 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27376 {
27377 #ifdef CONFIG_NEED_MULTIPLE_NODES
27378 pg_data_t *last = NULL;
27379 - unsigned int cpu;
27380 + int cpu;
27381
27382 for_each_possible_cpu(cpu) {
27383 int node = early_cpu_to_node(cpu);
27384 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27385 {
27386 #ifdef CONFIG_X86_32
27387 struct desc_struct gdt;
27388 + unsigned long base = per_cpu_offset(cpu);
27389
27390 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27391 - 0x2 | DESCTYPE_S, 0x8);
27392 - gdt.s = 1;
27393 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27394 + 0x83 | DESCTYPE_S, 0xC);
27395 write_gdt_entry(get_cpu_gdt_table(cpu),
27396 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27397 #endif
27398 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27399 /* alrighty, percpu areas up and running */
27400 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27401 for_each_possible_cpu(cpu) {
27402 +#ifdef CONFIG_CC_STACKPROTECTOR
27403 +#ifdef CONFIG_X86_32
27404 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27405 +#endif
27406 +#endif
27407 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27408 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27409 per_cpu(cpu_number, cpu) = cpu;
27410 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27411 */
27412 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27413 #endif
27414 +#ifdef CONFIG_CC_STACKPROTECTOR
27415 +#ifdef CONFIG_X86_32
27416 + if (!cpu)
27417 + per_cpu(stack_canary.canary, cpu) = canary;
27418 +#endif
27419 +#endif
27420 /*
27421 * Up to this point, the boot CPU has been using .init.data
27422 * area. Reload any changed state for the boot CPU.
27423 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27424 index 2851d63..83bf567 100644
27425 --- a/arch/x86/kernel/signal.c
27426 +++ b/arch/x86/kernel/signal.c
27427 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27428 * Align the stack pointer according to the i386 ABI,
27429 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27430 */
27431 - sp = ((sp + 4) & -16ul) - 4;
27432 + sp = ((sp - 12) & -16ul) - 4;
27433 #else /* !CONFIG_X86_32 */
27434 sp = round_down(sp, 16) - 8;
27435 #endif
27436 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27437 }
27438
27439 if (current->mm->context.vdso)
27440 - restorer = current->mm->context.vdso +
27441 - selected_vdso32->sym___kernel_sigreturn;
27442 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27443 else
27444 - restorer = &frame->retcode;
27445 + restorer = (void __user *)&frame->retcode;
27446 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27447 restorer = ksig->ka.sa.sa_restorer;
27448
27449 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27450 * reasons and because gdb uses it as a signature to notice
27451 * signal handler stack frames.
27452 */
27453 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27454 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27455
27456 if (err)
27457 return -EFAULT;
27458 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27459 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27460
27461 /* Set up to return from userspace. */
27462 - restorer = current->mm->context.vdso +
27463 - selected_vdso32->sym___kernel_rt_sigreturn;
27464 + if (current->mm->context.vdso)
27465 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27466 + else
27467 + restorer = (void __user *)&frame->retcode;
27468 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27469 restorer = ksig->ka.sa.sa_restorer;
27470 put_user_ex(restorer, &frame->pretcode);
27471 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27472 * reasons and because gdb uses it as a signature to notice
27473 * signal handler stack frames.
27474 */
27475 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27476 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27477 } put_user_catch(err);
27478
27479 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27480 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27481 {
27482 int usig = signr_convert(ksig->sig);
27483 sigset_t *set = sigmask_to_save();
27484 - compat_sigset_t *cset = (compat_sigset_t *) set;
27485 + sigset_t sigcopy;
27486 + compat_sigset_t *cset;
27487 +
27488 + sigcopy = *set;
27489 +
27490 + cset = (compat_sigset_t *) &sigcopy;
27491
27492 /* Set up the stack frame */
27493 if (is_ia32_frame()) {
27494 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27495 } else if (is_x32_frame()) {
27496 return x32_setup_rt_frame(ksig, cset, regs);
27497 } else {
27498 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
27499 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27500 }
27501 }
27502
27503 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27504 index be8e1bd..a3d93fa 100644
27505 --- a/arch/x86/kernel/smp.c
27506 +++ b/arch/x86/kernel/smp.c
27507 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27508
27509 __setup("nonmi_ipi", nonmi_ipi_setup);
27510
27511 -struct smp_ops smp_ops = {
27512 +struct smp_ops smp_ops __read_only = {
27513 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27514 .smp_prepare_cpus = native_smp_prepare_cpus,
27515 .smp_cpus_done = native_smp_cpus_done,
27516 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27517 index 5492798..a3bd4f2 100644
27518 --- a/arch/x86/kernel/smpboot.c
27519 +++ b/arch/x86/kernel/smpboot.c
27520 @@ -230,14 +230,17 @@ static void notrace start_secondary(void *unused)
27521
27522 enable_start_cpu0 = 0;
27523
27524 -#ifdef CONFIG_X86_32
27525 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27526 + barrier();
27527 +
27528 /* switch away from the initial page table */
27529 +#ifdef CONFIG_PAX_PER_CPU_PGD
27530 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27531 +#else
27532 load_cr3(swapper_pg_dir);
27533 +#endif
27534 __flush_tlb_all();
27535 -#endif
27536
27537 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27538 - barrier();
27539 /*
27540 * Check TSC synchronization with the BP:
27541 */
27542 @@ -764,8 +767,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27543 alternatives_enable_smp();
27544
27545 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27546 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27547 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27548 per_cpu(current_task, cpu) = idle;
27549 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27550
27551 #ifdef CONFIG_X86_32
27552 /* Stack for startup_32 can be just as for start_secondary onwards */
27553 @@ -774,10 +778,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27554 clear_tsk_thread_flag(idle, TIF_FORK);
27555 initial_gs = per_cpu_offset(cpu);
27556 #endif
27557 - per_cpu(kernel_stack, cpu) =
27558 - (unsigned long)task_stack_page(idle) -
27559 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27560 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27561 + pax_open_kernel();
27562 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27563 + pax_close_kernel();
27564 initial_code = (unsigned long)start_secondary;
27565 stack_start = idle->thread.sp;
27566
27567 @@ -923,6 +927,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27568 /* the FPU context is blank, nobody can own it */
27569 __cpu_disable_lazy_restore(cpu);
27570
27571 +#ifdef CONFIG_PAX_PER_CPU_PGD
27572 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27573 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27574 + KERNEL_PGD_PTRS);
27575 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27576 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27577 + KERNEL_PGD_PTRS);
27578 +#endif
27579 +
27580 err = do_boot_cpu(apicid, cpu, tidle);
27581 if (err) {
27582 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27583 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27584 index 9b4d51d..5d28b58 100644
27585 --- a/arch/x86/kernel/step.c
27586 +++ b/arch/x86/kernel/step.c
27587 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27588 struct desc_struct *desc;
27589 unsigned long base;
27590
27591 - seg &= ~7UL;
27592 + seg >>= 3;
27593
27594 mutex_lock(&child->mm->context.lock);
27595 - if (unlikely((seg >> 3) >= child->mm->context.size))
27596 + if (unlikely(seg >= child->mm->context.size))
27597 addr = -1L; /* bogus selector, access would fault */
27598 else {
27599 desc = child->mm->context.ldt + seg;
27600 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27601 addr += base;
27602 }
27603 mutex_unlock(&child->mm->context.lock);
27604 - }
27605 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27606 + addr = ktla_ktva(addr);
27607
27608 return addr;
27609 }
27610 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27611 unsigned char opcode[15];
27612 unsigned long addr = convert_ip_to_linear(child, regs);
27613
27614 + if (addr == -EINVAL)
27615 + return 0;
27616 +
27617 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27618 for (i = 0; i < copied; i++) {
27619 switch (opcode[i]) {
27620 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27621 new file mode 100644
27622 index 0000000..5877189
27623 --- /dev/null
27624 +++ b/arch/x86/kernel/sys_i386_32.c
27625 @@ -0,0 +1,189 @@
27626 +/*
27627 + * This file contains various random system calls that
27628 + * have a non-standard calling sequence on the Linux/i386
27629 + * platform.
27630 + */
27631 +
27632 +#include <linux/errno.h>
27633 +#include <linux/sched.h>
27634 +#include <linux/mm.h>
27635 +#include <linux/fs.h>
27636 +#include <linux/smp.h>
27637 +#include <linux/sem.h>
27638 +#include <linux/msg.h>
27639 +#include <linux/shm.h>
27640 +#include <linux/stat.h>
27641 +#include <linux/syscalls.h>
27642 +#include <linux/mman.h>
27643 +#include <linux/file.h>
27644 +#include <linux/utsname.h>
27645 +#include <linux/ipc.h>
27646 +#include <linux/elf.h>
27647 +
27648 +#include <linux/uaccess.h>
27649 +#include <linux/unistd.h>
27650 +
27651 +#include <asm/syscalls.h>
27652 +
27653 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27654 +{
27655 + unsigned long pax_task_size = TASK_SIZE;
27656 +
27657 +#ifdef CONFIG_PAX_SEGMEXEC
27658 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27659 + pax_task_size = SEGMEXEC_TASK_SIZE;
27660 +#endif
27661 +
27662 + if (flags & MAP_FIXED)
27663 + if (len > pax_task_size || addr > pax_task_size - len)
27664 + return -EINVAL;
27665 +
27666 + return 0;
27667 +}
27668 +
27669 +/*
27670 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27671 + */
27672 +static unsigned long get_align_mask(void)
27673 +{
27674 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27675 + return 0;
27676 +
27677 + if (!(current->flags & PF_RANDOMIZE))
27678 + return 0;
27679 +
27680 + return va_align.mask;
27681 +}
27682 +
27683 +unsigned long
27684 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27685 + unsigned long len, unsigned long pgoff, unsigned long flags)
27686 +{
27687 + struct mm_struct *mm = current->mm;
27688 + struct vm_area_struct *vma;
27689 + unsigned long pax_task_size = TASK_SIZE;
27690 + struct vm_unmapped_area_info info;
27691 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27692 +
27693 +#ifdef CONFIG_PAX_SEGMEXEC
27694 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27695 + pax_task_size = SEGMEXEC_TASK_SIZE;
27696 +#endif
27697 +
27698 + pax_task_size -= PAGE_SIZE;
27699 +
27700 + if (len > pax_task_size)
27701 + return -ENOMEM;
27702 +
27703 + if (flags & MAP_FIXED)
27704 + return addr;
27705 +
27706 +#ifdef CONFIG_PAX_RANDMMAP
27707 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27708 +#endif
27709 +
27710 + if (addr) {
27711 + addr = PAGE_ALIGN(addr);
27712 + if (pax_task_size - len >= addr) {
27713 + vma = find_vma(mm, addr);
27714 + if (check_heap_stack_gap(vma, addr, len, offset))
27715 + return addr;
27716 + }
27717 + }
27718 +
27719 + info.flags = 0;
27720 + info.length = len;
27721 + info.align_mask = filp ? get_align_mask() : 0;
27722 + info.align_offset = pgoff << PAGE_SHIFT;
27723 + info.threadstack_offset = offset;
27724 +
27725 +#ifdef CONFIG_PAX_PAGEEXEC
27726 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27727 + info.low_limit = 0x00110000UL;
27728 + info.high_limit = mm->start_code;
27729 +
27730 +#ifdef CONFIG_PAX_RANDMMAP
27731 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27732 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27733 +#endif
27734 +
27735 + if (info.low_limit < info.high_limit) {
27736 + addr = vm_unmapped_area(&info);
27737 + if (!IS_ERR_VALUE(addr))
27738 + return addr;
27739 + }
27740 + } else
27741 +#endif
27742 +
27743 + info.low_limit = mm->mmap_base;
27744 + info.high_limit = pax_task_size;
27745 +
27746 + return vm_unmapped_area(&info);
27747 +}
27748 +
27749 +unsigned long
27750 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27751 + const unsigned long len, const unsigned long pgoff,
27752 + const unsigned long flags)
27753 +{
27754 + struct vm_area_struct *vma;
27755 + struct mm_struct *mm = current->mm;
27756 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27757 + struct vm_unmapped_area_info info;
27758 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27759 +
27760 +#ifdef CONFIG_PAX_SEGMEXEC
27761 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27762 + pax_task_size = SEGMEXEC_TASK_SIZE;
27763 +#endif
27764 +
27765 + pax_task_size -= PAGE_SIZE;
27766 +
27767 + /* requested length too big for entire address space */
27768 + if (len > pax_task_size)
27769 + return -ENOMEM;
27770 +
27771 + if (flags & MAP_FIXED)
27772 + return addr;
27773 +
27774 +#ifdef CONFIG_PAX_PAGEEXEC
27775 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27776 + goto bottomup;
27777 +#endif
27778 +
27779 +#ifdef CONFIG_PAX_RANDMMAP
27780 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27781 +#endif
27782 +
27783 + /* requesting a specific address */
27784 + if (addr) {
27785 + addr = PAGE_ALIGN(addr);
27786 + if (pax_task_size - len >= addr) {
27787 + vma = find_vma(mm, addr);
27788 + if (check_heap_stack_gap(vma, addr, len, offset))
27789 + return addr;
27790 + }
27791 + }
27792 +
27793 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27794 + info.length = len;
27795 + info.low_limit = PAGE_SIZE;
27796 + info.high_limit = mm->mmap_base;
27797 + info.align_mask = filp ? get_align_mask() : 0;
27798 + info.align_offset = pgoff << PAGE_SHIFT;
27799 + info.threadstack_offset = offset;
27800 +
27801 + addr = vm_unmapped_area(&info);
27802 + if (!(addr & ~PAGE_MASK))
27803 + return addr;
27804 + VM_BUG_ON(addr != -ENOMEM);
27805 +
27806 +bottomup:
27807 + /*
27808 + * A failed mmap() very likely causes application failure,
27809 + * so fall back to the bottom-up function here. This scenario
27810 + * can happen with large stack limits and large mmap()
27811 + * allocations.
27812 + */
27813 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27814 +}
27815 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27816 index 30277e2..5664a29 100644
27817 --- a/arch/x86/kernel/sys_x86_64.c
27818 +++ b/arch/x86/kernel/sys_x86_64.c
27819 @@ -81,8 +81,8 @@ out:
27820 return error;
27821 }
27822
27823 -static void find_start_end(unsigned long flags, unsigned long *begin,
27824 - unsigned long *end)
27825 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27826 + unsigned long *begin, unsigned long *end)
27827 {
27828 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27829 unsigned long new_begin;
27830 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27831 *begin = new_begin;
27832 }
27833 } else {
27834 - *begin = current->mm->mmap_legacy_base;
27835 + *begin = mm->mmap_legacy_base;
27836 *end = TASK_SIZE;
27837 }
27838 }
27839 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27840 struct vm_area_struct *vma;
27841 struct vm_unmapped_area_info info;
27842 unsigned long begin, end;
27843 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27844
27845 if (flags & MAP_FIXED)
27846 return addr;
27847
27848 - find_start_end(flags, &begin, &end);
27849 + find_start_end(mm, flags, &begin, &end);
27850
27851 if (len > end)
27852 return -ENOMEM;
27853
27854 +#ifdef CONFIG_PAX_RANDMMAP
27855 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27856 +#endif
27857 +
27858 if (addr) {
27859 addr = PAGE_ALIGN(addr);
27860 vma = find_vma(mm, addr);
27861 - if (end - len >= addr &&
27862 - (!vma || addr + len <= vma->vm_start))
27863 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27864 return addr;
27865 }
27866
27867 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27868 info.high_limit = end;
27869 info.align_mask = filp ? get_align_mask() : 0;
27870 info.align_offset = pgoff << PAGE_SHIFT;
27871 + info.threadstack_offset = offset;
27872 return vm_unmapped_area(&info);
27873 }
27874
27875 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27876 struct mm_struct *mm = current->mm;
27877 unsigned long addr = addr0;
27878 struct vm_unmapped_area_info info;
27879 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27880
27881 /* requested length too big for entire address space */
27882 if (len > TASK_SIZE)
27883 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27884 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27885 goto bottomup;
27886
27887 +#ifdef CONFIG_PAX_RANDMMAP
27888 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27889 +#endif
27890 +
27891 /* requesting a specific address */
27892 if (addr) {
27893 addr = PAGE_ALIGN(addr);
27894 vma = find_vma(mm, addr);
27895 - if (TASK_SIZE - len >= addr &&
27896 - (!vma || addr + len <= vma->vm_start))
27897 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27898 return addr;
27899 }
27900
27901 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27902 info.high_limit = mm->mmap_base;
27903 info.align_mask = filp ? get_align_mask() : 0;
27904 info.align_offset = pgoff << PAGE_SHIFT;
27905 + info.threadstack_offset = offset;
27906 addr = vm_unmapped_area(&info);
27907 if (!(addr & ~PAGE_MASK))
27908 return addr;
27909 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27910 index 91a4496..bb87552 100644
27911 --- a/arch/x86/kernel/tboot.c
27912 +++ b/arch/x86/kernel/tboot.c
27913 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27914
27915 void tboot_shutdown(u32 shutdown_type)
27916 {
27917 - void (*shutdown)(void);
27918 + void (* __noreturn shutdown)(void);
27919
27920 if (!tboot_enabled())
27921 return;
27922 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27923
27924 switch_to_tboot_pt();
27925
27926 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27927 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27928 shutdown();
27929
27930 /* should not reach here */
27931 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27932 return -ENODEV;
27933 }
27934
27935 -static atomic_t ap_wfs_count;
27936 +static atomic_unchecked_t ap_wfs_count;
27937
27938 static int tboot_wait_for_aps(int num_aps)
27939 {
27940 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27941 {
27942 switch (action) {
27943 case CPU_DYING:
27944 - atomic_inc(&ap_wfs_count);
27945 + atomic_inc_unchecked(&ap_wfs_count);
27946 if (num_online_cpus() == 1)
27947 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27948 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27949 return NOTIFY_BAD;
27950 break;
27951 }
27952 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27953
27954 tboot_create_trampoline();
27955
27956 - atomic_set(&ap_wfs_count, 0);
27957 + atomic_set_unchecked(&ap_wfs_count, 0);
27958 register_hotcpu_notifier(&tboot_cpu_notifier);
27959
27960 #ifdef CONFIG_DEBUG_FS
27961 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27962 index bf7ef5c..59d0ac9 100644
27963 --- a/arch/x86/kernel/time.c
27964 +++ b/arch/x86/kernel/time.c
27965 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27966 {
27967 unsigned long pc = instruction_pointer(regs);
27968
27969 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27970 + if (!user_mode(regs) && in_lock_functions(pc)) {
27971 #ifdef CONFIG_FRAME_POINTER
27972 - return *(unsigned long *)(regs->bp + sizeof(long));
27973 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27974 #else
27975 unsigned long *sp =
27976 (unsigned long *)kernel_stack_pointer(regs);
27977 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27978 * or above a saved flags. Eflags has bits 22-31 zero,
27979 * kernel addresses don't.
27980 */
27981 +
27982 +#ifdef CONFIG_PAX_KERNEXEC
27983 + return ktla_ktva(sp[0]);
27984 +#else
27985 if (sp[0] >> 22)
27986 return sp[0];
27987 if (sp[1] >> 22)
27988 return sp[1];
27989 #endif
27990 +
27991 +#endif
27992 }
27993 return pc;
27994 }
27995 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27996 index f7fec09..9991981 100644
27997 --- a/arch/x86/kernel/tls.c
27998 +++ b/arch/x86/kernel/tls.c
27999 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
28000 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
28001 return -EINVAL;
28002
28003 +#ifdef CONFIG_PAX_SEGMEXEC
28004 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
28005 + return -EINVAL;
28006 +#endif
28007 +
28008 set_tls_desc(p, idx, &info, 1);
28009
28010 return 0;
28011 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
28012
28013 if (kbuf)
28014 info = kbuf;
28015 - else if (__copy_from_user(infobuf, ubuf, count))
28016 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
28017 return -EFAULT;
28018 else
28019 info = infobuf;
28020 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
28021 index 1c113db..287b42e 100644
28022 --- a/arch/x86/kernel/tracepoint.c
28023 +++ b/arch/x86/kernel/tracepoint.c
28024 @@ -9,11 +9,11 @@
28025 #include <linux/atomic.h>
28026
28027 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
28028 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28029 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28030 (unsigned long) trace_idt_table };
28031
28032 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28033 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
28034 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
28035
28036 static int trace_irq_vector_refcount;
28037 static DEFINE_MUTEX(irq_vector_mutex);
28038 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
28039 index 0d0e922..0886373 100644
28040 --- a/arch/x86/kernel/traps.c
28041 +++ b/arch/x86/kernel/traps.c
28042 @@ -67,7 +67,7 @@
28043 #include <asm/proto.h>
28044
28045 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28046 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
28047 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
28048 #else
28049 #include <asm/processor-flags.h>
28050 #include <asm/setup.h>
28051 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
28052 #endif
28053
28054 /* Must be page-aligned because the real IDT is used in a fixmap. */
28055 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
28056 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
28057
28058 DECLARE_BITMAP(used_vectors, NR_VECTORS);
28059 EXPORT_SYMBOL_GPL(used_vectors);
28060 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
28061 }
28062
28063 static nokprobe_inline int
28064 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28065 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
28066 struct pt_regs *regs, long error_code)
28067 {
28068 #ifdef CONFIG_X86_32
28069 - if (regs->flags & X86_VM_MASK) {
28070 + if (v8086_mode(regs)) {
28071 /*
28072 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
28073 * On nmi (interrupt 2), do_trap should not be called.
28074 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28075 return -1;
28076 }
28077 #endif
28078 - if (!user_mode(regs)) {
28079 + if (!user_mode_novm(regs)) {
28080 if (!fixup_exception(regs)) {
28081 tsk->thread.error_code = error_code;
28082 tsk->thread.trap_nr = trapnr;
28083 +
28084 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28085 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
28086 + str = "PAX: suspicious stack segment fault";
28087 +#endif
28088 +
28089 die(str, regs, error_code);
28090 }
28091 +
28092 +#ifdef CONFIG_PAX_REFCOUNT
28093 + if (trapnr == X86_TRAP_OF)
28094 + pax_report_refcount_overflow(regs);
28095 +#endif
28096 +
28097 return 0;
28098 }
28099
28100 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28101 }
28102
28103 static void
28104 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28105 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28106 long error_code, siginfo_t *info)
28107 {
28108 struct task_struct *tsk = current;
28109 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28110 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28111 printk_ratelimit()) {
28112 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28113 - tsk->comm, tsk->pid, str,
28114 + tsk->comm, task_pid_nr(tsk), str,
28115 regs->ip, regs->sp, error_code);
28116 print_vma_addr(" in ", regs->ip);
28117 pr_cont("\n");
28118 @@ -266,6 +278,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28119 tsk->thread.error_code = error_code;
28120 tsk->thread.trap_nr = X86_TRAP_DF;
28121
28122 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28123 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28124 + die("grsec: kernel stack overflow detected", regs, error_code);
28125 +#endif
28126 +
28127 #ifdef CONFIG_DOUBLEFAULT
28128 df_debug(regs, error_code);
28129 #endif
28130 @@ -288,7 +305,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28131 conditional_sti(regs);
28132
28133 #ifdef CONFIG_X86_32
28134 - if (regs->flags & X86_VM_MASK) {
28135 + if (v8086_mode(regs)) {
28136 local_irq_enable();
28137 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28138 goto exit;
28139 @@ -296,18 +313,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28140 #endif
28141
28142 tsk = current;
28143 - if (!user_mode(regs)) {
28144 + if (!user_mode_novm(regs)) {
28145 if (fixup_exception(regs))
28146 goto exit;
28147
28148 tsk->thread.error_code = error_code;
28149 tsk->thread.trap_nr = X86_TRAP_GP;
28150 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28151 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28152 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28153 +
28154 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28155 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28156 + die("PAX: suspicious general protection fault", regs, error_code);
28157 + else
28158 +#endif
28159 +
28160 die("general protection fault", regs, error_code);
28161 + }
28162 goto exit;
28163 }
28164
28165 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28166 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28167 + struct mm_struct *mm = tsk->mm;
28168 + unsigned long limit;
28169 +
28170 + down_write(&mm->mmap_sem);
28171 + limit = mm->context.user_cs_limit;
28172 + if (limit < TASK_SIZE) {
28173 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28174 + up_write(&mm->mmap_sem);
28175 + return;
28176 + }
28177 + up_write(&mm->mmap_sem);
28178 + }
28179 +#endif
28180 +
28181 tsk->thread.error_code = error_code;
28182 tsk->thread.trap_nr = X86_TRAP_GP;
28183
28184 @@ -481,7 +522,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28185 /* It's safe to allow irq's after DR6 has been saved */
28186 preempt_conditional_sti(regs);
28187
28188 - if (regs->flags & X86_VM_MASK) {
28189 + if (v8086_mode(regs)) {
28190 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28191 X86_TRAP_DB);
28192 preempt_conditional_cli(regs);
28193 @@ -496,7 +537,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28194 * We already checked v86 mode above, so we can check for kernel mode
28195 * by just checking the CPL of CS.
28196 */
28197 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28198 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28199 tsk->thread.debugreg6 &= ~DR_STEP;
28200 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28201 regs->flags &= ~X86_EFLAGS_TF;
28202 @@ -529,7 +570,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28203 return;
28204 conditional_sti(regs);
28205
28206 - if (!user_mode_vm(regs))
28207 + if (!user_mode(regs))
28208 {
28209 if (!fixup_exception(regs)) {
28210 task->thread.error_code = error_code;
28211 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28212 index ea03031..34a5cdda 100644
28213 --- a/arch/x86/kernel/tsc.c
28214 +++ b/arch/x86/kernel/tsc.c
28215 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28216 */
28217 smp_wmb();
28218
28219 - ACCESS_ONCE(c2n->head) = data;
28220 + ACCESS_ONCE_RW(c2n->head) = data;
28221 }
28222
28223 /*
28224 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28225 index 5d1cbfe..2a21feb 100644
28226 --- a/arch/x86/kernel/uprobes.c
28227 +++ b/arch/x86/kernel/uprobes.c
28228 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28229 int ret = NOTIFY_DONE;
28230
28231 /* We are only interested in userspace traps */
28232 - if (regs && !user_mode_vm(regs))
28233 + if (regs && !user_mode(regs))
28234 return NOTIFY_DONE;
28235
28236 switch (val) {
28237 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28238
28239 if (nleft != rasize) {
28240 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28241 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28242 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28243
28244 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28245 }
28246 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28247 index b9242ba..50c5edd 100644
28248 --- a/arch/x86/kernel/verify_cpu.S
28249 +++ b/arch/x86/kernel/verify_cpu.S
28250 @@ -20,6 +20,7 @@
28251 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28252 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28253 * arch/x86/kernel/head_32.S: processor startup
28254 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28255 *
28256 * verify_cpu, returns the status of longmode and SSE in register %eax.
28257 * 0: Success 1: Failure
28258 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28259 index e8edcf5..27f9344 100644
28260 --- a/arch/x86/kernel/vm86_32.c
28261 +++ b/arch/x86/kernel/vm86_32.c
28262 @@ -44,6 +44,7 @@
28263 #include <linux/ptrace.h>
28264 #include <linux/audit.h>
28265 #include <linux/stddef.h>
28266 +#include <linux/grsecurity.h>
28267
28268 #include <asm/uaccess.h>
28269 #include <asm/io.h>
28270 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28271 do_exit(SIGSEGV);
28272 }
28273
28274 - tss = &per_cpu(init_tss, get_cpu());
28275 + tss = init_tss + get_cpu();
28276 current->thread.sp0 = current->thread.saved_sp0;
28277 current->thread.sysenter_cs = __KERNEL_CS;
28278 load_sp0(tss, &current->thread);
28279 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28280
28281 if (tsk->thread.saved_sp0)
28282 return -EPERM;
28283 +
28284 +#ifdef CONFIG_GRKERNSEC_VM86
28285 + if (!capable(CAP_SYS_RAWIO)) {
28286 + gr_handle_vm86();
28287 + return -EPERM;
28288 + }
28289 +#endif
28290 +
28291 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28292 offsetof(struct kernel_vm86_struct, vm86plus) -
28293 sizeof(info.regs));
28294 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28295 int tmp;
28296 struct vm86plus_struct __user *v86;
28297
28298 +#ifdef CONFIG_GRKERNSEC_VM86
28299 + if (!capable(CAP_SYS_RAWIO)) {
28300 + gr_handle_vm86();
28301 + return -EPERM;
28302 + }
28303 +#endif
28304 +
28305 tsk = current;
28306 switch (cmd) {
28307 case VM86_REQUEST_IRQ:
28308 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28309 tsk->thread.saved_fs = info->regs32->fs;
28310 tsk->thread.saved_gs = get_user_gs(info->regs32);
28311
28312 - tss = &per_cpu(init_tss, get_cpu());
28313 + tss = init_tss + get_cpu();
28314 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28315 if (cpu_has_sep)
28316 tsk->thread.sysenter_cs = 0;
28317 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28318 goto cannot_handle;
28319 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28320 goto cannot_handle;
28321 - intr_ptr = (unsigned long __user *) (i << 2);
28322 + intr_ptr = (__force unsigned long __user *) (i << 2);
28323 if (get_user(segoffs, intr_ptr))
28324 goto cannot_handle;
28325 if ((segoffs >> 16) == BIOSSEG)
28326 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28327 index 49edf2d..c0d1362 100644
28328 --- a/arch/x86/kernel/vmlinux.lds.S
28329 +++ b/arch/x86/kernel/vmlinux.lds.S
28330 @@ -26,6 +26,13 @@
28331 #include <asm/page_types.h>
28332 #include <asm/cache.h>
28333 #include <asm/boot.h>
28334 +#include <asm/segment.h>
28335 +
28336 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28337 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28338 +#else
28339 +#define __KERNEL_TEXT_OFFSET 0
28340 +#endif
28341
28342 #undef i386 /* in case the preprocessor is a 32bit one */
28343
28344 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28345
28346 PHDRS {
28347 text PT_LOAD FLAGS(5); /* R_E */
28348 +#ifdef CONFIG_X86_32
28349 + module PT_LOAD FLAGS(5); /* R_E */
28350 +#endif
28351 +#ifdef CONFIG_XEN
28352 + rodata PT_LOAD FLAGS(5); /* R_E */
28353 +#else
28354 + rodata PT_LOAD FLAGS(4); /* R__ */
28355 +#endif
28356 data PT_LOAD FLAGS(6); /* RW_ */
28357 -#ifdef CONFIG_X86_64
28358 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28359 #ifdef CONFIG_SMP
28360 percpu PT_LOAD FLAGS(6); /* RW_ */
28361 #endif
28362 + text.init PT_LOAD FLAGS(5); /* R_E */
28363 + text.exit PT_LOAD FLAGS(5); /* R_E */
28364 init PT_LOAD FLAGS(7); /* RWE */
28365 -#endif
28366 note PT_NOTE FLAGS(0); /* ___ */
28367 }
28368
28369 SECTIONS
28370 {
28371 #ifdef CONFIG_X86_32
28372 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28373 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28374 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28375 #else
28376 - . = __START_KERNEL;
28377 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28378 + . = __START_KERNEL;
28379 #endif
28380
28381 /* Text and read-only data */
28382 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28383 - _text = .;
28384 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28385 /* bootstrapping code */
28386 +#ifdef CONFIG_X86_32
28387 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28388 +#else
28389 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28390 +#endif
28391 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28392 + _text = .;
28393 HEAD_TEXT
28394 . = ALIGN(8);
28395 _stext = .;
28396 @@ -104,13 +124,47 @@ SECTIONS
28397 IRQENTRY_TEXT
28398 *(.fixup)
28399 *(.gnu.warning)
28400 - /* End of text section */
28401 - _etext = .;
28402 } :text = 0x9090
28403
28404 - NOTES :text :note
28405 + . += __KERNEL_TEXT_OFFSET;
28406
28407 - EXCEPTION_TABLE(16) :text = 0x9090
28408 +#ifdef CONFIG_X86_32
28409 + . = ALIGN(PAGE_SIZE);
28410 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28411 +
28412 +#ifdef CONFIG_PAX_KERNEXEC
28413 + MODULES_EXEC_VADDR = .;
28414 + BYTE(0)
28415 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28416 + . = ALIGN(HPAGE_SIZE) - 1;
28417 + MODULES_EXEC_END = .;
28418 +#endif
28419 +
28420 + } :module
28421 +#endif
28422 +
28423 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28424 + /* End of text section */
28425 + BYTE(0)
28426 + _etext = . - __KERNEL_TEXT_OFFSET;
28427 + }
28428 +
28429 +#ifdef CONFIG_X86_32
28430 + . = ALIGN(PAGE_SIZE);
28431 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28432 + . = ALIGN(PAGE_SIZE);
28433 + *(.empty_zero_page)
28434 + *(.initial_pg_fixmap)
28435 + *(.initial_pg_pmd)
28436 + *(.initial_page_table)
28437 + *(.swapper_pg_dir)
28438 + } :rodata
28439 +#endif
28440 +
28441 + . = ALIGN(PAGE_SIZE);
28442 + NOTES :rodata :note
28443 +
28444 + EXCEPTION_TABLE(16) :rodata
28445
28446 #if defined(CONFIG_DEBUG_RODATA)
28447 /* .text should occupy whole number of pages */
28448 @@ -122,16 +176,20 @@ SECTIONS
28449
28450 /* Data */
28451 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28452 +
28453 +#ifdef CONFIG_PAX_KERNEXEC
28454 + . = ALIGN(HPAGE_SIZE);
28455 +#else
28456 + . = ALIGN(PAGE_SIZE);
28457 +#endif
28458 +
28459 /* Start of data section */
28460 _sdata = .;
28461
28462 /* init_task */
28463 INIT_TASK_DATA(THREAD_SIZE)
28464
28465 -#ifdef CONFIG_X86_32
28466 - /* 32 bit has nosave before _edata */
28467 NOSAVE_DATA
28468 -#endif
28469
28470 PAGE_ALIGNED_DATA(PAGE_SIZE)
28471
28472 @@ -174,12 +232,19 @@ SECTIONS
28473 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28474
28475 /* Init code and data - will be freed after init */
28476 - . = ALIGN(PAGE_SIZE);
28477 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28478 + BYTE(0)
28479 +
28480 +#ifdef CONFIG_PAX_KERNEXEC
28481 + . = ALIGN(HPAGE_SIZE);
28482 +#else
28483 + . = ALIGN(PAGE_SIZE);
28484 +#endif
28485 +
28486 __init_begin = .; /* paired with __init_end */
28487 - }
28488 + } :init.begin
28489
28490 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28491 +#ifdef CONFIG_SMP
28492 /*
28493 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28494 * output PHDR, so the next output section - .init.text - should
28495 @@ -188,12 +253,27 @@ SECTIONS
28496 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28497 #endif
28498
28499 - INIT_TEXT_SECTION(PAGE_SIZE)
28500 -#ifdef CONFIG_X86_64
28501 - :init
28502 -#endif
28503 + . = ALIGN(PAGE_SIZE);
28504 + init_begin = .;
28505 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28506 + VMLINUX_SYMBOL(_sinittext) = .;
28507 + INIT_TEXT
28508 + VMLINUX_SYMBOL(_einittext) = .;
28509 + . = ALIGN(PAGE_SIZE);
28510 + } :text.init
28511
28512 - INIT_DATA_SECTION(16)
28513 + /*
28514 + * .exit.text is discard at runtime, not link time, to deal with
28515 + * references from .altinstructions and .eh_frame
28516 + */
28517 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28518 + EXIT_TEXT
28519 + . = ALIGN(16);
28520 + } :text.exit
28521 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28522 +
28523 + . = ALIGN(PAGE_SIZE);
28524 + INIT_DATA_SECTION(16) :init
28525
28526 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28527 __x86_cpu_dev_start = .;
28528 @@ -264,19 +344,12 @@ SECTIONS
28529 }
28530
28531 . = ALIGN(8);
28532 - /*
28533 - * .exit.text is discard at runtime, not link time, to deal with
28534 - * references from .altinstructions and .eh_frame
28535 - */
28536 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28537 - EXIT_TEXT
28538 - }
28539
28540 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28541 EXIT_DATA
28542 }
28543
28544 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28545 +#ifndef CONFIG_SMP
28546 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28547 #endif
28548
28549 @@ -295,16 +368,10 @@ SECTIONS
28550 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28551 __smp_locks = .;
28552 *(.smp_locks)
28553 - . = ALIGN(PAGE_SIZE);
28554 __smp_locks_end = .;
28555 + . = ALIGN(PAGE_SIZE);
28556 }
28557
28558 -#ifdef CONFIG_X86_64
28559 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28560 - NOSAVE_DATA
28561 - }
28562 -#endif
28563 -
28564 /* BSS */
28565 . = ALIGN(PAGE_SIZE);
28566 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28567 @@ -320,6 +387,7 @@ SECTIONS
28568 __brk_base = .;
28569 . += 64 * 1024; /* 64k alignment slop space */
28570 *(.brk_reservation) /* areas brk users have reserved */
28571 + . = ALIGN(HPAGE_SIZE);
28572 __brk_limit = .;
28573 }
28574
28575 @@ -346,13 +414,12 @@ SECTIONS
28576 * for the boot processor.
28577 */
28578 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28579 -INIT_PER_CPU(gdt_page);
28580 INIT_PER_CPU(irq_stack_union);
28581
28582 /*
28583 * Build-time check on the image size:
28584 */
28585 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28586 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28587 "kernel image bigger than KERNEL_IMAGE_SIZE");
28588
28589 #ifdef CONFIG_SMP
28590 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28591 index e1e1e80..1400089 100644
28592 --- a/arch/x86/kernel/vsyscall_64.c
28593 +++ b/arch/x86/kernel/vsyscall_64.c
28594 @@ -54,15 +54,13 @@
28595
28596 DEFINE_VVAR(int, vgetcpu_mode);
28597
28598 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28599 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28600
28601 static int __init vsyscall_setup(char *str)
28602 {
28603 if (str) {
28604 if (!strcmp("emulate", str))
28605 vsyscall_mode = EMULATE;
28606 - else if (!strcmp("native", str))
28607 - vsyscall_mode = NATIVE;
28608 else if (!strcmp("none", str))
28609 vsyscall_mode = NONE;
28610 else
28611 @@ -279,8 +277,7 @@ do_ret:
28612 return true;
28613
28614 sigsegv:
28615 - force_sig(SIGSEGV, current);
28616 - return true;
28617 + do_group_exit(SIGKILL);
28618 }
28619
28620 /*
28621 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28622 extern char __vsyscall_page;
28623 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28624
28625 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28626 - vsyscall_mode == NATIVE
28627 - ? PAGE_KERNEL_VSYSCALL
28628 - : PAGE_KERNEL_VVAR);
28629 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28630 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28631 (unsigned long)VSYSCALL_ADDR);
28632 }
28633 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28634 index 04068192..4d75aa6 100644
28635 --- a/arch/x86/kernel/x8664_ksyms_64.c
28636 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28637 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28638 EXPORT_SYMBOL(copy_user_generic_unrolled);
28639 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28640 EXPORT_SYMBOL(__copy_user_nocache);
28641 -EXPORT_SYMBOL(_copy_from_user);
28642 -EXPORT_SYMBOL(_copy_to_user);
28643
28644 EXPORT_SYMBOL(copy_page);
28645 EXPORT_SYMBOL(clear_page);
28646 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28647 EXPORT_SYMBOL(___preempt_schedule_context);
28648 #endif
28649 #endif
28650 +
28651 +#ifdef CONFIG_PAX_PER_CPU_PGD
28652 +EXPORT_SYMBOL(cpu_pgd);
28653 +#endif
28654 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28655 index e48b674..a451dd9 100644
28656 --- a/arch/x86/kernel/x86_init.c
28657 +++ b/arch/x86/kernel/x86_init.c
28658 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28659 static void default_nmi_init(void) { };
28660 static int default_i8042_detect(void) { return 1; };
28661
28662 -struct x86_platform_ops x86_platform = {
28663 +struct x86_platform_ops x86_platform __read_only = {
28664 .calibrate_tsc = native_calibrate_tsc,
28665 .get_wallclock = mach_get_cmos_time,
28666 .set_wallclock = mach_set_rtc_mmss,
28667 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28668 EXPORT_SYMBOL_GPL(x86_platform);
28669
28670 #if defined(CONFIG_PCI_MSI)
28671 -struct x86_msi_ops x86_msi = {
28672 +struct x86_msi_ops x86_msi __read_only = {
28673 .setup_msi_irqs = native_setup_msi_irqs,
28674 .compose_msi_msg = native_compose_msi_msg,
28675 .teardown_msi_irq = native_teardown_msi_irq,
28676 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28677 }
28678 #endif
28679
28680 -struct x86_io_apic_ops x86_io_apic_ops = {
28681 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28682 .init = native_io_apic_init_mappings,
28683 .read = native_io_apic_read,
28684 .write = native_io_apic_write,
28685 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28686 index a4b451c..8dfe1ad 100644
28687 --- a/arch/x86/kernel/xsave.c
28688 +++ b/arch/x86/kernel/xsave.c
28689 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28690
28691 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28692 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28693 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28694 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28695
28696 if (!use_xsave())
28697 return err;
28698
28699 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28700 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28701
28702 /*
28703 * Read the xstate_bv which we copied (directly from the cpu or
28704 * from the state in task struct) to the user buffers.
28705 */
28706 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28707 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28708
28709 /*
28710 * For legacy compatible, we always set FP/SSE bits in the bit
28711 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28712 */
28713 xstate_bv |= XSTATE_FPSSE;
28714
28715 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28716 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28717
28718 return err;
28719 }
28720 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28721 {
28722 int err;
28723
28724 + buf = (struct xsave_struct __user *)____m(buf);
28725 if (use_xsave())
28726 err = xsave_user(buf);
28727 else if (use_fxsr())
28728 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28729 */
28730 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28731 {
28732 + buf = (void __user *)____m(buf);
28733 if (use_xsave()) {
28734 if ((unsigned long)buf % 64 || fx_only) {
28735 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28736 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28737 index 38a0afe..94421a9 100644
28738 --- a/arch/x86/kvm/cpuid.c
28739 +++ b/arch/x86/kvm/cpuid.c
28740 @@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28741 struct kvm_cpuid2 *cpuid,
28742 struct kvm_cpuid_entry2 __user *entries)
28743 {
28744 - int r;
28745 + int r, i;
28746
28747 r = -E2BIG;
28748 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28749 goto out;
28750 r = -EFAULT;
28751 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28752 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28753 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28754 goto out;
28755 + for (i = 0; i < cpuid->nent; ++i) {
28756 + struct kvm_cpuid_entry2 cpuid_entry;
28757 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28758 + goto out;
28759 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28760 + }
28761 vcpu->arch.cpuid_nent = cpuid->nent;
28762 kvm_apic_set_version(vcpu);
28763 kvm_x86_ops->cpuid_update(vcpu);
28764 @@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28765 struct kvm_cpuid2 *cpuid,
28766 struct kvm_cpuid_entry2 __user *entries)
28767 {
28768 - int r;
28769 + int r, i;
28770
28771 r = -E2BIG;
28772 if (cpuid->nent < vcpu->arch.cpuid_nent)
28773 goto out;
28774 r = -EFAULT;
28775 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28776 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28777 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28778 goto out;
28779 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28780 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28781 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28782 + goto out;
28783 + }
28784 return 0;
28785
28786 out:
28787 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28788 index 453e5fb..214168f 100644
28789 --- a/arch/x86/kvm/lapic.c
28790 +++ b/arch/x86/kvm/lapic.c
28791 @@ -55,7 +55,7 @@
28792 #define APIC_BUS_CYCLE_NS 1
28793
28794 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28795 -#define apic_debug(fmt, arg...)
28796 +#define apic_debug(fmt, arg...) do {} while (0)
28797
28798 #define APIC_LVT_NUM 6
28799 /* 14 is the version for Xeon and Pentium 8.4.8*/
28800 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28801 index 4107765..d9eb358 100644
28802 --- a/arch/x86/kvm/paging_tmpl.h
28803 +++ b/arch/x86/kvm/paging_tmpl.h
28804 @@ -331,7 +331,7 @@ retry_walk:
28805 if (unlikely(kvm_is_error_hva(host_addr)))
28806 goto error;
28807
28808 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28809 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28810 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28811 goto error;
28812 walker->ptep_user[walker->level - 1] = ptep_user;
28813 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28814 index b5e994a..35b5866 100644
28815 --- a/arch/x86/kvm/svm.c
28816 +++ b/arch/x86/kvm/svm.c
28817 @@ -3541,7 +3541,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28818 int cpu = raw_smp_processor_id();
28819
28820 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28821 +
28822 + pax_open_kernel();
28823 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28824 + pax_close_kernel();
28825 +
28826 load_TR_desc();
28827 }
28828
28829 @@ -3942,6 +3946,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28830 #endif
28831 #endif
28832
28833 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28834 + __set_fs(current_thread_info()->addr_limit);
28835 +#endif
28836 +
28837 reload_tss(vcpu);
28838
28839 local_irq_disable();
28840 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28841 index 801332e..eeff1cc 100644
28842 --- a/arch/x86/kvm/vmx.c
28843 +++ b/arch/x86/kvm/vmx.c
28844 @@ -1339,12 +1339,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28845 #endif
28846 }
28847
28848 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28849 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28850 {
28851 vmcs_writel(field, vmcs_readl(field) & ~mask);
28852 }
28853
28854 -static void vmcs_set_bits(unsigned long field, u32 mask)
28855 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28856 {
28857 vmcs_writel(field, vmcs_readl(field) | mask);
28858 }
28859 @@ -1604,7 +1604,11 @@ static void reload_tss(void)
28860 struct desc_struct *descs;
28861
28862 descs = (void *)gdt->address;
28863 +
28864 + pax_open_kernel();
28865 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28866 + pax_close_kernel();
28867 +
28868 load_TR_desc();
28869 }
28870
28871 @@ -1832,6 +1836,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28872 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28873 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28874
28875 +#ifdef CONFIG_PAX_PER_CPU_PGD
28876 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28877 +#endif
28878 +
28879 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28880 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28881 vmx->loaded_vmcs->cpu = cpu;
28882 @@ -2121,7 +2129,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28883 * reads and returns guest's timestamp counter "register"
28884 * guest_tsc = host_tsc + tsc_offset -- 21.3
28885 */
28886 -static u64 guest_read_tsc(void)
28887 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28888 {
28889 u64 host_tsc, tsc_offset;
28890
28891 @@ -3093,8 +3101,11 @@ static __init int hardware_setup(void)
28892 if (!cpu_has_vmx_flexpriority())
28893 flexpriority_enabled = 0;
28894
28895 - if (!cpu_has_vmx_tpr_shadow())
28896 - kvm_x86_ops->update_cr8_intercept = NULL;
28897 + if (!cpu_has_vmx_tpr_shadow()) {
28898 + pax_open_kernel();
28899 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28900 + pax_close_kernel();
28901 + }
28902
28903 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28904 kvm_disable_largepages();
28905 @@ -3105,13 +3116,15 @@ static __init int hardware_setup(void)
28906 if (!cpu_has_vmx_apicv())
28907 enable_apicv = 0;
28908
28909 + pax_open_kernel();
28910 if (enable_apicv)
28911 - kvm_x86_ops->update_cr8_intercept = NULL;
28912 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28913 else {
28914 - kvm_x86_ops->hwapic_irr_update = NULL;
28915 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28916 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28917 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28918 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28919 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28920 }
28921 + pax_close_kernel();
28922
28923 if (nested)
28924 nested_vmx_setup_ctls_msrs();
28925 @@ -4221,7 +4234,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28926
28927 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28928 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28929 +
28930 +#ifndef CONFIG_PAX_PER_CPU_PGD
28931 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28932 +#endif
28933
28934 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28935 #ifdef CONFIG_X86_64
28936 @@ -4243,7 +4259,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28937 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28938 vmx->host_idt_base = dt.address;
28939
28940 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28941 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28942
28943 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28944 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28945 @@ -7413,6 +7429,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28946 "jmp 2f \n\t"
28947 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28948 "2: "
28949 +
28950 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28951 + "ljmp %[cs],$3f\n\t"
28952 + "3: "
28953 +#endif
28954 +
28955 /* Save guest registers, load host registers, keep flags */
28956 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28957 "pop %0 \n\t"
28958 @@ -7465,6 +7487,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28959 #endif
28960 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28961 [wordsize]"i"(sizeof(ulong))
28962 +
28963 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28964 + ,[cs]"i"(__KERNEL_CS)
28965 +#endif
28966 +
28967 : "cc", "memory"
28968 #ifdef CONFIG_X86_64
28969 , "rax", "rbx", "rdi", "rsi"
28970 @@ -7478,7 +7505,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28971 if (debugctlmsr)
28972 update_debugctlmsr(debugctlmsr);
28973
28974 -#ifndef CONFIG_X86_64
28975 +#ifdef CONFIG_X86_32
28976 /*
28977 * The sysexit path does not restore ds/es, so we must set them to
28978 * a reasonable value ourselves.
28979 @@ -7487,8 +7514,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28980 * may be executed in interrupt context, which saves and restore segments
28981 * around it, nullifying its effect.
28982 */
28983 - loadsegment(ds, __USER_DS);
28984 - loadsegment(es, __USER_DS);
28985 + loadsegment(ds, __KERNEL_DS);
28986 + loadsegment(es, __KERNEL_DS);
28987 + loadsegment(ss, __KERNEL_DS);
28988 +
28989 +#ifdef CONFIG_PAX_KERNEXEC
28990 + loadsegment(fs, __KERNEL_PERCPU);
28991 +#endif
28992 +
28993 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28994 + __set_fs(current_thread_info()->addr_limit);
28995 +#endif
28996 +
28997 #endif
28998
28999 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
29000 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
29001 index ef432f8..a630659 100644
29002 --- a/arch/x86/kvm/x86.c
29003 +++ b/arch/x86/kvm/x86.c
29004 @@ -1808,8 +1808,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
29005 {
29006 struct kvm *kvm = vcpu->kvm;
29007 int lm = is_long_mode(vcpu);
29008 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29009 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29010 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29011 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29012 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29013 : kvm->arch.xen_hvm_config.blob_size_32;
29014 u32 page_num = data & ~PAGE_MASK;
29015 @@ -2729,6 +2729,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29016 if (n < msr_list.nmsrs)
29017 goto out;
29018 r = -EFAULT;
29019 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29020 + goto out;
29021 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29022 num_msrs_to_save * sizeof(u32)))
29023 goto out;
29024 @@ -5567,7 +5569,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29025 };
29026 #endif
29027
29028 -int kvm_arch_init(void *opaque)
29029 +int kvm_arch_init(const void *opaque)
29030 {
29031 int r;
29032 struct kvm_x86_ops *ops = opaque;
29033 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29034 index aae9413..d11e829 100644
29035 --- a/arch/x86/lguest/boot.c
29036 +++ b/arch/x86/lguest/boot.c
29037 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29038 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29039 * Launcher to reboot us.
29040 */
29041 -static void lguest_restart(char *reason)
29042 +static __noreturn void lguest_restart(char *reason)
29043 {
29044 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29045 + BUG();
29046 }
29047
29048 /*G:050
29049 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29050 index 00933d5..3a64af9 100644
29051 --- a/arch/x86/lib/atomic64_386_32.S
29052 +++ b/arch/x86/lib/atomic64_386_32.S
29053 @@ -48,6 +48,10 @@ BEGIN(read)
29054 movl (v), %eax
29055 movl 4(v), %edx
29056 RET_ENDP
29057 +BEGIN(read_unchecked)
29058 + movl (v), %eax
29059 + movl 4(v), %edx
29060 +RET_ENDP
29061 #undef v
29062
29063 #define v %esi
29064 @@ -55,6 +59,10 @@ BEGIN(set)
29065 movl %ebx, (v)
29066 movl %ecx, 4(v)
29067 RET_ENDP
29068 +BEGIN(set_unchecked)
29069 + movl %ebx, (v)
29070 + movl %ecx, 4(v)
29071 +RET_ENDP
29072 #undef v
29073
29074 #define v %esi
29075 @@ -70,6 +78,20 @@ RET_ENDP
29076 BEGIN(add)
29077 addl %eax, (v)
29078 adcl %edx, 4(v)
29079 +
29080 +#ifdef CONFIG_PAX_REFCOUNT
29081 + jno 0f
29082 + subl %eax, (v)
29083 + sbbl %edx, 4(v)
29084 + int $4
29085 +0:
29086 + _ASM_EXTABLE(0b, 0b)
29087 +#endif
29088 +
29089 +RET_ENDP
29090 +BEGIN(add_unchecked)
29091 + addl %eax, (v)
29092 + adcl %edx, 4(v)
29093 RET_ENDP
29094 #undef v
29095
29096 @@ -77,6 +99,24 @@ RET_ENDP
29097 BEGIN(add_return)
29098 addl (v), %eax
29099 adcl 4(v), %edx
29100 +
29101 +#ifdef CONFIG_PAX_REFCOUNT
29102 + into
29103 +1234:
29104 + _ASM_EXTABLE(1234b, 2f)
29105 +#endif
29106 +
29107 + movl %eax, (v)
29108 + movl %edx, 4(v)
29109 +
29110 +#ifdef CONFIG_PAX_REFCOUNT
29111 +2:
29112 +#endif
29113 +
29114 +RET_ENDP
29115 +BEGIN(add_return_unchecked)
29116 + addl (v), %eax
29117 + adcl 4(v), %edx
29118 movl %eax, (v)
29119 movl %edx, 4(v)
29120 RET_ENDP
29121 @@ -86,6 +126,20 @@ RET_ENDP
29122 BEGIN(sub)
29123 subl %eax, (v)
29124 sbbl %edx, 4(v)
29125 +
29126 +#ifdef CONFIG_PAX_REFCOUNT
29127 + jno 0f
29128 + addl %eax, (v)
29129 + adcl %edx, 4(v)
29130 + int $4
29131 +0:
29132 + _ASM_EXTABLE(0b, 0b)
29133 +#endif
29134 +
29135 +RET_ENDP
29136 +BEGIN(sub_unchecked)
29137 + subl %eax, (v)
29138 + sbbl %edx, 4(v)
29139 RET_ENDP
29140 #undef v
29141
29142 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29143 sbbl $0, %edx
29144 addl (v), %eax
29145 adcl 4(v), %edx
29146 +
29147 +#ifdef CONFIG_PAX_REFCOUNT
29148 + into
29149 +1234:
29150 + _ASM_EXTABLE(1234b, 2f)
29151 +#endif
29152 +
29153 + movl %eax, (v)
29154 + movl %edx, 4(v)
29155 +
29156 +#ifdef CONFIG_PAX_REFCOUNT
29157 +2:
29158 +#endif
29159 +
29160 +RET_ENDP
29161 +BEGIN(sub_return_unchecked)
29162 + negl %edx
29163 + negl %eax
29164 + sbbl $0, %edx
29165 + addl (v), %eax
29166 + adcl 4(v), %edx
29167 movl %eax, (v)
29168 movl %edx, 4(v)
29169 RET_ENDP
29170 @@ -105,6 +180,20 @@ RET_ENDP
29171 BEGIN(inc)
29172 addl $1, (v)
29173 adcl $0, 4(v)
29174 +
29175 +#ifdef CONFIG_PAX_REFCOUNT
29176 + jno 0f
29177 + subl $1, (v)
29178 + sbbl $0, 4(v)
29179 + int $4
29180 +0:
29181 + _ASM_EXTABLE(0b, 0b)
29182 +#endif
29183 +
29184 +RET_ENDP
29185 +BEGIN(inc_unchecked)
29186 + addl $1, (v)
29187 + adcl $0, 4(v)
29188 RET_ENDP
29189 #undef v
29190
29191 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29192 movl 4(v), %edx
29193 addl $1, %eax
29194 adcl $0, %edx
29195 +
29196 +#ifdef CONFIG_PAX_REFCOUNT
29197 + into
29198 +1234:
29199 + _ASM_EXTABLE(1234b, 2f)
29200 +#endif
29201 +
29202 + movl %eax, (v)
29203 + movl %edx, 4(v)
29204 +
29205 +#ifdef CONFIG_PAX_REFCOUNT
29206 +2:
29207 +#endif
29208 +
29209 +RET_ENDP
29210 +BEGIN(inc_return_unchecked)
29211 + movl (v), %eax
29212 + movl 4(v), %edx
29213 + addl $1, %eax
29214 + adcl $0, %edx
29215 movl %eax, (v)
29216 movl %edx, 4(v)
29217 RET_ENDP
29218 @@ -123,6 +232,20 @@ RET_ENDP
29219 BEGIN(dec)
29220 subl $1, (v)
29221 sbbl $0, 4(v)
29222 +
29223 +#ifdef CONFIG_PAX_REFCOUNT
29224 + jno 0f
29225 + addl $1, (v)
29226 + adcl $0, 4(v)
29227 + int $4
29228 +0:
29229 + _ASM_EXTABLE(0b, 0b)
29230 +#endif
29231 +
29232 +RET_ENDP
29233 +BEGIN(dec_unchecked)
29234 + subl $1, (v)
29235 + sbbl $0, 4(v)
29236 RET_ENDP
29237 #undef v
29238
29239 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29240 movl 4(v), %edx
29241 subl $1, %eax
29242 sbbl $0, %edx
29243 +
29244 +#ifdef CONFIG_PAX_REFCOUNT
29245 + into
29246 +1234:
29247 + _ASM_EXTABLE(1234b, 2f)
29248 +#endif
29249 +
29250 + movl %eax, (v)
29251 + movl %edx, 4(v)
29252 +
29253 +#ifdef CONFIG_PAX_REFCOUNT
29254 +2:
29255 +#endif
29256 +
29257 +RET_ENDP
29258 +BEGIN(dec_return_unchecked)
29259 + movl (v), %eax
29260 + movl 4(v), %edx
29261 + subl $1, %eax
29262 + sbbl $0, %edx
29263 movl %eax, (v)
29264 movl %edx, 4(v)
29265 RET_ENDP
29266 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29267 adcl %edx, %edi
29268 addl (v), %eax
29269 adcl 4(v), %edx
29270 +
29271 +#ifdef CONFIG_PAX_REFCOUNT
29272 + into
29273 +1234:
29274 + _ASM_EXTABLE(1234b, 2f)
29275 +#endif
29276 +
29277 cmpl %eax, %ecx
29278 je 3f
29279 1:
29280 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29281 1:
29282 addl $1, %eax
29283 adcl $0, %edx
29284 +
29285 +#ifdef CONFIG_PAX_REFCOUNT
29286 + into
29287 +1234:
29288 + _ASM_EXTABLE(1234b, 2f)
29289 +#endif
29290 +
29291 movl %eax, (v)
29292 movl %edx, 4(v)
29293 movl $1, %eax
29294 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29295 movl 4(v), %edx
29296 subl $1, %eax
29297 sbbl $0, %edx
29298 +
29299 +#ifdef CONFIG_PAX_REFCOUNT
29300 + into
29301 +1234:
29302 + _ASM_EXTABLE(1234b, 1f)
29303 +#endif
29304 +
29305 js 1f
29306 movl %eax, (v)
29307 movl %edx, 4(v)
29308 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29309 index f5cc9eb..51fa319 100644
29310 --- a/arch/x86/lib/atomic64_cx8_32.S
29311 +++ b/arch/x86/lib/atomic64_cx8_32.S
29312 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29313 CFI_STARTPROC
29314
29315 read64 %ecx
29316 + pax_force_retaddr
29317 ret
29318 CFI_ENDPROC
29319 ENDPROC(atomic64_read_cx8)
29320
29321 +ENTRY(atomic64_read_unchecked_cx8)
29322 + CFI_STARTPROC
29323 +
29324 + read64 %ecx
29325 + pax_force_retaddr
29326 + ret
29327 + CFI_ENDPROC
29328 +ENDPROC(atomic64_read_unchecked_cx8)
29329 +
29330 ENTRY(atomic64_set_cx8)
29331 CFI_STARTPROC
29332
29333 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29334 cmpxchg8b (%esi)
29335 jne 1b
29336
29337 + pax_force_retaddr
29338 ret
29339 CFI_ENDPROC
29340 ENDPROC(atomic64_set_cx8)
29341
29342 +ENTRY(atomic64_set_unchecked_cx8)
29343 + CFI_STARTPROC
29344 +
29345 +1:
29346 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29347 + * are atomic on 586 and newer */
29348 + cmpxchg8b (%esi)
29349 + jne 1b
29350 +
29351 + pax_force_retaddr
29352 + ret
29353 + CFI_ENDPROC
29354 +ENDPROC(atomic64_set_unchecked_cx8)
29355 +
29356 ENTRY(atomic64_xchg_cx8)
29357 CFI_STARTPROC
29358
29359 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29360 cmpxchg8b (%esi)
29361 jne 1b
29362
29363 + pax_force_retaddr
29364 ret
29365 CFI_ENDPROC
29366 ENDPROC(atomic64_xchg_cx8)
29367
29368 -.macro addsub_return func ins insc
29369 -ENTRY(atomic64_\func\()_return_cx8)
29370 +.macro addsub_return func ins insc unchecked=""
29371 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29372 CFI_STARTPROC
29373 SAVE ebp
29374 SAVE ebx
29375 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29376 movl %edx, %ecx
29377 \ins\()l %esi, %ebx
29378 \insc\()l %edi, %ecx
29379 +
29380 +.ifb \unchecked
29381 +#ifdef CONFIG_PAX_REFCOUNT
29382 + into
29383 +2:
29384 + _ASM_EXTABLE(2b, 3f)
29385 +#endif
29386 +.endif
29387 +
29388 LOCK_PREFIX
29389 cmpxchg8b (%ebp)
29390 jne 1b
29391 -
29392 -10:
29393 movl %ebx, %eax
29394 movl %ecx, %edx
29395 +
29396 +.ifb \unchecked
29397 +#ifdef CONFIG_PAX_REFCOUNT
29398 +3:
29399 +#endif
29400 +.endif
29401 +
29402 RESTORE edi
29403 RESTORE esi
29404 RESTORE ebx
29405 RESTORE ebp
29406 + pax_force_retaddr
29407 ret
29408 CFI_ENDPROC
29409 -ENDPROC(atomic64_\func\()_return_cx8)
29410 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29411 .endm
29412
29413 addsub_return add add adc
29414 addsub_return sub sub sbb
29415 +addsub_return add add adc _unchecked
29416 +addsub_return sub sub sbb _unchecked
29417
29418 -.macro incdec_return func ins insc
29419 -ENTRY(atomic64_\func\()_return_cx8)
29420 +.macro incdec_return func ins insc unchecked=""
29421 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29422 CFI_STARTPROC
29423 SAVE ebx
29424
29425 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29426 movl %edx, %ecx
29427 \ins\()l $1, %ebx
29428 \insc\()l $0, %ecx
29429 +
29430 +.ifb \unchecked
29431 +#ifdef CONFIG_PAX_REFCOUNT
29432 + into
29433 +2:
29434 + _ASM_EXTABLE(2b, 3f)
29435 +#endif
29436 +.endif
29437 +
29438 LOCK_PREFIX
29439 cmpxchg8b (%esi)
29440 jne 1b
29441
29442 -10:
29443 movl %ebx, %eax
29444 movl %ecx, %edx
29445 +
29446 +.ifb \unchecked
29447 +#ifdef CONFIG_PAX_REFCOUNT
29448 +3:
29449 +#endif
29450 +.endif
29451 +
29452 RESTORE ebx
29453 + pax_force_retaddr
29454 ret
29455 CFI_ENDPROC
29456 -ENDPROC(atomic64_\func\()_return_cx8)
29457 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29458 .endm
29459
29460 incdec_return inc add adc
29461 incdec_return dec sub sbb
29462 +incdec_return inc add adc _unchecked
29463 +incdec_return dec sub sbb _unchecked
29464
29465 ENTRY(atomic64_dec_if_positive_cx8)
29466 CFI_STARTPROC
29467 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29468 movl %edx, %ecx
29469 subl $1, %ebx
29470 sbb $0, %ecx
29471 +
29472 +#ifdef CONFIG_PAX_REFCOUNT
29473 + into
29474 +1234:
29475 + _ASM_EXTABLE(1234b, 2f)
29476 +#endif
29477 +
29478 js 2f
29479 LOCK_PREFIX
29480 cmpxchg8b (%esi)
29481 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29482 movl %ebx, %eax
29483 movl %ecx, %edx
29484 RESTORE ebx
29485 + pax_force_retaddr
29486 ret
29487 CFI_ENDPROC
29488 ENDPROC(atomic64_dec_if_positive_cx8)
29489 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29490 movl %edx, %ecx
29491 addl %ebp, %ebx
29492 adcl %edi, %ecx
29493 +
29494 +#ifdef CONFIG_PAX_REFCOUNT
29495 + into
29496 +1234:
29497 + _ASM_EXTABLE(1234b, 3f)
29498 +#endif
29499 +
29500 LOCK_PREFIX
29501 cmpxchg8b (%esi)
29502 jne 1b
29503 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29504 CFI_ADJUST_CFA_OFFSET -8
29505 RESTORE ebx
29506 RESTORE ebp
29507 + pax_force_retaddr
29508 ret
29509 4:
29510 cmpl %edx, 4(%esp)
29511 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29512 xorl %ecx, %ecx
29513 addl $1, %ebx
29514 adcl %edx, %ecx
29515 +
29516 +#ifdef CONFIG_PAX_REFCOUNT
29517 + into
29518 +1234:
29519 + _ASM_EXTABLE(1234b, 3f)
29520 +#endif
29521 +
29522 LOCK_PREFIX
29523 cmpxchg8b (%esi)
29524 jne 1b
29525 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29526 movl $1, %eax
29527 3:
29528 RESTORE ebx
29529 + pax_force_retaddr
29530 ret
29531 CFI_ENDPROC
29532 ENDPROC(atomic64_inc_not_zero_cx8)
29533 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29534 index e78b8ee..7e173a8 100644
29535 --- a/arch/x86/lib/checksum_32.S
29536 +++ b/arch/x86/lib/checksum_32.S
29537 @@ -29,7 +29,8 @@
29538 #include <asm/dwarf2.h>
29539 #include <asm/errno.h>
29540 #include <asm/asm.h>
29541 -
29542 +#include <asm/segment.h>
29543 +
29544 /*
29545 * computes a partial checksum, e.g. for TCP/UDP fragments
29546 */
29547 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29548
29549 #define ARGBASE 16
29550 #define FP 12
29551 -
29552 -ENTRY(csum_partial_copy_generic)
29553 +
29554 +ENTRY(csum_partial_copy_generic_to_user)
29555 CFI_STARTPROC
29556 +
29557 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29558 + pushl_cfi %gs
29559 + popl_cfi %es
29560 + jmp csum_partial_copy_generic
29561 +#endif
29562 +
29563 +ENTRY(csum_partial_copy_generic_from_user)
29564 +
29565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29566 + pushl_cfi %gs
29567 + popl_cfi %ds
29568 +#endif
29569 +
29570 +ENTRY(csum_partial_copy_generic)
29571 subl $4,%esp
29572 CFI_ADJUST_CFA_OFFSET 4
29573 pushl_cfi %edi
29574 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29575 jmp 4f
29576 SRC(1: movw (%esi), %bx )
29577 addl $2, %esi
29578 -DST( movw %bx, (%edi) )
29579 +DST( movw %bx, %es:(%edi) )
29580 addl $2, %edi
29581 addw %bx, %ax
29582 adcl $0, %eax
29583 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29584 SRC(1: movl (%esi), %ebx )
29585 SRC( movl 4(%esi), %edx )
29586 adcl %ebx, %eax
29587 -DST( movl %ebx, (%edi) )
29588 +DST( movl %ebx, %es:(%edi) )
29589 adcl %edx, %eax
29590 -DST( movl %edx, 4(%edi) )
29591 +DST( movl %edx, %es:4(%edi) )
29592
29593 SRC( movl 8(%esi), %ebx )
29594 SRC( movl 12(%esi), %edx )
29595 adcl %ebx, %eax
29596 -DST( movl %ebx, 8(%edi) )
29597 +DST( movl %ebx, %es:8(%edi) )
29598 adcl %edx, %eax
29599 -DST( movl %edx, 12(%edi) )
29600 +DST( movl %edx, %es:12(%edi) )
29601
29602 SRC( movl 16(%esi), %ebx )
29603 SRC( movl 20(%esi), %edx )
29604 adcl %ebx, %eax
29605 -DST( movl %ebx, 16(%edi) )
29606 +DST( movl %ebx, %es:16(%edi) )
29607 adcl %edx, %eax
29608 -DST( movl %edx, 20(%edi) )
29609 +DST( movl %edx, %es:20(%edi) )
29610
29611 SRC( movl 24(%esi), %ebx )
29612 SRC( movl 28(%esi), %edx )
29613 adcl %ebx, %eax
29614 -DST( movl %ebx, 24(%edi) )
29615 +DST( movl %ebx, %es:24(%edi) )
29616 adcl %edx, %eax
29617 -DST( movl %edx, 28(%edi) )
29618 +DST( movl %edx, %es:28(%edi) )
29619
29620 lea 32(%esi), %esi
29621 lea 32(%edi), %edi
29622 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29623 shrl $2, %edx # This clears CF
29624 SRC(3: movl (%esi), %ebx )
29625 adcl %ebx, %eax
29626 -DST( movl %ebx, (%edi) )
29627 +DST( movl %ebx, %es:(%edi) )
29628 lea 4(%esi), %esi
29629 lea 4(%edi), %edi
29630 dec %edx
29631 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29632 jb 5f
29633 SRC( movw (%esi), %cx )
29634 leal 2(%esi), %esi
29635 -DST( movw %cx, (%edi) )
29636 +DST( movw %cx, %es:(%edi) )
29637 leal 2(%edi), %edi
29638 je 6f
29639 shll $16,%ecx
29640 SRC(5: movb (%esi), %cl )
29641 -DST( movb %cl, (%edi) )
29642 +DST( movb %cl, %es:(%edi) )
29643 6: addl %ecx, %eax
29644 adcl $0, %eax
29645 7:
29646 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29647
29648 6001:
29649 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29650 - movl $-EFAULT, (%ebx)
29651 + movl $-EFAULT, %ss:(%ebx)
29652
29653 # zero the complete destination - computing the rest
29654 # is too much work
29655 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29656
29657 6002:
29658 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29659 - movl $-EFAULT,(%ebx)
29660 + movl $-EFAULT,%ss:(%ebx)
29661 jmp 5000b
29662
29663 .previous
29664
29665 + pushl_cfi %ss
29666 + popl_cfi %ds
29667 + pushl_cfi %ss
29668 + popl_cfi %es
29669 popl_cfi %ebx
29670 CFI_RESTORE ebx
29671 popl_cfi %esi
29672 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29673 popl_cfi %ecx # equivalent to addl $4,%esp
29674 ret
29675 CFI_ENDPROC
29676 -ENDPROC(csum_partial_copy_generic)
29677 +ENDPROC(csum_partial_copy_generic_to_user)
29678
29679 #else
29680
29681 /* Version for PentiumII/PPro */
29682
29683 #define ROUND1(x) \
29684 + nop; nop; nop; \
29685 SRC(movl x(%esi), %ebx ) ; \
29686 addl %ebx, %eax ; \
29687 - DST(movl %ebx, x(%edi) ) ;
29688 + DST(movl %ebx, %es:x(%edi)) ;
29689
29690 #define ROUND(x) \
29691 + nop; nop; nop; \
29692 SRC(movl x(%esi), %ebx ) ; \
29693 adcl %ebx, %eax ; \
29694 - DST(movl %ebx, x(%edi) ) ;
29695 + DST(movl %ebx, %es:x(%edi)) ;
29696
29697 #define ARGBASE 12
29698 -
29699 -ENTRY(csum_partial_copy_generic)
29700 +
29701 +ENTRY(csum_partial_copy_generic_to_user)
29702 CFI_STARTPROC
29703 +
29704 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29705 + pushl_cfi %gs
29706 + popl_cfi %es
29707 + jmp csum_partial_copy_generic
29708 +#endif
29709 +
29710 +ENTRY(csum_partial_copy_generic_from_user)
29711 +
29712 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29713 + pushl_cfi %gs
29714 + popl_cfi %ds
29715 +#endif
29716 +
29717 +ENTRY(csum_partial_copy_generic)
29718 pushl_cfi %ebx
29719 CFI_REL_OFFSET ebx, 0
29720 pushl_cfi %edi
29721 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29722 subl %ebx, %edi
29723 lea -1(%esi),%edx
29724 andl $-32,%edx
29725 - lea 3f(%ebx,%ebx), %ebx
29726 + lea 3f(%ebx,%ebx,2), %ebx
29727 testl %esi, %esi
29728 jmp *%ebx
29729 1: addl $64,%esi
29730 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29731 jb 5f
29732 SRC( movw (%esi), %dx )
29733 leal 2(%esi), %esi
29734 -DST( movw %dx, (%edi) )
29735 +DST( movw %dx, %es:(%edi) )
29736 leal 2(%edi), %edi
29737 je 6f
29738 shll $16,%edx
29739 5:
29740 SRC( movb (%esi), %dl )
29741 -DST( movb %dl, (%edi) )
29742 +DST( movb %dl, %es:(%edi) )
29743 6: addl %edx, %eax
29744 adcl $0, %eax
29745 7:
29746 .section .fixup, "ax"
29747 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29748 - movl $-EFAULT, (%ebx)
29749 + movl $-EFAULT, %ss:(%ebx)
29750 # zero the complete destination (computing the rest is too much work)
29751 movl ARGBASE+8(%esp),%edi # dst
29752 movl ARGBASE+12(%esp),%ecx # len
29753 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29754 rep; stosb
29755 jmp 7b
29756 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29757 - movl $-EFAULT, (%ebx)
29758 + movl $-EFAULT, %ss:(%ebx)
29759 jmp 7b
29760 .previous
29761
29762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29763 + pushl_cfi %ss
29764 + popl_cfi %ds
29765 + pushl_cfi %ss
29766 + popl_cfi %es
29767 +#endif
29768 +
29769 popl_cfi %esi
29770 CFI_RESTORE esi
29771 popl_cfi %edi
29772 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29773 CFI_RESTORE ebx
29774 ret
29775 CFI_ENDPROC
29776 -ENDPROC(csum_partial_copy_generic)
29777 +ENDPROC(csum_partial_copy_generic_to_user)
29778
29779 #undef ROUND
29780 #undef ROUND1
29781 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29782 index f2145cf..cea889d 100644
29783 --- a/arch/x86/lib/clear_page_64.S
29784 +++ b/arch/x86/lib/clear_page_64.S
29785 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29786 movl $4096/8,%ecx
29787 xorl %eax,%eax
29788 rep stosq
29789 + pax_force_retaddr
29790 ret
29791 CFI_ENDPROC
29792 ENDPROC(clear_page_c)
29793 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29794 movl $4096,%ecx
29795 xorl %eax,%eax
29796 rep stosb
29797 + pax_force_retaddr
29798 ret
29799 CFI_ENDPROC
29800 ENDPROC(clear_page_c_e)
29801 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29802 leaq 64(%rdi),%rdi
29803 jnz .Lloop
29804 nop
29805 + pax_force_retaddr
29806 ret
29807 CFI_ENDPROC
29808 .Lclear_page_end:
29809 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29810
29811 #include <asm/cpufeature.h>
29812
29813 - .section .altinstr_replacement,"ax"
29814 + .section .altinstr_replacement,"a"
29815 1: .byte 0xeb /* jmp <disp8> */
29816 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29817 2: .byte 0xeb /* jmp <disp8> */
29818 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29819 index 1e572c5..2a162cd 100644
29820 --- a/arch/x86/lib/cmpxchg16b_emu.S
29821 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29822 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29823
29824 popf
29825 mov $1, %al
29826 + pax_force_retaddr
29827 ret
29828
29829 not_same:
29830 popf
29831 xor %al,%al
29832 + pax_force_retaddr
29833 ret
29834
29835 CFI_ENDPROC
29836 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29837 index 176cca6..e0d658e 100644
29838 --- a/arch/x86/lib/copy_page_64.S
29839 +++ b/arch/x86/lib/copy_page_64.S
29840 @@ -9,6 +9,7 @@ copy_page_rep:
29841 CFI_STARTPROC
29842 movl $4096/8, %ecx
29843 rep movsq
29844 + pax_force_retaddr
29845 ret
29846 CFI_ENDPROC
29847 ENDPROC(copy_page_rep)
29848 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29849 CFI_ADJUST_CFA_OFFSET 2*8
29850 movq %rbx, (%rsp)
29851 CFI_REL_OFFSET rbx, 0
29852 - movq %r12, 1*8(%rsp)
29853 - CFI_REL_OFFSET r12, 1*8
29854 + movq %r13, 1*8(%rsp)
29855 + CFI_REL_OFFSET r13, 1*8
29856
29857 movl $(4096/64)-5, %ecx
29858 .p2align 4
29859 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29860 movq 0x8*4(%rsi), %r9
29861 movq 0x8*5(%rsi), %r10
29862 movq 0x8*6(%rsi), %r11
29863 - movq 0x8*7(%rsi), %r12
29864 + movq 0x8*7(%rsi), %r13
29865
29866 prefetcht0 5*64(%rsi)
29867
29868 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29869 movq %r9, 0x8*4(%rdi)
29870 movq %r10, 0x8*5(%rdi)
29871 movq %r11, 0x8*6(%rdi)
29872 - movq %r12, 0x8*7(%rdi)
29873 + movq %r13, 0x8*7(%rdi)
29874
29875 leaq 64 (%rsi), %rsi
29876 leaq 64 (%rdi), %rdi
29877 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29878 movq 0x8*4(%rsi), %r9
29879 movq 0x8*5(%rsi), %r10
29880 movq 0x8*6(%rsi), %r11
29881 - movq 0x8*7(%rsi), %r12
29882 + movq 0x8*7(%rsi), %r13
29883
29884 movq %rax, 0x8*0(%rdi)
29885 movq %rbx, 0x8*1(%rdi)
29886 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29887 movq %r9, 0x8*4(%rdi)
29888 movq %r10, 0x8*5(%rdi)
29889 movq %r11, 0x8*6(%rdi)
29890 - movq %r12, 0x8*7(%rdi)
29891 + movq %r13, 0x8*7(%rdi)
29892
29893 leaq 64(%rdi), %rdi
29894 leaq 64(%rsi), %rsi
29895 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29896
29897 movq (%rsp), %rbx
29898 CFI_RESTORE rbx
29899 - movq 1*8(%rsp), %r12
29900 - CFI_RESTORE r12
29901 + movq 1*8(%rsp), %r13
29902 + CFI_RESTORE r13
29903 addq $2*8, %rsp
29904 CFI_ADJUST_CFA_OFFSET -2*8
29905 + pax_force_retaddr
29906 ret
29907 .Lcopy_page_end:
29908 CFI_ENDPROC
29909 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29910
29911 #include <asm/cpufeature.h>
29912
29913 - .section .altinstr_replacement,"ax"
29914 + .section .altinstr_replacement,"a"
29915 1: .byte 0xeb /* jmp <disp8> */
29916 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29917 2:
29918 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29919 index dee945d..a84067b 100644
29920 --- a/arch/x86/lib/copy_user_64.S
29921 +++ b/arch/x86/lib/copy_user_64.S
29922 @@ -18,31 +18,7 @@
29923 #include <asm/alternative-asm.h>
29924 #include <asm/asm.h>
29925 #include <asm/smap.h>
29926 -
29927 -/*
29928 - * By placing feature2 after feature1 in altinstructions section, we logically
29929 - * implement:
29930 - * If CPU has feature2, jmp to alt2 is used
29931 - * else if CPU has feature1, jmp to alt1 is used
29932 - * else jmp to orig is used.
29933 - */
29934 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29935 -0:
29936 - .byte 0xe9 /* 32bit jump */
29937 - .long \orig-1f /* by default jump to orig */
29938 -1:
29939 - .section .altinstr_replacement,"ax"
29940 -2: .byte 0xe9 /* near jump with 32bit immediate */
29941 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29942 -3: .byte 0xe9 /* near jump with 32bit immediate */
29943 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29944 - .previous
29945 -
29946 - .section .altinstructions,"a"
29947 - altinstruction_entry 0b,2b,\feature1,5,5
29948 - altinstruction_entry 0b,3b,\feature2,5,5
29949 - .previous
29950 - .endm
29951 +#include <asm/pgtable.h>
29952
29953 .macro ALIGN_DESTINATION
29954 #ifdef FIX_ALIGNMENT
29955 @@ -70,52 +46,6 @@
29956 #endif
29957 .endm
29958
29959 -/* Standard copy_to_user with segment limit checking */
29960 -ENTRY(_copy_to_user)
29961 - CFI_STARTPROC
29962 - GET_THREAD_INFO(%rax)
29963 - movq %rdi,%rcx
29964 - addq %rdx,%rcx
29965 - jc bad_to_user
29966 - cmpq TI_addr_limit(%rax),%rcx
29967 - ja bad_to_user
29968 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29969 - copy_user_generic_unrolled,copy_user_generic_string, \
29970 - copy_user_enhanced_fast_string
29971 - CFI_ENDPROC
29972 -ENDPROC(_copy_to_user)
29973 -
29974 -/* Standard copy_from_user with segment limit checking */
29975 -ENTRY(_copy_from_user)
29976 - CFI_STARTPROC
29977 - GET_THREAD_INFO(%rax)
29978 - movq %rsi,%rcx
29979 - addq %rdx,%rcx
29980 - jc bad_from_user
29981 - cmpq TI_addr_limit(%rax),%rcx
29982 - ja bad_from_user
29983 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29984 - copy_user_generic_unrolled,copy_user_generic_string, \
29985 - copy_user_enhanced_fast_string
29986 - CFI_ENDPROC
29987 -ENDPROC(_copy_from_user)
29988 -
29989 - .section .fixup,"ax"
29990 - /* must zero dest */
29991 -ENTRY(bad_from_user)
29992 -bad_from_user:
29993 - CFI_STARTPROC
29994 - movl %edx,%ecx
29995 - xorl %eax,%eax
29996 - rep
29997 - stosb
29998 -bad_to_user:
29999 - movl %edx,%eax
30000 - ret
30001 - CFI_ENDPROC
30002 -ENDPROC(bad_from_user)
30003 - .previous
30004 -
30005 /*
30006 * copy_user_generic_unrolled - memory copy with exception handling.
30007 * This version is for CPUs like P4 that don't have efficient micro
30008 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30009 */
30010 ENTRY(copy_user_generic_unrolled)
30011 CFI_STARTPROC
30012 + ASM_PAX_OPEN_USERLAND
30013 ASM_STAC
30014 cmpl $8,%edx
30015 jb 20f /* less then 8 bytes, go to byte copy loop */
30016 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30017 jnz 21b
30018 23: xor %eax,%eax
30019 ASM_CLAC
30020 + ASM_PAX_CLOSE_USERLAND
30021 + pax_force_retaddr
30022 ret
30023
30024 .section .fixup,"ax"
30025 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30026 */
30027 ENTRY(copy_user_generic_string)
30028 CFI_STARTPROC
30029 + ASM_PAX_OPEN_USERLAND
30030 ASM_STAC
30031 cmpl $8,%edx
30032 jb 2f /* less than 8 bytes, go to byte copy loop */
30033 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30034 movsb
30035 xorl %eax,%eax
30036 ASM_CLAC
30037 + ASM_PAX_CLOSE_USERLAND
30038 + pax_force_retaddr
30039 ret
30040
30041 .section .fixup,"ax"
30042 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30043 */
30044 ENTRY(copy_user_enhanced_fast_string)
30045 CFI_STARTPROC
30046 + ASM_PAX_OPEN_USERLAND
30047 ASM_STAC
30048 movl %edx,%ecx
30049 1: rep
30050 movsb
30051 xorl %eax,%eax
30052 ASM_CLAC
30053 + ASM_PAX_CLOSE_USERLAND
30054 + pax_force_retaddr
30055 ret
30056
30057 .section .fixup,"ax"
30058 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30059 index 6a4f43c..c70fb52 100644
30060 --- a/arch/x86/lib/copy_user_nocache_64.S
30061 +++ b/arch/x86/lib/copy_user_nocache_64.S
30062 @@ -8,6 +8,7 @@
30063
30064 #include <linux/linkage.h>
30065 #include <asm/dwarf2.h>
30066 +#include <asm/alternative-asm.h>
30067
30068 #define FIX_ALIGNMENT 1
30069
30070 @@ -16,6 +17,7 @@
30071 #include <asm/thread_info.h>
30072 #include <asm/asm.h>
30073 #include <asm/smap.h>
30074 +#include <asm/pgtable.h>
30075
30076 .macro ALIGN_DESTINATION
30077 #ifdef FIX_ALIGNMENT
30078 @@ -49,6 +51,16 @@
30079 */
30080 ENTRY(__copy_user_nocache)
30081 CFI_STARTPROC
30082 +
30083 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30084 + mov pax_user_shadow_base,%rcx
30085 + cmp %rcx,%rsi
30086 + jae 1f
30087 + add %rcx,%rsi
30088 +1:
30089 +#endif
30090 +
30091 + ASM_PAX_OPEN_USERLAND
30092 ASM_STAC
30093 cmpl $8,%edx
30094 jb 20f /* less then 8 bytes, go to byte copy loop */
30095 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30096 jnz 21b
30097 23: xorl %eax,%eax
30098 ASM_CLAC
30099 + ASM_PAX_CLOSE_USERLAND
30100 sfence
30101 + pax_force_retaddr
30102 ret
30103
30104 .section .fixup,"ax"
30105 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30106 index 2419d5f..fe52d0e 100644
30107 --- a/arch/x86/lib/csum-copy_64.S
30108 +++ b/arch/x86/lib/csum-copy_64.S
30109 @@ -9,6 +9,7 @@
30110 #include <asm/dwarf2.h>
30111 #include <asm/errno.h>
30112 #include <asm/asm.h>
30113 +#include <asm/alternative-asm.h>
30114
30115 /*
30116 * Checksum copy with exception handling.
30117 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30118 CFI_ADJUST_CFA_OFFSET 7*8
30119 movq %rbx, 2*8(%rsp)
30120 CFI_REL_OFFSET rbx, 2*8
30121 - movq %r12, 3*8(%rsp)
30122 - CFI_REL_OFFSET r12, 3*8
30123 + movq %r15, 3*8(%rsp)
30124 + CFI_REL_OFFSET r15, 3*8
30125 movq %r14, 4*8(%rsp)
30126 CFI_REL_OFFSET r14, 4*8
30127 movq %r13, 5*8(%rsp)
30128 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30129 movl %edx, %ecx
30130
30131 xorl %r9d, %r9d
30132 - movq %rcx, %r12
30133 + movq %rcx, %r15
30134
30135 - shrq $6, %r12
30136 + shrq $6, %r15
30137 jz .Lhandle_tail /* < 64 */
30138
30139 clc
30140
30141 /* main loop. clear in 64 byte blocks */
30142 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30143 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30144 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30145 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30146 .p2align 4
30147 .Lloop:
30148 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30149 adcq %r14, %rax
30150 adcq %r13, %rax
30151
30152 - decl %r12d
30153 + decl %r15d
30154
30155 dest
30156 movq %rbx, (%rsi)
30157 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30158 .Lende:
30159 movq 2*8(%rsp), %rbx
30160 CFI_RESTORE rbx
30161 - movq 3*8(%rsp), %r12
30162 - CFI_RESTORE r12
30163 + movq 3*8(%rsp), %r15
30164 + CFI_RESTORE r15
30165 movq 4*8(%rsp), %r14
30166 CFI_RESTORE r14
30167 movq 5*8(%rsp), %r13
30168 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30169 CFI_RESTORE rbp
30170 addq $7*8, %rsp
30171 CFI_ADJUST_CFA_OFFSET -7*8
30172 + pax_force_retaddr
30173 ret
30174 CFI_RESTORE_STATE
30175
30176 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30177 index 7609e0e..b449b98 100644
30178 --- a/arch/x86/lib/csum-wrappers_64.c
30179 +++ b/arch/x86/lib/csum-wrappers_64.c
30180 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30181 len -= 2;
30182 }
30183 }
30184 + pax_open_userland();
30185 stac();
30186 - isum = csum_partial_copy_generic((__force const void *)src,
30187 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30188 dst, len, isum, errp, NULL);
30189 clac();
30190 + pax_close_userland();
30191 if (unlikely(*errp))
30192 goto out_err;
30193
30194 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30195 }
30196
30197 *errp = 0;
30198 + pax_open_userland();
30199 stac();
30200 - ret = csum_partial_copy_generic(src, (void __force *)dst,
30201 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30202 len, isum, NULL, errp);
30203 clac();
30204 + pax_close_userland();
30205 return ret;
30206 }
30207 EXPORT_SYMBOL(csum_partial_copy_to_user);
30208 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30209 index a451235..1daa956 100644
30210 --- a/arch/x86/lib/getuser.S
30211 +++ b/arch/x86/lib/getuser.S
30212 @@ -33,17 +33,40 @@
30213 #include <asm/thread_info.h>
30214 #include <asm/asm.h>
30215 #include <asm/smap.h>
30216 +#include <asm/segment.h>
30217 +#include <asm/pgtable.h>
30218 +#include <asm/alternative-asm.h>
30219 +
30220 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30221 +#define __copyuser_seg gs;
30222 +#else
30223 +#define __copyuser_seg
30224 +#endif
30225
30226 .text
30227 ENTRY(__get_user_1)
30228 CFI_STARTPROC
30229 +
30230 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30231 GET_THREAD_INFO(%_ASM_DX)
30232 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30233 jae bad_get_user
30234 ASM_STAC
30235 -1: movzbl (%_ASM_AX),%edx
30236 +
30237 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30238 + mov pax_user_shadow_base,%_ASM_DX
30239 + cmp %_ASM_DX,%_ASM_AX
30240 + jae 1234f
30241 + add %_ASM_DX,%_ASM_AX
30242 +1234:
30243 +#endif
30244 +
30245 +#endif
30246 +
30247 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30248 xor %eax,%eax
30249 ASM_CLAC
30250 + pax_force_retaddr
30251 ret
30252 CFI_ENDPROC
30253 ENDPROC(__get_user_1)
30254 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30255 ENTRY(__get_user_2)
30256 CFI_STARTPROC
30257 add $1,%_ASM_AX
30258 +
30259 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30260 jc bad_get_user
30261 GET_THREAD_INFO(%_ASM_DX)
30262 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30263 jae bad_get_user
30264 ASM_STAC
30265 -2: movzwl -1(%_ASM_AX),%edx
30266 +
30267 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30268 + mov pax_user_shadow_base,%_ASM_DX
30269 + cmp %_ASM_DX,%_ASM_AX
30270 + jae 1234f
30271 + add %_ASM_DX,%_ASM_AX
30272 +1234:
30273 +#endif
30274 +
30275 +#endif
30276 +
30277 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30278 xor %eax,%eax
30279 ASM_CLAC
30280 + pax_force_retaddr
30281 ret
30282 CFI_ENDPROC
30283 ENDPROC(__get_user_2)
30284 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30285 ENTRY(__get_user_4)
30286 CFI_STARTPROC
30287 add $3,%_ASM_AX
30288 +
30289 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30290 jc bad_get_user
30291 GET_THREAD_INFO(%_ASM_DX)
30292 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30293 jae bad_get_user
30294 ASM_STAC
30295 -3: movl -3(%_ASM_AX),%edx
30296 +
30297 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30298 + mov pax_user_shadow_base,%_ASM_DX
30299 + cmp %_ASM_DX,%_ASM_AX
30300 + jae 1234f
30301 + add %_ASM_DX,%_ASM_AX
30302 +1234:
30303 +#endif
30304 +
30305 +#endif
30306 +
30307 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30308 xor %eax,%eax
30309 ASM_CLAC
30310 + pax_force_retaddr
30311 ret
30312 CFI_ENDPROC
30313 ENDPROC(__get_user_4)
30314 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30315 GET_THREAD_INFO(%_ASM_DX)
30316 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30317 jae bad_get_user
30318 +
30319 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30320 + mov pax_user_shadow_base,%_ASM_DX
30321 + cmp %_ASM_DX,%_ASM_AX
30322 + jae 1234f
30323 + add %_ASM_DX,%_ASM_AX
30324 +1234:
30325 +#endif
30326 +
30327 ASM_STAC
30328 4: movq -7(%_ASM_AX),%rdx
30329 xor %eax,%eax
30330 ASM_CLAC
30331 + pax_force_retaddr
30332 ret
30333 #else
30334 add $7,%_ASM_AX
30335 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30336 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30337 jae bad_get_user_8
30338 ASM_STAC
30339 -4: movl -7(%_ASM_AX),%edx
30340 -5: movl -3(%_ASM_AX),%ecx
30341 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30342 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30343 xor %eax,%eax
30344 ASM_CLAC
30345 + pax_force_retaddr
30346 ret
30347 #endif
30348 CFI_ENDPROC
30349 @@ -113,6 +175,7 @@ bad_get_user:
30350 xor %edx,%edx
30351 mov $(-EFAULT),%_ASM_AX
30352 ASM_CLAC
30353 + pax_force_retaddr
30354 ret
30355 CFI_ENDPROC
30356 END(bad_get_user)
30357 @@ -124,6 +187,7 @@ bad_get_user_8:
30358 xor %ecx,%ecx
30359 mov $(-EFAULT),%_ASM_AX
30360 ASM_CLAC
30361 + pax_force_retaddr
30362 ret
30363 CFI_ENDPROC
30364 END(bad_get_user_8)
30365 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30366 index 54fcffe..7be149e 100644
30367 --- a/arch/x86/lib/insn.c
30368 +++ b/arch/x86/lib/insn.c
30369 @@ -20,8 +20,10 @@
30370
30371 #ifdef __KERNEL__
30372 #include <linux/string.h>
30373 +#include <asm/pgtable_types.h>
30374 #else
30375 #include <string.h>
30376 +#define ktla_ktva(addr) addr
30377 #endif
30378 #include <asm/inat.h>
30379 #include <asm/insn.h>
30380 @@ -53,8 +55,8 @@
30381 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30382 {
30383 memset(insn, 0, sizeof(*insn));
30384 - insn->kaddr = kaddr;
30385 - insn->next_byte = kaddr;
30386 + insn->kaddr = ktla_ktva(kaddr);
30387 + insn->next_byte = ktla_ktva(kaddr);
30388 insn->x86_64 = x86_64 ? 1 : 0;
30389 insn->opnd_bytes = 4;
30390 if (x86_64)
30391 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30392 index 05a95e7..326f2fa 100644
30393 --- a/arch/x86/lib/iomap_copy_64.S
30394 +++ b/arch/x86/lib/iomap_copy_64.S
30395 @@ -17,6 +17,7 @@
30396
30397 #include <linux/linkage.h>
30398 #include <asm/dwarf2.h>
30399 +#include <asm/alternative-asm.h>
30400
30401 /*
30402 * override generic version in lib/iomap_copy.c
30403 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30404 CFI_STARTPROC
30405 movl %edx,%ecx
30406 rep movsd
30407 + pax_force_retaddr
30408 ret
30409 CFI_ENDPROC
30410 ENDPROC(__iowrite32_copy)
30411 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30412 index 56313a3..0db417e 100644
30413 --- a/arch/x86/lib/memcpy_64.S
30414 +++ b/arch/x86/lib/memcpy_64.S
30415 @@ -24,7 +24,7 @@
30416 * This gets patched over the unrolled variant (below) via the
30417 * alternative instructions framework:
30418 */
30419 - .section .altinstr_replacement, "ax", @progbits
30420 + .section .altinstr_replacement, "a", @progbits
30421 .Lmemcpy_c:
30422 movq %rdi, %rax
30423 movq %rdx, %rcx
30424 @@ -33,6 +33,7 @@
30425 rep movsq
30426 movl %edx, %ecx
30427 rep movsb
30428 + pax_force_retaddr
30429 ret
30430 .Lmemcpy_e:
30431 .previous
30432 @@ -44,11 +45,12 @@
30433 * This gets patched over the unrolled variant (below) via the
30434 * alternative instructions framework:
30435 */
30436 - .section .altinstr_replacement, "ax", @progbits
30437 + .section .altinstr_replacement, "a", @progbits
30438 .Lmemcpy_c_e:
30439 movq %rdi, %rax
30440 movq %rdx, %rcx
30441 rep movsb
30442 + pax_force_retaddr
30443 ret
30444 .Lmemcpy_e_e:
30445 .previous
30446 @@ -136,6 +138,7 @@ ENTRY(memcpy)
30447 movq %r9, 1*8(%rdi)
30448 movq %r10, -2*8(%rdi, %rdx)
30449 movq %r11, -1*8(%rdi, %rdx)
30450 + pax_force_retaddr
30451 retq
30452 .p2align 4
30453 .Lless_16bytes:
30454 @@ -148,6 +151,7 @@ ENTRY(memcpy)
30455 movq -1*8(%rsi, %rdx), %r9
30456 movq %r8, 0*8(%rdi)
30457 movq %r9, -1*8(%rdi, %rdx)
30458 + pax_force_retaddr
30459 retq
30460 .p2align 4
30461 .Lless_8bytes:
30462 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30463 movl -4(%rsi, %rdx), %r8d
30464 movl %ecx, (%rdi)
30465 movl %r8d, -4(%rdi, %rdx)
30466 + pax_force_retaddr
30467 retq
30468 .p2align 4
30469 .Lless_3bytes:
30470 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30471 movb %cl, (%rdi)
30472
30473 .Lend:
30474 + pax_force_retaddr
30475 retq
30476 CFI_ENDPROC
30477 ENDPROC(memcpy)
30478 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30479 index 65268a6..dd1de11 100644
30480 --- a/arch/x86/lib/memmove_64.S
30481 +++ b/arch/x86/lib/memmove_64.S
30482 @@ -202,14 +202,16 @@ ENTRY(memmove)
30483 movb (%rsi), %r11b
30484 movb %r11b, (%rdi)
30485 13:
30486 + pax_force_retaddr
30487 retq
30488 CFI_ENDPROC
30489
30490 - .section .altinstr_replacement,"ax"
30491 + .section .altinstr_replacement,"a"
30492 .Lmemmove_begin_forward_efs:
30493 /* Forward moving data. */
30494 movq %rdx, %rcx
30495 rep movsb
30496 + pax_force_retaddr
30497 retq
30498 .Lmemmove_end_forward_efs:
30499 .previous
30500 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30501 index 2dcb380..2eb79fe 100644
30502 --- a/arch/x86/lib/memset_64.S
30503 +++ b/arch/x86/lib/memset_64.S
30504 @@ -16,7 +16,7 @@
30505 *
30506 * rax original destination
30507 */
30508 - .section .altinstr_replacement, "ax", @progbits
30509 + .section .altinstr_replacement, "a", @progbits
30510 .Lmemset_c:
30511 movq %rdi,%r9
30512 movq %rdx,%rcx
30513 @@ -30,6 +30,7 @@
30514 movl %edx,%ecx
30515 rep stosb
30516 movq %r9,%rax
30517 + pax_force_retaddr
30518 ret
30519 .Lmemset_e:
30520 .previous
30521 @@ -45,13 +46,14 @@
30522 *
30523 * rax original destination
30524 */
30525 - .section .altinstr_replacement, "ax", @progbits
30526 + .section .altinstr_replacement, "a", @progbits
30527 .Lmemset_c_e:
30528 movq %rdi,%r9
30529 movb %sil,%al
30530 movq %rdx,%rcx
30531 rep stosb
30532 movq %r9,%rax
30533 + pax_force_retaddr
30534 ret
30535 .Lmemset_e_e:
30536 .previous
30537 @@ -118,6 +120,7 @@ ENTRY(__memset)
30538
30539 .Lende:
30540 movq %r10,%rax
30541 + pax_force_retaddr
30542 ret
30543
30544 CFI_RESTORE_STATE
30545 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30546 index c9f2d9b..e7fd2c0 100644
30547 --- a/arch/x86/lib/mmx_32.c
30548 +++ b/arch/x86/lib/mmx_32.c
30549 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30550 {
30551 void *p;
30552 int i;
30553 + unsigned long cr0;
30554
30555 if (unlikely(in_interrupt()))
30556 return __memcpy(to, from, len);
30557 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30558 kernel_fpu_begin();
30559
30560 __asm__ __volatile__ (
30561 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30562 - " prefetch 64(%0)\n"
30563 - " prefetch 128(%0)\n"
30564 - " prefetch 192(%0)\n"
30565 - " prefetch 256(%0)\n"
30566 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30567 + " prefetch 64(%1)\n"
30568 + " prefetch 128(%1)\n"
30569 + " prefetch 192(%1)\n"
30570 + " prefetch 256(%1)\n"
30571 "2: \n"
30572 ".section .fixup, \"ax\"\n"
30573 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30574 + "3: \n"
30575 +
30576 +#ifdef CONFIG_PAX_KERNEXEC
30577 + " movl %%cr0, %0\n"
30578 + " movl %0, %%eax\n"
30579 + " andl $0xFFFEFFFF, %%eax\n"
30580 + " movl %%eax, %%cr0\n"
30581 +#endif
30582 +
30583 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30584 +
30585 +#ifdef CONFIG_PAX_KERNEXEC
30586 + " movl %0, %%cr0\n"
30587 +#endif
30588 +
30589 " jmp 2b\n"
30590 ".previous\n"
30591 _ASM_EXTABLE(1b, 3b)
30592 - : : "r" (from));
30593 + : "=&r" (cr0) : "r" (from) : "ax");
30594
30595 for ( ; i > 5; i--) {
30596 __asm__ __volatile__ (
30597 - "1: prefetch 320(%0)\n"
30598 - "2: movq (%0), %%mm0\n"
30599 - " movq 8(%0), %%mm1\n"
30600 - " movq 16(%0), %%mm2\n"
30601 - " movq 24(%0), %%mm3\n"
30602 - " movq %%mm0, (%1)\n"
30603 - " movq %%mm1, 8(%1)\n"
30604 - " movq %%mm2, 16(%1)\n"
30605 - " movq %%mm3, 24(%1)\n"
30606 - " movq 32(%0), %%mm0\n"
30607 - " movq 40(%0), %%mm1\n"
30608 - " movq 48(%0), %%mm2\n"
30609 - " movq 56(%0), %%mm3\n"
30610 - " movq %%mm0, 32(%1)\n"
30611 - " movq %%mm1, 40(%1)\n"
30612 - " movq %%mm2, 48(%1)\n"
30613 - " movq %%mm3, 56(%1)\n"
30614 + "1: prefetch 320(%1)\n"
30615 + "2: movq (%1), %%mm0\n"
30616 + " movq 8(%1), %%mm1\n"
30617 + " movq 16(%1), %%mm2\n"
30618 + " movq 24(%1), %%mm3\n"
30619 + " movq %%mm0, (%2)\n"
30620 + " movq %%mm1, 8(%2)\n"
30621 + " movq %%mm2, 16(%2)\n"
30622 + " movq %%mm3, 24(%2)\n"
30623 + " movq 32(%1), %%mm0\n"
30624 + " movq 40(%1), %%mm1\n"
30625 + " movq 48(%1), %%mm2\n"
30626 + " movq 56(%1), %%mm3\n"
30627 + " movq %%mm0, 32(%2)\n"
30628 + " movq %%mm1, 40(%2)\n"
30629 + " movq %%mm2, 48(%2)\n"
30630 + " movq %%mm3, 56(%2)\n"
30631 ".section .fixup, \"ax\"\n"
30632 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30633 + "3:\n"
30634 +
30635 +#ifdef CONFIG_PAX_KERNEXEC
30636 + " movl %%cr0, %0\n"
30637 + " movl %0, %%eax\n"
30638 + " andl $0xFFFEFFFF, %%eax\n"
30639 + " movl %%eax, %%cr0\n"
30640 +#endif
30641 +
30642 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30643 +
30644 +#ifdef CONFIG_PAX_KERNEXEC
30645 + " movl %0, %%cr0\n"
30646 +#endif
30647 +
30648 " jmp 2b\n"
30649 ".previous\n"
30650 _ASM_EXTABLE(1b, 3b)
30651 - : : "r" (from), "r" (to) : "memory");
30652 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30653
30654 from += 64;
30655 to += 64;
30656 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30657 static void fast_copy_page(void *to, void *from)
30658 {
30659 int i;
30660 + unsigned long cr0;
30661
30662 kernel_fpu_begin();
30663
30664 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30665 * but that is for later. -AV
30666 */
30667 __asm__ __volatile__(
30668 - "1: prefetch (%0)\n"
30669 - " prefetch 64(%0)\n"
30670 - " prefetch 128(%0)\n"
30671 - " prefetch 192(%0)\n"
30672 - " prefetch 256(%0)\n"
30673 + "1: prefetch (%1)\n"
30674 + " prefetch 64(%1)\n"
30675 + " prefetch 128(%1)\n"
30676 + " prefetch 192(%1)\n"
30677 + " prefetch 256(%1)\n"
30678 "2: \n"
30679 ".section .fixup, \"ax\"\n"
30680 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30681 + "3: \n"
30682 +
30683 +#ifdef CONFIG_PAX_KERNEXEC
30684 + " movl %%cr0, %0\n"
30685 + " movl %0, %%eax\n"
30686 + " andl $0xFFFEFFFF, %%eax\n"
30687 + " movl %%eax, %%cr0\n"
30688 +#endif
30689 +
30690 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30691 +
30692 +#ifdef CONFIG_PAX_KERNEXEC
30693 + " movl %0, %%cr0\n"
30694 +#endif
30695 +
30696 " jmp 2b\n"
30697 ".previous\n"
30698 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30699 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30700
30701 for (i = 0; i < (4096-320)/64; i++) {
30702 __asm__ __volatile__ (
30703 - "1: prefetch 320(%0)\n"
30704 - "2: movq (%0), %%mm0\n"
30705 - " movntq %%mm0, (%1)\n"
30706 - " movq 8(%0), %%mm1\n"
30707 - " movntq %%mm1, 8(%1)\n"
30708 - " movq 16(%0), %%mm2\n"
30709 - " movntq %%mm2, 16(%1)\n"
30710 - " movq 24(%0), %%mm3\n"
30711 - " movntq %%mm3, 24(%1)\n"
30712 - " movq 32(%0), %%mm4\n"
30713 - " movntq %%mm4, 32(%1)\n"
30714 - " movq 40(%0), %%mm5\n"
30715 - " movntq %%mm5, 40(%1)\n"
30716 - " movq 48(%0), %%mm6\n"
30717 - " movntq %%mm6, 48(%1)\n"
30718 - " movq 56(%0), %%mm7\n"
30719 - " movntq %%mm7, 56(%1)\n"
30720 + "1: prefetch 320(%1)\n"
30721 + "2: movq (%1), %%mm0\n"
30722 + " movntq %%mm0, (%2)\n"
30723 + " movq 8(%1), %%mm1\n"
30724 + " movntq %%mm1, 8(%2)\n"
30725 + " movq 16(%1), %%mm2\n"
30726 + " movntq %%mm2, 16(%2)\n"
30727 + " movq 24(%1), %%mm3\n"
30728 + " movntq %%mm3, 24(%2)\n"
30729 + " movq 32(%1), %%mm4\n"
30730 + " movntq %%mm4, 32(%2)\n"
30731 + " movq 40(%1), %%mm5\n"
30732 + " movntq %%mm5, 40(%2)\n"
30733 + " movq 48(%1), %%mm6\n"
30734 + " movntq %%mm6, 48(%2)\n"
30735 + " movq 56(%1), %%mm7\n"
30736 + " movntq %%mm7, 56(%2)\n"
30737 ".section .fixup, \"ax\"\n"
30738 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30739 + "3:\n"
30740 +
30741 +#ifdef CONFIG_PAX_KERNEXEC
30742 + " movl %%cr0, %0\n"
30743 + " movl %0, %%eax\n"
30744 + " andl $0xFFFEFFFF, %%eax\n"
30745 + " movl %%eax, %%cr0\n"
30746 +#endif
30747 +
30748 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30749 +
30750 +#ifdef CONFIG_PAX_KERNEXEC
30751 + " movl %0, %%cr0\n"
30752 +#endif
30753 +
30754 " jmp 2b\n"
30755 ".previous\n"
30756 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30757 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30758
30759 from += 64;
30760 to += 64;
30761 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30762 static void fast_copy_page(void *to, void *from)
30763 {
30764 int i;
30765 + unsigned long cr0;
30766
30767 kernel_fpu_begin();
30768
30769 __asm__ __volatile__ (
30770 - "1: prefetch (%0)\n"
30771 - " prefetch 64(%0)\n"
30772 - " prefetch 128(%0)\n"
30773 - " prefetch 192(%0)\n"
30774 - " prefetch 256(%0)\n"
30775 + "1: prefetch (%1)\n"
30776 + " prefetch 64(%1)\n"
30777 + " prefetch 128(%1)\n"
30778 + " prefetch 192(%1)\n"
30779 + " prefetch 256(%1)\n"
30780 "2: \n"
30781 ".section .fixup, \"ax\"\n"
30782 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30783 + "3: \n"
30784 +
30785 +#ifdef CONFIG_PAX_KERNEXEC
30786 + " movl %%cr0, %0\n"
30787 + " movl %0, %%eax\n"
30788 + " andl $0xFFFEFFFF, %%eax\n"
30789 + " movl %%eax, %%cr0\n"
30790 +#endif
30791 +
30792 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30793 +
30794 +#ifdef CONFIG_PAX_KERNEXEC
30795 + " movl %0, %%cr0\n"
30796 +#endif
30797 +
30798 " jmp 2b\n"
30799 ".previous\n"
30800 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30801 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30802
30803 for (i = 0; i < 4096/64; i++) {
30804 __asm__ __volatile__ (
30805 - "1: prefetch 320(%0)\n"
30806 - "2: movq (%0), %%mm0\n"
30807 - " movq 8(%0), %%mm1\n"
30808 - " movq 16(%0), %%mm2\n"
30809 - " movq 24(%0), %%mm3\n"
30810 - " movq %%mm0, (%1)\n"
30811 - " movq %%mm1, 8(%1)\n"
30812 - " movq %%mm2, 16(%1)\n"
30813 - " movq %%mm3, 24(%1)\n"
30814 - " movq 32(%0), %%mm0\n"
30815 - " movq 40(%0), %%mm1\n"
30816 - " movq 48(%0), %%mm2\n"
30817 - " movq 56(%0), %%mm3\n"
30818 - " movq %%mm0, 32(%1)\n"
30819 - " movq %%mm1, 40(%1)\n"
30820 - " movq %%mm2, 48(%1)\n"
30821 - " movq %%mm3, 56(%1)\n"
30822 + "1: prefetch 320(%1)\n"
30823 + "2: movq (%1), %%mm0\n"
30824 + " movq 8(%1), %%mm1\n"
30825 + " movq 16(%1), %%mm2\n"
30826 + " movq 24(%1), %%mm3\n"
30827 + " movq %%mm0, (%2)\n"
30828 + " movq %%mm1, 8(%2)\n"
30829 + " movq %%mm2, 16(%2)\n"
30830 + " movq %%mm3, 24(%2)\n"
30831 + " movq 32(%1), %%mm0\n"
30832 + " movq 40(%1), %%mm1\n"
30833 + " movq 48(%1), %%mm2\n"
30834 + " movq 56(%1), %%mm3\n"
30835 + " movq %%mm0, 32(%2)\n"
30836 + " movq %%mm1, 40(%2)\n"
30837 + " movq %%mm2, 48(%2)\n"
30838 + " movq %%mm3, 56(%2)\n"
30839 ".section .fixup, \"ax\"\n"
30840 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30841 + "3:\n"
30842 +
30843 +#ifdef CONFIG_PAX_KERNEXEC
30844 + " movl %%cr0, %0\n"
30845 + " movl %0, %%eax\n"
30846 + " andl $0xFFFEFFFF, %%eax\n"
30847 + " movl %%eax, %%cr0\n"
30848 +#endif
30849 +
30850 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30851 +
30852 +#ifdef CONFIG_PAX_KERNEXEC
30853 + " movl %0, %%cr0\n"
30854 +#endif
30855 +
30856 " jmp 2b\n"
30857 ".previous\n"
30858 _ASM_EXTABLE(1b, 3b)
30859 - : : "r" (from), "r" (to) : "memory");
30860 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30861
30862 from += 64;
30863 to += 64;
30864 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30865 index f6d13ee..d789440 100644
30866 --- a/arch/x86/lib/msr-reg.S
30867 +++ b/arch/x86/lib/msr-reg.S
30868 @@ -3,6 +3,7 @@
30869 #include <asm/dwarf2.h>
30870 #include <asm/asm.h>
30871 #include <asm/msr.h>
30872 +#include <asm/alternative-asm.h>
30873
30874 #ifdef CONFIG_X86_64
30875 /*
30876 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30877 movl %edi, 28(%r10)
30878 popq_cfi %rbp
30879 popq_cfi %rbx
30880 + pax_force_retaddr
30881 ret
30882 3:
30883 CFI_RESTORE_STATE
30884 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30885 index fc6ba17..d4d989d 100644
30886 --- a/arch/x86/lib/putuser.S
30887 +++ b/arch/x86/lib/putuser.S
30888 @@ -16,7 +16,9 @@
30889 #include <asm/errno.h>
30890 #include <asm/asm.h>
30891 #include <asm/smap.h>
30892 -
30893 +#include <asm/segment.h>
30894 +#include <asm/pgtable.h>
30895 +#include <asm/alternative-asm.h>
30896
30897 /*
30898 * __put_user_X
30899 @@ -30,57 +32,125 @@
30900 * as they get called from within inline assembly.
30901 */
30902
30903 -#define ENTER CFI_STARTPROC ; \
30904 - GET_THREAD_INFO(%_ASM_BX)
30905 -#define EXIT ASM_CLAC ; \
30906 - ret ; \
30907 +#define ENTER CFI_STARTPROC
30908 +#define EXIT ASM_CLAC ; \
30909 + pax_force_retaddr ; \
30910 + ret ; \
30911 CFI_ENDPROC
30912
30913 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30914 +#define _DEST %_ASM_CX,%_ASM_BX
30915 +#else
30916 +#define _DEST %_ASM_CX
30917 +#endif
30918 +
30919 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30920 +#define __copyuser_seg gs;
30921 +#else
30922 +#define __copyuser_seg
30923 +#endif
30924 +
30925 .text
30926 ENTRY(__put_user_1)
30927 ENTER
30928 +
30929 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30930 + GET_THREAD_INFO(%_ASM_BX)
30931 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30932 jae bad_put_user
30933 ASM_STAC
30934 -1: movb %al,(%_ASM_CX)
30935 +
30936 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30937 + mov pax_user_shadow_base,%_ASM_BX
30938 + cmp %_ASM_BX,%_ASM_CX
30939 + jb 1234f
30940 + xor %ebx,%ebx
30941 +1234:
30942 +#endif
30943 +
30944 +#endif
30945 +
30946 +1: __copyuser_seg movb %al,(_DEST)
30947 xor %eax,%eax
30948 EXIT
30949 ENDPROC(__put_user_1)
30950
30951 ENTRY(__put_user_2)
30952 ENTER
30953 +
30954 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30955 + GET_THREAD_INFO(%_ASM_BX)
30956 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30957 sub $1,%_ASM_BX
30958 cmp %_ASM_BX,%_ASM_CX
30959 jae bad_put_user
30960 ASM_STAC
30961 -2: movw %ax,(%_ASM_CX)
30962 +
30963 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30964 + mov pax_user_shadow_base,%_ASM_BX
30965 + cmp %_ASM_BX,%_ASM_CX
30966 + jb 1234f
30967 + xor %ebx,%ebx
30968 +1234:
30969 +#endif
30970 +
30971 +#endif
30972 +
30973 +2: __copyuser_seg movw %ax,(_DEST)
30974 xor %eax,%eax
30975 EXIT
30976 ENDPROC(__put_user_2)
30977
30978 ENTRY(__put_user_4)
30979 ENTER
30980 +
30981 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30982 + GET_THREAD_INFO(%_ASM_BX)
30983 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30984 sub $3,%_ASM_BX
30985 cmp %_ASM_BX,%_ASM_CX
30986 jae bad_put_user
30987 ASM_STAC
30988 -3: movl %eax,(%_ASM_CX)
30989 +
30990 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30991 + mov pax_user_shadow_base,%_ASM_BX
30992 + cmp %_ASM_BX,%_ASM_CX
30993 + jb 1234f
30994 + xor %ebx,%ebx
30995 +1234:
30996 +#endif
30997 +
30998 +#endif
30999 +
31000 +3: __copyuser_seg movl %eax,(_DEST)
31001 xor %eax,%eax
31002 EXIT
31003 ENDPROC(__put_user_4)
31004
31005 ENTRY(__put_user_8)
31006 ENTER
31007 +
31008 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31009 + GET_THREAD_INFO(%_ASM_BX)
31010 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31011 sub $7,%_ASM_BX
31012 cmp %_ASM_BX,%_ASM_CX
31013 jae bad_put_user
31014 ASM_STAC
31015 -4: mov %_ASM_AX,(%_ASM_CX)
31016 +
31017 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31018 + mov pax_user_shadow_base,%_ASM_BX
31019 + cmp %_ASM_BX,%_ASM_CX
31020 + jb 1234f
31021 + xor %ebx,%ebx
31022 +1234:
31023 +#endif
31024 +
31025 +#endif
31026 +
31027 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
31028 #ifdef CONFIG_X86_32
31029 -5: movl %edx,4(%_ASM_CX)
31030 +5: __copyuser_seg movl %edx,4(_DEST)
31031 #endif
31032 xor %eax,%eax
31033 EXIT
31034 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
31035 index 1cad221..de671ee 100644
31036 --- a/arch/x86/lib/rwlock.S
31037 +++ b/arch/x86/lib/rwlock.S
31038 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
31039 FRAME
31040 0: LOCK_PREFIX
31041 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31042 +
31043 +#ifdef CONFIG_PAX_REFCOUNT
31044 + jno 1234f
31045 + LOCK_PREFIX
31046 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31047 + int $4
31048 +1234:
31049 + _ASM_EXTABLE(1234b, 1234b)
31050 +#endif
31051 +
31052 1: rep; nop
31053 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
31054 jne 1b
31055 LOCK_PREFIX
31056 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31057 +
31058 +#ifdef CONFIG_PAX_REFCOUNT
31059 + jno 1234f
31060 + LOCK_PREFIX
31061 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31062 + int $4
31063 +1234:
31064 + _ASM_EXTABLE(1234b, 1234b)
31065 +#endif
31066 +
31067 jnz 0b
31068 ENDFRAME
31069 + pax_force_retaddr
31070 ret
31071 CFI_ENDPROC
31072 END(__write_lock_failed)
31073 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
31074 FRAME
31075 0: LOCK_PREFIX
31076 READ_LOCK_SIZE(inc) (%__lock_ptr)
31077 +
31078 +#ifdef CONFIG_PAX_REFCOUNT
31079 + jno 1234f
31080 + LOCK_PREFIX
31081 + READ_LOCK_SIZE(dec) (%__lock_ptr)
31082 + int $4
31083 +1234:
31084 + _ASM_EXTABLE(1234b, 1234b)
31085 +#endif
31086 +
31087 1: rep; nop
31088 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
31089 js 1b
31090 LOCK_PREFIX
31091 READ_LOCK_SIZE(dec) (%__lock_ptr)
31092 +
31093 +#ifdef CONFIG_PAX_REFCOUNT
31094 + jno 1234f
31095 + LOCK_PREFIX
31096 + READ_LOCK_SIZE(inc) (%__lock_ptr)
31097 + int $4
31098 +1234:
31099 + _ASM_EXTABLE(1234b, 1234b)
31100 +#endif
31101 +
31102 js 0b
31103 ENDFRAME
31104 + pax_force_retaddr
31105 ret
31106 CFI_ENDPROC
31107 END(__read_lock_failed)
31108 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31109 index 5dff5f0..cadebf4 100644
31110 --- a/arch/x86/lib/rwsem.S
31111 +++ b/arch/x86/lib/rwsem.S
31112 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31113 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31114 CFI_RESTORE __ASM_REG(dx)
31115 restore_common_regs
31116 + pax_force_retaddr
31117 ret
31118 CFI_ENDPROC
31119 ENDPROC(call_rwsem_down_read_failed)
31120 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31121 movq %rax,%rdi
31122 call rwsem_down_write_failed
31123 restore_common_regs
31124 + pax_force_retaddr
31125 ret
31126 CFI_ENDPROC
31127 ENDPROC(call_rwsem_down_write_failed)
31128 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31129 movq %rax,%rdi
31130 call rwsem_wake
31131 restore_common_regs
31132 -1: ret
31133 +1: pax_force_retaddr
31134 + ret
31135 CFI_ENDPROC
31136 ENDPROC(call_rwsem_wake)
31137
31138 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31139 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31140 CFI_RESTORE __ASM_REG(dx)
31141 restore_common_regs
31142 + pax_force_retaddr
31143 ret
31144 CFI_ENDPROC
31145 ENDPROC(call_rwsem_downgrade_wake)
31146 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31147 index 92d9fea..b2762c8 100644
31148 --- a/arch/x86/lib/thunk_64.S
31149 +++ b/arch/x86/lib/thunk_64.S
31150 @@ -9,6 +9,7 @@
31151 #include <asm/dwarf2.h>
31152 #include <asm/calling.h>
31153 #include <asm/asm.h>
31154 +#include <asm/alternative-asm.h>
31155
31156 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31157 .macro THUNK name, func, put_ret_addr_in_rdi=0
31158 @@ -16,11 +17,11 @@
31159 \name:
31160 CFI_STARTPROC
31161
31162 - /* this one pushes 9 elems, the next one would be %rIP */
31163 - SAVE_ARGS
31164 + /* this one pushes 15+1 elems, the next one would be %rIP */
31165 + SAVE_ARGS 8
31166
31167 .if \put_ret_addr_in_rdi
31168 - movq_cfi_restore 9*8, rdi
31169 + movq_cfi_restore RIP, rdi
31170 .endif
31171
31172 call \func
31173 @@ -40,9 +41,10 @@
31174
31175 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31176 CFI_STARTPROC
31177 - SAVE_ARGS
31178 + SAVE_ARGS 8
31179 restore:
31180 - RESTORE_ARGS
31181 + RESTORE_ARGS 1,8
31182 + pax_force_retaddr
31183 ret
31184 CFI_ENDPROC
31185 _ASM_NOKPROBE(restore)
31186 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31187 index e2f5e21..4b22130 100644
31188 --- a/arch/x86/lib/usercopy_32.c
31189 +++ b/arch/x86/lib/usercopy_32.c
31190 @@ -42,11 +42,13 @@ do { \
31191 int __d0; \
31192 might_fault(); \
31193 __asm__ __volatile__( \
31194 + __COPYUSER_SET_ES \
31195 ASM_STAC "\n" \
31196 "0: rep; stosl\n" \
31197 " movl %2,%0\n" \
31198 "1: rep; stosb\n" \
31199 "2: " ASM_CLAC "\n" \
31200 + __COPYUSER_RESTORE_ES \
31201 ".section .fixup,\"ax\"\n" \
31202 "3: lea 0(%2,%0,4),%0\n" \
31203 " jmp 2b\n" \
31204 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31205
31206 #ifdef CONFIG_X86_INTEL_USERCOPY
31207 static unsigned long
31208 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
31209 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31210 {
31211 int d0, d1;
31212 __asm__ __volatile__(
31213 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31214 " .align 2,0x90\n"
31215 "3: movl 0(%4), %%eax\n"
31216 "4: movl 4(%4), %%edx\n"
31217 - "5: movl %%eax, 0(%3)\n"
31218 - "6: movl %%edx, 4(%3)\n"
31219 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31220 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31221 "7: movl 8(%4), %%eax\n"
31222 "8: movl 12(%4),%%edx\n"
31223 - "9: movl %%eax, 8(%3)\n"
31224 - "10: movl %%edx, 12(%3)\n"
31225 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31226 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31227 "11: movl 16(%4), %%eax\n"
31228 "12: movl 20(%4), %%edx\n"
31229 - "13: movl %%eax, 16(%3)\n"
31230 - "14: movl %%edx, 20(%3)\n"
31231 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31232 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31233 "15: movl 24(%4), %%eax\n"
31234 "16: movl 28(%4), %%edx\n"
31235 - "17: movl %%eax, 24(%3)\n"
31236 - "18: movl %%edx, 28(%3)\n"
31237 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31238 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31239 "19: movl 32(%4), %%eax\n"
31240 "20: movl 36(%4), %%edx\n"
31241 - "21: movl %%eax, 32(%3)\n"
31242 - "22: movl %%edx, 36(%3)\n"
31243 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31244 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31245 "23: movl 40(%4), %%eax\n"
31246 "24: movl 44(%4), %%edx\n"
31247 - "25: movl %%eax, 40(%3)\n"
31248 - "26: movl %%edx, 44(%3)\n"
31249 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31250 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31251 "27: movl 48(%4), %%eax\n"
31252 "28: movl 52(%4), %%edx\n"
31253 - "29: movl %%eax, 48(%3)\n"
31254 - "30: movl %%edx, 52(%3)\n"
31255 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31256 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31257 "31: movl 56(%4), %%eax\n"
31258 "32: movl 60(%4), %%edx\n"
31259 - "33: movl %%eax, 56(%3)\n"
31260 - "34: movl %%edx, 60(%3)\n"
31261 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31262 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31263 " addl $-64, %0\n"
31264 " addl $64, %4\n"
31265 " addl $64, %3\n"
31266 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31267 " shrl $2, %0\n"
31268 " andl $3, %%eax\n"
31269 " cld\n"
31270 + __COPYUSER_SET_ES
31271 "99: rep; movsl\n"
31272 "36: movl %%eax, %0\n"
31273 "37: rep; movsb\n"
31274 "100:\n"
31275 + __COPYUSER_RESTORE_ES
31276 + ".section .fixup,\"ax\"\n"
31277 + "101: lea 0(%%eax,%0,4),%0\n"
31278 + " jmp 100b\n"
31279 + ".previous\n"
31280 + _ASM_EXTABLE(1b,100b)
31281 + _ASM_EXTABLE(2b,100b)
31282 + _ASM_EXTABLE(3b,100b)
31283 + _ASM_EXTABLE(4b,100b)
31284 + _ASM_EXTABLE(5b,100b)
31285 + _ASM_EXTABLE(6b,100b)
31286 + _ASM_EXTABLE(7b,100b)
31287 + _ASM_EXTABLE(8b,100b)
31288 + _ASM_EXTABLE(9b,100b)
31289 + _ASM_EXTABLE(10b,100b)
31290 + _ASM_EXTABLE(11b,100b)
31291 + _ASM_EXTABLE(12b,100b)
31292 + _ASM_EXTABLE(13b,100b)
31293 + _ASM_EXTABLE(14b,100b)
31294 + _ASM_EXTABLE(15b,100b)
31295 + _ASM_EXTABLE(16b,100b)
31296 + _ASM_EXTABLE(17b,100b)
31297 + _ASM_EXTABLE(18b,100b)
31298 + _ASM_EXTABLE(19b,100b)
31299 + _ASM_EXTABLE(20b,100b)
31300 + _ASM_EXTABLE(21b,100b)
31301 + _ASM_EXTABLE(22b,100b)
31302 + _ASM_EXTABLE(23b,100b)
31303 + _ASM_EXTABLE(24b,100b)
31304 + _ASM_EXTABLE(25b,100b)
31305 + _ASM_EXTABLE(26b,100b)
31306 + _ASM_EXTABLE(27b,100b)
31307 + _ASM_EXTABLE(28b,100b)
31308 + _ASM_EXTABLE(29b,100b)
31309 + _ASM_EXTABLE(30b,100b)
31310 + _ASM_EXTABLE(31b,100b)
31311 + _ASM_EXTABLE(32b,100b)
31312 + _ASM_EXTABLE(33b,100b)
31313 + _ASM_EXTABLE(34b,100b)
31314 + _ASM_EXTABLE(35b,100b)
31315 + _ASM_EXTABLE(36b,100b)
31316 + _ASM_EXTABLE(37b,100b)
31317 + _ASM_EXTABLE(99b,101b)
31318 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31319 + : "1"(to), "2"(from), "0"(size)
31320 + : "eax", "edx", "memory");
31321 + return size;
31322 +}
31323 +
31324 +static unsigned long
31325 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31326 +{
31327 + int d0, d1;
31328 + __asm__ __volatile__(
31329 + " .align 2,0x90\n"
31330 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31331 + " cmpl $67, %0\n"
31332 + " jbe 3f\n"
31333 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31334 + " .align 2,0x90\n"
31335 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31336 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31337 + "5: movl %%eax, 0(%3)\n"
31338 + "6: movl %%edx, 4(%3)\n"
31339 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31340 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31341 + "9: movl %%eax, 8(%3)\n"
31342 + "10: movl %%edx, 12(%3)\n"
31343 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31344 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31345 + "13: movl %%eax, 16(%3)\n"
31346 + "14: movl %%edx, 20(%3)\n"
31347 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31348 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31349 + "17: movl %%eax, 24(%3)\n"
31350 + "18: movl %%edx, 28(%3)\n"
31351 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31352 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31353 + "21: movl %%eax, 32(%3)\n"
31354 + "22: movl %%edx, 36(%3)\n"
31355 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31356 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31357 + "25: movl %%eax, 40(%3)\n"
31358 + "26: movl %%edx, 44(%3)\n"
31359 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31360 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31361 + "29: movl %%eax, 48(%3)\n"
31362 + "30: movl %%edx, 52(%3)\n"
31363 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31364 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31365 + "33: movl %%eax, 56(%3)\n"
31366 + "34: movl %%edx, 60(%3)\n"
31367 + " addl $-64, %0\n"
31368 + " addl $64, %4\n"
31369 + " addl $64, %3\n"
31370 + " cmpl $63, %0\n"
31371 + " ja 1b\n"
31372 + "35: movl %0, %%eax\n"
31373 + " shrl $2, %0\n"
31374 + " andl $3, %%eax\n"
31375 + " cld\n"
31376 + "99: rep; "__copyuser_seg" movsl\n"
31377 + "36: movl %%eax, %0\n"
31378 + "37: rep; "__copyuser_seg" movsb\n"
31379 + "100:\n"
31380 ".section .fixup,\"ax\"\n"
31381 "101: lea 0(%%eax,%0,4),%0\n"
31382 " jmp 100b\n"
31383 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31384 int d0, d1;
31385 __asm__ __volatile__(
31386 " .align 2,0x90\n"
31387 - "0: movl 32(%4), %%eax\n"
31388 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31389 " cmpl $67, %0\n"
31390 " jbe 2f\n"
31391 - "1: movl 64(%4), %%eax\n"
31392 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31393 " .align 2,0x90\n"
31394 - "2: movl 0(%4), %%eax\n"
31395 - "21: movl 4(%4), %%edx\n"
31396 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31397 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31398 " movl %%eax, 0(%3)\n"
31399 " movl %%edx, 4(%3)\n"
31400 - "3: movl 8(%4), %%eax\n"
31401 - "31: movl 12(%4),%%edx\n"
31402 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31403 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31404 " movl %%eax, 8(%3)\n"
31405 " movl %%edx, 12(%3)\n"
31406 - "4: movl 16(%4), %%eax\n"
31407 - "41: movl 20(%4), %%edx\n"
31408 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31409 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31410 " movl %%eax, 16(%3)\n"
31411 " movl %%edx, 20(%3)\n"
31412 - "10: movl 24(%4), %%eax\n"
31413 - "51: movl 28(%4), %%edx\n"
31414 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31415 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31416 " movl %%eax, 24(%3)\n"
31417 " movl %%edx, 28(%3)\n"
31418 - "11: movl 32(%4), %%eax\n"
31419 - "61: movl 36(%4), %%edx\n"
31420 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31421 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31422 " movl %%eax, 32(%3)\n"
31423 " movl %%edx, 36(%3)\n"
31424 - "12: movl 40(%4), %%eax\n"
31425 - "71: movl 44(%4), %%edx\n"
31426 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31427 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31428 " movl %%eax, 40(%3)\n"
31429 " movl %%edx, 44(%3)\n"
31430 - "13: movl 48(%4), %%eax\n"
31431 - "81: movl 52(%4), %%edx\n"
31432 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31433 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31434 " movl %%eax, 48(%3)\n"
31435 " movl %%edx, 52(%3)\n"
31436 - "14: movl 56(%4), %%eax\n"
31437 - "91: movl 60(%4), %%edx\n"
31438 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31439 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31440 " movl %%eax, 56(%3)\n"
31441 " movl %%edx, 60(%3)\n"
31442 " addl $-64, %0\n"
31443 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31444 " shrl $2, %0\n"
31445 " andl $3, %%eax\n"
31446 " cld\n"
31447 - "6: rep; movsl\n"
31448 + "6: rep; "__copyuser_seg" movsl\n"
31449 " movl %%eax,%0\n"
31450 - "7: rep; movsb\n"
31451 + "7: rep; "__copyuser_seg" movsb\n"
31452 "8:\n"
31453 ".section .fixup,\"ax\"\n"
31454 "9: lea 0(%%eax,%0,4),%0\n"
31455 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31456
31457 __asm__ __volatile__(
31458 " .align 2,0x90\n"
31459 - "0: movl 32(%4), %%eax\n"
31460 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31461 " cmpl $67, %0\n"
31462 " jbe 2f\n"
31463 - "1: movl 64(%4), %%eax\n"
31464 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31465 " .align 2,0x90\n"
31466 - "2: movl 0(%4), %%eax\n"
31467 - "21: movl 4(%4), %%edx\n"
31468 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31469 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31470 " movnti %%eax, 0(%3)\n"
31471 " movnti %%edx, 4(%3)\n"
31472 - "3: movl 8(%4), %%eax\n"
31473 - "31: movl 12(%4),%%edx\n"
31474 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31475 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31476 " movnti %%eax, 8(%3)\n"
31477 " movnti %%edx, 12(%3)\n"
31478 - "4: movl 16(%4), %%eax\n"
31479 - "41: movl 20(%4), %%edx\n"
31480 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31481 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31482 " movnti %%eax, 16(%3)\n"
31483 " movnti %%edx, 20(%3)\n"
31484 - "10: movl 24(%4), %%eax\n"
31485 - "51: movl 28(%4), %%edx\n"
31486 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31487 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31488 " movnti %%eax, 24(%3)\n"
31489 " movnti %%edx, 28(%3)\n"
31490 - "11: movl 32(%4), %%eax\n"
31491 - "61: movl 36(%4), %%edx\n"
31492 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31493 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31494 " movnti %%eax, 32(%3)\n"
31495 " movnti %%edx, 36(%3)\n"
31496 - "12: movl 40(%4), %%eax\n"
31497 - "71: movl 44(%4), %%edx\n"
31498 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31499 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31500 " movnti %%eax, 40(%3)\n"
31501 " movnti %%edx, 44(%3)\n"
31502 - "13: movl 48(%4), %%eax\n"
31503 - "81: movl 52(%4), %%edx\n"
31504 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31505 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31506 " movnti %%eax, 48(%3)\n"
31507 " movnti %%edx, 52(%3)\n"
31508 - "14: movl 56(%4), %%eax\n"
31509 - "91: movl 60(%4), %%edx\n"
31510 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31511 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31512 " movnti %%eax, 56(%3)\n"
31513 " movnti %%edx, 60(%3)\n"
31514 " addl $-64, %0\n"
31515 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31516 " shrl $2, %0\n"
31517 " andl $3, %%eax\n"
31518 " cld\n"
31519 - "6: rep; movsl\n"
31520 + "6: rep; "__copyuser_seg" movsl\n"
31521 " movl %%eax,%0\n"
31522 - "7: rep; movsb\n"
31523 + "7: rep; "__copyuser_seg" movsb\n"
31524 "8:\n"
31525 ".section .fixup,\"ax\"\n"
31526 "9: lea 0(%%eax,%0,4),%0\n"
31527 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31528
31529 __asm__ __volatile__(
31530 " .align 2,0x90\n"
31531 - "0: movl 32(%4), %%eax\n"
31532 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31533 " cmpl $67, %0\n"
31534 " jbe 2f\n"
31535 - "1: movl 64(%4), %%eax\n"
31536 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31537 " .align 2,0x90\n"
31538 - "2: movl 0(%4), %%eax\n"
31539 - "21: movl 4(%4), %%edx\n"
31540 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31541 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31542 " movnti %%eax, 0(%3)\n"
31543 " movnti %%edx, 4(%3)\n"
31544 - "3: movl 8(%4), %%eax\n"
31545 - "31: movl 12(%4),%%edx\n"
31546 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31547 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31548 " movnti %%eax, 8(%3)\n"
31549 " movnti %%edx, 12(%3)\n"
31550 - "4: movl 16(%4), %%eax\n"
31551 - "41: movl 20(%4), %%edx\n"
31552 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31553 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31554 " movnti %%eax, 16(%3)\n"
31555 " movnti %%edx, 20(%3)\n"
31556 - "10: movl 24(%4), %%eax\n"
31557 - "51: movl 28(%4), %%edx\n"
31558 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31559 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31560 " movnti %%eax, 24(%3)\n"
31561 " movnti %%edx, 28(%3)\n"
31562 - "11: movl 32(%4), %%eax\n"
31563 - "61: movl 36(%4), %%edx\n"
31564 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31565 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31566 " movnti %%eax, 32(%3)\n"
31567 " movnti %%edx, 36(%3)\n"
31568 - "12: movl 40(%4), %%eax\n"
31569 - "71: movl 44(%4), %%edx\n"
31570 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31571 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31572 " movnti %%eax, 40(%3)\n"
31573 " movnti %%edx, 44(%3)\n"
31574 - "13: movl 48(%4), %%eax\n"
31575 - "81: movl 52(%4), %%edx\n"
31576 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31577 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31578 " movnti %%eax, 48(%3)\n"
31579 " movnti %%edx, 52(%3)\n"
31580 - "14: movl 56(%4), %%eax\n"
31581 - "91: movl 60(%4), %%edx\n"
31582 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31583 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31584 " movnti %%eax, 56(%3)\n"
31585 " movnti %%edx, 60(%3)\n"
31586 " addl $-64, %0\n"
31587 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31588 " shrl $2, %0\n"
31589 " andl $3, %%eax\n"
31590 " cld\n"
31591 - "6: rep; movsl\n"
31592 + "6: rep; "__copyuser_seg" movsl\n"
31593 " movl %%eax,%0\n"
31594 - "7: rep; movsb\n"
31595 + "7: rep; "__copyuser_seg" movsb\n"
31596 "8:\n"
31597 ".section .fixup,\"ax\"\n"
31598 "9: lea 0(%%eax,%0,4),%0\n"
31599 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31600 */
31601 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31602 unsigned long size);
31603 -unsigned long __copy_user_intel(void __user *to, const void *from,
31604 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31605 + unsigned long size);
31606 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31607 unsigned long size);
31608 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31609 const void __user *from, unsigned long size);
31610 #endif /* CONFIG_X86_INTEL_USERCOPY */
31611
31612 /* Generic arbitrary sized copy. */
31613 -#define __copy_user(to, from, size) \
31614 +#define __copy_user(to, from, size, prefix, set, restore) \
31615 do { \
31616 int __d0, __d1, __d2; \
31617 __asm__ __volatile__( \
31618 + set \
31619 " cmp $7,%0\n" \
31620 " jbe 1f\n" \
31621 " movl %1,%0\n" \
31622 " negl %0\n" \
31623 " andl $7,%0\n" \
31624 " subl %0,%3\n" \
31625 - "4: rep; movsb\n" \
31626 + "4: rep; "prefix"movsb\n" \
31627 " movl %3,%0\n" \
31628 " shrl $2,%0\n" \
31629 " andl $3,%3\n" \
31630 " .align 2,0x90\n" \
31631 - "0: rep; movsl\n" \
31632 + "0: rep; "prefix"movsl\n" \
31633 " movl %3,%0\n" \
31634 - "1: rep; movsb\n" \
31635 + "1: rep; "prefix"movsb\n" \
31636 "2:\n" \
31637 + restore \
31638 ".section .fixup,\"ax\"\n" \
31639 "5: addl %3,%0\n" \
31640 " jmp 2b\n" \
31641 @@ -538,14 +650,14 @@ do { \
31642 " negl %0\n" \
31643 " andl $7,%0\n" \
31644 " subl %0,%3\n" \
31645 - "4: rep; movsb\n" \
31646 + "4: rep; "__copyuser_seg"movsb\n" \
31647 " movl %3,%0\n" \
31648 " shrl $2,%0\n" \
31649 " andl $3,%3\n" \
31650 " .align 2,0x90\n" \
31651 - "0: rep; movsl\n" \
31652 + "0: rep; "__copyuser_seg"movsl\n" \
31653 " movl %3,%0\n" \
31654 - "1: rep; movsb\n" \
31655 + "1: rep; "__copyuser_seg"movsb\n" \
31656 "2:\n" \
31657 ".section .fixup,\"ax\"\n" \
31658 "5: addl %3,%0\n" \
31659 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31660 {
31661 stac();
31662 if (movsl_is_ok(to, from, n))
31663 - __copy_user(to, from, n);
31664 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31665 else
31666 - n = __copy_user_intel(to, from, n);
31667 + n = __generic_copy_to_user_intel(to, from, n);
31668 clac();
31669 return n;
31670 }
31671 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31672 {
31673 stac();
31674 if (movsl_is_ok(to, from, n))
31675 - __copy_user(to, from, n);
31676 + __copy_user(to, from, n, __copyuser_seg, "", "");
31677 else
31678 - n = __copy_user_intel((void __user *)to,
31679 - (const void *)from, n);
31680 + n = __generic_copy_from_user_intel(to, from, n);
31681 clac();
31682 return n;
31683 }
31684 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31685 if (n > 64 && cpu_has_xmm2)
31686 n = __copy_user_intel_nocache(to, from, n);
31687 else
31688 - __copy_user(to, from, n);
31689 + __copy_user(to, from, n, __copyuser_seg, "", "");
31690 #else
31691 - __copy_user(to, from, n);
31692 + __copy_user(to, from, n, __copyuser_seg, "", "");
31693 #endif
31694 clac();
31695 return n;
31696 }
31697 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31698
31699 -/**
31700 - * copy_to_user: - Copy a block of data into user space.
31701 - * @to: Destination address, in user space.
31702 - * @from: Source address, in kernel space.
31703 - * @n: Number of bytes to copy.
31704 - *
31705 - * Context: User context only. This function may sleep.
31706 - *
31707 - * Copy data from kernel space to user space.
31708 - *
31709 - * Returns number of bytes that could not be copied.
31710 - * On success, this will be zero.
31711 - */
31712 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31713 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31714 +void __set_fs(mm_segment_t x)
31715 {
31716 - if (access_ok(VERIFY_WRITE, to, n))
31717 - n = __copy_to_user(to, from, n);
31718 - return n;
31719 + switch (x.seg) {
31720 + case 0:
31721 + loadsegment(gs, 0);
31722 + break;
31723 + case TASK_SIZE_MAX:
31724 + loadsegment(gs, __USER_DS);
31725 + break;
31726 + case -1UL:
31727 + loadsegment(gs, __KERNEL_DS);
31728 + break;
31729 + default:
31730 + BUG();
31731 + }
31732 }
31733 -EXPORT_SYMBOL(_copy_to_user);
31734 +EXPORT_SYMBOL(__set_fs);
31735
31736 -/**
31737 - * copy_from_user: - Copy a block of data from user space.
31738 - * @to: Destination address, in kernel space.
31739 - * @from: Source address, in user space.
31740 - * @n: Number of bytes to copy.
31741 - *
31742 - * Context: User context only. This function may sleep.
31743 - *
31744 - * Copy data from user space to kernel space.
31745 - *
31746 - * Returns number of bytes that could not be copied.
31747 - * On success, this will be zero.
31748 - *
31749 - * If some data could not be copied, this function will pad the copied
31750 - * data to the requested size using zero bytes.
31751 - */
31752 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31753 +void set_fs(mm_segment_t x)
31754 {
31755 - if (access_ok(VERIFY_READ, from, n))
31756 - n = __copy_from_user(to, from, n);
31757 - else
31758 - memset(to, 0, n);
31759 - return n;
31760 + current_thread_info()->addr_limit = x;
31761 + __set_fs(x);
31762 }
31763 -EXPORT_SYMBOL(_copy_from_user);
31764 +EXPORT_SYMBOL(set_fs);
31765 +#endif
31766 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31767 index c905e89..01ab928 100644
31768 --- a/arch/x86/lib/usercopy_64.c
31769 +++ b/arch/x86/lib/usercopy_64.c
31770 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31771 might_fault();
31772 /* no memory constraint because it doesn't change any memory gcc knows
31773 about */
31774 + pax_open_userland();
31775 stac();
31776 asm volatile(
31777 " testq %[size8],%[size8]\n"
31778 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31779 _ASM_EXTABLE(0b,3b)
31780 _ASM_EXTABLE(1b,2b)
31781 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31782 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31783 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31784 [zero] "r" (0UL), [eight] "r" (8UL));
31785 clac();
31786 + pax_close_userland();
31787 return size;
31788 }
31789 EXPORT_SYMBOL(__clear_user);
31790 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31791 }
31792 EXPORT_SYMBOL(clear_user);
31793
31794 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31795 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31796 {
31797 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31798 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31799 - }
31800 - return len;
31801 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31802 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31803 + return len;
31804 }
31805 EXPORT_SYMBOL(copy_in_user);
31806
31807 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31808 * it is not necessary to optimize tail handling.
31809 */
31810 __visible unsigned long
31811 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31812 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31813 {
31814 char c;
31815 unsigned zero_len;
31816
31817 + clac();
31818 + pax_close_userland();
31819 for (; len; --len, to++) {
31820 if (__get_user_nocheck(c, from++, sizeof(char)))
31821 break;
31822 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31823 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31824 if (__put_user_nocheck(c, to++, sizeof(char)))
31825 break;
31826 - clac();
31827 return len;
31828 }
31829 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31830 index 6a19ad9..1c48f9a 100644
31831 --- a/arch/x86/mm/Makefile
31832 +++ b/arch/x86/mm/Makefile
31833 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31834 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31835
31836 obj-$(CONFIG_MEMTEST) += memtest.o
31837 +
31838 +quote:="
31839 +obj-$(CONFIG_X86_64) += uderef_64.o
31840 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31841 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31842 index 903ec1e..c4166b2 100644
31843 --- a/arch/x86/mm/extable.c
31844 +++ b/arch/x86/mm/extable.c
31845 @@ -6,12 +6,24 @@
31846 static inline unsigned long
31847 ex_insn_addr(const struct exception_table_entry *x)
31848 {
31849 - return (unsigned long)&x->insn + x->insn;
31850 + unsigned long reloc = 0;
31851 +
31852 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31853 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31854 +#endif
31855 +
31856 + return (unsigned long)&x->insn + x->insn + reloc;
31857 }
31858 static inline unsigned long
31859 ex_fixup_addr(const struct exception_table_entry *x)
31860 {
31861 - return (unsigned long)&x->fixup + x->fixup;
31862 + unsigned long reloc = 0;
31863 +
31864 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31865 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31866 +#endif
31867 +
31868 + return (unsigned long)&x->fixup + x->fixup + reloc;
31869 }
31870
31871 int fixup_exception(struct pt_regs *regs)
31872 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31873 unsigned long new_ip;
31874
31875 #ifdef CONFIG_PNPBIOS
31876 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31877 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31878 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31879 extern u32 pnp_bios_is_utter_crap;
31880 pnp_bios_is_utter_crap = 1;
31881 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31882 i += 4;
31883 p->fixup -= i;
31884 i += 4;
31885 +
31886 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31887 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31888 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31889 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31890 +#endif
31891 +
31892 }
31893 }
31894
31895 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31896 index 3664279..c6a7830 100644
31897 --- a/arch/x86/mm/fault.c
31898 +++ b/arch/x86/mm/fault.c
31899 @@ -14,12 +14,19 @@
31900 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31901 #include <linux/prefetch.h> /* prefetchw */
31902 #include <linux/context_tracking.h> /* exception_enter(), ... */
31903 +#include <linux/unistd.h>
31904 +#include <linux/compiler.h>
31905
31906 #include <asm/traps.h> /* dotraplinkage, ... */
31907 #include <asm/pgalloc.h> /* pgd_*(), ... */
31908 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31909 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31910 #include <asm/vsyscall.h> /* emulate_vsyscall */
31911 +#include <asm/tlbflush.h>
31912 +
31913 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31914 +#include <asm/stacktrace.h>
31915 +#endif
31916
31917 #define CREATE_TRACE_POINTS
31918 #include <asm/trace/exceptions.h>
31919 @@ -60,7 +67,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31920 int ret = 0;
31921
31922 /* kprobe_running() needs smp_processor_id() */
31923 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31924 + if (kprobes_built_in() && !user_mode(regs)) {
31925 preempt_disable();
31926 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31927 ret = 1;
31928 @@ -121,7 +128,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31929 return !instr_lo || (instr_lo>>1) == 1;
31930 case 0x00:
31931 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31932 - if (probe_kernel_address(instr, opcode))
31933 + if (user_mode(regs)) {
31934 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31935 + return 0;
31936 + } else if (probe_kernel_address(instr, opcode))
31937 return 0;
31938
31939 *prefetch = (instr_lo == 0xF) &&
31940 @@ -155,7 +165,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31941 while (instr < max_instr) {
31942 unsigned char opcode;
31943
31944 - if (probe_kernel_address(instr, opcode))
31945 + if (user_mode(regs)) {
31946 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31947 + break;
31948 + } else if (probe_kernel_address(instr, opcode))
31949 break;
31950
31951 instr++;
31952 @@ -186,6 +199,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31953 force_sig_info(si_signo, &info, tsk);
31954 }
31955
31956 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31957 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31958 +#endif
31959 +
31960 +#ifdef CONFIG_PAX_EMUTRAMP
31961 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31962 +#endif
31963 +
31964 +#ifdef CONFIG_PAX_PAGEEXEC
31965 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31966 +{
31967 + pgd_t *pgd;
31968 + pud_t *pud;
31969 + pmd_t *pmd;
31970 +
31971 + pgd = pgd_offset(mm, address);
31972 + if (!pgd_present(*pgd))
31973 + return NULL;
31974 + pud = pud_offset(pgd, address);
31975 + if (!pud_present(*pud))
31976 + return NULL;
31977 + pmd = pmd_offset(pud, address);
31978 + if (!pmd_present(*pmd))
31979 + return NULL;
31980 + return pmd;
31981 +}
31982 +#endif
31983 +
31984 DEFINE_SPINLOCK(pgd_lock);
31985 LIST_HEAD(pgd_list);
31986
31987 @@ -236,10 +277,27 @@ void vmalloc_sync_all(void)
31988 for (address = VMALLOC_START & PMD_MASK;
31989 address >= TASK_SIZE && address < FIXADDR_TOP;
31990 address += PMD_SIZE) {
31991 +
31992 +#ifdef CONFIG_PAX_PER_CPU_PGD
31993 + unsigned long cpu;
31994 +#else
31995 struct page *page;
31996 +#endif
31997
31998 spin_lock(&pgd_lock);
31999 +
32000 +#ifdef CONFIG_PAX_PER_CPU_PGD
32001 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32002 + pgd_t *pgd = get_cpu_pgd(cpu, user);
32003 + pmd_t *ret;
32004 +
32005 + ret = vmalloc_sync_one(pgd, address);
32006 + if (!ret)
32007 + break;
32008 + pgd = get_cpu_pgd(cpu, kernel);
32009 +#else
32010 list_for_each_entry(page, &pgd_list, lru) {
32011 + pgd_t *pgd;
32012 spinlock_t *pgt_lock;
32013 pmd_t *ret;
32014
32015 @@ -247,8 +305,14 @@ void vmalloc_sync_all(void)
32016 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32017
32018 spin_lock(pgt_lock);
32019 - ret = vmalloc_sync_one(page_address(page), address);
32020 + pgd = page_address(page);
32021 +#endif
32022 +
32023 + ret = vmalloc_sync_one(pgd, address);
32024 +
32025 +#ifndef CONFIG_PAX_PER_CPU_PGD
32026 spin_unlock(pgt_lock);
32027 +#endif
32028
32029 if (!ret)
32030 break;
32031 @@ -282,6 +346,12 @@ static noinline int vmalloc_fault(unsigned long address)
32032 * an interrupt in the middle of a task switch..
32033 */
32034 pgd_paddr = read_cr3();
32035 +
32036 +#ifdef CONFIG_PAX_PER_CPU_PGD
32037 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
32038 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
32039 +#endif
32040 +
32041 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
32042 if (!pmd_k)
32043 return -1;
32044 @@ -378,11 +448,25 @@ static noinline int vmalloc_fault(unsigned long address)
32045 * happen within a race in page table update. In the later
32046 * case just flush:
32047 */
32048 - pgd = pgd_offset(current->active_mm, address);
32049 +
32050 pgd_ref = pgd_offset_k(address);
32051 if (pgd_none(*pgd_ref))
32052 return -1;
32053
32054 +#ifdef CONFIG_PAX_PER_CPU_PGD
32055 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
32056 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
32057 + if (pgd_none(*pgd)) {
32058 + set_pgd(pgd, *pgd_ref);
32059 + arch_flush_lazy_mmu_mode();
32060 + } else {
32061 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
32062 + }
32063 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
32064 +#else
32065 + pgd = pgd_offset(current->active_mm, address);
32066 +#endif
32067 +
32068 if (pgd_none(*pgd)) {
32069 set_pgd(pgd, *pgd_ref);
32070 arch_flush_lazy_mmu_mode();
32071 @@ -549,7 +633,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
32072 static int is_errata100(struct pt_regs *regs, unsigned long address)
32073 {
32074 #ifdef CONFIG_X86_64
32075 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32076 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32077 return 1;
32078 #endif
32079 return 0;
32080 @@ -576,7 +660,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32081 }
32082
32083 static const char nx_warning[] = KERN_CRIT
32084 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32085 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32086
32087 static void
32088 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32089 @@ -585,7 +669,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32090 if (!oops_may_print())
32091 return;
32092
32093 - if (error_code & PF_INSTR) {
32094 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32095 unsigned int level;
32096 pgd_t *pgd;
32097 pte_t *pte;
32098 @@ -596,9 +680,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32099 pte = lookup_address_in_pgd(pgd, address, &level);
32100
32101 if (pte && pte_present(*pte) && !pte_exec(*pte))
32102 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32103 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32104 }
32105
32106 +#ifdef CONFIG_PAX_KERNEXEC
32107 + if (init_mm.start_code <= address && address < init_mm.end_code) {
32108 + if (current->signal->curr_ip)
32109 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32110 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
32111 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32112 + else
32113 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32114 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32115 + }
32116 +#endif
32117 +
32118 printk(KERN_ALERT "BUG: unable to handle kernel ");
32119 if (address < PAGE_SIZE)
32120 printk(KERN_CONT "NULL pointer dereference");
32121 @@ -779,6 +875,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32122 return;
32123 }
32124 #endif
32125 +
32126 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32127 + if (pax_is_fetch_fault(regs, error_code, address)) {
32128 +
32129 +#ifdef CONFIG_PAX_EMUTRAMP
32130 + switch (pax_handle_fetch_fault(regs)) {
32131 + case 2:
32132 + return;
32133 + }
32134 +#endif
32135 +
32136 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32137 + do_group_exit(SIGKILL);
32138 + }
32139 +#endif
32140 +
32141 /* Kernel addresses are always protection faults: */
32142 if (address >= TASK_SIZE)
32143 error_code |= PF_PROT;
32144 @@ -864,7 +976,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32145 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32146 printk(KERN_ERR
32147 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32148 - tsk->comm, tsk->pid, address);
32149 + tsk->comm, task_pid_nr(tsk), address);
32150 code = BUS_MCEERR_AR;
32151 }
32152 #endif
32153 @@ -918,6 +1030,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32154 return 1;
32155 }
32156
32157 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32158 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32159 +{
32160 + pte_t *pte;
32161 + pmd_t *pmd;
32162 + spinlock_t *ptl;
32163 + unsigned char pte_mask;
32164 +
32165 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32166 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32167 + return 0;
32168 +
32169 + /* PaX: it's our fault, let's handle it if we can */
32170 +
32171 + /* PaX: take a look at read faults before acquiring any locks */
32172 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32173 + /* instruction fetch attempt from a protected page in user mode */
32174 + up_read(&mm->mmap_sem);
32175 +
32176 +#ifdef CONFIG_PAX_EMUTRAMP
32177 + switch (pax_handle_fetch_fault(regs)) {
32178 + case 2:
32179 + return 1;
32180 + }
32181 +#endif
32182 +
32183 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32184 + do_group_exit(SIGKILL);
32185 + }
32186 +
32187 + pmd = pax_get_pmd(mm, address);
32188 + if (unlikely(!pmd))
32189 + return 0;
32190 +
32191 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32192 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32193 + pte_unmap_unlock(pte, ptl);
32194 + return 0;
32195 + }
32196 +
32197 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32198 + /* write attempt to a protected page in user mode */
32199 + pte_unmap_unlock(pte, ptl);
32200 + return 0;
32201 + }
32202 +
32203 +#ifdef CONFIG_SMP
32204 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32205 +#else
32206 + if (likely(address > get_limit(regs->cs)))
32207 +#endif
32208 + {
32209 + set_pte(pte, pte_mkread(*pte));
32210 + __flush_tlb_one(address);
32211 + pte_unmap_unlock(pte, ptl);
32212 + up_read(&mm->mmap_sem);
32213 + return 1;
32214 + }
32215 +
32216 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32217 +
32218 + /*
32219 + * PaX: fill DTLB with user rights and retry
32220 + */
32221 + __asm__ __volatile__ (
32222 + "orb %2,(%1)\n"
32223 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32224 +/*
32225 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32226 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32227 + * page fault when examined during a TLB load attempt. this is true not only
32228 + * for PTEs holding a non-present entry but also present entries that will
32229 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32230 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32231 + * for our target pages since their PTEs are simply not in the TLBs at all.
32232 +
32233 + * the best thing in omitting it is that we gain around 15-20% speed in the
32234 + * fast path of the page fault handler and can get rid of tracing since we
32235 + * can no longer flush unintended entries.
32236 + */
32237 + "invlpg (%0)\n"
32238 +#endif
32239 + __copyuser_seg"testb $0,(%0)\n"
32240 + "xorb %3,(%1)\n"
32241 + :
32242 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32243 + : "memory", "cc");
32244 + pte_unmap_unlock(pte, ptl);
32245 + up_read(&mm->mmap_sem);
32246 + return 1;
32247 +}
32248 +#endif
32249 +
32250 /*
32251 * Handle a spurious fault caused by a stale TLB entry.
32252 *
32253 @@ -985,6 +1190,9 @@ int show_unhandled_signals = 1;
32254 static inline int
32255 access_error(unsigned long error_code, struct vm_area_struct *vma)
32256 {
32257 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32258 + return 1;
32259 +
32260 if (error_code & PF_WRITE) {
32261 /* write, present and write, not present: */
32262 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32263 @@ -1019,7 +1227,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32264 if (error_code & PF_USER)
32265 return false;
32266
32267 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32268 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32269 return false;
32270
32271 return true;
32272 @@ -1047,6 +1255,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32273 tsk = current;
32274 mm = tsk->mm;
32275
32276 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32277 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32278 + if (!search_exception_tables(regs->ip)) {
32279 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32280 + bad_area_nosemaphore(regs, error_code, address);
32281 + return;
32282 + }
32283 + if (address < pax_user_shadow_base) {
32284 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32285 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32286 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32287 + } else
32288 + address -= pax_user_shadow_base;
32289 + }
32290 +#endif
32291 +
32292 /*
32293 * Detect and handle instructions that would cause a page fault for
32294 * both a tracked kernel page and a userspace page.
32295 @@ -1124,7 +1348,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32296 * User-mode registers count as a user access even for any
32297 * potential system fault or CPU buglet:
32298 */
32299 - if (user_mode_vm(regs)) {
32300 + if (user_mode(regs)) {
32301 local_irq_enable();
32302 error_code |= PF_USER;
32303 flags |= FAULT_FLAG_USER;
32304 @@ -1171,6 +1395,11 @@ retry:
32305 might_sleep();
32306 }
32307
32308 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32309 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32310 + return;
32311 +#endif
32312 +
32313 vma = find_vma(mm, address);
32314 if (unlikely(!vma)) {
32315 bad_area(regs, error_code, address);
32316 @@ -1182,18 +1411,24 @@ retry:
32317 bad_area(regs, error_code, address);
32318 return;
32319 }
32320 - if (error_code & PF_USER) {
32321 - /*
32322 - * Accessing the stack below %sp is always a bug.
32323 - * The large cushion allows instructions like enter
32324 - * and pusha to work. ("enter $65535, $31" pushes
32325 - * 32 pointers and then decrements %sp by 65535.)
32326 - */
32327 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32328 - bad_area(regs, error_code, address);
32329 - return;
32330 - }
32331 + /*
32332 + * Accessing the stack below %sp is always a bug.
32333 + * The large cushion allows instructions like enter
32334 + * and pusha to work. ("enter $65535, $31" pushes
32335 + * 32 pointers and then decrements %sp by 65535.)
32336 + */
32337 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32338 + bad_area(regs, error_code, address);
32339 + return;
32340 }
32341 +
32342 +#ifdef CONFIG_PAX_SEGMEXEC
32343 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32344 + bad_area(regs, error_code, address);
32345 + return;
32346 + }
32347 +#endif
32348 +
32349 if (unlikely(expand_stack(vma, address))) {
32350 bad_area(regs, error_code, address);
32351 return;
32352 @@ -1309,3 +1544,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32353 }
32354 NOKPROBE_SYMBOL(trace_do_page_fault);
32355 #endif /* CONFIG_TRACING */
32356 +
32357 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32358 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32359 +{
32360 + struct mm_struct *mm = current->mm;
32361 + unsigned long ip = regs->ip;
32362 +
32363 + if (v8086_mode(regs))
32364 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32365 +
32366 +#ifdef CONFIG_PAX_PAGEEXEC
32367 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32368 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32369 + return true;
32370 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32371 + return true;
32372 + return false;
32373 + }
32374 +#endif
32375 +
32376 +#ifdef CONFIG_PAX_SEGMEXEC
32377 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32378 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32379 + return true;
32380 + return false;
32381 + }
32382 +#endif
32383 +
32384 + return false;
32385 +}
32386 +#endif
32387 +
32388 +#ifdef CONFIG_PAX_EMUTRAMP
32389 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32390 +{
32391 + int err;
32392 +
32393 + do { /* PaX: libffi trampoline emulation */
32394 + unsigned char mov, jmp;
32395 + unsigned int addr1, addr2;
32396 +
32397 +#ifdef CONFIG_X86_64
32398 + if ((regs->ip + 9) >> 32)
32399 + break;
32400 +#endif
32401 +
32402 + err = get_user(mov, (unsigned char __user *)regs->ip);
32403 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32404 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32405 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32406 +
32407 + if (err)
32408 + break;
32409 +
32410 + if (mov == 0xB8 && jmp == 0xE9) {
32411 + regs->ax = addr1;
32412 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32413 + return 2;
32414 + }
32415 + } while (0);
32416 +
32417 + do { /* PaX: gcc trampoline emulation #1 */
32418 + unsigned char mov1, mov2;
32419 + unsigned short jmp;
32420 + unsigned int addr1, addr2;
32421 +
32422 +#ifdef CONFIG_X86_64
32423 + if ((regs->ip + 11) >> 32)
32424 + break;
32425 +#endif
32426 +
32427 + err = get_user(mov1, (unsigned char __user *)regs->ip);
32428 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32429 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32430 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32431 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32432 +
32433 + if (err)
32434 + break;
32435 +
32436 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32437 + regs->cx = addr1;
32438 + regs->ax = addr2;
32439 + regs->ip = addr2;
32440 + return 2;
32441 + }
32442 + } while (0);
32443 +
32444 + do { /* PaX: gcc trampoline emulation #2 */
32445 + unsigned char mov, jmp;
32446 + unsigned int addr1, addr2;
32447 +
32448 +#ifdef CONFIG_X86_64
32449 + if ((regs->ip + 9) >> 32)
32450 + break;
32451 +#endif
32452 +
32453 + err = get_user(mov, (unsigned char __user *)regs->ip);
32454 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32455 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32456 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32457 +
32458 + if (err)
32459 + break;
32460 +
32461 + if (mov == 0xB9 && jmp == 0xE9) {
32462 + regs->cx = addr1;
32463 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32464 + return 2;
32465 + }
32466 + } while (0);
32467 +
32468 + return 1; /* PaX in action */
32469 +}
32470 +
32471 +#ifdef CONFIG_X86_64
32472 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32473 +{
32474 + int err;
32475 +
32476 + do { /* PaX: libffi trampoline emulation */
32477 + unsigned short mov1, mov2, jmp1;
32478 + unsigned char stcclc, jmp2;
32479 + unsigned long addr1, addr2;
32480 +
32481 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32482 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32483 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32484 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32485 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32486 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32487 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32488 +
32489 + if (err)
32490 + break;
32491 +
32492 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32493 + regs->r11 = addr1;
32494 + regs->r10 = addr2;
32495 + if (stcclc == 0xF8)
32496 + regs->flags &= ~X86_EFLAGS_CF;
32497 + else
32498 + regs->flags |= X86_EFLAGS_CF;
32499 + regs->ip = addr1;
32500 + return 2;
32501 + }
32502 + } while (0);
32503 +
32504 + do { /* PaX: gcc trampoline emulation #1 */
32505 + unsigned short mov1, mov2, jmp1;
32506 + unsigned char jmp2;
32507 + unsigned int addr1;
32508 + unsigned long addr2;
32509 +
32510 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32511 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32512 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32513 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32514 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32515 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32516 +
32517 + if (err)
32518 + break;
32519 +
32520 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32521 + regs->r11 = addr1;
32522 + regs->r10 = addr2;
32523 + regs->ip = addr1;
32524 + return 2;
32525 + }
32526 + } while (0);
32527 +
32528 + do { /* PaX: gcc trampoline emulation #2 */
32529 + unsigned short mov1, mov2, jmp1;
32530 + unsigned char jmp2;
32531 + unsigned long addr1, addr2;
32532 +
32533 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32534 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32535 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32536 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32537 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32538 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32539 +
32540 + if (err)
32541 + break;
32542 +
32543 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32544 + regs->r11 = addr1;
32545 + regs->r10 = addr2;
32546 + regs->ip = addr1;
32547 + return 2;
32548 + }
32549 + } while (0);
32550 +
32551 + return 1; /* PaX in action */
32552 +}
32553 +#endif
32554 +
32555 +/*
32556 + * PaX: decide what to do with offenders (regs->ip = fault address)
32557 + *
32558 + * returns 1 when task should be killed
32559 + * 2 when gcc trampoline was detected
32560 + */
32561 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32562 +{
32563 + if (v8086_mode(regs))
32564 + return 1;
32565 +
32566 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32567 + return 1;
32568 +
32569 +#ifdef CONFIG_X86_32
32570 + return pax_handle_fetch_fault_32(regs);
32571 +#else
32572 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32573 + return pax_handle_fetch_fault_32(regs);
32574 + else
32575 + return pax_handle_fetch_fault_64(regs);
32576 +#endif
32577 +}
32578 +#endif
32579 +
32580 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32581 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32582 +{
32583 + long i;
32584 +
32585 + printk(KERN_ERR "PAX: bytes at PC: ");
32586 + for (i = 0; i < 20; i++) {
32587 + unsigned char c;
32588 + if (get_user(c, (unsigned char __force_user *)pc+i))
32589 + printk(KERN_CONT "?? ");
32590 + else
32591 + printk(KERN_CONT "%02x ", c);
32592 + }
32593 + printk("\n");
32594 +
32595 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32596 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32597 + unsigned long c;
32598 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32599 +#ifdef CONFIG_X86_32
32600 + printk(KERN_CONT "???????? ");
32601 +#else
32602 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32603 + printk(KERN_CONT "???????? ???????? ");
32604 + else
32605 + printk(KERN_CONT "???????????????? ");
32606 +#endif
32607 + } else {
32608 +#ifdef CONFIG_X86_64
32609 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32610 + printk(KERN_CONT "%08x ", (unsigned int)c);
32611 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32612 + } else
32613 +#endif
32614 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32615 + }
32616 + }
32617 + printk("\n");
32618 +}
32619 +#endif
32620 +
32621 +/**
32622 + * probe_kernel_write(): safely attempt to write to a location
32623 + * @dst: address to write to
32624 + * @src: pointer to the data that shall be written
32625 + * @size: size of the data chunk
32626 + *
32627 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32628 + * happens, handle that and return -EFAULT.
32629 + */
32630 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32631 +{
32632 + long ret;
32633 + mm_segment_t old_fs = get_fs();
32634 +
32635 + set_fs(KERNEL_DS);
32636 + pagefault_disable();
32637 + pax_open_kernel();
32638 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32639 + pax_close_kernel();
32640 + pagefault_enable();
32641 + set_fs(old_fs);
32642 +
32643 + return ret ? -EFAULT : 0;
32644 +}
32645 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32646 index 207d9aef..69030980 100644
32647 --- a/arch/x86/mm/gup.c
32648 +++ b/arch/x86/mm/gup.c
32649 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32650 addr = start;
32651 len = (unsigned long) nr_pages << PAGE_SHIFT;
32652 end = start + len;
32653 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32654 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32655 (void __user *)start, len)))
32656 return 0;
32657
32658 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32659 goto slow_irqon;
32660 #endif
32661
32662 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32663 + (void __user *)start, len)))
32664 + return 0;
32665 +
32666 /*
32667 * XXX: batch / limit 'nr', to avoid large irq off latency
32668 * needs some instrumenting to determine the common sizes used by
32669 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32670 index 4500142..53a363c 100644
32671 --- a/arch/x86/mm/highmem_32.c
32672 +++ b/arch/x86/mm/highmem_32.c
32673 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32674 idx = type + KM_TYPE_NR*smp_processor_id();
32675 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32676 BUG_ON(!pte_none(*(kmap_pte-idx)));
32677 +
32678 + pax_open_kernel();
32679 set_pte(kmap_pte-idx, mk_pte(page, prot));
32680 + pax_close_kernel();
32681 +
32682 arch_flush_lazy_mmu_mode();
32683
32684 return (void *)vaddr;
32685 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32686 index 8b977eb..4732c33 100644
32687 --- a/arch/x86/mm/hugetlbpage.c
32688 +++ b/arch/x86/mm/hugetlbpage.c
32689 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32690 #ifdef CONFIG_HUGETLB_PAGE
32691 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32692 unsigned long addr, unsigned long len,
32693 - unsigned long pgoff, unsigned long flags)
32694 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32695 {
32696 struct hstate *h = hstate_file(file);
32697 struct vm_unmapped_area_info info;
32698 -
32699 +
32700 info.flags = 0;
32701 info.length = len;
32702 info.low_limit = current->mm->mmap_legacy_base;
32703 info.high_limit = TASK_SIZE;
32704 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32705 info.align_offset = 0;
32706 + info.threadstack_offset = offset;
32707 return vm_unmapped_area(&info);
32708 }
32709
32710 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32711 unsigned long addr0, unsigned long len,
32712 - unsigned long pgoff, unsigned long flags)
32713 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32714 {
32715 struct hstate *h = hstate_file(file);
32716 struct vm_unmapped_area_info info;
32717 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32718 info.high_limit = current->mm->mmap_base;
32719 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32720 info.align_offset = 0;
32721 + info.threadstack_offset = offset;
32722 addr = vm_unmapped_area(&info);
32723
32724 /*
32725 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32726 VM_BUG_ON(addr != -ENOMEM);
32727 info.flags = 0;
32728 info.low_limit = TASK_UNMAPPED_BASE;
32729 +
32730 +#ifdef CONFIG_PAX_RANDMMAP
32731 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32732 + info.low_limit += current->mm->delta_mmap;
32733 +#endif
32734 +
32735 info.high_limit = TASK_SIZE;
32736 addr = vm_unmapped_area(&info);
32737 }
32738 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32739 struct hstate *h = hstate_file(file);
32740 struct mm_struct *mm = current->mm;
32741 struct vm_area_struct *vma;
32742 + unsigned long pax_task_size = TASK_SIZE;
32743 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32744
32745 if (len & ~huge_page_mask(h))
32746 return -EINVAL;
32747 - if (len > TASK_SIZE)
32748 +
32749 +#ifdef CONFIG_PAX_SEGMEXEC
32750 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32751 + pax_task_size = SEGMEXEC_TASK_SIZE;
32752 +#endif
32753 +
32754 + pax_task_size -= PAGE_SIZE;
32755 +
32756 + if (len > pax_task_size)
32757 return -ENOMEM;
32758
32759 if (flags & MAP_FIXED) {
32760 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32761 return addr;
32762 }
32763
32764 +#ifdef CONFIG_PAX_RANDMMAP
32765 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32766 +#endif
32767 +
32768 if (addr) {
32769 addr = ALIGN(addr, huge_page_size(h));
32770 vma = find_vma(mm, addr);
32771 - if (TASK_SIZE - len >= addr &&
32772 - (!vma || addr + len <= vma->vm_start))
32773 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32774 return addr;
32775 }
32776 if (mm->get_unmapped_area == arch_get_unmapped_area)
32777 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32778 - pgoff, flags);
32779 + pgoff, flags, offset);
32780 else
32781 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32782 - pgoff, flags);
32783 + pgoff, flags, offset);
32784 }
32785 #endif /* CONFIG_HUGETLB_PAGE */
32786
32787 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32788 index f971306..e83e0f6 100644
32789 --- a/arch/x86/mm/init.c
32790 +++ b/arch/x86/mm/init.c
32791 @@ -4,6 +4,7 @@
32792 #include <linux/swap.h>
32793 #include <linux/memblock.h>
32794 #include <linux/bootmem.h> /* for max_low_pfn */
32795 +#include <linux/tboot.h>
32796
32797 #include <asm/cacheflush.h>
32798 #include <asm/e820.h>
32799 @@ -17,6 +18,8 @@
32800 #include <asm/proto.h>
32801 #include <asm/dma.h> /* for MAX_DMA_PFN */
32802 #include <asm/microcode.h>
32803 +#include <asm/desc.h>
32804 +#include <asm/bios_ebda.h>
32805
32806 #include "mm_internal.h"
32807
32808 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32809 early_ioremap_page_table_range_init();
32810 #endif
32811
32812 +#ifdef CONFIG_PAX_PER_CPU_PGD
32813 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32814 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32815 + KERNEL_PGD_PTRS);
32816 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32817 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32818 + KERNEL_PGD_PTRS);
32819 + load_cr3(get_cpu_pgd(0, kernel));
32820 +#else
32821 load_cr3(swapper_pg_dir);
32822 +#endif
32823 +
32824 __flush_tlb_all();
32825
32826 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32827 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32828 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32829 * mmio resources as well as potential bios/acpi data regions.
32830 */
32831 +
32832 +#ifdef CONFIG_GRKERNSEC_KMEM
32833 +static unsigned int ebda_start __read_only;
32834 +static unsigned int ebda_end __read_only;
32835 +#endif
32836 +
32837 int devmem_is_allowed(unsigned long pagenr)
32838 {
32839 - if (pagenr < 256)
32840 +#ifdef CONFIG_GRKERNSEC_KMEM
32841 + /* allow BDA */
32842 + if (!pagenr)
32843 return 1;
32844 + /* allow EBDA */
32845 + if (pagenr >= ebda_start && pagenr < ebda_end)
32846 + return 1;
32847 + /* if tboot is in use, allow access to its hardcoded serial log range */
32848 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32849 + return 1;
32850 +#else
32851 + if (!pagenr)
32852 + return 1;
32853 +#ifdef CONFIG_VM86
32854 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32855 + return 1;
32856 +#endif
32857 +#endif
32858 +
32859 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32860 + return 1;
32861 +#ifdef CONFIG_GRKERNSEC_KMEM
32862 + /* throw out everything else below 1MB */
32863 + if (pagenr <= 256)
32864 + return 0;
32865 +#endif
32866 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32867 return 0;
32868 if (!page_is_ram(pagenr))
32869 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32870 #endif
32871 }
32872
32873 +#ifdef CONFIG_GRKERNSEC_KMEM
32874 +static inline void gr_init_ebda(void)
32875 +{
32876 + unsigned int ebda_addr;
32877 + unsigned int ebda_size = 0;
32878 +
32879 + ebda_addr = get_bios_ebda();
32880 + if (ebda_addr) {
32881 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32882 + ebda_size <<= 10;
32883 + }
32884 + if (ebda_addr && ebda_size) {
32885 + ebda_start = ebda_addr >> PAGE_SHIFT;
32886 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32887 + } else {
32888 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32889 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32890 + }
32891 +}
32892 +#else
32893 +static inline void gr_init_ebda(void) { }
32894 +#endif
32895 +
32896 void free_initmem(void)
32897 {
32898 +#ifdef CONFIG_PAX_KERNEXEC
32899 +#ifdef CONFIG_X86_32
32900 + /* PaX: limit KERNEL_CS to actual size */
32901 + unsigned long addr, limit;
32902 + struct desc_struct d;
32903 + int cpu;
32904 +#else
32905 + pgd_t *pgd;
32906 + pud_t *pud;
32907 + pmd_t *pmd;
32908 + unsigned long addr, end;
32909 +#endif
32910 +#endif
32911 +
32912 + gr_init_ebda();
32913 +
32914 +#ifdef CONFIG_PAX_KERNEXEC
32915 +#ifdef CONFIG_X86_32
32916 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32917 + limit = (limit - 1UL) >> PAGE_SHIFT;
32918 +
32919 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32920 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32921 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32922 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32923 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32924 + }
32925 +
32926 + /* PaX: make KERNEL_CS read-only */
32927 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32928 + if (!paravirt_enabled())
32929 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32930 +/*
32931 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32932 + pgd = pgd_offset_k(addr);
32933 + pud = pud_offset(pgd, addr);
32934 + pmd = pmd_offset(pud, addr);
32935 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32936 + }
32937 +*/
32938 +#ifdef CONFIG_X86_PAE
32939 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32940 +/*
32941 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32942 + pgd = pgd_offset_k(addr);
32943 + pud = pud_offset(pgd, addr);
32944 + pmd = pmd_offset(pud, addr);
32945 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32946 + }
32947 +*/
32948 +#endif
32949 +
32950 +#ifdef CONFIG_MODULES
32951 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32952 +#endif
32953 +
32954 +#else
32955 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32956 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32957 + pgd = pgd_offset_k(addr);
32958 + pud = pud_offset(pgd, addr);
32959 + pmd = pmd_offset(pud, addr);
32960 + if (!pmd_present(*pmd))
32961 + continue;
32962 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32963 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32964 + else
32965 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32966 + }
32967 +
32968 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32969 + end = addr + KERNEL_IMAGE_SIZE;
32970 + for (; addr < end; addr += PMD_SIZE) {
32971 + pgd = pgd_offset_k(addr);
32972 + pud = pud_offset(pgd, addr);
32973 + pmd = pmd_offset(pud, addr);
32974 + if (!pmd_present(*pmd))
32975 + continue;
32976 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32977 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32978 + }
32979 +#endif
32980 +
32981 + flush_tlb_all();
32982 +#endif
32983 +
32984 free_init_pages("unused kernel",
32985 (unsigned long)(&__init_begin),
32986 (unsigned long)(&__init_end));
32987 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32988 index e395048..cd38278 100644
32989 --- a/arch/x86/mm/init_32.c
32990 +++ b/arch/x86/mm/init_32.c
32991 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32992 bool __read_mostly __vmalloc_start_set = false;
32993
32994 /*
32995 - * Creates a middle page table and puts a pointer to it in the
32996 - * given global directory entry. This only returns the gd entry
32997 - * in non-PAE compilation mode, since the middle layer is folded.
32998 - */
32999 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
33000 -{
33001 - pud_t *pud;
33002 - pmd_t *pmd_table;
33003 -
33004 -#ifdef CONFIG_X86_PAE
33005 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
33006 - pmd_table = (pmd_t *)alloc_low_page();
33007 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
33008 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
33009 - pud = pud_offset(pgd, 0);
33010 - BUG_ON(pmd_table != pmd_offset(pud, 0));
33011 -
33012 - return pmd_table;
33013 - }
33014 -#endif
33015 - pud = pud_offset(pgd, 0);
33016 - pmd_table = pmd_offset(pud, 0);
33017 -
33018 - return pmd_table;
33019 -}
33020 -
33021 -/*
33022 * Create a page table and place a pointer to it in a middle page
33023 * directory entry:
33024 */
33025 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
33026 pte_t *page_table = (pte_t *)alloc_low_page();
33027
33028 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
33029 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33030 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
33031 +#else
33032 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
33033 +#endif
33034 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
33035 }
33036
33037 return pte_offset_kernel(pmd, 0);
33038 }
33039
33040 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
33041 +{
33042 + pud_t *pud;
33043 + pmd_t *pmd_table;
33044 +
33045 + pud = pud_offset(pgd, 0);
33046 + pmd_table = pmd_offset(pud, 0);
33047 +
33048 + return pmd_table;
33049 +}
33050 +
33051 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
33052 {
33053 int pgd_idx = pgd_index(vaddr);
33054 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33055 int pgd_idx, pmd_idx;
33056 unsigned long vaddr;
33057 pgd_t *pgd;
33058 + pud_t *pud;
33059 pmd_t *pmd;
33060 pte_t *pte = NULL;
33061 unsigned long count = page_table_range_init_count(start, end);
33062 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33063 pgd = pgd_base + pgd_idx;
33064
33065 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
33066 - pmd = one_md_table_init(pgd);
33067 - pmd = pmd + pmd_index(vaddr);
33068 + pud = pud_offset(pgd, vaddr);
33069 + pmd = pmd_offset(pud, vaddr);
33070 +
33071 +#ifdef CONFIG_X86_PAE
33072 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33073 +#endif
33074 +
33075 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33076 pmd++, pmd_idx++) {
33077 pte = page_table_kmap_check(one_page_table_init(pmd),
33078 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33079 }
33080 }
33081
33082 -static inline int is_kernel_text(unsigned long addr)
33083 +static inline int is_kernel_text(unsigned long start, unsigned long end)
33084 {
33085 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33086 - return 1;
33087 - return 0;
33088 + if ((start >= ktla_ktva((unsigned long)_etext) ||
33089 + end <= ktla_ktva((unsigned long)_stext)) &&
33090 + (start >= ktla_ktva((unsigned long)_einittext) ||
33091 + end <= ktla_ktva((unsigned long)_sinittext)) &&
33092 +
33093 +#ifdef CONFIG_ACPI_SLEEP
33094 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33095 +#endif
33096 +
33097 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33098 + return 0;
33099 + return 1;
33100 }
33101
33102 /*
33103 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33104 unsigned long last_map_addr = end;
33105 unsigned long start_pfn, end_pfn;
33106 pgd_t *pgd_base = swapper_pg_dir;
33107 - int pgd_idx, pmd_idx, pte_ofs;
33108 + unsigned int pgd_idx, pmd_idx, pte_ofs;
33109 unsigned long pfn;
33110 pgd_t *pgd;
33111 + pud_t *pud;
33112 pmd_t *pmd;
33113 pte_t *pte;
33114 unsigned pages_2m, pages_4k;
33115 @@ -291,8 +295,13 @@ repeat:
33116 pfn = start_pfn;
33117 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33118 pgd = pgd_base + pgd_idx;
33119 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33120 - pmd = one_md_table_init(pgd);
33121 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33122 + pud = pud_offset(pgd, 0);
33123 + pmd = pmd_offset(pud, 0);
33124 +
33125 +#ifdef CONFIG_X86_PAE
33126 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33127 +#endif
33128
33129 if (pfn >= end_pfn)
33130 continue;
33131 @@ -304,14 +313,13 @@ repeat:
33132 #endif
33133 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33134 pmd++, pmd_idx++) {
33135 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33136 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33137
33138 /*
33139 * Map with big pages if possible, otherwise
33140 * create normal page tables:
33141 */
33142 if (use_pse) {
33143 - unsigned int addr2;
33144 pgprot_t prot = PAGE_KERNEL_LARGE;
33145 /*
33146 * first pass will use the same initial
33147 @@ -322,11 +330,7 @@ repeat:
33148 _PAGE_PSE);
33149
33150 pfn &= PMD_MASK >> PAGE_SHIFT;
33151 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33152 - PAGE_OFFSET + PAGE_SIZE-1;
33153 -
33154 - if (is_kernel_text(addr) ||
33155 - is_kernel_text(addr2))
33156 + if (is_kernel_text(address, address + PMD_SIZE))
33157 prot = PAGE_KERNEL_LARGE_EXEC;
33158
33159 pages_2m++;
33160 @@ -343,7 +347,7 @@ repeat:
33161 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33162 pte += pte_ofs;
33163 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33164 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33165 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33166 pgprot_t prot = PAGE_KERNEL;
33167 /*
33168 * first pass will use the same initial
33169 @@ -351,7 +355,7 @@ repeat:
33170 */
33171 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33172
33173 - if (is_kernel_text(addr))
33174 + if (is_kernel_text(address, address + PAGE_SIZE))
33175 prot = PAGE_KERNEL_EXEC;
33176
33177 pages_4k++;
33178 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33179
33180 pud = pud_offset(pgd, va);
33181 pmd = pmd_offset(pud, va);
33182 - if (!pmd_present(*pmd))
33183 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33184 break;
33185
33186 /* should not be large page here */
33187 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33188
33189 static void __init pagetable_init(void)
33190 {
33191 - pgd_t *pgd_base = swapper_pg_dir;
33192 -
33193 - permanent_kmaps_init(pgd_base);
33194 + permanent_kmaps_init(swapper_pg_dir);
33195 }
33196
33197 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33198 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33199 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33200
33201 /* user-defined highmem size */
33202 @@ -787,10 +789,10 @@ void __init mem_init(void)
33203 ((unsigned long)&__init_end -
33204 (unsigned long)&__init_begin) >> 10,
33205
33206 - (unsigned long)&_etext, (unsigned long)&_edata,
33207 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33208 + (unsigned long)&_sdata, (unsigned long)&_edata,
33209 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33210
33211 - (unsigned long)&_text, (unsigned long)&_etext,
33212 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33213 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33214
33215 /*
33216 @@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
33217 if (!kernel_set_to_readonly)
33218 return;
33219
33220 + start = ktla_ktva(start);
33221 pr_debug("Set kernel text: %lx - %lx for read write\n",
33222 start, start+size);
33223
33224 @@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
33225 if (!kernel_set_to_readonly)
33226 return;
33227
33228 + start = ktla_ktva(start);
33229 pr_debug("Set kernel text: %lx - %lx for read only\n",
33230 start, start+size);
33231
33232 @@ -925,6 +929,7 @@ void mark_rodata_ro(void)
33233 unsigned long start = PFN_ALIGN(_text);
33234 unsigned long size = PFN_ALIGN(_etext) - start;
33235
33236 + start = ktla_ktva(start);
33237 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33238 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33239 size >> 10);
33240 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33241 index df1a992..94c272c 100644
33242 --- a/arch/x86/mm/init_64.c
33243 +++ b/arch/x86/mm/init_64.c
33244 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33245 * around without checking the pgd every time.
33246 */
33247
33248 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
33249 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
33250 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33251
33252 int force_personality32;
33253 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33254
33255 for (address = start; address <= end; address += PGDIR_SIZE) {
33256 const pgd_t *pgd_ref = pgd_offset_k(address);
33257 +
33258 +#ifdef CONFIG_PAX_PER_CPU_PGD
33259 + unsigned long cpu;
33260 +#else
33261 struct page *page;
33262 +#endif
33263
33264 if (pgd_none(*pgd_ref))
33265 continue;
33266
33267 spin_lock(&pgd_lock);
33268 +
33269 +#ifdef CONFIG_PAX_PER_CPU_PGD
33270 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33271 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33272 +
33273 + if (pgd_none(*pgd))
33274 + set_pgd(pgd, *pgd_ref);
33275 + else
33276 + BUG_ON(pgd_page_vaddr(*pgd)
33277 + != pgd_page_vaddr(*pgd_ref));
33278 + pgd = pgd_offset_cpu(cpu, kernel, address);
33279 +#else
33280 list_for_each_entry(page, &pgd_list, lru) {
33281 pgd_t *pgd;
33282 spinlock_t *pgt_lock;
33283 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33284 /* the pgt_lock only for Xen */
33285 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33286 spin_lock(pgt_lock);
33287 +#endif
33288
33289 if (pgd_none(*pgd))
33290 set_pgd(pgd, *pgd_ref);
33291 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33292 BUG_ON(pgd_page_vaddr(*pgd)
33293 != pgd_page_vaddr(*pgd_ref));
33294
33295 +#ifndef CONFIG_PAX_PER_CPU_PGD
33296 spin_unlock(pgt_lock);
33297 +#endif
33298 +
33299 }
33300 spin_unlock(&pgd_lock);
33301 }
33302 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33303 {
33304 if (pgd_none(*pgd)) {
33305 pud_t *pud = (pud_t *)spp_getpage();
33306 - pgd_populate(&init_mm, pgd, pud);
33307 + pgd_populate_kernel(&init_mm, pgd, pud);
33308 if (pud != pud_offset(pgd, 0))
33309 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33310 pud, pud_offset(pgd, 0));
33311 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33312 {
33313 if (pud_none(*pud)) {
33314 pmd_t *pmd = (pmd_t *) spp_getpage();
33315 - pud_populate(&init_mm, pud, pmd);
33316 + pud_populate_kernel(&init_mm, pud, pmd);
33317 if (pmd != pmd_offset(pud, 0))
33318 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33319 pmd, pmd_offset(pud, 0));
33320 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33321 pmd = fill_pmd(pud, vaddr);
33322 pte = fill_pte(pmd, vaddr);
33323
33324 + pax_open_kernel();
33325 set_pte(pte, new_pte);
33326 + pax_close_kernel();
33327
33328 /*
33329 * It's enough to flush this one mapping.
33330 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33331 pgd = pgd_offset_k((unsigned long)__va(phys));
33332 if (pgd_none(*pgd)) {
33333 pud = (pud_t *) spp_getpage();
33334 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33335 - _PAGE_USER));
33336 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33337 }
33338 pud = pud_offset(pgd, (unsigned long)__va(phys));
33339 if (pud_none(*pud)) {
33340 pmd = (pmd_t *) spp_getpage();
33341 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33342 - _PAGE_USER));
33343 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33344 }
33345 pmd = pmd_offset(pud, phys);
33346 BUG_ON(!pmd_none(*pmd));
33347 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33348 prot);
33349
33350 spin_lock(&init_mm.page_table_lock);
33351 - pud_populate(&init_mm, pud, pmd);
33352 + pud_populate_kernel(&init_mm, pud, pmd);
33353 spin_unlock(&init_mm.page_table_lock);
33354 }
33355 __flush_tlb_all();
33356 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33357 page_size_mask);
33358
33359 spin_lock(&init_mm.page_table_lock);
33360 - pgd_populate(&init_mm, pgd, pud);
33361 + pgd_populate_kernel(&init_mm, pgd, pud);
33362 spin_unlock(&init_mm.page_table_lock);
33363 pgd_changed = true;
33364 }
33365 @@ -1195,8 +1216,8 @@ static struct vm_operations_struct gate_vma_ops = {
33366 static struct vm_area_struct gate_vma = {
33367 .vm_start = VSYSCALL_ADDR,
33368 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33369 - .vm_page_prot = PAGE_READONLY_EXEC,
33370 - .vm_flags = VM_READ | VM_EXEC,
33371 + .vm_page_prot = PAGE_READONLY,
33372 + .vm_flags = VM_READ,
33373 .vm_ops = &gate_vma_ops,
33374 };
33375
33376 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33377 index 7b179b4..6bd17777 100644
33378 --- a/arch/x86/mm/iomap_32.c
33379 +++ b/arch/x86/mm/iomap_32.c
33380 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33381 type = kmap_atomic_idx_push();
33382 idx = type + KM_TYPE_NR * smp_processor_id();
33383 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33384 +
33385 + pax_open_kernel();
33386 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33387 + pax_close_kernel();
33388 +
33389 arch_flush_lazy_mmu_mode();
33390
33391 return (void *)vaddr;
33392 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33393 index baff1da..2816ef4 100644
33394 --- a/arch/x86/mm/ioremap.c
33395 +++ b/arch/x86/mm/ioremap.c
33396 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33397 unsigned long i;
33398
33399 for (i = 0; i < nr_pages; ++i)
33400 - if (pfn_valid(start_pfn + i) &&
33401 - !PageReserved(pfn_to_page(start_pfn + i)))
33402 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33403 + !PageReserved(pfn_to_page(start_pfn + i))))
33404 return 1;
33405
33406 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33407 @@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
33408 *
33409 * Caller must ensure there is only one unmapping for the same pointer.
33410 */
33411 -void iounmap(volatile void __iomem *addr)
33412 +void iounmap(const volatile void __iomem *addr)
33413 {
33414 struct vm_struct *p, *o;
33415
33416 @@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33417
33418 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33419 if (page_is_ram(start >> PAGE_SHIFT))
33420 +#ifdef CONFIG_HIGHMEM
33421 + if ((start >> PAGE_SHIFT) < max_low_pfn)
33422 +#endif
33423 return __va(phys);
33424
33425 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33426 @@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33427 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33428 {
33429 if (page_is_ram(phys >> PAGE_SHIFT))
33430 +#ifdef CONFIG_HIGHMEM
33431 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33432 +#endif
33433 return;
33434
33435 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33436 return;
33437 }
33438
33439 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33440 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33441
33442 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33443 {
33444 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33445 early_ioremap_setup();
33446
33447 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33448 - memset(bm_pte, 0, sizeof(bm_pte));
33449 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
33450 + pmd_populate_user(&init_mm, pmd, bm_pte);
33451
33452 /*
33453 * The boot-ioremap range spans multiple pmds, for which
33454 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33455 index dd89a13..d77bdcc 100644
33456 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33457 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33458 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33459 * memory (e.g. tracked pages)? For now, we need this to avoid
33460 * invoking kmemcheck for PnP BIOS calls.
33461 */
33462 - if (regs->flags & X86_VM_MASK)
33463 + if (v8086_mode(regs))
33464 return false;
33465 - if (regs->cs != __KERNEL_CS)
33466 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33467 return false;
33468
33469 pte = kmemcheck_pte_lookup(address);
33470 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33471 index 25e7e13..1964579 100644
33472 --- a/arch/x86/mm/mmap.c
33473 +++ b/arch/x86/mm/mmap.c
33474 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33475 * Leave an at least ~128 MB hole with possible stack randomization.
33476 */
33477 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33478 -#define MAX_GAP (TASK_SIZE/6*5)
33479 +#define MAX_GAP (pax_task_size/6*5)
33480
33481 static int mmap_is_legacy(void)
33482 {
33483 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33484 return rnd << PAGE_SHIFT;
33485 }
33486
33487 -static unsigned long mmap_base(void)
33488 +static unsigned long mmap_base(struct mm_struct *mm)
33489 {
33490 unsigned long gap = rlimit(RLIMIT_STACK);
33491 + unsigned long pax_task_size = TASK_SIZE;
33492 +
33493 +#ifdef CONFIG_PAX_SEGMEXEC
33494 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33495 + pax_task_size = SEGMEXEC_TASK_SIZE;
33496 +#endif
33497
33498 if (gap < MIN_GAP)
33499 gap = MIN_GAP;
33500 else if (gap > MAX_GAP)
33501 gap = MAX_GAP;
33502
33503 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33504 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33505 }
33506
33507 /*
33508 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33509 * does, but not when emulating X86_32
33510 */
33511 -static unsigned long mmap_legacy_base(void)
33512 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33513 {
33514 - if (mmap_is_ia32())
33515 + if (mmap_is_ia32()) {
33516 +
33517 +#ifdef CONFIG_PAX_SEGMEXEC
33518 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33519 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33520 + else
33521 +#endif
33522 +
33523 return TASK_UNMAPPED_BASE;
33524 - else
33525 + } else
33526 return TASK_UNMAPPED_BASE + mmap_rnd();
33527 }
33528
33529 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33530 */
33531 void arch_pick_mmap_layout(struct mm_struct *mm)
33532 {
33533 - mm->mmap_legacy_base = mmap_legacy_base();
33534 - mm->mmap_base = mmap_base();
33535 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33536 + mm->mmap_base = mmap_base(mm);
33537 +
33538 +#ifdef CONFIG_PAX_RANDMMAP
33539 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33540 + mm->mmap_legacy_base += mm->delta_mmap;
33541 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33542 + }
33543 +#endif
33544
33545 if (mmap_is_legacy()) {
33546 mm->mmap_base = mm->mmap_legacy_base;
33547 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33548 index 0057a7a..95c7edd 100644
33549 --- a/arch/x86/mm/mmio-mod.c
33550 +++ b/arch/x86/mm/mmio-mod.c
33551 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33552 break;
33553 default:
33554 {
33555 - unsigned char *ip = (unsigned char *)instptr;
33556 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33557 my_trace->opcode = MMIO_UNKNOWN_OP;
33558 my_trace->width = 0;
33559 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33560 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33561 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33562 void __iomem *addr)
33563 {
33564 - static atomic_t next_id;
33565 + static atomic_unchecked_t next_id;
33566 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33567 /* These are page-unaligned. */
33568 struct mmiotrace_map map = {
33569 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33570 .private = trace
33571 },
33572 .phys = offset,
33573 - .id = atomic_inc_return(&next_id)
33574 + .id = atomic_inc_return_unchecked(&next_id)
33575 };
33576 map.map_id = trace->id;
33577
33578 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33579 ioremap_trace_core(offset, size, addr);
33580 }
33581
33582 -static void iounmap_trace_core(volatile void __iomem *addr)
33583 +static void iounmap_trace_core(const volatile void __iomem *addr)
33584 {
33585 struct mmiotrace_map map = {
33586 .phys = 0,
33587 @@ -328,7 +328,7 @@ not_enabled:
33588 }
33589 }
33590
33591 -void mmiotrace_iounmap(volatile void __iomem *addr)
33592 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33593 {
33594 might_sleep();
33595 if (is_enabled()) /* recheck and proper locking in *_core() */
33596 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33597 index a32b706..efb308b 100644
33598 --- a/arch/x86/mm/numa.c
33599 +++ b/arch/x86/mm/numa.c
33600 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33601 return true;
33602 }
33603
33604 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33605 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33606 {
33607 unsigned long uninitialized_var(pfn_align);
33608 int i, nid;
33609 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33610 index ae242a7..1c7998f 100644
33611 --- a/arch/x86/mm/pageattr.c
33612 +++ b/arch/x86/mm/pageattr.c
33613 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33614 */
33615 #ifdef CONFIG_PCI_BIOS
33616 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33617 - pgprot_val(forbidden) |= _PAGE_NX;
33618 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33619 #endif
33620
33621 /*
33622 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33623 * Does not cover __inittext since that is gone later on. On
33624 * 64bit we do not enforce !NX on the low mapping
33625 */
33626 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33627 - pgprot_val(forbidden) |= _PAGE_NX;
33628 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33629 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33630
33631 +#ifdef CONFIG_DEBUG_RODATA
33632 /*
33633 * The .rodata section needs to be read-only. Using the pfn
33634 * catches all aliases.
33635 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33636 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33637 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33638 pgprot_val(forbidden) |= _PAGE_RW;
33639 +#endif
33640
33641 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33642 /*
33643 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33644 }
33645 #endif
33646
33647 +#ifdef CONFIG_PAX_KERNEXEC
33648 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33649 + pgprot_val(forbidden) |= _PAGE_RW;
33650 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33651 + }
33652 +#endif
33653 +
33654 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33655
33656 return prot;
33657 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33658 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33659 {
33660 /* change init_mm */
33661 + pax_open_kernel();
33662 set_pte_atomic(kpte, pte);
33663 +
33664 #ifdef CONFIG_X86_32
33665 if (!SHARED_KERNEL_PMD) {
33666 +
33667 +#ifdef CONFIG_PAX_PER_CPU_PGD
33668 + unsigned long cpu;
33669 +#else
33670 struct page *page;
33671 +#endif
33672
33673 +#ifdef CONFIG_PAX_PER_CPU_PGD
33674 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33675 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33676 +#else
33677 list_for_each_entry(page, &pgd_list, lru) {
33678 - pgd_t *pgd;
33679 + pgd_t *pgd = (pgd_t *)page_address(page);
33680 +#endif
33681 +
33682 pud_t *pud;
33683 pmd_t *pmd;
33684
33685 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33686 + pgd += pgd_index(address);
33687 pud = pud_offset(pgd, address);
33688 pmd = pmd_offset(pud, address);
33689 set_pte_atomic((pte_t *)pmd, pte);
33690 }
33691 }
33692 #endif
33693 + pax_close_kernel();
33694 }
33695
33696 static int
33697 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33698 index 6574388..87e9bef 100644
33699 --- a/arch/x86/mm/pat.c
33700 +++ b/arch/x86/mm/pat.c
33701 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33702
33703 if (!entry) {
33704 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33705 - current->comm, current->pid, start, end - 1);
33706 + current->comm, task_pid_nr(current), start, end - 1);
33707 return -EINVAL;
33708 }
33709
33710 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33711
33712 while (cursor < to) {
33713 if (!devmem_is_allowed(pfn)) {
33714 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33715 - current->comm, from, to - 1);
33716 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33717 + current->comm, from, to - 1, cursor);
33718 return 0;
33719 }
33720 cursor += PAGE_SIZE;
33721 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33722 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33723 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33724 "for [mem %#010Lx-%#010Lx]\n",
33725 - current->comm, current->pid,
33726 + current->comm, task_pid_nr(current),
33727 cattr_name(flags),
33728 base, (unsigned long long)(base + size-1));
33729 return -EINVAL;
33730 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33731 flags = lookup_memtype(paddr);
33732 if (want_flags != flags) {
33733 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33734 - current->comm, current->pid,
33735 + current->comm, task_pid_nr(current),
33736 cattr_name(want_flags),
33737 (unsigned long long)paddr,
33738 (unsigned long long)(paddr + size - 1),
33739 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33740 free_memtype(paddr, paddr + size);
33741 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33742 " for [mem %#010Lx-%#010Lx], got %s\n",
33743 - current->comm, current->pid,
33744 + current->comm, task_pid_nr(current),
33745 cattr_name(want_flags),
33746 (unsigned long long)paddr,
33747 (unsigned long long)(paddr + size - 1),
33748 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33749 index 415f6c4..d319983 100644
33750 --- a/arch/x86/mm/pat_rbtree.c
33751 +++ b/arch/x86/mm/pat_rbtree.c
33752 @@ -160,7 +160,7 @@ success:
33753
33754 failure:
33755 printk(KERN_INFO "%s:%d conflicting memory types "
33756 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33757 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33758 end, cattr_name(found_type), cattr_name(match->type));
33759 return -EBUSY;
33760 }
33761 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33762 index 9f0614d..92ae64a 100644
33763 --- a/arch/x86/mm/pf_in.c
33764 +++ b/arch/x86/mm/pf_in.c
33765 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33766 int i;
33767 enum reason_type rv = OTHERS;
33768
33769 - p = (unsigned char *)ins_addr;
33770 + p = (unsigned char *)ktla_ktva(ins_addr);
33771 p += skip_prefix(p, &prf);
33772 p += get_opcode(p, &opcode);
33773
33774 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33775 struct prefix_bits prf;
33776 int i;
33777
33778 - p = (unsigned char *)ins_addr;
33779 + p = (unsigned char *)ktla_ktva(ins_addr);
33780 p += skip_prefix(p, &prf);
33781 p += get_opcode(p, &opcode);
33782
33783 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33784 struct prefix_bits prf;
33785 int i;
33786
33787 - p = (unsigned char *)ins_addr;
33788 + p = (unsigned char *)ktla_ktva(ins_addr);
33789 p += skip_prefix(p, &prf);
33790 p += get_opcode(p, &opcode);
33791
33792 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33793 struct prefix_bits prf;
33794 int i;
33795
33796 - p = (unsigned char *)ins_addr;
33797 + p = (unsigned char *)ktla_ktva(ins_addr);
33798 p += skip_prefix(p, &prf);
33799 p += get_opcode(p, &opcode);
33800 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33801 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33802 struct prefix_bits prf;
33803 int i;
33804
33805 - p = (unsigned char *)ins_addr;
33806 + p = (unsigned char *)ktla_ktva(ins_addr);
33807 p += skip_prefix(p, &prf);
33808 p += get_opcode(p, &opcode);
33809 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33810 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33811 index 6fb6927..4fc13c0 100644
33812 --- a/arch/x86/mm/pgtable.c
33813 +++ b/arch/x86/mm/pgtable.c
33814 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33815 list_del(&page->lru);
33816 }
33817
33818 -#define UNSHARED_PTRS_PER_PGD \
33819 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33820 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33821 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33822
33823 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33824 +{
33825 + unsigned int count = USER_PGD_PTRS;
33826
33827 + if (!pax_user_shadow_base)
33828 + return;
33829 +
33830 + while (count--)
33831 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33832 +}
33833 +#endif
33834 +
33835 +#ifdef CONFIG_PAX_PER_CPU_PGD
33836 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33837 +{
33838 + unsigned int count = USER_PGD_PTRS;
33839 +
33840 + while (count--) {
33841 + pgd_t pgd;
33842 +
33843 +#ifdef CONFIG_X86_64
33844 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33845 +#else
33846 + pgd = *src++;
33847 +#endif
33848 +
33849 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33850 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33851 +#endif
33852 +
33853 + *dst++ = pgd;
33854 + }
33855 +
33856 +}
33857 +#endif
33858 +
33859 +#ifdef CONFIG_X86_64
33860 +#define pxd_t pud_t
33861 +#define pyd_t pgd_t
33862 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33863 +#define pgtable_pxd_page_ctor(page) true
33864 +#define pgtable_pxd_page_dtor(page)
33865 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33866 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33867 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33868 +#define PYD_SIZE PGDIR_SIZE
33869 +#else
33870 +#define pxd_t pmd_t
33871 +#define pyd_t pud_t
33872 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33873 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33874 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33875 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33876 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33877 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33878 +#define PYD_SIZE PUD_SIZE
33879 +#endif
33880 +
33881 +#ifdef CONFIG_PAX_PER_CPU_PGD
33882 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33883 +static inline void pgd_dtor(pgd_t *pgd) {}
33884 +#else
33885 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33886 {
33887 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33888 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33889 pgd_list_del(pgd);
33890 spin_unlock(&pgd_lock);
33891 }
33892 +#endif
33893
33894 /*
33895 * List of all pgd's needed for non-PAE so it can invalidate entries
33896 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33897 * -- nyc
33898 */
33899
33900 -#ifdef CONFIG_X86_PAE
33901 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33902 /*
33903 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33904 * updating the top-level pagetable entries to guarantee the
33905 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33906 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33907 * and initialize the kernel pmds here.
33908 */
33909 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33910 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33911
33912 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33913 {
33914 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33915 */
33916 flush_tlb_mm(mm);
33917 }
33918 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33919 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33920 #else /* !CONFIG_X86_PAE */
33921
33922 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33923 -#define PREALLOCATED_PMDS 0
33924 +#define PREALLOCATED_PXDS 0
33925
33926 #endif /* CONFIG_X86_PAE */
33927
33928 -static void free_pmds(pmd_t *pmds[])
33929 +static void free_pxds(pxd_t *pxds[])
33930 {
33931 int i;
33932
33933 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33934 - if (pmds[i]) {
33935 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33936 - free_page((unsigned long)pmds[i]);
33937 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33938 + if (pxds[i]) {
33939 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33940 + free_page((unsigned long)pxds[i]);
33941 }
33942 }
33943
33944 -static int preallocate_pmds(pmd_t *pmds[])
33945 +static int preallocate_pxds(pxd_t *pxds[])
33946 {
33947 int i;
33948 bool failed = false;
33949
33950 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33951 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33952 - if (!pmd)
33953 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33954 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33955 + if (!pxd)
33956 failed = true;
33957 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33958 - free_page((unsigned long)pmd);
33959 - pmd = NULL;
33960 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33961 + free_page((unsigned long)pxd);
33962 + pxd = NULL;
33963 failed = true;
33964 }
33965 - pmds[i] = pmd;
33966 + pxds[i] = pxd;
33967 }
33968
33969 if (failed) {
33970 - free_pmds(pmds);
33971 + free_pxds(pxds);
33972 return -ENOMEM;
33973 }
33974
33975 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33976 * preallocate which never got a corresponding vma will need to be
33977 * freed manually.
33978 */
33979 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33980 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33981 {
33982 int i;
33983
33984 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33985 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33986 pgd_t pgd = pgdp[i];
33987
33988 if (pgd_val(pgd) != 0) {
33989 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33990 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33991
33992 - pgdp[i] = native_make_pgd(0);
33993 + set_pgd(pgdp + i, native_make_pgd(0));
33994
33995 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33996 - pmd_free(mm, pmd);
33997 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33998 + pxd_free(mm, pxd);
33999 }
34000 }
34001 }
34002
34003 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
34004 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
34005 {
34006 - pud_t *pud;
34007 + pyd_t *pyd;
34008 int i;
34009
34010 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
34011 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
34012 return;
34013
34014 - pud = pud_offset(pgd, 0);
34015 -
34016 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
34017 - pmd_t *pmd = pmds[i];
34018 +#ifdef CONFIG_X86_64
34019 + pyd = pyd_offset(mm, 0L);
34020 +#else
34021 + pyd = pyd_offset(pgd, 0L);
34022 +#endif
34023
34024 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
34025 + pxd_t *pxd = pxds[i];
34026 if (i >= KERNEL_PGD_BOUNDARY)
34027 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34028 - sizeof(pmd_t) * PTRS_PER_PMD);
34029 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34030 + sizeof(pxd_t) * PTRS_PER_PMD);
34031
34032 - pud_populate(mm, pud, pmd);
34033 + pyd_populate(mm, pyd, pxd);
34034 }
34035 }
34036
34037 pgd_t *pgd_alloc(struct mm_struct *mm)
34038 {
34039 pgd_t *pgd;
34040 - pmd_t *pmds[PREALLOCATED_PMDS];
34041 + pxd_t *pxds[PREALLOCATED_PXDS];
34042
34043 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
34044
34045 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34046
34047 mm->pgd = pgd;
34048
34049 - if (preallocate_pmds(pmds) != 0)
34050 + if (preallocate_pxds(pxds) != 0)
34051 goto out_free_pgd;
34052
34053 if (paravirt_pgd_alloc(mm) != 0)
34054 - goto out_free_pmds;
34055 + goto out_free_pxds;
34056
34057 /*
34058 * Make sure that pre-populating the pmds is atomic with
34059 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34060 spin_lock(&pgd_lock);
34061
34062 pgd_ctor(mm, pgd);
34063 - pgd_prepopulate_pmd(mm, pgd, pmds);
34064 + pgd_prepopulate_pxd(mm, pgd, pxds);
34065
34066 spin_unlock(&pgd_lock);
34067
34068 return pgd;
34069
34070 -out_free_pmds:
34071 - free_pmds(pmds);
34072 +out_free_pxds:
34073 + free_pxds(pxds);
34074 out_free_pgd:
34075 free_page((unsigned long)pgd);
34076 out:
34077 @@ -313,7 +380,7 @@ out:
34078
34079 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34080 {
34081 - pgd_mop_up_pmds(mm, pgd);
34082 + pgd_mop_up_pxds(mm, pgd);
34083 pgd_dtor(pgd);
34084 paravirt_pgd_free(mm, pgd);
34085 free_page((unsigned long)pgd);
34086 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34087 index 4dd8cf6..f9d143e 100644
34088 --- a/arch/x86/mm/pgtable_32.c
34089 +++ b/arch/x86/mm/pgtable_32.c
34090 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34091 return;
34092 }
34093 pte = pte_offset_kernel(pmd, vaddr);
34094 +
34095 + pax_open_kernel();
34096 if (pte_val(pteval))
34097 set_pte_at(&init_mm, vaddr, pte, pteval);
34098 else
34099 pte_clear(&init_mm, vaddr, pte);
34100 + pax_close_kernel();
34101
34102 /*
34103 * It's enough to flush this one mapping.
34104 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34105 index e666cbb..61788c45 100644
34106 --- a/arch/x86/mm/physaddr.c
34107 +++ b/arch/x86/mm/physaddr.c
34108 @@ -10,7 +10,7 @@
34109 #ifdef CONFIG_X86_64
34110
34111 #ifdef CONFIG_DEBUG_VIRTUAL
34112 -unsigned long __phys_addr(unsigned long x)
34113 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34114 {
34115 unsigned long y = x - __START_KERNEL_map;
34116
34117 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34118 #else
34119
34120 #ifdef CONFIG_DEBUG_VIRTUAL
34121 -unsigned long __phys_addr(unsigned long x)
34122 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34123 {
34124 unsigned long phys_addr = x - PAGE_OFFSET;
34125 /* VMALLOC_* aren't constants */
34126 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34127 index 90555bf..f5f1828 100644
34128 --- a/arch/x86/mm/setup_nx.c
34129 +++ b/arch/x86/mm/setup_nx.c
34130 @@ -5,8 +5,10 @@
34131 #include <asm/pgtable.h>
34132 #include <asm/proto.h>
34133
34134 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34135 static int disable_nx;
34136
34137 +#ifndef CONFIG_PAX_PAGEEXEC
34138 /*
34139 * noexec = on|off
34140 *
34141 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34142 return 0;
34143 }
34144 early_param("noexec", noexec_setup);
34145 +#endif
34146 +
34147 +#endif
34148
34149 void x86_configure_nx(void)
34150 {
34151 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34152 if (cpu_has_nx && !disable_nx)
34153 __supported_pte_mask |= _PAGE_NX;
34154 else
34155 +#endif
34156 __supported_pte_mask &= ~_PAGE_NX;
34157 }
34158
34159 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34160 index dd8dda1..9e9b0f6 100644
34161 --- a/arch/x86/mm/tlb.c
34162 +++ b/arch/x86/mm/tlb.c
34163 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34164 BUG();
34165 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34166 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34167 +
34168 +#ifndef CONFIG_PAX_PER_CPU_PGD
34169 load_cr3(swapper_pg_dir);
34170 +#endif
34171 +
34172 }
34173 }
34174 EXPORT_SYMBOL_GPL(leave_mm);
34175 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34176 new file mode 100644
34177 index 0000000..dace51c
34178 --- /dev/null
34179 +++ b/arch/x86/mm/uderef_64.c
34180 @@ -0,0 +1,37 @@
34181 +#include <linux/mm.h>
34182 +#include <asm/pgtable.h>
34183 +#include <asm/uaccess.h>
34184 +
34185 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34186 +/* PaX: due to the special call convention these functions must
34187 + * - remain leaf functions under all configurations,
34188 + * - never be called directly, only dereferenced from the wrappers.
34189 + */
34190 +void __pax_open_userland(void)
34191 +{
34192 + unsigned int cpu;
34193 +
34194 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34195 + return;
34196 +
34197 + cpu = raw_get_cpu();
34198 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34199 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34200 + raw_put_cpu_no_resched();
34201 +}
34202 +EXPORT_SYMBOL(__pax_open_userland);
34203 +
34204 +void __pax_close_userland(void)
34205 +{
34206 + unsigned int cpu;
34207 +
34208 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34209 + return;
34210 +
34211 + cpu = raw_get_cpu();
34212 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34213 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34214 + raw_put_cpu_no_resched();
34215 +}
34216 +EXPORT_SYMBOL(__pax_close_userland);
34217 +#endif
34218 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34219 index 6440221..f746de8 100644
34220 --- a/arch/x86/net/bpf_jit.S
34221 +++ b/arch/x86/net/bpf_jit.S
34222 @@ -9,19 +9,17 @@
34223 */
34224 #include <linux/linkage.h>
34225 #include <asm/dwarf2.h>
34226 +#include <asm/alternative-asm.h>
34227
34228 /*
34229 * Calling convention :
34230 - * rbx : skb pointer (callee saved)
34231 + * rdi : skb pointer
34232 * esi : offset of byte(s) to fetch in skb (can be scratched)
34233 - * r10 : copy of skb->data
34234 + * r8 : copy of skb->data
34235 * r9d : hlen = skb->len - skb->data_len
34236 */
34237 -#define SKBDATA %r10
34238 +#define SKBDATA %r8
34239 #define SKF_MAX_NEG_OFF $(-0x200000) /* SKF_LL_OFF from filter.h */
34240 -#define MAX_BPF_STACK (512 /* from filter.h */ + \
34241 - 32 /* space for rbx,r13,r14,r15 */ + \
34242 - 8 /* space for skb_copy_bits */)
34243
34244 sk_load_word:
34245 .globl sk_load_word
34246 @@ -38,6 +36,7 @@ sk_load_word_positive_offset:
34247 jle bpf_slow_path_word
34248 mov (SKBDATA,%rsi),%eax
34249 bswap %eax /* ntohl() */
34250 + pax_force_retaddr
34251 ret
34252
34253 sk_load_half:
34254 @@ -55,6 +54,7 @@ sk_load_half_positive_offset:
34255 jle bpf_slow_path_half
34256 movzwl (SKBDATA,%rsi),%eax
34257 rol $8,%ax # ntohs()
34258 + pax_force_retaddr
34259 ret
34260
34261 sk_load_byte:
34262 @@ -69,45 +69,83 @@ sk_load_byte_positive_offset:
34263 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34264 jle bpf_slow_path_byte
34265 movzbl (SKBDATA,%rsi),%eax
34266 + pax_force_retaddr
34267 + ret
34268 +
34269 +/**
34270 + * sk_load_byte_msh - BPF_S_LDX_B_MSH helper
34271 + *
34272 + * Implements BPF_S_LDX_B_MSH : ldxb 4*([offset]&0xf)
34273 + * Must preserve A accumulator (%eax)
34274 + * Inputs : %esi is the offset value
34275 + */
34276 +sk_load_byte_msh:
34277 + .globl sk_load_byte_msh
34278 + test %esi,%esi
34279 + js bpf_slow_path_byte_msh_neg
34280 +
34281 +sk_load_byte_msh_positive_offset:
34282 + .globl sk_load_byte_msh_positive_offset
34283 + cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte_msh */
34284 + jle bpf_slow_path_byte_msh
34285 + movzbl (SKBDATA,%rsi),%ebx
34286 + and $15,%bl
34287 + shl $2,%bl
34288 + pax_force_retaddr
34289 ret
34290
34291 /* rsi contains offset and can be scratched */
34292 #define bpf_slow_path_common(LEN) \
34293 - mov %rbx, %rdi; /* arg1 == skb */ \
34294 + push %rdi; /* save skb */ \
34295 push %r9; \
34296 push SKBDATA; \
34297 /* rsi already has offset */ \
34298 mov $LEN,%ecx; /* len */ \
34299 - lea - MAX_BPF_STACK + 32(%rbp),%rdx; \
34300 + lea -12(%rbp),%rdx; \
34301 call skb_copy_bits; \
34302 test %eax,%eax; \
34303 pop SKBDATA; \
34304 - pop %r9;
34305 + pop %r9; \
34306 + pop %rdi
34307
34308
34309 bpf_slow_path_word:
34310 bpf_slow_path_common(4)
34311 js bpf_error
34312 - mov - MAX_BPF_STACK + 32(%rbp),%eax
34313 + mov -12(%rbp),%eax
34314 bswap %eax
34315 + pax_force_retaddr
34316 ret
34317
34318 bpf_slow_path_half:
34319 bpf_slow_path_common(2)
34320 js bpf_error
34321 - mov - MAX_BPF_STACK + 32(%rbp),%ax
34322 + mov -12(%rbp),%ax
34323 rol $8,%ax
34324 movzwl %ax,%eax
34325 + pax_force_retaddr
34326 ret
34327
34328 bpf_slow_path_byte:
34329 bpf_slow_path_common(1)
34330 js bpf_error
34331 - movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34332 + movzbl -12(%rbp),%eax
34333 + pax_force_retaddr
34334 + ret
34335 +
34336 +bpf_slow_path_byte_msh:
34337 + xchg %eax,%ebx /* dont lose A , X is about to be scratched */
34338 + bpf_slow_path_common(1)
34339 + js bpf_error
34340 + movzbl -12(%rbp),%eax
34341 + and $15,%al
34342 + shl $2,%al
34343 + xchg %eax,%ebx
34344 + pax_force_retaddr
34345 ret
34346
34347 #define sk_negative_common(SIZE) \
34348 - mov %rbx, %rdi; /* arg1 == skb */ \
34349 + push %rdi; /* save skb */ \
34350 push %r9; \
34351 push SKBDATA; \
34352 /* rsi already has offset */ \
34353 @@ -116,8 +154,10 @@ bpf_slow_path_byte:
34354 test %rax,%rax; \
34355 pop SKBDATA; \
34356 pop %r9; \
34357 + pop %rdi; \
34358 jz bpf_error
34359
34360 +
34361 bpf_slow_path_word_neg:
34362 cmp SKF_MAX_NEG_OFF, %esi /* test range */
34363 jl bpf_error /* offset lower -> error */
34364 @@ -126,6 +166,7 @@ sk_load_word_negative_offset:
34365 sk_negative_common(4)
34366 mov (%rax), %eax
34367 bswap %eax
34368 + pax_force_retaddr
34369 ret
34370
34371 bpf_slow_path_half_neg:
34372 @@ -137,6 +178,7 @@ sk_load_half_negative_offset:
34373 mov (%rax),%ax
34374 rol $8,%ax
34375 movzwl %ax,%eax
34376 + pax_force_retaddr
34377 ret
34378
34379 bpf_slow_path_byte_neg:
34380 @@ -146,14 +188,27 @@ sk_load_byte_negative_offset:
34381 .globl sk_load_byte_negative_offset
34382 sk_negative_common(1)
34383 movzbl (%rax), %eax
34384 + pax_force_retaddr
34385 + ret
34386 +
34387 +bpf_slow_path_byte_msh_neg:
34388 + cmp SKF_MAX_NEG_OFF, %esi
34389 + jl bpf_error
34390 +sk_load_byte_msh_negative_offset:
34391 + .globl sk_load_byte_msh_negative_offset
34392 + xchg %eax,%ebx /* dont lose A , X is about to be scratched */
34393 + sk_negative_common(1)
34394 + movzbl (%rax),%eax
34395 + and $15,%al
34396 + shl $2,%al
34397 + xchg %eax,%ebx
34398 + pax_force_retaddr
34399 ret
34400
34401 bpf_error:
34402 # force a return 0 from jit handler
34403 - xor %eax,%eax
34404 - mov - MAX_BPF_STACK(%rbp),%rbx
34405 - mov - MAX_BPF_STACK + 8(%rbp),%r13
34406 - mov - MAX_BPF_STACK + 16(%rbp),%r14
34407 - mov - MAX_BPF_STACK + 24(%rbp),%r15
34408 + xor %eax,%eax
34409 + mov -8(%rbp),%rbx
34410 leaveq
34411 + pax_force_retaddr
34412 ret
34413 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34414 index 99bef86..bdfb5c6 100644
34415 --- a/arch/x86/net/bpf_jit_comp.c
34416 +++ b/arch/x86/net/bpf_jit_comp.c
34417 @@ -1,7 +1,6 @@
34418 /* bpf_jit_comp.c : BPF JIT compiler
34419 *
34420 * Copyright (C) 2011-2013 Eric Dumazet (eric.dumazet@gmail.com)
34421 - * Internal BPF Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
34422 *
34423 * This program is free software; you can redistribute it and/or
34424 * modify it under the terms of the GNU General Public License
34425 @@ -15,16 +14,28 @@
34426 #include <linux/if_vlan.h>
34427 #include <linux/random.h>
34428
34429 +/*
34430 + * Conventions :
34431 + * EAX : BPF A accumulator
34432 + * EBX : BPF X accumulator
34433 + * RDI : pointer to skb (first argument given to JIT function)
34434 + * RBP : frame pointer (even if CONFIG_FRAME_POINTER=n)
34435 + * ECX,EDX,ESI : scratch registers
34436 + * r9d : skb->len - skb->data_len (headlen)
34437 + * r8 : skb->data
34438 + * -8(RBP) : saved RBX value
34439 + * -16(RBP)..-80(RBP) : BPF_MEMWORDS values
34440 + */
34441 int bpf_jit_enable __read_mostly;
34442
34443 /*
34444 * assembly code in arch/x86/net/bpf_jit.S
34445 */
34446 -extern u8 sk_load_word[], sk_load_half[], sk_load_byte[];
34447 +extern u8 sk_load_word[], sk_load_half[], sk_load_byte[], sk_load_byte_msh[];
34448 extern u8 sk_load_word_positive_offset[], sk_load_half_positive_offset[];
34449 -extern u8 sk_load_byte_positive_offset[];
34450 +extern u8 sk_load_byte_positive_offset[], sk_load_byte_msh_positive_offset[];
34451 extern u8 sk_load_word_negative_offset[], sk_load_half_negative_offset[];
34452 -extern u8 sk_load_byte_negative_offset[];
34453 +extern u8 sk_load_byte_negative_offset[], sk_load_byte_msh_negative_offset[];
34454
34455 static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34456 {
34457 @@ -39,50 +50,113 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34458 return ptr + len;
34459 }
34460
34461 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34462 +#define MAX_INSTR_CODE_SIZE 96
34463 +#else
34464 +#define MAX_INSTR_CODE_SIZE 64
34465 +#endif
34466 +
34467 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
34468
34469 #define EMIT1(b1) EMIT(b1, 1)
34470 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
34471 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
34472 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
34473 -#define EMIT1_off32(b1, off) \
34474 - do {EMIT1(b1); EMIT(off, 4); } while (0)
34475 -#define EMIT2_off32(b1, b2, off) \
34476 - do {EMIT2(b1, b2); EMIT(off, 4); } while (0)
34477 -#define EMIT3_off32(b1, b2, b3, off) \
34478 - do {EMIT3(b1, b2, b3); EMIT(off, 4); } while (0)
34479 -#define EMIT4_off32(b1, b2, b3, b4, off) \
34480 - do {EMIT4(b1, b2, b3, b4); EMIT(off, 4); } while (0)
34481 +
34482 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34483 +/* original constant will appear in ecx */
34484 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
34485 +do { \
34486 + /* mov ecx, randkey */ \
34487 + EMIT1(0xb9); \
34488 + EMIT(_key, 4); \
34489 + /* xor ecx, randkey ^ off */ \
34490 + EMIT2(0x81, 0xf1); \
34491 + EMIT((_key) ^ (_off), 4); \
34492 +} while (0)
34493 +
34494 +#define EMIT1_off32(b1, _off) \
34495 +do { \
34496 + switch (b1) { \
34497 + case 0x05: /* add eax, imm32 */ \
34498 + case 0x2d: /* sub eax, imm32 */ \
34499 + case 0x25: /* and eax, imm32 */ \
34500 + case 0x0d: /* or eax, imm32 */ \
34501 + case 0xb8: /* mov eax, imm32 */ \
34502 + case 0x35: /* xor eax, imm32 */ \
34503 + case 0x3d: /* cmp eax, imm32 */ \
34504 + case 0xa9: /* test eax, imm32 */ \
34505 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34506 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
34507 + break; \
34508 + case 0xbb: /* mov ebx, imm32 */ \
34509 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34510 + /* mov ebx, ecx */ \
34511 + EMIT2(0x89, 0xcb); \
34512 + break; \
34513 + case 0xbe: /* mov esi, imm32 */ \
34514 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34515 + /* mov esi, ecx */ \
34516 + EMIT2(0x89, 0xce); \
34517 + break; \
34518 + case 0xe8: /* call rel imm32, always to known funcs */ \
34519 + EMIT1(b1); \
34520 + EMIT(_off, 4); \
34521 + break; \
34522 + case 0xe9: /* jmp rel imm32 */ \
34523 + EMIT1(b1); \
34524 + EMIT(_off, 4); \
34525 + /* prevent fall-through, we're not called if off = 0 */ \
34526 + EMIT(0xcccccccc, 4); \
34527 + EMIT(0xcccccccc, 4); \
34528 + break; \
34529 + default: \
34530 + BUILD_BUG(); \
34531 + } \
34532 +} while (0)
34533 +
34534 +#define EMIT2_off32(b1, b2, _off) \
34535 +do { \
34536 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
34537 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
34538 + EMIT(randkey, 4); \
34539 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
34540 + EMIT((_off) - randkey, 4); \
34541 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
34542 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34543 + /* imul eax, ecx */ \
34544 + EMIT3(0x0f, 0xaf, 0xc1); \
34545 + } else { \
34546 + BUILD_BUG(); \
34547 + } \
34548 +} while (0)
34549 +#else
34550 +#define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
34551 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
34552 +#endif
34553 +
34554 +#define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
34555 +#define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
34556
34557 static inline bool is_imm8(int value)
34558 {
34559 return value <= 127 && value >= -128;
34560 }
34561
34562 -static inline bool is_simm32(s64 value)
34563 +static inline bool is_near(int offset)
34564 {
34565 - return value == (s64) (s32) value;
34566 + return offset <= 127 && offset >= -128;
34567 }
34568
34569 -/* mov dst, src */
34570 -#define EMIT_mov(DST, SRC) \
34571 - do {if (DST != SRC) \
34572 - EMIT3(add_2mod(0x48, DST, SRC), 0x89, add_2reg(0xC0, DST, SRC)); \
34573 - } while (0)
34574 -
34575 -static int bpf_size_to_x86_bytes(int bpf_size)
34576 -{
34577 - if (bpf_size == BPF_W)
34578 - return 4;
34579 - else if (bpf_size == BPF_H)
34580 - return 2;
34581 - else if (bpf_size == BPF_B)
34582 - return 1;
34583 - else if (bpf_size == BPF_DW)
34584 - return 4; /* imm32 */
34585 - else
34586 - return 0;
34587 -}
34588 +#define EMIT_JMP(offset) \
34589 +do { \
34590 + if (offset) { \
34591 + if (is_near(offset)) \
34592 + EMIT2(0xeb, offset); /* jmp .+off8 */ \
34593 + else \
34594 + EMIT1_off32(0xe9, offset); /* jmp .+off32 */ \
34595 + } \
34596 +} while (0)
34597
34598 /* list of x86 cond jumps opcodes (. + s8)
34599 * Add 0x10 (and an extra 0x0f) to generate far jumps (. + s32)
34600 @@ -93,8 +167,46 @@ static int bpf_size_to_x86_bytes(int bpf_size)
34601 #define X86_JNE 0x75
34602 #define X86_JBE 0x76
34603 #define X86_JA 0x77
34604 -#define X86_JGE 0x7D
34605 -#define X86_JG 0x7F
34606 +
34607 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34608 +#define APPEND_FLOW_VERIFY() \
34609 +do { \
34610 + /* mov ecx, randkey */ \
34611 + EMIT1(0xb9); \
34612 + EMIT(randkey, 4); \
34613 + /* cmp ecx, randkey */ \
34614 + EMIT2(0x81, 0xf9); \
34615 + EMIT(randkey, 4); \
34616 + /* jz after 8 int 3s */ \
34617 + EMIT2(0x74, 0x08); \
34618 + EMIT(0xcccccccc, 4); \
34619 + EMIT(0xcccccccc, 4); \
34620 +} while (0)
34621 +#else
34622 +#define APPEND_FLOW_VERIFY() do { } while (0)
34623 +#endif
34624 +
34625 +#define EMIT_COND_JMP(op, offset) \
34626 +do { \
34627 + if (is_near(offset)) \
34628 + EMIT2(op, offset); /* jxx .+off8 */ \
34629 + else { \
34630 + EMIT2(0x0f, op + 0x10); \
34631 + EMIT(offset, 4); /* jxx .+off32 */ \
34632 + APPEND_FLOW_VERIFY(); \
34633 + } \
34634 +} while (0)
34635 +
34636 +#define COND_SEL(CODE, TOP, FOP) \
34637 + case CODE: \
34638 + t_op = TOP; \
34639 + f_op = FOP; \
34640 + goto cond_branch
34641 +
34642 +
34643 +#define SEEN_DATAREF 1 /* might call external helpers */
34644 +#define SEEN_XREG 2 /* ebx is used */
34645 +#define SEEN_MEM 4 /* use mem[] for temporary storage */
34646
34647 static inline void bpf_flush_icache(void *start, void *end)
34648 {
34649 @@ -109,804 +221,646 @@ static inline void bpf_flush_icache(void *start, void *end)
34650 #define CHOOSE_LOAD_FUNC(K, func) \
34651 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
34652
34653 -struct bpf_binary_header {
34654 - unsigned int pages;
34655 - /* Note : for security reasons, bpf code will follow a randomly
34656 - * sized amount of int3 instructions
34657 - */
34658 - u8 image[];
34659 -};
34660 +/* Helper to find the offset of pkt_type in sk_buff
34661 + * We want to make sure its still a 3bit field starting at a byte boundary.
34662 + */
34663 +#define PKT_TYPE_MAX 7
34664 +static int pkt_type_offset(void)
34665 +{
34666 + struct sk_buff skb_probe = {
34667 + .pkt_type = ~0,
34668 + };
34669 + char *ct = (char *)&skb_probe;
34670 + unsigned int off;
34671
34672 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34673 + for (off = 0; off < sizeof(struct sk_buff); off++) {
34674 + if (ct[off] == PKT_TYPE_MAX)
34675 + return off;
34676 + }
34677 + pr_err_once("Please fix pkt_type_offset(), as pkt_type couldn't be found\n");
34678 + return -1;
34679 +}
34680 +
34681 +/* Note : for security reasons, bpf code will follow a randomly
34682 + * sized amount of int3 instructions
34683 + */
34684 +static u8 *bpf_alloc_binary(unsigned int proglen,
34685 u8 **image_ptr)
34686 {
34687 unsigned int sz, hole;
34688 - struct bpf_binary_header *header;
34689 + u8 *header;
34690
34691 /* Most of BPF filters are really small,
34692 * but if some of them fill a page, allow at least
34693 * 128 extra bytes to insert a random section of int3
34694 */
34695 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34696 - header = module_alloc(sz);
34697 + sz = round_up(proglen + 128, PAGE_SIZE);
34698 + header = module_alloc_exec(sz);
34699 if (!header)
34700 return NULL;
34701
34702 + pax_open_kernel();
34703 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34704 + pax_close_kernel();
34705
34706 - header->pages = sz / PAGE_SIZE;
34707 - hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34708 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34709
34710 /* insert a random number of int3 instructions before BPF code */
34711 - *image_ptr = &header->image[prandom_u32() % hole];
34712 + *image_ptr = &header[prandom_u32() % hole];
34713 return header;
34714 }
34715
34716 -/* pick a register outside of BPF range for JIT internal work */
34717 -#define AUX_REG (MAX_BPF_REG + 1)
34718 -
34719 -/* the following table maps BPF registers to x64 registers.
34720 - * x64 register r12 is unused, since if used as base address register
34721 - * in load/store instructions, it always needs an extra byte of encoding
34722 - */
34723 -static const int reg2hex[] = {
34724 - [BPF_REG_0] = 0, /* rax */
34725 - [BPF_REG_1] = 7, /* rdi */
34726 - [BPF_REG_2] = 6, /* rsi */
34727 - [BPF_REG_3] = 2, /* rdx */
34728 - [BPF_REG_4] = 1, /* rcx */
34729 - [BPF_REG_5] = 0, /* r8 */
34730 - [BPF_REG_6] = 3, /* rbx callee saved */
34731 - [BPF_REG_7] = 5, /* r13 callee saved */
34732 - [BPF_REG_8] = 6, /* r14 callee saved */
34733 - [BPF_REG_9] = 7, /* r15 callee saved */
34734 - [BPF_REG_FP] = 5, /* rbp readonly */
34735 - [AUX_REG] = 3, /* r11 temp register */
34736 -};
34737 -
34738 -/* is_ereg() == true if BPF register 'reg' maps to x64 r8..r15
34739 - * which need extra byte of encoding.
34740 - * rax,rcx,...,rbp have simpler encoding
34741 - */
34742 -static inline bool is_ereg(u32 reg)
34743 -{
34744 - if (reg == BPF_REG_5 || reg == AUX_REG ||
34745 - (reg >= BPF_REG_7 && reg <= BPF_REG_9))
34746 - return true;
34747 - else
34748 - return false;
34749 -}
34750 -
34751 -/* add modifiers if 'reg' maps to x64 registers r8..r15 */
34752 -static inline u8 add_1mod(u8 byte, u32 reg)
34753 -{
34754 - if (is_ereg(reg))
34755 - byte |= 1;
34756 - return byte;
34757 -}
34758 -
34759 -static inline u8 add_2mod(u8 byte, u32 r1, u32 r2)
34760 -{
34761 - if (is_ereg(r1))
34762 - byte |= 1;
34763 - if (is_ereg(r2))
34764 - byte |= 4;
34765 - return byte;
34766 -}
34767 -
34768 -/* encode 'dst_reg' register into x64 opcode 'byte' */
34769 -static inline u8 add_1reg(u8 byte, u32 dst_reg)
34770 -{
34771 - return byte + reg2hex[dst_reg];
34772 -}
34773 -
34774 -/* encode 'dst_reg' and 'src_reg' registers into x64 opcode 'byte' */
34775 -static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34776 -{
34777 - return byte + reg2hex[dst_reg] + (reg2hex[src_reg] << 3);
34778 -}
34779 -
34780 -struct jit_context {
34781 - unsigned int cleanup_addr; /* epilogue code offset */
34782 - bool seen_ld_abs;
34783 -};
34784 -
34785 -static int do_jit(struct sk_filter *bpf_prog, int *addrs, u8 *image,
34786 - int oldproglen, struct jit_context *ctx)
34787 -{
34788 - struct sock_filter_int *insn = bpf_prog->insnsi;
34789 - int insn_cnt = bpf_prog->len;
34790 - u8 temp[64];
34791 - int i;
34792 - int proglen = 0;
34793 - u8 *prog = temp;
34794 - int stacksize = MAX_BPF_STACK +
34795 - 32 /* space for rbx, r13, r14, r15 */ +
34796 - 8 /* space for skb_copy_bits() buffer */;
34797 -
34798 - EMIT1(0x55); /* push rbp */
34799 - EMIT3(0x48, 0x89, 0xE5); /* mov rbp,rsp */
34800 -
34801 - /* sub rsp, stacksize */
34802 - EMIT3_off32(0x48, 0x81, 0xEC, stacksize);
34803 -
34804 - /* all classic BPF filters use R6(rbx) save it */
34805 -
34806 - /* mov qword ptr [rbp-X],rbx */
34807 - EMIT3_off32(0x48, 0x89, 0x9D, -stacksize);
34808 -
34809 - /* sk_convert_filter() maps classic BPF register X to R7 and uses R8
34810 - * as temporary, so all tcpdump filters need to spill/fill R7(r13) and
34811 - * R8(r14). R9(r15) spill could be made conditional, but there is only
34812 - * one 'bpf_error' return path out of helper functions inside bpf_jit.S
34813 - * The overhead of extra spill is negligible for any filter other
34814 - * than synthetic ones. Therefore not worth adding complexity.
34815 - */
34816 -
34817 - /* mov qword ptr [rbp-X],r13 */
34818 - EMIT3_off32(0x4C, 0x89, 0xAD, -stacksize + 8);
34819 - /* mov qword ptr [rbp-X],r14 */
34820 - EMIT3_off32(0x4C, 0x89, 0xB5, -stacksize + 16);
34821 - /* mov qword ptr [rbp-X],r15 */
34822 - EMIT3_off32(0x4C, 0x89, 0xBD, -stacksize + 24);
34823 -
34824 - /* clear A and X registers */
34825 - EMIT2(0x31, 0xc0); /* xor eax, eax */
34826 - EMIT3(0x4D, 0x31, 0xED); /* xor r13, r13 */
34827 -
34828 - if (ctx->seen_ld_abs) {
34829 - /* r9d : skb->len - skb->data_len (headlen)
34830 - * r10 : skb->data
34831 - */
34832 - if (is_imm8(offsetof(struct sk_buff, len)))
34833 - /* mov %r9d, off8(%rdi) */
34834 - EMIT4(0x44, 0x8b, 0x4f,
34835 - offsetof(struct sk_buff, len));
34836 - else
34837 - /* mov %r9d, off32(%rdi) */
34838 - EMIT3_off32(0x44, 0x8b, 0x8f,
34839 - offsetof(struct sk_buff, len));
34840 -
34841 - if (is_imm8(offsetof(struct sk_buff, data_len)))
34842 - /* sub %r9d, off8(%rdi) */
34843 - EMIT4(0x44, 0x2b, 0x4f,
34844 - offsetof(struct sk_buff, data_len));
34845 - else
34846 - EMIT3_off32(0x44, 0x2b, 0x8f,
34847 - offsetof(struct sk_buff, data_len));
34848 -
34849 - if (is_imm8(offsetof(struct sk_buff, data)))
34850 - /* mov %r10, off8(%rdi) */
34851 - EMIT4(0x4c, 0x8b, 0x57,
34852 - offsetof(struct sk_buff, data));
34853 - else
34854 - /* mov %r10, off32(%rdi) */
34855 - EMIT3_off32(0x4c, 0x8b, 0x97,
34856 - offsetof(struct sk_buff, data));
34857 - }
34858 -
34859 - for (i = 0; i < insn_cnt; i++, insn++) {
34860 - const s32 imm32 = insn->imm;
34861 - u32 dst_reg = insn->dst_reg;
34862 - u32 src_reg = insn->src_reg;
34863 - u8 b1 = 0, b2 = 0, b3 = 0;
34864 - s64 jmp_offset;
34865 - u8 jmp_cond;
34866 - int ilen;
34867 - u8 *func;
34868 -
34869 - switch (insn->code) {
34870 - /* ALU */
34871 - case BPF_ALU | BPF_ADD | BPF_X:
34872 - case BPF_ALU | BPF_SUB | BPF_X:
34873 - case BPF_ALU | BPF_AND | BPF_X:
34874 - case BPF_ALU | BPF_OR | BPF_X:
34875 - case BPF_ALU | BPF_XOR | BPF_X:
34876 - case BPF_ALU64 | BPF_ADD | BPF_X:
34877 - case BPF_ALU64 | BPF_SUB | BPF_X:
34878 - case BPF_ALU64 | BPF_AND | BPF_X:
34879 - case BPF_ALU64 | BPF_OR | BPF_X:
34880 - case BPF_ALU64 | BPF_XOR | BPF_X:
34881 - switch (BPF_OP(insn->code)) {
34882 - case BPF_ADD: b2 = 0x01; break;
34883 - case BPF_SUB: b2 = 0x29; break;
34884 - case BPF_AND: b2 = 0x21; break;
34885 - case BPF_OR: b2 = 0x09; break;
34886 - case BPF_XOR: b2 = 0x31; break;
34887 - }
34888 - if (BPF_CLASS(insn->code) == BPF_ALU64)
34889 - EMIT1(add_2mod(0x48, dst_reg, src_reg));
34890 - else if (is_ereg(dst_reg) || is_ereg(src_reg))
34891 - EMIT1(add_2mod(0x40, dst_reg, src_reg));
34892 - EMIT2(b2, add_2reg(0xC0, dst_reg, src_reg));
34893 - break;
34894 -
34895 - /* mov dst, src */
34896 - case BPF_ALU64 | BPF_MOV | BPF_X:
34897 - EMIT_mov(dst_reg, src_reg);
34898 - break;
34899 -
34900 - /* mov32 dst, src */
34901 - case BPF_ALU | BPF_MOV | BPF_X:
34902 - if (is_ereg(dst_reg) || is_ereg(src_reg))
34903 - EMIT1(add_2mod(0x40, dst_reg, src_reg));
34904 - EMIT2(0x89, add_2reg(0xC0, dst_reg, src_reg));
34905 - break;
34906 -
34907 - /* neg dst */
34908 - case BPF_ALU | BPF_NEG:
34909 - case BPF_ALU64 | BPF_NEG:
34910 - if (BPF_CLASS(insn->code) == BPF_ALU64)
34911 - EMIT1(add_1mod(0x48, dst_reg));
34912 - else if (is_ereg(dst_reg))
34913 - EMIT1(add_1mod(0x40, dst_reg));
34914 - EMIT2(0xF7, add_1reg(0xD8, dst_reg));
34915 - break;
34916 -
34917 - case BPF_ALU | BPF_ADD | BPF_K:
34918 - case BPF_ALU | BPF_SUB | BPF_K:
34919 - case BPF_ALU | BPF_AND | BPF_K:
34920 - case BPF_ALU | BPF_OR | BPF_K:
34921 - case BPF_ALU | BPF_XOR | BPF_K:
34922 - case BPF_ALU64 | BPF_ADD | BPF_K:
34923 - case BPF_ALU64 | BPF_SUB | BPF_K:
34924 - case BPF_ALU64 | BPF_AND | BPF_K:
34925 - case BPF_ALU64 | BPF_OR | BPF_K:
34926 - case BPF_ALU64 | BPF_XOR | BPF_K:
34927 - if (BPF_CLASS(insn->code) == BPF_ALU64)
34928 - EMIT1(add_1mod(0x48, dst_reg));
34929 - else if (is_ereg(dst_reg))
34930 - EMIT1(add_1mod(0x40, dst_reg));
34931 -
34932 - switch (BPF_OP(insn->code)) {
34933 - case BPF_ADD: b3 = 0xC0; break;
34934 - case BPF_SUB: b3 = 0xE8; break;
34935 - case BPF_AND: b3 = 0xE0; break;
34936 - case BPF_OR: b3 = 0xC8; break;
34937 - case BPF_XOR: b3 = 0xF0; break;
34938 - }
34939 -
34940 - if (is_imm8(imm32))
34941 - EMIT3(0x83, add_1reg(b3, dst_reg), imm32);
34942 - else
34943 - EMIT2_off32(0x81, add_1reg(b3, dst_reg), imm32);
34944 - break;
34945 -
34946 - case BPF_ALU64 | BPF_MOV | BPF_K:
34947 - /* optimization: if imm32 is positive,
34948 - * use 'mov eax, imm32' (which zero-extends imm32)
34949 - * to save 2 bytes
34950 - */
34951 - if (imm32 < 0) {
34952 - /* 'mov rax, imm32' sign extends imm32 */
34953 - b1 = add_1mod(0x48, dst_reg);
34954 - b2 = 0xC7;
34955 - b3 = 0xC0;
34956 - EMIT3_off32(b1, b2, add_1reg(b3, dst_reg), imm32);
34957 - break;
34958 - }
34959 -
34960 - case BPF_ALU | BPF_MOV | BPF_K:
34961 - /* mov %eax, imm32 */
34962 - if (is_ereg(dst_reg))
34963 - EMIT1(add_1mod(0x40, dst_reg));
34964 - EMIT1_off32(add_1reg(0xB8, dst_reg), imm32);
34965 - break;
34966 -
34967 - /* dst %= src, dst /= src, dst %= imm32, dst /= imm32 */
34968 - case BPF_ALU | BPF_MOD | BPF_X:
34969 - case BPF_ALU | BPF_DIV | BPF_X:
34970 - case BPF_ALU | BPF_MOD | BPF_K:
34971 - case BPF_ALU | BPF_DIV | BPF_K:
34972 - case BPF_ALU64 | BPF_MOD | BPF_X:
34973 - case BPF_ALU64 | BPF_DIV | BPF_X:
34974 - case BPF_ALU64 | BPF_MOD | BPF_K:
34975 - case BPF_ALU64 | BPF_DIV | BPF_K:
34976 - EMIT1(0x50); /* push rax */
34977 - EMIT1(0x52); /* push rdx */
34978 -
34979 - if (BPF_SRC(insn->code) == BPF_X)
34980 - /* mov r11, src_reg */
34981 - EMIT_mov(AUX_REG, src_reg);
34982 - else
34983 - /* mov r11, imm32 */
34984 - EMIT3_off32(0x49, 0xC7, 0xC3, imm32);
34985 -
34986 - /* mov rax, dst_reg */
34987 - EMIT_mov(BPF_REG_0, dst_reg);
34988 -
34989 - /* xor edx, edx
34990 - * equivalent to 'xor rdx, rdx', but one byte less
34991 - */
34992 - EMIT2(0x31, 0xd2);
34993 -
34994 - if (BPF_SRC(insn->code) == BPF_X) {
34995 - /* if (src_reg == 0) return 0 */
34996 -
34997 - /* cmp r11, 0 */
34998 - EMIT4(0x49, 0x83, 0xFB, 0x00);
34999 -
35000 - /* jne .+9 (skip over pop, pop, xor and jmp) */
35001 - EMIT2(X86_JNE, 1 + 1 + 2 + 5);
35002 - EMIT1(0x5A); /* pop rdx */
35003 - EMIT1(0x58); /* pop rax */
35004 - EMIT2(0x31, 0xc0); /* xor eax, eax */
35005 -
35006 - /* jmp cleanup_addr
35007 - * addrs[i] - 11, because there are 11 bytes
35008 - * after this insn: div, mov, pop, pop, mov
35009 - */
35010 - jmp_offset = ctx->cleanup_addr - (addrs[i] - 11);
35011 - EMIT1_off32(0xE9, jmp_offset);
35012 - }
35013 -
35014 - if (BPF_CLASS(insn->code) == BPF_ALU64)
35015 - /* div r11 */
35016 - EMIT3(0x49, 0xF7, 0xF3);
35017 - else
35018 - /* div r11d */
35019 - EMIT3(0x41, 0xF7, 0xF3);
35020 -
35021 - if (BPF_OP(insn->code) == BPF_MOD)
35022 - /* mov r11, rdx */
35023 - EMIT3(0x49, 0x89, 0xD3);
35024 - else
35025 - /* mov r11, rax */
35026 - EMIT3(0x49, 0x89, 0xC3);
35027 -
35028 - EMIT1(0x5A); /* pop rdx */
35029 - EMIT1(0x58); /* pop rax */
35030 -
35031 - /* mov dst_reg, r11 */
35032 - EMIT_mov(dst_reg, AUX_REG);
35033 - break;
35034 -
35035 - case BPF_ALU | BPF_MUL | BPF_K:
35036 - case BPF_ALU | BPF_MUL | BPF_X:
35037 - case BPF_ALU64 | BPF_MUL | BPF_K:
35038 - case BPF_ALU64 | BPF_MUL | BPF_X:
35039 - EMIT1(0x50); /* push rax */
35040 - EMIT1(0x52); /* push rdx */
35041 -
35042 - /* mov r11, dst_reg */
35043 - EMIT_mov(AUX_REG, dst_reg);
35044 -
35045 - if (BPF_SRC(insn->code) == BPF_X)
35046 - /* mov rax, src_reg */
35047 - EMIT_mov(BPF_REG_0, src_reg);
35048 - else
35049 - /* mov rax, imm32 */
35050 - EMIT3_off32(0x48, 0xC7, 0xC0, imm32);
35051 -
35052 - if (BPF_CLASS(insn->code) == BPF_ALU64)
35053 - EMIT1(add_1mod(0x48, AUX_REG));
35054 - else if (is_ereg(AUX_REG))
35055 - EMIT1(add_1mod(0x40, AUX_REG));
35056 - /* mul(q) r11 */
35057 - EMIT2(0xF7, add_1reg(0xE0, AUX_REG));
35058 -
35059 - /* mov r11, rax */
35060 - EMIT_mov(AUX_REG, BPF_REG_0);
35061 -
35062 - EMIT1(0x5A); /* pop rdx */
35063 - EMIT1(0x58); /* pop rax */
35064 -
35065 - /* mov dst_reg, r11 */
35066 - EMIT_mov(dst_reg, AUX_REG);
35067 - break;
35068 -
35069 - /* shifts */
35070 - case BPF_ALU | BPF_LSH | BPF_K:
35071 - case BPF_ALU | BPF_RSH | BPF_K:
35072 - case BPF_ALU | BPF_ARSH | BPF_K:
35073 - case BPF_ALU64 | BPF_LSH | BPF_K:
35074 - case BPF_ALU64 | BPF_RSH | BPF_K:
35075 - case BPF_ALU64 | BPF_ARSH | BPF_K:
35076 - if (BPF_CLASS(insn->code) == BPF_ALU64)
35077 - EMIT1(add_1mod(0x48, dst_reg));
35078 - else if (is_ereg(dst_reg))
35079 - EMIT1(add_1mod(0x40, dst_reg));
35080 -
35081 - switch (BPF_OP(insn->code)) {
35082 - case BPF_LSH: b3 = 0xE0; break;
35083 - case BPF_RSH: b3 = 0xE8; break;
35084 - case BPF_ARSH: b3 = 0xF8; break;
35085 - }
35086 - EMIT3(0xC1, add_1reg(b3, dst_reg), imm32);
35087 - break;
35088 -
35089 - case BPF_ALU | BPF_END | BPF_FROM_BE:
35090 - switch (imm32) {
35091 - case 16:
35092 - /* emit 'ror %ax, 8' to swap lower 2 bytes */
35093 - EMIT1(0x66);
35094 - if (is_ereg(dst_reg))
35095 - EMIT1(0x41);
35096 - EMIT3(0xC1, add_1reg(0xC8, dst_reg), 8);
35097 - break;
35098 - case 32:
35099 - /* emit 'bswap eax' to swap lower 4 bytes */
35100 - if (is_ereg(dst_reg))
35101 - EMIT2(0x41, 0x0F);
35102 - else
35103 - EMIT1(0x0F);
35104 - EMIT1(add_1reg(0xC8, dst_reg));
35105 - break;
35106 - case 64:
35107 - /* emit 'bswap rax' to swap 8 bytes */
35108 - EMIT3(add_1mod(0x48, dst_reg), 0x0F,
35109 - add_1reg(0xC8, dst_reg));
35110 - break;
35111 - }
35112 - break;
35113 -
35114 - case BPF_ALU | BPF_END | BPF_FROM_LE:
35115 - break;
35116 -
35117 - /* ST: *(u8*)(dst_reg + off) = imm */
35118 - case BPF_ST | BPF_MEM | BPF_B:
35119 - if (is_ereg(dst_reg))
35120 - EMIT2(0x41, 0xC6);
35121 - else
35122 - EMIT1(0xC6);
35123 - goto st;
35124 - case BPF_ST | BPF_MEM | BPF_H:
35125 - if (is_ereg(dst_reg))
35126 - EMIT3(0x66, 0x41, 0xC7);
35127 - else
35128 - EMIT2(0x66, 0xC7);
35129 - goto st;
35130 - case BPF_ST | BPF_MEM | BPF_W:
35131 - if (is_ereg(dst_reg))
35132 - EMIT2(0x41, 0xC7);
35133 - else
35134 - EMIT1(0xC7);
35135 - goto st;
35136 - case BPF_ST | BPF_MEM | BPF_DW:
35137 - EMIT2(add_1mod(0x48, dst_reg), 0xC7);
35138 -
35139 -st: if (is_imm8(insn->off))
35140 - EMIT2(add_1reg(0x40, dst_reg), insn->off);
35141 - else
35142 - EMIT1_off32(add_1reg(0x80, dst_reg), insn->off);
35143 -
35144 - EMIT(imm32, bpf_size_to_x86_bytes(BPF_SIZE(insn->code)));
35145 - break;
35146 -
35147 - /* STX: *(u8*)(dst_reg + off) = src_reg */
35148 - case BPF_STX | BPF_MEM | BPF_B:
35149 - /* emit 'mov byte ptr [rax + off], al' */
35150 - if (is_ereg(dst_reg) || is_ereg(src_reg) ||
35151 - /* have to add extra byte for x86 SIL, DIL regs */
35152 - src_reg == BPF_REG_1 || src_reg == BPF_REG_2)
35153 - EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x88);
35154 - else
35155 - EMIT1(0x88);
35156 - goto stx;
35157 - case BPF_STX | BPF_MEM | BPF_H:
35158 - if (is_ereg(dst_reg) || is_ereg(src_reg))
35159 - EMIT3(0x66, add_2mod(0x40, dst_reg, src_reg), 0x89);
35160 - else
35161 - EMIT2(0x66, 0x89);
35162 - goto stx;
35163 - case BPF_STX | BPF_MEM | BPF_W:
35164 - if (is_ereg(dst_reg) || is_ereg(src_reg))
35165 - EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x89);
35166 - else
35167 - EMIT1(0x89);
35168 - goto stx;
35169 - case BPF_STX | BPF_MEM | BPF_DW:
35170 - EMIT2(add_2mod(0x48, dst_reg, src_reg), 0x89);
35171 -stx: if (is_imm8(insn->off))
35172 - EMIT2(add_2reg(0x40, dst_reg, src_reg), insn->off);
35173 - else
35174 - EMIT1_off32(add_2reg(0x80, dst_reg, src_reg),
35175 - insn->off);
35176 - break;
35177 -
35178 - /* LDX: dst_reg = *(u8*)(src_reg + off) */
35179 - case BPF_LDX | BPF_MEM | BPF_B:
35180 - /* emit 'movzx rax, byte ptr [rax + off]' */
35181 - EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB6);
35182 - goto ldx;
35183 - case BPF_LDX | BPF_MEM | BPF_H:
35184 - /* emit 'movzx rax, word ptr [rax + off]' */
35185 - EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB7);
35186 - goto ldx;
35187 - case BPF_LDX | BPF_MEM | BPF_W:
35188 - /* emit 'mov eax, dword ptr [rax+0x14]' */
35189 - if (is_ereg(dst_reg) || is_ereg(src_reg))
35190 - EMIT2(add_2mod(0x40, src_reg, dst_reg), 0x8B);
35191 - else
35192 - EMIT1(0x8B);
35193 - goto ldx;
35194 - case BPF_LDX | BPF_MEM | BPF_DW:
35195 - /* emit 'mov rax, qword ptr [rax+0x14]' */
35196 - EMIT2(add_2mod(0x48, src_reg, dst_reg), 0x8B);
35197 -ldx: /* if insn->off == 0 we can save one extra byte, but
35198 - * special case of x86 r13 which always needs an offset
35199 - * is not worth the hassle
35200 - */
35201 - if (is_imm8(insn->off))
35202 - EMIT2(add_2reg(0x40, src_reg, dst_reg), insn->off);
35203 - else
35204 - EMIT1_off32(add_2reg(0x80, src_reg, dst_reg),
35205 - insn->off);
35206 - break;
35207 -
35208 - /* STX XADD: lock *(u32*)(dst_reg + off) += src_reg */
35209 - case BPF_STX | BPF_XADD | BPF_W:
35210 - /* emit 'lock add dword ptr [rax + off], eax' */
35211 - if (is_ereg(dst_reg) || is_ereg(src_reg))
35212 - EMIT3(0xF0, add_2mod(0x40, dst_reg, src_reg), 0x01);
35213 - else
35214 - EMIT2(0xF0, 0x01);
35215 - goto xadd;
35216 - case BPF_STX | BPF_XADD | BPF_DW:
35217 - EMIT3(0xF0, add_2mod(0x48, dst_reg, src_reg), 0x01);
35218 -xadd: if (is_imm8(insn->off))
35219 - EMIT2(add_2reg(0x40, dst_reg, src_reg), insn->off);
35220 - else
35221 - EMIT1_off32(add_2reg(0x80, dst_reg, src_reg),
35222 - insn->off);
35223 - break;
35224 -
35225 - /* call */
35226 - case BPF_JMP | BPF_CALL:
35227 - func = (u8 *) __bpf_call_base + imm32;
35228 - jmp_offset = func - (image + addrs[i]);
35229 - if (ctx->seen_ld_abs) {
35230 - EMIT2(0x41, 0x52); /* push %r10 */
35231 - EMIT2(0x41, 0x51); /* push %r9 */
35232 - /* need to adjust jmp offset, since
35233 - * pop %r9, pop %r10 take 4 bytes after call insn
35234 - */
35235 - jmp_offset += 4;
35236 - }
35237 - if (!imm32 || !is_simm32(jmp_offset)) {
35238 - pr_err("unsupported bpf func %d addr %p image %p\n",
35239 - imm32, func, image);
35240 - return -EINVAL;
35241 - }
35242 - EMIT1_off32(0xE8, jmp_offset);
35243 - if (ctx->seen_ld_abs) {
35244 - EMIT2(0x41, 0x59); /* pop %r9 */
35245 - EMIT2(0x41, 0x5A); /* pop %r10 */
35246 - }
35247 - break;
35248 -
35249 - /* cond jump */
35250 - case BPF_JMP | BPF_JEQ | BPF_X:
35251 - case BPF_JMP | BPF_JNE | BPF_X:
35252 - case BPF_JMP | BPF_JGT | BPF_X:
35253 - case BPF_JMP | BPF_JGE | BPF_X:
35254 - case BPF_JMP | BPF_JSGT | BPF_X:
35255 - case BPF_JMP | BPF_JSGE | BPF_X:
35256 - /* cmp dst_reg, src_reg */
35257 - EMIT3(add_2mod(0x48, dst_reg, src_reg), 0x39,
35258 - add_2reg(0xC0, dst_reg, src_reg));
35259 - goto emit_cond_jmp;
35260 -
35261 - case BPF_JMP | BPF_JSET | BPF_X:
35262 - /* test dst_reg, src_reg */
35263 - EMIT3(add_2mod(0x48, dst_reg, src_reg), 0x85,
35264 - add_2reg(0xC0, dst_reg, src_reg));
35265 - goto emit_cond_jmp;
35266 -
35267 - case BPF_JMP | BPF_JSET | BPF_K:
35268 - /* test dst_reg, imm32 */
35269 - EMIT1(add_1mod(0x48, dst_reg));
35270 - EMIT2_off32(0xF7, add_1reg(0xC0, dst_reg), imm32);
35271 - goto emit_cond_jmp;
35272 -
35273 - case BPF_JMP | BPF_JEQ | BPF_K:
35274 - case BPF_JMP | BPF_JNE | BPF_K:
35275 - case BPF_JMP | BPF_JGT | BPF_K:
35276 - case BPF_JMP | BPF_JGE | BPF_K:
35277 - case BPF_JMP | BPF_JSGT | BPF_K:
35278 - case BPF_JMP | BPF_JSGE | BPF_K:
35279 - /* cmp dst_reg, imm8/32 */
35280 - EMIT1(add_1mod(0x48, dst_reg));
35281 -
35282 - if (is_imm8(imm32))
35283 - EMIT3(0x83, add_1reg(0xF8, dst_reg), imm32);
35284 - else
35285 - EMIT2_off32(0x81, add_1reg(0xF8, dst_reg), imm32);
35286 -
35287 -emit_cond_jmp: /* convert BPF opcode to x86 */
35288 - switch (BPF_OP(insn->code)) {
35289 - case BPF_JEQ:
35290 - jmp_cond = X86_JE;
35291 - break;
35292 - case BPF_JSET:
35293 - case BPF_JNE:
35294 - jmp_cond = X86_JNE;
35295 - break;
35296 - case BPF_JGT:
35297 - /* GT is unsigned '>', JA in x86 */
35298 - jmp_cond = X86_JA;
35299 - break;
35300 - case BPF_JGE:
35301 - /* GE is unsigned '>=', JAE in x86 */
35302 - jmp_cond = X86_JAE;
35303 - break;
35304 - case BPF_JSGT:
35305 - /* signed '>', GT in x86 */
35306 - jmp_cond = X86_JG;
35307 - break;
35308 - case BPF_JSGE:
35309 - /* signed '>=', GE in x86 */
35310 - jmp_cond = X86_JGE;
35311 - break;
35312 - default: /* to silence gcc warning */
35313 - return -EFAULT;
35314 - }
35315 - jmp_offset = addrs[i + insn->off] - addrs[i];
35316 - if (is_imm8(jmp_offset)) {
35317 - EMIT2(jmp_cond, jmp_offset);
35318 - } else if (is_simm32(jmp_offset)) {
35319 - EMIT2_off32(0x0F, jmp_cond + 0x10, jmp_offset);
35320 - } else {
35321 - pr_err("cond_jmp gen bug %llx\n", jmp_offset);
35322 - return -EFAULT;
35323 - }
35324 -
35325 - break;
35326 -
35327 - case BPF_JMP | BPF_JA:
35328 - jmp_offset = addrs[i + insn->off] - addrs[i];
35329 - if (!jmp_offset)
35330 - /* optimize out nop jumps */
35331 - break;
35332 -emit_jmp:
35333 - if (is_imm8(jmp_offset)) {
35334 - EMIT2(0xEB, jmp_offset);
35335 - } else if (is_simm32(jmp_offset)) {
35336 - EMIT1_off32(0xE9, jmp_offset);
35337 - } else {
35338 - pr_err("jmp gen bug %llx\n", jmp_offset);
35339 - return -EFAULT;
35340 - }
35341 - break;
35342 -
35343 - case BPF_LD | BPF_IND | BPF_W:
35344 - func = sk_load_word;
35345 - goto common_load;
35346 - case BPF_LD | BPF_ABS | BPF_W:
35347 - func = CHOOSE_LOAD_FUNC(imm32, sk_load_word);
35348 -common_load: ctx->seen_ld_abs = true;
35349 - jmp_offset = func - (image + addrs[i]);
35350 - if (!func || !is_simm32(jmp_offset)) {
35351 - pr_err("unsupported bpf func %d addr %p image %p\n",
35352 - imm32, func, image);
35353 - return -EINVAL;
35354 - }
35355 - if (BPF_MODE(insn->code) == BPF_ABS) {
35356 - /* mov %esi, imm32 */
35357 - EMIT1_off32(0xBE, imm32);
35358 - } else {
35359 - /* mov %rsi, src_reg */
35360 - EMIT_mov(BPF_REG_2, src_reg);
35361 - if (imm32) {
35362 - if (is_imm8(imm32))
35363 - /* add %esi, imm8 */
35364 - EMIT3(0x83, 0xC6, imm32);
35365 - else
35366 - /* add %esi, imm32 */
35367 - EMIT2_off32(0x81, 0xC6, imm32);
35368 - }
35369 - }
35370 - /* skb pointer is in R6 (%rbx), it will be copied into
35371 - * %rdi if skb_copy_bits() call is necessary.
35372 - * sk_load_* helpers also use %r10 and %r9d.
35373 - * See bpf_jit.S
35374 - */
35375 - EMIT1_off32(0xE8, jmp_offset); /* call */
35376 - break;
35377 -
35378 - case BPF_LD | BPF_IND | BPF_H:
35379 - func = sk_load_half;
35380 - goto common_load;
35381 - case BPF_LD | BPF_ABS | BPF_H:
35382 - func = CHOOSE_LOAD_FUNC(imm32, sk_load_half);
35383 - goto common_load;
35384 - case BPF_LD | BPF_IND | BPF_B:
35385 - func = sk_load_byte;
35386 - goto common_load;
35387 - case BPF_LD | BPF_ABS | BPF_B:
35388 - func = CHOOSE_LOAD_FUNC(imm32, sk_load_byte);
35389 - goto common_load;
35390 -
35391 - case BPF_JMP | BPF_EXIT:
35392 - if (i != insn_cnt - 1) {
35393 - jmp_offset = ctx->cleanup_addr - addrs[i];
35394 - goto emit_jmp;
35395 - }
35396 - /* update cleanup_addr */
35397 - ctx->cleanup_addr = proglen;
35398 - /* mov rbx, qword ptr [rbp-X] */
35399 - EMIT3_off32(0x48, 0x8B, 0x9D, -stacksize);
35400 - /* mov r13, qword ptr [rbp-X] */
35401 - EMIT3_off32(0x4C, 0x8B, 0xAD, -stacksize + 8);
35402 - /* mov r14, qword ptr [rbp-X] */
35403 - EMIT3_off32(0x4C, 0x8B, 0xB5, -stacksize + 16);
35404 - /* mov r15, qword ptr [rbp-X] */
35405 - EMIT3_off32(0x4C, 0x8B, 0xBD, -stacksize + 24);
35406 -
35407 - EMIT1(0xC9); /* leave */
35408 - EMIT1(0xC3); /* ret */
35409 - break;
35410 -
35411 - default:
35412 - /* By design x64 JIT should support all BPF instructions
35413 - * This error will be seen if new instruction was added
35414 - * to interpreter, but not to JIT
35415 - * or if there is junk in sk_filter
35416 - */
35417 - pr_err("bpf_jit: unknown opcode %02x\n", insn->code);
35418 - return -EINVAL;
35419 - }
35420 -
35421 - ilen = prog - temp;
35422 - if (image) {
35423 - if (unlikely(proglen + ilen > oldproglen)) {
35424 - pr_err("bpf_jit_compile fatal error\n");
35425 - return -EFAULT;
35426 - }
35427 - memcpy(image + proglen, temp, ilen);
35428 - }
35429 - proglen += ilen;
35430 - addrs[i] = proglen;
35431 - prog = temp;
35432 - }
35433 - return proglen;
35434 -}
35435 -
35436 -void bpf_jit_compile(struct sk_filter *prog)
35437 -{
35438 -}
35439 -
35440 -void bpf_int_jit_compile(struct sk_filter *prog)
35441 -{
35442 - struct bpf_binary_header *header = NULL;
35443 - int proglen, oldproglen = 0;
35444 - struct jit_context ctx = {};
35445 +void bpf_jit_compile(struct sk_filter *fp)
35446 +{
35447 + u8 temp[MAX_INSTR_CODE_SIZE];
35448 + u8 *prog;
35449 + unsigned int proglen, oldproglen = 0;
35450 + int ilen, i;
35451 + int t_offset, f_offset;
35452 + u8 t_op, f_op, seen = 0, pass;
35453 u8 *image = NULL;
35454 - int *addrs;
35455 - int pass;
35456 - int i;
35457 + u8 *header = NULL;
35458 + u8 *func;
35459 + int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
35460 + unsigned int cleanup_addr; /* epilogue code offset */
35461 + unsigned int *addrs;
35462 + const struct sock_filter *filter = fp->insns;
35463 + int flen = fp->len;
35464 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35465 + unsigned int randkey;
35466 +#endif
35467
35468 if (!bpf_jit_enable)
35469 return;
35470
35471 - if (!prog || !prog->len)
35472 - return;
35473 -
35474 - addrs = kmalloc(prog->len * sizeof(*addrs), GFP_KERNEL);
35475 - if (!addrs)
35476 + addrs = kmalloc(flen * sizeof(*addrs), GFP_KERNEL);
35477 + if (addrs == NULL)
35478 return;
35479
35480 /* Before first pass, make a rough estimation of addrs[]
35481 - * each bpf instruction is translated to less than 64 bytes
35482 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
35483 */
35484 - for (proglen = 0, i = 0; i < prog->len; i++) {
35485 - proglen += 64;
35486 + for (proglen = 0, i = 0; i < flen; i++) {
35487 + proglen += MAX_INSTR_CODE_SIZE;
35488 addrs[i] = proglen;
35489 }
35490 - ctx.cleanup_addr = proglen;
35491 + cleanup_addr = proglen; /* epilogue address */
35492
35493 for (pass = 0; pass < 10; pass++) {
35494 - proglen = do_jit(prog, addrs, image, oldproglen, &ctx);
35495 - if (proglen <= 0) {
35496 - image = NULL;
35497 - if (header)
35498 - module_free(NULL, header);
35499 - goto out;
35500 + u8 seen_or_pass0 = (pass == 0) ? (SEEN_XREG | SEEN_DATAREF | SEEN_MEM) : seen;
35501 + /* no prologue/epilogue for trivial filters (RET something) */
35502 + proglen = 0;
35503 + prog = temp;
35504 +
35505 + if (seen_or_pass0) {
35506 + EMIT4(0x55, 0x48, 0x89, 0xe5); /* push %rbp; mov %rsp,%rbp */
35507 + EMIT4(0x48, 0x83, 0xec, 96); /* subq $96,%rsp */
35508 + /* note : must save %rbx in case bpf_error is hit */
35509 + if (seen_or_pass0 & (SEEN_XREG | SEEN_DATAREF))
35510 + EMIT4(0x48, 0x89, 0x5d, 0xf8); /* mov %rbx, -8(%rbp) */
35511 + if (seen_or_pass0 & SEEN_XREG)
35512 + CLEAR_X(); /* make sure we dont leek kernel memory */
35513 +
35514 + /*
35515 + * If this filter needs to access skb data,
35516 + * loads r9 and r8 with :
35517 + * r9 = skb->len - skb->data_len
35518 + * r8 = skb->data
35519 + */
35520 + if (seen_or_pass0 & SEEN_DATAREF) {
35521 + if (offsetof(struct sk_buff, len) <= 127)
35522 + /* mov off8(%rdi),%r9d */
35523 + EMIT4(0x44, 0x8b, 0x4f, offsetof(struct sk_buff, len));
35524 + else {
35525 + /* mov off32(%rdi),%r9d */
35526 + EMIT3(0x44, 0x8b, 0x8f);
35527 + EMIT(offsetof(struct sk_buff, len), 4);
35528 + }
35529 + if (is_imm8(offsetof(struct sk_buff, data_len)))
35530 + /* sub off8(%rdi),%r9d */
35531 + EMIT4(0x44, 0x2b, 0x4f, offsetof(struct sk_buff, data_len));
35532 + else {
35533 + EMIT3(0x44, 0x2b, 0x8f);
35534 + EMIT(offsetof(struct sk_buff, data_len), 4);
35535 + }
35536 +
35537 + if (is_imm8(offsetof(struct sk_buff, data)))
35538 + /* mov off8(%rdi),%r8 */
35539 + EMIT4(0x4c, 0x8b, 0x47, offsetof(struct sk_buff, data));
35540 + else {
35541 + /* mov off32(%rdi),%r8 */
35542 + EMIT3(0x4c, 0x8b, 0x87);
35543 + EMIT(offsetof(struct sk_buff, data), 4);
35544 + }
35545 + }
35546 }
35547 +
35548 + switch (filter[0].code) {
35549 + case BPF_S_RET_K:
35550 + case BPF_S_LD_W_LEN:
35551 + case BPF_S_ANC_PROTOCOL:
35552 + case BPF_S_ANC_IFINDEX:
35553 + case BPF_S_ANC_MARK:
35554 + case BPF_S_ANC_RXHASH:
35555 + case BPF_S_ANC_CPU:
35556 + case BPF_S_ANC_VLAN_TAG:
35557 + case BPF_S_ANC_VLAN_TAG_PRESENT:
35558 + case BPF_S_ANC_QUEUE:
35559 + case BPF_S_ANC_PKTTYPE:
35560 + case BPF_S_LD_W_ABS:
35561 + case BPF_S_LD_H_ABS:
35562 + case BPF_S_LD_B_ABS:
35563 + /* first instruction sets A register (or is RET 'constant') */
35564 + break;
35565 + default:
35566 + /* make sure we dont leak kernel information to user */
35567 + CLEAR_A(); /* A = 0 */
35568 + }
35569 +
35570 + for (i = 0; i < flen; i++) {
35571 + unsigned int K = filter[i].k;
35572 +
35573 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35574 + randkey = prandom_u32();
35575 +#endif
35576 +
35577 + switch (filter[i].code) {
35578 + case BPF_S_ALU_ADD_X: /* A += X; */
35579 + seen |= SEEN_XREG;
35580 + EMIT2(0x01, 0xd8); /* add %ebx,%eax */
35581 + break;
35582 + case BPF_S_ALU_ADD_K: /* A += K; */
35583 + if (!K)
35584 + break;
35585 + if (is_imm8(K))
35586 + EMIT3(0x83, 0xc0, K); /* add imm8,%eax */
35587 + else
35588 + EMIT1_off32(0x05, K); /* add imm32,%eax */
35589 + break;
35590 + case BPF_S_ALU_SUB_X: /* A -= X; */
35591 + seen |= SEEN_XREG;
35592 + EMIT2(0x29, 0xd8); /* sub %ebx,%eax */
35593 + break;
35594 + case BPF_S_ALU_SUB_K: /* A -= K */
35595 + if (!K)
35596 + break;
35597 + if (is_imm8(K))
35598 + EMIT3(0x83, 0xe8, K); /* sub imm8,%eax */
35599 + else
35600 + EMIT1_off32(0x2d, K); /* sub imm32,%eax */
35601 + break;
35602 + case BPF_S_ALU_MUL_X: /* A *= X; */
35603 + seen |= SEEN_XREG;
35604 + EMIT3(0x0f, 0xaf, 0xc3); /* imul %ebx,%eax */
35605 + break;
35606 + case BPF_S_ALU_MUL_K: /* A *= K */
35607 + if (is_imm8(K))
35608 + EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
35609 + else
35610 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
35611 + break;
35612 + case BPF_S_ALU_DIV_X: /* A /= X; */
35613 + seen |= SEEN_XREG;
35614 + EMIT2(0x85, 0xdb); /* test %ebx,%ebx */
35615 + if (pc_ret0 > 0) {
35616 + /* addrs[pc_ret0 - 1] is start address of target
35617 + * (addrs[i] - 4) is the address following this jmp
35618 + * ("xor %edx,%edx; div %ebx" being 4 bytes long)
35619 + */
35620 + EMIT_COND_JMP(X86_JE, addrs[pc_ret0 - 1] -
35621 + (addrs[i] - 4));
35622 + } else {
35623 + EMIT_COND_JMP(X86_JNE, 2 + 5);
35624 + CLEAR_A();
35625 + EMIT1_off32(0xe9, cleanup_addr - (addrs[i] - 4)); /* jmp .+off32 */
35626 + }
35627 + EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */
35628 + break;
35629 + case BPF_S_ALU_MOD_X: /* A %= X; */
35630 + seen |= SEEN_XREG;
35631 + EMIT2(0x85, 0xdb); /* test %ebx,%ebx */
35632 + if (pc_ret0 > 0) {
35633 + /* addrs[pc_ret0 - 1] is start address of target
35634 + * (addrs[i] - 6) is the address following this jmp
35635 + * ("xor %edx,%edx; div %ebx;mov %edx,%eax" being 6 bytes long)
35636 + */
35637 + EMIT_COND_JMP(X86_JE, addrs[pc_ret0 - 1] -
35638 + (addrs[i] - 6));
35639 + } else {
35640 + EMIT_COND_JMP(X86_JNE, 2 + 5);
35641 + CLEAR_A();
35642 + EMIT1_off32(0xe9, cleanup_addr - (addrs[i] - 6)); /* jmp .+off32 */
35643 + }
35644 + EMIT2(0x31, 0xd2); /* xor %edx,%edx */
35645 + EMIT2(0xf7, 0xf3); /* div %ebx */
35646 + EMIT2(0x89, 0xd0); /* mov %edx,%eax */
35647 + break;
35648 + case BPF_S_ALU_MOD_K: /* A %= K; */
35649 + if (K == 1) {
35650 + CLEAR_A();
35651 + break;
35652 + }
35653 + EMIT2(0x31, 0xd2); /* xor %edx,%edx */
35654 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35655 + DILUTE_CONST_SEQUENCE(K, randkey);
35656 +#else
35657 + EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
35658 +#endif
35659 + EMIT2(0xf7, 0xf1); /* div %ecx */
35660 + EMIT2(0x89, 0xd0); /* mov %edx,%eax */
35661 + break;
35662 + case BPF_S_ALU_DIV_K: /* A /= K */
35663 + if (K == 1)
35664 + break;
35665 + EMIT2(0x31, 0xd2); /* xor %edx,%edx */
35666 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35667 + DILUTE_CONST_SEQUENCE(K, randkey);
35668 +#else
35669 + EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
35670 +#endif
35671 + EMIT2(0xf7, 0xf1); /* div %ecx */
35672 + break;
35673 + case BPF_S_ALU_AND_X:
35674 + seen |= SEEN_XREG;
35675 + EMIT2(0x21, 0xd8); /* and %ebx,%eax */
35676 + break;
35677 + case BPF_S_ALU_AND_K:
35678 + if (K >= 0xFFFFFF00) {
35679 + EMIT2(0x24, K & 0xFF); /* and imm8,%al */
35680 + } else if (K >= 0xFFFF0000) {
35681 + EMIT2(0x66, 0x25); /* and imm16,%ax */
35682 + EMIT(K, 2);
35683 + } else {
35684 + EMIT1_off32(0x25, K); /* and imm32,%eax */
35685 + }
35686 + break;
35687 + case BPF_S_ALU_OR_X:
35688 + seen |= SEEN_XREG;
35689 + EMIT2(0x09, 0xd8); /* or %ebx,%eax */
35690 + break;
35691 + case BPF_S_ALU_OR_K:
35692 + if (is_imm8(K))
35693 + EMIT3(0x83, 0xc8, K); /* or imm8,%eax */
35694 + else
35695 + EMIT1_off32(0x0d, K); /* or imm32,%eax */
35696 + break;
35697 + case BPF_S_ANC_ALU_XOR_X: /* A ^= X; */
35698 + case BPF_S_ALU_XOR_X:
35699 + seen |= SEEN_XREG;
35700 + EMIT2(0x31, 0xd8); /* xor %ebx,%eax */
35701 + break;
35702 + case BPF_S_ALU_XOR_K: /* A ^= K; */
35703 + if (K == 0)
35704 + break;
35705 + if (is_imm8(K))
35706 + EMIT3(0x83, 0xf0, K); /* xor imm8,%eax */
35707 + else
35708 + EMIT1_off32(0x35, K); /* xor imm32,%eax */
35709 + break;
35710 + case BPF_S_ALU_LSH_X: /* A <<= X; */
35711 + seen |= SEEN_XREG;
35712 + EMIT4(0x89, 0xd9, 0xd3, 0xe0); /* mov %ebx,%ecx; shl %cl,%eax */
35713 + break;
35714 + case BPF_S_ALU_LSH_K:
35715 + if (K == 0)
35716 + break;
35717 + else if (K == 1)
35718 + EMIT2(0xd1, 0xe0); /* shl %eax */
35719 + else
35720 + EMIT3(0xc1, 0xe0, K);
35721 + break;
35722 + case BPF_S_ALU_RSH_X: /* A >>= X; */
35723 + seen |= SEEN_XREG;
35724 + EMIT4(0x89, 0xd9, 0xd3, 0xe8); /* mov %ebx,%ecx; shr %cl,%eax */
35725 + break;
35726 + case BPF_S_ALU_RSH_K: /* A >>= K; */
35727 + if (K == 0)
35728 + break;
35729 + else if (K == 1)
35730 + EMIT2(0xd1, 0xe8); /* shr %eax */
35731 + else
35732 + EMIT3(0xc1, 0xe8, K);
35733 + break;
35734 + case BPF_S_ALU_NEG:
35735 + EMIT2(0xf7, 0xd8); /* neg %eax */
35736 + break;
35737 + case BPF_S_RET_K:
35738 + if (!K) {
35739 + if (pc_ret0 == -1)
35740 + pc_ret0 = i;
35741 + CLEAR_A();
35742 + } else {
35743 + EMIT1_off32(0xb8, K); /* mov $imm32,%eax */
35744 + }
35745 + /* fallinto */
35746 + case BPF_S_RET_A:
35747 + if (seen_or_pass0) {
35748 + if (i != flen - 1) {
35749 + EMIT_JMP(cleanup_addr - addrs[i]);
35750 + break;
35751 + }
35752 + if (seen_or_pass0 & SEEN_XREG)
35753 + EMIT4(0x48, 0x8b, 0x5d, 0xf8); /* mov -8(%rbp),%rbx */
35754 + EMIT1(0xc9); /* leaveq */
35755 + }
35756 + EMIT1(0xc3); /* ret */
35757 + break;
35758 + case BPF_S_MISC_TAX: /* X = A */
35759 + seen |= SEEN_XREG;
35760 + EMIT2(0x89, 0xc3); /* mov %eax,%ebx */
35761 + break;
35762 + case BPF_S_MISC_TXA: /* A = X */
35763 + seen |= SEEN_XREG;
35764 + EMIT2(0x89, 0xd8); /* mov %ebx,%eax */
35765 + break;
35766 + case BPF_S_LD_IMM: /* A = K */
35767 + if (!K)
35768 + CLEAR_A();
35769 + else
35770 + EMIT1_off32(0xb8, K); /* mov $imm32,%eax */
35771 + break;
35772 + case BPF_S_LDX_IMM: /* X = K */
35773 + seen |= SEEN_XREG;
35774 + if (!K)
35775 + CLEAR_X();
35776 + else
35777 + EMIT1_off32(0xbb, K); /* mov $imm32,%ebx */
35778 + break;
35779 + case BPF_S_LD_MEM: /* A = mem[K] : mov off8(%rbp),%eax */
35780 + seen |= SEEN_MEM;
35781 + EMIT3(0x8b, 0x45, 0xf0 - K*4);
35782 + break;
35783 + case BPF_S_LDX_MEM: /* X = mem[K] : mov off8(%rbp),%ebx */
35784 + seen |= SEEN_XREG | SEEN_MEM;
35785 + EMIT3(0x8b, 0x5d, 0xf0 - K*4);
35786 + break;
35787 + case BPF_S_ST: /* mem[K] = A : mov %eax,off8(%rbp) */
35788 + seen |= SEEN_MEM;
35789 + EMIT3(0x89, 0x45, 0xf0 - K*4);
35790 + break;
35791 + case BPF_S_STX: /* mem[K] = X : mov %ebx,off8(%rbp) */
35792 + seen |= SEEN_XREG | SEEN_MEM;
35793 + EMIT3(0x89, 0x5d, 0xf0 - K*4);
35794 + break;
35795 + case BPF_S_LD_W_LEN: /* A = skb->len; */
35796 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, len) != 4);
35797 + if (is_imm8(offsetof(struct sk_buff, len)))
35798 + /* mov off8(%rdi),%eax */
35799 + EMIT3(0x8b, 0x47, offsetof(struct sk_buff, len));
35800 + else {
35801 + EMIT2(0x8b, 0x87);
35802 + EMIT(offsetof(struct sk_buff, len), 4);
35803 + }
35804 + break;
35805 + case BPF_S_LDX_W_LEN: /* X = skb->len; */
35806 + seen |= SEEN_XREG;
35807 + if (is_imm8(offsetof(struct sk_buff, len)))
35808 + /* mov off8(%rdi),%ebx */
35809 + EMIT3(0x8b, 0x5f, offsetof(struct sk_buff, len));
35810 + else {
35811 + EMIT2(0x8b, 0x9f);
35812 + EMIT(offsetof(struct sk_buff, len), 4);
35813 + }
35814 + break;
35815 + case BPF_S_ANC_PROTOCOL: /* A = ntohs(skb->protocol); */
35816 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, protocol) != 2);
35817 + if (is_imm8(offsetof(struct sk_buff, protocol))) {
35818 + /* movzwl off8(%rdi),%eax */
35819 + EMIT4(0x0f, 0xb7, 0x47, offsetof(struct sk_buff, protocol));
35820 + } else {
35821 + EMIT3(0x0f, 0xb7, 0x87); /* movzwl off32(%rdi),%eax */
35822 + EMIT(offsetof(struct sk_buff, protocol), 4);
35823 + }
35824 + EMIT2(0x86, 0xc4); /* ntohs() : xchg %al,%ah */
35825 + break;
35826 + case BPF_S_ANC_IFINDEX:
35827 + if (is_imm8(offsetof(struct sk_buff, dev))) {
35828 + /* movq off8(%rdi),%rax */
35829 + EMIT4(0x48, 0x8b, 0x47, offsetof(struct sk_buff, dev));
35830 + } else {
35831 + EMIT3(0x48, 0x8b, 0x87); /* movq off32(%rdi),%rax */
35832 + EMIT(offsetof(struct sk_buff, dev), 4);
35833 + }
35834 + EMIT3(0x48, 0x85, 0xc0); /* test %rax,%rax */
35835 + EMIT_COND_JMP(X86_JE, cleanup_addr - (addrs[i] - 6));
35836 + BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
35837 + EMIT2(0x8b, 0x80); /* mov off32(%rax),%eax */
35838 + EMIT(offsetof(struct net_device, ifindex), 4);
35839 + break;
35840 + case BPF_S_ANC_MARK:
35841 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, mark) != 4);
35842 + if (is_imm8(offsetof(struct sk_buff, mark))) {
35843 + /* mov off8(%rdi),%eax */
35844 + EMIT3(0x8b, 0x47, offsetof(struct sk_buff, mark));
35845 + } else {
35846 + EMIT2(0x8b, 0x87);
35847 + EMIT(offsetof(struct sk_buff, mark), 4);
35848 + }
35849 + break;
35850 + case BPF_S_ANC_RXHASH:
35851 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, hash) != 4);
35852 + if (is_imm8(offsetof(struct sk_buff, hash))) {
35853 + /* mov off8(%rdi),%eax */
35854 + EMIT3(0x8b, 0x47, offsetof(struct sk_buff, hash));
35855 + } else {
35856 + EMIT2(0x8b, 0x87);
35857 + EMIT(offsetof(struct sk_buff, hash), 4);
35858 + }
35859 + break;
35860 + case BPF_S_ANC_QUEUE:
35861 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, queue_mapping) != 2);
35862 + if (is_imm8(offsetof(struct sk_buff, queue_mapping))) {
35863 + /* movzwl off8(%rdi),%eax */
35864 + EMIT4(0x0f, 0xb7, 0x47, offsetof(struct sk_buff, queue_mapping));
35865 + } else {
35866 + EMIT3(0x0f, 0xb7, 0x87); /* movzwl off32(%rdi),%eax */
35867 + EMIT(offsetof(struct sk_buff, queue_mapping), 4);
35868 + }
35869 + break;
35870 + case BPF_S_ANC_CPU:
35871 +#ifdef CONFIG_SMP
35872 + EMIT4(0x65, 0x8b, 0x04, 0x25); /* mov %gs:off32,%eax */
35873 + EMIT((u32)(unsigned long)&cpu_number, 4); /* A = smp_processor_id(); */
35874 +#else
35875 + CLEAR_A();
35876 +#endif
35877 + break;
35878 + case BPF_S_ANC_VLAN_TAG:
35879 + case BPF_S_ANC_VLAN_TAG_PRESENT:
35880 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
35881 + if (is_imm8(offsetof(struct sk_buff, vlan_tci))) {
35882 + /* movzwl off8(%rdi),%eax */
35883 + EMIT4(0x0f, 0xb7, 0x47, offsetof(struct sk_buff, vlan_tci));
35884 + } else {
35885 + EMIT3(0x0f, 0xb7, 0x87); /* movzwl off32(%rdi),%eax */
35886 + EMIT(offsetof(struct sk_buff, vlan_tci), 4);
35887 + }
35888 + BUILD_BUG_ON(VLAN_TAG_PRESENT != 0x1000);
35889 + if (filter[i].code == BPF_S_ANC_VLAN_TAG) {
35890 + EMIT3(0x80, 0xe4, 0xef); /* and $0xef,%ah */
35891 + } else {
35892 + EMIT3(0xc1, 0xe8, 0x0c); /* shr $0xc,%eax */
35893 + EMIT3(0x83, 0xe0, 0x01); /* and $0x1,%eax */
35894 + }
35895 + break;
35896 + case BPF_S_ANC_PKTTYPE:
35897 + {
35898 + int off = pkt_type_offset();
35899 +
35900 + if (off < 0)
35901 + goto out;
35902 + if (is_imm8(off)) {
35903 + /* movzbl off8(%rdi),%eax */
35904 + EMIT4(0x0f, 0xb6, 0x47, off);
35905 + } else {
35906 + /* movbl off32(%rdi),%eax */
35907 + EMIT3(0x0f, 0xb6, 0x87);
35908 + EMIT(off, 4);
35909 + }
35910 + EMIT3(0x83, 0xe0, PKT_TYPE_MAX); /* and $0x7,%eax */
35911 + break;
35912 + }
35913 + case BPF_S_LD_W_ABS:
35914 + func = CHOOSE_LOAD_FUNC(K, sk_load_word);
35915 +common_load: seen |= SEEN_DATAREF;
35916 + t_offset = func - (image + addrs[i]);
35917 + EMIT1_off32(0xbe, K); /* mov imm32,%esi */
35918 + EMIT1_off32(0xe8, t_offset); /* call */
35919 + break;
35920 + case BPF_S_LD_H_ABS:
35921 + func = CHOOSE_LOAD_FUNC(K, sk_load_half);
35922 + goto common_load;
35923 + case BPF_S_LD_B_ABS:
35924 + func = CHOOSE_LOAD_FUNC(K, sk_load_byte);
35925 + goto common_load;
35926 + case BPF_S_LDX_B_MSH:
35927 + func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
35928 + seen |= SEEN_DATAREF | SEEN_XREG;
35929 + t_offset = func - (image + addrs[i]);
35930 + EMIT1_off32(0xbe, K); /* mov imm32,%esi */
35931 + EMIT1_off32(0xe8, t_offset); /* call sk_load_byte_msh */
35932 + break;
35933 + case BPF_S_LD_W_IND:
35934 + func = sk_load_word;
35935 +common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
35936 + t_offset = func - (image + addrs[i]);
35937 + if (K) {
35938 + if (is_imm8(K)) {
35939 + EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
35940 + } else {
35941 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
35942 + }
35943 + } else {
35944 + EMIT2(0x89,0xde); /* mov %ebx,%esi */
35945 + }
35946 + EMIT1_off32(0xe8, t_offset); /* call sk_load_xxx_ind */
35947 + break;
35948 + case BPF_S_LD_H_IND:
35949 + func = sk_load_half;
35950 + goto common_load_ind;
35951 + case BPF_S_LD_B_IND:
35952 + func = sk_load_byte;
35953 + goto common_load_ind;
35954 + case BPF_S_JMP_JA:
35955 + t_offset = addrs[i + K] - addrs[i];
35956 + EMIT_JMP(t_offset);
35957 + break;
35958 + COND_SEL(BPF_S_JMP_JGT_K, X86_JA, X86_JBE);
35959 + COND_SEL(BPF_S_JMP_JGE_K, X86_JAE, X86_JB);
35960 + COND_SEL(BPF_S_JMP_JEQ_K, X86_JE, X86_JNE);
35961 + COND_SEL(BPF_S_JMP_JSET_K,X86_JNE, X86_JE);
35962 + COND_SEL(BPF_S_JMP_JGT_X, X86_JA, X86_JBE);
35963 + COND_SEL(BPF_S_JMP_JGE_X, X86_JAE, X86_JB);
35964 + COND_SEL(BPF_S_JMP_JEQ_X, X86_JE, X86_JNE);
35965 + COND_SEL(BPF_S_JMP_JSET_X,X86_JNE, X86_JE);
35966 +
35967 +cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
35968 + t_offset = addrs[i + filter[i].jt] - addrs[i];
35969 +
35970 + /* same targets, can avoid doing the test :) */
35971 + if (filter[i].jt == filter[i].jf) {
35972 + EMIT_JMP(t_offset);
35973 + break;
35974 + }
35975 +
35976 + switch (filter[i].code) {
35977 + case BPF_S_JMP_JGT_X:
35978 + case BPF_S_JMP_JGE_X:
35979 + case BPF_S_JMP_JEQ_X:
35980 + seen |= SEEN_XREG;
35981 + EMIT2(0x39, 0xd8); /* cmp %ebx,%eax */
35982 + break;
35983 + case BPF_S_JMP_JSET_X:
35984 + seen |= SEEN_XREG;
35985 + EMIT2(0x85, 0xd8); /* test %ebx,%eax */
35986 + break;
35987 + case BPF_S_JMP_JEQ_K:
35988 + if (K == 0) {
35989 + EMIT2(0x85, 0xc0); /* test %eax,%eax */
35990 + break;
35991 + }
35992 + case BPF_S_JMP_JGT_K:
35993 + case BPF_S_JMP_JGE_K:
35994 + if (K <= 127)
35995 + EMIT3(0x83, 0xf8, K); /* cmp imm8,%eax */
35996 + else
35997 + EMIT1_off32(0x3d, K); /* cmp imm32,%eax */
35998 + break;
35999 + case BPF_S_JMP_JSET_K:
36000 + if (K <= 0xFF)
36001 + EMIT2(0xa8, K); /* test imm8,%al */
36002 + else if (!(K & 0xFFFF00FF))
36003 + EMIT3(0xf6, 0xc4, K >> 8); /* test imm8,%ah */
36004 + else if (K <= 0xFFFF) {
36005 + EMIT2(0x66, 0xa9); /* test imm16,%ax */
36006 + EMIT(K, 2);
36007 + } else {
36008 + EMIT1_off32(0xa9, K); /* test imm32,%eax */
36009 + }
36010 + break;
36011 + }
36012 + if (filter[i].jt != 0) {
36013 + if (filter[i].jf && f_offset)
36014 + t_offset += is_near(f_offset) ? 2 : 5;
36015 + EMIT_COND_JMP(t_op, t_offset);
36016 + if (filter[i].jf)
36017 + EMIT_JMP(f_offset);
36018 + break;
36019 + }
36020 + EMIT_COND_JMP(f_op, f_offset);
36021 + break;
36022 + default:
36023 + /* hmm, too complex filter, give up with jit compiler */
36024 + goto out;
36025 + }
36026 + ilen = prog - temp;
36027 + if (image) {
36028 + if (unlikely(proglen + ilen > oldproglen)) {
36029 + pr_err("bpb_jit_compile fatal error\n");
36030 + kfree(addrs);
36031 + module_free_exec(NULL, image);
36032 + return;
36033 + }
36034 + pax_open_kernel();
36035 + memcpy(image + proglen, temp, ilen);
36036 + pax_close_kernel();
36037 + }
36038 + proglen += ilen;
36039 + addrs[i] = proglen;
36040 + prog = temp;
36041 + }
36042 + /* last bpf instruction is always a RET :
36043 + * use it to give the cleanup instruction(s) addr
36044 + */
36045 + cleanup_addr = proglen - 1; /* ret */
36046 + if (seen_or_pass0)
36047 + cleanup_addr -= 1; /* leaveq */
36048 + if (seen_or_pass0 & SEEN_XREG)
36049 + cleanup_addr -= 4; /* mov -8(%rbp),%rbx */
36050 +
36051 if (image) {
36052 if (proglen != oldproglen)
36053 - pr_err("bpf_jit: proglen=%d != oldproglen=%d\n",
36054 - proglen, oldproglen);
36055 + pr_err("bpb_jit_compile proglen=%u != oldproglen=%u\n", proglen, oldproglen);
36056 break;
36057 }
36058 if (proglen == oldproglen) {
36059 @@ -918,32 +872,30 @@ void bpf_int_jit_compile(struct sk_filter *prog)
36060 }
36061
36062 if (bpf_jit_enable > 1)
36063 - bpf_jit_dump(prog->len, proglen, 0, image);
36064 + bpf_jit_dump(flen, proglen, pass, image);
36065
36066 if (image) {
36067 bpf_flush_icache(header, image + proglen);
36068 - set_memory_ro((unsigned long)header, header->pages);
36069 - prog->bpf_func = (void *)image;
36070 - prog->jited = 1;
36071 + fp->bpf_func = (void *)image;
36072 }
36073 out:
36074 kfree(addrs);
36075 + return;
36076 }
36077
36078 static void bpf_jit_free_deferred(struct work_struct *work)
36079 {
36080 struct sk_filter *fp = container_of(work, struct sk_filter, work);
36081 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
36082 - struct bpf_binary_header *header = (void *)addr;
36083
36084 - set_memory_rw(addr, header->pages);
36085 - module_free(NULL, header);
36086 + set_memory_rw(addr, 1);
36087 + module_free_exec(NULL, (void *)addr);
36088 kfree(fp);
36089 }
36090
36091 void bpf_jit_free(struct sk_filter *fp)
36092 {
36093 - if (fp->jited) {
36094 + if (fp->bpf_func != sk_run_filter) {
36095 INIT_WORK(&fp->work, bpf_jit_free_deferred);
36096 schedule_work(&fp->work);
36097 } else {
36098 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
36099 index 5d04be5..2beeaa2 100644
36100 --- a/arch/x86/oprofile/backtrace.c
36101 +++ b/arch/x86/oprofile/backtrace.c
36102 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
36103 struct stack_frame_ia32 *fp;
36104 unsigned long bytes;
36105
36106 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
36107 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
36108 if (bytes != 0)
36109 return NULL;
36110
36111 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
36112 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
36113
36114 oprofile_add_trace(bufhead[0].return_address);
36115
36116 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
36117 struct stack_frame bufhead[2];
36118 unsigned long bytes;
36119
36120 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
36121 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
36122 if (bytes != 0)
36123 return NULL;
36124
36125 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
36126 {
36127 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
36128
36129 - if (!user_mode_vm(regs)) {
36130 + if (!user_mode(regs)) {
36131 unsigned long stack = kernel_stack_pointer(regs);
36132 if (depth)
36133 dump_trace(NULL, regs, (unsigned long *)stack, 0,
36134 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
36135 index 379e8bd..6386e09 100644
36136 --- a/arch/x86/oprofile/nmi_int.c
36137 +++ b/arch/x86/oprofile/nmi_int.c
36138 @@ -23,6 +23,7 @@
36139 #include <asm/nmi.h>
36140 #include <asm/msr.h>
36141 #include <asm/apic.h>
36142 +#include <asm/pgtable.h>
36143
36144 #include "op_counter.h"
36145 #include "op_x86_model.h"
36146 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
36147 if (ret)
36148 return ret;
36149
36150 - if (!model->num_virt_counters)
36151 - model->num_virt_counters = model->num_counters;
36152 + if (!model->num_virt_counters) {
36153 + pax_open_kernel();
36154 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
36155 + pax_close_kernel();
36156 + }
36157
36158 mux_init(ops);
36159
36160 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
36161 index 50d86c0..7985318 100644
36162 --- a/arch/x86/oprofile/op_model_amd.c
36163 +++ b/arch/x86/oprofile/op_model_amd.c
36164 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
36165 num_counters = AMD64_NUM_COUNTERS;
36166 }
36167
36168 - op_amd_spec.num_counters = num_counters;
36169 - op_amd_spec.num_controls = num_counters;
36170 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
36171 + pax_open_kernel();
36172 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
36173 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
36174 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
36175 + pax_close_kernel();
36176
36177 return 0;
36178 }
36179 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
36180 index d90528e..0127e2b 100644
36181 --- a/arch/x86/oprofile/op_model_ppro.c
36182 +++ b/arch/x86/oprofile/op_model_ppro.c
36183 @@ -19,6 +19,7 @@
36184 #include <asm/msr.h>
36185 #include <asm/apic.h>
36186 #include <asm/nmi.h>
36187 +#include <asm/pgtable.h>
36188
36189 #include "op_x86_model.h"
36190 #include "op_counter.h"
36191 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
36192
36193 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
36194
36195 - op_arch_perfmon_spec.num_counters = num_counters;
36196 - op_arch_perfmon_spec.num_controls = num_counters;
36197 + pax_open_kernel();
36198 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
36199 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
36200 + pax_close_kernel();
36201 }
36202
36203 static int arch_perfmon_init(struct oprofile_operations *ignore)
36204 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
36205 index 71e8a67..6a313bb 100644
36206 --- a/arch/x86/oprofile/op_x86_model.h
36207 +++ b/arch/x86/oprofile/op_x86_model.h
36208 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
36209 void (*switch_ctrl)(struct op_x86_model_spec const *model,
36210 struct op_msrs const * const msrs);
36211 #endif
36212 -};
36213 +} __do_const;
36214
36215 struct op_counter_config;
36216
36217 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
36218 index 84b9d67..260e5ff 100644
36219 --- a/arch/x86/pci/intel_mid_pci.c
36220 +++ b/arch/x86/pci/intel_mid_pci.c
36221 @@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
36222 pr_info("Intel MID platform detected, using MID PCI ops\n");
36223 pci_mmcfg_late_init();
36224 pcibios_enable_irq = intel_mid_pci_irq_enable;
36225 - pci_root_ops = intel_mid_pci_ops;
36226 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
36227 pci_soc_mode = 1;
36228 /* Continue with standard init */
36229 return 1;
36230 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
36231 index 84112f5..6334d60 100644
36232 --- a/arch/x86/pci/irq.c
36233 +++ b/arch/x86/pci/irq.c
36234 @@ -50,7 +50,7 @@ struct irq_router {
36235 struct irq_router_handler {
36236 u16 vendor;
36237 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
36238 -};
36239 +} __do_const;
36240
36241 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
36242 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
36243 @@ -790,7 +790,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
36244 return 0;
36245 }
36246
36247 -static __initdata struct irq_router_handler pirq_routers[] = {
36248 +static __initconst const struct irq_router_handler pirq_routers[] = {
36249 { PCI_VENDOR_ID_INTEL, intel_router_probe },
36250 { PCI_VENDOR_ID_AL, ali_router_probe },
36251 { PCI_VENDOR_ID_ITE, ite_router_probe },
36252 @@ -817,7 +817,7 @@ static struct pci_dev *pirq_router_dev;
36253 static void __init pirq_find_router(struct irq_router *r)
36254 {
36255 struct irq_routing_table *rt = pirq_table;
36256 - struct irq_router_handler *h;
36257 + const struct irq_router_handler *h;
36258
36259 #ifdef CONFIG_PCI_BIOS
36260 if (!rt->signature) {
36261 @@ -1090,7 +1090,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
36262 return 0;
36263 }
36264
36265 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
36266 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
36267 {
36268 .callback = fix_broken_hp_bios_irq9,
36269 .ident = "HP Pavilion N5400 Series Laptop",
36270 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
36271 index c77b24a..c979855 100644
36272 --- a/arch/x86/pci/pcbios.c
36273 +++ b/arch/x86/pci/pcbios.c
36274 @@ -79,7 +79,7 @@ union bios32 {
36275 static struct {
36276 unsigned long address;
36277 unsigned short segment;
36278 -} bios32_indirect = { 0, __KERNEL_CS };
36279 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
36280
36281 /*
36282 * Returns the entry point for the given service, NULL on error
36283 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
36284 unsigned long length; /* %ecx */
36285 unsigned long entry; /* %edx */
36286 unsigned long flags;
36287 + struct desc_struct d, *gdt;
36288
36289 local_irq_save(flags);
36290 - __asm__("lcall *(%%edi); cld"
36291 +
36292 + gdt = get_cpu_gdt_table(smp_processor_id());
36293 +
36294 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
36295 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
36296 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
36297 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
36298 +
36299 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
36300 : "=a" (return_code),
36301 "=b" (address),
36302 "=c" (length),
36303 "=d" (entry)
36304 : "0" (service),
36305 "1" (0),
36306 - "D" (&bios32_indirect));
36307 + "D" (&bios32_indirect),
36308 + "r"(__PCIBIOS_DS)
36309 + : "memory");
36310 +
36311 + pax_open_kernel();
36312 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
36313 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
36314 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
36315 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
36316 + pax_close_kernel();
36317 +
36318 local_irq_restore(flags);
36319
36320 switch (return_code) {
36321 - case 0:
36322 - return address + entry;
36323 - case 0x80: /* Not present */
36324 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
36325 - return 0;
36326 - default: /* Shouldn't happen */
36327 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
36328 - service, return_code);
36329 + case 0: {
36330 + int cpu;
36331 + unsigned char flags;
36332 +
36333 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
36334 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
36335 + printk(KERN_WARNING "bios32_service: not valid\n");
36336 return 0;
36337 + }
36338 + address = address + PAGE_OFFSET;
36339 + length += 16UL; /* some BIOSs underreport this... */
36340 + flags = 4;
36341 + if (length >= 64*1024*1024) {
36342 + length >>= PAGE_SHIFT;
36343 + flags |= 8;
36344 + }
36345 +
36346 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
36347 + gdt = get_cpu_gdt_table(cpu);
36348 + pack_descriptor(&d, address, length, 0x9b, flags);
36349 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
36350 + pack_descriptor(&d, address, length, 0x93, flags);
36351 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
36352 + }
36353 + return entry;
36354 + }
36355 + case 0x80: /* Not present */
36356 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
36357 + return 0;
36358 + default: /* Shouldn't happen */
36359 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
36360 + service, return_code);
36361 + return 0;
36362 }
36363 }
36364
36365 static struct {
36366 unsigned long address;
36367 unsigned short segment;
36368 -} pci_indirect = { 0, __KERNEL_CS };
36369 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
36370
36371 -static int pci_bios_present;
36372 +static int pci_bios_present __read_only;
36373
36374 static int check_pcibios(void)
36375 {
36376 @@ -131,11 +174,13 @@ static int check_pcibios(void)
36377 unsigned long flags, pcibios_entry;
36378
36379 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
36380 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
36381 + pci_indirect.address = pcibios_entry;
36382
36383 local_irq_save(flags);
36384 - __asm__(
36385 - "lcall *(%%edi); cld\n\t"
36386 + __asm__("movw %w6, %%ds\n\t"
36387 + "lcall *%%ss:(%%edi); cld\n\t"
36388 + "push %%ss\n\t"
36389 + "pop %%ds\n\t"
36390 "jc 1f\n\t"
36391 "xor %%ah, %%ah\n"
36392 "1:"
36393 @@ -144,7 +189,8 @@ static int check_pcibios(void)
36394 "=b" (ebx),
36395 "=c" (ecx)
36396 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
36397 - "D" (&pci_indirect)
36398 + "D" (&pci_indirect),
36399 + "r" (__PCIBIOS_DS)
36400 : "memory");
36401 local_irq_restore(flags);
36402
36403 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36404
36405 switch (len) {
36406 case 1:
36407 - __asm__("lcall *(%%esi); cld\n\t"
36408 + __asm__("movw %w6, %%ds\n\t"
36409 + "lcall *%%ss:(%%esi); cld\n\t"
36410 + "push %%ss\n\t"
36411 + "pop %%ds\n\t"
36412 "jc 1f\n\t"
36413 "xor %%ah, %%ah\n"
36414 "1:"
36415 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36416 : "1" (PCIBIOS_READ_CONFIG_BYTE),
36417 "b" (bx),
36418 "D" ((long)reg),
36419 - "S" (&pci_indirect));
36420 + "S" (&pci_indirect),
36421 + "r" (__PCIBIOS_DS));
36422 /*
36423 * Zero-extend the result beyond 8 bits, do not trust the
36424 * BIOS having done it:
36425 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36426 *value &= 0xff;
36427 break;
36428 case 2:
36429 - __asm__("lcall *(%%esi); cld\n\t"
36430 + __asm__("movw %w6, %%ds\n\t"
36431 + "lcall *%%ss:(%%esi); cld\n\t"
36432 + "push %%ss\n\t"
36433 + "pop %%ds\n\t"
36434 "jc 1f\n\t"
36435 "xor %%ah, %%ah\n"
36436 "1:"
36437 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36438 : "1" (PCIBIOS_READ_CONFIG_WORD),
36439 "b" (bx),
36440 "D" ((long)reg),
36441 - "S" (&pci_indirect));
36442 + "S" (&pci_indirect),
36443 + "r" (__PCIBIOS_DS));
36444 /*
36445 * Zero-extend the result beyond 16 bits, do not trust the
36446 * BIOS having done it:
36447 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36448 *value &= 0xffff;
36449 break;
36450 case 4:
36451 - __asm__("lcall *(%%esi); cld\n\t"
36452 + __asm__("movw %w6, %%ds\n\t"
36453 + "lcall *%%ss:(%%esi); cld\n\t"
36454 + "push %%ss\n\t"
36455 + "pop %%ds\n\t"
36456 "jc 1f\n\t"
36457 "xor %%ah, %%ah\n"
36458 "1:"
36459 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36460 : "1" (PCIBIOS_READ_CONFIG_DWORD),
36461 "b" (bx),
36462 "D" ((long)reg),
36463 - "S" (&pci_indirect));
36464 + "S" (&pci_indirect),
36465 + "r" (__PCIBIOS_DS));
36466 break;
36467 }
36468
36469 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36470
36471 switch (len) {
36472 case 1:
36473 - __asm__("lcall *(%%esi); cld\n\t"
36474 + __asm__("movw %w6, %%ds\n\t"
36475 + "lcall *%%ss:(%%esi); cld\n\t"
36476 + "push %%ss\n\t"
36477 + "pop %%ds\n\t"
36478 "jc 1f\n\t"
36479 "xor %%ah, %%ah\n"
36480 "1:"
36481 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36482 "c" (value),
36483 "b" (bx),
36484 "D" ((long)reg),
36485 - "S" (&pci_indirect));
36486 + "S" (&pci_indirect),
36487 + "r" (__PCIBIOS_DS));
36488 break;
36489 case 2:
36490 - __asm__("lcall *(%%esi); cld\n\t"
36491 + __asm__("movw %w6, %%ds\n\t"
36492 + "lcall *%%ss:(%%esi); cld\n\t"
36493 + "push %%ss\n\t"
36494 + "pop %%ds\n\t"
36495 "jc 1f\n\t"
36496 "xor %%ah, %%ah\n"
36497 "1:"
36498 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36499 "c" (value),
36500 "b" (bx),
36501 "D" ((long)reg),
36502 - "S" (&pci_indirect));
36503 + "S" (&pci_indirect),
36504 + "r" (__PCIBIOS_DS));
36505 break;
36506 case 4:
36507 - __asm__("lcall *(%%esi); cld\n\t"
36508 + __asm__("movw %w6, %%ds\n\t"
36509 + "lcall *%%ss:(%%esi); cld\n\t"
36510 + "push %%ss\n\t"
36511 + "pop %%ds\n\t"
36512 "jc 1f\n\t"
36513 "xor %%ah, %%ah\n"
36514 "1:"
36515 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36516 "c" (value),
36517 "b" (bx),
36518 "D" ((long)reg),
36519 - "S" (&pci_indirect));
36520 + "S" (&pci_indirect),
36521 + "r" (__PCIBIOS_DS));
36522 break;
36523 }
36524
36525 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
36526
36527 DBG("PCI: Fetching IRQ routing table... ");
36528 __asm__("push %%es\n\t"
36529 + "movw %w8, %%ds\n\t"
36530 "push %%ds\n\t"
36531 "pop %%es\n\t"
36532 - "lcall *(%%esi); cld\n\t"
36533 + "lcall *%%ss:(%%esi); cld\n\t"
36534 "pop %%es\n\t"
36535 + "push %%ss\n\t"
36536 + "pop %%ds\n"
36537 "jc 1f\n\t"
36538 "xor %%ah, %%ah\n"
36539 "1:"
36540 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
36541 "1" (0),
36542 "D" ((long) &opt),
36543 "S" (&pci_indirect),
36544 - "m" (opt)
36545 + "m" (opt),
36546 + "r" (__PCIBIOS_DS)
36547 : "memory");
36548 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
36549 if (ret & 0xff00)
36550 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
36551 {
36552 int ret;
36553
36554 - __asm__("lcall *(%%esi); cld\n\t"
36555 + __asm__("movw %w5, %%ds\n\t"
36556 + "lcall *%%ss:(%%esi); cld\n\t"
36557 + "push %%ss\n\t"
36558 + "pop %%ds\n"
36559 "jc 1f\n\t"
36560 "xor %%ah, %%ah\n"
36561 "1:"
36562 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
36563 : "0" (PCIBIOS_SET_PCI_HW_INT),
36564 "b" ((dev->bus->number << 8) | dev->devfn),
36565 "c" ((irq << 8) | (pin + 10)),
36566 - "S" (&pci_indirect));
36567 + "S" (&pci_indirect),
36568 + "r" (__PCIBIOS_DS));
36569 return !(ret & 0xff00);
36570 }
36571 EXPORT_SYMBOL(pcibios_set_irq_routing);
36572 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
36573 index 9ee3491..872192f 100644
36574 --- a/arch/x86/platform/efi/efi_32.c
36575 +++ b/arch/x86/platform/efi/efi_32.c
36576 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
36577 {
36578 struct desc_ptr gdt_descr;
36579
36580 +#ifdef CONFIG_PAX_KERNEXEC
36581 + struct desc_struct d;
36582 +#endif
36583 +
36584 local_irq_save(efi_rt_eflags);
36585
36586 load_cr3(initial_page_table);
36587 __flush_tlb_all();
36588
36589 +#ifdef CONFIG_PAX_KERNEXEC
36590 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
36591 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
36592 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
36593 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
36594 +#endif
36595 +
36596 gdt_descr.address = __pa(get_cpu_gdt_table(0));
36597 gdt_descr.size = GDT_SIZE - 1;
36598 load_gdt(&gdt_descr);
36599 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
36600 {
36601 struct desc_ptr gdt_descr;
36602
36603 +#ifdef CONFIG_PAX_KERNEXEC
36604 + struct desc_struct d;
36605 +
36606 + memset(&d, 0, sizeof d);
36607 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
36608 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
36609 +#endif
36610 +
36611 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
36612 gdt_descr.size = GDT_SIZE - 1;
36613 load_gdt(&gdt_descr);
36614
36615 +#ifdef CONFIG_PAX_PER_CPU_PGD
36616 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
36617 +#else
36618 load_cr3(swapper_pg_dir);
36619 +#endif
36620 +
36621 __flush_tlb_all();
36622
36623 local_irq_restore(efi_rt_eflags);
36624 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
36625 index 290d397..3906bcd 100644
36626 --- a/arch/x86/platform/efi/efi_64.c
36627 +++ b/arch/x86/platform/efi/efi_64.c
36628 @@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
36629 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
36630 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
36631 }
36632 +
36633 +#ifdef CONFIG_PAX_PER_CPU_PGD
36634 + load_cr3(swapper_pg_dir);
36635 +#endif
36636 +
36637 __flush_tlb_all();
36638 }
36639
36640 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
36641 for (pgd = 0; pgd < n_pgds; pgd++)
36642 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
36643 kfree(save_pgd);
36644 +
36645 +#ifdef CONFIG_PAX_PER_CPU_PGD
36646 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
36647 +#endif
36648 +
36649 __flush_tlb_all();
36650 local_irq_restore(efi_flags);
36651 early_code_mapping_set_exec(0);
36652 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
36653 index fbe66e6..eae5e38 100644
36654 --- a/arch/x86/platform/efi/efi_stub_32.S
36655 +++ b/arch/x86/platform/efi/efi_stub_32.S
36656 @@ -6,7 +6,9 @@
36657 */
36658
36659 #include <linux/linkage.h>
36660 +#include <linux/init.h>
36661 #include <asm/page_types.h>
36662 +#include <asm/segment.h>
36663
36664 /*
36665 * efi_call_phys(void *, ...) is a function with variable parameters.
36666 @@ -20,7 +22,7 @@
36667 * service functions will comply with gcc calling convention, too.
36668 */
36669
36670 -.text
36671 +__INIT
36672 ENTRY(efi_call_phys)
36673 /*
36674 * 0. The function can only be called in Linux kernel. So CS has been
36675 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
36676 * The mapping of lower virtual memory has been created in prelog and
36677 * epilog.
36678 */
36679 - movl $1f, %edx
36680 - subl $__PAGE_OFFSET, %edx
36681 - jmp *%edx
36682 +#ifdef CONFIG_PAX_KERNEXEC
36683 + movl $(__KERNEXEC_EFI_DS), %edx
36684 + mov %edx, %ds
36685 + mov %edx, %es
36686 + mov %edx, %ss
36687 + addl $2f,(1f)
36688 + ljmp *(1f)
36689 +
36690 +__INITDATA
36691 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
36692 +.previous
36693 +
36694 +2:
36695 + subl $2b,(1b)
36696 +#else
36697 + jmp 1f-__PAGE_OFFSET
36698 1:
36699 +#endif
36700
36701 /*
36702 * 2. Now on the top of stack is the return
36703 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
36704 * parameter 2, ..., param n. To make things easy, we save the return
36705 * address of efi_call_phys in a global variable.
36706 */
36707 - popl %edx
36708 - movl %edx, saved_return_addr
36709 - /* get the function pointer into ECX*/
36710 - popl %ecx
36711 - movl %ecx, efi_rt_function_ptr
36712 - movl $2f, %edx
36713 - subl $__PAGE_OFFSET, %edx
36714 - pushl %edx
36715 + popl (saved_return_addr)
36716 + popl (efi_rt_function_ptr)
36717
36718 /*
36719 * 3. Clear PG bit in %CR0.
36720 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
36721 /*
36722 * 5. Call the physical function.
36723 */
36724 - jmp *%ecx
36725 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
36726
36727 -2:
36728 /*
36729 * 6. After EFI runtime service returns, control will return to
36730 * following instruction. We'd better readjust stack pointer first.
36731 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
36732 movl %cr0, %edx
36733 orl $0x80000000, %edx
36734 movl %edx, %cr0
36735 - jmp 1f
36736 -1:
36737 +
36738 /*
36739 * 8. Now restore the virtual mode from flat mode by
36740 * adding EIP with PAGE_OFFSET.
36741 */
36742 - movl $1f, %edx
36743 - jmp *%edx
36744 +#ifdef CONFIG_PAX_KERNEXEC
36745 + movl $(__KERNEL_DS), %edx
36746 + mov %edx, %ds
36747 + mov %edx, %es
36748 + mov %edx, %ss
36749 + ljmp $(__KERNEL_CS),$1f
36750 +#else
36751 + jmp 1f+__PAGE_OFFSET
36752 +#endif
36753 1:
36754
36755 /*
36756 * 9. Balance the stack. And because EAX contain the return value,
36757 * we'd better not clobber it.
36758 */
36759 - leal efi_rt_function_ptr, %edx
36760 - movl (%edx), %ecx
36761 - pushl %ecx
36762 + pushl (efi_rt_function_ptr)
36763
36764 /*
36765 - * 10. Push the saved return address onto the stack and return.
36766 + * 10. Return to the saved return address.
36767 */
36768 - leal saved_return_addr, %edx
36769 - movl (%edx), %ecx
36770 - pushl %ecx
36771 - ret
36772 + jmpl *(saved_return_addr)
36773 ENDPROC(efi_call_phys)
36774 .previous
36775
36776 -.data
36777 +__INITDATA
36778 saved_return_addr:
36779 .long 0
36780 efi_rt_function_ptr:
36781 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
36782 index 5fcda72..b9d1d65 100644
36783 --- a/arch/x86/platform/efi/efi_stub_64.S
36784 +++ b/arch/x86/platform/efi/efi_stub_64.S
36785 @@ -11,6 +11,7 @@
36786 #include <asm/msr.h>
36787 #include <asm/processor-flags.h>
36788 #include <asm/page_types.h>
36789 +#include <asm/alternative-asm.h>
36790
36791 #define SAVE_XMM \
36792 mov %rsp, %rax; \
36793 @@ -88,6 +89,7 @@ ENTRY(efi_call)
36794 RESTORE_PGT
36795 addq $48, %rsp
36796 RESTORE_XMM
36797 + pax_force_retaddr 0, 1
36798 ret
36799 ENDPROC(efi_call)
36800
36801 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
36802 index 1bbedc4..eb795b5 100644
36803 --- a/arch/x86/platform/intel-mid/intel-mid.c
36804 +++ b/arch/x86/platform/intel-mid/intel-mid.c
36805 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
36806 {
36807 };
36808
36809 -static void intel_mid_reboot(void)
36810 +static void __noreturn intel_mid_reboot(void)
36811 {
36812 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
36813 + BUG();
36814 }
36815
36816 static unsigned long __init intel_mid_calibrate_tsc(void)
36817 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
36818 index d6ee929..3637cb5 100644
36819 --- a/arch/x86/platform/olpc/olpc_dt.c
36820 +++ b/arch/x86/platform/olpc/olpc_dt.c
36821 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
36822 return res;
36823 }
36824
36825 -static struct of_pdt_ops prom_olpc_ops __initdata = {
36826 +static struct of_pdt_ops prom_olpc_ops __initconst = {
36827 .nextprop = olpc_dt_nextprop,
36828 .getproplen = olpc_dt_getproplen,
36829 .getproperty = olpc_dt_getproperty,
36830 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
36831 index 424f4c9..f2a2988 100644
36832 --- a/arch/x86/power/cpu.c
36833 +++ b/arch/x86/power/cpu.c
36834 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
36835 static void fix_processor_context(void)
36836 {
36837 int cpu = smp_processor_id();
36838 - struct tss_struct *t = &per_cpu(init_tss, cpu);
36839 -#ifdef CONFIG_X86_64
36840 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
36841 - tss_desc tss;
36842 -#endif
36843 + struct tss_struct *t = init_tss + cpu;
36844 +
36845 set_tss_desc(cpu, t); /*
36846 * This just modifies memory; should not be
36847 * necessary. But... This is necessary, because
36848 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
36849 */
36850
36851 #ifdef CONFIG_X86_64
36852 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
36853 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
36854 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
36855 -
36856 syscall_init(); /* This sets MSR_*STAR and related */
36857 #endif
36858 load_TR_desc(); /* This does ltr */
36859 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
36860 index bad628a..a102610 100644
36861 --- a/arch/x86/realmode/init.c
36862 +++ b/arch/x86/realmode/init.c
36863 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
36864 __va(real_mode_header->trampoline_header);
36865
36866 #ifdef CONFIG_X86_32
36867 - trampoline_header->start = __pa_symbol(startup_32_smp);
36868 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
36869 +
36870 +#ifdef CONFIG_PAX_KERNEXEC
36871 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
36872 +#endif
36873 +
36874 + trampoline_header->boot_cs = __BOOT_CS;
36875 trampoline_header->gdt_limit = __BOOT_DS + 7;
36876 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
36877 #else
36878 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
36879 *trampoline_cr4_features = read_cr4();
36880
36881 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
36882 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
36883 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
36884 trampoline_pgd[511] = init_level4_pgt[511].pgd;
36885 #endif
36886 }
36887 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
36888 index 7c0d7be..d24dc88 100644
36889 --- a/arch/x86/realmode/rm/Makefile
36890 +++ b/arch/x86/realmode/rm/Makefile
36891 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
36892
36893 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
36894 -I$(srctree)/arch/x86/boot
36895 +ifdef CONSTIFY_PLUGIN
36896 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
36897 +endif
36898 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
36899 GCOV_PROFILE := n
36900 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
36901 index a28221d..93c40f1 100644
36902 --- a/arch/x86/realmode/rm/header.S
36903 +++ b/arch/x86/realmode/rm/header.S
36904 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
36905 #endif
36906 /* APM/BIOS reboot */
36907 .long pa_machine_real_restart_asm
36908 -#ifdef CONFIG_X86_64
36909 +#ifdef CONFIG_X86_32
36910 + .long __KERNEL_CS
36911 +#else
36912 .long __KERNEL32_CS
36913 #endif
36914 END(real_mode_header)
36915 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
36916 index 48ddd76..c26749f 100644
36917 --- a/arch/x86/realmode/rm/trampoline_32.S
36918 +++ b/arch/x86/realmode/rm/trampoline_32.S
36919 @@ -24,6 +24,12 @@
36920 #include <asm/page_types.h>
36921 #include "realmode.h"
36922
36923 +#ifdef CONFIG_PAX_KERNEXEC
36924 +#define ta(X) (X)
36925 +#else
36926 +#define ta(X) (pa_ ## X)
36927 +#endif
36928 +
36929 .text
36930 .code16
36931
36932 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
36933
36934 cli # We should be safe anyway
36935
36936 - movl tr_start, %eax # where we need to go
36937 -
36938 movl $0xA5A5A5A5, trampoline_status
36939 # write marker for master knows we're running
36940
36941 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
36942 movw $1, %dx # protected mode (PE) bit
36943 lmsw %dx # into protected mode
36944
36945 - ljmpl $__BOOT_CS, $pa_startup_32
36946 + ljmpl *(trampoline_header)
36947
36948 .section ".text32","ax"
36949 .code32
36950 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
36951 .balign 8
36952 GLOBAL(trampoline_header)
36953 tr_start: .space 4
36954 - tr_gdt_pad: .space 2
36955 + tr_boot_cs: .space 2
36956 tr_gdt: .space 6
36957 END(trampoline_header)
36958
36959 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
36960 index dac7b20..72dbaca 100644
36961 --- a/arch/x86/realmode/rm/trampoline_64.S
36962 +++ b/arch/x86/realmode/rm/trampoline_64.S
36963 @@ -93,6 +93,7 @@ ENTRY(startup_32)
36964 movl %edx, %gs
36965
36966 movl pa_tr_cr4, %eax
36967 + andl $~X86_CR4_PCIDE, %eax
36968 movl %eax, %cr4 # Enable PAE mode
36969
36970 # Setup trampoline 4 level pagetables
36971 @@ -106,7 +107,7 @@ ENTRY(startup_32)
36972 wrmsr
36973
36974 # Enable paging and in turn activate Long Mode
36975 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
36976 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
36977 movl %eax, %cr0
36978
36979 /*
36980 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
36981 index 9e7e147..25a4158 100644
36982 --- a/arch/x86/realmode/rm/wakeup_asm.S
36983 +++ b/arch/x86/realmode/rm/wakeup_asm.S
36984 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
36985 lgdtl pmode_gdt
36986
36987 /* This really couldn't... */
36988 - movl pmode_entry, %eax
36989 movl pmode_cr0, %ecx
36990 movl %ecx, %cr0
36991 - ljmpl $__KERNEL_CS, $pa_startup_32
36992 - /* -> jmp *%eax in trampoline_32.S */
36993 +
36994 + ljmpl *pmode_entry
36995 #else
36996 jmp trampoline_start
36997 #endif
36998 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
36999 index 604a37e..e49702a 100644
37000 --- a/arch/x86/tools/Makefile
37001 +++ b/arch/x86/tools/Makefile
37002 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
37003
37004 $(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c
37005
37006 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
37007 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
37008 hostprogs-y += relocs
37009 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
37010 PHONY += relocs
37011 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
37012 index bbb1d22..e505211 100644
37013 --- a/arch/x86/tools/relocs.c
37014 +++ b/arch/x86/tools/relocs.c
37015 @@ -1,5 +1,7 @@
37016 /* This is included from relocs_32/64.c */
37017
37018 +#include "../../../include/generated/autoconf.h"
37019 +
37020 #define ElfW(type) _ElfW(ELF_BITS, type)
37021 #define _ElfW(bits, type) __ElfW(bits, type)
37022 #define __ElfW(bits, type) Elf##bits##_##type
37023 @@ -11,6 +13,7 @@
37024 #define Elf_Sym ElfW(Sym)
37025
37026 static Elf_Ehdr ehdr;
37027 +static Elf_Phdr *phdr;
37028
37029 struct relocs {
37030 uint32_t *offset;
37031 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
37032 }
37033 }
37034
37035 +static void read_phdrs(FILE *fp)
37036 +{
37037 + unsigned int i;
37038 +
37039 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
37040 + if (!phdr) {
37041 + die("Unable to allocate %d program headers\n",
37042 + ehdr.e_phnum);
37043 + }
37044 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
37045 + die("Seek to %d failed: %s\n",
37046 + ehdr.e_phoff, strerror(errno));
37047 + }
37048 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
37049 + die("Cannot read ELF program headers: %s\n",
37050 + strerror(errno));
37051 + }
37052 + for(i = 0; i < ehdr.e_phnum; i++) {
37053 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
37054 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
37055 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
37056 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
37057 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
37058 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
37059 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
37060 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
37061 + }
37062 +
37063 +}
37064 +
37065 static void read_shdrs(FILE *fp)
37066 {
37067 - int i;
37068 + unsigned int i;
37069 Elf_Shdr shdr;
37070
37071 secs = calloc(ehdr.e_shnum, sizeof(struct section));
37072 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
37073
37074 static void read_strtabs(FILE *fp)
37075 {
37076 - int i;
37077 + unsigned int i;
37078 for (i = 0; i < ehdr.e_shnum; i++) {
37079 struct section *sec = &secs[i];
37080 if (sec->shdr.sh_type != SHT_STRTAB) {
37081 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
37082
37083 static void read_symtabs(FILE *fp)
37084 {
37085 - int i,j;
37086 + unsigned int i,j;
37087 for (i = 0; i < ehdr.e_shnum; i++) {
37088 struct section *sec = &secs[i];
37089 if (sec->shdr.sh_type != SHT_SYMTAB) {
37090 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
37091 }
37092
37093
37094 -static void read_relocs(FILE *fp)
37095 +static void read_relocs(FILE *fp, int use_real_mode)
37096 {
37097 - int i,j;
37098 + unsigned int i,j;
37099 + uint32_t base;
37100 +
37101 for (i = 0; i < ehdr.e_shnum; i++) {
37102 struct section *sec = &secs[i];
37103 if (sec->shdr.sh_type != SHT_REL_TYPE) {
37104 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
37105 die("Cannot read symbol table: %s\n",
37106 strerror(errno));
37107 }
37108 + base = 0;
37109 +
37110 +#ifdef CONFIG_X86_32
37111 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
37112 + if (phdr[j].p_type != PT_LOAD )
37113 + continue;
37114 + if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
37115 + continue;
37116 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
37117 + break;
37118 + }
37119 +#endif
37120 +
37121 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
37122 Elf_Rel *rel = &sec->reltab[j];
37123 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
37124 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
37125 rel->r_info = elf_xword_to_cpu(rel->r_info);
37126 #if (SHT_REL_TYPE == SHT_RELA)
37127 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
37128 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
37129
37130 static void print_absolute_symbols(void)
37131 {
37132 - int i;
37133 + unsigned int i;
37134 const char *format;
37135
37136 if (ELF_BITS == 64)
37137 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
37138 for (i = 0; i < ehdr.e_shnum; i++) {
37139 struct section *sec = &secs[i];
37140 char *sym_strtab;
37141 - int j;
37142 + unsigned int j;
37143
37144 if (sec->shdr.sh_type != SHT_SYMTAB) {
37145 continue;
37146 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
37147
37148 static void print_absolute_relocs(void)
37149 {
37150 - int i, printed = 0;
37151 + unsigned int i, printed = 0;
37152 const char *format;
37153
37154 if (ELF_BITS == 64)
37155 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
37156 struct section *sec_applies, *sec_symtab;
37157 char *sym_strtab;
37158 Elf_Sym *sh_symtab;
37159 - int j;
37160 + unsigned int j;
37161 if (sec->shdr.sh_type != SHT_REL_TYPE) {
37162 continue;
37163 }
37164 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
37165 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
37166 Elf_Sym *sym, const char *symname))
37167 {
37168 - int i;
37169 + unsigned int i;
37170 /* Walk through the relocations */
37171 for (i = 0; i < ehdr.e_shnum; i++) {
37172 char *sym_strtab;
37173 Elf_Sym *sh_symtab;
37174 struct section *sec_applies, *sec_symtab;
37175 - int j;
37176 + unsigned int j;
37177 struct section *sec = &secs[i];
37178
37179 if (sec->shdr.sh_type != SHT_REL_TYPE) {
37180 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
37181 {
37182 unsigned r_type = ELF32_R_TYPE(rel->r_info);
37183 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
37184 + char *sym_strtab = sec->link->link->strtab;
37185 +
37186 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
37187 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
37188 + return 0;
37189 +
37190 +#ifdef CONFIG_PAX_KERNEXEC
37191 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
37192 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
37193 + return 0;
37194 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
37195 + return 0;
37196 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
37197 + return 0;
37198 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
37199 + return 0;
37200 +#endif
37201
37202 switch (r_type) {
37203 case R_386_NONE:
37204 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
37205
37206 static void emit_relocs(int as_text, int use_real_mode)
37207 {
37208 - int i;
37209 + unsigned int i;
37210 int (*write_reloc)(uint32_t, FILE *) = write32;
37211 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
37212 const char *symname);
37213 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
37214 {
37215 regex_init(use_real_mode);
37216 read_ehdr(fp);
37217 + read_phdrs(fp);
37218 read_shdrs(fp);
37219 read_strtabs(fp);
37220 read_symtabs(fp);
37221 - read_relocs(fp);
37222 + read_relocs(fp, use_real_mode);
37223 if (ELF_BITS == 64)
37224 percpu_init();
37225 if (show_absolute_syms) {
37226 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
37227 index f40281e..92728c9 100644
37228 --- a/arch/x86/um/mem_32.c
37229 +++ b/arch/x86/um/mem_32.c
37230 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
37231 gate_vma.vm_start = FIXADDR_USER_START;
37232 gate_vma.vm_end = FIXADDR_USER_END;
37233 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
37234 - gate_vma.vm_page_prot = __P101;
37235 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
37236
37237 return 0;
37238 }
37239 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
37240 index 80ffa5b..a33bd15 100644
37241 --- a/arch/x86/um/tls_32.c
37242 +++ b/arch/x86/um/tls_32.c
37243 @@ -260,7 +260,7 @@ out:
37244 if (unlikely(task == current &&
37245 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
37246 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
37247 - "without flushed TLS.", current->pid);
37248 + "without flushed TLS.", task_pid_nr(current));
37249 }
37250
37251 return 0;
37252 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
37253 index 61b04fe..3134230 100644
37254 --- a/arch/x86/vdso/Makefile
37255 +++ b/arch/x86/vdso/Makefile
37256 @@ -170,7 +170,7 @@ quiet_cmd_vdso = VDSO $@
37257 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
37258 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
37259
37260 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
37261 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
37262 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
37263 GCOV_PROFILE := n
37264
37265 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
37266 index e4f7781..ab5ab26 100644
37267 --- a/arch/x86/vdso/vdso32-setup.c
37268 +++ b/arch/x86/vdso/vdso32-setup.c
37269 @@ -14,6 +14,7 @@
37270 #include <asm/cpufeature.h>
37271 #include <asm/processor.h>
37272 #include <asm/vdso.h>
37273 +#include <asm/mman.h>
37274
37275 #ifdef CONFIG_COMPAT_VDSO
37276 #define VDSO_DEFAULT 0
37277 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
37278 index 5a5176d..e570acd 100644
37279 --- a/arch/x86/vdso/vma.c
37280 +++ b/arch/x86/vdso/vma.c
37281 @@ -16,10 +16,9 @@
37282 #include <asm/vdso.h>
37283 #include <asm/page.h>
37284 #include <asm/hpet.h>
37285 +#include <asm/mman.h>
37286
37287 #if defined(CONFIG_X86_64)
37288 -unsigned int __read_mostly vdso64_enabled = 1;
37289 -
37290 extern unsigned short vdso_sync_cpuid;
37291 #endif
37292
37293 @@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
37294 .pages = no_pages,
37295 };
37296
37297 +#ifdef CONFIG_PAX_RANDMMAP
37298 + if (mm->pax_flags & MF_PAX_RANDMMAP)
37299 + calculate_addr = false;
37300 +#endif
37301 +
37302 if (calculate_addr) {
37303 addr = vdso_addr(current->mm->start_stack,
37304 image->sym_end_mapping);
37305 @@ -110,13 +114,13 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
37306
37307 down_write(&mm->mmap_sem);
37308
37309 - addr = get_unmapped_area(NULL, addr, image->sym_end_mapping, 0, 0);
37310 + addr = get_unmapped_area(NULL, addr, image->sym_end_mapping, 0, MAP_EXECUTABLE);
37311 if (IS_ERR_VALUE(addr)) {
37312 ret = addr;
37313 goto up_fail;
37314 }
37315
37316 - current->mm->context.vdso = (void __user *)addr;
37317 + mm->context.vdso = addr;
37318
37319 /*
37320 * MAYWRITE to allow gdb to COW and set breakpoints
37321 @@ -161,15 +165,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
37322 hpet_address >> PAGE_SHIFT,
37323 PAGE_SIZE,
37324 pgprot_noncached(PAGE_READONLY));
37325 -
37326 - if (ret)
37327 - goto up_fail;
37328 }
37329 #endif
37330
37331 up_fail:
37332 if (ret)
37333 - current->mm->context.vdso = NULL;
37334 + current->mm->context.vdso = 0;
37335
37336 up_write(&mm->mmap_sem);
37337 return ret;
37338 @@ -189,8 +190,8 @@ static int load_vdso32(void)
37339
37340 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
37341 current_thread_info()->sysenter_return =
37342 - current->mm->context.vdso +
37343 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
37344 + (void __force_user *)(current->mm->context.vdso +
37345 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
37346
37347 return 0;
37348 }
37349 @@ -199,9 +200,6 @@ static int load_vdso32(void)
37350 #ifdef CONFIG_X86_64
37351 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
37352 {
37353 - if (!vdso64_enabled)
37354 - return 0;
37355 -
37356 return map_vdso(&vdso_image_64, true);
37357 }
37358
37359 @@ -210,12 +208,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
37360 int uses_interp)
37361 {
37362 #ifdef CONFIG_X86_X32_ABI
37363 - if (test_thread_flag(TIF_X32)) {
37364 - if (!vdso64_enabled)
37365 - return 0;
37366 -
37367 + if (test_thread_flag(TIF_X32))
37368 return map_vdso(&vdso_image_x32, true);
37369 - }
37370 #endif
37371
37372 return load_vdso32();
37373 @@ -227,12 +221,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
37374 return load_vdso32();
37375 }
37376 #endif
37377 -
37378 -#ifdef CONFIG_X86_64
37379 -static __init int vdso_setup(char *s)
37380 -{
37381 - vdso64_enabled = simple_strtoul(s, NULL, 0);
37382 - return 0;
37383 -}
37384 -__setup("vdso=", vdso_setup);
37385 -#endif
37386 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
37387 index e88fda8..76ce7ce 100644
37388 --- a/arch/x86/xen/Kconfig
37389 +++ b/arch/x86/xen/Kconfig
37390 @@ -9,6 +9,7 @@ config XEN
37391 select XEN_HAVE_PVMMU
37392 depends on X86_64 || (X86_32 && X86_PAE)
37393 depends on X86_TSC
37394 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
37395 help
37396 This is the Linux Xen port. Enabling this will allow the
37397 kernel to boot in a paravirtualized environment under the
37398 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
37399 index ffb101e..98c0ecf 100644
37400 --- a/arch/x86/xen/enlighten.c
37401 +++ b/arch/x86/xen/enlighten.c
37402 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
37403
37404 struct shared_info xen_dummy_shared_info;
37405
37406 -void *xen_initial_gdt;
37407 -
37408 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
37409 __read_mostly int xen_have_vector_callback;
37410 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
37411 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
37412 {
37413 unsigned long va = dtr->address;
37414 unsigned int size = dtr->size + 1;
37415 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
37416 - unsigned long frames[pages];
37417 + unsigned long frames[65536 / PAGE_SIZE];
37418 int f;
37419
37420 /*
37421 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
37422 {
37423 unsigned long va = dtr->address;
37424 unsigned int size = dtr->size + 1;
37425 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
37426 - unsigned long frames[pages];
37427 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
37428 int f;
37429
37430 /*
37431 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
37432 * 8-byte entries, or 16 4k pages..
37433 */
37434
37435 - BUG_ON(size > 65536);
37436 + BUG_ON(size > GDT_SIZE);
37437 BUG_ON(va & ~PAGE_MASK);
37438
37439 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
37440 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
37441 return 0;
37442 }
37443
37444 -static void set_xen_basic_apic_ops(void)
37445 +static void __init set_xen_basic_apic_ops(void)
37446 {
37447 apic->read = xen_apic_read;
37448 apic->write = xen_apic_write;
37449 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
37450 #endif
37451 };
37452
37453 -static void xen_reboot(int reason)
37454 +static __noreturn void xen_reboot(int reason)
37455 {
37456 struct sched_shutdown r = { .reason = reason };
37457
37458 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
37459 - BUG();
37460 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
37461 + BUG();
37462 }
37463
37464 -static void xen_restart(char *msg)
37465 +static __noreturn void xen_restart(char *msg)
37466 {
37467 xen_reboot(SHUTDOWN_reboot);
37468 }
37469
37470 -static void xen_emergency_restart(void)
37471 +static __noreturn void xen_emergency_restart(void)
37472 {
37473 xen_reboot(SHUTDOWN_reboot);
37474 }
37475
37476 -static void xen_machine_halt(void)
37477 +static __noreturn void xen_machine_halt(void)
37478 {
37479 xen_reboot(SHUTDOWN_poweroff);
37480 }
37481
37482 -static void xen_machine_power_off(void)
37483 +static __noreturn void xen_machine_power_off(void)
37484 {
37485 if (pm_power_off)
37486 pm_power_off();
37487 @@ -1568,7 +1564,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
37488 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
37489
37490 /* Work out if we support NX */
37491 - x86_configure_nx();
37492 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
37493 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
37494 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
37495 + unsigned l, h;
37496 +
37497 + __supported_pte_mask |= _PAGE_NX;
37498 + rdmsr(MSR_EFER, l, h);
37499 + l |= EFER_NX;
37500 + wrmsr(MSR_EFER, l, h);
37501 + }
37502 +#endif
37503
37504 /* Get mfn list */
37505 xen_build_dynamic_phys_to_machine();
37506 @@ -1596,13 +1602,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
37507
37508 machine_ops = xen_machine_ops;
37509
37510 - /*
37511 - * The only reliable way to retain the initial address of the
37512 - * percpu gdt_page is to remember it here, so we can go and
37513 - * mark it RW later, when the initial percpu area is freed.
37514 - */
37515 - xen_initial_gdt = &per_cpu(gdt_page, 0);
37516 -
37517 xen_smp_init();
37518
37519 #ifdef CONFIG_ACPI_NUMA
37520 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
37521 index e8a1201..046c66c 100644
37522 --- a/arch/x86/xen/mmu.c
37523 +++ b/arch/x86/xen/mmu.c
37524 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
37525 return val;
37526 }
37527
37528 -static pteval_t pte_pfn_to_mfn(pteval_t val)
37529 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
37530 {
37531 if (val & _PAGE_PRESENT) {
37532 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
37533 @@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
37534 /* L3_k[510] -> level2_kernel_pgt
37535 * L3_i[511] -> level2_fixmap_pgt */
37536 convert_pfn_mfn(level3_kernel_pgt);
37537 + convert_pfn_mfn(level3_vmalloc_start_pgt);
37538 + convert_pfn_mfn(level3_vmalloc_end_pgt);
37539 + convert_pfn_mfn(level3_vmemmap_pgt);
37540 }
37541 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
37542 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
37543 @@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
37544 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
37545 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
37546 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
37547 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
37548 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
37549 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
37550 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
37551 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
37552 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
37553 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
37554 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
37555
37556 @@ -2120,6 +2127,7 @@ static void __init xen_post_allocator_init(void)
37557 pv_mmu_ops.set_pud = xen_set_pud;
37558 #if PAGETABLE_LEVELS == 4
37559 pv_mmu_ops.set_pgd = xen_set_pgd;
37560 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
37561 #endif
37562
37563 /* This will work as long as patching hasn't happened yet
37564 @@ -2198,6 +2206,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
37565 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
37566 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
37567 .set_pgd = xen_set_pgd_hyper,
37568 + .set_pgd_batched = xen_set_pgd_hyper,
37569
37570 .alloc_pud = xen_alloc_pmd_init,
37571 .release_pud = xen_release_pmd_init,
37572 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
37573 index 7005974..54fb05f 100644
37574 --- a/arch/x86/xen/smp.c
37575 +++ b/arch/x86/xen/smp.c
37576 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
37577
37578 if (xen_pv_domain()) {
37579 if (!xen_feature(XENFEAT_writable_page_tables))
37580 - /* We've switched to the "real" per-cpu gdt, so make
37581 - * sure the old memory can be recycled. */
37582 - make_lowmem_page_readwrite(xen_initial_gdt);
37583 -
37584 #ifdef CONFIG_X86_32
37585 /*
37586 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
37587 * expects __USER_DS
37588 */
37589 - loadsegment(ds, __USER_DS);
37590 - loadsegment(es, __USER_DS);
37591 + loadsegment(ds, __KERNEL_DS);
37592 + loadsegment(es, __KERNEL_DS);
37593 #endif
37594
37595 xen_filter_cpu_maps();
37596 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
37597 #ifdef CONFIG_X86_32
37598 /* Note: PVH is not yet supported on x86_32. */
37599 ctxt->user_regs.fs = __KERNEL_PERCPU;
37600 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
37601 + savesegment(gs, ctxt->user_regs.gs);
37602 #endif
37603 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
37604
37605 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
37606 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
37607 ctxt->flags = VGCF_IN_KERNEL;
37608 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
37609 - ctxt->user_regs.ds = __USER_DS;
37610 - ctxt->user_regs.es = __USER_DS;
37611 + ctxt->user_regs.ds = __KERNEL_DS;
37612 + ctxt->user_regs.es = __KERNEL_DS;
37613 ctxt->user_regs.ss = __KERNEL_DS;
37614
37615 xen_copy_trap_info(ctxt->trap_ctxt);
37616 @@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
37617 int rc;
37618
37619 per_cpu(current_task, cpu) = idle;
37620 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
37621 #ifdef CONFIG_X86_32
37622 irq_ctx_init(cpu);
37623 #else
37624 clear_tsk_thread_flag(idle, TIF_FORK);
37625 #endif
37626 - per_cpu(kernel_stack, cpu) =
37627 - (unsigned long)task_stack_page(idle) -
37628 - KERNEL_STACK_OFFSET + THREAD_SIZE;
37629 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
37630
37631 xen_setup_runstate_info(cpu);
37632 xen_setup_timer(cpu);
37633 @@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
37634
37635 void __init xen_smp_init(void)
37636 {
37637 - smp_ops = xen_smp_ops;
37638 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
37639 xen_fill_possible_map();
37640 }
37641
37642 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
37643 index fd92a64..1f72641 100644
37644 --- a/arch/x86/xen/xen-asm_32.S
37645 +++ b/arch/x86/xen/xen-asm_32.S
37646 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
37647 pushw %fs
37648 movl $(__KERNEL_PERCPU), %eax
37649 movl %eax, %fs
37650 - movl %fs:xen_vcpu, %eax
37651 + mov PER_CPU_VAR(xen_vcpu), %eax
37652 POP_FS
37653 #else
37654 movl %ss:xen_vcpu, %eax
37655 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
37656 index 485b695..fda3e7c 100644
37657 --- a/arch/x86/xen/xen-head.S
37658 +++ b/arch/x86/xen/xen-head.S
37659 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
37660 #ifdef CONFIG_X86_32
37661 mov %esi,xen_start_info
37662 mov $init_thread_union+THREAD_SIZE,%esp
37663 +#ifdef CONFIG_SMP
37664 + movl $cpu_gdt_table,%edi
37665 + movl $__per_cpu_load,%eax
37666 + movw %ax,__KERNEL_PERCPU + 2(%edi)
37667 + rorl $16,%eax
37668 + movb %al,__KERNEL_PERCPU + 4(%edi)
37669 + movb %ah,__KERNEL_PERCPU + 7(%edi)
37670 + movl $__per_cpu_end - 1,%eax
37671 + subl $__per_cpu_start,%eax
37672 + movw %ax,__KERNEL_PERCPU + 0(%edi)
37673 +#endif
37674 #else
37675 mov %rsi,xen_start_info
37676 mov $init_thread_union+THREAD_SIZE,%rsp
37677 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
37678 index 97d8765..c4526ec 100644
37679 --- a/arch/x86/xen/xen-ops.h
37680 +++ b/arch/x86/xen/xen-ops.h
37681 @@ -10,8 +10,6 @@
37682 extern const char xen_hypervisor_callback[];
37683 extern const char xen_failsafe_callback[];
37684
37685 -extern void *xen_initial_gdt;
37686 -
37687 struct trap_info;
37688 void xen_copy_trap_info(struct trap_info *traps);
37689
37690 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
37691 index 525bd3d..ef888b1 100644
37692 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
37693 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
37694 @@ -119,9 +119,9 @@
37695 ----------------------------------------------------------------------*/
37696
37697 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
37698 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
37699 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
37700 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
37701 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37702
37703 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
37704 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
37705 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
37706 index 2f33760..835e50a 100644
37707 --- a/arch/xtensa/variants/fsf/include/variant/core.h
37708 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
37709 @@ -11,6 +11,7 @@
37710 #ifndef _XTENSA_CORE_H
37711 #define _XTENSA_CORE_H
37712
37713 +#include <linux/const.h>
37714
37715 /****************************************************************************
37716 Parameters Useful for Any Code, USER or PRIVILEGED
37717 @@ -112,9 +113,9 @@
37718 ----------------------------------------------------------------------*/
37719
37720 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
37721 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
37722 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
37723 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
37724 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37725
37726 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
37727 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
37728 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
37729 index af00795..2bb8105 100644
37730 --- a/arch/xtensa/variants/s6000/include/variant/core.h
37731 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
37732 @@ -11,6 +11,7 @@
37733 #ifndef _XTENSA_CORE_CONFIGURATION_H
37734 #define _XTENSA_CORE_CONFIGURATION_H
37735
37736 +#include <linux/const.h>
37737
37738 /****************************************************************************
37739 Parameters Useful for Any Code, USER or PRIVILEGED
37740 @@ -118,9 +119,9 @@
37741 ----------------------------------------------------------------------*/
37742
37743 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
37744 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
37745 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
37746 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
37747 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37748
37749 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
37750 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
37751 diff --git a/block/bio.c b/block/bio.c
37752 index 0ec61c9..93b94060 100644
37753 --- a/block/bio.c
37754 +++ b/block/bio.c
37755 @@ -1159,7 +1159,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
37756 /*
37757 * Overflow, abort
37758 */
37759 - if (end < start)
37760 + if (end < start || end - start > INT_MAX - nr_pages)
37761 return ERR_PTR(-EINVAL);
37762
37763 nr_pages += end - start;
37764 @@ -1293,7 +1293,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
37765 /*
37766 * Overflow, abort
37767 */
37768 - if (end < start)
37769 + if (end < start || end - start > INT_MAX - nr_pages)
37770 return ERR_PTR(-EINVAL);
37771
37772 nr_pages += end - start;
37773 @@ -1555,7 +1555,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
37774 const int read = bio_data_dir(bio) == READ;
37775 struct bio_map_data *bmd = bio->bi_private;
37776 int i;
37777 - char *p = bmd->sgvecs[0].iov_base;
37778 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
37779
37780 bio_for_each_segment_all(bvec, bio, i) {
37781 char *addr = page_address(bvec->bv_page);
37782 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
37783 index 28d227c..d4c0bad 100644
37784 --- a/block/blk-cgroup.c
37785 +++ b/block/blk-cgroup.c
37786 @@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
37787 static struct cgroup_subsys_state *
37788 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
37789 {
37790 - static atomic64_t id_seq = ATOMIC64_INIT(0);
37791 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
37792 struct blkcg *blkcg;
37793
37794 if (!parent_css) {
37795 @@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
37796
37797 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
37798 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
37799 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
37800 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
37801 done:
37802 spin_lock_init(&blkcg->lock);
37803 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
37804 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
37805 index 0736729..2ec3b48 100644
37806 --- a/block/blk-iopoll.c
37807 +++ b/block/blk-iopoll.c
37808 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
37809 }
37810 EXPORT_SYMBOL(blk_iopoll_complete);
37811
37812 -static void blk_iopoll_softirq(struct softirq_action *h)
37813 +static __latent_entropy void blk_iopoll_softirq(void)
37814 {
37815 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
37816 int rearm = 0, budget = blk_iopoll_budget;
37817 diff --git a/block/blk-map.c b/block/blk-map.c
37818 index f890d43..97b0482 100644
37819 --- a/block/blk-map.c
37820 +++ b/block/blk-map.c
37821 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
37822 if (!len || !kbuf)
37823 return -EINVAL;
37824
37825 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
37826 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
37827 if (do_copy)
37828 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
37829 else
37830 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
37831 index 53b1737..08177d2e 100644
37832 --- a/block/blk-softirq.c
37833 +++ b/block/blk-softirq.c
37834 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
37835 * Softirq action handler - move entries to local list and loop over them
37836 * while passing them to the queue registered handler.
37837 */
37838 -static void blk_done_softirq(struct softirq_action *h)
37839 +static __latent_entropy void blk_done_softirq(void)
37840 {
37841 struct list_head *cpu_list, local_list;
37842
37843 diff --git a/block/bsg.c b/block/bsg.c
37844 index ff46add..c4ba8ee 100644
37845 --- a/block/bsg.c
37846 +++ b/block/bsg.c
37847 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
37848 struct sg_io_v4 *hdr, struct bsg_device *bd,
37849 fmode_t has_write_perm)
37850 {
37851 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37852 + unsigned char *cmdptr;
37853 +
37854 if (hdr->request_len > BLK_MAX_CDB) {
37855 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
37856 if (!rq->cmd)
37857 return -ENOMEM;
37858 - }
37859 + cmdptr = rq->cmd;
37860 + } else
37861 + cmdptr = tmpcmd;
37862
37863 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
37864 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
37865 hdr->request_len))
37866 return -EFAULT;
37867
37868 + if (cmdptr != rq->cmd)
37869 + memcpy(rq->cmd, cmdptr, hdr->request_len);
37870 +
37871 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
37872 if (blk_verify_command(rq->cmd, has_write_perm))
37873 return -EPERM;
37874 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
37875 index a0926a6..b2b14b2 100644
37876 --- a/block/compat_ioctl.c
37877 +++ b/block/compat_ioctl.c
37878 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
37879 cgc = compat_alloc_user_space(sizeof(*cgc));
37880 cgc32 = compat_ptr(arg);
37881
37882 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
37883 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
37884 get_user(data, &cgc32->buffer) ||
37885 put_user(compat_ptr(data), &cgc->buffer) ||
37886 copy_in_user(&cgc->buflen, &cgc32->buflen,
37887 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
37888 err |= __get_user(f->spec1, &uf->spec1);
37889 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
37890 err |= __get_user(name, &uf->name);
37891 - f->name = compat_ptr(name);
37892 + f->name = (void __force_kernel *)compat_ptr(name);
37893 if (err) {
37894 err = -EFAULT;
37895 goto out;
37896 diff --git a/block/genhd.c b/block/genhd.c
37897 index 791f419..89f21c4 100644
37898 --- a/block/genhd.c
37899 +++ b/block/genhd.c
37900 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
37901
37902 /*
37903 * Register device numbers dev..(dev+range-1)
37904 - * range must be nonzero
37905 + * Noop if @range is zero.
37906 * The hash chain is sorted on range, so that subranges can override.
37907 */
37908 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
37909 struct kobject *(*probe)(dev_t, int *, void *),
37910 int (*lock)(dev_t, void *), void *data)
37911 {
37912 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
37913 + if (range)
37914 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
37915 }
37916
37917 EXPORT_SYMBOL(blk_register_region);
37918
37919 +/* undo blk_register_region(), noop if @range is zero */
37920 void blk_unregister_region(dev_t devt, unsigned long range)
37921 {
37922 - kobj_unmap(bdev_map, devt, range);
37923 + if (range)
37924 + kobj_unmap(bdev_map, devt, range);
37925 }
37926
37927 EXPORT_SYMBOL(blk_unregister_region);
37928 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
37929 index dc51f46..d5446a8 100644
37930 --- a/block/partitions/efi.c
37931 +++ b/block/partitions/efi.c
37932 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
37933 if (!gpt)
37934 return NULL;
37935
37936 + if (!le32_to_cpu(gpt->num_partition_entries))
37937 + return NULL;
37938 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
37939 + if (!pte)
37940 + return NULL;
37941 +
37942 count = le32_to_cpu(gpt->num_partition_entries) *
37943 le32_to_cpu(gpt->sizeof_partition_entry);
37944 - if (!count)
37945 - return NULL;
37946 - pte = kmalloc(count, GFP_KERNEL);
37947 - if (!pte)
37948 - return NULL;
37949 -
37950 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
37951 (u8 *) pte, count) < count) {
37952 kfree(pte);
37953 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
37954 index 14695c6..27a4636 100644
37955 --- a/block/scsi_ioctl.c
37956 +++ b/block/scsi_ioctl.c
37957 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
37958 return put_user(0, p);
37959 }
37960
37961 -static int sg_get_timeout(struct request_queue *q)
37962 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
37963 {
37964 return jiffies_to_clock_t(q->sg_timeout);
37965 }
37966 @@ -220,8 +220,20 @@ EXPORT_SYMBOL(blk_verify_command);
37967 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
37968 struct sg_io_hdr *hdr, fmode_t mode)
37969 {
37970 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
37971 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37972 + unsigned char *cmdptr;
37973 +
37974 + if (rq->cmd != rq->__cmd)
37975 + cmdptr = rq->cmd;
37976 + else
37977 + cmdptr = tmpcmd;
37978 +
37979 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
37980 return -EFAULT;
37981 +
37982 + if (cmdptr != rq->cmd)
37983 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
37984 +
37985 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
37986 return -EPERM;
37987
37988 @@ -413,6 +425,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37989 int err;
37990 unsigned int in_len, out_len, bytes, opcode, cmdlen;
37991 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
37992 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37993 + unsigned char *cmdptr;
37994
37995 if (!sic)
37996 return -EINVAL;
37997 @@ -446,9 +460,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37998 */
37999 err = -EFAULT;
38000 rq->cmd_len = cmdlen;
38001 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
38002 +
38003 + if (rq->cmd != rq->__cmd)
38004 + cmdptr = rq->cmd;
38005 + else
38006 + cmdptr = tmpcmd;
38007 +
38008 + if (copy_from_user(cmdptr, sic->data, cmdlen))
38009 goto error;
38010
38011 + if (rq->cmd != cmdptr)
38012 + memcpy(rq->cmd, cmdptr, cmdlen);
38013 +
38014 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
38015 goto error;
38016
38017 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
38018 index 7bdd61b..afec999 100644
38019 --- a/crypto/cryptd.c
38020 +++ b/crypto/cryptd.c
38021 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
38022
38023 struct cryptd_blkcipher_request_ctx {
38024 crypto_completion_t complete;
38025 -};
38026 +} __no_const;
38027
38028 struct cryptd_hash_ctx {
38029 struct crypto_shash *child;
38030 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
38031
38032 struct cryptd_aead_request_ctx {
38033 crypto_completion_t complete;
38034 -};
38035 +} __no_const;
38036
38037 static void cryptd_queue_worker(struct work_struct *work);
38038
38039 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
38040 index 309d345..1632720 100644
38041 --- a/crypto/pcrypt.c
38042 +++ b/crypto/pcrypt.c
38043 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
38044 int ret;
38045
38046 pinst->kobj.kset = pcrypt_kset;
38047 - ret = kobject_add(&pinst->kobj, NULL, name);
38048 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
38049 if (!ret)
38050 kobject_uevent(&pinst->kobj, KOBJ_ADD);
38051
38052 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
38053 index 6921c7f..78e1af7 100644
38054 --- a/drivers/acpi/acpica/hwxfsleep.c
38055 +++ b/drivers/acpi/acpica/hwxfsleep.c
38056 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
38057 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
38058
38059 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
38060 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
38061 - acpi_hw_extended_sleep},
38062 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
38063 - acpi_hw_extended_wake_prep},
38064 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
38065 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
38066 + .extended_function = acpi_hw_extended_sleep},
38067 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
38068 + .extended_function = acpi_hw_extended_wake_prep},
38069 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
38070 + .extended_function = acpi_hw_extended_wake}
38071 };
38072
38073 /*
38074 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
38075 index e5bcd91..74f050d 100644
38076 --- a/drivers/acpi/apei/apei-internal.h
38077 +++ b/drivers/acpi/apei/apei-internal.h
38078 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
38079 struct apei_exec_ins_type {
38080 u32 flags;
38081 apei_exec_ins_func_t run;
38082 -};
38083 +} __do_const;
38084
38085 struct apei_exec_context {
38086 u32 ip;
38087 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
38088 index dab7cb7..f0d2994 100644
38089 --- a/drivers/acpi/apei/ghes.c
38090 +++ b/drivers/acpi/apei/ghes.c
38091 @@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
38092 const struct acpi_hest_generic *generic,
38093 const struct acpi_generic_status *estatus)
38094 {
38095 - static atomic_t seqno;
38096 + static atomic_unchecked_t seqno;
38097 unsigned int curr_seqno;
38098 char pfx_seq[64];
38099
38100 @@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
38101 else
38102 pfx = KERN_ERR;
38103 }
38104 - curr_seqno = atomic_inc_return(&seqno);
38105 + curr_seqno = atomic_inc_return_unchecked(&seqno);
38106 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
38107 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
38108 pfx_seq, generic->header.source_id);
38109 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
38110 index a83e3c6..c3d617f 100644
38111 --- a/drivers/acpi/bgrt.c
38112 +++ b/drivers/acpi/bgrt.c
38113 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
38114 if (!bgrt_image)
38115 return -ENODEV;
38116
38117 - bin_attr_image.private = bgrt_image;
38118 - bin_attr_image.size = bgrt_image_size;
38119 + pax_open_kernel();
38120 + *(void **)&bin_attr_image.private = bgrt_image;
38121 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
38122 + pax_close_kernel();
38123
38124 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
38125 if (!bgrt_kobj)
38126 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
38127 index 3d8413d..95f638c 100644
38128 --- a/drivers/acpi/blacklist.c
38129 +++ b/drivers/acpi/blacklist.c
38130 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
38131 u32 is_critical_error;
38132 };
38133
38134 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
38135 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
38136
38137 /*
38138 * POLICY: If *anything* doesn't work, put it on the blacklist.
38139 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
38140 return 0;
38141 }
38142
38143 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
38144 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
38145 {
38146 .callback = dmi_disable_osi_vista,
38147 .ident = "Fujitsu Siemens",
38148 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
38149 index c68e724..e863008 100644
38150 --- a/drivers/acpi/custom_method.c
38151 +++ b/drivers/acpi/custom_method.c
38152 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
38153 struct acpi_table_header table;
38154 acpi_status status;
38155
38156 +#ifdef CONFIG_GRKERNSEC_KMEM
38157 + return -EPERM;
38158 +#endif
38159 +
38160 if (!(*ppos)) {
38161 /* parse the table header to get the table length */
38162 if (count <= sizeof(struct acpi_table_header))
38163 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
38164 index 3dca36d..abaf070 100644
38165 --- a/drivers/acpi/processor_idle.c
38166 +++ b/drivers/acpi/processor_idle.c
38167 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
38168 {
38169 int i, count = CPUIDLE_DRIVER_STATE_START;
38170 struct acpi_processor_cx *cx;
38171 - struct cpuidle_state *state;
38172 + cpuidle_state_no_const *state;
38173 struct cpuidle_driver *drv = &acpi_idle_driver;
38174
38175 if (!pr->flags.power_setup_done)
38176 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
38177 index 38cb978..352c761 100644
38178 --- a/drivers/acpi/sysfs.c
38179 +++ b/drivers/acpi/sysfs.c
38180 @@ -423,11 +423,11 @@ static u32 num_counters;
38181 static struct attribute **all_attrs;
38182 static u32 acpi_gpe_count;
38183
38184 -static struct attribute_group interrupt_stats_attr_group = {
38185 +static attribute_group_no_const interrupt_stats_attr_group = {
38186 .name = "interrupts",
38187 };
38188
38189 -static struct kobj_attribute *counter_attrs;
38190 +static kobj_attribute_no_const *counter_attrs;
38191
38192 static void delete_gpe_attr_array(void)
38193 {
38194 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
38195 index d72ce04..d6ab3c2 100644
38196 --- a/drivers/ata/libahci.c
38197 +++ b/drivers/ata/libahci.c
38198 @@ -1257,7 +1257,7 @@ int ahci_kick_engine(struct ata_port *ap)
38199 }
38200 EXPORT_SYMBOL_GPL(ahci_kick_engine);
38201
38202 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
38203 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
38204 struct ata_taskfile *tf, int is_cmd, u16 flags,
38205 unsigned long timeout_msec)
38206 {
38207 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
38208 index 677c0c1..354b89b 100644
38209 --- a/drivers/ata/libata-core.c
38210 +++ b/drivers/ata/libata-core.c
38211 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
38212 static void ata_dev_xfermask(struct ata_device *dev);
38213 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
38214
38215 -atomic_t ata_print_id = ATOMIC_INIT(0);
38216 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
38217
38218 struct ata_force_param {
38219 const char *name;
38220 @@ -4863,7 +4863,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
38221 struct ata_port *ap;
38222 unsigned int tag;
38223
38224 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38225 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38226 ap = qc->ap;
38227
38228 qc->flags = 0;
38229 @@ -4879,7 +4879,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
38230 struct ata_port *ap;
38231 struct ata_link *link;
38232
38233 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38234 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38235 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
38236 ap = qc->ap;
38237 link = qc->dev->link;
38238 @@ -5983,6 +5983,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
38239 return;
38240
38241 spin_lock(&lock);
38242 + pax_open_kernel();
38243
38244 for (cur = ops->inherits; cur; cur = cur->inherits) {
38245 void **inherit = (void **)cur;
38246 @@ -5996,8 +5997,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
38247 if (IS_ERR(*pp))
38248 *pp = NULL;
38249
38250 - ops->inherits = NULL;
38251 + *(struct ata_port_operations **)&ops->inherits = NULL;
38252
38253 + pax_close_kernel();
38254 spin_unlock(&lock);
38255 }
38256
38257 @@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
38258
38259 /* give ports names and add SCSI hosts */
38260 for (i = 0; i < host->n_ports; i++) {
38261 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
38262 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
38263 host->ports[i]->local_port_no = i + 1;
38264 }
38265
38266 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
38267 index 72691fd..ad104c0 100644
38268 --- a/drivers/ata/libata-scsi.c
38269 +++ b/drivers/ata/libata-scsi.c
38270 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
38271
38272 if (rc)
38273 return rc;
38274 - ap->print_id = atomic_inc_return(&ata_print_id);
38275 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
38276 return 0;
38277 }
38278 EXPORT_SYMBOL_GPL(ata_sas_port_init);
38279 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
38280 index 45b5ab3..98446b8 100644
38281 --- a/drivers/ata/libata.h
38282 +++ b/drivers/ata/libata.h
38283 @@ -53,7 +53,7 @@ enum {
38284 ATA_DNXFER_QUIET = (1 << 31),
38285 };
38286
38287 -extern atomic_t ata_print_id;
38288 +extern atomic_unchecked_t ata_print_id;
38289 extern int atapi_passthru16;
38290 extern int libata_fua;
38291 extern int libata_noacpi;
38292 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
38293 index 4edb1a8..84e1658 100644
38294 --- a/drivers/ata/pata_arasan_cf.c
38295 +++ b/drivers/ata/pata_arasan_cf.c
38296 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
38297 /* Handle platform specific quirks */
38298 if (quirk) {
38299 if (quirk & CF_BROKEN_PIO) {
38300 - ap->ops->set_piomode = NULL;
38301 + pax_open_kernel();
38302 + *(void **)&ap->ops->set_piomode = NULL;
38303 + pax_close_kernel();
38304 ap->pio_mask = 0;
38305 }
38306 if (quirk & CF_BROKEN_MWDMA)
38307 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
38308 index f9b983a..887b9d8 100644
38309 --- a/drivers/atm/adummy.c
38310 +++ b/drivers/atm/adummy.c
38311 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
38312 vcc->pop(vcc, skb);
38313 else
38314 dev_kfree_skb_any(skb);
38315 - atomic_inc(&vcc->stats->tx);
38316 + atomic_inc_unchecked(&vcc->stats->tx);
38317
38318 return 0;
38319 }
38320 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
38321 index f1a9198..f466a4a 100644
38322 --- a/drivers/atm/ambassador.c
38323 +++ b/drivers/atm/ambassador.c
38324 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
38325 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
38326
38327 // VC layer stats
38328 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38329 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38330
38331 // free the descriptor
38332 kfree (tx_descr);
38333 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
38334 dump_skb ("<<<", vc, skb);
38335
38336 // VC layer stats
38337 - atomic_inc(&atm_vcc->stats->rx);
38338 + atomic_inc_unchecked(&atm_vcc->stats->rx);
38339 __net_timestamp(skb);
38340 // end of our responsibility
38341 atm_vcc->push (atm_vcc, skb);
38342 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
38343 } else {
38344 PRINTK (KERN_INFO, "dropped over-size frame");
38345 // should we count this?
38346 - atomic_inc(&atm_vcc->stats->rx_drop);
38347 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
38348 }
38349
38350 } else {
38351 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
38352 }
38353
38354 if (check_area (skb->data, skb->len)) {
38355 - atomic_inc(&atm_vcc->stats->tx_err);
38356 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
38357 return -ENOMEM; // ?
38358 }
38359
38360 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
38361 index 0e3f8f9..765a7a5 100644
38362 --- a/drivers/atm/atmtcp.c
38363 +++ b/drivers/atm/atmtcp.c
38364 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
38365 if (vcc->pop) vcc->pop(vcc,skb);
38366 else dev_kfree_skb(skb);
38367 if (dev_data) return 0;
38368 - atomic_inc(&vcc->stats->tx_err);
38369 + atomic_inc_unchecked(&vcc->stats->tx_err);
38370 return -ENOLINK;
38371 }
38372 size = skb->len+sizeof(struct atmtcp_hdr);
38373 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
38374 if (!new_skb) {
38375 if (vcc->pop) vcc->pop(vcc,skb);
38376 else dev_kfree_skb(skb);
38377 - atomic_inc(&vcc->stats->tx_err);
38378 + atomic_inc_unchecked(&vcc->stats->tx_err);
38379 return -ENOBUFS;
38380 }
38381 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
38382 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
38383 if (vcc->pop) vcc->pop(vcc,skb);
38384 else dev_kfree_skb(skb);
38385 out_vcc->push(out_vcc,new_skb);
38386 - atomic_inc(&vcc->stats->tx);
38387 - atomic_inc(&out_vcc->stats->rx);
38388 + atomic_inc_unchecked(&vcc->stats->tx);
38389 + atomic_inc_unchecked(&out_vcc->stats->rx);
38390 return 0;
38391 }
38392
38393 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
38394 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
38395 read_unlock(&vcc_sklist_lock);
38396 if (!out_vcc) {
38397 - atomic_inc(&vcc->stats->tx_err);
38398 + atomic_inc_unchecked(&vcc->stats->tx_err);
38399 goto done;
38400 }
38401 skb_pull(skb,sizeof(struct atmtcp_hdr));
38402 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
38403 __net_timestamp(new_skb);
38404 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
38405 out_vcc->push(out_vcc,new_skb);
38406 - atomic_inc(&vcc->stats->tx);
38407 - atomic_inc(&out_vcc->stats->rx);
38408 + atomic_inc_unchecked(&vcc->stats->tx);
38409 + atomic_inc_unchecked(&out_vcc->stats->rx);
38410 done:
38411 if (vcc->pop) vcc->pop(vcc,skb);
38412 else dev_kfree_skb(skb);
38413 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
38414 index b1955ba..b179940 100644
38415 --- a/drivers/atm/eni.c
38416 +++ b/drivers/atm/eni.c
38417 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
38418 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
38419 vcc->dev->number);
38420 length = 0;
38421 - atomic_inc(&vcc->stats->rx_err);
38422 + atomic_inc_unchecked(&vcc->stats->rx_err);
38423 }
38424 else {
38425 length = ATM_CELL_SIZE-1; /* no HEC */
38426 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
38427 size);
38428 }
38429 eff = length = 0;
38430 - atomic_inc(&vcc->stats->rx_err);
38431 + atomic_inc_unchecked(&vcc->stats->rx_err);
38432 }
38433 else {
38434 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
38435 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
38436 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
38437 vcc->dev->number,vcc->vci,length,size << 2,descr);
38438 length = eff = 0;
38439 - atomic_inc(&vcc->stats->rx_err);
38440 + atomic_inc_unchecked(&vcc->stats->rx_err);
38441 }
38442 }
38443 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
38444 @@ -767,7 +767,7 @@ rx_dequeued++;
38445 vcc->push(vcc,skb);
38446 pushed++;
38447 }
38448 - atomic_inc(&vcc->stats->rx);
38449 + atomic_inc_unchecked(&vcc->stats->rx);
38450 }
38451 wake_up(&eni_dev->rx_wait);
38452 }
38453 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
38454 PCI_DMA_TODEVICE);
38455 if (vcc->pop) vcc->pop(vcc,skb);
38456 else dev_kfree_skb_irq(skb);
38457 - atomic_inc(&vcc->stats->tx);
38458 + atomic_inc_unchecked(&vcc->stats->tx);
38459 wake_up(&eni_dev->tx_wait);
38460 dma_complete++;
38461 }
38462 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
38463 index 82f2ae0..f205c02 100644
38464 --- a/drivers/atm/firestream.c
38465 +++ b/drivers/atm/firestream.c
38466 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
38467 }
38468 }
38469
38470 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38471 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38472
38473 fs_dprintk (FS_DEBUG_TXMEM, "i");
38474 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
38475 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
38476 #endif
38477 skb_put (skb, qe->p1 & 0xffff);
38478 ATM_SKB(skb)->vcc = atm_vcc;
38479 - atomic_inc(&atm_vcc->stats->rx);
38480 + atomic_inc_unchecked(&atm_vcc->stats->rx);
38481 __net_timestamp(skb);
38482 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
38483 atm_vcc->push (atm_vcc, skb);
38484 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
38485 kfree (pe);
38486 }
38487 if (atm_vcc)
38488 - atomic_inc(&atm_vcc->stats->rx_drop);
38489 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
38490 break;
38491 case 0x1f: /* Reassembly abort: no buffers. */
38492 /* Silently increment error counter. */
38493 if (atm_vcc)
38494 - atomic_inc(&atm_vcc->stats->rx_drop);
38495 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
38496 break;
38497 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
38498 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
38499 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
38500 index d4725fc..2d4ea65 100644
38501 --- a/drivers/atm/fore200e.c
38502 +++ b/drivers/atm/fore200e.c
38503 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
38504 #endif
38505 /* check error condition */
38506 if (*entry->status & STATUS_ERROR)
38507 - atomic_inc(&vcc->stats->tx_err);
38508 + atomic_inc_unchecked(&vcc->stats->tx_err);
38509 else
38510 - atomic_inc(&vcc->stats->tx);
38511 + atomic_inc_unchecked(&vcc->stats->tx);
38512 }
38513 }
38514
38515 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
38516 if (skb == NULL) {
38517 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
38518
38519 - atomic_inc(&vcc->stats->rx_drop);
38520 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38521 return -ENOMEM;
38522 }
38523
38524 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
38525
38526 dev_kfree_skb_any(skb);
38527
38528 - atomic_inc(&vcc->stats->rx_drop);
38529 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38530 return -ENOMEM;
38531 }
38532
38533 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
38534
38535 vcc->push(vcc, skb);
38536 - atomic_inc(&vcc->stats->rx);
38537 + atomic_inc_unchecked(&vcc->stats->rx);
38538
38539 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
38540
38541 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
38542 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
38543 fore200e->atm_dev->number,
38544 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
38545 - atomic_inc(&vcc->stats->rx_err);
38546 + atomic_inc_unchecked(&vcc->stats->rx_err);
38547 }
38548 }
38549
38550 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
38551 goto retry_here;
38552 }
38553
38554 - atomic_inc(&vcc->stats->tx_err);
38555 + atomic_inc_unchecked(&vcc->stats->tx_err);
38556
38557 fore200e->tx_sat++;
38558 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
38559 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
38560 index aa6be26..f70a785 100644
38561 --- a/drivers/atm/he.c
38562 +++ b/drivers/atm/he.c
38563 @@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
38564
38565 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
38566 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
38567 - atomic_inc(&vcc->stats->rx_drop);
38568 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38569 goto return_host_buffers;
38570 }
38571
38572 @@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
38573 RBRQ_LEN_ERR(he_dev->rbrq_head)
38574 ? "LEN_ERR" : "",
38575 vcc->vpi, vcc->vci);
38576 - atomic_inc(&vcc->stats->rx_err);
38577 + atomic_inc_unchecked(&vcc->stats->rx_err);
38578 goto return_host_buffers;
38579 }
38580
38581 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
38582 vcc->push(vcc, skb);
38583 spin_lock(&he_dev->global_lock);
38584
38585 - atomic_inc(&vcc->stats->rx);
38586 + atomic_inc_unchecked(&vcc->stats->rx);
38587
38588 return_host_buffers:
38589 ++pdus_assembled;
38590 @@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
38591 tpd->vcc->pop(tpd->vcc, tpd->skb);
38592 else
38593 dev_kfree_skb_any(tpd->skb);
38594 - atomic_inc(&tpd->vcc->stats->tx_err);
38595 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
38596 }
38597 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
38598 return;
38599 @@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38600 vcc->pop(vcc, skb);
38601 else
38602 dev_kfree_skb_any(skb);
38603 - atomic_inc(&vcc->stats->tx_err);
38604 + atomic_inc_unchecked(&vcc->stats->tx_err);
38605 return -EINVAL;
38606 }
38607
38608 @@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38609 vcc->pop(vcc, skb);
38610 else
38611 dev_kfree_skb_any(skb);
38612 - atomic_inc(&vcc->stats->tx_err);
38613 + atomic_inc_unchecked(&vcc->stats->tx_err);
38614 return -EINVAL;
38615 }
38616 #endif
38617 @@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38618 vcc->pop(vcc, skb);
38619 else
38620 dev_kfree_skb_any(skb);
38621 - atomic_inc(&vcc->stats->tx_err);
38622 + atomic_inc_unchecked(&vcc->stats->tx_err);
38623 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38624 return -ENOMEM;
38625 }
38626 @@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38627 vcc->pop(vcc, skb);
38628 else
38629 dev_kfree_skb_any(skb);
38630 - atomic_inc(&vcc->stats->tx_err);
38631 + atomic_inc_unchecked(&vcc->stats->tx_err);
38632 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38633 return -ENOMEM;
38634 }
38635 @@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38636 __enqueue_tpd(he_dev, tpd, cid);
38637 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38638
38639 - atomic_inc(&vcc->stats->tx);
38640 + atomic_inc_unchecked(&vcc->stats->tx);
38641
38642 return 0;
38643 }
38644 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
38645 index 1dc0519..1aadaf7 100644
38646 --- a/drivers/atm/horizon.c
38647 +++ b/drivers/atm/horizon.c
38648 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
38649 {
38650 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
38651 // VC layer stats
38652 - atomic_inc(&vcc->stats->rx);
38653 + atomic_inc_unchecked(&vcc->stats->rx);
38654 __net_timestamp(skb);
38655 // end of our responsibility
38656 vcc->push (vcc, skb);
38657 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
38658 dev->tx_iovec = NULL;
38659
38660 // VC layer stats
38661 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38662 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38663
38664 // free the skb
38665 hrz_kfree_skb (skb);
38666 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
38667 index b621f56..1e3a799 100644
38668 --- a/drivers/atm/idt77252.c
38669 +++ b/drivers/atm/idt77252.c
38670 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
38671 else
38672 dev_kfree_skb(skb);
38673
38674 - atomic_inc(&vcc->stats->tx);
38675 + atomic_inc_unchecked(&vcc->stats->tx);
38676 }
38677
38678 atomic_dec(&scq->used);
38679 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38680 if ((sb = dev_alloc_skb(64)) == NULL) {
38681 printk("%s: Can't allocate buffers for aal0.\n",
38682 card->name);
38683 - atomic_add(i, &vcc->stats->rx_drop);
38684 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
38685 break;
38686 }
38687 if (!atm_charge(vcc, sb->truesize)) {
38688 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
38689 card->name);
38690 - atomic_add(i - 1, &vcc->stats->rx_drop);
38691 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
38692 dev_kfree_skb(sb);
38693 break;
38694 }
38695 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38696 ATM_SKB(sb)->vcc = vcc;
38697 __net_timestamp(sb);
38698 vcc->push(vcc, sb);
38699 - atomic_inc(&vcc->stats->rx);
38700 + atomic_inc_unchecked(&vcc->stats->rx);
38701
38702 cell += ATM_CELL_PAYLOAD;
38703 }
38704 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38705 "(CDC: %08x)\n",
38706 card->name, len, rpp->len, readl(SAR_REG_CDC));
38707 recycle_rx_pool_skb(card, rpp);
38708 - atomic_inc(&vcc->stats->rx_err);
38709 + atomic_inc_unchecked(&vcc->stats->rx_err);
38710 return;
38711 }
38712 if (stat & SAR_RSQE_CRC) {
38713 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
38714 recycle_rx_pool_skb(card, rpp);
38715 - atomic_inc(&vcc->stats->rx_err);
38716 + atomic_inc_unchecked(&vcc->stats->rx_err);
38717 return;
38718 }
38719 if (skb_queue_len(&rpp->queue) > 1) {
38720 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38721 RXPRINTK("%s: Can't alloc RX skb.\n",
38722 card->name);
38723 recycle_rx_pool_skb(card, rpp);
38724 - atomic_inc(&vcc->stats->rx_err);
38725 + atomic_inc_unchecked(&vcc->stats->rx_err);
38726 return;
38727 }
38728 if (!atm_charge(vcc, skb->truesize)) {
38729 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38730 __net_timestamp(skb);
38731
38732 vcc->push(vcc, skb);
38733 - atomic_inc(&vcc->stats->rx);
38734 + atomic_inc_unchecked(&vcc->stats->rx);
38735
38736 return;
38737 }
38738 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38739 __net_timestamp(skb);
38740
38741 vcc->push(vcc, skb);
38742 - atomic_inc(&vcc->stats->rx);
38743 + atomic_inc_unchecked(&vcc->stats->rx);
38744
38745 if (skb->truesize > SAR_FB_SIZE_3)
38746 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
38747 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
38748 if (vcc->qos.aal != ATM_AAL0) {
38749 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
38750 card->name, vpi, vci);
38751 - atomic_inc(&vcc->stats->rx_drop);
38752 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38753 goto drop;
38754 }
38755
38756 if ((sb = dev_alloc_skb(64)) == NULL) {
38757 printk("%s: Can't allocate buffers for AAL0.\n",
38758 card->name);
38759 - atomic_inc(&vcc->stats->rx_err);
38760 + atomic_inc_unchecked(&vcc->stats->rx_err);
38761 goto drop;
38762 }
38763
38764 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
38765 ATM_SKB(sb)->vcc = vcc;
38766 __net_timestamp(sb);
38767 vcc->push(vcc, sb);
38768 - atomic_inc(&vcc->stats->rx);
38769 + atomic_inc_unchecked(&vcc->stats->rx);
38770
38771 drop:
38772 skb_pull(queue, 64);
38773 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38774
38775 if (vc == NULL) {
38776 printk("%s: NULL connection in send().\n", card->name);
38777 - atomic_inc(&vcc->stats->tx_err);
38778 + atomic_inc_unchecked(&vcc->stats->tx_err);
38779 dev_kfree_skb(skb);
38780 return -EINVAL;
38781 }
38782 if (!test_bit(VCF_TX, &vc->flags)) {
38783 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
38784 - atomic_inc(&vcc->stats->tx_err);
38785 + atomic_inc_unchecked(&vcc->stats->tx_err);
38786 dev_kfree_skb(skb);
38787 return -EINVAL;
38788 }
38789 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38790 break;
38791 default:
38792 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
38793 - atomic_inc(&vcc->stats->tx_err);
38794 + atomic_inc_unchecked(&vcc->stats->tx_err);
38795 dev_kfree_skb(skb);
38796 return -EINVAL;
38797 }
38798
38799 if (skb_shinfo(skb)->nr_frags != 0) {
38800 printk("%s: No scatter-gather yet.\n", card->name);
38801 - atomic_inc(&vcc->stats->tx_err);
38802 + atomic_inc_unchecked(&vcc->stats->tx_err);
38803 dev_kfree_skb(skb);
38804 return -EINVAL;
38805 }
38806 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38807
38808 err = queue_skb(card, vc, skb, oam);
38809 if (err) {
38810 - atomic_inc(&vcc->stats->tx_err);
38811 + atomic_inc_unchecked(&vcc->stats->tx_err);
38812 dev_kfree_skb(skb);
38813 return err;
38814 }
38815 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
38816 skb = dev_alloc_skb(64);
38817 if (!skb) {
38818 printk("%s: Out of memory in send_oam().\n", card->name);
38819 - atomic_inc(&vcc->stats->tx_err);
38820 + atomic_inc_unchecked(&vcc->stats->tx_err);
38821 return -ENOMEM;
38822 }
38823 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
38824 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
38825 index 4217f29..88f547a 100644
38826 --- a/drivers/atm/iphase.c
38827 +++ b/drivers/atm/iphase.c
38828 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
38829 status = (u_short) (buf_desc_ptr->desc_mode);
38830 if (status & (RX_CER | RX_PTE | RX_OFL))
38831 {
38832 - atomic_inc(&vcc->stats->rx_err);
38833 + atomic_inc_unchecked(&vcc->stats->rx_err);
38834 IF_ERR(printk("IA: bad packet, dropping it");)
38835 if (status & RX_CER) {
38836 IF_ERR(printk(" cause: packet CRC error\n");)
38837 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
38838 len = dma_addr - buf_addr;
38839 if (len > iadev->rx_buf_sz) {
38840 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
38841 - atomic_inc(&vcc->stats->rx_err);
38842 + atomic_inc_unchecked(&vcc->stats->rx_err);
38843 goto out_free_desc;
38844 }
38845
38846 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38847 ia_vcc = INPH_IA_VCC(vcc);
38848 if (ia_vcc == NULL)
38849 {
38850 - atomic_inc(&vcc->stats->rx_err);
38851 + atomic_inc_unchecked(&vcc->stats->rx_err);
38852 atm_return(vcc, skb->truesize);
38853 dev_kfree_skb_any(skb);
38854 goto INCR_DLE;
38855 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38856 if ((length > iadev->rx_buf_sz) || (length >
38857 (skb->len - sizeof(struct cpcs_trailer))))
38858 {
38859 - atomic_inc(&vcc->stats->rx_err);
38860 + atomic_inc_unchecked(&vcc->stats->rx_err);
38861 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
38862 length, skb->len);)
38863 atm_return(vcc, skb->truesize);
38864 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38865
38866 IF_RX(printk("rx_dle_intr: skb push");)
38867 vcc->push(vcc,skb);
38868 - atomic_inc(&vcc->stats->rx);
38869 + atomic_inc_unchecked(&vcc->stats->rx);
38870 iadev->rx_pkt_cnt++;
38871 }
38872 INCR_DLE:
38873 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
38874 {
38875 struct k_sonet_stats *stats;
38876 stats = &PRIV(_ia_dev[board])->sonet_stats;
38877 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
38878 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
38879 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
38880 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
38881 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
38882 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
38883 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
38884 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
38885 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
38886 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
38887 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
38888 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
38889 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
38890 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
38891 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
38892 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
38893 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
38894 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
38895 }
38896 ia_cmds.status = 0;
38897 break;
38898 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38899 if ((desc == 0) || (desc > iadev->num_tx_desc))
38900 {
38901 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
38902 - atomic_inc(&vcc->stats->tx);
38903 + atomic_inc_unchecked(&vcc->stats->tx);
38904 if (vcc->pop)
38905 vcc->pop(vcc, skb);
38906 else
38907 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38908 ATM_DESC(skb) = vcc->vci;
38909 skb_queue_tail(&iadev->tx_dma_q, skb);
38910
38911 - atomic_inc(&vcc->stats->tx);
38912 + atomic_inc_unchecked(&vcc->stats->tx);
38913 iadev->tx_pkt_cnt++;
38914 /* Increment transaction counter */
38915 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
38916
38917 #if 0
38918 /* add flow control logic */
38919 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
38920 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
38921 if (iavcc->vc_desc_cnt > 10) {
38922 vcc->tx_quota = vcc->tx_quota * 3 / 4;
38923 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
38924 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
38925 index fa7d7019..1e404c7 100644
38926 --- a/drivers/atm/lanai.c
38927 +++ b/drivers/atm/lanai.c
38928 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
38929 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
38930 lanai_endtx(lanai, lvcc);
38931 lanai_free_skb(lvcc->tx.atmvcc, skb);
38932 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
38933 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
38934 }
38935
38936 /* Try to fill the buffer - don't call unless there is backlog */
38937 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
38938 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
38939 __net_timestamp(skb);
38940 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
38941 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
38942 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
38943 out:
38944 lvcc->rx.buf.ptr = end;
38945 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
38946 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38947 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
38948 "vcc %d\n", lanai->number, (unsigned int) s, vci);
38949 lanai->stats.service_rxnotaal5++;
38950 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38951 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38952 return 0;
38953 }
38954 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
38955 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38956 int bytes;
38957 read_unlock(&vcc_sklist_lock);
38958 DPRINTK("got trashed rx pdu on vci %d\n", vci);
38959 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38960 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38961 lvcc->stats.x.aal5.service_trash++;
38962 bytes = (SERVICE_GET_END(s) * 16) -
38963 (((unsigned long) lvcc->rx.buf.ptr) -
38964 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38965 }
38966 if (s & SERVICE_STREAM) {
38967 read_unlock(&vcc_sklist_lock);
38968 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38969 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38970 lvcc->stats.x.aal5.service_stream++;
38971 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
38972 "PDU on VCI %d!\n", lanai->number, vci);
38973 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38974 return 0;
38975 }
38976 DPRINTK("got rx crc error on vci %d\n", vci);
38977 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38978 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38979 lvcc->stats.x.aal5.service_rxcrc++;
38980 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
38981 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
38982 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
38983 index 9988ac9..7c52585 100644
38984 --- a/drivers/atm/nicstar.c
38985 +++ b/drivers/atm/nicstar.c
38986 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38987 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
38988 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
38989 card->index);
38990 - atomic_inc(&vcc->stats->tx_err);
38991 + atomic_inc_unchecked(&vcc->stats->tx_err);
38992 dev_kfree_skb_any(skb);
38993 return -EINVAL;
38994 }
38995 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38996 if (!vc->tx) {
38997 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
38998 card->index);
38999 - atomic_inc(&vcc->stats->tx_err);
39000 + atomic_inc_unchecked(&vcc->stats->tx_err);
39001 dev_kfree_skb_any(skb);
39002 return -EINVAL;
39003 }
39004 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
39005 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
39006 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
39007 card->index);
39008 - atomic_inc(&vcc->stats->tx_err);
39009 + atomic_inc_unchecked(&vcc->stats->tx_err);
39010 dev_kfree_skb_any(skb);
39011 return -EINVAL;
39012 }
39013
39014 if (skb_shinfo(skb)->nr_frags != 0) {
39015 printk("nicstar%d: No scatter-gather yet.\n", card->index);
39016 - atomic_inc(&vcc->stats->tx_err);
39017 + atomic_inc_unchecked(&vcc->stats->tx_err);
39018 dev_kfree_skb_any(skb);
39019 return -EINVAL;
39020 }
39021 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
39022 }
39023
39024 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
39025 - atomic_inc(&vcc->stats->tx_err);
39026 + atomic_inc_unchecked(&vcc->stats->tx_err);
39027 dev_kfree_skb_any(skb);
39028 return -EIO;
39029 }
39030 - atomic_inc(&vcc->stats->tx);
39031 + atomic_inc_unchecked(&vcc->stats->tx);
39032
39033 return 0;
39034 }
39035 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39036 printk
39037 ("nicstar%d: Can't allocate buffers for aal0.\n",
39038 card->index);
39039 - atomic_add(i, &vcc->stats->rx_drop);
39040 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
39041 break;
39042 }
39043 if (!atm_charge(vcc, sb->truesize)) {
39044 RXPRINTK
39045 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
39046 card->index);
39047 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
39048 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
39049 dev_kfree_skb_any(sb);
39050 break;
39051 }
39052 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39053 ATM_SKB(sb)->vcc = vcc;
39054 __net_timestamp(sb);
39055 vcc->push(vcc, sb);
39056 - atomic_inc(&vcc->stats->rx);
39057 + atomic_inc_unchecked(&vcc->stats->rx);
39058 cell += ATM_CELL_PAYLOAD;
39059 }
39060
39061 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39062 if (iovb == NULL) {
39063 printk("nicstar%d: Out of iovec buffers.\n",
39064 card->index);
39065 - atomic_inc(&vcc->stats->rx_drop);
39066 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39067 recycle_rx_buf(card, skb);
39068 return;
39069 }
39070 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39071 small or large buffer itself. */
39072 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
39073 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
39074 - atomic_inc(&vcc->stats->rx_err);
39075 + atomic_inc_unchecked(&vcc->stats->rx_err);
39076 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
39077 NS_MAX_IOVECS);
39078 NS_PRV_IOVCNT(iovb) = 0;
39079 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39080 ("nicstar%d: Expected a small buffer, and this is not one.\n",
39081 card->index);
39082 which_list(card, skb);
39083 - atomic_inc(&vcc->stats->rx_err);
39084 + atomic_inc_unchecked(&vcc->stats->rx_err);
39085 recycle_rx_buf(card, skb);
39086 vc->rx_iov = NULL;
39087 recycle_iov_buf(card, iovb);
39088 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39089 ("nicstar%d: Expected a large buffer, and this is not one.\n",
39090 card->index);
39091 which_list(card, skb);
39092 - atomic_inc(&vcc->stats->rx_err);
39093 + atomic_inc_unchecked(&vcc->stats->rx_err);
39094 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
39095 NS_PRV_IOVCNT(iovb));
39096 vc->rx_iov = NULL;
39097 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39098 printk(" - PDU size mismatch.\n");
39099 else
39100 printk(".\n");
39101 - atomic_inc(&vcc->stats->rx_err);
39102 + atomic_inc_unchecked(&vcc->stats->rx_err);
39103 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
39104 NS_PRV_IOVCNT(iovb));
39105 vc->rx_iov = NULL;
39106 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39107 /* skb points to a small buffer */
39108 if (!atm_charge(vcc, skb->truesize)) {
39109 push_rxbufs(card, skb);
39110 - atomic_inc(&vcc->stats->rx_drop);
39111 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39112 } else {
39113 skb_put(skb, len);
39114 dequeue_sm_buf(card, skb);
39115 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39116 ATM_SKB(skb)->vcc = vcc;
39117 __net_timestamp(skb);
39118 vcc->push(vcc, skb);
39119 - atomic_inc(&vcc->stats->rx);
39120 + atomic_inc_unchecked(&vcc->stats->rx);
39121 }
39122 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
39123 struct sk_buff *sb;
39124 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39125 if (len <= NS_SMBUFSIZE) {
39126 if (!atm_charge(vcc, sb->truesize)) {
39127 push_rxbufs(card, sb);
39128 - atomic_inc(&vcc->stats->rx_drop);
39129 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39130 } else {
39131 skb_put(sb, len);
39132 dequeue_sm_buf(card, sb);
39133 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39134 ATM_SKB(sb)->vcc = vcc;
39135 __net_timestamp(sb);
39136 vcc->push(vcc, sb);
39137 - atomic_inc(&vcc->stats->rx);
39138 + atomic_inc_unchecked(&vcc->stats->rx);
39139 }
39140
39141 push_rxbufs(card, skb);
39142 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39143
39144 if (!atm_charge(vcc, skb->truesize)) {
39145 push_rxbufs(card, skb);
39146 - atomic_inc(&vcc->stats->rx_drop);
39147 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39148 } else {
39149 dequeue_lg_buf(card, skb);
39150 #ifdef NS_USE_DESTRUCTORS
39151 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39152 ATM_SKB(skb)->vcc = vcc;
39153 __net_timestamp(skb);
39154 vcc->push(vcc, skb);
39155 - atomic_inc(&vcc->stats->rx);
39156 + atomic_inc_unchecked(&vcc->stats->rx);
39157 }
39158
39159 push_rxbufs(card, sb);
39160 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39161 printk
39162 ("nicstar%d: Out of huge buffers.\n",
39163 card->index);
39164 - atomic_inc(&vcc->stats->rx_drop);
39165 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39166 recycle_iovec_rx_bufs(card,
39167 (struct iovec *)
39168 iovb->data,
39169 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39170 card->hbpool.count++;
39171 } else
39172 dev_kfree_skb_any(hb);
39173 - atomic_inc(&vcc->stats->rx_drop);
39174 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39175 } else {
39176 /* Copy the small buffer to the huge buffer */
39177 sb = (struct sk_buff *)iov->iov_base;
39178 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39179 #endif /* NS_USE_DESTRUCTORS */
39180 __net_timestamp(hb);
39181 vcc->push(vcc, hb);
39182 - atomic_inc(&vcc->stats->rx);
39183 + atomic_inc_unchecked(&vcc->stats->rx);
39184 }
39185 }
39186
39187 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
39188 index 943cf0d..37d15d5 100644
39189 --- a/drivers/atm/solos-pci.c
39190 +++ b/drivers/atm/solos-pci.c
39191 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
39192 }
39193 atm_charge(vcc, skb->truesize);
39194 vcc->push(vcc, skb);
39195 - atomic_inc(&vcc->stats->rx);
39196 + atomic_inc_unchecked(&vcc->stats->rx);
39197 break;
39198
39199 case PKT_STATUS:
39200 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
39201 vcc = SKB_CB(oldskb)->vcc;
39202
39203 if (vcc) {
39204 - atomic_inc(&vcc->stats->tx);
39205 + atomic_inc_unchecked(&vcc->stats->tx);
39206 solos_pop(vcc, oldskb);
39207 } else {
39208 dev_kfree_skb_irq(oldskb);
39209 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
39210 index 0215934..ce9f5b1 100644
39211 --- a/drivers/atm/suni.c
39212 +++ b/drivers/atm/suni.c
39213 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
39214
39215
39216 #define ADD_LIMITED(s,v) \
39217 - atomic_add((v),&stats->s); \
39218 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
39219 + atomic_add_unchecked((v),&stats->s); \
39220 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
39221
39222
39223 static void suni_hz(unsigned long from_timer)
39224 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
39225 index 5120a96..e2572bd 100644
39226 --- a/drivers/atm/uPD98402.c
39227 +++ b/drivers/atm/uPD98402.c
39228 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
39229 struct sonet_stats tmp;
39230 int error = 0;
39231
39232 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
39233 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
39234 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
39235 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
39236 if (zero && !error) {
39237 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
39238
39239
39240 #define ADD_LIMITED(s,v) \
39241 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
39242 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
39243 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
39244 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
39245 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
39246 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
39247
39248
39249 static void stat_event(struct atm_dev *dev)
39250 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
39251 if (reason & uPD98402_INT_PFM) stat_event(dev);
39252 if (reason & uPD98402_INT_PCO) {
39253 (void) GET(PCOCR); /* clear interrupt cause */
39254 - atomic_add(GET(HECCT),
39255 + atomic_add_unchecked(GET(HECCT),
39256 &PRIV(dev)->sonet_stats.uncorr_hcs);
39257 }
39258 if ((reason & uPD98402_INT_RFO) &&
39259 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
39260 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
39261 uPD98402_INT_LOS),PIMR); /* enable them */
39262 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
39263 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
39264 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
39265 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
39266 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
39267 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
39268 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
39269 return 0;
39270 }
39271
39272 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
39273 index 969c3c2..9b72956 100644
39274 --- a/drivers/atm/zatm.c
39275 +++ b/drivers/atm/zatm.c
39276 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
39277 }
39278 if (!size) {
39279 dev_kfree_skb_irq(skb);
39280 - if (vcc) atomic_inc(&vcc->stats->rx_err);
39281 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
39282 continue;
39283 }
39284 if (!atm_charge(vcc,skb->truesize)) {
39285 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
39286 skb->len = size;
39287 ATM_SKB(skb)->vcc = vcc;
39288 vcc->push(vcc,skb);
39289 - atomic_inc(&vcc->stats->rx);
39290 + atomic_inc_unchecked(&vcc->stats->rx);
39291 }
39292 zout(pos & 0xffff,MTA(mbx));
39293 #if 0 /* probably a stupid idea */
39294 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
39295 skb_queue_head(&zatm_vcc->backlog,skb);
39296 break;
39297 }
39298 - atomic_inc(&vcc->stats->tx);
39299 + atomic_inc_unchecked(&vcc->stats->tx);
39300 wake_up(&zatm_vcc->tx_wait);
39301 }
39302
39303 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
39304 index 83e910a..b224a73 100644
39305 --- a/drivers/base/bus.c
39306 +++ b/drivers/base/bus.c
39307 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
39308 return -EINVAL;
39309
39310 mutex_lock(&subsys->p->mutex);
39311 - list_add_tail(&sif->node, &subsys->p->interfaces);
39312 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
39313 if (sif->add_dev) {
39314 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
39315 while ((dev = subsys_dev_iter_next(&iter)))
39316 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
39317 subsys = sif->subsys;
39318
39319 mutex_lock(&subsys->p->mutex);
39320 - list_del_init(&sif->node);
39321 + pax_list_del_init((struct list_head *)&sif->node);
39322 if (sif->remove_dev) {
39323 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
39324 while ((dev = subsys_dev_iter_next(&iter)))
39325 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
39326 index 25798db..15f130e 100644
39327 --- a/drivers/base/devtmpfs.c
39328 +++ b/drivers/base/devtmpfs.c
39329 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
39330 if (!thread)
39331 return 0;
39332
39333 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
39334 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
39335 if (err)
39336 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
39337 else
39338 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
39339 *err = sys_unshare(CLONE_NEWNS);
39340 if (*err)
39341 goto out;
39342 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
39343 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
39344 if (*err)
39345 goto out;
39346 - sys_chdir("/.."); /* will traverse into overmounted root */
39347 - sys_chroot(".");
39348 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
39349 + sys_chroot((char __force_user *)".");
39350 complete(&setup_done);
39351 while (1) {
39352 spin_lock(&req_lock);
39353 diff --git a/drivers/base/node.c b/drivers/base/node.c
39354 index 8f7ed99..700dd0c 100644
39355 --- a/drivers/base/node.c
39356 +++ b/drivers/base/node.c
39357 @@ -624,7 +624,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
39358 struct node_attr {
39359 struct device_attribute attr;
39360 enum node_states state;
39361 -};
39362 +} __do_const;
39363
39364 static ssize_t show_node_state(struct device *dev,
39365 struct device_attribute *attr, char *buf)
39366 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
39367 index eee55c1..b8c9393 100644
39368 --- a/drivers/base/power/domain.c
39369 +++ b/drivers/base/power/domain.c
39370 @@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
39371
39372 if (dev->power.subsys_data->domain_data) {
39373 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
39374 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
39375 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
39376 if (clear_td)
39377 - gpd_data->td = (struct gpd_timing_data){ 0 };
39378 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
39379
39380 if (--gpd_data->refcount == 0) {
39381 dev->power.subsys_data->domain_data = NULL;
39382 @@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
39383 {
39384 struct cpuidle_driver *cpuidle_drv;
39385 struct gpd_cpu_data *cpu_data;
39386 - struct cpuidle_state *idle_state;
39387 + cpuidle_state_no_const *idle_state;
39388 int ret = 0;
39389
39390 if (IS_ERR_OR_NULL(genpd) || state < 0)
39391 @@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
39392 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
39393 {
39394 struct gpd_cpu_data *cpu_data;
39395 - struct cpuidle_state *idle_state;
39396 + cpuidle_state_no_const *idle_state;
39397 int ret = 0;
39398
39399 if (IS_ERR_OR_NULL(genpd))
39400 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
39401 index 95b181d1..c4f0e19 100644
39402 --- a/drivers/base/power/sysfs.c
39403 +++ b/drivers/base/power/sysfs.c
39404 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
39405 return -EIO;
39406 }
39407 }
39408 - return sprintf(buf, p);
39409 + return sprintf(buf, "%s", p);
39410 }
39411
39412 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
39413 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
39414 index eb1bd2e..2667d3a 100644
39415 --- a/drivers/base/power/wakeup.c
39416 +++ b/drivers/base/power/wakeup.c
39417 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
39418 * They need to be modified together atomically, so it's better to use one
39419 * atomic variable to hold them both.
39420 */
39421 -static atomic_t combined_event_count = ATOMIC_INIT(0);
39422 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
39423
39424 #define IN_PROGRESS_BITS (sizeof(int) * 4)
39425 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
39426
39427 static void split_counters(unsigned int *cnt, unsigned int *inpr)
39428 {
39429 - unsigned int comb = atomic_read(&combined_event_count);
39430 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
39431
39432 *cnt = (comb >> IN_PROGRESS_BITS);
39433 *inpr = comb & MAX_IN_PROGRESS;
39434 @@ -401,7 +401,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
39435 ws->start_prevent_time = ws->last_time;
39436
39437 /* Increment the counter of events in progress. */
39438 - cec = atomic_inc_return(&combined_event_count);
39439 + cec = atomic_inc_return_unchecked(&combined_event_count);
39440
39441 trace_wakeup_source_activate(ws->name, cec);
39442 }
39443 @@ -527,7 +527,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
39444 * Increment the counter of registered wakeup events and decrement the
39445 * couter of wakeup events in progress simultaneously.
39446 */
39447 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
39448 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
39449 trace_wakeup_source_deactivate(ws->name, cec);
39450
39451 split_counters(&cnt, &inpr);
39452 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
39453 index dbb8350..4762f4c 100644
39454 --- a/drivers/base/syscore.c
39455 +++ b/drivers/base/syscore.c
39456 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
39457 void register_syscore_ops(struct syscore_ops *ops)
39458 {
39459 mutex_lock(&syscore_ops_lock);
39460 - list_add_tail(&ops->node, &syscore_ops_list);
39461 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
39462 mutex_unlock(&syscore_ops_lock);
39463 }
39464 EXPORT_SYMBOL_GPL(register_syscore_ops);
39465 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
39466 void unregister_syscore_ops(struct syscore_ops *ops)
39467 {
39468 mutex_lock(&syscore_ops_lock);
39469 - list_del(&ops->node);
39470 + pax_list_del((struct list_head *)&ops->node);
39471 mutex_unlock(&syscore_ops_lock);
39472 }
39473 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
39474 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
39475 index 4595c22..d4f6c54 100644
39476 --- a/drivers/block/cciss.c
39477 +++ b/drivers/block/cciss.c
39478 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
39479 while (!list_empty(&h->reqQ)) {
39480 c = list_entry(h->reqQ.next, CommandList_struct, list);
39481 /* can't do anything if fifo is full */
39482 - if ((h->access.fifo_full(h))) {
39483 + if ((h->access->fifo_full(h))) {
39484 dev_warn(&h->pdev->dev, "fifo full\n");
39485 break;
39486 }
39487 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
39488 h->Qdepth--;
39489
39490 /* Tell the controller execute command */
39491 - h->access.submit_command(h, c);
39492 + h->access->submit_command(h, c);
39493
39494 /* Put job onto the completed Q */
39495 addQ(&h->cmpQ, c);
39496 @@ -3447,17 +3447,17 @@ startio:
39497
39498 static inline unsigned long get_next_completion(ctlr_info_t *h)
39499 {
39500 - return h->access.command_completed(h);
39501 + return h->access->command_completed(h);
39502 }
39503
39504 static inline int interrupt_pending(ctlr_info_t *h)
39505 {
39506 - return h->access.intr_pending(h);
39507 + return h->access->intr_pending(h);
39508 }
39509
39510 static inline long interrupt_not_for_us(ctlr_info_t *h)
39511 {
39512 - return ((h->access.intr_pending(h) == 0) ||
39513 + return ((h->access->intr_pending(h) == 0) ||
39514 (h->interrupts_enabled == 0));
39515 }
39516
39517 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
39518 u32 a;
39519
39520 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
39521 - return h->access.command_completed(h);
39522 + return h->access->command_completed(h);
39523
39524 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
39525 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
39526 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
39527 trans_support & CFGTBL_Trans_use_short_tags);
39528
39529 /* Change the access methods to the performant access methods */
39530 - h->access = SA5_performant_access;
39531 + h->access = &SA5_performant_access;
39532 h->transMethod = CFGTBL_Trans_Performant;
39533
39534 return;
39535 @@ -4321,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
39536 if (prod_index < 0)
39537 return -ENODEV;
39538 h->product_name = products[prod_index].product_name;
39539 - h->access = *(products[prod_index].access);
39540 + h->access = products[prod_index].access;
39541
39542 if (cciss_board_disabled(h)) {
39543 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
39544 @@ -5053,7 +5053,7 @@ reinit_after_soft_reset:
39545 }
39546
39547 /* make sure the board interrupts are off */
39548 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
39549 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
39550 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
39551 if (rc)
39552 goto clean2;
39553 @@ -5103,7 +5103,7 @@ reinit_after_soft_reset:
39554 * fake ones to scoop up any residual completions.
39555 */
39556 spin_lock_irqsave(&h->lock, flags);
39557 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
39558 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
39559 spin_unlock_irqrestore(&h->lock, flags);
39560 free_irq(h->intr[h->intr_mode], h);
39561 rc = cciss_request_irq(h, cciss_msix_discard_completions,
39562 @@ -5123,9 +5123,9 @@ reinit_after_soft_reset:
39563 dev_info(&h->pdev->dev, "Board READY.\n");
39564 dev_info(&h->pdev->dev,
39565 "Waiting for stale completions to drain.\n");
39566 - h->access.set_intr_mask(h, CCISS_INTR_ON);
39567 + h->access->set_intr_mask(h, CCISS_INTR_ON);
39568 msleep(10000);
39569 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
39570 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
39571
39572 rc = controller_reset_failed(h->cfgtable);
39573 if (rc)
39574 @@ -5148,7 +5148,7 @@ reinit_after_soft_reset:
39575 cciss_scsi_setup(h);
39576
39577 /* Turn the interrupts on so we can service requests */
39578 - h->access.set_intr_mask(h, CCISS_INTR_ON);
39579 + h->access->set_intr_mask(h, CCISS_INTR_ON);
39580
39581 /* Get the firmware version */
39582 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
39583 @@ -5220,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
39584 kfree(flush_buf);
39585 if (return_code != IO_OK)
39586 dev_warn(&h->pdev->dev, "Error flushing cache\n");
39587 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
39588 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
39589 free_irq(h->intr[h->intr_mode], h);
39590 }
39591
39592 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
39593 index 7fda30e..2f27946 100644
39594 --- a/drivers/block/cciss.h
39595 +++ b/drivers/block/cciss.h
39596 @@ -101,7 +101,7 @@ struct ctlr_info
39597 /* information about each logical volume */
39598 drive_info_struct *drv[CISS_MAX_LUN];
39599
39600 - struct access_method access;
39601 + struct access_method *access;
39602
39603 /* queue and queue Info */
39604 struct list_head reqQ;
39605 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
39606 }
39607
39608 static struct access_method SA5_access = {
39609 - SA5_submit_command,
39610 - SA5_intr_mask,
39611 - SA5_fifo_full,
39612 - SA5_intr_pending,
39613 - SA5_completed,
39614 + .submit_command = SA5_submit_command,
39615 + .set_intr_mask = SA5_intr_mask,
39616 + .fifo_full = SA5_fifo_full,
39617 + .intr_pending = SA5_intr_pending,
39618 + .command_completed = SA5_completed,
39619 };
39620
39621 static struct access_method SA5B_access = {
39622 - SA5_submit_command,
39623 - SA5B_intr_mask,
39624 - SA5_fifo_full,
39625 - SA5B_intr_pending,
39626 - SA5_completed,
39627 + .submit_command = SA5_submit_command,
39628 + .set_intr_mask = SA5B_intr_mask,
39629 + .fifo_full = SA5_fifo_full,
39630 + .intr_pending = SA5B_intr_pending,
39631 + .command_completed = SA5_completed,
39632 };
39633
39634 static struct access_method SA5_performant_access = {
39635 - SA5_submit_command,
39636 - SA5_performant_intr_mask,
39637 - SA5_fifo_full,
39638 - SA5_performant_intr_pending,
39639 - SA5_performant_completed,
39640 + .submit_command = SA5_submit_command,
39641 + .set_intr_mask = SA5_performant_intr_mask,
39642 + .fifo_full = SA5_fifo_full,
39643 + .intr_pending = SA5_performant_intr_pending,
39644 + .command_completed = SA5_performant_completed,
39645 };
39646
39647 struct board_type {
39648 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
39649 index 2b94403..fd6ad1f 100644
39650 --- a/drivers/block/cpqarray.c
39651 +++ b/drivers/block/cpqarray.c
39652 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
39653 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
39654 goto Enomem4;
39655 }
39656 - hba[i]->access.set_intr_mask(hba[i], 0);
39657 + hba[i]->access->set_intr_mask(hba[i], 0);
39658 if (request_irq(hba[i]->intr, do_ida_intr,
39659 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
39660 {
39661 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
39662 add_timer(&hba[i]->timer);
39663
39664 /* Enable IRQ now that spinlock and rate limit timer are set up */
39665 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
39666 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
39667
39668 for(j=0; j<NWD; j++) {
39669 struct gendisk *disk = ida_gendisk[i][j];
39670 @@ -694,7 +694,7 @@ DBGINFO(
39671 for(i=0; i<NR_PRODUCTS; i++) {
39672 if (board_id == products[i].board_id) {
39673 c->product_name = products[i].product_name;
39674 - c->access = *(products[i].access);
39675 + c->access = products[i].access;
39676 break;
39677 }
39678 }
39679 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
39680 hba[ctlr]->intr = intr;
39681 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
39682 hba[ctlr]->product_name = products[j].product_name;
39683 - hba[ctlr]->access = *(products[j].access);
39684 + hba[ctlr]->access = products[j].access;
39685 hba[ctlr]->ctlr = ctlr;
39686 hba[ctlr]->board_id = board_id;
39687 hba[ctlr]->pci_dev = NULL; /* not PCI */
39688 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
39689
39690 while((c = h->reqQ) != NULL) {
39691 /* Can't do anything if we're busy */
39692 - if (h->access.fifo_full(h) == 0)
39693 + if (h->access->fifo_full(h) == 0)
39694 return;
39695
39696 /* Get the first entry from the request Q */
39697 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
39698 h->Qdepth--;
39699
39700 /* Tell the controller to do our bidding */
39701 - h->access.submit_command(h, c);
39702 + h->access->submit_command(h, c);
39703
39704 /* Get onto the completion Q */
39705 addQ(&h->cmpQ, c);
39706 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
39707 unsigned long flags;
39708 __u32 a,a1;
39709
39710 - istat = h->access.intr_pending(h);
39711 + istat = h->access->intr_pending(h);
39712 /* Is this interrupt for us? */
39713 if (istat == 0)
39714 return IRQ_NONE;
39715 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
39716 */
39717 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
39718 if (istat & FIFO_NOT_EMPTY) {
39719 - while((a = h->access.command_completed(h))) {
39720 + while((a = h->access->command_completed(h))) {
39721 a1 = a; a &= ~3;
39722 if ((c = h->cmpQ) == NULL)
39723 {
39724 @@ -1448,11 +1448,11 @@ static int sendcmd(
39725 /*
39726 * Disable interrupt
39727 */
39728 - info_p->access.set_intr_mask(info_p, 0);
39729 + info_p->access->set_intr_mask(info_p, 0);
39730 /* Make sure there is room in the command FIFO */
39731 /* Actually it should be completely empty at this time. */
39732 for (i = 200000; i > 0; i--) {
39733 - temp = info_p->access.fifo_full(info_p);
39734 + temp = info_p->access->fifo_full(info_p);
39735 if (temp != 0) {
39736 break;
39737 }
39738 @@ -1465,7 +1465,7 @@ DBG(
39739 /*
39740 * Send the cmd
39741 */
39742 - info_p->access.submit_command(info_p, c);
39743 + info_p->access->submit_command(info_p, c);
39744 complete = pollcomplete(ctlr);
39745
39746 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
39747 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
39748 * we check the new geometry. Then turn interrupts back on when
39749 * we're done.
39750 */
39751 - host->access.set_intr_mask(host, 0);
39752 + host->access->set_intr_mask(host, 0);
39753 getgeometry(ctlr);
39754 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
39755 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
39756
39757 for(i=0; i<NWD; i++) {
39758 struct gendisk *disk = ida_gendisk[ctlr][i];
39759 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
39760 /* Wait (up to 2 seconds) for a command to complete */
39761
39762 for (i = 200000; i > 0; i--) {
39763 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
39764 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
39765 if (done == 0) {
39766 udelay(10); /* a short fixed delay */
39767 } else
39768 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
39769 index be73e9d..7fbf140 100644
39770 --- a/drivers/block/cpqarray.h
39771 +++ b/drivers/block/cpqarray.h
39772 @@ -99,7 +99,7 @@ struct ctlr_info {
39773 drv_info_t drv[NWD];
39774 struct proc_dir_entry *proc;
39775
39776 - struct access_method access;
39777 + struct access_method *access;
39778
39779 cmdlist_t *reqQ;
39780 cmdlist_t *cmpQ;
39781 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
39782 index a76ceb3..3c1a9fd 100644
39783 --- a/drivers/block/drbd/drbd_int.h
39784 +++ b/drivers/block/drbd/drbd_int.h
39785 @@ -331,7 +331,7 @@ struct drbd_epoch {
39786 struct drbd_connection *connection;
39787 struct list_head list;
39788 unsigned int barrier_nr;
39789 - atomic_t epoch_size; /* increased on every request added. */
39790 + atomic_unchecked_t epoch_size; /* increased on every request added. */
39791 atomic_t active; /* increased on every req. added, and dec on every finished. */
39792 unsigned long flags;
39793 };
39794 @@ -797,7 +797,7 @@ struct drbd_device {
39795 unsigned int al_tr_number;
39796 int al_tr_cycle;
39797 wait_queue_head_t seq_wait;
39798 - atomic_t packet_seq;
39799 + atomic_unchecked_t packet_seq;
39800 unsigned int peer_seq;
39801 spinlock_t peer_seq_lock;
39802 unsigned int minor;
39803 @@ -1407,7 +1407,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
39804 char __user *uoptval;
39805 int err;
39806
39807 - uoptval = (char __user __force *)optval;
39808 + uoptval = (char __force_user *)optval;
39809
39810 set_fs(KERNEL_DS);
39811 if (level == SOL_SOCKET)
39812 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
39813 index 89c497c..9c736ae 100644
39814 --- a/drivers/block/drbd/drbd_interval.c
39815 +++ b/drivers/block/drbd/drbd_interval.c
39816 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
39817 }
39818
39819 static const struct rb_augment_callbacks augment_callbacks = {
39820 - augment_propagate,
39821 - augment_copy,
39822 - augment_rotate,
39823 + .propagate = augment_propagate,
39824 + .copy = augment_copy,
39825 + .rotate = augment_rotate,
39826 };
39827
39828 /**
39829 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
39830 index 960645c..6c2724a 100644
39831 --- a/drivers/block/drbd/drbd_main.c
39832 +++ b/drivers/block/drbd/drbd_main.c
39833 @@ -1322,7 +1322,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
39834 p->sector = sector;
39835 p->block_id = block_id;
39836 p->blksize = blksize;
39837 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
39838 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
39839 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
39840 }
39841
39842 @@ -1628,7 +1628,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
39843 return -EIO;
39844 p->sector = cpu_to_be64(req->i.sector);
39845 p->block_id = (unsigned long)req;
39846 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
39847 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
39848 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
39849 if (device->state.conn >= C_SYNC_SOURCE &&
39850 device->state.conn <= C_PAUSED_SYNC_T)
39851 @@ -2670,8 +2670,8 @@ void drbd_destroy_connection(struct kref *kref)
39852 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
39853 struct drbd_resource *resource = connection->resource;
39854
39855 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
39856 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
39857 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
39858 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
39859 kfree(connection->current_epoch);
39860
39861 idr_destroy(&connection->peer_devices);
39862 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
39863 index 3f2e167..d3170e4 100644
39864 --- a/drivers/block/drbd/drbd_nl.c
39865 +++ b/drivers/block/drbd/drbd_nl.c
39866 @@ -3616,7 +3616,7 @@ finish:
39867
39868 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
39869 {
39870 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39871 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39872 struct sk_buff *msg;
39873 struct drbd_genlmsghdr *d_out;
39874 unsigned seq;
39875 @@ -3629,7 +3629,7 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
39876 return;
39877 }
39878
39879 - seq = atomic_inc_return(&drbd_genl_seq);
39880 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
39881 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
39882 if (!msg)
39883 goto failed;
39884 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
39885 index 5b17ec8..6c21e6b 100644
39886 --- a/drivers/block/drbd/drbd_receiver.c
39887 +++ b/drivers/block/drbd/drbd_receiver.c
39888 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
39889 struct drbd_device *device = peer_device->device;
39890 int err;
39891
39892 - atomic_set(&device->packet_seq, 0);
39893 + atomic_set_unchecked(&device->packet_seq, 0);
39894 device->peer_seq = 0;
39895
39896 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
39897 @@ -1199,7 +1199,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39898 do {
39899 next_epoch = NULL;
39900
39901 - epoch_size = atomic_read(&epoch->epoch_size);
39902 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
39903
39904 switch (ev & ~EV_CLEANUP) {
39905 case EV_PUT:
39906 @@ -1239,7 +1239,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39907 rv = FE_DESTROYED;
39908 } else {
39909 epoch->flags = 0;
39910 - atomic_set(&epoch->epoch_size, 0);
39911 + atomic_set_unchecked(&epoch->epoch_size, 0);
39912 /* atomic_set(&epoch->active, 0); is already zero */
39913 if (rv == FE_STILL_LIVE)
39914 rv = FE_RECYCLED;
39915 @@ -1490,7 +1490,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39916 conn_wait_active_ee_empty(connection);
39917 drbd_flush(connection);
39918
39919 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39920 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39921 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
39922 if (epoch)
39923 break;
39924 @@ -1503,11 +1503,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39925 }
39926
39927 epoch->flags = 0;
39928 - atomic_set(&epoch->epoch_size, 0);
39929 + atomic_set_unchecked(&epoch->epoch_size, 0);
39930 atomic_set(&epoch->active, 0);
39931
39932 spin_lock(&connection->epoch_lock);
39933 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39934 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39935 list_add(&epoch->list, &connection->current_epoch->list);
39936 connection->current_epoch = epoch;
39937 connection->epochs++;
39938 @@ -2224,7 +2224,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39939
39940 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
39941 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39942 - atomic_inc(&connection->current_epoch->epoch_size);
39943 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
39944 err2 = drbd_drain_block(peer_device, pi->size);
39945 if (!err)
39946 err = err2;
39947 @@ -2266,7 +2266,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39948
39949 spin_lock(&connection->epoch_lock);
39950 peer_req->epoch = connection->current_epoch;
39951 - atomic_inc(&peer_req->epoch->epoch_size);
39952 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
39953 atomic_inc(&peer_req->epoch->active);
39954 spin_unlock(&connection->epoch_lock);
39955
39956 @@ -4461,7 +4461,7 @@ struct data_cmd {
39957 int expect_payload;
39958 size_t pkt_size;
39959 int (*fn)(struct drbd_connection *, struct packet_info *);
39960 -};
39961 +} __do_const;
39962
39963 static struct data_cmd drbd_cmd_handler[] = {
39964 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
39965 @@ -4572,7 +4572,7 @@ static void conn_disconnect(struct drbd_connection *connection)
39966 if (!list_empty(&connection->current_epoch->list))
39967 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
39968 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
39969 - atomic_set(&connection->current_epoch->epoch_size, 0);
39970 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
39971 connection->send.seen_any_write_yet = false;
39972
39973 drbd_info(connection, "Connection closed\n");
39974 @@ -5364,7 +5364,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
39975 struct asender_cmd {
39976 size_t pkt_size;
39977 int (*fn)(struct drbd_connection *connection, struct packet_info *);
39978 -};
39979 +} __do_const;
39980
39981 static struct asender_cmd asender_tbl[] = {
39982 [P_PING] = { 0, got_Ping },
39983 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39984 index 6cb1beb..bf490f7 100644
39985 --- a/drivers/block/loop.c
39986 +++ b/drivers/block/loop.c
39987 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
39988
39989 file_start_write(file);
39990 set_fs(get_ds());
39991 - bw = file->f_op->write(file, buf, len, &pos);
39992 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
39993 set_fs(old_fs);
39994 file_end_write(file);
39995 if (likely(bw == len))
39996 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
39997 index 02351e2..a9ea617 100644
39998 --- a/drivers/block/nvme-core.c
39999 +++ b/drivers/block/nvme-core.c
40000 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
40001 static struct task_struct *nvme_thread;
40002 static struct workqueue_struct *nvme_workq;
40003 static wait_queue_head_t nvme_kthread_wait;
40004 -static struct notifier_block nvme_nb;
40005
40006 static void nvme_reset_failed_dev(struct work_struct *ws);
40007
40008 @@ -2925,6 +2924,10 @@ static struct pci_driver nvme_driver = {
40009 .err_handler = &nvme_err_handler,
40010 };
40011
40012 +static struct notifier_block nvme_nb = {
40013 + .notifier_call = &nvme_cpu_notify,
40014 +};
40015 +
40016 static int __init nvme_init(void)
40017 {
40018 int result;
40019 @@ -2941,7 +2944,6 @@ static int __init nvme_init(void)
40020 else if (result > 0)
40021 nvme_major = result;
40022
40023 - nvme_nb.notifier_call = &nvme_cpu_notify;
40024 result = register_hotcpu_notifier(&nvme_nb);
40025 if (result)
40026 goto unregister_blkdev;
40027 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
40028 index 758ac44..58087fd 100644
40029 --- a/drivers/block/pktcdvd.c
40030 +++ b/drivers/block/pktcdvd.c
40031 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
40032
40033 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
40034 {
40035 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
40036 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
40037 }
40038
40039 /*
40040 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
40041 return -EROFS;
40042 }
40043 pd->settings.fp = ti.fp;
40044 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
40045 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
40046
40047 if (ti.nwa_v) {
40048 pd->nwa = be32_to_cpu(ti.next_writable);
40049 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
40050 index e5565fb..71be10b4 100644
40051 --- a/drivers/block/smart1,2.h
40052 +++ b/drivers/block/smart1,2.h
40053 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
40054 }
40055
40056 static struct access_method smart4_access = {
40057 - smart4_submit_command,
40058 - smart4_intr_mask,
40059 - smart4_fifo_full,
40060 - smart4_intr_pending,
40061 - smart4_completed,
40062 + .submit_command = smart4_submit_command,
40063 + .set_intr_mask = smart4_intr_mask,
40064 + .fifo_full = smart4_fifo_full,
40065 + .intr_pending = smart4_intr_pending,
40066 + .command_completed = smart4_completed,
40067 };
40068
40069 /*
40070 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
40071 }
40072
40073 static struct access_method smart2_access = {
40074 - smart2_submit_command,
40075 - smart2_intr_mask,
40076 - smart2_fifo_full,
40077 - smart2_intr_pending,
40078 - smart2_completed,
40079 + .submit_command = smart2_submit_command,
40080 + .set_intr_mask = smart2_intr_mask,
40081 + .fifo_full = smart2_fifo_full,
40082 + .intr_pending = smart2_intr_pending,
40083 + .command_completed = smart2_completed,
40084 };
40085
40086 /*
40087 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
40088 }
40089
40090 static struct access_method smart2e_access = {
40091 - smart2e_submit_command,
40092 - smart2e_intr_mask,
40093 - smart2e_fifo_full,
40094 - smart2e_intr_pending,
40095 - smart2e_completed,
40096 + .submit_command = smart2e_submit_command,
40097 + .set_intr_mask = smart2e_intr_mask,
40098 + .fifo_full = smart2e_fifo_full,
40099 + .intr_pending = smart2e_intr_pending,
40100 + .command_completed = smart2e_completed,
40101 };
40102
40103 /*
40104 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
40105 }
40106
40107 static struct access_method smart1_access = {
40108 - smart1_submit_command,
40109 - smart1_intr_mask,
40110 - smart1_fifo_full,
40111 - smart1_intr_pending,
40112 - smart1_completed,
40113 + .submit_command = smart1_submit_command,
40114 + .set_intr_mask = smart1_intr_mask,
40115 + .fifo_full = smart1_fifo_full,
40116 + .intr_pending = smart1_intr_pending,
40117 + .command_completed = smart1_completed,
40118 };
40119 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
40120 index f038dba..bb74c08 100644
40121 --- a/drivers/bluetooth/btwilink.c
40122 +++ b/drivers/bluetooth/btwilink.c
40123 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
40124
40125 static int bt_ti_probe(struct platform_device *pdev)
40126 {
40127 - static struct ti_st *hst;
40128 + struct ti_st *hst;
40129 struct hci_dev *hdev;
40130 int err;
40131
40132 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
40133 index 898b84b..86f74b9 100644
40134 --- a/drivers/cdrom/cdrom.c
40135 +++ b/drivers/cdrom/cdrom.c
40136 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
40137 ENSURE(reset, CDC_RESET);
40138 ENSURE(generic_packet, CDC_GENERIC_PACKET);
40139 cdi->mc_flags = 0;
40140 - cdo->n_minors = 0;
40141 cdi->options = CDO_USE_FFLAGS;
40142
40143 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
40144 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
40145 else
40146 cdi->cdda_method = CDDA_OLD;
40147
40148 - if (!cdo->generic_packet)
40149 - cdo->generic_packet = cdrom_dummy_generic_packet;
40150 + if (!cdo->generic_packet) {
40151 + pax_open_kernel();
40152 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
40153 + pax_close_kernel();
40154 + }
40155
40156 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
40157 mutex_lock(&cdrom_mutex);
40158 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
40159 if (cdi->exit)
40160 cdi->exit(cdi);
40161
40162 - cdi->ops->n_minors--;
40163 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
40164 }
40165
40166 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
40167 */
40168 nr = nframes;
40169 do {
40170 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
40171 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
40172 if (cgc.buffer)
40173 break;
40174
40175 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
40176 struct cdrom_device_info *cdi;
40177 int ret;
40178
40179 - ret = scnprintf(info + *pos, max_size - *pos, header);
40180 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
40181 if (!ret)
40182 return 1;
40183
40184 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
40185 index 584bc31..e64a12c 100644
40186 --- a/drivers/cdrom/gdrom.c
40187 +++ b/drivers/cdrom/gdrom.c
40188 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
40189 .audio_ioctl = gdrom_audio_ioctl,
40190 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
40191 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
40192 - .n_minors = 1,
40193 };
40194
40195 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
40196 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
40197 index 6e9f74a..50c7cea 100644
40198 --- a/drivers/char/Kconfig
40199 +++ b/drivers/char/Kconfig
40200 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
40201
40202 config DEVKMEM
40203 bool "/dev/kmem virtual device support"
40204 - default y
40205 + default n
40206 + depends on !GRKERNSEC_KMEM
40207 help
40208 Say Y here if you want to support the /dev/kmem device. The
40209 /dev/kmem device is rarely used, but can be used for certain
40210 @@ -577,6 +578,7 @@ config DEVPORT
40211 bool
40212 depends on !M68K
40213 depends on ISA || PCI
40214 + depends on !GRKERNSEC_KMEM
40215 default y
40216
40217 source "drivers/s390/char/Kconfig"
40218 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
40219 index a48e05b..6bac831 100644
40220 --- a/drivers/char/agp/compat_ioctl.c
40221 +++ b/drivers/char/agp/compat_ioctl.c
40222 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
40223 return -ENOMEM;
40224 }
40225
40226 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
40227 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
40228 sizeof(*usegment) * ureserve.seg_count)) {
40229 kfree(usegment);
40230 kfree(ksegment);
40231 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
40232 index b297033..fa217ca 100644
40233 --- a/drivers/char/agp/frontend.c
40234 +++ b/drivers/char/agp/frontend.c
40235 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
40236 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
40237 return -EFAULT;
40238
40239 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
40240 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
40241 return -EFAULT;
40242
40243 client = agp_find_client_by_pid(reserve.pid);
40244 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
40245 if (segment == NULL)
40246 return -ENOMEM;
40247
40248 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
40249 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
40250 sizeof(struct agp_segment) * reserve.seg_count)) {
40251 kfree(segment);
40252 return -EFAULT;
40253 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
40254 index 4f94375..413694e 100644
40255 --- a/drivers/char/genrtc.c
40256 +++ b/drivers/char/genrtc.c
40257 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
40258 switch (cmd) {
40259
40260 case RTC_PLL_GET:
40261 + memset(&pll, 0, sizeof(pll));
40262 if (get_rtc_pll(&pll))
40263 return -EINVAL;
40264 else
40265 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
40266 index d5d4cd8..22d561d 100644
40267 --- a/drivers/char/hpet.c
40268 +++ b/drivers/char/hpet.c
40269 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
40270 }
40271
40272 static int
40273 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
40274 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
40275 struct hpet_info *info)
40276 {
40277 struct hpet_timer __iomem *timer;
40278 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
40279 index 86fe45c..c0ea948 100644
40280 --- a/drivers/char/hw_random/intel-rng.c
40281 +++ b/drivers/char/hw_random/intel-rng.c
40282 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
40283
40284 if (no_fwh_detect)
40285 return -ENODEV;
40286 - printk(warning);
40287 + printk("%s", warning);
40288 return -EBUSY;
40289 }
40290
40291 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
40292 index e6db938..835e3a2 100644
40293 --- a/drivers/char/ipmi/ipmi_msghandler.c
40294 +++ b/drivers/char/ipmi/ipmi_msghandler.c
40295 @@ -438,7 +438,7 @@ struct ipmi_smi {
40296 struct proc_dir_entry *proc_dir;
40297 char proc_dir_name[10];
40298
40299 - atomic_t stats[IPMI_NUM_STATS];
40300 + atomic_unchecked_t stats[IPMI_NUM_STATS];
40301
40302 /*
40303 * run_to_completion duplicate of smb_info, smi_info
40304 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
40305 static DEFINE_MUTEX(smi_watchers_mutex);
40306
40307 #define ipmi_inc_stat(intf, stat) \
40308 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
40309 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
40310 #define ipmi_get_stat(intf, stat) \
40311 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
40312 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
40313
40314 static int is_lan_addr(struct ipmi_addr *addr)
40315 {
40316 @@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
40317 INIT_LIST_HEAD(&intf->cmd_rcvrs);
40318 init_waitqueue_head(&intf->waitq);
40319 for (i = 0; i < IPMI_NUM_STATS; i++)
40320 - atomic_set(&intf->stats[i], 0);
40321 + atomic_set_unchecked(&intf->stats[i], 0);
40322
40323 intf->proc_dir = NULL;
40324
40325 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
40326 index 5d66568..c9d93c3 100644
40327 --- a/drivers/char/ipmi/ipmi_si_intf.c
40328 +++ b/drivers/char/ipmi/ipmi_si_intf.c
40329 @@ -285,7 +285,7 @@ struct smi_info {
40330 unsigned char slave_addr;
40331
40332 /* Counters and things for the proc filesystem. */
40333 - atomic_t stats[SI_NUM_STATS];
40334 + atomic_unchecked_t stats[SI_NUM_STATS];
40335
40336 struct task_struct *thread;
40337
40338 @@ -294,9 +294,9 @@ struct smi_info {
40339 };
40340
40341 #define smi_inc_stat(smi, stat) \
40342 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
40343 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
40344 #define smi_get_stat(smi, stat) \
40345 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
40346 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
40347
40348 #define SI_MAX_PARMS 4
40349
40350 @@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
40351 atomic_set(&new_smi->req_events, 0);
40352 new_smi->run_to_completion = false;
40353 for (i = 0; i < SI_NUM_STATS; i++)
40354 - atomic_set(&new_smi->stats[i], 0);
40355 + atomic_set_unchecked(&new_smi->stats[i], 0);
40356
40357 new_smi->interrupt_disabled = true;
40358 atomic_set(&new_smi->stop_operation, 0);
40359 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
40360 index 917403f..dddd899 100644
40361 --- a/drivers/char/mem.c
40362 +++ b/drivers/char/mem.c
40363 @@ -18,6 +18,7 @@
40364 #include <linux/raw.h>
40365 #include <linux/tty.h>
40366 #include <linux/capability.h>
40367 +#include <linux/security.h>
40368 #include <linux/ptrace.h>
40369 #include <linux/device.h>
40370 #include <linux/highmem.h>
40371 @@ -36,6 +37,10 @@
40372
40373 #define DEVPORT_MINOR 4
40374
40375 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
40376 +extern const struct file_operations grsec_fops;
40377 +#endif
40378 +
40379 static inline unsigned long size_inside_page(unsigned long start,
40380 unsigned long size)
40381 {
40382 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40383
40384 while (cursor < to) {
40385 if (!devmem_is_allowed(pfn)) {
40386 +#ifdef CONFIG_GRKERNSEC_KMEM
40387 + gr_handle_mem_readwrite(from, to);
40388 +#else
40389 printk(KERN_INFO
40390 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
40391 current->comm, from, to);
40392 +#endif
40393 return 0;
40394 }
40395 cursor += PAGE_SIZE;
40396 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40397 }
40398 return 1;
40399 }
40400 +#elif defined(CONFIG_GRKERNSEC_KMEM)
40401 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40402 +{
40403 + return 0;
40404 +}
40405 #else
40406 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40407 {
40408 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
40409
40410 while (count > 0) {
40411 unsigned long remaining;
40412 + char *temp;
40413
40414 sz = size_inside_page(p, count);
40415
40416 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
40417 if (!ptr)
40418 return -EFAULT;
40419
40420 - remaining = copy_to_user(buf, ptr, sz);
40421 +#ifdef CONFIG_PAX_USERCOPY
40422 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
40423 + if (!temp) {
40424 + unxlate_dev_mem_ptr(p, ptr);
40425 + return -ENOMEM;
40426 + }
40427 + memcpy(temp, ptr, sz);
40428 +#else
40429 + temp = ptr;
40430 +#endif
40431 +
40432 + remaining = copy_to_user(buf, temp, sz);
40433 +
40434 +#ifdef CONFIG_PAX_USERCOPY
40435 + kfree(temp);
40436 +#endif
40437 +
40438 unxlate_dev_mem_ptr(p, ptr);
40439 if (remaining)
40440 return -EFAULT;
40441 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
40442 size_t count, loff_t *ppos)
40443 {
40444 unsigned long p = *ppos;
40445 - ssize_t low_count, read, sz;
40446 + ssize_t low_count, read, sz, err = 0;
40447 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
40448 - int err = 0;
40449
40450 read = 0;
40451 if (p < (unsigned long) high_memory) {
40452 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
40453 }
40454 #endif
40455 while (low_count > 0) {
40456 + char *temp;
40457 +
40458 sz = size_inside_page(p, low_count);
40459
40460 /*
40461 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
40462 */
40463 kbuf = xlate_dev_kmem_ptr((char *)p);
40464
40465 - if (copy_to_user(buf, kbuf, sz))
40466 +#ifdef CONFIG_PAX_USERCOPY
40467 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
40468 + if (!temp)
40469 + return -ENOMEM;
40470 + memcpy(temp, kbuf, sz);
40471 +#else
40472 + temp = kbuf;
40473 +#endif
40474 +
40475 + err = copy_to_user(buf, temp, sz);
40476 +
40477 +#ifdef CONFIG_PAX_USERCOPY
40478 + kfree(temp);
40479 +#endif
40480 +
40481 + if (err)
40482 return -EFAULT;
40483 buf += sz;
40484 p += sz;
40485 @@ -827,6 +874,9 @@ static const struct memdev {
40486 #ifdef CONFIG_PRINTK
40487 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
40488 #endif
40489 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
40490 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
40491 +#endif
40492 };
40493
40494 static int memory_open(struct inode *inode, struct file *filp)
40495 @@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
40496 continue;
40497
40498 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
40499 - NULL, devlist[minor].name);
40500 + NULL, "%s", devlist[minor].name);
40501 }
40502
40503 return tty_init();
40504 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
40505 index 9df78e2..01ba9ae 100644
40506 --- a/drivers/char/nvram.c
40507 +++ b/drivers/char/nvram.c
40508 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
40509
40510 spin_unlock_irq(&rtc_lock);
40511
40512 - if (copy_to_user(buf, contents, tmp - contents))
40513 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
40514 return -EFAULT;
40515
40516 *ppos = i;
40517 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
40518 index 8320abd..ec48108 100644
40519 --- a/drivers/char/pcmcia/synclink_cs.c
40520 +++ b/drivers/char/pcmcia/synclink_cs.c
40521 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
40522
40523 if (debug_level >= DEBUG_LEVEL_INFO)
40524 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
40525 - __FILE__, __LINE__, info->device_name, port->count);
40526 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
40527
40528 - WARN_ON(!port->count);
40529 + WARN_ON(!atomic_read(&port->count));
40530
40531 if (tty_port_close_start(port, tty, filp) == 0)
40532 goto cleanup;
40533 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
40534 cleanup:
40535 if (debug_level >= DEBUG_LEVEL_INFO)
40536 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
40537 - tty->driver->name, port->count);
40538 + tty->driver->name, atomic_read(&port->count));
40539 }
40540
40541 /* Wait until the transmitter is empty.
40542 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
40543
40544 if (debug_level >= DEBUG_LEVEL_INFO)
40545 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
40546 - __FILE__, __LINE__, tty->driver->name, port->count);
40547 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
40548
40549 /* If port is closing, signal caller to try again */
40550 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
40551 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
40552 goto cleanup;
40553 }
40554 spin_lock(&port->lock);
40555 - port->count++;
40556 + atomic_inc(&port->count);
40557 spin_unlock(&port->lock);
40558 spin_unlock_irqrestore(&info->netlock, flags);
40559
40560 - if (port->count == 1) {
40561 + if (atomic_read(&port->count) == 1) {
40562 /* 1st open on this device, init hardware */
40563 retval = startup(info, tty);
40564 if (retval < 0)
40565 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40566 unsigned short new_crctype;
40567
40568 /* return error if TTY interface open */
40569 - if (info->port.count)
40570 + if (atomic_read(&info->port.count))
40571 return -EBUSY;
40572
40573 switch (encoding)
40574 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
40575
40576 /* arbitrate between network and tty opens */
40577 spin_lock_irqsave(&info->netlock, flags);
40578 - if (info->port.count != 0 || info->netcount != 0) {
40579 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40580 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40581 spin_unlock_irqrestore(&info->netlock, flags);
40582 return -EBUSY;
40583 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40584 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
40585
40586 /* return error if TTY interface open */
40587 - if (info->port.count)
40588 + if (atomic_read(&info->port.count))
40589 return -EBUSY;
40590
40591 if (cmd != SIOCWANDEV)
40592 diff --git a/drivers/char/random.c b/drivers/char/random.c
40593 index 71529e1..822b036 100644
40594 --- a/drivers/char/random.c
40595 +++ b/drivers/char/random.c
40596 @@ -284,9 +284,6 @@
40597 /*
40598 * To allow fractional bits to be tracked, the entropy_count field is
40599 * denominated in units of 1/8th bits.
40600 - *
40601 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
40602 - * credit_entropy_bits() needs to be 64 bits wide.
40603 */
40604 #define ENTROPY_SHIFT 3
40605 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
40606 @@ -433,9 +430,9 @@ struct entropy_store {
40607 };
40608
40609 static void push_to_pool(struct work_struct *work);
40610 -static __u32 input_pool_data[INPUT_POOL_WORDS];
40611 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
40612 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
40613 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
40614 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
40615 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
40616
40617 static struct entropy_store input_pool = {
40618 .poolinfo = &poolinfo_table[0],
40619 @@ -524,8 +521,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
40620 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
40621 }
40622
40623 - ACCESS_ONCE(r->input_rotate) = input_rotate;
40624 - ACCESS_ONCE(r->add_ptr) = i;
40625 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
40626 + ACCESS_ONCE_RW(r->add_ptr) = i;
40627 smp_wmb();
40628
40629 if (out)
40630 @@ -632,7 +629,7 @@ retry:
40631 /* The +2 corresponds to the /4 in the denominator */
40632
40633 do {
40634 - unsigned int anfrac = min(pnfrac, pool_size/2);
40635 + u64 anfrac = min(pnfrac, pool_size/2);
40636 unsigned int add =
40637 ((pool_size - entropy_count)*anfrac*3) >> s;
40638
40639 @@ -1177,7 +1174,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
40640
40641 extract_buf(r, tmp);
40642 i = min_t(int, nbytes, EXTRACT_SIZE);
40643 - if (copy_to_user(buf, tmp, i)) {
40644 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
40645 ret = -EFAULT;
40646 break;
40647 }
40648 @@ -1567,7 +1564,7 @@ static char sysctl_bootid[16];
40649 static int proc_do_uuid(struct ctl_table *table, int write,
40650 void __user *buffer, size_t *lenp, loff_t *ppos)
40651 {
40652 - struct ctl_table fake_table;
40653 + ctl_table_no_const fake_table;
40654 unsigned char buf[64], tmp_uuid[16], *uuid;
40655
40656 uuid = table->data;
40657 @@ -1597,7 +1594,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
40658 static int proc_do_entropy(struct ctl_table *table, int write,
40659 void __user *buffer, size_t *lenp, loff_t *ppos)
40660 {
40661 - struct ctl_table fake_table;
40662 + ctl_table_no_const fake_table;
40663 int entropy_count;
40664
40665 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
40666 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
40667 index 7cc1fe22..b602d6b 100644
40668 --- a/drivers/char/sonypi.c
40669 +++ b/drivers/char/sonypi.c
40670 @@ -54,6 +54,7 @@
40671
40672 #include <asm/uaccess.h>
40673 #include <asm/io.h>
40674 +#include <asm/local.h>
40675
40676 #include <linux/sonypi.h>
40677
40678 @@ -490,7 +491,7 @@ static struct sonypi_device {
40679 spinlock_t fifo_lock;
40680 wait_queue_head_t fifo_proc_list;
40681 struct fasync_struct *fifo_async;
40682 - int open_count;
40683 + local_t open_count;
40684 int model;
40685 struct input_dev *input_jog_dev;
40686 struct input_dev *input_key_dev;
40687 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
40688 static int sonypi_misc_release(struct inode *inode, struct file *file)
40689 {
40690 mutex_lock(&sonypi_device.lock);
40691 - sonypi_device.open_count--;
40692 + local_dec(&sonypi_device.open_count);
40693 mutex_unlock(&sonypi_device.lock);
40694 return 0;
40695 }
40696 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
40697 {
40698 mutex_lock(&sonypi_device.lock);
40699 /* Flush input queue on first open */
40700 - if (!sonypi_device.open_count)
40701 + if (!local_read(&sonypi_device.open_count))
40702 kfifo_reset(&sonypi_device.fifo);
40703 - sonypi_device.open_count++;
40704 + local_inc(&sonypi_device.open_count);
40705 mutex_unlock(&sonypi_device.lock);
40706
40707 return 0;
40708 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
40709 index 565a947..dcdc06e 100644
40710 --- a/drivers/char/tpm/tpm_acpi.c
40711 +++ b/drivers/char/tpm/tpm_acpi.c
40712 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
40713 virt = acpi_os_map_iomem(start, len);
40714 if (!virt) {
40715 kfree(log->bios_event_log);
40716 + log->bios_event_log = NULL;
40717 printk("%s: ERROR - Unable to map memory\n", __func__);
40718 return -EIO;
40719 }
40720
40721 - memcpy_fromio(log->bios_event_log, virt, len);
40722 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
40723
40724 acpi_os_unmap_iomem(virt, len);
40725 return 0;
40726 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
40727 index 59f7cb2..bac8b6d 100644
40728 --- a/drivers/char/tpm/tpm_eventlog.c
40729 +++ b/drivers/char/tpm/tpm_eventlog.c
40730 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
40731 event = addr;
40732
40733 if ((event->event_type == 0 && event->event_size == 0) ||
40734 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
40735 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
40736 return NULL;
40737
40738 return addr;
40739 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
40740 return NULL;
40741
40742 if ((event->event_type == 0 && event->event_size == 0) ||
40743 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
40744 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
40745 return NULL;
40746
40747 (*pos)++;
40748 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
40749 int i;
40750
40751 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
40752 - seq_putc(m, data[i]);
40753 + if (!seq_putc(m, data[i]))
40754 + return -EFAULT;
40755
40756 return 0;
40757 }
40758 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
40759 index 60aafb8..10c08e0 100644
40760 --- a/drivers/char/virtio_console.c
40761 +++ b/drivers/char/virtio_console.c
40762 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
40763 if (to_user) {
40764 ssize_t ret;
40765
40766 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
40767 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
40768 if (ret)
40769 return -EFAULT;
40770 } else {
40771 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
40772 if (!port_has_data(port) && !port->host_connected)
40773 return 0;
40774
40775 - return fill_readbuf(port, ubuf, count, true);
40776 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
40777 }
40778
40779 static int wait_port_writable(struct port *port, bool nonblock)
40780 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
40781 index 57a078e..c17cde8 100644
40782 --- a/drivers/clk/clk-composite.c
40783 +++ b/drivers/clk/clk-composite.c
40784 @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
40785 struct clk *clk;
40786 struct clk_init_data init;
40787 struct clk_composite *composite;
40788 - struct clk_ops *clk_composite_ops;
40789 + clk_ops_no_const *clk_composite_ops;
40790
40791 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
40792 if (!composite) {
40793 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
40794 index dd3a78c..386d49c 100644
40795 --- a/drivers/clk/socfpga/clk-gate.c
40796 +++ b/drivers/clk/socfpga/clk-gate.c
40797 @@ -22,6 +22,7 @@
40798 #include <linux/mfd/syscon.h>
40799 #include <linux/of.h>
40800 #include <linux/regmap.h>
40801 +#include <asm/pgtable.h>
40802
40803 #include "clk.h"
40804
40805 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
40806 return 0;
40807 }
40808
40809 -static struct clk_ops gateclk_ops = {
40810 +static clk_ops_no_const gateclk_ops __read_only = {
40811 .prepare = socfpga_clk_prepare,
40812 .recalc_rate = socfpga_clk_recalc_rate,
40813 .get_parent = socfpga_clk_get_parent,
40814 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
40815 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
40816 socfpga_clk->hw.bit_idx = clk_gate[1];
40817
40818 - gateclk_ops.enable = clk_gate_ops.enable;
40819 - gateclk_ops.disable = clk_gate_ops.disable;
40820 + pax_open_kernel();
40821 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
40822 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
40823 + pax_close_kernel();
40824 }
40825
40826 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
40827 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
40828 index de6da95..c98278b 100644
40829 --- a/drivers/clk/socfpga/clk-pll.c
40830 +++ b/drivers/clk/socfpga/clk-pll.c
40831 @@ -21,6 +21,7 @@
40832 #include <linux/io.h>
40833 #include <linux/of.h>
40834 #include <linux/of_address.h>
40835 +#include <asm/pgtable.h>
40836
40837 #include "clk.h"
40838
40839 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
40840 CLK_MGR_PLL_CLK_SRC_MASK;
40841 }
40842
40843 -static struct clk_ops clk_pll_ops = {
40844 +static clk_ops_no_const clk_pll_ops __read_only = {
40845 .recalc_rate = clk_pll_recalc_rate,
40846 .get_parent = clk_pll_get_parent,
40847 };
40848 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
40849 pll_clk->hw.hw.init = &init;
40850
40851 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
40852 - clk_pll_ops.enable = clk_gate_ops.enable;
40853 - clk_pll_ops.disable = clk_gate_ops.disable;
40854 + pax_open_kernel();
40855 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
40856 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
40857 + pax_close_kernel();
40858
40859 clk = clk_register(NULL, &pll_clk->hw.hw);
40860 if (WARN_ON(IS_ERR(clk))) {
40861 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
40862 index b0c18ed..1713a80 100644
40863 --- a/drivers/cpufreq/acpi-cpufreq.c
40864 +++ b/drivers/cpufreq/acpi-cpufreq.c
40865 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40866 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
40867 per_cpu(acfreq_data, cpu) = data;
40868
40869 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
40870 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40871 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
40872 + pax_open_kernel();
40873 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40874 + pax_close_kernel();
40875 + }
40876
40877 result = acpi_processor_register_performance(data->acpi_data, cpu);
40878 if (result)
40879 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40880 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
40881 break;
40882 case ACPI_ADR_SPACE_FIXED_HARDWARE:
40883 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40884 + pax_open_kernel();
40885 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40886 + pax_close_kernel();
40887 break;
40888 default:
40889 break;
40890 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
40891 if (!msrs)
40892 return;
40893
40894 - acpi_cpufreq_driver.boost_supported = true;
40895 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
40896 + pax_open_kernel();
40897 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
40898 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
40899 + pax_close_kernel();
40900
40901 cpu_notifier_register_begin();
40902
40903 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
40904 index 6f02485..13684ae 100644
40905 --- a/drivers/cpufreq/cpufreq.c
40906 +++ b/drivers/cpufreq/cpufreq.c
40907 @@ -2100,7 +2100,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
40908 }
40909
40910 mutex_lock(&cpufreq_governor_mutex);
40911 - list_del(&governor->governor_list);
40912 + pax_list_del(&governor->governor_list);
40913 mutex_unlock(&cpufreq_governor_mutex);
40914 return;
40915 }
40916 @@ -2316,7 +2316,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
40917 return NOTIFY_OK;
40918 }
40919
40920 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
40921 +static struct notifier_block cpufreq_cpu_notifier = {
40922 .notifier_call = cpufreq_cpu_callback,
40923 };
40924
40925 @@ -2356,13 +2356,17 @@ int cpufreq_boost_trigger_state(int state)
40926 return 0;
40927
40928 write_lock_irqsave(&cpufreq_driver_lock, flags);
40929 - cpufreq_driver->boost_enabled = state;
40930 + pax_open_kernel();
40931 + *(bool *)&cpufreq_driver->boost_enabled = state;
40932 + pax_close_kernel();
40933 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40934
40935 ret = cpufreq_driver->set_boost(state);
40936 if (ret) {
40937 write_lock_irqsave(&cpufreq_driver_lock, flags);
40938 - cpufreq_driver->boost_enabled = !state;
40939 + pax_open_kernel();
40940 + *(bool *)&cpufreq_driver->boost_enabled = !state;
40941 + pax_close_kernel();
40942 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40943
40944 pr_err("%s: Cannot %s BOOST\n",
40945 @@ -2419,8 +2423,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40946
40947 pr_debug("trying to register driver %s\n", driver_data->name);
40948
40949 - if (driver_data->setpolicy)
40950 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
40951 + if (driver_data->setpolicy) {
40952 + pax_open_kernel();
40953 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
40954 + pax_close_kernel();
40955 + }
40956
40957 write_lock_irqsave(&cpufreq_driver_lock, flags);
40958 if (cpufreq_driver) {
40959 @@ -2435,8 +2442,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40960 * Check if driver provides function to enable boost -
40961 * if not, use cpufreq_boost_set_sw as default
40962 */
40963 - if (!cpufreq_driver->set_boost)
40964 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40965 + if (!cpufreq_driver->set_boost) {
40966 + pax_open_kernel();
40967 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40968 + pax_close_kernel();
40969 + }
40970
40971 ret = cpufreq_sysfs_create_file(&boost.attr);
40972 if (ret) {
40973 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
40974 index 1b44496..b80ff5e 100644
40975 --- a/drivers/cpufreq/cpufreq_governor.c
40976 +++ b/drivers/cpufreq/cpufreq_governor.c
40977 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40978 struct dbs_data *dbs_data;
40979 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
40980 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
40981 - struct od_ops *od_ops = NULL;
40982 + const struct od_ops *od_ops = NULL;
40983 struct od_dbs_tuners *od_tuners = NULL;
40984 struct cs_dbs_tuners *cs_tuners = NULL;
40985 struct cpu_dbs_common_info *cpu_cdbs;
40986 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40987
40988 if ((cdata->governor == GOV_CONSERVATIVE) &&
40989 (!policy->governor->initialized)) {
40990 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40991 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40992
40993 cpufreq_register_notifier(cs_ops->notifier_block,
40994 CPUFREQ_TRANSITION_NOTIFIER);
40995 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40996
40997 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
40998 (policy->governor->initialized == 1)) {
40999 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
41000 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
41001
41002 cpufreq_unregister_notifier(cs_ops->notifier_block,
41003 CPUFREQ_TRANSITION_NOTIFIER);
41004 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
41005 index cc401d1..8197340 100644
41006 --- a/drivers/cpufreq/cpufreq_governor.h
41007 +++ b/drivers/cpufreq/cpufreq_governor.h
41008 @@ -212,7 +212,7 @@ struct common_dbs_data {
41009 void (*exit)(struct dbs_data *dbs_data);
41010
41011 /* Governor specific ops, see below */
41012 - void *gov_ops;
41013 + const void *gov_ops;
41014 };
41015
41016 /* Governor Per policy data */
41017 @@ -232,7 +232,7 @@ struct od_ops {
41018 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
41019 unsigned int freq_next, unsigned int relation);
41020 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
41021 -};
41022 +} __no_const;
41023
41024 struct cs_ops {
41025 struct notifier_block *notifier_block;
41026 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
41027 index 18d4091..434be15 100644
41028 --- a/drivers/cpufreq/cpufreq_ondemand.c
41029 +++ b/drivers/cpufreq/cpufreq_ondemand.c
41030 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
41031
41032 define_get_cpu_dbs_routines(od_cpu_dbs_info);
41033
41034 -static struct od_ops od_ops = {
41035 +static struct od_ops od_ops __read_only = {
41036 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
41037 .powersave_bias_target = generic_powersave_bias_target,
41038 .freq_increase = dbs_freq_increase,
41039 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
41040 (struct cpufreq_policy *, unsigned int, unsigned int),
41041 unsigned int powersave_bias)
41042 {
41043 - od_ops.powersave_bias_target = f;
41044 + pax_open_kernel();
41045 + *(void **)&od_ops.powersave_bias_target = f;
41046 + pax_close_kernel();
41047 od_set_powersave_bias(powersave_bias);
41048 }
41049 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
41050
41051 void od_unregister_powersave_bias_handler(void)
41052 {
41053 - od_ops.powersave_bias_target = generic_powersave_bias_target;
41054 + pax_open_kernel();
41055 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
41056 + pax_close_kernel();
41057 od_set_powersave_bias(0);
41058 }
41059 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
41060 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
41061 index 86631cb..c34ec78 100644
41062 --- a/drivers/cpufreq/intel_pstate.c
41063 +++ b/drivers/cpufreq/intel_pstate.c
41064 @@ -121,10 +121,10 @@ struct pstate_funcs {
41065 struct cpu_defaults {
41066 struct pstate_adjust_policy pid_policy;
41067 struct pstate_funcs funcs;
41068 -};
41069 +} __do_const;
41070
41071 static struct pstate_adjust_policy pid_params;
41072 -static struct pstate_funcs pstate_funcs;
41073 +static struct pstate_funcs *pstate_funcs;
41074
41075 struct perf_limits {
41076 int no_turbo;
41077 @@ -526,7 +526,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
41078
41079 cpu->pstate.current_pstate = pstate;
41080
41081 - pstate_funcs.set(cpu, pstate);
41082 + pstate_funcs->set(cpu, pstate);
41083 }
41084
41085 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
41086 @@ -546,12 +546,12 @@ static inline void intel_pstate_pstate_decrease(struct cpudata *cpu, int steps)
41087
41088 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
41089 {
41090 - cpu->pstate.min_pstate = pstate_funcs.get_min();
41091 - cpu->pstate.max_pstate = pstate_funcs.get_max();
41092 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
41093 + cpu->pstate.min_pstate = pstate_funcs->get_min();
41094 + cpu->pstate.max_pstate = pstate_funcs->get_max();
41095 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
41096
41097 - if (pstate_funcs.get_vid)
41098 - pstate_funcs.get_vid(cpu);
41099 + if (pstate_funcs->get_vid)
41100 + pstate_funcs->get_vid(cpu);
41101 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
41102 }
41103
41104 @@ -838,9 +838,9 @@ static int intel_pstate_msrs_not_valid(void)
41105 rdmsrl(MSR_IA32_APERF, aperf);
41106 rdmsrl(MSR_IA32_MPERF, mperf);
41107
41108 - if (!pstate_funcs.get_max() ||
41109 - !pstate_funcs.get_min() ||
41110 - !pstate_funcs.get_turbo())
41111 + if (!pstate_funcs->get_max() ||
41112 + !pstate_funcs->get_min() ||
41113 + !pstate_funcs->get_turbo())
41114 return -ENODEV;
41115
41116 rdmsrl(MSR_IA32_APERF, tmp);
41117 @@ -854,7 +854,7 @@ static int intel_pstate_msrs_not_valid(void)
41118 return 0;
41119 }
41120
41121 -static void copy_pid_params(struct pstate_adjust_policy *policy)
41122 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
41123 {
41124 pid_params.sample_rate_ms = policy->sample_rate_ms;
41125 pid_params.p_gain_pct = policy->p_gain_pct;
41126 @@ -866,11 +866,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
41127
41128 static void copy_cpu_funcs(struct pstate_funcs *funcs)
41129 {
41130 - pstate_funcs.get_max = funcs->get_max;
41131 - pstate_funcs.get_min = funcs->get_min;
41132 - pstate_funcs.get_turbo = funcs->get_turbo;
41133 - pstate_funcs.set = funcs->set;
41134 - pstate_funcs.get_vid = funcs->get_vid;
41135 + pstate_funcs = funcs;
41136 }
41137
41138 #if IS_ENABLED(CONFIG_ACPI)
41139 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
41140 index 529cfd9..0e28fff 100644
41141 --- a/drivers/cpufreq/p4-clockmod.c
41142 +++ b/drivers/cpufreq/p4-clockmod.c
41143 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
41144 case 0x0F: /* Core Duo */
41145 case 0x16: /* Celeron Core */
41146 case 0x1C: /* Atom */
41147 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41148 + pax_open_kernel();
41149 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41150 + pax_close_kernel();
41151 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
41152 case 0x0D: /* Pentium M (Dothan) */
41153 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41154 + pax_open_kernel();
41155 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41156 + pax_close_kernel();
41157 /* fall through */
41158 case 0x09: /* Pentium M (Banias) */
41159 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
41160 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
41161
41162 /* on P-4s, the TSC runs with constant frequency independent whether
41163 * throttling is active or not. */
41164 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41165 + pax_open_kernel();
41166 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41167 + pax_close_kernel();
41168
41169 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
41170 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
41171 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
41172 index 9bb42ba..b01b4a2 100644
41173 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
41174 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
41175 @@ -18,14 +18,12 @@
41176 #include <asm/head.h>
41177 #include <asm/timer.h>
41178
41179 -static struct cpufreq_driver *cpufreq_us3_driver;
41180 -
41181 struct us3_freq_percpu_info {
41182 struct cpufreq_frequency_table table[4];
41183 };
41184
41185 /* Indexed by cpu number. */
41186 -static struct us3_freq_percpu_info *us3_freq_table;
41187 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
41188
41189 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
41190 * in the Safari config register.
41191 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
41192
41193 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
41194 {
41195 - if (cpufreq_us3_driver)
41196 - us3_freq_target(policy, 0);
41197 + us3_freq_target(policy, 0);
41198
41199 return 0;
41200 }
41201
41202 +static int __init us3_freq_init(void);
41203 +static void __exit us3_freq_exit(void);
41204 +
41205 +static struct cpufreq_driver cpufreq_us3_driver = {
41206 + .init = us3_freq_cpu_init,
41207 + .verify = cpufreq_generic_frequency_table_verify,
41208 + .target_index = us3_freq_target,
41209 + .get = us3_freq_get,
41210 + .exit = us3_freq_cpu_exit,
41211 + .name = "UltraSPARC-III",
41212 +
41213 +};
41214 +
41215 static int __init us3_freq_init(void)
41216 {
41217 unsigned long manuf, impl, ver;
41218 - int ret;
41219
41220 if (tlb_type != cheetah && tlb_type != cheetah_plus)
41221 return -ENODEV;
41222 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
41223 (impl == CHEETAH_IMPL ||
41224 impl == CHEETAH_PLUS_IMPL ||
41225 impl == JAGUAR_IMPL ||
41226 - impl == PANTHER_IMPL)) {
41227 - struct cpufreq_driver *driver;
41228 -
41229 - ret = -ENOMEM;
41230 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
41231 - if (!driver)
41232 - goto err_out;
41233 -
41234 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
41235 - GFP_KERNEL);
41236 - if (!us3_freq_table)
41237 - goto err_out;
41238 -
41239 - driver->init = us3_freq_cpu_init;
41240 - driver->verify = cpufreq_generic_frequency_table_verify;
41241 - driver->target_index = us3_freq_target;
41242 - driver->get = us3_freq_get;
41243 - driver->exit = us3_freq_cpu_exit;
41244 - strcpy(driver->name, "UltraSPARC-III");
41245 -
41246 - cpufreq_us3_driver = driver;
41247 - ret = cpufreq_register_driver(driver);
41248 - if (ret)
41249 - goto err_out;
41250 -
41251 - return 0;
41252 -
41253 -err_out:
41254 - if (driver) {
41255 - kfree(driver);
41256 - cpufreq_us3_driver = NULL;
41257 - }
41258 - kfree(us3_freq_table);
41259 - us3_freq_table = NULL;
41260 - return ret;
41261 - }
41262 + impl == PANTHER_IMPL))
41263 + return cpufreq_register_driver(&cpufreq_us3_driver);
41264
41265 return -ENODEV;
41266 }
41267
41268 static void __exit us3_freq_exit(void)
41269 {
41270 - if (cpufreq_us3_driver) {
41271 - cpufreq_unregister_driver(cpufreq_us3_driver);
41272 - kfree(cpufreq_us3_driver);
41273 - cpufreq_us3_driver = NULL;
41274 - kfree(us3_freq_table);
41275 - us3_freq_table = NULL;
41276 - }
41277 + cpufreq_unregister_driver(&cpufreq_us3_driver);
41278 }
41279
41280 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
41281 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
41282 index 7d4a315..21bb886 100644
41283 --- a/drivers/cpufreq/speedstep-centrino.c
41284 +++ b/drivers/cpufreq/speedstep-centrino.c
41285 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
41286 !cpu_has(cpu, X86_FEATURE_EST))
41287 return -ENODEV;
41288
41289 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
41290 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
41291 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
41292 + pax_open_kernel();
41293 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
41294 + pax_close_kernel();
41295 + }
41296
41297 if (policy->cpu != 0)
41298 return -ENODEV;
41299 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
41300 index 9634f20..e1499c7 100644
41301 --- a/drivers/cpuidle/driver.c
41302 +++ b/drivers/cpuidle/driver.c
41303 @@ -205,7 +205,7 @@ static int poll_idle(struct cpuidle_device *dev,
41304
41305 static void poll_idle_init(struct cpuidle_driver *drv)
41306 {
41307 - struct cpuidle_state *state = &drv->states[0];
41308 + cpuidle_state_no_const *state = &drv->states[0];
41309
41310 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
41311 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
41312 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
41313 index ca89412..a7b9c49 100644
41314 --- a/drivers/cpuidle/governor.c
41315 +++ b/drivers/cpuidle/governor.c
41316 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
41317 mutex_lock(&cpuidle_lock);
41318 if (__cpuidle_find_governor(gov->name) == NULL) {
41319 ret = 0;
41320 - list_add_tail(&gov->governor_list, &cpuidle_governors);
41321 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
41322 if (!cpuidle_curr_governor ||
41323 cpuidle_curr_governor->rating < gov->rating)
41324 cpuidle_switch_governor(gov);
41325 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
41326 index efe2f17..b8124f9 100644
41327 --- a/drivers/cpuidle/sysfs.c
41328 +++ b/drivers/cpuidle/sysfs.c
41329 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
41330 NULL
41331 };
41332
41333 -static struct attribute_group cpuidle_attr_group = {
41334 +static attribute_group_no_const cpuidle_attr_group = {
41335 .attrs = cpuidle_default_attrs,
41336 .name = "cpuidle",
41337 };
41338 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
41339 index 12fea3e..1e28f47 100644
41340 --- a/drivers/crypto/hifn_795x.c
41341 +++ b/drivers/crypto/hifn_795x.c
41342 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
41343 MODULE_PARM_DESC(hifn_pll_ref,
41344 "PLL reference clock (pci[freq] or ext[freq], default ext)");
41345
41346 -static atomic_t hifn_dev_number;
41347 +static atomic_unchecked_t hifn_dev_number;
41348
41349 #define ACRYPTO_OP_DECRYPT 0
41350 #define ACRYPTO_OP_ENCRYPT 1
41351 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
41352 goto err_out_disable_pci_device;
41353
41354 snprintf(name, sizeof(name), "hifn%d",
41355 - atomic_inc_return(&hifn_dev_number)-1);
41356 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
41357
41358 err = pci_request_regions(pdev, name);
41359 if (err)
41360 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
41361 index 9f90369..bfcacdb 100644
41362 --- a/drivers/devfreq/devfreq.c
41363 +++ b/drivers/devfreq/devfreq.c
41364 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
41365 goto err_out;
41366 }
41367
41368 - list_add(&governor->node, &devfreq_governor_list);
41369 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
41370
41371 list_for_each_entry(devfreq, &devfreq_list, node) {
41372 int ret = 0;
41373 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
41374 }
41375 }
41376
41377 - list_del(&governor->node);
41378 + pax_list_del((struct list_head *)&governor->node);
41379 err_out:
41380 mutex_unlock(&devfreq_list_lock);
41381
41382 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
41383 index b35007e..55ad549 100644
41384 --- a/drivers/dma/sh/shdma-base.c
41385 +++ b/drivers/dma/sh/shdma-base.c
41386 @@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
41387 schan->slave_id = -EINVAL;
41388 }
41389
41390 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
41391 - sdev->desc_size, GFP_KERNEL);
41392 + schan->desc = kcalloc(sdev->desc_size,
41393 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
41394 if (!schan->desc) {
41395 ret = -ENOMEM;
41396 goto edescalloc;
41397 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
41398 index 146d5df..3c14970 100644
41399 --- a/drivers/dma/sh/shdmac.c
41400 +++ b/drivers/dma/sh/shdmac.c
41401 @@ -514,7 +514,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
41402 return ret;
41403 }
41404
41405 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
41406 +static struct notifier_block sh_dmae_nmi_notifier = {
41407 .notifier_call = sh_dmae_nmi_handler,
41408
41409 /* Run before NMI debug handler and KGDB */
41410 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
41411 index 592af5f..bb1d583 100644
41412 --- a/drivers/edac/edac_device.c
41413 +++ b/drivers/edac/edac_device.c
41414 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
41415 */
41416 int edac_device_alloc_index(void)
41417 {
41418 - static atomic_t device_indexes = ATOMIC_INIT(0);
41419 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
41420
41421 - return atomic_inc_return(&device_indexes) - 1;
41422 + return atomic_inc_return_unchecked(&device_indexes) - 1;
41423 }
41424 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
41425
41426 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
41427 index 01fae82..1dd8289 100644
41428 --- a/drivers/edac/edac_mc_sysfs.c
41429 +++ b/drivers/edac/edac_mc_sysfs.c
41430 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
41431 struct dev_ch_attribute {
41432 struct device_attribute attr;
41433 int channel;
41434 -};
41435 +} __do_const;
41436
41437 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
41438 struct dev_ch_attribute dev_attr_legacy_##_name = \
41439 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
41440 }
41441
41442 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
41443 + pax_open_kernel();
41444 if (mci->get_sdram_scrub_rate) {
41445 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
41446 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
41447 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
41448 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
41449 }
41450 if (mci->set_sdram_scrub_rate) {
41451 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
41452 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
41453 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
41454 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
41455 }
41456 + pax_close_kernel();
41457 err = device_create_file(&mci->dev,
41458 &dev_attr_sdram_scrub_rate);
41459 if (err) {
41460 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
41461 index 2cf44b4d..6dd2dc7 100644
41462 --- a/drivers/edac/edac_pci.c
41463 +++ b/drivers/edac/edac_pci.c
41464 @@ -29,7 +29,7 @@
41465
41466 static DEFINE_MUTEX(edac_pci_ctls_mutex);
41467 static LIST_HEAD(edac_pci_list);
41468 -static atomic_t pci_indexes = ATOMIC_INIT(0);
41469 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
41470
41471 /*
41472 * edac_pci_alloc_ctl_info
41473 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
41474 */
41475 int edac_pci_alloc_index(void)
41476 {
41477 - return atomic_inc_return(&pci_indexes) - 1;
41478 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
41479 }
41480 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
41481
41482 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
41483 index e8658e4..22746d6 100644
41484 --- a/drivers/edac/edac_pci_sysfs.c
41485 +++ b/drivers/edac/edac_pci_sysfs.c
41486 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
41487 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
41488 static int edac_pci_poll_msec = 1000; /* one second workq period */
41489
41490 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
41491 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
41492 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
41493 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
41494
41495 static struct kobject *edac_pci_top_main_kobj;
41496 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
41497 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
41498 void *value;
41499 ssize_t(*show) (void *, char *);
41500 ssize_t(*store) (void *, const char *, size_t);
41501 -};
41502 +} __do_const;
41503
41504 /* Set of show/store abstract level functions for PCI Parity object */
41505 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
41506 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41507 edac_printk(KERN_CRIT, EDAC_PCI,
41508 "Signaled System Error on %s\n",
41509 pci_name(dev));
41510 - atomic_inc(&pci_nonparity_count);
41511 + atomic_inc_unchecked(&pci_nonparity_count);
41512 }
41513
41514 if (status & (PCI_STATUS_PARITY)) {
41515 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41516 "Master Data Parity Error on %s\n",
41517 pci_name(dev));
41518
41519 - atomic_inc(&pci_parity_count);
41520 + atomic_inc_unchecked(&pci_parity_count);
41521 }
41522
41523 if (status & (PCI_STATUS_DETECTED_PARITY)) {
41524 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41525 "Detected Parity Error on %s\n",
41526 pci_name(dev));
41527
41528 - atomic_inc(&pci_parity_count);
41529 + atomic_inc_unchecked(&pci_parity_count);
41530 }
41531 }
41532
41533 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41534 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
41535 "Signaled System Error on %s\n",
41536 pci_name(dev));
41537 - atomic_inc(&pci_nonparity_count);
41538 + atomic_inc_unchecked(&pci_nonparity_count);
41539 }
41540
41541 if (status & (PCI_STATUS_PARITY)) {
41542 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41543 "Master Data Parity Error on "
41544 "%s\n", pci_name(dev));
41545
41546 - atomic_inc(&pci_parity_count);
41547 + atomic_inc_unchecked(&pci_parity_count);
41548 }
41549
41550 if (status & (PCI_STATUS_DETECTED_PARITY)) {
41551 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41552 "Detected Parity Error on %s\n",
41553 pci_name(dev));
41554
41555 - atomic_inc(&pci_parity_count);
41556 + atomic_inc_unchecked(&pci_parity_count);
41557 }
41558 }
41559 }
41560 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
41561 if (!check_pci_errors)
41562 return;
41563
41564 - before_count = atomic_read(&pci_parity_count);
41565 + before_count = atomic_read_unchecked(&pci_parity_count);
41566
41567 /* scan all PCI devices looking for a Parity Error on devices and
41568 * bridges.
41569 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
41570 /* Only if operator has selected panic on PCI Error */
41571 if (edac_pci_get_panic_on_pe()) {
41572 /* If the count is different 'after' from 'before' */
41573 - if (before_count != atomic_read(&pci_parity_count))
41574 + if (before_count != atomic_read_unchecked(&pci_parity_count))
41575 panic("EDAC: PCI Parity Error");
41576 }
41577 }
41578 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
41579 index 51b7e3a..aa8a3e8 100644
41580 --- a/drivers/edac/mce_amd.h
41581 +++ b/drivers/edac/mce_amd.h
41582 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
41583 bool (*mc0_mce)(u16, u8);
41584 bool (*mc1_mce)(u16, u8);
41585 bool (*mc2_mce)(u16, u8);
41586 -};
41587 +} __no_const;
41588
41589 void amd_report_gart_errors(bool);
41590 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
41591 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
41592 index 57ea7f4..af06b76 100644
41593 --- a/drivers/firewire/core-card.c
41594 +++ b/drivers/firewire/core-card.c
41595 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
41596 const struct fw_card_driver *driver,
41597 struct device *device)
41598 {
41599 - static atomic_t index = ATOMIC_INIT(-1);
41600 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
41601
41602 - card->index = atomic_inc_return(&index);
41603 + card->index = atomic_inc_return_unchecked(&index);
41604 card->driver = driver;
41605 card->device = device;
41606 card->current_tlabel = 0;
41607 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
41608
41609 void fw_core_remove_card(struct fw_card *card)
41610 {
41611 - struct fw_card_driver dummy_driver = dummy_driver_template;
41612 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
41613
41614 card->driver->update_phy_reg(card, 4,
41615 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
41616 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
41617 index 2c6d5e1..a2cca6b 100644
41618 --- a/drivers/firewire/core-device.c
41619 +++ b/drivers/firewire/core-device.c
41620 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
41621 struct config_rom_attribute {
41622 struct device_attribute attr;
41623 u32 key;
41624 -};
41625 +} __do_const;
41626
41627 static ssize_t show_immediate(struct device *dev,
41628 struct device_attribute *dattr, char *buf)
41629 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
41630 index eb6935c..3cc2bfa 100644
41631 --- a/drivers/firewire/core-transaction.c
41632 +++ b/drivers/firewire/core-transaction.c
41633 @@ -38,6 +38,7 @@
41634 #include <linux/timer.h>
41635 #include <linux/types.h>
41636 #include <linux/workqueue.h>
41637 +#include <linux/sched.h>
41638
41639 #include <asm/byteorder.h>
41640
41641 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
41642 index e1480ff6..1a429bd 100644
41643 --- a/drivers/firewire/core.h
41644 +++ b/drivers/firewire/core.h
41645 @@ -111,6 +111,7 @@ struct fw_card_driver {
41646
41647 int (*stop_iso)(struct fw_iso_context *ctx);
41648 };
41649 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
41650
41651 void fw_card_initialize(struct fw_card *card,
41652 const struct fw_card_driver *driver, struct device *device);
41653 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
41654 index a66a321..f6caf20 100644
41655 --- a/drivers/firewire/ohci.c
41656 +++ b/drivers/firewire/ohci.c
41657 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
41658 be32_to_cpu(ohci->next_header));
41659 }
41660
41661 +#ifndef CONFIG_GRKERNSEC
41662 if (param_remote_dma) {
41663 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
41664 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
41665 }
41666 +#endif
41667
41668 spin_unlock_irq(&ohci->lock);
41669
41670 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
41671 unsigned long flags;
41672 int n, ret = 0;
41673
41674 +#ifndef CONFIG_GRKERNSEC
41675 if (param_remote_dma)
41676 return 0;
41677 +#endif
41678
41679 /*
41680 * FIXME: Make sure this bitmask is cleared when we clear the busReset
41681 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
41682 index 94a58a0..f5eba42 100644
41683 --- a/drivers/firmware/dmi-id.c
41684 +++ b/drivers/firmware/dmi-id.c
41685 @@ -16,7 +16,7 @@
41686 struct dmi_device_attribute{
41687 struct device_attribute dev_attr;
41688 int field;
41689 -};
41690 +} __do_const;
41691 #define to_dmi_dev_attr(_dev_attr) \
41692 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
41693
41694 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
41695 index 17afc51..0ef90cd 100644
41696 --- a/drivers/firmware/dmi_scan.c
41697 +++ b/drivers/firmware/dmi_scan.c
41698 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
41699 if (buf == NULL)
41700 return -1;
41701
41702 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
41703 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
41704
41705 dmi_unmap(buf);
41706 return 0;
41707 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
41708 index 1491dd4..aa910db 100644
41709 --- a/drivers/firmware/efi/cper.c
41710 +++ b/drivers/firmware/efi/cper.c
41711 @@ -41,12 +41,12 @@
41712 */
41713 u64 cper_next_record_id(void)
41714 {
41715 - static atomic64_t seq;
41716 + static atomic64_unchecked_t seq;
41717
41718 - if (!atomic64_read(&seq))
41719 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
41720 + if (!atomic64_read_unchecked(&seq))
41721 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
41722
41723 - return atomic64_inc_return(&seq);
41724 + return atomic64_inc_return_unchecked(&seq);
41725 }
41726 EXPORT_SYMBOL_GPL(cper_next_record_id);
41727
41728 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
41729 index dc79346..b39bd69 100644
41730 --- a/drivers/firmware/efi/efi.c
41731 +++ b/drivers/firmware/efi/efi.c
41732 @@ -122,14 +122,16 @@ static struct attribute_group efi_subsys_attr_group = {
41733 };
41734
41735 static struct efivars generic_efivars;
41736 -static struct efivar_operations generic_ops;
41737 +static efivar_operations_no_const generic_ops __read_only;
41738
41739 static int generic_ops_register(void)
41740 {
41741 - generic_ops.get_variable = efi.get_variable;
41742 - generic_ops.set_variable = efi.set_variable;
41743 - generic_ops.get_next_variable = efi.get_next_variable;
41744 - generic_ops.query_variable_store = efi_query_variable_store;
41745 + pax_open_kernel();
41746 + *(void **)&generic_ops.get_variable = efi.get_variable;
41747 + *(void **)&generic_ops.set_variable = efi.set_variable;
41748 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
41749 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
41750 + pax_close_kernel();
41751
41752 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
41753 }
41754 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
41755 index 463c565..02a5640 100644
41756 --- a/drivers/firmware/efi/efivars.c
41757 +++ b/drivers/firmware/efi/efivars.c
41758 @@ -588,7 +588,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
41759 static int
41760 create_efivars_bin_attributes(void)
41761 {
41762 - struct bin_attribute *attr;
41763 + bin_attribute_no_const *attr;
41764 int error;
41765
41766 /* new_var */
41767 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
41768 index 2f569aa..c95f4fb 100644
41769 --- a/drivers/firmware/google/memconsole.c
41770 +++ b/drivers/firmware/google/memconsole.c
41771 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
41772 if (!found_memconsole())
41773 return -ENODEV;
41774
41775 - memconsole_bin_attr.size = memconsole_length;
41776 + pax_open_kernel();
41777 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
41778 + pax_close_kernel();
41779 +
41780 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
41781 }
41782
41783 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
41784 index cde3605..8b69df7 100644
41785 --- a/drivers/gpio/gpio-em.c
41786 +++ b/drivers/gpio/gpio-em.c
41787 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
41788 struct em_gio_priv *p;
41789 struct resource *io[2], *irq[2];
41790 struct gpio_chip *gpio_chip;
41791 - struct irq_chip *irq_chip;
41792 + irq_chip_no_const *irq_chip;
41793 const char *name = dev_name(&pdev->dev);
41794 int ret;
41795
41796 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
41797 index 7030422..42a3fe9 100644
41798 --- a/drivers/gpio/gpio-ich.c
41799 +++ b/drivers/gpio/gpio-ich.c
41800 @@ -94,7 +94,7 @@ struct ichx_desc {
41801 * this option allows driver caching written output values
41802 */
41803 bool use_outlvl_cache;
41804 -};
41805 +} __do_const;
41806
41807 static struct {
41808 spinlock_t lock;
41809 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
41810 index b6ae89e..ac7349c 100644
41811 --- a/drivers/gpio/gpio-rcar.c
41812 +++ b/drivers/gpio/gpio-rcar.c
41813 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
41814 struct gpio_rcar_priv *p;
41815 struct resource *io, *irq;
41816 struct gpio_chip *gpio_chip;
41817 - struct irq_chip *irq_chip;
41818 + irq_chip_no_const *irq_chip;
41819 struct device *dev = &pdev->dev;
41820 const char *name = dev_name(dev);
41821 int ret;
41822 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
41823 index 66cbcc1..0c5e622 100644
41824 --- a/drivers/gpio/gpio-vr41xx.c
41825 +++ b/drivers/gpio/gpio-vr41xx.c
41826 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
41827 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
41828 maskl, pendl, maskh, pendh);
41829
41830 - atomic_inc(&irq_err_count);
41831 + atomic_inc_unchecked(&irq_err_count);
41832
41833 return -EINVAL;
41834 }
41835 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
41836 index 2ebc907..01bdd6e 100644
41837 --- a/drivers/gpio/gpiolib.c
41838 +++ b/drivers/gpio/gpiolib.c
41839 @@ -1482,8 +1482,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
41840 }
41841
41842 if (gpiochip->irqchip) {
41843 - gpiochip->irqchip->irq_request_resources = NULL;
41844 - gpiochip->irqchip->irq_release_resources = NULL;
41845 + pax_open_kernel();
41846 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
41847 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
41848 + pax_close_kernel();
41849 gpiochip->irqchip = NULL;
41850 }
41851 }
41852 @@ -1549,8 +1551,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
41853 gpiochip->irqchip = NULL;
41854 return -EINVAL;
41855 }
41856 - irqchip->irq_request_resources = gpiochip_irq_reqres;
41857 - irqchip->irq_release_resources = gpiochip_irq_relres;
41858 +
41859 + pax_open_kernel();
41860 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
41861 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
41862 + pax_close_kernel();
41863
41864 /*
41865 * Prepare the mapping since the irqchip shall be orthogonal to
41866 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
41867 index fe94cc1..5e697b3 100644
41868 --- a/drivers/gpu/drm/drm_crtc.c
41869 +++ b/drivers/gpu/drm/drm_crtc.c
41870 @@ -3584,7 +3584,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
41871 goto done;
41872 }
41873
41874 - if (copy_to_user(&enum_ptr[copied].name,
41875 + if (copy_to_user(enum_ptr[copied].name,
41876 &prop_enum->name, DRM_PROP_NAME_LEN)) {
41877 ret = -EFAULT;
41878 goto done;
41879 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
41880 index 8218078..9960928a 100644
41881 --- a/drivers/gpu/drm/drm_drv.c
41882 +++ b/drivers/gpu/drm/drm_drv.c
41883 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
41884 /**
41885 * Copy and IOCTL return string to user space
41886 */
41887 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
41888 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
41889 {
41890 int len;
41891
41892 @@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
41893 struct drm_file *file_priv = filp->private_data;
41894 struct drm_device *dev;
41895 const struct drm_ioctl_desc *ioctl = NULL;
41896 - drm_ioctl_t *func;
41897 + drm_ioctl_no_const_t func;
41898 unsigned int nr = DRM_IOCTL_NR(cmd);
41899 int retcode = -EINVAL;
41900 char stack_kdata[128];
41901 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
41902 index 021fe5d..abc9ce6 100644
41903 --- a/drivers/gpu/drm/drm_fops.c
41904 +++ b/drivers/gpu/drm/drm_fops.c
41905 @@ -88,7 +88,7 @@ int drm_open(struct inode *inode, struct file *filp)
41906 return PTR_ERR(minor);
41907
41908 dev = minor->dev;
41909 - if (!dev->open_count++)
41910 + if (local_inc_return(&dev->open_count) == 1)
41911 need_setup = 1;
41912
41913 /* share address_space across all char-devs of a single device */
41914 @@ -105,7 +105,7 @@ int drm_open(struct inode *inode, struct file *filp)
41915 return 0;
41916
41917 err_undo:
41918 - dev->open_count--;
41919 + local_dec(&dev->open_count);
41920 drm_minor_release(minor);
41921 return retcode;
41922 }
41923 @@ -427,7 +427,7 @@ int drm_release(struct inode *inode, struct file *filp)
41924
41925 mutex_lock(&drm_global_mutex);
41926
41927 - DRM_DEBUG("open_count = %d\n", dev->open_count);
41928 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
41929
41930 if (dev->driver->preclose)
41931 dev->driver->preclose(dev, file_priv);
41932 @@ -436,10 +436,10 @@ int drm_release(struct inode *inode, struct file *filp)
41933 * Begin inline drm_release
41934 */
41935
41936 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
41937 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
41938 task_pid_nr(current),
41939 (long)old_encode_dev(file_priv->minor->kdev->devt),
41940 - dev->open_count);
41941 + local_read(&dev->open_count));
41942
41943 /* Release any auth tokens that might point to this file_priv,
41944 (do that under the drm_global_mutex) */
41945 @@ -540,7 +540,7 @@ int drm_release(struct inode *inode, struct file *filp)
41946 * End inline drm_release
41947 */
41948
41949 - if (!--dev->open_count) {
41950 + if (local_dec_and_test(&dev->open_count)) {
41951 retcode = drm_lastclose(dev);
41952 if (drm_device_is_unplugged(dev))
41953 drm_put_dev(dev);
41954 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
41955 index 3d2e91c..d31c4c9 100644
41956 --- a/drivers/gpu/drm/drm_global.c
41957 +++ b/drivers/gpu/drm/drm_global.c
41958 @@ -36,7 +36,7 @@
41959 struct drm_global_item {
41960 struct mutex mutex;
41961 void *object;
41962 - int refcount;
41963 + atomic_t refcount;
41964 };
41965
41966 static struct drm_global_item glob[DRM_GLOBAL_NUM];
41967 @@ -49,7 +49,7 @@ void drm_global_init(void)
41968 struct drm_global_item *item = &glob[i];
41969 mutex_init(&item->mutex);
41970 item->object = NULL;
41971 - item->refcount = 0;
41972 + atomic_set(&item->refcount, 0);
41973 }
41974 }
41975
41976 @@ -59,7 +59,7 @@ void drm_global_release(void)
41977 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
41978 struct drm_global_item *item = &glob[i];
41979 BUG_ON(item->object != NULL);
41980 - BUG_ON(item->refcount != 0);
41981 + BUG_ON(atomic_read(&item->refcount) != 0);
41982 }
41983 }
41984
41985 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41986 struct drm_global_item *item = &glob[ref->global_type];
41987
41988 mutex_lock(&item->mutex);
41989 - if (item->refcount == 0) {
41990 + if (atomic_read(&item->refcount) == 0) {
41991 item->object = kzalloc(ref->size, GFP_KERNEL);
41992 if (unlikely(item->object == NULL)) {
41993 ret = -ENOMEM;
41994 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41995 goto out_err;
41996
41997 }
41998 - ++item->refcount;
41999 + atomic_inc(&item->refcount);
42000 ref->object = item->object;
42001 mutex_unlock(&item->mutex);
42002 return 0;
42003 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
42004 struct drm_global_item *item = &glob[ref->global_type];
42005
42006 mutex_lock(&item->mutex);
42007 - BUG_ON(item->refcount == 0);
42008 + BUG_ON(atomic_read(&item->refcount) == 0);
42009 BUG_ON(ref->object != item->object);
42010 - if (--item->refcount == 0) {
42011 + if (atomic_dec_and_test(&item->refcount)) {
42012 ref->release(ref);
42013 item->object = NULL;
42014 }
42015 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
42016 index 86feedd..cba70f5 100644
42017 --- a/drivers/gpu/drm/drm_info.c
42018 +++ b/drivers/gpu/drm/drm_info.c
42019 @@ -73,10 +73,13 @@ int drm_vm_info(struct seq_file *m, void *data)
42020 struct drm_local_map *map;
42021 struct drm_map_list *r_list;
42022
42023 - /* Hardcoded from _DRM_FRAME_BUFFER,
42024 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
42025 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
42026 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
42027 + static const char * const types[] = {
42028 + [_DRM_FRAME_BUFFER] = "FB",
42029 + [_DRM_REGISTERS] = "REG",
42030 + [_DRM_SHM] = "SHM",
42031 + [_DRM_AGP] = "AGP",
42032 + [_DRM_SCATTER_GATHER] = "SG",
42033 + [_DRM_CONSISTENT] = "PCI"};
42034 const char *type;
42035 int i;
42036
42037 @@ -87,7 +90,7 @@ int drm_vm_info(struct seq_file *m, void *data)
42038 map = r_list->map;
42039 if (!map)
42040 continue;
42041 - if (map->type < 0 || map->type > 5)
42042 + if (map->type >= ARRAY_SIZE(types))
42043 type = "??";
42044 else
42045 type = types[map->type];
42046 @@ -259,7 +262,11 @@ int drm_vma_info(struct seq_file *m, void *data)
42047 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
42048 vma->vm_flags & VM_LOCKED ? 'l' : '-',
42049 vma->vm_flags & VM_IO ? 'i' : '-',
42050 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42051 + 0);
42052 +#else
42053 vma->vm_pgoff);
42054 +#endif
42055
42056 #if defined(__i386__)
42057 pgprot = pgprot_val(vma->vm_page_prot);
42058 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
42059 index 2f4c4343..dd12cd2 100644
42060 --- a/drivers/gpu/drm/drm_ioc32.c
42061 +++ b/drivers/gpu/drm/drm_ioc32.c
42062 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
42063 request = compat_alloc_user_space(nbytes);
42064 if (!access_ok(VERIFY_WRITE, request, nbytes))
42065 return -EFAULT;
42066 - list = (struct drm_buf_desc *) (request + 1);
42067 + list = (struct drm_buf_desc __user *) (request + 1);
42068
42069 if (__put_user(count, &request->count)
42070 || __put_user(list, &request->list))
42071 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
42072 request = compat_alloc_user_space(nbytes);
42073 if (!access_ok(VERIFY_WRITE, request, nbytes))
42074 return -EFAULT;
42075 - list = (struct drm_buf_pub *) (request + 1);
42076 + list = (struct drm_buf_pub __user *) (request + 1);
42077
42078 if (__put_user(count, &request->count)
42079 || __put_user(list, &request->list))
42080 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
42081 return 0;
42082 }
42083
42084 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
42085 +drm_ioctl_compat_t drm_compat_ioctls[] = {
42086 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
42087 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
42088 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
42089 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
42090 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42091 {
42092 unsigned int nr = DRM_IOCTL_NR(cmd);
42093 - drm_ioctl_compat_t *fn;
42094 int ret;
42095
42096 /* Assume that ioctls without an explicit compat routine will just
42097 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42098 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
42099 return drm_ioctl(filp, cmd, arg);
42100
42101 - fn = drm_compat_ioctls[nr];
42102 -
42103 - if (fn != NULL)
42104 - ret = (*fn) (filp, cmd, arg);
42105 + if (drm_compat_ioctls[nr] != NULL)
42106 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
42107 else
42108 ret = drm_ioctl(filp, cmd, arg);
42109
42110 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
42111 index 14d1646..99f9d49 100644
42112 --- a/drivers/gpu/drm/drm_stub.c
42113 +++ b/drivers/gpu/drm/drm_stub.c
42114 @@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
42115
42116 drm_device_set_unplugged(dev);
42117
42118 - if (dev->open_count == 0) {
42119 + if (local_read(&dev->open_count) == 0) {
42120 drm_put_dev(dev);
42121 }
42122 mutex_unlock(&drm_global_mutex);
42123 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
42124 index 369b262..09ea3ab 100644
42125 --- a/drivers/gpu/drm/drm_sysfs.c
42126 +++ b/drivers/gpu/drm/drm_sysfs.c
42127 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
42128 */
42129 int drm_sysfs_device_add(struct drm_minor *minor)
42130 {
42131 - char *minor_str;
42132 + const char *minor_str;
42133 int r;
42134
42135 if (minor->type == DRM_MINOR_CONTROL)
42136 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
42137 index d4d16ed..8fb0b51 100644
42138 --- a/drivers/gpu/drm/i810/i810_drv.h
42139 +++ b/drivers/gpu/drm/i810/i810_drv.h
42140 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
42141 int page_flipping;
42142
42143 wait_queue_head_t irq_queue;
42144 - atomic_t irq_received;
42145 - atomic_t irq_emitted;
42146 + atomic_unchecked_t irq_received;
42147 + atomic_unchecked_t irq_emitted;
42148
42149 int front_offset;
42150 } drm_i810_private_t;
42151 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
42152 index d443441..ab091dd 100644
42153 --- a/drivers/gpu/drm/i915/i915_dma.c
42154 +++ b/drivers/gpu/drm/i915/i915_dma.c
42155 @@ -1290,7 +1290,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
42156 * locking inversion with the driver load path. And the access here is
42157 * completely racy anyway. So don't bother with locking for now.
42158 */
42159 - return dev->open_count == 0;
42160 + return local_read(&dev->open_count) == 0;
42161 }
42162
42163 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
42164 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
42165 index 3a30133..ef4a743 100644
42166 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
42167 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
42168 @@ -891,9 +891,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
42169
42170 static int
42171 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
42172 - int count)
42173 + unsigned int count)
42174 {
42175 - int i;
42176 + unsigned int i;
42177 unsigned relocs_total = 0;
42178 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
42179
42180 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
42181 index 2e0613e..a8b94d9 100644
42182 --- a/drivers/gpu/drm/i915/i915_ioc32.c
42183 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
42184 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
42185 (unsigned long)request);
42186 }
42187
42188 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
42189 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
42190 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
42191 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
42192 [DRM_I915_GETPARAM] = compat_i915_getparam,
42193 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
42194 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42195 {
42196 unsigned int nr = DRM_IOCTL_NR(cmd);
42197 - drm_ioctl_compat_t *fn = NULL;
42198 int ret;
42199
42200 if (nr < DRM_COMMAND_BASE)
42201 return drm_compat_ioctl(filp, cmd, arg);
42202
42203 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
42204 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
42205 -
42206 - if (fn != NULL)
42207 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
42208 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
42209 ret = (*fn) (filp, cmd, arg);
42210 - else
42211 + } else
42212 ret = drm_ioctl(filp, cmd, arg);
42213
42214 return ret;
42215 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
42216 index f0be855..94e82d9 100644
42217 --- a/drivers/gpu/drm/i915/intel_display.c
42218 +++ b/drivers/gpu/drm/i915/intel_display.c
42219 @@ -11604,13 +11604,13 @@ struct intel_quirk {
42220 int subsystem_vendor;
42221 int subsystem_device;
42222 void (*hook)(struct drm_device *dev);
42223 -};
42224 +} __do_const;
42225
42226 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
42227 struct intel_dmi_quirk {
42228 void (*hook)(struct drm_device *dev);
42229 const struct dmi_system_id (*dmi_id_list)[];
42230 -};
42231 +} __do_const;
42232
42233 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
42234 {
42235 @@ -11618,18 +11618,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
42236 return 1;
42237 }
42238
42239 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
42240 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
42241 {
42242 - .dmi_id_list = &(const struct dmi_system_id[]) {
42243 - {
42244 - .callback = intel_dmi_reverse_brightness,
42245 - .ident = "NCR Corporation",
42246 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
42247 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
42248 - },
42249 - },
42250 - { } /* terminating entry */
42251 + .callback = intel_dmi_reverse_brightness,
42252 + .ident = "NCR Corporation",
42253 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
42254 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
42255 },
42256 + },
42257 + { } /* terminating entry */
42258 +};
42259 +
42260 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
42261 + {
42262 + .dmi_id_list = &intel_dmi_quirks_table,
42263 .hook = quirk_invert_brightness,
42264 },
42265 };
42266 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
42267 index fe45321..836fdca 100644
42268 --- a/drivers/gpu/drm/mga/mga_drv.h
42269 +++ b/drivers/gpu/drm/mga/mga_drv.h
42270 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
42271 u32 clear_cmd;
42272 u32 maccess;
42273
42274 - atomic_t vbl_received; /**< Number of vblanks received. */
42275 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
42276 wait_queue_head_t fence_queue;
42277 - atomic_t last_fence_retired;
42278 + atomic_unchecked_t last_fence_retired;
42279 u32 next_fence_to_post;
42280
42281 unsigned int fb_cpp;
42282 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
42283 index 729bfd5..ead8823 100644
42284 --- a/drivers/gpu/drm/mga/mga_ioc32.c
42285 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
42286 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
42287 return 0;
42288 }
42289
42290 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
42291 +drm_ioctl_compat_t mga_compat_ioctls[] = {
42292 [DRM_MGA_INIT] = compat_mga_init,
42293 [DRM_MGA_GETPARAM] = compat_mga_getparam,
42294 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
42295 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
42296 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42297 {
42298 unsigned int nr = DRM_IOCTL_NR(cmd);
42299 - drm_ioctl_compat_t *fn = NULL;
42300 int ret;
42301
42302 if (nr < DRM_COMMAND_BASE)
42303 return drm_compat_ioctl(filp, cmd, arg);
42304
42305 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
42306 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
42307 -
42308 - if (fn != NULL)
42309 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
42310 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
42311 ret = (*fn) (filp, cmd, arg);
42312 - else
42313 + } else
42314 ret = drm_ioctl(filp, cmd, arg);
42315
42316 return ret;
42317 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
42318 index 1b071b8..de8601a 100644
42319 --- a/drivers/gpu/drm/mga/mga_irq.c
42320 +++ b/drivers/gpu/drm/mga/mga_irq.c
42321 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
42322 if (crtc != 0)
42323 return 0;
42324
42325 - return atomic_read(&dev_priv->vbl_received);
42326 + return atomic_read_unchecked(&dev_priv->vbl_received);
42327 }
42328
42329
42330 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
42331 /* VBLANK interrupt */
42332 if (status & MGA_VLINEPEN) {
42333 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
42334 - atomic_inc(&dev_priv->vbl_received);
42335 + atomic_inc_unchecked(&dev_priv->vbl_received);
42336 drm_handle_vblank(dev, 0);
42337 handled = 1;
42338 }
42339 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
42340 if ((prim_start & ~0x03) != (prim_end & ~0x03))
42341 MGA_WRITE(MGA_PRIMEND, prim_end);
42342
42343 - atomic_inc(&dev_priv->last_fence_retired);
42344 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
42345 wake_up(&dev_priv->fence_queue);
42346 handled = 1;
42347 }
42348 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
42349 * using fences.
42350 */
42351 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
42352 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
42353 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
42354 - *sequence) <= (1 << 23)));
42355
42356 *sequence = cur_fence;
42357 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
42358 index 8268a4c..5105708 100644
42359 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
42360 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
42361 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
42362 struct bit_table {
42363 const char id;
42364 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
42365 -};
42366 +} __no_const;
42367
42368 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
42369
42370 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
42371 index 7efbafa..19f8087 100644
42372 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
42373 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
42374 @@ -97,7 +97,6 @@ struct nouveau_drm {
42375 struct drm_global_reference mem_global_ref;
42376 struct ttm_bo_global_ref bo_global_ref;
42377 struct ttm_bo_device bdev;
42378 - atomic_t validate_sequence;
42379 int (*move)(struct nouveau_channel *,
42380 struct ttm_buffer_object *,
42381 struct ttm_mem_reg *, struct ttm_mem_reg *);
42382 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
42383 index 462679a..88e32a7 100644
42384 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
42385 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
42386 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
42387 unsigned long arg)
42388 {
42389 unsigned int nr = DRM_IOCTL_NR(cmd);
42390 - drm_ioctl_compat_t *fn = NULL;
42391 + drm_ioctl_compat_t fn = NULL;
42392 int ret;
42393
42394 if (nr < DRM_COMMAND_BASE)
42395 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
42396 index ab0228f..20b756b 100644
42397 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
42398 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
42399 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
42400 }
42401
42402 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
42403 - nouveau_vram_manager_init,
42404 - nouveau_vram_manager_fini,
42405 - nouveau_vram_manager_new,
42406 - nouveau_vram_manager_del,
42407 - nouveau_vram_manager_debug
42408 + .init = nouveau_vram_manager_init,
42409 + .takedown = nouveau_vram_manager_fini,
42410 + .get_node = nouveau_vram_manager_new,
42411 + .put_node = nouveau_vram_manager_del,
42412 + .debug = nouveau_vram_manager_debug
42413 };
42414
42415 static int
42416 @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
42417 }
42418
42419 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
42420 - nouveau_gart_manager_init,
42421 - nouveau_gart_manager_fini,
42422 - nouveau_gart_manager_new,
42423 - nouveau_gart_manager_del,
42424 - nouveau_gart_manager_debug
42425 + .init = nouveau_gart_manager_init,
42426 + .takedown = nouveau_gart_manager_fini,
42427 + .get_node = nouveau_gart_manager_new,
42428 + .put_node = nouveau_gart_manager_del,
42429 + .debug = nouveau_gart_manager_debug
42430 };
42431
42432 #include <core/subdev/vm/nv04.h>
42433 @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
42434 }
42435
42436 const struct ttm_mem_type_manager_func nv04_gart_manager = {
42437 - nv04_gart_manager_init,
42438 - nv04_gart_manager_fini,
42439 - nv04_gart_manager_new,
42440 - nv04_gart_manager_del,
42441 - nv04_gart_manager_debug
42442 + .init = nv04_gart_manager_init,
42443 + .takedown = nv04_gart_manager_fini,
42444 + .get_node = nv04_gart_manager_new,
42445 + .put_node = nv04_gart_manager_del,
42446 + .debug = nv04_gart_manager_debug
42447 };
42448
42449 int
42450 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
42451 index 4f4c3fe..2cce716 100644
42452 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
42453 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
42454 @@ -70,7 +70,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
42455 * locking inversion with the driver load path. And the access here is
42456 * completely racy anyway. So don't bother with locking for now.
42457 */
42458 - return dev->open_count == 0;
42459 + return local_read(&dev->open_count) == 0;
42460 }
42461
42462 static const struct vga_switcheroo_client_ops
42463 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
42464 index eb89653..613cf71 100644
42465 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
42466 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
42467 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
42468 int ret;
42469
42470 mutex_lock(&qdev->async_io_mutex);
42471 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
42472 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
42473 if (qdev->last_sent_io_cmd > irq_num) {
42474 if (intr)
42475 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
42476 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42477 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42478 else
42479 ret = wait_event_timeout(qdev->io_cmd_event,
42480 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42481 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42482 /* 0 is timeout, just bail the "hw" has gone away */
42483 if (ret <= 0)
42484 goto out;
42485 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
42486 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
42487 }
42488 outb(val, addr);
42489 qdev->last_sent_io_cmd = irq_num + 1;
42490 if (intr)
42491 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
42492 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42493 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42494 else
42495 ret = wait_event_timeout(qdev->io_cmd_event,
42496 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42497 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42498 out:
42499 if (ret > 0)
42500 ret = 0;
42501 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
42502 index c3c2bbd..bc3c0fb 100644
42503 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
42504 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
42505 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
42506 struct drm_info_node *node = (struct drm_info_node *) m->private;
42507 struct qxl_device *qdev = node->minor->dev->dev_private;
42508
42509 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
42510 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
42511 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
42512 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
42513 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
42514 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
42515 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
42516 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
42517 seq_printf(m, "%d\n", qdev->irq_received_error);
42518 return 0;
42519 }
42520 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
42521 index 36ed40b..0397633 100644
42522 --- a/drivers/gpu/drm/qxl/qxl_drv.h
42523 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
42524 @@ -290,10 +290,10 @@ struct qxl_device {
42525 unsigned int last_sent_io_cmd;
42526
42527 /* interrupt handling */
42528 - atomic_t irq_received;
42529 - atomic_t irq_received_display;
42530 - atomic_t irq_received_cursor;
42531 - atomic_t irq_received_io_cmd;
42532 + atomic_unchecked_t irq_received;
42533 + atomic_unchecked_t irq_received_display;
42534 + atomic_unchecked_t irq_received_cursor;
42535 + atomic_unchecked_t irq_received_io_cmd;
42536 unsigned irq_received_error;
42537 wait_queue_head_t display_event;
42538 wait_queue_head_t cursor_event;
42539 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
42540 index b110883..dd06418 100644
42541 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
42542 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
42543 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
42544
42545 /* TODO copy slow path code from i915 */
42546 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
42547 - unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void *)(unsigned long)cmd->command, cmd->command_size);
42548 + unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void __force_user *)(unsigned long)cmd->command, cmd->command_size);
42549
42550 {
42551 struct qxl_drawable *draw = fb_cmd;
42552 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
42553 struct drm_qxl_reloc reloc;
42554
42555 if (copy_from_user(&reloc,
42556 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
42557 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
42558 sizeof(reloc))) {
42559 ret = -EFAULT;
42560 goto out_free_bos;
42561 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
42562
42563 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
42564
42565 - struct drm_qxl_command *commands =
42566 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
42567 + struct drm_qxl_command __user *commands =
42568 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
42569
42570 - if (copy_from_user(&user_cmd, &commands[cmd_num],
42571 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
42572 sizeof(user_cmd)))
42573 return -EFAULT;
42574
42575 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
42576 index 0bf1e20..42a7310 100644
42577 --- a/drivers/gpu/drm/qxl/qxl_irq.c
42578 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
42579 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
42580 if (!pending)
42581 return IRQ_NONE;
42582
42583 - atomic_inc(&qdev->irq_received);
42584 + atomic_inc_unchecked(&qdev->irq_received);
42585
42586 if (pending & QXL_INTERRUPT_DISPLAY) {
42587 - atomic_inc(&qdev->irq_received_display);
42588 + atomic_inc_unchecked(&qdev->irq_received_display);
42589 wake_up_all(&qdev->display_event);
42590 qxl_queue_garbage_collect(qdev, false);
42591 }
42592 if (pending & QXL_INTERRUPT_CURSOR) {
42593 - atomic_inc(&qdev->irq_received_cursor);
42594 + atomic_inc_unchecked(&qdev->irq_received_cursor);
42595 wake_up_all(&qdev->cursor_event);
42596 }
42597 if (pending & QXL_INTERRUPT_IO_CMD) {
42598 - atomic_inc(&qdev->irq_received_io_cmd);
42599 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
42600 wake_up_all(&qdev->io_cmd_event);
42601 }
42602 if (pending & QXL_INTERRUPT_ERROR) {
42603 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
42604 init_waitqueue_head(&qdev->io_cmd_event);
42605 INIT_WORK(&qdev->client_monitors_config_work,
42606 qxl_client_monitors_config_work_func);
42607 - atomic_set(&qdev->irq_received, 0);
42608 - atomic_set(&qdev->irq_received_display, 0);
42609 - atomic_set(&qdev->irq_received_cursor, 0);
42610 - atomic_set(&qdev->irq_received_io_cmd, 0);
42611 + atomic_set_unchecked(&qdev->irq_received, 0);
42612 + atomic_set_unchecked(&qdev->irq_received_display, 0);
42613 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
42614 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
42615 qdev->irq_received_error = 0;
42616 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
42617 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
42618 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
42619 index 71a1bae..cb1f103 100644
42620 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
42621 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
42622 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
42623 }
42624 }
42625
42626 -static struct vm_operations_struct qxl_ttm_vm_ops;
42627 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
42628 static const struct vm_operations_struct *ttm_vm_ops;
42629
42630 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42631 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
42632 return r;
42633 if (unlikely(ttm_vm_ops == NULL)) {
42634 ttm_vm_ops = vma->vm_ops;
42635 + pax_open_kernel();
42636 qxl_ttm_vm_ops = *ttm_vm_ops;
42637 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
42638 + pax_close_kernel();
42639 }
42640 vma->vm_ops = &qxl_ttm_vm_ops;
42641 return 0;
42642 @@ -555,25 +557,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
42643 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
42644 {
42645 #if defined(CONFIG_DEBUG_FS)
42646 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
42647 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
42648 - unsigned i;
42649 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
42650 + {
42651 + .name = "qxl_mem_mm",
42652 + .show = &qxl_mm_dump_table,
42653 + },
42654 + {
42655 + .name = "qxl_surf_mm",
42656 + .show = &qxl_mm_dump_table,
42657 + }
42658 + };
42659
42660 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
42661 - if (i == 0)
42662 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
42663 - else
42664 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
42665 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
42666 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
42667 - qxl_mem_types_list[i].driver_features = 0;
42668 - if (i == 0)
42669 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
42670 - else
42671 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
42672 + pax_open_kernel();
42673 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
42674 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
42675 + pax_close_kernel();
42676
42677 - }
42678 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
42679 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
42680 #else
42681 return 0;
42682 #endif
42683 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
42684 index 59459fe..be26b31 100644
42685 --- a/drivers/gpu/drm/r128/r128_cce.c
42686 +++ b/drivers/gpu/drm/r128/r128_cce.c
42687 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
42688
42689 /* GH: Simple idle check.
42690 */
42691 - atomic_set(&dev_priv->idle_count, 0);
42692 + atomic_set_unchecked(&dev_priv->idle_count, 0);
42693
42694 /* We don't support anything other than bus-mastering ring mode,
42695 * but the ring can be in either AGP or PCI space for the ring
42696 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
42697 index 5bf3f5f..7000661 100644
42698 --- a/drivers/gpu/drm/r128/r128_drv.h
42699 +++ b/drivers/gpu/drm/r128/r128_drv.h
42700 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
42701 int is_pci;
42702 unsigned long cce_buffers_offset;
42703
42704 - atomic_t idle_count;
42705 + atomic_unchecked_t idle_count;
42706
42707 int page_flipping;
42708 int current_page;
42709 u32 crtc_offset;
42710 u32 crtc_offset_cntl;
42711
42712 - atomic_t vbl_received;
42713 + atomic_unchecked_t vbl_received;
42714
42715 u32 color_fmt;
42716 unsigned int front_offset;
42717 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
42718 index 663f38c..c689495 100644
42719 --- a/drivers/gpu/drm/r128/r128_ioc32.c
42720 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
42721 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
42722 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
42723 }
42724
42725 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
42726 +drm_ioctl_compat_t r128_compat_ioctls[] = {
42727 [DRM_R128_INIT] = compat_r128_init,
42728 [DRM_R128_DEPTH] = compat_r128_depth,
42729 [DRM_R128_STIPPLE] = compat_r128_stipple,
42730 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
42731 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42732 {
42733 unsigned int nr = DRM_IOCTL_NR(cmd);
42734 - drm_ioctl_compat_t *fn = NULL;
42735 int ret;
42736
42737 if (nr < DRM_COMMAND_BASE)
42738 return drm_compat_ioctl(filp, cmd, arg);
42739
42740 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
42741 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
42742 -
42743 - if (fn != NULL)
42744 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
42745 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
42746 ret = (*fn) (filp, cmd, arg);
42747 - else
42748 + } else
42749 ret = drm_ioctl(filp, cmd, arg);
42750
42751 return ret;
42752 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
42753 index c2ae496..30b5993 100644
42754 --- a/drivers/gpu/drm/r128/r128_irq.c
42755 +++ b/drivers/gpu/drm/r128/r128_irq.c
42756 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
42757 if (crtc != 0)
42758 return 0;
42759
42760 - return atomic_read(&dev_priv->vbl_received);
42761 + return atomic_read_unchecked(&dev_priv->vbl_received);
42762 }
42763
42764 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42765 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42766 /* VBLANK interrupt */
42767 if (status & R128_CRTC_VBLANK_INT) {
42768 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
42769 - atomic_inc(&dev_priv->vbl_received);
42770 + atomic_inc_unchecked(&dev_priv->vbl_received);
42771 drm_handle_vblank(dev, 0);
42772 return IRQ_HANDLED;
42773 }
42774 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
42775 index 575e986..66e62ca 100644
42776 --- a/drivers/gpu/drm/r128/r128_state.c
42777 +++ b/drivers/gpu/drm/r128/r128_state.c
42778 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
42779
42780 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
42781 {
42782 - if (atomic_read(&dev_priv->idle_count) == 0)
42783 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
42784 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
42785 else
42786 - atomic_set(&dev_priv->idle_count, 0);
42787 + atomic_set_unchecked(&dev_priv->idle_count, 0);
42788 }
42789
42790 #endif
42791 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
42792 index 4a85bb6..aaea819 100644
42793 --- a/drivers/gpu/drm/radeon/mkregtable.c
42794 +++ b/drivers/gpu/drm/radeon/mkregtable.c
42795 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
42796 regex_t mask_rex;
42797 regmatch_t match[4];
42798 char buf[1024];
42799 - size_t end;
42800 + long end;
42801 int len;
42802 int done = 0;
42803 int r;
42804 unsigned o;
42805 struct offset *offset;
42806 char last_reg_s[10];
42807 - int last_reg;
42808 + unsigned long last_reg;
42809
42810 if (regcomp
42811 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
42812 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
42813 index 697add2..9860f5b 100644
42814 --- a/drivers/gpu/drm/radeon/radeon_device.c
42815 +++ b/drivers/gpu/drm/radeon/radeon_device.c
42816 @@ -1169,7 +1169,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
42817 * locking inversion with the driver load path. And the access here is
42818 * completely racy anyway. So don't bother with locking for now.
42819 */
42820 - return dev->open_count == 0;
42821 + return local_read(&dev->open_count) == 0;
42822 }
42823
42824 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
42825 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
42826 index dafd812..1bf20c7 100644
42827 --- a/drivers/gpu/drm/radeon/radeon_drv.h
42828 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
42829 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
42830
42831 /* SW interrupt */
42832 wait_queue_head_t swi_queue;
42833 - atomic_t swi_emitted;
42834 + atomic_unchecked_t swi_emitted;
42835 int vblank_crtc;
42836 uint32_t irq_enable_reg;
42837 uint32_t r500_disp_irq_reg;
42838 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
42839 index 0b98ea1..0881827 100644
42840 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
42841 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
42842 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42843 request = compat_alloc_user_space(sizeof(*request));
42844 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
42845 || __put_user(req32.param, &request->param)
42846 - || __put_user((void __user *)(unsigned long)req32.value,
42847 + || __put_user((unsigned long)req32.value,
42848 &request->value))
42849 return -EFAULT;
42850
42851 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42852 #define compat_radeon_cp_setparam NULL
42853 #endif /* X86_64 || IA64 */
42854
42855 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42856 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
42857 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
42858 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
42859 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
42860 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42861 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42862 {
42863 unsigned int nr = DRM_IOCTL_NR(cmd);
42864 - drm_ioctl_compat_t *fn = NULL;
42865 int ret;
42866
42867 if (nr < DRM_COMMAND_BASE)
42868 return drm_compat_ioctl(filp, cmd, arg);
42869
42870 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
42871 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42872 -
42873 - if (fn != NULL)
42874 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
42875 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42876 ret = (*fn) (filp, cmd, arg);
42877 - else
42878 + } else
42879 ret = drm_ioctl(filp, cmd, arg);
42880
42881 return ret;
42882 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
42883 index 244b19b..c19226d 100644
42884 --- a/drivers/gpu/drm/radeon/radeon_irq.c
42885 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
42886 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
42887 unsigned int ret;
42888 RING_LOCALS;
42889
42890 - atomic_inc(&dev_priv->swi_emitted);
42891 - ret = atomic_read(&dev_priv->swi_emitted);
42892 + atomic_inc_unchecked(&dev_priv->swi_emitted);
42893 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
42894
42895 BEGIN_RING(4);
42896 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
42897 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
42898 drm_radeon_private_t *dev_priv =
42899 (drm_radeon_private_t *) dev->dev_private;
42900
42901 - atomic_set(&dev_priv->swi_emitted, 0);
42902 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
42903 init_waitqueue_head(&dev_priv->swi_queue);
42904
42905 dev->max_vblank_count = 0x001fffff;
42906 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
42907 index 23bb64f..69d7234 100644
42908 --- a/drivers/gpu/drm/radeon/radeon_state.c
42909 +++ b/drivers/gpu/drm/radeon/radeon_state.c
42910 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
42911 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
42912 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
42913
42914 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
42915 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
42916 sarea_priv->nbox * sizeof(depth_boxes[0])))
42917 return -EFAULT;
42918
42919 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
42920 {
42921 drm_radeon_private_t *dev_priv = dev->dev_private;
42922 drm_radeon_getparam_t *param = data;
42923 - int value;
42924 + int value = 0;
42925
42926 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
42927
42928 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
42929 index c8a8a51..219dacc 100644
42930 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
42931 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
42932 @@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
42933 man->size = size >> PAGE_SHIFT;
42934 }
42935
42936 -static struct vm_operations_struct radeon_ttm_vm_ops;
42937 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
42938 static const struct vm_operations_struct *ttm_vm_ops = NULL;
42939
42940 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42941 @@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
42942 }
42943 if (unlikely(ttm_vm_ops == NULL)) {
42944 ttm_vm_ops = vma->vm_ops;
42945 + pax_open_kernel();
42946 radeon_ttm_vm_ops = *ttm_vm_ops;
42947 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
42948 + pax_close_kernel();
42949 }
42950 vma->vm_ops = &radeon_ttm_vm_ops;
42951 return 0;
42952 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
42953 index ef40381..347463e 100644
42954 --- a/drivers/gpu/drm/tegra/dc.c
42955 +++ b/drivers/gpu/drm/tegra/dc.c
42956 @@ -1173,7 +1173,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
42957 }
42958
42959 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
42960 - dc->debugfs_files[i].data = dc;
42961 + *(void **)&dc->debugfs_files[i].data = dc;
42962
42963 err = drm_debugfs_create_files(dc->debugfs_files,
42964 ARRAY_SIZE(debugfs_files),
42965 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
42966 index bd56f2a..255af4b 100644
42967 --- a/drivers/gpu/drm/tegra/dsi.c
42968 +++ b/drivers/gpu/drm/tegra/dsi.c
42969 @@ -41,7 +41,7 @@ struct tegra_dsi {
42970 struct clk *clk_lp;
42971 struct clk *clk;
42972
42973 - struct drm_info_list *debugfs_files;
42974 + drm_info_list_no_const *debugfs_files;
42975 struct drm_minor *minor;
42976 struct dentry *debugfs;
42977
42978 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
42979 index ba067bb..23afbbd 100644
42980 --- a/drivers/gpu/drm/tegra/hdmi.c
42981 +++ b/drivers/gpu/drm/tegra/hdmi.c
42982 @@ -60,7 +60,7 @@ struct tegra_hdmi {
42983 bool stereo;
42984 bool dvi;
42985
42986 - struct drm_info_list *debugfs_files;
42987 + drm_info_list_no_const *debugfs_files;
42988 struct drm_minor *minor;
42989 struct dentry *debugfs;
42990 };
42991 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42992 index bd850c9..d9f3573 100644
42993 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
42994 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42995 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
42996 }
42997
42998 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
42999 - ttm_bo_man_init,
43000 - ttm_bo_man_takedown,
43001 - ttm_bo_man_get_node,
43002 - ttm_bo_man_put_node,
43003 - ttm_bo_man_debug
43004 + .init = ttm_bo_man_init,
43005 + .takedown = ttm_bo_man_takedown,
43006 + .get_node = ttm_bo_man_get_node,
43007 + .put_node = ttm_bo_man_put_node,
43008 + .debug = ttm_bo_man_debug
43009 };
43010 EXPORT_SYMBOL(ttm_bo_manager_func);
43011 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
43012 index dbc2def..0a9f710 100644
43013 --- a/drivers/gpu/drm/ttm/ttm_memory.c
43014 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
43015 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
43016 zone->glob = glob;
43017 glob->zone_kernel = zone;
43018 ret = kobject_init_and_add(
43019 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
43020 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
43021 if (unlikely(ret != 0)) {
43022 kobject_put(&zone->kobj);
43023 return ret;
43024 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
43025 zone->glob = glob;
43026 glob->zone_dma32 = zone;
43027 ret = kobject_init_and_add(
43028 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
43029 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
43030 if (unlikely(ret != 0)) {
43031 kobject_put(&zone->kobj);
43032 return ret;
43033 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
43034 index 863bef9..cba15cf 100644
43035 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
43036 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
43037 @@ -391,9 +391,9 @@ out:
43038 static unsigned long
43039 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
43040 {
43041 - static atomic_t start_pool = ATOMIC_INIT(0);
43042 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
43043 unsigned i;
43044 - unsigned pool_offset = atomic_add_return(1, &start_pool);
43045 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
43046 struct ttm_page_pool *pool;
43047 int shrink_pages = sc->nr_to_scan;
43048 unsigned long freed = 0;
43049 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
43050 index 3771763..883f206 100644
43051 --- a/drivers/gpu/drm/udl/udl_fb.c
43052 +++ b/drivers/gpu/drm/udl/udl_fb.c
43053 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
43054 fb_deferred_io_cleanup(info);
43055 kfree(info->fbdefio);
43056 info->fbdefio = NULL;
43057 - info->fbops->fb_mmap = udl_fb_mmap;
43058 }
43059
43060 pr_warn("released /dev/fb%d user=%d count=%d\n",
43061 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
43062 index ad02732..144f5ed 100644
43063 --- a/drivers/gpu/drm/via/via_drv.h
43064 +++ b/drivers/gpu/drm/via/via_drv.h
43065 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
43066 typedef uint32_t maskarray_t[5];
43067
43068 typedef struct drm_via_irq {
43069 - atomic_t irq_received;
43070 + atomic_unchecked_t irq_received;
43071 uint32_t pending_mask;
43072 uint32_t enable_mask;
43073 wait_queue_head_t irq_queue;
43074 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
43075 struct timeval last_vblank;
43076 int last_vblank_valid;
43077 unsigned usec_per_vblank;
43078 - atomic_t vbl_received;
43079 + atomic_unchecked_t vbl_received;
43080 drm_via_state_t hc_state;
43081 char pci_buf[VIA_PCI_BUF_SIZE];
43082 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
43083 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
43084 index 1319433..a993b0c 100644
43085 --- a/drivers/gpu/drm/via/via_irq.c
43086 +++ b/drivers/gpu/drm/via/via_irq.c
43087 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
43088 if (crtc != 0)
43089 return 0;
43090
43091 - return atomic_read(&dev_priv->vbl_received);
43092 + return atomic_read_unchecked(&dev_priv->vbl_received);
43093 }
43094
43095 irqreturn_t via_driver_irq_handler(int irq, void *arg)
43096 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
43097
43098 status = VIA_READ(VIA_REG_INTERRUPT);
43099 if (status & VIA_IRQ_VBLANK_PENDING) {
43100 - atomic_inc(&dev_priv->vbl_received);
43101 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
43102 + atomic_inc_unchecked(&dev_priv->vbl_received);
43103 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
43104 do_gettimeofday(&cur_vblank);
43105 if (dev_priv->last_vblank_valid) {
43106 dev_priv->usec_per_vblank =
43107 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
43108 dev_priv->last_vblank = cur_vblank;
43109 dev_priv->last_vblank_valid = 1;
43110 }
43111 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
43112 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
43113 DRM_DEBUG("US per vblank is: %u\n",
43114 dev_priv->usec_per_vblank);
43115 }
43116 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
43117
43118 for (i = 0; i < dev_priv->num_irqs; ++i) {
43119 if (status & cur_irq->pending_mask) {
43120 - atomic_inc(&cur_irq->irq_received);
43121 + atomic_inc_unchecked(&cur_irq->irq_received);
43122 wake_up(&cur_irq->irq_queue);
43123 handled = 1;
43124 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
43125 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
43126 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
43127 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
43128 masks[irq][4]));
43129 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
43130 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
43131 } else {
43132 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
43133 (((cur_irq_sequence =
43134 - atomic_read(&cur_irq->irq_received)) -
43135 + atomic_read_unchecked(&cur_irq->irq_received)) -
43136 *sequence) <= (1 << 23)));
43137 }
43138 *sequence = cur_irq_sequence;
43139 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
43140 }
43141
43142 for (i = 0; i < dev_priv->num_irqs; ++i) {
43143 - atomic_set(&cur_irq->irq_received, 0);
43144 + atomic_set_unchecked(&cur_irq->irq_received, 0);
43145 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
43146 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
43147 init_waitqueue_head(&cur_irq->irq_queue);
43148 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
43149 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
43150 case VIA_IRQ_RELATIVE:
43151 irqwait->request.sequence +=
43152 - atomic_read(&cur_irq->irq_received);
43153 + atomic_read_unchecked(&cur_irq->irq_received);
43154 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
43155 case VIA_IRQ_ABSOLUTE:
43156 break;
43157 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
43158 index 6b252a8..5975dfe 100644
43159 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
43160 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
43161 @@ -437,7 +437,7 @@ struct vmw_private {
43162 * Fencing and IRQs.
43163 */
43164
43165 - atomic_t marker_seq;
43166 + atomic_unchecked_t marker_seq;
43167 wait_queue_head_t fence_queue;
43168 wait_queue_head_t fifo_queue;
43169 int fence_queue_waiters; /* Protected by hw_mutex */
43170 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
43171 index 6ccd993..618d592 100644
43172 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
43173 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
43174 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
43175 (unsigned int) min,
43176 (unsigned int) fifo->capabilities);
43177
43178 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
43179 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
43180 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
43181 vmw_marker_queue_init(&fifo->marker_queue);
43182 return vmw_fifo_send_fence(dev_priv, &dummy);
43183 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
43184 if (reserveable)
43185 iowrite32(bytes, fifo_mem +
43186 SVGA_FIFO_RESERVED);
43187 - return fifo_mem + (next_cmd >> 2);
43188 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
43189 } else {
43190 need_bounce = true;
43191 }
43192 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
43193
43194 fm = vmw_fifo_reserve(dev_priv, bytes);
43195 if (unlikely(fm == NULL)) {
43196 - *seqno = atomic_read(&dev_priv->marker_seq);
43197 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
43198 ret = -ENOMEM;
43199 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
43200 false, 3*HZ);
43201 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
43202 }
43203
43204 do {
43205 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
43206 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
43207 } while (*seqno == 0);
43208
43209 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
43210 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
43211 index b1273e8..9c274fd 100644
43212 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
43213 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
43214 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
43215 }
43216
43217 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
43218 - vmw_gmrid_man_init,
43219 - vmw_gmrid_man_takedown,
43220 - vmw_gmrid_man_get_node,
43221 - vmw_gmrid_man_put_node,
43222 - vmw_gmrid_man_debug
43223 + .init = vmw_gmrid_man_init,
43224 + .takedown = vmw_gmrid_man_takedown,
43225 + .get_node = vmw_gmrid_man_get_node,
43226 + .put_node = vmw_gmrid_man_put_node,
43227 + .debug = vmw_gmrid_man_debug
43228 };
43229 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
43230 index 37881ec..319065d 100644
43231 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
43232 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
43233 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
43234 int ret;
43235
43236 num_clips = arg->num_clips;
43237 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
43238 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
43239
43240 if (unlikely(num_clips == 0))
43241 return 0;
43242 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
43243 int ret;
43244
43245 num_clips = arg->num_clips;
43246 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
43247 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
43248
43249 if (unlikely(num_clips == 0))
43250 return 0;
43251 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
43252 index 0c42376..6febe77 100644
43253 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
43254 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
43255 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
43256 * emitted. Then the fence is stale and signaled.
43257 */
43258
43259 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
43260 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
43261 > VMW_FENCE_WRAP);
43262
43263 return ret;
43264 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
43265
43266 if (fifo_idle)
43267 down_read(&fifo_state->rwsem);
43268 - signal_seq = atomic_read(&dev_priv->marker_seq);
43269 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
43270 ret = 0;
43271
43272 for (;;) {
43273 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
43274 index 8a8725c2..afed796 100644
43275 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
43276 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
43277 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
43278 while (!vmw_lag_lt(queue, us)) {
43279 spin_lock(&queue->lock);
43280 if (list_empty(&queue->head))
43281 - seqno = atomic_read(&dev_priv->marker_seq);
43282 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
43283 else {
43284 marker = list_first_entry(&queue->head,
43285 struct vmw_marker, head);
43286 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
43287 index 6866448..2ad2b34 100644
43288 --- a/drivers/gpu/vga/vga_switcheroo.c
43289 +++ b/drivers/gpu/vga/vga_switcheroo.c
43290 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
43291
43292 /* this version is for the case where the power switch is separate
43293 to the device being powered down. */
43294 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
43295 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
43296 {
43297 /* copy over all the bus versions */
43298 if (dev->bus && dev->bus->pm) {
43299 @@ -689,7 +689,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
43300 return ret;
43301 }
43302
43303 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
43304 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
43305 {
43306 /* copy over all the bus versions */
43307 if (dev->bus && dev->bus->pm) {
43308 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
43309 index 8ed66fd..38ff772 100644
43310 --- a/drivers/hid/hid-core.c
43311 +++ b/drivers/hid/hid-core.c
43312 @@ -2488,7 +2488,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
43313
43314 int hid_add_device(struct hid_device *hdev)
43315 {
43316 - static atomic_t id = ATOMIC_INIT(0);
43317 + static atomic_unchecked_t id = ATOMIC_INIT(0);
43318 int ret;
43319
43320 if (WARN_ON(hdev->status & HID_STAT_ADDED))
43321 @@ -2530,7 +2530,7 @@ int hid_add_device(struct hid_device *hdev)
43322 /* XXX hack, any other cleaner solution after the driver core
43323 * is converted to allow more than 20 bytes as the device name? */
43324 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
43325 - hdev->vendor, hdev->product, atomic_inc_return(&id));
43326 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
43327
43328 hid_debug_register(hdev, dev_name(&hdev->dev));
43329 ret = device_add(&hdev->dev);
43330 diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
43331 index ecc2cbf..29a74c1 100644
43332 --- a/drivers/hid/hid-magicmouse.c
43333 +++ b/drivers/hid/hid-magicmouse.c
43334 @@ -290,6 +290,11 @@ static int magicmouse_raw_event(struct hid_device *hdev,
43335 if (size < 4 || ((size - 4) % 9) != 0)
43336 return 0;
43337 npoints = (size - 4) / 9;
43338 + if (npoints > 15) {
43339 + hid_warn(hdev, "invalid size value (%d) for TRACKPAD_REPORT_ID\n",
43340 + size);
43341 + return 0;
43342 + }
43343 msc->ntouches = 0;
43344 for (ii = 0; ii < npoints; ii++)
43345 magicmouse_emit_touch(msc, ii, data + ii * 9 + 4);
43346 @@ -307,6 +312,11 @@ static int magicmouse_raw_event(struct hid_device *hdev,
43347 if (size < 6 || ((size - 6) % 8) != 0)
43348 return 0;
43349 npoints = (size - 6) / 8;
43350 + if (npoints > 15) {
43351 + hid_warn(hdev, "invalid size value (%d) for MOUSE_REPORT_ID\n",
43352 + size);
43353 + return 0;
43354 + }
43355 msc->ntouches = 0;
43356 for (ii = 0; ii < npoints; ii++)
43357 magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
43358 diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
43359 index acbb0210..020df3c 100644
43360 --- a/drivers/hid/hid-picolcd_core.c
43361 +++ b/drivers/hid/hid-picolcd_core.c
43362 @@ -350,6 +350,12 @@ static int picolcd_raw_event(struct hid_device *hdev,
43363 if (!data)
43364 return 1;
43365
43366 + if (size > 64) {
43367 + hid_warn(hdev, "invalid size value (%d) for picolcd raw event\n",
43368 + size);
43369 + return 0;
43370 + }
43371 +
43372 if (report->id == REPORT_KEY_STATE) {
43373 if (data->input_keys)
43374 ret = picolcd_raw_keypad(data, report, raw_data+1, size-1);
43375 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
43376 index c13fb5b..55a3802 100644
43377 --- a/drivers/hid/hid-wiimote-debug.c
43378 +++ b/drivers/hid/hid-wiimote-debug.c
43379 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
43380 else if (size == 0)
43381 return -EIO;
43382
43383 - if (copy_to_user(u, buf, size))
43384 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
43385 return -EFAULT;
43386
43387 *off += size;
43388 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
43389 index 0cb92e3..c7d453d 100644
43390 --- a/drivers/hid/uhid.c
43391 +++ b/drivers/hid/uhid.c
43392 @@ -47,7 +47,7 @@ struct uhid_device {
43393 struct mutex report_lock;
43394 wait_queue_head_t report_wait;
43395 atomic_t report_done;
43396 - atomic_t report_id;
43397 + atomic_unchecked_t report_id;
43398 struct uhid_event report_buf;
43399 };
43400
43401 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
43402
43403 spin_lock_irqsave(&uhid->qlock, flags);
43404 ev->type = UHID_FEATURE;
43405 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
43406 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
43407 ev->u.feature.rnum = rnum;
43408 ev->u.feature.rtype = report_type;
43409
43410 @@ -538,7 +538,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
43411 spin_lock_irqsave(&uhid->qlock, flags);
43412
43413 /* id for old report; drop it silently */
43414 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
43415 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
43416 goto unlock;
43417 if (atomic_read(&uhid->report_done))
43418 goto unlock;
43419 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
43420 index 284cf66..084c627 100644
43421 --- a/drivers/hv/channel.c
43422 +++ b/drivers/hv/channel.c
43423 @@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
43424 int ret = 0;
43425 int t;
43426
43427 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
43428 - atomic_inc(&vmbus_connection.next_gpadl_handle);
43429 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
43430 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
43431
43432 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
43433 if (ret)
43434 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
43435 index edfc848..d83e195 100644
43436 --- a/drivers/hv/hv.c
43437 +++ b/drivers/hv/hv.c
43438 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
43439 u64 output_address = (output) ? virt_to_phys(output) : 0;
43440 u32 output_address_hi = output_address >> 32;
43441 u32 output_address_lo = output_address & 0xFFFFFFFF;
43442 - void *hypercall_page = hv_context.hypercall_page;
43443 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
43444
43445 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
43446 "=a"(hv_status_lo) : "d" (control_hi),
43447 @@ -154,7 +154,7 @@ int hv_init(void)
43448 /* See if the hypercall page is already set */
43449 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
43450
43451 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
43452 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
43453
43454 if (!virtaddr)
43455 goto cleanup;
43456 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
43457 index 5e90c5d..d8fcefb 100644
43458 --- a/drivers/hv/hv_balloon.c
43459 +++ b/drivers/hv/hv_balloon.c
43460 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
43461
43462 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
43463 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
43464 -static atomic_t trans_id = ATOMIC_INIT(0);
43465 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
43466
43467 static int dm_ring_size = (5 * PAGE_SIZE);
43468
43469 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
43470 pr_info("Memory hot add failed\n");
43471
43472 dm->state = DM_INITIALIZED;
43473 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
43474 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43475 vmbus_sendpacket(dm->dev->channel, &resp,
43476 sizeof(struct dm_hot_add_response),
43477 (unsigned long)NULL,
43478 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
43479 memset(&status, 0, sizeof(struct dm_status));
43480 status.hdr.type = DM_STATUS_REPORT;
43481 status.hdr.size = sizeof(struct dm_status);
43482 - status.hdr.trans_id = atomic_inc_return(&trans_id);
43483 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43484
43485 /*
43486 * The host expects the guest to report free memory.
43487 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
43488 * send the status. This can happen if we were interrupted
43489 * after we picked our transaction ID.
43490 */
43491 - if (status.hdr.trans_id != atomic_read(&trans_id))
43492 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
43493 return;
43494
43495 /*
43496 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
43497 */
43498
43499 do {
43500 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
43501 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43502 ret = vmbus_sendpacket(dm_device.dev->channel,
43503 bl_resp,
43504 bl_resp->hdr.size,
43505 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
43506
43507 memset(&resp, 0, sizeof(struct dm_unballoon_response));
43508 resp.hdr.type = DM_UNBALLOON_RESPONSE;
43509 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
43510 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43511 resp.hdr.size = sizeof(struct dm_unballoon_response);
43512
43513 vmbus_sendpacket(dm_device.dev->channel, &resp,
43514 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
43515 memset(&version_req, 0, sizeof(struct dm_version_request));
43516 version_req.hdr.type = DM_VERSION_REQUEST;
43517 version_req.hdr.size = sizeof(struct dm_version_request);
43518 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
43519 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43520 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
43521 version_req.is_last_attempt = 1;
43522
43523 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
43524 memset(&version_req, 0, sizeof(struct dm_version_request));
43525 version_req.hdr.type = DM_VERSION_REQUEST;
43526 version_req.hdr.size = sizeof(struct dm_version_request);
43527 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
43528 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43529 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
43530 version_req.is_last_attempt = 0;
43531
43532 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
43533 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
43534 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
43535 cap_msg.hdr.size = sizeof(struct dm_capabilities);
43536 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
43537 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43538
43539 cap_msg.caps.cap_bits.balloon = 1;
43540 cap_msg.caps.cap_bits.hot_add = 1;
43541 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
43542 index 22b7507..fc2fc47 100644
43543 --- a/drivers/hv/hyperv_vmbus.h
43544 +++ b/drivers/hv/hyperv_vmbus.h
43545 @@ -607,7 +607,7 @@ enum vmbus_connect_state {
43546 struct vmbus_connection {
43547 enum vmbus_connect_state conn_state;
43548
43549 - atomic_t next_gpadl_handle;
43550 + atomic_unchecked_t next_gpadl_handle;
43551
43552 /*
43553 * Represents channel interrupts. Each bit position represents a
43554 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
43555 index 4d6b269..2e23b86 100644
43556 --- a/drivers/hv/vmbus_drv.c
43557 +++ b/drivers/hv/vmbus_drv.c
43558 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
43559 {
43560 int ret = 0;
43561
43562 - static atomic_t device_num = ATOMIC_INIT(0);
43563 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
43564
43565 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
43566 - atomic_inc_return(&device_num));
43567 + atomic_inc_return_unchecked(&device_num));
43568
43569 child_device_obj->device.bus = &hv_bus;
43570 child_device_obj->device.parent = &hv_acpi_dev->dev;
43571 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
43572 index 579bdf9..75118b5 100644
43573 --- a/drivers/hwmon/acpi_power_meter.c
43574 +++ b/drivers/hwmon/acpi_power_meter.c
43575 @@ -116,7 +116,7 @@ struct sensor_template {
43576 struct device_attribute *devattr,
43577 const char *buf, size_t count);
43578 int index;
43579 -};
43580 +} __do_const;
43581
43582 /* Averaging interval */
43583 static int update_avg_interval(struct acpi_power_meter_resource *resource)
43584 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
43585 struct sensor_template *attrs)
43586 {
43587 struct device *dev = &resource->acpi_dev->dev;
43588 - struct sensor_device_attribute *sensors =
43589 + sensor_device_attribute_no_const *sensors =
43590 &resource->sensors[resource->num_sensors];
43591 int res = 0;
43592
43593 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
43594 index 3288f13..71cfb4e 100644
43595 --- a/drivers/hwmon/applesmc.c
43596 +++ b/drivers/hwmon/applesmc.c
43597 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
43598 {
43599 struct applesmc_node_group *grp;
43600 struct applesmc_dev_attr *node;
43601 - struct attribute *attr;
43602 + attribute_no_const *attr;
43603 int ret, i;
43604
43605 for (grp = groups; grp->format; grp++) {
43606 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
43607 index ae208f6..48b6c5b 100644
43608 --- a/drivers/hwmon/asus_atk0110.c
43609 +++ b/drivers/hwmon/asus_atk0110.c
43610 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
43611 struct atk_sensor_data {
43612 struct list_head list;
43613 struct atk_data *data;
43614 - struct device_attribute label_attr;
43615 - struct device_attribute input_attr;
43616 - struct device_attribute limit1_attr;
43617 - struct device_attribute limit2_attr;
43618 + device_attribute_no_const label_attr;
43619 + device_attribute_no_const input_attr;
43620 + device_attribute_no_const limit1_attr;
43621 + device_attribute_no_const limit2_attr;
43622 char label_attr_name[ATTR_NAME_SIZE];
43623 char input_attr_name[ATTR_NAME_SIZE];
43624 char limit1_attr_name[ATTR_NAME_SIZE];
43625 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
43626 static struct device_attribute atk_name_attr =
43627 __ATTR(name, 0444, atk_name_show, NULL);
43628
43629 -static void atk_init_attribute(struct device_attribute *attr, char *name,
43630 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
43631 sysfs_show_func show)
43632 {
43633 sysfs_attr_init(&attr->attr);
43634 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
43635 index d76f0b7..55ae976 100644
43636 --- a/drivers/hwmon/coretemp.c
43637 +++ b/drivers/hwmon/coretemp.c
43638 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
43639 return NOTIFY_OK;
43640 }
43641
43642 -static struct notifier_block coretemp_cpu_notifier __refdata = {
43643 +static struct notifier_block coretemp_cpu_notifier = {
43644 .notifier_call = coretemp_cpu_callback,
43645 };
43646
43647 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
43648 index 632f1dc..57e6a58 100644
43649 --- a/drivers/hwmon/ibmaem.c
43650 +++ b/drivers/hwmon/ibmaem.c
43651 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
43652 struct aem_rw_sensor_template *rw)
43653 {
43654 struct device *dev = &data->pdev->dev;
43655 - struct sensor_device_attribute *sensors = data->sensors;
43656 + sensor_device_attribute_no_const *sensors = data->sensors;
43657 int err;
43658
43659 /* Set up read-only sensors */
43660 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
43661 index 14c82da..09b25d7 100644
43662 --- a/drivers/hwmon/iio_hwmon.c
43663 +++ b/drivers/hwmon/iio_hwmon.c
43664 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
43665 {
43666 struct device *dev = &pdev->dev;
43667 struct iio_hwmon_state *st;
43668 - struct sensor_device_attribute *a;
43669 + sensor_device_attribute_no_const *a;
43670 int ret, i;
43671 int in_i = 1, temp_i = 1, curr_i = 1;
43672 enum iio_chan_type type;
43673 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
43674 index 7710f46..427a28d 100644
43675 --- a/drivers/hwmon/nct6683.c
43676 +++ b/drivers/hwmon/nct6683.c
43677 @@ -397,11 +397,11 @@ static struct attribute_group *
43678 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43679 int repeat)
43680 {
43681 - struct sensor_device_attribute_2 *a2;
43682 - struct sensor_device_attribute *a;
43683 + sensor_device_attribute_2_no_const *a2;
43684 + sensor_device_attribute_no_const *a;
43685 struct sensor_device_template **t;
43686 struct sensor_device_attr_u *su;
43687 - struct attribute_group *group;
43688 + attribute_group_no_const *group;
43689 struct attribute **attrs;
43690 int i, j, count;
43691
43692 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
43693 index 59d9a3f..2298fa4 100644
43694 --- a/drivers/hwmon/nct6775.c
43695 +++ b/drivers/hwmon/nct6775.c
43696 @@ -944,10 +944,10 @@ static struct attribute_group *
43697 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43698 int repeat)
43699 {
43700 - struct attribute_group *group;
43701 + attribute_group_no_const *group;
43702 struct sensor_device_attr_u *su;
43703 - struct sensor_device_attribute *a;
43704 - struct sensor_device_attribute_2 *a2;
43705 + sensor_device_attribute_no_const *a;
43706 + sensor_device_attribute_2_no_const *a2;
43707 struct attribute **attrs;
43708 struct sensor_device_template **t;
43709 int i, count;
43710 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
43711 index 291d11f..3f0dbbd 100644
43712 --- a/drivers/hwmon/pmbus/pmbus_core.c
43713 +++ b/drivers/hwmon/pmbus/pmbus_core.c
43714 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
43715 return 0;
43716 }
43717
43718 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43719 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
43720 const char *name,
43721 umode_t mode,
43722 ssize_t (*show)(struct device *dev,
43723 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43724 dev_attr->store = store;
43725 }
43726
43727 -static void pmbus_attr_init(struct sensor_device_attribute *a,
43728 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
43729 const char *name,
43730 umode_t mode,
43731 ssize_t (*show)(struct device *dev,
43732 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
43733 u16 reg, u8 mask)
43734 {
43735 struct pmbus_boolean *boolean;
43736 - struct sensor_device_attribute *a;
43737 + sensor_device_attribute_no_const *a;
43738
43739 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
43740 if (!boolean)
43741 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
43742 bool update, bool readonly)
43743 {
43744 struct pmbus_sensor *sensor;
43745 - struct device_attribute *a;
43746 + device_attribute_no_const *a;
43747
43748 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
43749 if (!sensor)
43750 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
43751 const char *lstring, int index)
43752 {
43753 struct pmbus_label *label;
43754 - struct device_attribute *a;
43755 + device_attribute_no_const *a;
43756
43757 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
43758 if (!label)
43759 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
43760 index 97cd45a..ac54d8b 100644
43761 --- a/drivers/hwmon/sht15.c
43762 +++ b/drivers/hwmon/sht15.c
43763 @@ -169,7 +169,7 @@ struct sht15_data {
43764 int supply_uv;
43765 bool supply_uv_valid;
43766 struct work_struct update_supply_work;
43767 - atomic_t interrupt_handled;
43768 + atomic_unchecked_t interrupt_handled;
43769 };
43770
43771 /**
43772 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
43773 ret = gpio_direction_input(data->pdata->gpio_data);
43774 if (ret)
43775 return ret;
43776 - atomic_set(&data->interrupt_handled, 0);
43777 + atomic_set_unchecked(&data->interrupt_handled, 0);
43778
43779 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43780 if (gpio_get_value(data->pdata->gpio_data) == 0) {
43781 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
43782 /* Only relevant if the interrupt hasn't occurred. */
43783 - if (!atomic_read(&data->interrupt_handled))
43784 + if (!atomic_read_unchecked(&data->interrupt_handled))
43785 schedule_work(&data->read_work);
43786 }
43787 ret = wait_event_timeout(data->wait_queue,
43788 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
43789
43790 /* First disable the interrupt */
43791 disable_irq_nosync(irq);
43792 - atomic_inc(&data->interrupt_handled);
43793 + atomic_inc_unchecked(&data->interrupt_handled);
43794 /* Then schedule a reading work struct */
43795 if (data->state != SHT15_READING_NOTHING)
43796 schedule_work(&data->read_work);
43797 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
43798 * If not, then start the interrupt again - care here as could
43799 * have gone low in meantime so verify it hasn't!
43800 */
43801 - atomic_set(&data->interrupt_handled, 0);
43802 + atomic_set_unchecked(&data->interrupt_handled, 0);
43803 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43804 /* If still not occurred or another handler was scheduled */
43805 if (gpio_get_value(data->pdata->gpio_data)
43806 - || atomic_read(&data->interrupt_handled))
43807 + || atomic_read_unchecked(&data->interrupt_handled))
43808 return;
43809 }
43810
43811 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
43812 index 8df43c5..b07b91d 100644
43813 --- a/drivers/hwmon/via-cputemp.c
43814 +++ b/drivers/hwmon/via-cputemp.c
43815 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
43816 return NOTIFY_OK;
43817 }
43818
43819 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
43820 +static struct notifier_block via_cputemp_cpu_notifier = {
43821 .notifier_call = via_cputemp_cpu_callback,
43822 };
43823
43824 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
43825 index 41fc683..a39cfea 100644
43826 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
43827 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
43828 @@ -43,7 +43,7 @@
43829 extern struct i2c_adapter amd756_smbus;
43830
43831 static struct i2c_adapter *s4882_adapter;
43832 -static struct i2c_algorithm *s4882_algo;
43833 +static i2c_algorithm_no_const *s4882_algo;
43834
43835 /* Wrapper access functions for multiplexed SMBus */
43836 static DEFINE_MUTEX(amd756_lock);
43837 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
43838 index b19a310..d6eece0 100644
43839 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
43840 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
43841 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
43842 /* usb layer */
43843
43844 /* Send command to device, and get response. */
43845 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43846 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43847 {
43848 int ret = 0;
43849 int actual;
43850 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
43851 index b170bdf..3c76427 100644
43852 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
43853 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
43854 @@ -41,7 +41,7 @@
43855 extern struct i2c_adapter *nforce2_smbus;
43856
43857 static struct i2c_adapter *s4985_adapter;
43858 -static struct i2c_algorithm *s4985_algo;
43859 +static i2c_algorithm_no_const *s4985_algo;
43860
43861 /* Wrapper access functions for multiplexed SMBus */
43862 static DEFINE_MUTEX(nforce2_lock);
43863 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
43864 index 80b47e8..1a6040d9 100644
43865 --- a/drivers/i2c/i2c-dev.c
43866 +++ b/drivers/i2c/i2c-dev.c
43867 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
43868 break;
43869 }
43870
43871 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
43872 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
43873 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
43874 if (IS_ERR(rdwr_pa[i].buf)) {
43875 res = PTR_ERR(rdwr_pa[i].buf);
43876 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
43877 index 0b510ba..4fbb5085 100644
43878 --- a/drivers/ide/ide-cd.c
43879 +++ b/drivers/ide/ide-cd.c
43880 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
43881 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
43882 if ((unsigned long)buf & alignment
43883 || blk_rq_bytes(rq) & q->dma_pad_mask
43884 - || object_is_on_stack(buf))
43885 + || object_starts_on_stack(buf))
43886 drive->dma = 0;
43887 }
43888 }
43889 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
43890 index 4b1f375..770b95f 100644
43891 --- a/drivers/iio/industrialio-core.c
43892 +++ b/drivers/iio/industrialio-core.c
43893 @@ -551,7 +551,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
43894 }
43895
43896 static
43897 -int __iio_device_attr_init(struct device_attribute *dev_attr,
43898 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
43899 const char *postfix,
43900 struct iio_chan_spec const *chan,
43901 ssize_t (*readfunc)(struct device *dev,
43902 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
43903 index c323917..6ddea8b 100644
43904 --- a/drivers/infiniband/core/cm.c
43905 +++ b/drivers/infiniband/core/cm.c
43906 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
43907
43908 struct cm_counter_group {
43909 struct kobject obj;
43910 - atomic_long_t counter[CM_ATTR_COUNT];
43911 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
43912 };
43913
43914 struct cm_counter_attribute {
43915 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
43916 struct ib_mad_send_buf *msg = NULL;
43917 int ret;
43918
43919 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43920 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43921 counter[CM_REQ_COUNTER]);
43922
43923 /* Quick state check to discard duplicate REQs. */
43924 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
43925 if (!cm_id_priv)
43926 return;
43927
43928 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43929 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43930 counter[CM_REP_COUNTER]);
43931 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
43932 if (ret)
43933 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
43934 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
43935 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
43936 spin_unlock_irq(&cm_id_priv->lock);
43937 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43938 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43939 counter[CM_RTU_COUNTER]);
43940 goto out;
43941 }
43942 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
43943 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
43944 dreq_msg->local_comm_id);
43945 if (!cm_id_priv) {
43946 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43947 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43948 counter[CM_DREQ_COUNTER]);
43949 cm_issue_drep(work->port, work->mad_recv_wc);
43950 return -EINVAL;
43951 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
43952 case IB_CM_MRA_REP_RCVD:
43953 break;
43954 case IB_CM_TIMEWAIT:
43955 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43956 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43957 counter[CM_DREQ_COUNTER]);
43958 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43959 goto unlock;
43960 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
43961 cm_free_msg(msg);
43962 goto deref;
43963 case IB_CM_DREQ_RCVD:
43964 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43965 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43966 counter[CM_DREQ_COUNTER]);
43967 goto unlock;
43968 default:
43969 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
43970 ib_modify_mad(cm_id_priv->av.port->mad_agent,
43971 cm_id_priv->msg, timeout)) {
43972 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
43973 - atomic_long_inc(&work->port->
43974 + atomic_long_inc_unchecked(&work->port->
43975 counter_group[CM_RECV_DUPLICATES].
43976 counter[CM_MRA_COUNTER]);
43977 goto out;
43978 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
43979 break;
43980 case IB_CM_MRA_REQ_RCVD:
43981 case IB_CM_MRA_REP_RCVD:
43982 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43983 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43984 counter[CM_MRA_COUNTER]);
43985 /* fall through */
43986 default:
43987 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
43988 case IB_CM_LAP_IDLE:
43989 break;
43990 case IB_CM_MRA_LAP_SENT:
43991 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43992 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43993 counter[CM_LAP_COUNTER]);
43994 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43995 goto unlock;
43996 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
43997 cm_free_msg(msg);
43998 goto deref;
43999 case IB_CM_LAP_RCVD:
44000 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44001 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44002 counter[CM_LAP_COUNTER]);
44003 goto unlock;
44004 default:
44005 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
44006 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
44007 if (cur_cm_id_priv) {
44008 spin_unlock_irq(&cm.lock);
44009 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44010 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44011 counter[CM_SIDR_REQ_COUNTER]);
44012 goto out; /* Duplicate message. */
44013 }
44014 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
44015 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
44016 msg->retries = 1;
44017
44018 - atomic_long_add(1 + msg->retries,
44019 + atomic_long_add_unchecked(1 + msg->retries,
44020 &port->counter_group[CM_XMIT].counter[attr_index]);
44021 if (msg->retries)
44022 - atomic_long_add(msg->retries,
44023 + atomic_long_add_unchecked(msg->retries,
44024 &port->counter_group[CM_XMIT_RETRIES].
44025 counter[attr_index]);
44026
44027 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
44028 }
44029
44030 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
44031 - atomic_long_inc(&port->counter_group[CM_RECV].
44032 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
44033 counter[attr_id - CM_ATTR_ID_OFFSET]);
44034
44035 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
44036 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
44037 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
44038
44039 return sprintf(buf, "%ld\n",
44040 - atomic_long_read(&group->counter[cm_attr->index]));
44041 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
44042 }
44043
44044 static const struct sysfs_ops cm_counter_ops = {
44045 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
44046 index 9f5ad7c..588cd84 100644
44047 --- a/drivers/infiniband/core/fmr_pool.c
44048 +++ b/drivers/infiniband/core/fmr_pool.c
44049 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
44050
44051 struct task_struct *thread;
44052
44053 - atomic_t req_ser;
44054 - atomic_t flush_ser;
44055 + atomic_unchecked_t req_ser;
44056 + atomic_unchecked_t flush_ser;
44057
44058 wait_queue_head_t force_wait;
44059 };
44060 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
44061 struct ib_fmr_pool *pool = pool_ptr;
44062
44063 do {
44064 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
44065 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
44066 ib_fmr_batch_release(pool);
44067
44068 - atomic_inc(&pool->flush_ser);
44069 + atomic_inc_unchecked(&pool->flush_ser);
44070 wake_up_interruptible(&pool->force_wait);
44071
44072 if (pool->flush_function)
44073 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
44074 }
44075
44076 set_current_state(TASK_INTERRUPTIBLE);
44077 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
44078 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
44079 !kthread_should_stop())
44080 schedule();
44081 __set_current_state(TASK_RUNNING);
44082 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
44083 pool->dirty_watermark = params->dirty_watermark;
44084 pool->dirty_len = 0;
44085 spin_lock_init(&pool->pool_lock);
44086 - atomic_set(&pool->req_ser, 0);
44087 - atomic_set(&pool->flush_ser, 0);
44088 + atomic_set_unchecked(&pool->req_ser, 0);
44089 + atomic_set_unchecked(&pool->flush_ser, 0);
44090 init_waitqueue_head(&pool->force_wait);
44091
44092 pool->thread = kthread_run(ib_fmr_cleanup_thread,
44093 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
44094 }
44095 spin_unlock_irq(&pool->pool_lock);
44096
44097 - serial = atomic_inc_return(&pool->req_ser);
44098 + serial = atomic_inc_return_unchecked(&pool->req_ser);
44099 wake_up_process(pool->thread);
44100
44101 if (wait_event_interruptible(pool->force_wait,
44102 - atomic_read(&pool->flush_ser) - serial >= 0))
44103 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
44104 return -EINTR;
44105
44106 return 0;
44107 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
44108 } else {
44109 list_add_tail(&fmr->list, &pool->dirty_list);
44110 if (++pool->dirty_len >= pool->dirty_watermark) {
44111 - atomic_inc(&pool->req_ser);
44112 + atomic_inc_unchecked(&pool->req_ser);
44113 wake_up_process(pool->thread);
44114 }
44115 }
44116 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
44117 index ec7a298..8742e59 100644
44118 --- a/drivers/infiniband/hw/cxgb4/mem.c
44119 +++ b/drivers/infiniband/hw/cxgb4/mem.c
44120 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
44121 int err;
44122 struct fw_ri_tpte tpt;
44123 u32 stag_idx;
44124 - static atomic_t key;
44125 + static atomic_unchecked_t key;
44126
44127 if (c4iw_fatal_error(rdev))
44128 return -EIO;
44129 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
44130 if (rdev->stats.stag.cur > rdev->stats.stag.max)
44131 rdev->stats.stag.max = rdev->stats.stag.cur;
44132 mutex_unlock(&rdev->stats.lock);
44133 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
44134 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
44135 }
44136 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
44137 __func__, stag_state, type, pdid, stag_idx);
44138 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
44139 index 79b3dbc..96e5fcc 100644
44140 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
44141 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
44142 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
44143 struct ib_atomic_eth *ateth;
44144 struct ipath_ack_entry *e;
44145 u64 vaddr;
44146 - atomic64_t *maddr;
44147 + atomic64_unchecked_t *maddr;
44148 u64 sdata;
44149 u32 rkey;
44150 u8 next;
44151 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
44152 IB_ACCESS_REMOTE_ATOMIC)))
44153 goto nack_acc_unlck;
44154 /* Perform atomic OP and save result. */
44155 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
44156 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
44157 sdata = be64_to_cpu(ateth->swap_data);
44158 e = &qp->s_ack_queue[qp->r_head_ack_queue];
44159 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
44160 - (u64) atomic64_add_return(sdata, maddr) - sdata :
44161 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
44162 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
44163 be64_to_cpu(ateth->compare_data),
44164 sdata);
44165 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
44166 index 1f95bba..9530f87 100644
44167 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
44168 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
44169 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
44170 unsigned long flags;
44171 struct ib_wc wc;
44172 u64 sdata;
44173 - atomic64_t *maddr;
44174 + atomic64_unchecked_t *maddr;
44175 enum ib_wc_status send_status;
44176
44177 /*
44178 @@ -382,11 +382,11 @@ again:
44179 IB_ACCESS_REMOTE_ATOMIC)))
44180 goto acc_err;
44181 /* Perform atomic OP and save result. */
44182 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
44183 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
44184 sdata = wqe->wr.wr.atomic.compare_add;
44185 *(u64 *) sqp->s_sge.sge.vaddr =
44186 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
44187 - (u64) atomic64_add_return(sdata, maddr) - sdata :
44188 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
44189 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
44190 sdata, wqe->wr.wr.atomic.swap);
44191 goto send_comp;
44192 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
44193 index 287ad05..5ae7b44d 100644
44194 --- a/drivers/infiniband/hw/mlx4/mad.c
44195 +++ b/drivers/infiniband/hw/mlx4/mad.c
44196 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
44197
44198 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
44199 {
44200 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
44201 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
44202 cpu_to_be64(0xff00000000000000LL);
44203 }
44204
44205 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
44206 index ed327e6..ca1739e0 100644
44207 --- a/drivers/infiniband/hw/mlx4/mcg.c
44208 +++ b/drivers/infiniband/hw/mlx4/mcg.c
44209 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
44210 {
44211 char name[20];
44212
44213 - atomic_set(&ctx->tid, 0);
44214 + atomic_set_unchecked(&ctx->tid, 0);
44215 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
44216 ctx->mcg_wq = create_singlethread_workqueue(name);
44217 if (!ctx->mcg_wq)
44218 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
44219 index 369da3c..223e6e9 100644
44220 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
44221 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
44222 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
44223 struct list_head mcg_mgid0_list;
44224 struct workqueue_struct *mcg_wq;
44225 struct mlx4_ib_demux_pv_ctx **tun;
44226 - atomic_t tid;
44227 + atomic_unchecked_t tid;
44228 int flushing; /* flushing the work queue */
44229 };
44230
44231 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
44232 index 9d3e5c1..6f166df 100644
44233 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
44234 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
44235 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
44236 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
44237 }
44238
44239 -int mthca_QUERY_FW(struct mthca_dev *dev)
44240 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
44241 {
44242 struct mthca_mailbox *mailbox;
44243 u32 *outbox;
44244 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44245 CMD_TIME_CLASS_B);
44246 }
44247
44248 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44249 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44250 int num_mtt)
44251 {
44252 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
44253 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
44254 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
44255 }
44256
44257 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44258 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44259 int eq_num)
44260 {
44261 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
44262 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
44263 CMD_TIME_CLASS_B);
44264 }
44265
44266 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
44267 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
44268 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
44269 void *in_mad, void *response_mad)
44270 {
44271 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
44272 index ded76c1..0cf0a08 100644
44273 --- a/drivers/infiniband/hw/mthca/mthca_main.c
44274 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
44275 @@ -692,7 +692,7 @@ err_close:
44276 return err;
44277 }
44278
44279 -static int mthca_setup_hca(struct mthca_dev *dev)
44280 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
44281 {
44282 int err;
44283
44284 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
44285 index ed9a989..6aa5dc2 100644
44286 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
44287 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
44288 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
44289 * through the bitmaps)
44290 */
44291
44292 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
44293 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
44294 {
44295 int o;
44296 int m;
44297 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
44298 return key;
44299 }
44300
44301 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
44302 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
44303 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
44304 {
44305 struct mthca_mailbox *mailbox;
44306 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
44307 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
44308 }
44309
44310 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
44311 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
44312 u64 *buffer_list, int buffer_size_shift,
44313 int list_len, u64 iova, u64 total_size,
44314 u32 access, struct mthca_mr *mr)
44315 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
44316 index 415f8e1..e34214e 100644
44317 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
44318 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
44319 @@ -764,7 +764,7 @@ unlock:
44320 return 0;
44321 }
44322
44323 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
44324 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
44325 {
44326 struct mthca_dev *dev = to_mdev(ibcq->device);
44327 struct mthca_cq *cq = to_mcq(ibcq);
44328 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
44329 index 3b2a6dc..bce26ff 100644
44330 --- a/drivers/infiniband/hw/nes/nes.c
44331 +++ b/drivers/infiniband/hw/nes/nes.c
44332 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
44333 LIST_HEAD(nes_adapter_list);
44334 static LIST_HEAD(nes_dev_list);
44335
44336 -atomic_t qps_destroyed;
44337 +atomic_unchecked_t qps_destroyed;
44338
44339 static unsigned int ee_flsh_adapter;
44340 static unsigned int sysfs_nonidx_addr;
44341 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
44342 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
44343 struct nes_adapter *nesadapter = nesdev->nesadapter;
44344
44345 - atomic_inc(&qps_destroyed);
44346 + atomic_inc_unchecked(&qps_destroyed);
44347
44348 /* Free the control structures */
44349
44350 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
44351 index bd9d132..70d84f4 100644
44352 --- a/drivers/infiniband/hw/nes/nes.h
44353 +++ b/drivers/infiniband/hw/nes/nes.h
44354 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
44355 extern unsigned int wqm_quanta;
44356 extern struct list_head nes_adapter_list;
44357
44358 -extern atomic_t cm_connects;
44359 -extern atomic_t cm_accepts;
44360 -extern atomic_t cm_disconnects;
44361 -extern atomic_t cm_closes;
44362 -extern atomic_t cm_connecteds;
44363 -extern atomic_t cm_connect_reqs;
44364 -extern atomic_t cm_rejects;
44365 -extern atomic_t mod_qp_timouts;
44366 -extern atomic_t qps_created;
44367 -extern atomic_t qps_destroyed;
44368 -extern atomic_t sw_qps_destroyed;
44369 +extern atomic_unchecked_t cm_connects;
44370 +extern atomic_unchecked_t cm_accepts;
44371 +extern atomic_unchecked_t cm_disconnects;
44372 +extern atomic_unchecked_t cm_closes;
44373 +extern atomic_unchecked_t cm_connecteds;
44374 +extern atomic_unchecked_t cm_connect_reqs;
44375 +extern atomic_unchecked_t cm_rejects;
44376 +extern atomic_unchecked_t mod_qp_timouts;
44377 +extern atomic_unchecked_t qps_created;
44378 +extern atomic_unchecked_t qps_destroyed;
44379 +extern atomic_unchecked_t sw_qps_destroyed;
44380 extern u32 mh_detected;
44381 extern u32 mh_pauses_sent;
44382 extern u32 cm_packets_sent;
44383 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
44384 extern u32 cm_packets_received;
44385 extern u32 cm_packets_dropped;
44386 extern u32 cm_packets_retrans;
44387 -extern atomic_t cm_listens_created;
44388 -extern atomic_t cm_listens_destroyed;
44389 +extern atomic_unchecked_t cm_listens_created;
44390 +extern atomic_unchecked_t cm_listens_destroyed;
44391 extern u32 cm_backlog_drops;
44392 -extern atomic_t cm_loopbacks;
44393 -extern atomic_t cm_nodes_created;
44394 -extern atomic_t cm_nodes_destroyed;
44395 -extern atomic_t cm_accel_dropped_pkts;
44396 -extern atomic_t cm_resets_recvd;
44397 -extern atomic_t pau_qps_created;
44398 -extern atomic_t pau_qps_destroyed;
44399 +extern atomic_unchecked_t cm_loopbacks;
44400 +extern atomic_unchecked_t cm_nodes_created;
44401 +extern atomic_unchecked_t cm_nodes_destroyed;
44402 +extern atomic_unchecked_t cm_accel_dropped_pkts;
44403 +extern atomic_unchecked_t cm_resets_recvd;
44404 +extern atomic_unchecked_t pau_qps_created;
44405 +extern atomic_unchecked_t pau_qps_destroyed;
44406
44407 extern u32 int_mod_timer_init;
44408 extern u32 int_mod_cq_depth_256;
44409 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
44410 index 6f09a72..cf4399d 100644
44411 --- a/drivers/infiniband/hw/nes/nes_cm.c
44412 +++ b/drivers/infiniband/hw/nes/nes_cm.c
44413 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
44414 u32 cm_packets_retrans;
44415 u32 cm_packets_created;
44416 u32 cm_packets_received;
44417 -atomic_t cm_listens_created;
44418 -atomic_t cm_listens_destroyed;
44419 +atomic_unchecked_t cm_listens_created;
44420 +atomic_unchecked_t cm_listens_destroyed;
44421 u32 cm_backlog_drops;
44422 -atomic_t cm_loopbacks;
44423 -atomic_t cm_nodes_created;
44424 -atomic_t cm_nodes_destroyed;
44425 -atomic_t cm_accel_dropped_pkts;
44426 -atomic_t cm_resets_recvd;
44427 +atomic_unchecked_t cm_loopbacks;
44428 +atomic_unchecked_t cm_nodes_created;
44429 +atomic_unchecked_t cm_nodes_destroyed;
44430 +atomic_unchecked_t cm_accel_dropped_pkts;
44431 +atomic_unchecked_t cm_resets_recvd;
44432
44433 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
44434 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
44435 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
44436 /* instance of function pointers for client API */
44437 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
44438 static struct nes_cm_ops nes_cm_api = {
44439 - mini_cm_accelerated,
44440 - mini_cm_listen,
44441 - mini_cm_del_listen,
44442 - mini_cm_connect,
44443 - mini_cm_close,
44444 - mini_cm_accept,
44445 - mini_cm_reject,
44446 - mini_cm_recv_pkt,
44447 - mini_cm_dealloc_core,
44448 - mini_cm_get,
44449 - mini_cm_set
44450 + .accelerated = mini_cm_accelerated,
44451 + .listen = mini_cm_listen,
44452 + .stop_listener = mini_cm_del_listen,
44453 + .connect = mini_cm_connect,
44454 + .close = mini_cm_close,
44455 + .accept = mini_cm_accept,
44456 + .reject = mini_cm_reject,
44457 + .recv_pkt = mini_cm_recv_pkt,
44458 + .destroy_cm_core = mini_cm_dealloc_core,
44459 + .get = mini_cm_get,
44460 + .set = mini_cm_set
44461 };
44462
44463 static struct nes_cm_core *g_cm_core;
44464
44465 -atomic_t cm_connects;
44466 -atomic_t cm_accepts;
44467 -atomic_t cm_disconnects;
44468 -atomic_t cm_closes;
44469 -atomic_t cm_connecteds;
44470 -atomic_t cm_connect_reqs;
44471 -atomic_t cm_rejects;
44472 +atomic_unchecked_t cm_connects;
44473 +atomic_unchecked_t cm_accepts;
44474 +atomic_unchecked_t cm_disconnects;
44475 +atomic_unchecked_t cm_closes;
44476 +atomic_unchecked_t cm_connecteds;
44477 +atomic_unchecked_t cm_connect_reqs;
44478 +atomic_unchecked_t cm_rejects;
44479
44480 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
44481 {
44482 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
44483 kfree(listener);
44484 listener = NULL;
44485 ret = 0;
44486 - atomic_inc(&cm_listens_destroyed);
44487 + atomic_inc_unchecked(&cm_listens_destroyed);
44488 } else {
44489 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
44490 }
44491 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
44492 cm_node->rem_mac);
44493
44494 add_hte_node(cm_core, cm_node);
44495 - atomic_inc(&cm_nodes_created);
44496 + atomic_inc_unchecked(&cm_nodes_created);
44497
44498 return cm_node;
44499 }
44500 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
44501 }
44502
44503 atomic_dec(&cm_core->node_cnt);
44504 - atomic_inc(&cm_nodes_destroyed);
44505 + atomic_inc_unchecked(&cm_nodes_destroyed);
44506 nesqp = cm_node->nesqp;
44507 if (nesqp) {
44508 nesqp->cm_node = NULL;
44509 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
44510
44511 static void drop_packet(struct sk_buff *skb)
44512 {
44513 - atomic_inc(&cm_accel_dropped_pkts);
44514 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
44515 dev_kfree_skb_any(skb);
44516 }
44517
44518 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
44519 {
44520
44521 int reset = 0; /* whether to send reset in case of err.. */
44522 - atomic_inc(&cm_resets_recvd);
44523 + atomic_inc_unchecked(&cm_resets_recvd);
44524 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
44525 " refcnt=%d\n", cm_node, cm_node->state,
44526 atomic_read(&cm_node->ref_count));
44527 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
44528 rem_ref_cm_node(cm_node->cm_core, cm_node);
44529 return NULL;
44530 }
44531 - atomic_inc(&cm_loopbacks);
44532 + atomic_inc_unchecked(&cm_loopbacks);
44533 loopbackremotenode->loopbackpartner = cm_node;
44534 loopbackremotenode->tcp_cntxt.rcv_wscale =
44535 NES_CM_DEFAULT_RCV_WND_SCALE;
44536 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
44537 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
44538 else {
44539 rem_ref_cm_node(cm_core, cm_node);
44540 - atomic_inc(&cm_accel_dropped_pkts);
44541 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
44542 dev_kfree_skb_any(skb);
44543 }
44544 break;
44545 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
44546
44547 if ((cm_id) && (cm_id->event_handler)) {
44548 if (issue_disconn) {
44549 - atomic_inc(&cm_disconnects);
44550 + atomic_inc_unchecked(&cm_disconnects);
44551 cm_event.event = IW_CM_EVENT_DISCONNECT;
44552 cm_event.status = disconn_status;
44553 cm_event.local_addr = cm_id->local_addr;
44554 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
44555 }
44556
44557 if (issue_close) {
44558 - atomic_inc(&cm_closes);
44559 + atomic_inc_unchecked(&cm_closes);
44560 nes_disconnect(nesqp, 1);
44561
44562 cm_id->provider_data = nesqp;
44563 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
44564
44565 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
44566 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
44567 - atomic_inc(&cm_accepts);
44568 + atomic_inc_unchecked(&cm_accepts);
44569
44570 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
44571 netdev_refcnt_read(nesvnic->netdev));
44572 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
44573 struct nes_cm_core *cm_core;
44574 u8 *start_buff;
44575
44576 - atomic_inc(&cm_rejects);
44577 + atomic_inc_unchecked(&cm_rejects);
44578 cm_node = (struct nes_cm_node *)cm_id->provider_data;
44579 loopback = cm_node->loopbackpartner;
44580 cm_core = cm_node->cm_core;
44581 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
44582 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
44583 ntohs(laddr->sin_port));
44584
44585 - atomic_inc(&cm_connects);
44586 + atomic_inc_unchecked(&cm_connects);
44587 nesqp->active_conn = 1;
44588
44589 /* cache the cm_id in the qp */
44590 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
44591 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
44592 return err;
44593 }
44594 - atomic_inc(&cm_listens_created);
44595 + atomic_inc_unchecked(&cm_listens_created);
44596 }
44597
44598 cm_id->add_ref(cm_id);
44599 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
44600
44601 if (nesqp->destroyed)
44602 return;
44603 - atomic_inc(&cm_connecteds);
44604 + atomic_inc_unchecked(&cm_connecteds);
44605 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
44606 " local port 0x%04X. jiffies = %lu.\n",
44607 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
44608 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
44609
44610 cm_id->add_ref(cm_id);
44611 ret = cm_id->event_handler(cm_id, &cm_event);
44612 - atomic_inc(&cm_closes);
44613 + atomic_inc_unchecked(&cm_closes);
44614 cm_event.event = IW_CM_EVENT_CLOSE;
44615 cm_event.status = 0;
44616 cm_event.provider_data = cm_id->provider_data;
44617 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
44618 return;
44619 cm_id = cm_node->cm_id;
44620
44621 - atomic_inc(&cm_connect_reqs);
44622 + atomic_inc_unchecked(&cm_connect_reqs);
44623 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
44624 cm_node, cm_id, jiffies);
44625
44626 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
44627 return;
44628 cm_id = cm_node->cm_id;
44629
44630 - atomic_inc(&cm_connect_reqs);
44631 + atomic_inc_unchecked(&cm_connect_reqs);
44632 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
44633 cm_node, cm_id, jiffies);
44634
44635 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
44636 index 4166452..fc952c3 100644
44637 --- a/drivers/infiniband/hw/nes/nes_mgt.c
44638 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
44639 @@ -40,8 +40,8 @@
44640 #include "nes.h"
44641 #include "nes_mgt.h"
44642
44643 -atomic_t pau_qps_created;
44644 -atomic_t pau_qps_destroyed;
44645 +atomic_unchecked_t pau_qps_created;
44646 +atomic_unchecked_t pau_qps_destroyed;
44647
44648 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
44649 {
44650 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
44651 {
44652 struct sk_buff *skb;
44653 unsigned long flags;
44654 - atomic_inc(&pau_qps_destroyed);
44655 + atomic_inc_unchecked(&pau_qps_destroyed);
44656
44657 /* Free packets that have not yet been forwarded */
44658 /* Lock is acquired by skb_dequeue when removing the skb */
44659 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
44660 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
44661 skb_queue_head_init(&nesqp->pau_list);
44662 spin_lock_init(&nesqp->pau_lock);
44663 - atomic_inc(&pau_qps_created);
44664 + atomic_inc_unchecked(&pau_qps_created);
44665 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
44666 }
44667
44668 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
44669 index 49eb511..a774366 100644
44670 --- a/drivers/infiniband/hw/nes/nes_nic.c
44671 +++ b/drivers/infiniband/hw/nes/nes_nic.c
44672 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
44673 target_stat_values[++index] = mh_detected;
44674 target_stat_values[++index] = mh_pauses_sent;
44675 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
44676 - target_stat_values[++index] = atomic_read(&cm_connects);
44677 - target_stat_values[++index] = atomic_read(&cm_accepts);
44678 - target_stat_values[++index] = atomic_read(&cm_disconnects);
44679 - target_stat_values[++index] = atomic_read(&cm_connecteds);
44680 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
44681 - target_stat_values[++index] = atomic_read(&cm_rejects);
44682 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
44683 - target_stat_values[++index] = atomic_read(&qps_created);
44684 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
44685 - target_stat_values[++index] = atomic_read(&qps_destroyed);
44686 - target_stat_values[++index] = atomic_read(&cm_closes);
44687 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
44688 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
44689 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
44690 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
44691 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
44692 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
44693 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
44694 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
44695 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
44696 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
44697 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
44698 target_stat_values[++index] = cm_packets_sent;
44699 target_stat_values[++index] = cm_packets_bounced;
44700 target_stat_values[++index] = cm_packets_created;
44701 target_stat_values[++index] = cm_packets_received;
44702 target_stat_values[++index] = cm_packets_dropped;
44703 target_stat_values[++index] = cm_packets_retrans;
44704 - target_stat_values[++index] = atomic_read(&cm_listens_created);
44705 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
44706 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
44707 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
44708 target_stat_values[++index] = cm_backlog_drops;
44709 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
44710 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
44711 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
44712 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
44713 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
44714 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
44715 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
44716 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
44717 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
44718 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
44719 target_stat_values[++index] = nesadapter->free_4kpbl;
44720 target_stat_values[++index] = nesadapter->free_256pbl;
44721 target_stat_values[++index] = int_mod_timer_init;
44722 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
44723 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
44724 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
44725 - target_stat_values[++index] = atomic_read(&pau_qps_created);
44726 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
44727 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
44728 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
44729 }
44730
44731 /**
44732 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
44733 index 218dd35..97ce31d 100644
44734 --- a/drivers/infiniband/hw/nes/nes_verbs.c
44735 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
44736 @@ -46,9 +46,9 @@
44737
44738 #include <rdma/ib_umem.h>
44739
44740 -atomic_t mod_qp_timouts;
44741 -atomic_t qps_created;
44742 -atomic_t sw_qps_destroyed;
44743 +atomic_unchecked_t mod_qp_timouts;
44744 +atomic_unchecked_t qps_created;
44745 +atomic_unchecked_t sw_qps_destroyed;
44746
44747 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
44748
44749 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
44750 if (init_attr->create_flags)
44751 return ERR_PTR(-EINVAL);
44752
44753 - atomic_inc(&qps_created);
44754 + atomic_inc_unchecked(&qps_created);
44755 switch (init_attr->qp_type) {
44756 case IB_QPT_RC:
44757 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
44758 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
44759 struct iw_cm_event cm_event;
44760 int ret = 0;
44761
44762 - atomic_inc(&sw_qps_destroyed);
44763 + atomic_inc_unchecked(&sw_qps_destroyed);
44764 nesqp->destroyed = 1;
44765
44766 /* Blow away the connection if it exists. */
44767 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
44768 index c00ae09..04e91be 100644
44769 --- a/drivers/infiniband/hw/qib/qib.h
44770 +++ b/drivers/infiniband/hw/qib/qib.h
44771 @@ -52,6 +52,7 @@
44772 #include <linux/kref.h>
44773 #include <linux/sched.h>
44774 #include <linux/kthread.h>
44775 +#include <linux/slab.h>
44776
44777 #include "qib_common.h"
44778 #include "qib_verbs.h"
44779 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
44780 index 24c41ba..102d71f 100644
44781 --- a/drivers/input/gameport/gameport.c
44782 +++ b/drivers/input/gameport/gameport.c
44783 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
44784 */
44785 static void gameport_init_port(struct gameport *gameport)
44786 {
44787 - static atomic_t gameport_no = ATOMIC_INIT(0);
44788 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
44789
44790 __module_get(THIS_MODULE);
44791
44792 mutex_init(&gameport->drv_mutex);
44793 device_initialize(&gameport->dev);
44794 dev_set_name(&gameport->dev, "gameport%lu",
44795 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
44796 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
44797 gameport->dev.bus = &gameport_bus;
44798 gameport->dev.release = gameport_release_port;
44799 if (gameport->parent)
44800 diff --git a/drivers/input/input.c b/drivers/input/input.c
44801 index 29ca0bb..f4bc2e3 100644
44802 --- a/drivers/input/input.c
44803 +++ b/drivers/input/input.c
44804 @@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
44805 */
44806 struct input_dev *input_allocate_device(void)
44807 {
44808 - static atomic_t input_no = ATOMIC_INIT(0);
44809 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
44810 struct input_dev *dev;
44811
44812 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
44813 @@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
44814 INIT_LIST_HEAD(&dev->node);
44815
44816 dev_set_name(&dev->dev, "input%ld",
44817 - (unsigned long) atomic_inc_return(&input_no) - 1);
44818 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
44819
44820 __module_get(THIS_MODULE);
44821 }
44822 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
44823 index 4a95b22..874c182 100644
44824 --- a/drivers/input/joystick/sidewinder.c
44825 +++ b/drivers/input/joystick/sidewinder.c
44826 @@ -30,6 +30,7 @@
44827 #include <linux/kernel.h>
44828 #include <linux/module.h>
44829 #include <linux/slab.h>
44830 +#include <linux/sched.h>
44831 #include <linux/input.h>
44832 #include <linux/gameport.h>
44833 #include <linux/jiffies.h>
44834 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
44835 index 603fe0d..f63decc 100644
44836 --- a/drivers/input/joystick/xpad.c
44837 +++ b/drivers/input/joystick/xpad.c
44838 @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
44839
44840 static int xpad_led_probe(struct usb_xpad *xpad)
44841 {
44842 - static atomic_t led_seq = ATOMIC_INIT(0);
44843 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
44844 long led_no;
44845 struct xpad_led *led;
44846 struct led_classdev *led_cdev;
44847 @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
44848 if (!led)
44849 return -ENOMEM;
44850
44851 - led_no = (long)atomic_inc_return(&led_seq) - 1;
44852 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
44853
44854 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
44855 led->xpad = xpad;
44856 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
44857 index 719410f..1896169 100644
44858 --- a/drivers/input/misc/ims-pcu.c
44859 +++ b/drivers/input/misc/ims-pcu.c
44860 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
44861
44862 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44863 {
44864 - static atomic_t device_no = ATOMIC_INIT(0);
44865 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
44866
44867 const struct ims_pcu_device_info *info;
44868 int error;
44869 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44870 }
44871
44872 /* Device appears to be operable, complete initialization */
44873 - pcu->device_no = atomic_inc_return(&device_no) - 1;
44874 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
44875
44876 /*
44877 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
44878 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
44879 index 2f0b39d..7370f13 100644
44880 --- a/drivers/input/mouse/psmouse.h
44881 +++ b/drivers/input/mouse/psmouse.h
44882 @@ -116,7 +116,7 @@ struct psmouse_attribute {
44883 ssize_t (*set)(struct psmouse *psmouse, void *data,
44884 const char *buf, size_t count);
44885 bool protect;
44886 -};
44887 +} __do_const;
44888 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
44889
44890 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
44891 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
44892 index b604564..3f14ae4 100644
44893 --- a/drivers/input/mousedev.c
44894 +++ b/drivers/input/mousedev.c
44895 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
44896
44897 spin_unlock_irq(&client->packet_lock);
44898
44899 - if (copy_to_user(buffer, data, count))
44900 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
44901 return -EFAULT;
44902
44903 return count;
44904 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
44905 index b29134d..394deb0 100644
44906 --- a/drivers/input/serio/serio.c
44907 +++ b/drivers/input/serio/serio.c
44908 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
44909 */
44910 static void serio_init_port(struct serio *serio)
44911 {
44912 - static atomic_t serio_no = ATOMIC_INIT(0);
44913 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
44914
44915 __module_get(THIS_MODULE);
44916
44917 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
44918 mutex_init(&serio->drv_mutex);
44919 device_initialize(&serio->dev);
44920 dev_set_name(&serio->dev, "serio%ld",
44921 - (long)atomic_inc_return(&serio_no) - 1);
44922 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
44923 serio->dev.bus = &serio_bus;
44924 serio->dev.release = serio_release_port;
44925 serio->dev.groups = serio_device_attr_groups;
44926 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
44927 index c9a02fe..0debc75 100644
44928 --- a/drivers/input/serio/serio_raw.c
44929 +++ b/drivers/input/serio/serio_raw.c
44930 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
44931
44932 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44933 {
44934 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
44935 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
44936 struct serio_raw *serio_raw;
44937 int err;
44938
44939 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44940 }
44941
44942 snprintf(serio_raw->name, sizeof(serio_raw->name),
44943 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
44944 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
44945 kref_init(&serio_raw->kref);
44946 INIT_LIST_HEAD(&serio_raw->client_list);
44947 init_waitqueue_head(&serio_raw->wait);
44948 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
44949 index e5555fc..937986d 100644
44950 --- a/drivers/iommu/iommu.c
44951 +++ b/drivers/iommu/iommu.c
44952 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
44953 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
44954 {
44955 bus_register_notifier(bus, &iommu_bus_nb);
44956 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
44957 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
44958 }
44959
44960 /**
44961 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
44962 index 33c4395..e06447e 100644
44963 --- a/drivers/iommu/irq_remapping.c
44964 +++ b/drivers/iommu/irq_remapping.c
44965 @@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
44966 void panic_if_irq_remap(const char *msg)
44967 {
44968 if (irq_remapping_enabled)
44969 - panic(msg);
44970 + panic("%s", msg);
44971 }
44972
44973 static void ir_ack_apic_edge(struct irq_data *data)
44974 @@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
44975
44976 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
44977 {
44978 - chip->irq_print_chip = ir_print_prefix;
44979 - chip->irq_ack = ir_ack_apic_edge;
44980 - chip->irq_eoi = ir_ack_apic_level;
44981 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44982 + pax_open_kernel();
44983 + *(void **)&chip->irq_print_chip = ir_print_prefix;
44984 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
44985 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
44986 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44987 + pax_close_kernel();
44988 }
44989
44990 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
44991 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
44992 index 7c131cf..035129b 100644
44993 --- a/drivers/irqchip/irq-gic.c
44994 +++ b/drivers/irqchip/irq-gic.c
44995 @@ -85,7 +85,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
44996 * Supported arch specific GIC irq extension.
44997 * Default make them NULL.
44998 */
44999 -struct irq_chip gic_arch_extn = {
45000 +irq_chip_no_const gic_arch_extn = {
45001 .irq_eoi = NULL,
45002 .irq_mask = NULL,
45003 .irq_unmask = NULL,
45004 @@ -337,7 +337,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
45005 chained_irq_exit(chip, desc);
45006 }
45007
45008 -static struct irq_chip gic_chip = {
45009 +static irq_chip_no_const gic_chip __read_only = {
45010 .name = "GIC",
45011 .irq_mask = gic_mask_irq,
45012 .irq_unmask = gic_unmask_irq,
45013 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
45014 index 8777065..a4a9967 100644
45015 --- a/drivers/irqchip/irq-renesas-irqc.c
45016 +++ b/drivers/irqchip/irq-renesas-irqc.c
45017 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
45018 struct irqc_priv *p;
45019 struct resource *io;
45020 struct resource *irq;
45021 - struct irq_chip *irq_chip;
45022 + irq_chip_no_const *irq_chip;
45023 const char *name = dev_name(&pdev->dev);
45024 int ret;
45025 int k;
45026 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
45027 index f9a87ed..3fdd854 100644
45028 --- a/drivers/isdn/capi/capi.c
45029 +++ b/drivers/isdn/capi/capi.c
45030 @@ -81,8 +81,8 @@ struct capiminor {
45031
45032 struct capi20_appl *ap;
45033 u32 ncci;
45034 - atomic_t datahandle;
45035 - atomic_t msgid;
45036 + atomic_unchecked_t datahandle;
45037 + atomic_unchecked_t msgid;
45038
45039 struct tty_port port;
45040 int ttyinstop;
45041 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
45042 capimsg_setu16(s, 2, mp->ap->applid);
45043 capimsg_setu8 (s, 4, CAPI_DATA_B3);
45044 capimsg_setu8 (s, 5, CAPI_RESP);
45045 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
45046 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
45047 capimsg_setu32(s, 8, mp->ncci);
45048 capimsg_setu16(s, 12, datahandle);
45049 }
45050 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
45051 mp->outbytes -= len;
45052 spin_unlock_bh(&mp->outlock);
45053
45054 - datahandle = atomic_inc_return(&mp->datahandle);
45055 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
45056 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
45057 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
45058 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
45059 capimsg_setu16(skb->data, 2, mp->ap->applid);
45060 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
45061 capimsg_setu8 (skb->data, 5, CAPI_REQ);
45062 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
45063 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
45064 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
45065 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
45066 capimsg_setu16(skb->data, 16, len); /* Data length */
45067 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
45068 index b7ae0a0..04590fa 100644
45069 --- a/drivers/isdn/gigaset/bas-gigaset.c
45070 +++ b/drivers/isdn/gigaset/bas-gigaset.c
45071 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
45072
45073
45074 static const struct gigaset_ops gigops = {
45075 - gigaset_write_cmd,
45076 - gigaset_write_room,
45077 - gigaset_chars_in_buffer,
45078 - gigaset_brkchars,
45079 - gigaset_init_bchannel,
45080 - gigaset_close_bchannel,
45081 - gigaset_initbcshw,
45082 - gigaset_freebcshw,
45083 - gigaset_reinitbcshw,
45084 - gigaset_initcshw,
45085 - gigaset_freecshw,
45086 - gigaset_set_modem_ctrl,
45087 - gigaset_baud_rate,
45088 - gigaset_set_line_ctrl,
45089 - gigaset_isoc_send_skb,
45090 - gigaset_isoc_input,
45091 + .write_cmd = gigaset_write_cmd,
45092 + .write_room = gigaset_write_room,
45093 + .chars_in_buffer = gigaset_chars_in_buffer,
45094 + .brkchars = gigaset_brkchars,
45095 + .init_bchannel = gigaset_init_bchannel,
45096 + .close_bchannel = gigaset_close_bchannel,
45097 + .initbcshw = gigaset_initbcshw,
45098 + .freebcshw = gigaset_freebcshw,
45099 + .reinitbcshw = gigaset_reinitbcshw,
45100 + .initcshw = gigaset_initcshw,
45101 + .freecshw = gigaset_freecshw,
45102 + .set_modem_ctrl = gigaset_set_modem_ctrl,
45103 + .baud_rate = gigaset_baud_rate,
45104 + .set_line_ctrl = gigaset_set_line_ctrl,
45105 + .send_skb = gigaset_isoc_send_skb,
45106 + .handle_input = gigaset_isoc_input,
45107 };
45108
45109 /* bas_gigaset_init
45110 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
45111 index 600c79b..3752bab 100644
45112 --- a/drivers/isdn/gigaset/interface.c
45113 +++ b/drivers/isdn/gigaset/interface.c
45114 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
45115 }
45116 tty->driver_data = cs;
45117
45118 - ++cs->port.count;
45119 + atomic_inc(&cs->port.count);
45120
45121 - if (cs->port.count == 1) {
45122 + if (atomic_read(&cs->port.count) == 1) {
45123 tty_port_tty_set(&cs->port, tty);
45124 cs->port.low_latency = 1;
45125 }
45126 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
45127
45128 if (!cs->connected)
45129 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
45130 - else if (!cs->port.count)
45131 + else if (!atomic_read(&cs->port.count))
45132 dev_warn(cs->dev, "%s: device not opened\n", __func__);
45133 - else if (!--cs->port.count)
45134 + else if (!atomic_dec_return(&cs->port.count))
45135 tty_port_tty_set(&cs->port, NULL);
45136
45137 mutex_unlock(&cs->mutex);
45138 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
45139 index 8c91fd5..14f13ce 100644
45140 --- a/drivers/isdn/gigaset/ser-gigaset.c
45141 +++ b/drivers/isdn/gigaset/ser-gigaset.c
45142 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
45143 }
45144
45145 static const struct gigaset_ops ops = {
45146 - gigaset_write_cmd,
45147 - gigaset_write_room,
45148 - gigaset_chars_in_buffer,
45149 - gigaset_brkchars,
45150 - gigaset_init_bchannel,
45151 - gigaset_close_bchannel,
45152 - gigaset_initbcshw,
45153 - gigaset_freebcshw,
45154 - gigaset_reinitbcshw,
45155 - gigaset_initcshw,
45156 - gigaset_freecshw,
45157 - gigaset_set_modem_ctrl,
45158 - gigaset_baud_rate,
45159 - gigaset_set_line_ctrl,
45160 - gigaset_m10x_send_skb, /* asyncdata.c */
45161 - gigaset_m10x_input, /* asyncdata.c */
45162 + .write_cmd = gigaset_write_cmd,
45163 + .write_room = gigaset_write_room,
45164 + .chars_in_buffer = gigaset_chars_in_buffer,
45165 + .brkchars = gigaset_brkchars,
45166 + .init_bchannel = gigaset_init_bchannel,
45167 + .close_bchannel = gigaset_close_bchannel,
45168 + .initbcshw = gigaset_initbcshw,
45169 + .freebcshw = gigaset_freebcshw,
45170 + .reinitbcshw = gigaset_reinitbcshw,
45171 + .initcshw = gigaset_initcshw,
45172 + .freecshw = gigaset_freecshw,
45173 + .set_modem_ctrl = gigaset_set_modem_ctrl,
45174 + .baud_rate = gigaset_baud_rate,
45175 + .set_line_ctrl = gigaset_set_line_ctrl,
45176 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
45177 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
45178 };
45179
45180
45181 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
45182 index d0a41cb..b953e50 100644
45183 --- a/drivers/isdn/gigaset/usb-gigaset.c
45184 +++ b/drivers/isdn/gigaset/usb-gigaset.c
45185 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
45186 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
45187 memcpy(cs->hw.usb->bchars, buf, 6);
45188 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
45189 - 0, 0, &buf, 6, 2000);
45190 + 0, 0, buf, 6, 2000);
45191 }
45192
45193 static void gigaset_freebcshw(struct bc_state *bcs)
45194 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
45195 }
45196
45197 static const struct gigaset_ops ops = {
45198 - gigaset_write_cmd,
45199 - gigaset_write_room,
45200 - gigaset_chars_in_buffer,
45201 - gigaset_brkchars,
45202 - gigaset_init_bchannel,
45203 - gigaset_close_bchannel,
45204 - gigaset_initbcshw,
45205 - gigaset_freebcshw,
45206 - gigaset_reinitbcshw,
45207 - gigaset_initcshw,
45208 - gigaset_freecshw,
45209 - gigaset_set_modem_ctrl,
45210 - gigaset_baud_rate,
45211 - gigaset_set_line_ctrl,
45212 - gigaset_m10x_send_skb,
45213 - gigaset_m10x_input,
45214 + .write_cmd = gigaset_write_cmd,
45215 + .write_room = gigaset_write_room,
45216 + .chars_in_buffer = gigaset_chars_in_buffer,
45217 + .brkchars = gigaset_brkchars,
45218 + .init_bchannel = gigaset_init_bchannel,
45219 + .close_bchannel = gigaset_close_bchannel,
45220 + .initbcshw = gigaset_initbcshw,
45221 + .freebcshw = gigaset_freebcshw,
45222 + .reinitbcshw = gigaset_reinitbcshw,
45223 + .initcshw = gigaset_initcshw,
45224 + .freecshw = gigaset_freecshw,
45225 + .set_modem_ctrl = gigaset_set_modem_ctrl,
45226 + .baud_rate = gigaset_baud_rate,
45227 + .set_line_ctrl = gigaset_set_line_ctrl,
45228 + .send_skb = gigaset_m10x_send_skb,
45229 + .handle_input = gigaset_m10x_input,
45230 };
45231
45232 /*
45233 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
45234 index 4d9b195..455075c 100644
45235 --- a/drivers/isdn/hardware/avm/b1.c
45236 +++ b/drivers/isdn/hardware/avm/b1.c
45237 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
45238 }
45239 if (left) {
45240 if (t4file->user) {
45241 - if (copy_from_user(buf, dp, left))
45242 + if (left > sizeof buf || copy_from_user(buf, dp, left))
45243 return -EFAULT;
45244 } else {
45245 memcpy(buf, dp, left);
45246 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
45247 }
45248 if (left) {
45249 if (config->user) {
45250 - if (copy_from_user(buf, dp, left))
45251 + if (left > sizeof buf || copy_from_user(buf, dp, left))
45252 return -EFAULT;
45253 } else {
45254 memcpy(buf, dp, left);
45255 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
45256 index 9b856e1..fa03c92 100644
45257 --- a/drivers/isdn/i4l/isdn_common.c
45258 +++ b/drivers/isdn/i4l/isdn_common.c
45259 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
45260 } else
45261 return -EINVAL;
45262 case IIOCDBGVAR:
45263 + if (!capable(CAP_SYS_RAWIO))
45264 + return -EPERM;
45265 if (arg) {
45266 if (copy_to_user(argp, &dev, sizeof(ulong)))
45267 return -EFAULT;
45268 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
45269 index 91d5730..336523e 100644
45270 --- a/drivers/isdn/i4l/isdn_concap.c
45271 +++ b/drivers/isdn/i4l/isdn_concap.c
45272 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
45273 }
45274
45275 struct concap_device_ops isdn_concap_reliable_dl_dops = {
45276 - &isdn_concap_dl_data_req,
45277 - &isdn_concap_dl_connect_req,
45278 - &isdn_concap_dl_disconn_req
45279 + .data_req = &isdn_concap_dl_data_req,
45280 + .connect_req = &isdn_concap_dl_connect_req,
45281 + .disconn_req = &isdn_concap_dl_disconn_req
45282 };
45283
45284 /* The following should better go into a dedicated source file such that
45285 diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
45286 index 62f0688..38ceac5 100644
45287 --- a/drivers/isdn/i4l/isdn_ppp.c
45288 +++ b/drivers/isdn/i4l/isdn_ppp.c
45289 @@ -378,15 +378,10 @@ isdn_ppp_release(int min, struct file *file)
45290 is->slcomp = NULL;
45291 #endif
45292 #ifdef CONFIG_IPPP_FILTER
45293 - if (is->pass_filter) {
45294 - sk_unattached_filter_destroy(is->pass_filter);
45295 - is->pass_filter = NULL;
45296 - }
45297 -
45298 - if (is->active_filter) {
45299 - sk_unattached_filter_destroy(is->active_filter);
45300 - is->active_filter = NULL;
45301 - }
45302 + kfree(is->pass_filter);
45303 + is->pass_filter = NULL;
45304 + kfree(is->active_filter);
45305 + is->active_filter = NULL;
45306 #endif
45307
45308 /* TODO: if this was the previous master: link the stuff to the new master */
45309 @@ -442,7 +437,7 @@ static int get_filter(void __user *arg, struct sock_filter **p)
45310 {
45311 struct sock_fprog uprog;
45312 struct sock_filter *code = NULL;
45313 - int len;
45314 + int len, err;
45315
45316 if (copy_from_user(&uprog, arg, sizeof(uprog)))
45317 return -EFAULT;
45318 @@ -458,6 +453,12 @@ static int get_filter(void __user *arg, struct sock_filter **p)
45319 if (IS_ERR(code))
45320 return PTR_ERR(code);
45321
45322 + err = sk_chk_filter(code, uprog.len);
45323 + if (err) {
45324 + kfree(code);
45325 + return err;
45326 + }
45327 +
45328 *p = code;
45329 return uprog.len;
45330 }
45331 @@ -628,53 +629,25 @@ isdn_ppp_ioctl(int min, struct file *file, unsigned int cmd, unsigned long arg)
45332 #ifdef CONFIG_IPPP_FILTER
45333 case PPPIOCSPASS:
45334 {
45335 - struct sock_fprog_kern fprog;
45336 struct sock_filter *code;
45337 - int err, len = get_filter(argp, &code);
45338 -
45339 + int len = get_filter(argp, &code);
45340 if (len < 0)
45341 return len;
45342 -
45343 - fprog.len = len;
45344 - fprog.filter = code;
45345 -
45346 - if (is->pass_filter) {
45347 - sk_unattached_filter_destroy(is->pass_filter);
45348 - is->pass_filter = NULL;
45349 - }
45350 - if (fprog.filter != NULL)
45351 - err = sk_unattached_filter_create(&is->pass_filter,
45352 - &fprog);
45353 - else
45354 - err = 0;
45355 - kfree(code);
45356 -
45357 - return err;
45358 + kfree(is->pass_filter);
45359 + is->pass_filter = code;
45360 + is->pass_len = len;
45361 + break;
45362 }
45363 case PPPIOCSACTIVE:
45364 {
45365 - struct sock_fprog_kern fprog;
45366 struct sock_filter *code;
45367 - int err, len = get_filter(argp, &code);
45368 -
45369 + int len = get_filter(argp, &code);
45370 if (len < 0)
45371 return len;
45372 -
45373 - fprog.len = len;
45374 - fprog.filter = code;
45375 -
45376 - if (is->active_filter) {
45377 - sk_unattached_filter_destroy(is->active_filter);
45378 - is->active_filter = NULL;
45379 - }
45380 - if (fprog.filter != NULL)
45381 - err = sk_unattached_filter_create(&is->active_filter,
45382 - &fprog);
45383 - else
45384 - err = 0;
45385 - kfree(code);
45386 -
45387 - return err;
45388 + kfree(is->active_filter);
45389 + is->active_filter = code;
45390 + is->active_len = len;
45391 + break;
45392 }
45393 #endif /* CONFIG_IPPP_FILTER */
45394 default:
45395 @@ -1174,14 +1147,14 @@ isdn_ppp_push_higher(isdn_net_dev *net_dev, isdn_net_local *lp, struct sk_buff *
45396 }
45397
45398 if (is->pass_filter
45399 - && SK_RUN_FILTER(is->pass_filter, skb) == 0) {
45400 + && sk_run_filter(skb, is->pass_filter) == 0) {
45401 if (is->debug & 0x2)
45402 printk(KERN_DEBUG "IPPP: inbound frame filtered.\n");
45403 kfree_skb(skb);
45404 return;
45405 }
45406 if (!(is->active_filter
45407 - && SK_RUN_FILTER(is->active_filter, skb) == 0)) {
45408 + && sk_run_filter(skb, is->active_filter) == 0)) {
45409 if (is->debug & 0x2)
45410 printk(KERN_DEBUG "IPPP: link-active filter: resetting huptimer.\n");
45411 lp->huptimer = 0;
45412 @@ -1320,14 +1293,14 @@ isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
45413 }
45414
45415 if (ipt->pass_filter
45416 - && SK_RUN_FILTER(ipt->pass_filter, skb) == 0) {
45417 + && sk_run_filter(skb, ipt->pass_filter) == 0) {
45418 if (ipt->debug & 0x4)
45419 printk(KERN_DEBUG "IPPP: outbound frame filtered.\n");
45420 kfree_skb(skb);
45421 goto unlock;
45422 }
45423 if (!(ipt->active_filter
45424 - && SK_RUN_FILTER(ipt->active_filter, skb) == 0)) {
45425 + && sk_run_filter(skb, ipt->active_filter) == 0)) {
45426 if (ipt->debug & 0x4)
45427 printk(KERN_DEBUG "IPPP: link-active filter: resetting huptimer.\n");
45428 lp->huptimer = 0;
45429 @@ -1517,9 +1490,9 @@ int isdn_ppp_autodial_filter(struct sk_buff *skb, isdn_net_local *lp)
45430 }
45431
45432 drop |= is->pass_filter
45433 - && SK_RUN_FILTER(is->pass_filter, skb) == 0;
45434 + && sk_run_filter(skb, is->pass_filter) == 0;
45435 drop |= is->active_filter
45436 - && SK_RUN_FILTER(is->active_filter, skb) == 0;
45437 + && sk_run_filter(skb, is->active_filter) == 0;
45438
45439 skb_push(skb, IPPP_MAX_HEADER - 4);
45440 return drop;
45441 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
45442 index 3c5f249..5fac4d0 100644
45443 --- a/drivers/isdn/i4l/isdn_tty.c
45444 +++ b/drivers/isdn/i4l/isdn_tty.c
45445 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
45446
45447 #ifdef ISDN_DEBUG_MODEM_OPEN
45448 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
45449 - port->count);
45450 + atomic_read(&port->count));
45451 #endif
45452 - port->count++;
45453 + atomic_inc(&port->count);
45454 port->tty = tty;
45455 /*
45456 * Start up serial port
45457 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
45458 #endif
45459 return;
45460 }
45461 - if ((tty->count == 1) && (port->count != 1)) {
45462 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
45463 /*
45464 * Uh, oh. tty->count is 1, which means that the tty
45465 * structure will be freed. Info->count should always
45466 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
45467 * serial port won't be shutdown.
45468 */
45469 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
45470 - "info->count is %d\n", port->count);
45471 - port->count = 1;
45472 + "info->count is %d\n", atomic_read(&port->count));
45473 + atomic_set(&port->count, 1);
45474 }
45475 - if (--port->count < 0) {
45476 + if (atomic_dec_return(&port->count) < 0) {
45477 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
45478 - info->line, port->count);
45479 - port->count = 0;
45480 + info->line, atomic_read(&port->count));
45481 + atomic_set(&port->count, 0);
45482 }
45483 - if (port->count) {
45484 + if (atomic_read(&port->count)) {
45485 #ifdef ISDN_DEBUG_MODEM_OPEN
45486 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
45487 #endif
45488 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
45489 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
45490 return;
45491 isdn_tty_shutdown(info);
45492 - port->count = 0;
45493 + atomic_set(&port->count, 0);
45494 port->flags &= ~ASYNC_NORMAL_ACTIVE;
45495 port->tty = NULL;
45496 wake_up_interruptible(&port->open_wait);
45497 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
45498 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
45499 modem_info *info = &dev->mdm.info[i];
45500
45501 - if (info->port.count == 0)
45502 + if (atomic_read(&info->port.count) == 0)
45503 continue;
45504 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
45505 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
45506 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
45507 index e2d4e58..40cd045 100644
45508 --- a/drivers/isdn/i4l/isdn_x25iface.c
45509 +++ b/drivers/isdn/i4l/isdn_x25iface.c
45510 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
45511
45512
45513 static struct concap_proto_ops ix25_pops = {
45514 - &isdn_x25iface_proto_new,
45515 - &isdn_x25iface_proto_del,
45516 - &isdn_x25iface_proto_restart,
45517 - &isdn_x25iface_proto_close,
45518 - &isdn_x25iface_xmit,
45519 - &isdn_x25iface_receive,
45520 - &isdn_x25iface_connect_ind,
45521 - &isdn_x25iface_disconn_ind
45522 + .proto_new = &isdn_x25iface_proto_new,
45523 + .proto_del = &isdn_x25iface_proto_del,
45524 + .restart = &isdn_x25iface_proto_restart,
45525 + .close = &isdn_x25iface_proto_close,
45526 + .encap_and_xmit = &isdn_x25iface_xmit,
45527 + .data_ind = &isdn_x25iface_receive,
45528 + .connect_ind = &isdn_x25iface_connect_ind,
45529 + .disconn_ind = &isdn_x25iface_disconn_ind
45530 };
45531
45532 /* error message helper function */
45533 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
45534 index 6a7447c..cae33fe 100644
45535 --- a/drivers/isdn/icn/icn.c
45536 +++ b/drivers/isdn/icn/icn.c
45537 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
45538 if (count > len)
45539 count = len;
45540 if (user) {
45541 - if (copy_from_user(msg, buf, count))
45542 + if (count > sizeof msg || copy_from_user(msg, buf, count))
45543 return -EFAULT;
45544 } else
45545 memcpy(msg, buf, count);
45546 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
45547 index a4f05c5..1433bc5 100644
45548 --- a/drivers/isdn/mISDN/dsp_cmx.c
45549 +++ b/drivers/isdn/mISDN/dsp_cmx.c
45550 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
45551 static u16 dsp_count; /* last sample count */
45552 static int dsp_count_valid; /* if we have last sample count */
45553
45554 -void
45555 +void __intentional_overflow(-1)
45556 dsp_cmx_send(void *arg)
45557 {
45558 struct dsp_conf *conf;
45559 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
45560 index f58a354..fbae176 100644
45561 --- a/drivers/leds/leds-clevo-mail.c
45562 +++ b/drivers/leds/leds-clevo-mail.c
45563 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
45564 * detected as working, but in reality it is not) as low as
45565 * possible.
45566 */
45567 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
45568 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
45569 {
45570 .callback = clevo_mail_led_dmi_callback,
45571 .ident = "Clevo D410J",
45572 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
45573 index 2eb3ef6..295891f 100644
45574 --- a/drivers/leds/leds-ss4200.c
45575 +++ b/drivers/leds/leds-ss4200.c
45576 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
45577 * detected as working, but in reality it is not) as low as
45578 * possible.
45579 */
45580 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
45581 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
45582 {
45583 .callback = ss4200_led_dmi_callback,
45584 .ident = "Intel SS4200-E",
45585 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
45586 index 0bf1e4e..b4bf44e 100644
45587 --- a/drivers/lguest/core.c
45588 +++ b/drivers/lguest/core.c
45589 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
45590 * The end address needs +1 because __get_vm_area allocates an
45591 * extra guard page, so we need space for that.
45592 */
45593 +
45594 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
45595 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
45596 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
45597 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
45598 +#else
45599 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
45600 VM_ALLOC, switcher_addr, switcher_addr
45601 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
45602 +#endif
45603 +
45604 if (!switcher_vma) {
45605 err = -ENOMEM;
45606 printk("lguest: could not map switcher pages high\n");
45607 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
45608 * Now the Switcher is mapped at the right address, we can't fail!
45609 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
45610 */
45611 - memcpy(switcher_vma->addr, start_switcher_text,
45612 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
45613 end_switcher_text - start_switcher_text);
45614
45615 printk(KERN_INFO "lguest: mapped switcher at %p\n",
45616 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
45617 index e8b55c3..3514c37 100644
45618 --- a/drivers/lguest/page_tables.c
45619 +++ b/drivers/lguest/page_tables.c
45620 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
45621 /*:*/
45622
45623 #ifdef CONFIG_X86_PAE
45624 -static void release_pmd(pmd_t *spmd)
45625 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
45626 {
45627 /* If the entry's not present, there's nothing to release. */
45628 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
45629 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
45630 index 922a1ac..9dd0c2a 100644
45631 --- a/drivers/lguest/x86/core.c
45632 +++ b/drivers/lguest/x86/core.c
45633 @@ -59,7 +59,7 @@ static struct {
45634 /* Offset from where switcher.S was compiled to where we've copied it */
45635 static unsigned long switcher_offset(void)
45636 {
45637 - return switcher_addr - (unsigned long)start_switcher_text;
45638 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
45639 }
45640
45641 /* This cpu's struct lguest_pages (after the Switcher text page) */
45642 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
45643 * These copies are pretty cheap, so we do them unconditionally: */
45644 /* Save the current Host top-level page directory.
45645 */
45646 +
45647 +#ifdef CONFIG_PAX_PER_CPU_PGD
45648 + pages->state.host_cr3 = read_cr3();
45649 +#else
45650 pages->state.host_cr3 = __pa(current->mm->pgd);
45651 +#endif
45652 +
45653 /*
45654 * Set up the Guest's page tables to see this CPU's pages (and no
45655 * other CPU's pages).
45656 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
45657 * compiled-in switcher code and the high-mapped copy we just made.
45658 */
45659 for (i = 0; i < IDT_ENTRIES; i++)
45660 - default_idt_entries[i] += switcher_offset();
45661 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
45662
45663 /*
45664 * Set up the Switcher's per-cpu areas.
45665 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
45666 * it will be undisturbed when we switch. To change %cs and jump we
45667 * need this structure to feed to Intel's "lcall" instruction.
45668 */
45669 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
45670 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
45671 lguest_entry.segment = LGUEST_CS;
45672
45673 /*
45674 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
45675 index 40634b0..4f5855e 100644
45676 --- a/drivers/lguest/x86/switcher_32.S
45677 +++ b/drivers/lguest/x86/switcher_32.S
45678 @@ -87,6 +87,7 @@
45679 #include <asm/page.h>
45680 #include <asm/segment.h>
45681 #include <asm/lguest.h>
45682 +#include <asm/processor-flags.h>
45683
45684 // We mark the start of the code to copy
45685 // It's placed in .text tho it's never run here
45686 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
45687 // Changes type when we load it: damn Intel!
45688 // For after we switch over our page tables
45689 // That entry will be read-only: we'd crash.
45690 +
45691 +#ifdef CONFIG_PAX_KERNEXEC
45692 + mov %cr0, %edx
45693 + xor $X86_CR0_WP, %edx
45694 + mov %edx, %cr0
45695 +#endif
45696 +
45697 movl $(GDT_ENTRY_TSS*8), %edx
45698 ltr %dx
45699
45700 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
45701 // Let's clear it again for our return.
45702 // The GDT descriptor of the Host
45703 // Points to the table after two "size" bytes
45704 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
45705 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
45706 // Clear "used" from type field (byte 5, bit 2)
45707 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
45708 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
45709 +
45710 +#ifdef CONFIG_PAX_KERNEXEC
45711 + mov %cr0, %eax
45712 + xor $X86_CR0_WP, %eax
45713 + mov %eax, %cr0
45714 +#endif
45715
45716 // Once our page table's switched, the Guest is live!
45717 // The Host fades as we run this final step.
45718 @@ -295,13 +309,12 @@ deliver_to_host:
45719 // I consulted gcc, and it gave
45720 // These instructions, which I gladly credit:
45721 leal (%edx,%ebx,8), %eax
45722 - movzwl (%eax),%edx
45723 - movl 4(%eax), %eax
45724 - xorw %ax, %ax
45725 - orl %eax, %edx
45726 + movl 4(%eax), %edx
45727 + movw (%eax), %dx
45728 // Now the address of the handler's in %edx
45729 // We call it now: its "iret" drops us home.
45730 - jmp *%edx
45731 + ljmp $__KERNEL_CS, $1f
45732 +1: jmp *%edx
45733
45734 // Every interrupt can come to us here
45735 // But we must truly tell each apart.
45736 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
45737 index a08e3ee..df8ade2 100644
45738 --- a/drivers/md/bcache/closure.h
45739 +++ b/drivers/md/bcache/closure.h
45740 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
45741 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
45742 struct workqueue_struct *wq)
45743 {
45744 - BUG_ON(object_is_on_stack(cl));
45745 + BUG_ON(object_starts_on_stack(cl));
45746 closure_set_ip(cl);
45747 cl->fn = fn;
45748 cl->wq = wq;
45749 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
45750 index 67f8b31..9418f2b 100644
45751 --- a/drivers/md/bitmap.c
45752 +++ b/drivers/md/bitmap.c
45753 @@ -1775,7 +1775,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
45754 chunk_kb ? "KB" : "B");
45755 if (bitmap->storage.file) {
45756 seq_printf(seq, ", file: ");
45757 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
45758 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
45759 }
45760
45761 seq_printf(seq, "\n");
45762 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
45763 index 5152142..623d141 100644
45764 --- a/drivers/md/dm-ioctl.c
45765 +++ b/drivers/md/dm-ioctl.c
45766 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
45767 cmd == DM_LIST_VERSIONS_CMD)
45768 return 0;
45769
45770 - if ((cmd == DM_DEV_CREATE_CMD)) {
45771 + if (cmd == DM_DEV_CREATE_CMD) {
45772 if (!*param->name) {
45773 DMWARN("name not supplied when creating device");
45774 return -EINVAL;
45775 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
45776 index 7dfdb5c..4caada6 100644
45777 --- a/drivers/md/dm-raid1.c
45778 +++ b/drivers/md/dm-raid1.c
45779 @@ -40,7 +40,7 @@ enum dm_raid1_error {
45780
45781 struct mirror {
45782 struct mirror_set *ms;
45783 - atomic_t error_count;
45784 + atomic_unchecked_t error_count;
45785 unsigned long error_type;
45786 struct dm_dev *dev;
45787 sector_t offset;
45788 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
45789 struct mirror *m;
45790
45791 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
45792 - if (!atomic_read(&m->error_count))
45793 + if (!atomic_read_unchecked(&m->error_count))
45794 return m;
45795
45796 return NULL;
45797 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
45798 * simple way to tell if a device has encountered
45799 * errors.
45800 */
45801 - atomic_inc(&m->error_count);
45802 + atomic_inc_unchecked(&m->error_count);
45803
45804 if (test_and_set_bit(error_type, &m->error_type))
45805 return;
45806 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
45807 struct mirror *m = get_default_mirror(ms);
45808
45809 do {
45810 - if (likely(!atomic_read(&m->error_count)))
45811 + if (likely(!atomic_read_unchecked(&m->error_count)))
45812 return m;
45813
45814 if (m-- == ms->mirror)
45815 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
45816 {
45817 struct mirror *default_mirror = get_default_mirror(m->ms);
45818
45819 - return !atomic_read(&default_mirror->error_count);
45820 + return !atomic_read_unchecked(&default_mirror->error_count);
45821 }
45822
45823 static int mirror_available(struct mirror_set *ms, struct bio *bio)
45824 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
45825 */
45826 if (likely(region_in_sync(ms, region, 1)))
45827 m = choose_mirror(ms, bio->bi_iter.bi_sector);
45828 - else if (m && atomic_read(&m->error_count))
45829 + else if (m && atomic_read_unchecked(&m->error_count))
45830 m = NULL;
45831
45832 if (likely(m))
45833 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
45834 }
45835
45836 ms->mirror[mirror].ms = ms;
45837 - atomic_set(&(ms->mirror[mirror].error_count), 0);
45838 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
45839 ms->mirror[mirror].error_type = 0;
45840 ms->mirror[mirror].offset = offset;
45841
45842 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
45843 */
45844 static char device_status_char(struct mirror *m)
45845 {
45846 - if (!atomic_read(&(m->error_count)))
45847 + if (!atomic_read_unchecked(&(m->error_count)))
45848 return 'A';
45849
45850 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
45851 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
45852 index 28a9012..9c0f6a5 100644
45853 --- a/drivers/md/dm-stats.c
45854 +++ b/drivers/md/dm-stats.c
45855 @@ -382,7 +382,7 @@ do_sync_free:
45856 synchronize_rcu_expedited();
45857 dm_stat_free(&s->rcu_head);
45858 } else {
45859 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
45860 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
45861 call_rcu(&s->rcu_head, dm_stat_free);
45862 }
45863 return 0;
45864 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
45865 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
45866 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
45867 ));
45868 - ACCESS_ONCE(last->last_sector) = end_sector;
45869 - ACCESS_ONCE(last->last_rw) = bi_rw;
45870 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
45871 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
45872 }
45873
45874 rcu_read_lock();
45875 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
45876 index d1600d2..4c3af3a 100644
45877 --- a/drivers/md/dm-stripe.c
45878 +++ b/drivers/md/dm-stripe.c
45879 @@ -21,7 +21,7 @@ struct stripe {
45880 struct dm_dev *dev;
45881 sector_t physical_start;
45882
45883 - atomic_t error_count;
45884 + atomic_unchecked_t error_count;
45885 };
45886
45887 struct stripe_c {
45888 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
45889 kfree(sc);
45890 return r;
45891 }
45892 - atomic_set(&(sc->stripe[i].error_count), 0);
45893 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
45894 }
45895
45896 ti->private = sc;
45897 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
45898 DMEMIT("%d ", sc->stripes);
45899 for (i = 0; i < sc->stripes; i++) {
45900 DMEMIT("%s ", sc->stripe[i].dev->name);
45901 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
45902 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
45903 'D' : 'A';
45904 }
45905 buffer[i] = '\0';
45906 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
45907 */
45908 for (i = 0; i < sc->stripes; i++)
45909 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
45910 - atomic_inc(&(sc->stripe[i].error_count));
45911 - if (atomic_read(&(sc->stripe[i].error_count)) <
45912 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
45913 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
45914 DM_IO_ERROR_THRESHOLD)
45915 schedule_work(&sc->trigger_event);
45916 }
45917 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
45918 index 5f59f1e..01bd02e 100644
45919 --- a/drivers/md/dm-table.c
45920 +++ b/drivers/md/dm-table.c
45921 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
45922 static int open_dev(struct dm_dev_internal *d, dev_t dev,
45923 struct mapped_device *md)
45924 {
45925 - static char *_claim_ptr = "I belong to device-mapper";
45926 + static char _claim_ptr[] = "I belong to device-mapper";
45927 struct block_device *bdev;
45928
45929 int r;
45930 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
45931 if (!dev_size)
45932 return 0;
45933
45934 - if ((start >= dev_size) || (start + len > dev_size)) {
45935 + if ((start >= dev_size) || (len > dev_size - start)) {
45936 DMWARN("%s: %s too small for target: "
45937 "start=%llu, len=%llu, dev_size=%llu",
45938 dm_device_name(ti->table->md), bdevname(bdev, b),
45939 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
45940 index e9d33ad..dae9880d 100644
45941 --- a/drivers/md/dm-thin-metadata.c
45942 +++ b/drivers/md/dm-thin-metadata.c
45943 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
45944 {
45945 pmd->info.tm = pmd->tm;
45946 pmd->info.levels = 2;
45947 - pmd->info.value_type.context = pmd->data_sm;
45948 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
45949 pmd->info.value_type.size = sizeof(__le64);
45950 pmd->info.value_type.inc = data_block_inc;
45951 pmd->info.value_type.dec = data_block_dec;
45952 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
45953
45954 pmd->bl_info.tm = pmd->tm;
45955 pmd->bl_info.levels = 1;
45956 - pmd->bl_info.value_type.context = pmd->data_sm;
45957 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
45958 pmd->bl_info.value_type.size = sizeof(__le64);
45959 pmd->bl_info.value_type.inc = data_block_inc;
45960 pmd->bl_info.value_type.dec = data_block_dec;
45961 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
45962 index 32b958d..34011e8 100644
45963 --- a/drivers/md/dm.c
45964 +++ b/drivers/md/dm.c
45965 @@ -180,9 +180,9 @@ struct mapped_device {
45966 /*
45967 * Event handling.
45968 */
45969 - atomic_t event_nr;
45970 + atomic_unchecked_t event_nr;
45971 wait_queue_head_t eventq;
45972 - atomic_t uevent_seq;
45973 + atomic_unchecked_t uevent_seq;
45974 struct list_head uevent_list;
45975 spinlock_t uevent_lock; /* Protect access to uevent_list */
45976
45977 @@ -1952,8 +1952,8 @@ static struct mapped_device *alloc_dev(int minor)
45978 spin_lock_init(&md->deferred_lock);
45979 atomic_set(&md->holders, 1);
45980 atomic_set(&md->open_count, 0);
45981 - atomic_set(&md->event_nr, 0);
45982 - atomic_set(&md->uevent_seq, 0);
45983 + atomic_set_unchecked(&md->event_nr, 0);
45984 + atomic_set_unchecked(&md->uevent_seq, 0);
45985 INIT_LIST_HEAD(&md->uevent_list);
45986 spin_lock_init(&md->uevent_lock);
45987
45988 @@ -2107,7 +2107,7 @@ static void event_callback(void *context)
45989
45990 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
45991
45992 - atomic_inc(&md->event_nr);
45993 + atomic_inc_unchecked(&md->event_nr);
45994 wake_up(&md->eventq);
45995 }
45996
45997 @@ -2800,18 +2800,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
45998
45999 uint32_t dm_next_uevent_seq(struct mapped_device *md)
46000 {
46001 - return atomic_add_return(1, &md->uevent_seq);
46002 + return atomic_add_return_unchecked(1, &md->uevent_seq);
46003 }
46004
46005 uint32_t dm_get_event_nr(struct mapped_device *md)
46006 {
46007 - return atomic_read(&md->event_nr);
46008 + return atomic_read_unchecked(&md->event_nr);
46009 }
46010
46011 int dm_wait_event(struct mapped_device *md, int event_nr)
46012 {
46013 return wait_event_interruptible(md->eventq,
46014 - (event_nr != atomic_read(&md->event_nr)));
46015 + (event_nr != atomic_read_unchecked(&md->event_nr)));
46016 }
46017
46018 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
46019 diff --git a/drivers/md/md.c b/drivers/md/md.c
46020 index 32fc19c..cb6eba3 100644
46021 --- a/drivers/md/md.c
46022 +++ b/drivers/md/md.c
46023 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
46024 * start build, activate spare
46025 */
46026 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
46027 -static atomic_t md_event_count;
46028 +static atomic_unchecked_t md_event_count;
46029 void md_new_event(struct mddev *mddev)
46030 {
46031 - atomic_inc(&md_event_count);
46032 + atomic_inc_unchecked(&md_event_count);
46033 wake_up(&md_event_waiters);
46034 }
46035 EXPORT_SYMBOL_GPL(md_new_event);
46036 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
46037 */
46038 static void md_new_event_inintr(struct mddev *mddev)
46039 {
46040 - atomic_inc(&md_event_count);
46041 + atomic_inc_unchecked(&md_event_count);
46042 wake_up(&md_event_waiters);
46043 }
46044
46045 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
46046 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
46047 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
46048 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
46049 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
46050 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
46051
46052 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
46053 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
46054 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
46055 else
46056 sb->resync_offset = cpu_to_le64(0);
46057
46058 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
46059 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
46060
46061 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
46062 sb->size = cpu_to_le64(mddev->dev_sectors);
46063 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
46064 static ssize_t
46065 errors_show(struct md_rdev *rdev, char *page)
46066 {
46067 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
46068 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
46069 }
46070
46071 static ssize_t
46072 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
46073 char *e;
46074 unsigned long n = simple_strtoul(buf, &e, 10);
46075 if (*buf && (*e == 0 || *e == '\n')) {
46076 - atomic_set(&rdev->corrected_errors, n);
46077 + atomic_set_unchecked(&rdev->corrected_errors, n);
46078 return len;
46079 }
46080 return -EINVAL;
46081 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
46082 rdev->sb_loaded = 0;
46083 rdev->bb_page = NULL;
46084 atomic_set(&rdev->nr_pending, 0);
46085 - atomic_set(&rdev->read_errors, 0);
46086 - atomic_set(&rdev->corrected_errors, 0);
46087 + atomic_set_unchecked(&rdev->read_errors, 0);
46088 + atomic_set_unchecked(&rdev->corrected_errors, 0);
46089
46090 INIT_LIST_HEAD(&rdev->same_set);
46091 init_waitqueue_head(&rdev->blocked_wait);
46092 @@ -7068,7 +7068,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
46093
46094 spin_unlock(&pers_lock);
46095 seq_printf(seq, "\n");
46096 - seq->poll_event = atomic_read(&md_event_count);
46097 + seq->poll_event = atomic_read_unchecked(&md_event_count);
46098 return 0;
46099 }
46100 if (v == (void*)2) {
46101 @@ -7171,7 +7171,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
46102 return error;
46103
46104 seq = file->private_data;
46105 - seq->poll_event = atomic_read(&md_event_count);
46106 + seq->poll_event = atomic_read_unchecked(&md_event_count);
46107 return error;
46108 }
46109
46110 @@ -7188,7 +7188,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
46111 /* always allow read */
46112 mask = POLLIN | POLLRDNORM;
46113
46114 - if (seq->poll_event != atomic_read(&md_event_count))
46115 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
46116 mask |= POLLERR | POLLPRI;
46117 return mask;
46118 }
46119 @@ -7232,7 +7232,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
46120 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
46121 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
46122 (int)part_stat_read(&disk->part0, sectors[1]) -
46123 - atomic_read(&disk->sync_io);
46124 + atomic_read_unchecked(&disk->sync_io);
46125 /* sync IO will cause sync_io to increase before the disk_stats
46126 * as sync_io is counted when a request starts, and
46127 * disk_stats is counted when it completes.
46128 diff --git a/drivers/md/md.h b/drivers/md/md.h
46129 index a49d991..3582bb7 100644
46130 --- a/drivers/md/md.h
46131 +++ b/drivers/md/md.h
46132 @@ -94,13 +94,13 @@ struct md_rdev {
46133 * only maintained for arrays that
46134 * support hot removal
46135 */
46136 - atomic_t read_errors; /* number of consecutive read errors that
46137 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
46138 * we have tried to ignore.
46139 */
46140 struct timespec last_read_error; /* monotonic time since our
46141 * last read error
46142 */
46143 - atomic_t corrected_errors; /* number of corrected read errors,
46144 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
46145 * for reporting to userspace and storing
46146 * in superblock.
46147 */
46148 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
46149
46150 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
46151 {
46152 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
46153 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
46154 }
46155
46156 struct md_personality
46157 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
46158 index 786b689..ea8c956 100644
46159 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
46160 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
46161 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
46162 * Flick into a mode where all blocks get allocated in the new area.
46163 */
46164 smm->begin = old_len;
46165 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
46166 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
46167
46168 /*
46169 * Extend.
46170 @@ -710,7 +710,7 @@ out:
46171 /*
46172 * Switch back to normal behaviour.
46173 */
46174 - memcpy(sm, &ops, sizeof(*sm));
46175 + memcpy((void *)sm, &ops, sizeof(*sm));
46176 return r;
46177 }
46178
46179 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
46180 index 3e6d115..ffecdeb 100644
46181 --- a/drivers/md/persistent-data/dm-space-map.h
46182 +++ b/drivers/md/persistent-data/dm-space-map.h
46183 @@ -71,6 +71,7 @@ struct dm_space_map {
46184 dm_sm_threshold_fn fn,
46185 void *context);
46186 };
46187 +typedef struct dm_space_map __no_const dm_space_map_no_const;
46188
46189 /*----------------------------------------------------------------*/
46190
46191 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
46192 index 56e24c0..e1c8e1f 100644
46193 --- a/drivers/md/raid1.c
46194 +++ b/drivers/md/raid1.c
46195 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
46196 if (r1_sync_page_io(rdev, sect, s,
46197 bio->bi_io_vec[idx].bv_page,
46198 READ) != 0)
46199 - atomic_add(s, &rdev->corrected_errors);
46200 + atomic_add_unchecked(s, &rdev->corrected_errors);
46201 }
46202 sectors -= s;
46203 sect += s;
46204 @@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
46205 test_bit(In_sync, &rdev->flags)) {
46206 if (r1_sync_page_io(rdev, sect, s,
46207 conf->tmppage, READ)) {
46208 - atomic_add(s, &rdev->corrected_errors);
46209 + atomic_add_unchecked(s, &rdev->corrected_errors);
46210 printk(KERN_INFO
46211 "md/raid1:%s: read error corrected "
46212 "(%d sectors at %llu on %s)\n",
46213 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
46214 index cb882aa..cb8aeca 100644
46215 --- a/drivers/md/raid10.c
46216 +++ b/drivers/md/raid10.c
46217 @@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
46218 /* The write handler will notice the lack of
46219 * R10BIO_Uptodate and record any errors etc
46220 */
46221 - atomic_add(r10_bio->sectors,
46222 + atomic_add_unchecked(r10_bio->sectors,
46223 &conf->mirrors[d].rdev->corrected_errors);
46224
46225 /* for reconstruct, we always reschedule after a read.
46226 @@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
46227 {
46228 struct timespec cur_time_mon;
46229 unsigned long hours_since_last;
46230 - unsigned int read_errors = atomic_read(&rdev->read_errors);
46231 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
46232
46233 ktime_get_ts(&cur_time_mon);
46234
46235 @@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
46236 * overflowing the shift of read_errors by hours_since_last.
46237 */
46238 if (hours_since_last >= 8 * sizeof(read_errors))
46239 - atomic_set(&rdev->read_errors, 0);
46240 + atomic_set_unchecked(&rdev->read_errors, 0);
46241 else
46242 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
46243 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
46244 }
46245
46246 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
46247 @@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46248 return;
46249
46250 check_decay_read_errors(mddev, rdev);
46251 - atomic_inc(&rdev->read_errors);
46252 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
46253 + atomic_inc_unchecked(&rdev->read_errors);
46254 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
46255 char b[BDEVNAME_SIZE];
46256 bdevname(rdev->bdev, b);
46257
46258 @@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46259 "md/raid10:%s: %s: Raid device exceeded "
46260 "read_error threshold [cur %d:max %d]\n",
46261 mdname(mddev), b,
46262 - atomic_read(&rdev->read_errors), max_read_errors);
46263 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
46264 printk(KERN_NOTICE
46265 "md/raid10:%s: %s: Failing raid device\n",
46266 mdname(mddev), b);
46267 @@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46268 sect +
46269 choose_data_offset(r10_bio, rdev)),
46270 bdevname(rdev->bdev, b));
46271 - atomic_add(s, &rdev->corrected_errors);
46272 + atomic_add_unchecked(s, &rdev->corrected_errors);
46273 }
46274
46275 rdev_dec_pending(rdev, mddev);
46276 @@ -2954,6 +2954,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr,
46277 */
46278 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) {
46279 end_reshape(conf);
46280 + close_sync(conf);
46281 return 0;
46282 }
46283
46284 @@ -4411,7 +4412,7 @@ read_more:
46285 read_bio->bi_private = r10_bio;
46286 read_bio->bi_end_io = end_sync_read;
46287 read_bio->bi_rw = READ;
46288 - read_bio->bi_flags &= ~(BIO_POOL_MASK - 1);
46289 + read_bio->bi_flags &= (~0UL << BIO_RESET_BITS);
46290 read_bio->bi_flags |= 1 << BIO_UPTODATE;
46291 read_bio->bi_vcnt = 0;
46292 read_bio->bi_iter.bi_size = 0;
46293 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
46294 index 6234b2e..4990801 100644
46295 --- a/drivers/md/raid5.c
46296 +++ b/drivers/md/raid5.c
46297 @@ -1731,6 +1731,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
46298 return 1;
46299 }
46300
46301 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46302 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
46303 +#endif
46304 +
46305 static int grow_stripes(struct r5conf *conf, int num)
46306 {
46307 struct kmem_cache *sc;
46308 @@ -1742,7 +1746,11 @@ static int grow_stripes(struct r5conf *conf, int num)
46309 "raid%d-%s", conf->level, mdname(conf->mddev));
46310 else
46311 sprintf(conf->cache_name[0],
46312 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46313 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
46314 +#else
46315 "raid%d-%p", conf->level, conf->mddev);
46316 +#endif
46317 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
46318
46319 conf->active_name = 0;
46320 @@ -2018,21 +2026,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
46321 mdname(conf->mddev), STRIPE_SECTORS,
46322 (unsigned long long)s,
46323 bdevname(rdev->bdev, b));
46324 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
46325 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
46326 clear_bit(R5_ReadError, &sh->dev[i].flags);
46327 clear_bit(R5_ReWrite, &sh->dev[i].flags);
46328 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
46329 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
46330
46331 - if (atomic_read(&rdev->read_errors))
46332 - atomic_set(&rdev->read_errors, 0);
46333 + if (atomic_read_unchecked(&rdev->read_errors))
46334 + atomic_set_unchecked(&rdev->read_errors, 0);
46335 } else {
46336 const char *bdn = bdevname(rdev->bdev, b);
46337 int retry = 0;
46338 int set_bad = 0;
46339
46340 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
46341 - atomic_inc(&rdev->read_errors);
46342 + atomic_inc_unchecked(&rdev->read_errors);
46343 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
46344 printk_ratelimited(
46345 KERN_WARNING
46346 @@ -2060,7 +2068,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
46347 mdname(conf->mddev),
46348 (unsigned long long)s,
46349 bdn);
46350 - } else if (atomic_read(&rdev->read_errors)
46351 + } else if (atomic_read_unchecked(&rdev->read_errors)
46352 > conf->max_nr_stripes)
46353 printk(KERN_WARNING
46354 "md/raid:%s: Too many read errors, failing device %s.\n",
46355 @@ -3817,6 +3825,8 @@ static void handle_stripe(struct stripe_head *sh)
46356 set_bit(R5_Wantwrite, &dev->flags);
46357 if (prexor)
46358 continue;
46359 + if (s.failed > 1)
46360 + continue;
46361 if (!test_bit(R5_Insync, &dev->flags) ||
46362 ((i == sh->pd_idx || i == sh->qd_idx) &&
46363 s.failed == 0))
46364 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
46365 index 983db75..ef9248c 100644
46366 --- a/drivers/media/dvb-core/dvbdev.c
46367 +++ b/drivers/media/dvb-core/dvbdev.c
46368 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
46369 const struct dvb_device *template, void *priv, int type)
46370 {
46371 struct dvb_device *dvbdev;
46372 - struct file_operations *dvbdevfops;
46373 + file_operations_no_const *dvbdevfops;
46374 struct device *clsdev;
46375 int minor;
46376 int id;
46377 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
46378 index 539f4db..cdd403b 100644
46379 --- a/drivers/media/dvb-frontends/af9033.h
46380 +++ b/drivers/media/dvb-frontends/af9033.h
46381 @@ -82,7 +82,7 @@ struct af9033_ops {
46382 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
46383 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
46384 int onoff);
46385 -};
46386 +} __no_const;
46387
46388
46389 #if IS_ENABLED(CONFIG_DVB_AF9033)
46390 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
46391 index 9b6c3bb..baeb5c7 100644
46392 --- a/drivers/media/dvb-frontends/dib3000.h
46393 +++ b/drivers/media/dvb-frontends/dib3000.h
46394 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
46395 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
46396 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
46397 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
46398 -};
46399 +} __no_const;
46400
46401 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
46402 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
46403 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
46404 index ed8cb90..5ef7f79 100644
46405 --- a/drivers/media/pci/cx88/cx88-video.c
46406 +++ b/drivers/media/pci/cx88/cx88-video.c
46407 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
46408
46409 /* ------------------------------------------------------------------ */
46410
46411 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46412 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46413 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46414 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46415 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46416 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46417
46418 module_param_array(video_nr, int, NULL, 0444);
46419 module_param_array(vbi_nr, int, NULL, 0444);
46420 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
46421 index 802642d..5534900 100644
46422 --- a/drivers/media/pci/ivtv/ivtv-driver.c
46423 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
46424 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
46425 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
46426
46427 /* ivtv instance counter */
46428 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
46429 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
46430
46431 /* Parameter declarations */
46432 static int cardtype[IVTV_MAX_CARDS];
46433 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
46434 index 9a726ea..f5e9b52 100644
46435 --- a/drivers/media/platform/omap/omap_vout.c
46436 +++ b/drivers/media/platform/omap/omap_vout.c
46437 @@ -63,7 +63,6 @@ enum omap_vout_channels {
46438 OMAP_VIDEO2,
46439 };
46440
46441 -static struct videobuf_queue_ops video_vbq_ops;
46442 /* Variables configurable through module params*/
46443 static u32 video1_numbuffers = 3;
46444 static u32 video2_numbuffers = 3;
46445 @@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
46446 {
46447 struct videobuf_queue *q;
46448 struct omap_vout_device *vout = NULL;
46449 + static struct videobuf_queue_ops video_vbq_ops = {
46450 + .buf_setup = omap_vout_buffer_setup,
46451 + .buf_prepare = omap_vout_buffer_prepare,
46452 + .buf_release = omap_vout_buffer_release,
46453 + .buf_queue = omap_vout_buffer_queue,
46454 + };
46455
46456 vout = video_drvdata(file);
46457 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
46458 @@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
46459 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
46460
46461 q = &vout->vbq;
46462 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
46463 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
46464 - video_vbq_ops.buf_release = omap_vout_buffer_release;
46465 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
46466 spin_lock_init(&vout->vbq_lock);
46467
46468 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
46469 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
46470 index fb2acc5..a2fcbdc4 100644
46471 --- a/drivers/media/platform/s5p-tv/mixer.h
46472 +++ b/drivers/media/platform/s5p-tv/mixer.h
46473 @@ -156,7 +156,7 @@ struct mxr_layer {
46474 /** layer index (unique identifier) */
46475 int idx;
46476 /** callbacks for layer methods */
46477 - struct mxr_layer_ops ops;
46478 + struct mxr_layer_ops *ops;
46479 /** format array */
46480 const struct mxr_format **fmt_array;
46481 /** size of format array */
46482 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46483 index 74344c7..a39e70e 100644
46484 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46485 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46486 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
46487 {
46488 struct mxr_layer *layer;
46489 int ret;
46490 - struct mxr_layer_ops ops = {
46491 + static struct mxr_layer_ops ops = {
46492 .release = mxr_graph_layer_release,
46493 .buffer_set = mxr_graph_buffer_set,
46494 .stream_set = mxr_graph_stream_set,
46495 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
46496 index b713403..53cb5ad 100644
46497 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
46498 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
46499 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
46500 layer->update_buf = next;
46501 }
46502
46503 - layer->ops.buffer_set(layer, layer->update_buf);
46504 + layer->ops->buffer_set(layer, layer->update_buf);
46505
46506 if (done && done != layer->shadow_buf)
46507 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
46508 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
46509 index 8a8dbc8..b74c62d 100644
46510 --- a/drivers/media/platform/s5p-tv/mixer_video.c
46511 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
46512 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
46513 layer->geo.src.height = layer->geo.src.full_height;
46514
46515 mxr_geometry_dump(mdev, &layer->geo);
46516 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46517 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46518 mxr_geometry_dump(mdev, &layer->geo);
46519 }
46520
46521 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
46522 layer->geo.dst.full_width = mbus_fmt.width;
46523 layer->geo.dst.full_height = mbus_fmt.height;
46524 layer->geo.dst.field = mbus_fmt.field;
46525 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46526 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46527
46528 mxr_geometry_dump(mdev, &layer->geo);
46529 }
46530 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
46531 /* set source size to highest accepted value */
46532 geo->src.full_width = max(geo->dst.full_width, pix->width);
46533 geo->src.full_height = max(geo->dst.full_height, pix->height);
46534 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46535 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46536 mxr_geometry_dump(mdev, &layer->geo);
46537 /* set cropping to total visible screen */
46538 geo->src.width = pix->width;
46539 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
46540 geo->src.x_offset = 0;
46541 geo->src.y_offset = 0;
46542 /* assure consistency of geometry */
46543 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
46544 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
46545 mxr_geometry_dump(mdev, &layer->geo);
46546 /* set full size to lowest possible value */
46547 geo->src.full_width = 0;
46548 geo->src.full_height = 0;
46549 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46550 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46551 mxr_geometry_dump(mdev, &layer->geo);
46552
46553 /* returning results */
46554 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
46555 target->width = s->r.width;
46556 target->height = s->r.height;
46557
46558 - layer->ops.fix_geometry(layer, stage, s->flags);
46559 + layer->ops->fix_geometry(layer, stage, s->flags);
46560
46561 /* retrieve update selection rectangle */
46562 res.left = target->x_offset;
46563 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
46564 mxr_output_get(mdev);
46565
46566 mxr_layer_update_output(layer);
46567 - layer->ops.format_set(layer);
46568 + layer->ops->format_set(layer);
46569 /* enabling layer in hardware */
46570 spin_lock_irqsave(&layer->enq_slock, flags);
46571 layer->state = MXR_LAYER_STREAMING;
46572 spin_unlock_irqrestore(&layer->enq_slock, flags);
46573
46574 - layer->ops.stream_set(layer, MXR_ENABLE);
46575 + layer->ops->stream_set(layer, MXR_ENABLE);
46576 mxr_streamer_get(mdev);
46577
46578 return 0;
46579 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
46580 spin_unlock_irqrestore(&layer->enq_slock, flags);
46581
46582 /* disabling layer in hardware */
46583 - layer->ops.stream_set(layer, MXR_DISABLE);
46584 + layer->ops->stream_set(layer, MXR_DISABLE);
46585 /* remove one streamer */
46586 mxr_streamer_put(mdev);
46587 /* allow changes in output configuration */
46588 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
46589
46590 void mxr_layer_release(struct mxr_layer *layer)
46591 {
46592 - if (layer->ops.release)
46593 - layer->ops.release(layer);
46594 + if (layer->ops->release)
46595 + layer->ops->release(layer);
46596 }
46597
46598 void mxr_base_layer_release(struct mxr_layer *layer)
46599 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
46600
46601 layer->mdev = mdev;
46602 layer->idx = idx;
46603 - layer->ops = *ops;
46604 + layer->ops = ops;
46605
46606 spin_lock_init(&layer->enq_slock);
46607 INIT_LIST_HEAD(&layer->enq_list);
46608 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46609 index c9388c4..ce71ece 100644
46610 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46611 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46612 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
46613 {
46614 struct mxr_layer *layer;
46615 int ret;
46616 - struct mxr_layer_ops ops = {
46617 + static struct mxr_layer_ops ops = {
46618 .release = mxr_vp_layer_release,
46619 .buffer_set = mxr_vp_buffer_set,
46620 .stream_set = mxr_vp_stream_set,
46621 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
46622 index d00bf3d..1301a0c 100644
46623 --- a/drivers/media/platform/vivi.c
46624 +++ b/drivers/media/platform/vivi.c
46625 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
46626 MODULE_LICENSE("Dual BSD/GPL");
46627 MODULE_VERSION(VIVI_VERSION);
46628
46629 -static unsigned video_nr = -1;
46630 -module_param(video_nr, uint, 0644);
46631 +static int video_nr = -1;
46632 +module_param(video_nr, int, 0644);
46633 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
46634
46635 static unsigned n_devs = 1;
46636 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
46637 index d719e59..63f3470 100644
46638 --- a/drivers/media/radio/radio-cadet.c
46639 +++ b/drivers/media/radio/radio-cadet.c
46640 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
46641 unsigned char readbuf[RDS_BUFFER];
46642 int i = 0;
46643
46644 + if (count > RDS_BUFFER)
46645 + return -EFAULT;
46646 mutex_lock(&dev->lock);
46647 if (dev->rdsstat == 0)
46648 cadet_start_rds(dev);
46649 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
46650 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
46651 mutex_unlock(&dev->lock);
46652
46653 - if (i && copy_to_user(data, readbuf, i))
46654 - return -EFAULT;
46655 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
46656 + i = -EFAULT;
46657 +
46658 return i;
46659 }
46660
46661 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
46662 index 5236035..c622c74 100644
46663 --- a/drivers/media/radio/radio-maxiradio.c
46664 +++ b/drivers/media/radio/radio-maxiradio.c
46665 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
46666 /* TEA5757 pin mappings */
46667 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
46668
46669 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
46670 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
46671
46672 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
46673 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
46674 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
46675 index 050b3bb..79f62b9 100644
46676 --- a/drivers/media/radio/radio-shark.c
46677 +++ b/drivers/media/radio/radio-shark.c
46678 @@ -79,7 +79,7 @@ struct shark_device {
46679 u32 last_val;
46680 };
46681
46682 -static atomic_t shark_instance = ATOMIC_INIT(0);
46683 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46684
46685 static void shark_write_val(struct snd_tea575x *tea, u32 val)
46686 {
46687 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
46688 index 8654e0d..0608a64 100644
46689 --- a/drivers/media/radio/radio-shark2.c
46690 +++ b/drivers/media/radio/radio-shark2.c
46691 @@ -74,7 +74,7 @@ struct shark_device {
46692 u8 *transfer_buffer;
46693 };
46694
46695 -static atomic_t shark_instance = ATOMIC_INIT(0);
46696 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46697
46698 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
46699 {
46700 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
46701 index 2fd9009..278cc1e 100644
46702 --- a/drivers/media/radio/radio-si476x.c
46703 +++ b/drivers/media/radio/radio-si476x.c
46704 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
46705 struct si476x_radio *radio;
46706 struct v4l2_ctrl *ctrl;
46707
46708 - static atomic_t instance = ATOMIC_INIT(0);
46709 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
46710
46711 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
46712 if (!radio)
46713 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
46714 index a1c641e..3007da9 100644
46715 --- a/drivers/media/usb/dvb-usb/cxusb.c
46716 +++ b/drivers/media/usb/dvb-usb/cxusb.c
46717 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
46718
46719 struct dib0700_adapter_state {
46720 int (*set_param_save) (struct dvb_frontend *);
46721 -};
46722 +} __no_const;
46723
46724 static int dib7070_set_param_override(struct dvb_frontend *fe)
46725 {
46726 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46727 index 733a7ff..f8b52e3 100644
46728 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46729 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46730 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
46731
46732 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
46733 {
46734 - struct hexline hx;
46735 - u8 reset;
46736 + struct hexline *hx;
46737 + u8 *reset;
46738 int ret,pos=0;
46739
46740 + reset = kmalloc(1, GFP_KERNEL);
46741 + if (reset == NULL)
46742 + return -ENOMEM;
46743 +
46744 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
46745 + if (hx == NULL) {
46746 + kfree(reset);
46747 + return -ENOMEM;
46748 + }
46749 +
46750 /* stop the CPU */
46751 - reset = 1;
46752 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
46753 + reset[0] = 1;
46754 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
46755 err("could not stop the USB controller CPU.");
46756
46757 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
46758 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
46759 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
46760 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
46761 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
46762 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
46763
46764 - if (ret != hx.len) {
46765 + if (ret != hx->len) {
46766 err("error while transferring firmware "
46767 "(transferred size: %d, block size: %d)",
46768 - ret,hx.len);
46769 + ret,hx->len);
46770 ret = -EINVAL;
46771 break;
46772 }
46773 }
46774 if (ret < 0) {
46775 err("firmware download failed at %d with %d",pos,ret);
46776 + kfree(reset);
46777 + kfree(hx);
46778 return ret;
46779 }
46780
46781 if (ret == 0) {
46782 /* restart the CPU */
46783 - reset = 0;
46784 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
46785 + reset[0] = 0;
46786 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
46787 err("could not restart the USB controller CPU.");
46788 ret = -EINVAL;
46789 }
46790 } else
46791 ret = -EIO;
46792
46793 + kfree(reset);
46794 + kfree(hx);
46795 +
46796 return ret;
46797 }
46798 EXPORT_SYMBOL(usb_cypress_load_firmware);
46799 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
46800 index ae0f56a..ec71784 100644
46801 --- a/drivers/media/usb/dvb-usb/dw2102.c
46802 +++ b/drivers/media/usb/dvb-usb/dw2102.c
46803 @@ -118,7 +118,7 @@ struct su3000_state {
46804
46805 struct s6x0_state {
46806 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
46807 -};
46808 +} __no_const;
46809
46810 /* debug */
46811 static int dvb_usb_dw2102_debug;
46812 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
46813 index d947e03..87fef42 100644
46814 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
46815 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
46816 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
46817 static int technisat_usb2_i2c_access(struct usb_device *udev,
46818 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
46819 {
46820 - u8 b[64];
46821 - int ret, actual_length;
46822 + u8 *b = kmalloc(64, GFP_KERNEL);
46823 + int ret, actual_length, error = 0;
46824 +
46825 + if (b == NULL)
46826 + return -ENOMEM;
46827
46828 deb_i2c("i2c-access: %02x, tx: ", device_addr);
46829 debug_dump(tx, txlen, deb_i2c);
46830 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46831
46832 if (ret < 0) {
46833 err("i2c-error: out failed %02x = %d", device_addr, ret);
46834 - return -ENODEV;
46835 + error = -ENODEV;
46836 + goto out;
46837 }
46838
46839 ret = usb_bulk_msg(udev,
46840 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46841 b, 64, &actual_length, 1000);
46842 if (ret < 0) {
46843 err("i2c-error: in failed %02x = %d", device_addr, ret);
46844 - return -ENODEV;
46845 + error = -ENODEV;
46846 + goto out;
46847 }
46848
46849 if (b[0] != I2C_STATUS_OK) {
46850 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46851 /* handle tuner-i2c-nak */
46852 if (!(b[0] == I2C_STATUS_NAK &&
46853 device_addr == 0x60
46854 - /* && device_is_technisat_usb2 */))
46855 - return -ENODEV;
46856 + /* && device_is_technisat_usb2 */)) {
46857 + error = -ENODEV;
46858 + goto out;
46859 + }
46860 }
46861
46862 deb_i2c("status: %d, ", b[0]);
46863 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46864
46865 deb_i2c("\n");
46866
46867 - return 0;
46868 +out:
46869 + kfree(b);
46870 + return error;
46871 }
46872
46873 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
46874 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46875 {
46876 int ret;
46877
46878 - u8 led[8] = {
46879 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46880 - 0
46881 - };
46882 + u8 *led = kzalloc(8, GFP_KERNEL);
46883 +
46884 + if (led == NULL)
46885 + return -ENOMEM;
46886
46887 if (disable_led_control && state != TECH_LED_OFF)
46888 return 0;
46889
46890 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
46891 +
46892 switch (state) {
46893 case TECH_LED_ON:
46894 led[1] = 0x82;
46895 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46896 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46897 USB_TYPE_VENDOR | USB_DIR_OUT,
46898 0, 0,
46899 - led, sizeof(led), 500);
46900 + led, 8, 500);
46901
46902 mutex_unlock(&d->i2c_mutex);
46903 +
46904 + kfree(led);
46905 +
46906 return ret;
46907 }
46908
46909 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46910 {
46911 int ret;
46912 - u8 b = 0;
46913 + u8 *b = kzalloc(1, GFP_KERNEL);
46914 +
46915 + if (b == NULL)
46916 + return -ENOMEM;
46917
46918 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46919 return -EAGAIN;
46920 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46921 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46922 USB_TYPE_VENDOR | USB_DIR_OUT,
46923 (red << 8) | green, 0,
46924 - &b, 1, 500);
46925 + b, 1, 500);
46926
46927 mutex_unlock(&d->i2c_mutex);
46928
46929 + kfree(b);
46930 +
46931 return ret;
46932 }
46933
46934 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46935 struct dvb_usb_device_description **desc, int *cold)
46936 {
46937 int ret;
46938 - u8 version[3];
46939 + u8 *version = kmalloc(3, GFP_KERNEL);
46940
46941 /* first select the interface */
46942 if (usb_set_interface(udev, 0, 1) != 0)
46943 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46944
46945 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46946
46947 + if (version == NULL)
46948 + return 0;
46949 +
46950 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46951 GET_VERSION_INFO_VENDOR_REQUEST,
46952 USB_TYPE_VENDOR | USB_DIR_IN,
46953 0, 0,
46954 - version, sizeof(version), 500);
46955 + version, 3, 500);
46956
46957 if (ret < 0)
46958 *cold = 1;
46959 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46960 *cold = 0;
46961 }
46962
46963 + kfree(version);
46964 +
46965 return 0;
46966 }
46967
46968 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46969
46970 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46971 {
46972 - u8 buf[62], *b;
46973 + u8 *buf, *b;
46974 int ret;
46975 struct ir_raw_event ev;
46976
46977 + buf = kmalloc(62, GFP_KERNEL);
46978 +
46979 + if (buf == NULL)
46980 + return -ENOMEM;
46981 +
46982 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46983 buf[1] = 0x08;
46984 buf[2] = 0x8f;
46985 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46986 GET_IR_DATA_VENDOR_REQUEST,
46987 USB_TYPE_VENDOR | USB_DIR_IN,
46988 0x8080, 0,
46989 - buf, sizeof(buf), 500);
46990 + buf, 62, 500);
46991
46992 unlock:
46993 mutex_unlock(&d->i2c_mutex);
46994
46995 - if (ret < 0)
46996 + if (ret < 0) {
46997 + kfree(buf);
46998 return ret;
46999 + }
47000
47001 - if (ret == 1)
47002 + if (ret == 1) {
47003 + kfree(buf);
47004 return 0; /* no key pressed */
47005 + }
47006
47007 /* decoding */
47008 b = buf+1;
47009 @@ -653,6 +686,8 @@ unlock:
47010
47011 ir_raw_event_handle(d->rc_dev);
47012
47013 + kfree(buf);
47014 +
47015 return 1;
47016 }
47017
47018 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47019 index 7e2411c..cef73ca 100644
47020 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47021 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47022 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
47023 __u32 reserved;
47024 };
47025
47026 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47027 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
47028 enum v4l2_memory memory)
47029 {
47030 void __user *up_pln;
47031 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47032 return 0;
47033 }
47034
47035 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47036 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
47037 enum v4l2_memory memory)
47038 {
47039 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
47040 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
47041 * by passing a very big num_planes value */
47042 uplane = compat_alloc_user_space(num_planes *
47043 sizeof(struct v4l2_plane));
47044 - kp->m.planes = uplane;
47045 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
47046
47047 while (--num_planes >= 0) {
47048 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
47049 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
47050 if (num_planes == 0)
47051 return 0;
47052
47053 - uplane = kp->m.planes;
47054 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
47055 if (get_user(p, &up->m.planes))
47056 return -EFAULT;
47057 uplane32 = compat_ptr(p);
47058 @@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
47059 get_user(kp->capability, &up->capability) ||
47060 get_user(kp->flags, &up->flags))
47061 return -EFAULT;
47062 - kp->base = compat_ptr(tmp);
47063 + kp->base = (void __force_kernel *)compat_ptr(tmp);
47064 get_v4l2_pix_format(&kp->fmt, &up->fmt);
47065 return 0;
47066 }
47067 @@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
47068 n * sizeof(struct v4l2_ext_control32)))
47069 return -EFAULT;
47070 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
47071 - kp->controls = kcontrols;
47072 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
47073 while (--n >= 0) {
47074 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
47075 return -EFAULT;
47076 @@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
47077 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
47078 {
47079 struct v4l2_ext_control32 __user *ucontrols;
47080 - struct v4l2_ext_control __user *kcontrols = kp->controls;
47081 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
47082 int n = kp->count;
47083 compat_caddr_t p;
47084
47085 @@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
47086 put_user(kp->start_block, &up->start_block) ||
47087 put_user(kp->blocks, &up->blocks) ||
47088 put_user(tmp, &up->edid) ||
47089 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
47090 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
47091 return -EFAULT;
47092 return 0;
47093 }
47094 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
47095 index 55c6832..a91c7a6 100644
47096 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
47097 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
47098 @@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
47099 return 0;
47100
47101 case V4L2_CTRL_TYPE_STRING:
47102 - len = strlen(c->string);
47103 - if (len < ctrl->minimum)
47104 + len = strlen_user(c->string);
47105 + if (!len || len < ctrl->minimum)
47106 return -ERANGE;
47107 if ((len - ctrl->minimum) % ctrl->step)
47108 return -ERANGE;
47109 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
47110 index 015f92a..59e311e 100644
47111 --- a/drivers/media/v4l2-core/v4l2-device.c
47112 +++ b/drivers/media/v4l2-core/v4l2-device.c
47113 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
47114 EXPORT_SYMBOL_GPL(v4l2_device_put);
47115
47116 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
47117 - atomic_t *instance)
47118 + atomic_unchecked_t *instance)
47119 {
47120 - int num = atomic_inc_return(instance) - 1;
47121 + int num = atomic_inc_return_unchecked(instance) - 1;
47122 int len = strlen(basename);
47123
47124 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
47125 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
47126 index 16bffd8..3ab516a 100644
47127 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
47128 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
47129 @@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
47130 struct file *file, void *fh, void *p);
47131 } u;
47132 void (*debug)(const void *arg, bool write_only);
47133 -};
47134 +} __do_const;
47135 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
47136
47137 /* This control needs a priority check */
47138 #define INFO_FL_PRIO (1 << 0)
47139 @@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
47140 struct video_device *vfd = video_devdata(file);
47141 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
47142 bool write_only = false;
47143 - struct v4l2_ioctl_info default_info;
47144 + v4l2_ioctl_info_no_const default_info;
47145 const struct v4l2_ioctl_info *info;
47146 void *fh = file->private_data;
47147 struct v4l2_fh *vfh = NULL;
47148 @@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47149 ret = -EINVAL;
47150 break;
47151 }
47152 - *user_ptr = (void __user *)buf->m.planes;
47153 + *user_ptr = (void __force_user *)buf->m.planes;
47154 *kernel_ptr = (void **)&buf->m.planes;
47155 *array_size = sizeof(struct v4l2_plane) * buf->length;
47156 ret = 1;
47157 @@ -2293,7 +2294,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47158 ret = -EINVAL;
47159 break;
47160 }
47161 - *user_ptr = (void __user *)edid->edid;
47162 + *user_ptr = (void __force_user *)edid->edid;
47163 *kernel_ptr = (void **)&edid->edid;
47164 *array_size = edid->blocks * 128;
47165 ret = 1;
47166 @@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47167 ret = -EINVAL;
47168 break;
47169 }
47170 - *user_ptr = (void __user *)ctrls->controls;
47171 + *user_ptr = (void __force_user *)ctrls->controls;
47172 *kernel_ptr = (void **)&ctrls->controls;
47173 *array_size = sizeof(struct v4l2_ext_control)
47174 * ctrls->count;
47175 @@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
47176 }
47177
47178 if (has_array_args) {
47179 - *kernel_ptr = (void __force *)user_ptr;
47180 + *kernel_ptr = (void __force_kernel *)user_ptr;
47181 if (copy_to_user(user_ptr, mbuf, array_size))
47182 err = -EFAULT;
47183 goto out_array_args;
47184 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
47185 index ebc0af7..baed058 100644
47186 --- a/drivers/message/fusion/mptbase.c
47187 +++ b/drivers/message/fusion/mptbase.c
47188 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
47189 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
47190 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
47191
47192 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47193 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
47194 +#else
47195 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
47196 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
47197 +#endif
47198 +
47199 /*
47200 * Rounding UP to nearest 4-kB boundary here...
47201 */
47202 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
47203 ioc->facts.GlobalCredits);
47204
47205 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
47206 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47207 + NULL, NULL);
47208 +#else
47209 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
47210 +#endif
47211 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
47212 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
47213 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
47214 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
47215 index 711fcb5..5da1fb0 100644
47216 --- a/drivers/message/fusion/mptsas.c
47217 +++ b/drivers/message/fusion/mptsas.c
47218 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
47219 return 0;
47220 }
47221
47222 +static inline void
47223 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
47224 +{
47225 + if (phy_info->port_details) {
47226 + phy_info->port_details->rphy = rphy;
47227 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
47228 + ioc->name, rphy));
47229 + }
47230 +
47231 + if (rphy) {
47232 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
47233 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
47234 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
47235 + ioc->name, rphy, rphy->dev.release));
47236 + }
47237 +}
47238 +
47239 /* no mutex */
47240 static void
47241 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
47242 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
47243 return NULL;
47244 }
47245
47246 -static inline void
47247 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
47248 -{
47249 - if (phy_info->port_details) {
47250 - phy_info->port_details->rphy = rphy;
47251 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
47252 - ioc->name, rphy));
47253 - }
47254 -
47255 - if (rphy) {
47256 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
47257 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
47258 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
47259 - ioc->name, rphy, rphy->dev.release));
47260 - }
47261 -}
47262 -
47263 static inline struct sas_port *
47264 mptsas_get_port(struct mptsas_phyinfo *phy_info)
47265 {
47266 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
47267 index 2a1c6f2..a04c6a2 100644
47268 --- a/drivers/message/fusion/mptscsih.c
47269 +++ b/drivers/message/fusion/mptscsih.c
47270 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
47271
47272 h = shost_priv(SChost);
47273
47274 - if (h) {
47275 - if (h->info_kbuf == NULL)
47276 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
47277 - return h->info_kbuf;
47278 - h->info_kbuf[0] = '\0';
47279 + if (!h)
47280 + return NULL;
47281
47282 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
47283 - h->info_kbuf[size-1] = '\0';
47284 - }
47285 + if (h->info_kbuf == NULL)
47286 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
47287 + return h->info_kbuf;
47288 + h->info_kbuf[0] = '\0';
47289 +
47290 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
47291 + h->info_kbuf[size-1] = '\0';
47292
47293 return h->info_kbuf;
47294 }
47295 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
47296 index b7d87cd..3fb36da 100644
47297 --- a/drivers/message/i2o/i2o_proc.c
47298 +++ b/drivers/message/i2o/i2o_proc.c
47299 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
47300 "Array Controller Device"
47301 };
47302
47303 -static char *chtostr(char *tmp, u8 *chars, int n)
47304 -{
47305 - tmp[0] = 0;
47306 - return strncat(tmp, (char *)chars, n);
47307 -}
47308 -
47309 static int i2o_report_query_status(struct seq_file *seq, int block_status,
47310 char *group)
47311 {
47312 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
47313 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
47314 {
47315 struct i2o_controller *c = (struct i2o_controller *)seq->private;
47316 - static u32 work32[5];
47317 - static u8 *work8 = (u8 *) work32;
47318 - static u16 *work16 = (u16 *) work32;
47319 + u32 work32[5];
47320 + u8 *work8 = (u8 *) work32;
47321 + u16 *work16 = (u16 *) work32;
47322 int token;
47323 u32 hwcap;
47324
47325 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47326 } *result;
47327
47328 i2o_exec_execute_ddm_table ddm_table;
47329 - char tmp[28 + 1];
47330
47331 result = kmalloc(sizeof(*result), GFP_KERNEL);
47332 if (!result)
47333 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47334
47335 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
47336 seq_printf(seq, "%-#8x", ddm_table.module_id);
47337 - seq_printf(seq, "%-29s",
47338 - chtostr(tmp, ddm_table.module_name_version, 28));
47339 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
47340 seq_printf(seq, "%9d ", ddm_table.data_size);
47341 seq_printf(seq, "%8d", ddm_table.code_size);
47342
47343 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47344
47345 i2o_driver_result_table *result;
47346 i2o_driver_store_table *dst;
47347 - char tmp[28 + 1];
47348
47349 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
47350 if (result == NULL)
47351 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47352
47353 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
47354 seq_printf(seq, "%-#8x", dst->module_id);
47355 - seq_printf(seq, "%-29s",
47356 - chtostr(tmp, dst->module_name_version, 28));
47357 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
47358 + seq_printf(seq, "%-.28s", dst->module_name_version);
47359 + seq_printf(seq, "%-.8s", dst->date);
47360 seq_printf(seq, "%8d ", dst->module_size);
47361 seq_printf(seq, "%8d ", dst->mpb_size);
47362 seq_printf(seq, "0x%04x", dst->module_flags);
47363 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
47364 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47365 {
47366 struct i2o_device *d = (struct i2o_device *)seq->private;
47367 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47368 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47369 // == (allow) 512d bytes (max)
47370 - static u16 *work16 = (u16 *) work32;
47371 + u16 *work16 = (u16 *) work32;
47372 int token;
47373 - char tmp[16 + 1];
47374
47375 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
47376
47377 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47378 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
47379 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
47380 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
47381 - seq_printf(seq, "Vendor info : %s\n",
47382 - chtostr(tmp, (u8 *) (work32 + 2), 16));
47383 - seq_printf(seq, "Product info : %s\n",
47384 - chtostr(tmp, (u8 *) (work32 + 6), 16));
47385 - seq_printf(seq, "Description : %s\n",
47386 - chtostr(tmp, (u8 *) (work32 + 10), 16));
47387 - seq_printf(seq, "Product rev. : %s\n",
47388 - chtostr(tmp, (u8 *) (work32 + 14), 8));
47389 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
47390 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
47391 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
47392 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
47393
47394 seq_printf(seq, "Serial number : ");
47395 print_serial_number(seq, (u8 *) (work32 + 16),
47396 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47397 u8 pad[256]; // allow up to 256 byte (max) serial number
47398 } result;
47399
47400 - char tmp[24 + 1];
47401 -
47402 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
47403
47404 if (token < 0) {
47405 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47406 }
47407
47408 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
47409 - seq_printf(seq, "Module name : %s\n",
47410 - chtostr(tmp, result.module_name, 24));
47411 - seq_printf(seq, "Module revision : %s\n",
47412 - chtostr(tmp, result.module_rev, 8));
47413 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
47414 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
47415
47416 seq_printf(seq, "Serial number : ");
47417 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
47418 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47419 u8 instance_number[4];
47420 } result;
47421
47422 - char tmp[64 + 1];
47423 -
47424 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
47425
47426 if (token < 0) {
47427 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47428 return 0;
47429 }
47430
47431 - seq_printf(seq, "Device name : %s\n",
47432 - chtostr(tmp, result.device_name, 64));
47433 - seq_printf(seq, "Service name : %s\n",
47434 - chtostr(tmp, result.service_name, 64));
47435 - seq_printf(seq, "Physical name : %s\n",
47436 - chtostr(tmp, result.physical_location, 64));
47437 - seq_printf(seq, "Instance number : %s\n",
47438 - chtostr(tmp, result.instance_number, 4));
47439 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
47440 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
47441 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
47442 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
47443
47444 return 0;
47445 }
47446 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47447 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
47448 {
47449 struct i2o_device *d = (struct i2o_device *)seq->private;
47450 - static u32 work32[12];
47451 - static u16 *work16 = (u16 *) work32;
47452 - static u8 *work8 = (u8 *) work32;
47453 + u32 work32[12];
47454 + u16 *work16 = (u16 *) work32;
47455 + u8 *work8 = (u8 *) work32;
47456 int token;
47457
47458 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
47459 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
47460 index 92752fb..a7494f6 100644
47461 --- a/drivers/message/i2o/iop.c
47462 +++ b/drivers/message/i2o/iop.c
47463 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
47464
47465 spin_lock_irqsave(&c->context_list_lock, flags);
47466
47467 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
47468 - atomic_inc(&c->context_list_counter);
47469 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
47470 + atomic_inc_unchecked(&c->context_list_counter);
47471
47472 - entry->context = atomic_read(&c->context_list_counter);
47473 + entry->context = atomic_read_unchecked(&c->context_list_counter);
47474
47475 list_add(&entry->list, &c->context_list);
47476
47477 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
47478
47479 #if BITS_PER_LONG == 64
47480 spin_lock_init(&c->context_list_lock);
47481 - atomic_set(&c->context_list_counter, 0);
47482 + atomic_set_unchecked(&c->context_list_counter, 0);
47483 INIT_LIST_HEAD(&c->context_list);
47484 #endif
47485
47486 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
47487 index d1a22aa..d0f7bf7 100644
47488 --- a/drivers/mfd/ab8500-debugfs.c
47489 +++ b/drivers/mfd/ab8500-debugfs.c
47490 @@ -100,7 +100,7 @@ static int irq_last;
47491 static u32 *irq_count;
47492 static int num_irqs;
47493
47494 -static struct device_attribute **dev_attr;
47495 +static device_attribute_no_const **dev_attr;
47496 static char **event_name;
47497
47498 static u8 avg_sample = SAMPLE_16;
47499 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
47500 index a83eed5..62a58a9 100644
47501 --- a/drivers/mfd/max8925-i2c.c
47502 +++ b/drivers/mfd/max8925-i2c.c
47503 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
47504 const struct i2c_device_id *id)
47505 {
47506 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
47507 - static struct max8925_chip *chip;
47508 + struct max8925_chip *chip;
47509 struct device_node *node = client->dev.of_node;
47510
47511 if (node && !pdata) {
47512 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
47513 index f9e42ea..614d240 100644
47514 --- a/drivers/mfd/tps65910.c
47515 +++ b/drivers/mfd/tps65910.c
47516 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
47517 struct tps65910_platform_data *pdata)
47518 {
47519 int ret = 0;
47520 - static struct regmap_irq_chip *tps6591x_irqs_chip;
47521 + struct regmap_irq_chip *tps6591x_irqs_chip;
47522
47523 if (!irq) {
47524 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
47525 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
47526 index 596b1f6..5b6ab74 100644
47527 --- a/drivers/mfd/twl4030-irq.c
47528 +++ b/drivers/mfd/twl4030-irq.c
47529 @@ -34,6 +34,7 @@
47530 #include <linux/of.h>
47531 #include <linux/irqdomain.h>
47532 #include <linux/i2c/twl.h>
47533 +#include <asm/pgtable.h>
47534
47535 #include "twl-core.h"
47536
47537 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
47538 * Install an irq handler for each of the SIH modules;
47539 * clone dummy irq_chip since PIH can't *do* anything
47540 */
47541 - twl4030_irq_chip = dummy_irq_chip;
47542 - twl4030_irq_chip.name = "twl4030";
47543 + pax_open_kernel();
47544 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
47545 + *(const char **)&twl4030_irq_chip.name = "twl4030";
47546
47547 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47548 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47549 + pax_close_kernel();
47550
47551 for (i = irq_base; i < irq_end; i++) {
47552 irq_set_chip_and_handler(i, &twl4030_irq_chip,
47553 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
47554 index 464419b..64bae8d 100644
47555 --- a/drivers/misc/c2port/core.c
47556 +++ b/drivers/misc/c2port/core.c
47557 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
47558 goto error_idr_alloc;
47559 c2dev->id = ret;
47560
47561 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47562 + pax_open_kernel();
47563 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47564 + pax_close_kernel();
47565
47566 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
47567 "c2port%d", c2dev->id);
47568 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
47569 index 3f2b625..945e179 100644
47570 --- a/drivers/misc/eeprom/sunxi_sid.c
47571 +++ b/drivers/misc/eeprom/sunxi_sid.c
47572 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
47573
47574 platform_set_drvdata(pdev, sid_data);
47575
47576 - sid_bin_attr.size = sid_data->keysize;
47577 + pax_open_kernel();
47578 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
47579 + pax_close_kernel();
47580 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
47581 return -ENODEV;
47582
47583 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
47584 index 36f5d52..32311c3 100644
47585 --- a/drivers/misc/kgdbts.c
47586 +++ b/drivers/misc/kgdbts.c
47587 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
47588 char before[BREAK_INSTR_SIZE];
47589 char after[BREAK_INSTR_SIZE];
47590
47591 - probe_kernel_read(before, (char *)kgdbts_break_test,
47592 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
47593 BREAK_INSTR_SIZE);
47594 init_simple_test();
47595 ts.tst = plant_and_detach_test;
47596 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
47597 /* Activate test with initial breakpoint */
47598 if (!is_early)
47599 kgdb_breakpoint();
47600 - probe_kernel_read(after, (char *)kgdbts_break_test,
47601 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
47602 BREAK_INSTR_SIZE);
47603 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
47604 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
47605 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
47606 index 3ef4627..8d00486 100644
47607 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
47608 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
47609 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
47610 * the lid is closed. This leads to interrupts as soon as a little move
47611 * is done.
47612 */
47613 - atomic_inc(&lis3->count);
47614 + atomic_inc_unchecked(&lis3->count);
47615
47616 wake_up_interruptible(&lis3->misc_wait);
47617 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
47618 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
47619 if (lis3->pm_dev)
47620 pm_runtime_get_sync(lis3->pm_dev);
47621
47622 - atomic_set(&lis3->count, 0);
47623 + atomic_set_unchecked(&lis3->count, 0);
47624 return 0;
47625 }
47626
47627 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
47628 add_wait_queue(&lis3->misc_wait, &wait);
47629 while (true) {
47630 set_current_state(TASK_INTERRUPTIBLE);
47631 - data = atomic_xchg(&lis3->count, 0);
47632 + data = atomic_xchg_unchecked(&lis3->count, 0);
47633 if (data)
47634 break;
47635
47636 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
47637 struct lis3lv02d, miscdev);
47638
47639 poll_wait(file, &lis3->misc_wait, wait);
47640 - if (atomic_read(&lis3->count))
47641 + if (atomic_read_unchecked(&lis3->count))
47642 return POLLIN | POLLRDNORM;
47643 return 0;
47644 }
47645 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
47646 index c439c82..1f20f57 100644
47647 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
47648 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
47649 @@ -297,7 +297,7 @@ struct lis3lv02d {
47650 struct input_polled_dev *idev; /* input device */
47651 struct platform_device *pdev; /* platform device */
47652 struct regulator_bulk_data regulators[2];
47653 - atomic_t count; /* interrupt count after last read */
47654 + atomic_unchecked_t count; /* interrupt count after last read */
47655 union axis_conversion ac; /* hw -> logical axis */
47656 int mapped_btns[3];
47657
47658 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
47659 index 2f30bad..c4c13d0 100644
47660 --- a/drivers/misc/sgi-gru/gruhandles.c
47661 +++ b/drivers/misc/sgi-gru/gruhandles.c
47662 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
47663 unsigned long nsec;
47664
47665 nsec = CLKS2NSEC(clks);
47666 - atomic_long_inc(&mcs_op_statistics[op].count);
47667 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
47668 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
47669 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
47670 if (mcs_op_statistics[op].max < nsec)
47671 mcs_op_statistics[op].max = nsec;
47672 }
47673 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
47674 index 4f76359..cdfcb2e 100644
47675 --- a/drivers/misc/sgi-gru/gruprocfs.c
47676 +++ b/drivers/misc/sgi-gru/gruprocfs.c
47677 @@ -32,9 +32,9 @@
47678
47679 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
47680
47681 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
47682 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
47683 {
47684 - unsigned long val = atomic_long_read(v);
47685 + unsigned long val = atomic_long_read_unchecked(v);
47686
47687 seq_printf(s, "%16lu %s\n", val, id);
47688 }
47689 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
47690
47691 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
47692 for (op = 0; op < mcsop_last; op++) {
47693 - count = atomic_long_read(&mcs_op_statistics[op].count);
47694 - total = atomic_long_read(&mcs_op_statistics[op].total);
47695 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
47696 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
47697 max = mcs_op_statistics[op].max;
47698 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
47699 count ? total / count : 0, max);
47700 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
47701 index 5c3ce24..4915ccb 100644
47702 --- a/drivers/misc/sgi-gru/grutables.h
47703 +++ b/drivers/misc/sgi-gru/grutables.h
47704 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
47705 * GRU statistics.
47706 */
47707 struct gru_stats_s {
47708 - atomic_long_t vdata_alloc;
47709 - atomic_long_t vdata_free;
47710 - atomic_long_t gts_alloc;
47711 - atomic_long_t gts_free;
47712 - atomic_long_t gms_alloc;
47713 - atomic_long_t gms_free;
47714 - atomic_long_t gts_double_allocate;
47715 - atomic_long_t assign_context;
47716 - atomic_long_t assign_context_failed;
47717 - atomic_long_t free_context;
47718 - atomic_long_t load_user_context;
47719 - atomic_long_t load_kernel_context;
47720 - atomic_long_t lock_kernel_context;
47721 - atomic_long_t unlock_kernel_context;
47722 - atomic_long_t steal_user_context;
47723 - atomic_long_t steal_kernel_context;
47724 - atomic_long_t steal_context_failed;
47725 - atomic_long_t nopfn;
47726 - atomic_long_t asid_new;
47727 - atomic_long_t asid_next;
47728 - atomic_long_t asid_wrap;
47729 - atomic_long_t asid_reuse;
47730 - atomic_long_t intr;
47731 - atomic_long_t intr_cbr;
47732 - atomic_long_t intr_tfh;
47733 - atomic_long_t intr_spurious;
47734 - atomic_long_t intr_mm_lock_failed;
47735 - atomic_long_t call_os;
47736 - atomic_long_t call_os_wait_queue;
47737 - atomic_long_t user_flush_tlb;
47738 - atomic_long_t user_unload_context;
47739 - atomic_long_t user_exception;
47740 - atomic_long_t set_context_option;
47741 - atomic_long_t check_context_retarget_intr;
47742 - atomic_long_t check_context_unload;
47743 - atomic_long_t tlb_dropin;
47744 - atomic_long_t tlb_preload_page;
47745 - atomic_long_t tlb_dropin_fail_no_asid;
47746 - atomic_long_t tlb_dropin_fail_upm;
47747 - atomic_long_t tlb_dropin_fail_invalid;
47748 - atomic_long_t tlb_dropin_fail_range_active;
47749 - atomic_long_t tlb_dropin_fail_idle;
47750 - atomic_long_t tlb_dropin_fail_fmm;
47751 - atomic_long_t tlb_dropin_fail_no_exception;
47752 - atomic_long_t tfh_stale_on_fault;
47753 - atomic_long_t mmu_invalidate_range;
47754 - atomic_long_t mmu_invalidate_page;
47755 - atomic_long_t flush_tlb;
47756 - atomic_long_t flush_tlb_gru;
47757 - atomic_long_t flush_tlb_gru_tgh;
47758 - atomic_long_t flush_tlb_gru_zero_asid;
47759 + atomic_long_unchecked_t vdata_alloc;
47760 + atomic_long_unchecked_t vdata_free;
47761 + atomic_long_unchecked_t gts_alloc;
47762 + atomic_long_unchecked_t gts_free;
47763 + atomic_long_unchecked_t gms_alloc;
47764 + atomic_long_unchecked_t gms_free;
47765 + atomic_long_unchecked_t gts_double_allocate;
47766 + atomic_long_unchecked_t assign_context;
47767 + atomic_long_unchecked_t assign_context_failed;
47768 + atomic_long_unchecked_t free_context;
47769 + atomic_long_unchecked_t load_user_context;
47770 + atomic_long_unchecked_t load_kernel_context;
47771 + atomic_long_unchecked_t lock_kernel_context;
47772 + atomic_long_unchecked_t unlock_kernel_context;
47773 + atomic_long_unchecked_t steal_user_context;
47774 + atomic_long_unchecked_t steal_kernel_context;
47775 + atomic_long_unchecked_t steal_context_failed;
47776 + atomic_long_unchecked_t nopfn;
47777 + atomic_long_unchecked_t asid_new;
47778 + atomic_long_unchecked_t asid_next;
47779 + atomic_long_unchecked_t asid_wrap;
47780 + atomic_long_unchecked_t asid_reuse;
47781 + atomic_long_unchecked_t intr;
47782 + atomic_long_unchecked_t intr_cbr;
47783 + atomic_long_unchecked_t intr_tfh;
47784 + atomic_long_unchecked_t intr_spurious;
47785 + atomic_long_unchecked_t intr_mm_lock_failed;
47786 + atomic_long_unchecked_t call_os;
47787 + atomic_long_unchecked_t call_os_wait_queue;
47788 + atomic_long_unchecked_t user_flush_tlb;
47789 + atomic_long_unchecked_t user_unload_context;
47790 + atomic_long_unchecked_t user_exception;
47791 + atomic_long_unchecked_t set_context_option;
47792 + atomic_long_unchecked_t check_context_retarget_intr;
47793 + atomic_long_unchecked_t check_context_unload;
47794 + atomic_long_unchecked_t tlb_dropin;
47795 + atomic_long_unchecked_t tlb_preload_page;
47796 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
47797 + atomic_long_unchecked_t tlb_dropin_fail_upm;
47798 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
47799 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
47800 + atomic_long_unchecked_t tlb_dropin_fail_idle;
47801 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
47802 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
47803 + atomic_long_unchecked_t tfh_stale_on_fault;
47804 + atomic_long_unchecked_t mmu_invalidate_range;
47805 + atomic_long_unchecked_t mmu_invalidate_page;
47806 + atomic_long_unchecked_t flush_tlb;
47807 + atomic_long_unchecked_t flush_tlb_gru;
47808 + atomic_long_unchecked_t flush_tlb_gru_tgh;
47809 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
47810
47811 - atomic_long_t copy_gpa;
47812 - atomic_long_t read_gpa;
47813 + atomic_long_unchecked_t copy_gpa;
47814 + atomic_long_unchecked_t read_gpa;
47815
47816 - atomic_long_t mesq_receive;
47817 - atomic_long_t mesq_receive_none;
47818 - atomic_long_t mesq_send;
47819 - atomic_long_t mesq_send_failed;
47820 - atomic_long_t mesq_noop;
47821 - atomic_long_t mesq_send_unexpected_error;
47822 - atomic_long_t mesq_send_lb_overflow;
47823 - atomic_long_t mesq_send_qlimit_reached;
47824 - atomic_long_t mesq_send_amo_nacked;
47825 - atomic_long_t mesq_send_put_nacked;
47826 - atomic_long_t mesq_page_overflow;
47827 - atomic_long_t mesq_qf_locked;
47828 - atomic_long_t mesq_qf_noop_not_full;
47829 - atomic_long_t mesq_qf_switch_head_failed;
47830 - atomic_long_t mesq_qf_unexpected_error;
47831 - atomic_long_t mesq_noop_unexpected_error;
47832 - atomic_long_t mesq_noop_lb_overflow;
47833 - atomic_long_t mesq_noop_qlimit_reached;
47834 - atomic_long_t mesq_noop_amo_nacked;
47835 - atomic_long_t mesq_noop_put_nacked;
47836 - atomic_long_t mesq_noop_page_overflow;
47837 + atomic_long_unchecked_t mesq_receive;
47838 + atomic_long_unchecked_t mesq_receive_none;
47839 + atomic_long_unchecked_t mesq_send;
47840 + atomic_long_unchecked_t mesq_send_failed;
47841 + atomic_long_unchecked_t mesq_noop;
47842 + atomic_long_unchecked_t mesq_send_unexpected_error;
47843 + atomic_long_unchecked_t mesq_send_lb_overflow;
47844 + atomic_long_unchecked_t mesq_send_qlimit_reached;
47845 + atomic_long_unchecked_t mesq_send_amo_nacked;
47846 + atomic_long_unchecked_t mesq_send_put_nacked;
47847 + atomic_long_unchecked_t mesq_page_overflow;
47848 + atomic_long_unchecked_t mesq_qf_locked;
47849 + atomic_long_unchecked_t mesq_qf_noop_not_full;
47850 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
47851 + atomic_long_unchecked_t mesq_qf_unexpected_error;
47852 + atomic_long_unchecked_t mesq_noop_unexpected_error;
47853 + atomic_long_unchecked_t mesq_noop_lb_overflow;
47854 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
47855 + atomic_long_unchecked_t mesq_noop_amo_nacked;
47856 + atomic_long_unchecked_t mesq_noop_put_nacked;
47857 + atomic_long_unchecked_t mesq_noop_page_overflow;
47858
47859 };
47860
47861 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
47862 tghop_invalidate, mcsop_last};
47863
47864 struct mcs_op_statistic {
47865 - atomic_long_t count;
47866 - atomic_long_t total;
47867 + atomic_long_unchecked_t count;
47868 + atomic_long_unchecked_t total;
47869 unsigned long max;
47870 };
47871
47872 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
47873
47874 #define STAT(id) do { \
47875 if (gru_options & OPT_STATS) \
47876 - atomic_long_inc(&gru_stats.id); \
47877 + atomic_long_inc_unchecked(&gru_stats.id); \
47878 } while (0)
47879
47880 #ifdef CONFIG_SGI_GRU_DEBUG
47881 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
47882 index c862cd4..0d176fe 100644
47883 --- a/drivers/misc/sgi-xp/xp.h
47884 +++ b/drivers/misc/sgi-xp/xp.h
47885 @@ -288,7 +288,7 @@ struct xpc_interface {
47886 xpc_notify_func, void *);
47887 void (*received) (short, int, void *);
47888 enum xp_retval (*partid_to_nasids) (short, void *);
47889 -};
47890 +} __no_const;
47891
47892 extern struct xpc_interface xpc_interface;
47893
47894 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
47895 index 01be66d..e3a0c7e 100644
47896 --- a/drivers/misc/sgi-xp/xp_main.c
47897 +++ b/drivers/misc/sgi-xp/xp_main.c
47898 @@ -78,13 +78,13 @@ xpc_notloaded(void)
47899 }
47900
47901 struct xpc_interface xpc_interface = {
47902 - (void (*)(int))xpc_notloaded,
47903 - (void (*)(int))xpc_notloaded,
47904 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47905 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47906 + .connect = (void (*)(int))xpc_notloaded,
47907 + .disconnect = (void (*)(int))xpc_notloaded,
47908 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47909 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47910 void *))xpc_notloaded,
47911 - (void (*)(short, int, void *))xpc_notloaded,
47912 - (enum xp_retval(*)(short, void *))xpc_notloaded
47913 + .received = (void (*)(short, int, void *))xpc_notloaded,
47914 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
47915 };
47916 EXPORT_SYMBOL_GPL(xpc_interface);
47917
47918 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
47919 index b94d5f7..7f494c5 100644
47920 --- a/drivers/misc/sgi-xp/xpc.h
47921 +++ b/drivers/misc/sgi-xp/xpc.h
47922 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
47923 void (*received_payload) (struct xpc_channel *, void *);
47924 void (*notify_senders_of_disconnect) (struct xpc_channel *);
47925 };
47926 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
47927
47928 /* struct xpc_partition act_state values (for XPC HB) */
47929
47930 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
47931 /* found in xpc_main.c */
47932 extern struct device *xpc_part;
47933 extern struct device *xpc_chan;
47934 -extern struct xpc_arch_operations xpc_arch_ops;
47935 +extern xpc_arch_operations_no_const xpc_arch_ops;
47936 extern int xpc_disengage_timelimit;
47937 extern int xpc_disengage_timedout;
47938 extern int xpc_activate_IRQ_rcvd;
47939 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
47940 index 82dc574..8539ab2 100644
47941 --- a/drivers/misc/sgi-xp/xpc_main.c
47942 +++ b/drivers/misc/sgi-xp/xpc_main.c
47943 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
47944 .notifier_call = xpc_system_die,
47945 };
47946
47947 -struct xpc_arch_operations xpc_arch_ops;
47948 +xpc_arch_operations_no_const xpc_arch_ops;
47949
47950 /*
47951 * Timer function to enforce the timelimit on the partition disengage.
47952 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
47953
47954 if (((die_args->trapnr == X86_TRAP_MF) ||
47955 (die_args->trapnr == X86_TRAP_XF)) &&
47956 - !user_mode_vm(die_args->regs))
47957 + !user_mode(die_args->regs))
47958 xpc_die_deactivate();
47959
47960 break;
47961 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
47962 index 452782b..0c10e40 100644
47963 --- a/drivers/mmc/card/block.c
47964 +++ b/drivers/mmc/card/block.c
47965 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
47966 if (idata->ic.postsleep_min_us)
47967 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47968
47969 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47970 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47971 err = -EFAULT;
47972 goto cmd_rel_host;
47973 }
47974 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47975 index f51b5ba..86614a7 100644
47976 --- a/drivers/mmc/core/mmc_ops.c
47977 +++ b/drivers/mmc/core/mmc_ops.c
47978 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47979 void *data_buf;
47980 int is_on_stack;
47981
47982 - is_on_stack = object_is_on_stack(buf);
47983 + is_on_stack = object_starts_on_stack(buf);
47984 if (is_on_stack) {
47985 /*
47986 * dma onto stack is unsafe/nonportable, but callers to this
47987 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47988 index 738fa24..1568451 100644
47989 --- a/drivers/mmc/host/dw_mmc.h
47990 +++ b/drivers/mmc/host/dw_mmc.h
47991 @@ -257,5 +257,5 @@ struct dw_mci_drv_data {
47992 int (*parse_dt)(struct dw_mci *host);
47993 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47994 struct dw_mci_tuning_data *tuning_data);
47995 -};
47996 +} __do_const;
47997 #endif /* _DW_MMC_H_ */
47998 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47999 index 249ab80..9314ce1 100644
48000 --- a/drivers/mmc/host/mmci.c
48001 +++ b/drivers/mmc/host/mmci.c
48002 @@ -1507,7 +1507,9 @@ static int mmci_probe(struct amba_device *dev,
48003 mmc->caps |= MMC_CAP_CMD23;
48004
48005 if (variant->busy_detect) {
48006 - mmci_ops.card_busy = mmci_card_busy;
48007 + pax_open_kernel();
48008 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
48009 + pax_close_kernel();
48010 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
48011 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
48012 mmc->max_busy_timeout = 0;
48013 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
48014 index ccec0e3..199f9ce 100644
48015 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
48016 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
48017 @@ -1034,9 +1034,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
48018 host->mmc->caps |= MMC_CAP_1_8V_DDR;
48019 }
48020
48021 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
48022 - sdhci_esdhc_ops.platform_execute_tuning =
48023 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
48024 + pax_open_kernel();
48025 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
48026 esdhc_executing_tuning;
48027 + pax_close_kernel();
48028 + }
48029
48030 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
48031 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
48032 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
48033 index fa5954a..56840e5 100644
48034 --- a/drivers/mmc/host/sdhci-s3c.c
48035 +++ b/drivers/mmc/host/sdhci-s3c.c
48036 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
48037 * we can use overriding functions instead of default.
48038 */
48039 if (sc->no_divider) {
48040 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
48041 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
48042 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
48043 + pax_open_kernel();
48044 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
48045 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
48046 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
48047 + pax_close_kernel();
48048 }
48049
48050 /* It supports additional host capabilities if needed */
48051 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
48052 index 423666b..81ff5eb 100644
48053 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
48054 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
48055 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
48056 size_t totlen = 0, thislen;
48057 int ret = 0;
48058 size_t buflen = 0;
48059 - static char *buffer;
48060 + char *buffer;
48061
48062 if (!ECCBUF_SIZE) {
48063 /* We should fall back to a general writev implementation.
48064 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
48065 index 9f2012a..a81c720 100644
48066 --- a/drivers/mtd/nand/denali.c
48067 +++ b/drivers/mtd/nand/denali.c
48068 @@ -24,6 +24,7 @@
48069 #include <linux/slab.h>
48070 #include <linux/mtd/mtd.h>
48071 #include <linux/module.h>
48072 +#include <linux/slab.h>
48073
48074 #include "denali.h"
48075
48076 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48077 index f638cd8..2cbf586 100644
48078 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48079 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48080 @@ -387,7 +387,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
48081
48082 /* first try to map the upper buffer directly */
48083 if (virt_addr_valid(this->upper_buf) &&
48084 - !object_is_on_stack(this->upper_buf)) {
48085 + !object_starts_on_stack(this->upper_buf)) {
48086 sg_init_one(sgl, this->upper_buf, this->upper_len);
48087 ret = dma_map_sg(this->dev, sgl, 1, dr);
48088 if (ret == 0)
48089 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
48090 index 51b9d6a..52af9a7 100644
48091 --- a/drivers/mtd/nftlmount.c
48092 +++ b/drivers/mtd/nftlmount.c
48093 @@ -24,6 +24,7 @@
48094 #include <asm/errno.h>
48095 #include <linux/delay.h>
48096 #include <linux/slab.h>
48097 +#include <linux/sched.h>
48098 #include <linux/mtd/mtd.h>
48099 #include <linux/mtd/nand.h>
48100 #include <linux/mtd/nftl.h>
48101 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
48102 index cf49c22..971b133 100644
48103 --- a/drivers/mtd/sm_ftl.c
48104 +++ b/drivers/mtd/sm_ftl.c
48105 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
48106 #define SM_CIS_VENDOR_OFFSET 0x59
48107 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
48108 {
48109 - struct attribute_group *attr_group;
48110 + attribute_group_no_const *attr_group;
48111 struct attribute **attributes;
48112 struct sm_sysfs_attribute *vendor_attribute;
48113 char *vendor;
48114 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
48115 index 5ab3c18..5c3a836 100644
48116 --- a/drivers/net/bonding/bond_netlink.c
48117 +++ b/drivers/net/bonding/bond_netlink.c
48118 @@ -542,7 +542,7 @@ nla_put_failure:
48119 return -EMSGSIZE;
48120 }
48121
48122 -struct rtnl_link_ops bond_link_ops __read_mostly = {
48123 +struct rtnl_link_ops bond_link_ops = {
48124 .kind = "bond",
48125 .priv_size = sizeof(struct bonding),
48126 .setup = bond_setup,
48127 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
48128 index 4168822..f38eeddf 100644
48129 --- a/drivers/net/can/Kconfig
48130 +++ b/drivers/net/can/Kconfig
48131 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
48132
48133 config CAN_FLEXCAN
48134 tristate "Support for Freescale FLEXCAN based chips"
48135 - depends on ARM || PPC
48136 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
48137 ---help---
48138 Say Y here if you want to support for Freescale FlexCAN.
48139
48140 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
48141 index 1d162cc..b546a75 100644
48142 --- a/drivers/net/ethernet/8390/ax88796.c
48143 +++ b/drivers/net/ethernet/8390/ax88796.c
48144 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
48145 if (ax->plat->reg_offsets)
48146 ei_local->reg_offset = ax->plat->reg_offsets;
48147 else {
48148 + resource_size_t _mem_size = mem_size;
48149 + do_div(_mem_size, 0x18);
48150 ei_local->reg_offset = ax->reg_offsets;
48151 for (ret = 0; ret < 0x18; ret++)
48152 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
48153 + ax->reg_offsets[ret] = _mem_size * ret;
48154 }
48155
48156 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
48157 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
48158 index 7330681..7e9e463 100644
48159 --- a/drivers/net/ethernet/altera/altera_tse_main.c
48160 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
48161 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
48162 return 0;
48163 }
48164
48165 -static struct net_device_ops altera_tse_netdev_ops = {
48166 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
48167 .ndo_open = tse_open,
48168 .ndo_stop = tse_shutdown,
48169 .ndo_start_xmit = tse_start_xmit,
48170 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
48171 ndev->netdev_ops = &altera_tse_netdev_ops;
48172 altera_tse_set_ethtool_ops(ndev);
48173
48174 + pax_open_kernel();
48175 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
48176
48177 if (priv->hash_filter)
48178 altera_tse_netdev_ops.ndo_set_rx_mode =
48179 tse_set_rx_mode_hashfilter;
48180 + pax_close_kernel();
48181
48182 /* Scatter/gather IO is not supported,
48183 * so it is turned off
48184 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48185 index bf462ee8..18b8375 100644
48186 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48187 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48188 @@ -986,14 +986,14 @@ do { \
48189 * operations, everything works on mask values.
48190 */
48191 #define XMDIO_READ(_pdata, _mmd, _reg) \
48192 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
48193 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
48194 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
48195
48196 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
48197 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
48198
48199 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
48200 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
48201 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
48202 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
48203
48204 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
48205 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
48206 index 6bb76d5..ded47a8 100644
48207 --- a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
48208 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
48209 @@ -273,7 +273,7 @@ static ssize_t xpcs_reg_value_read(struct file *filp, char __user *buffer,
48210 struct xgbe_prv_data *pdata = filp->private_data;
48211 unsigned int value;
48212
48213 - value = pdata->hw_if.read_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48214 + value = pdata->hw_if->read_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48215 pdata->debugfs_xpcs_reg);
48216
48217 return xgbe_common_read(buffer, count, ppos, value);
48218 @@ -291,7 +291,7 @@ static ssize_t xpcs_reg_value_write(struct file *filp,
48219 if (len < 0)
48220 return len;
48221
48222 - pdata->hw_if.write_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48223 + pdata->hw_if->write_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48224 pdata->debugfs_xpcs_reg, value);
48225
48226 return len;
48227 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48228 index 6f1c859..e96ac1a 100644
48229 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48230 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48231 @@ -236,7 +236,7 @@ err_ring:
48232
48233 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
48234 {
48235 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48236 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48237 struct xgbe_channel *channel;
48238 struct xgbe_ring *ring;
48239 struct xgbe_ring_data *rdata;
48240 @@ -277,7 +277,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
48241
48242 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
48243 {
48244 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48245 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48246 struct xgbe_channel *channel;
48247 struct xgbe_ring *ring;
48248 struct xgbe_ring_desc *rdesc;
48249 @@ -496,7 +496,7 @@ err_out:
48250 static void xgbe_realloc_skb(struct xgbe_channel *channel)
48251 {
48252 struct xgbe_prv_data *pdata = channel->pdata;
48253 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48254 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48255 struct xgbe_ring *ring = channel->rx_ring;
48256 struct xgbe_ring_data *rdata;
48257 struct sk_buff *skb = NULL;
48258 @@ -540,17 +540,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
48259 DBGPR("<--xgbe_realloc_skb\n");
48260 }
48261
48262 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
48263 -{
48264 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
48265 -
48266 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
48267 - desc_if->free_ring_resources = xgbe_free_ring_resources;
48268 - desc_if->map_tx_skb = xgbe_map_tx_skb;
48269 - desc_if->realloc_skb = xgbe_realloc_skb;
48270 - desc_if->unmap_skb = xgbe_unmap_skb;
48271 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
48272 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
48273 -
48274 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
48275 -}
48276 +const struct xgbe_desc_if default_xgbe_desc_if = {
48277 + .alloc_ring_resources = xgbe_alloc_ring_resources,
48278 + .free_ring_resources = xgbe_free_ring_resources,
48279 + .map_tx_skb = xgbe_map_tx_skb,
48280 + .realloc_skb = xgbe_realloc_skb,
48281 + .unmap_skb = xgbe_unmap_skb,
48282 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
48283 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
48284 +};
48285 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48286 index 002293b..5ced1dd 100644
48287 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48288 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48289 @@ -2030,7 +2030,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
48290
48291 static int xgbe_init(struct xgbe_prv_data *pdata)
48292 {
48293 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48294 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48295 int ret;
48296
48297 DBGPR("-->xgbe_init\n");
48298 @@ -2096,87 +2096,82 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
48299 return 0;
48300 }
48301
48302 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
48303 -{
48304 - DBGPR("-->xgbe_init_function_ptrs\n");
48305 -
48306 - hw_if->tx_complete = xgbe_tx_complete;
48307 -
48308 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
48309 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
48310 - hw_if->set_addn_mac_addrs = xgbe_set_addn_mac_addrs;
48311 - hw_if->set_mac_address = xgbe_set_mac_address;
48312 -
48313 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
48314 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
48315 -
48316 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
48317 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
48318 -
48319 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
48320 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
48321 -
48322 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
48323 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
48324 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
48325 -
48326 - hw_if->enable_tx = xgbe_enable_tx;
48327 - hw_if->disable_tx = xgbe_disable_tx;
48328 - hw_if->enable_rx = xgbe_enable_rx;
48329 - hw_if->disable_rx = xgbe_disable_rx;
48330 -
48331 - hw_if->powerup_tx = xgbe_powerup_tx;
48332 - hw_if->powerdown_tx = xgbe_powerdown_tx;
48333 - hw_if->powerup_rx = xgbe_powerup_rx;
48334 - hw_if->powerdown_rx = xgbe_powerdown_rx;
48335 -
48336 - hw_if->pre_xmit = xgbe_pre_xmit;
48337 - hw_if->dev_read = xgbe_dev_read;
48338 - hw_if->enable_int = xgbe_enable_int;
48339 - hw_if->disable_int = xgbe_disable_int;
48340 - hw_if->init = xgbe_init;
48341 - hw_if->exit = xgbe_exit;
48342 +const struct xgbe_hw_if default_xgbe_hw_if = {
48343 + .tx_complete = xgbe_tx_complete,
48344 +
48345 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
48346 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
48347 + .set_addn_mac_addrs = xgbe_set_addn_mac_addrs,
48348 + .set_mac_address = xgbe_set_mac_address,
48349 +
48350 + .enable_rx_csum = xgbe_enable_rx_csum,
48351 + .disable_rx_csum = xgbe_disable_rx_csum,
48352 +
48353 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
48354 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
48355 +
48356 + .read_mmd_regs = xgbe_read_mmd_regs,
48357 + .write_mmd_regs = xgbe_write_mmd_regs,
48358 +
48359 + .set_gmii_speed = xgbe_set_gmii_speed,
48360 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
48361 + .set_xgmii_speed = xgbe_set_xgmii_speed,
48362 +
48363 + .enable_tx = xgbe_enable_tx,
48364 + .disable_tx = xgbe_disable_tx,
48365 + .enable_rx = xgbe_enable_rx,
48366 + .disable_rx = xgbe_disable_rx,
48367 +
48368 + .powerup_tx = xgbe_powerup_tx,
48369 + .powerdown_tx = xgbe_powerdown_tx,
48370 + .powerup_rx = xgbe_powerup_rx,
48371 + .powerdown_rx = xgbe_powerdown_rx,
48372 +
48373 + .pre_xmit = xgbe_pre_xmit,
48374 + .dev_read = xgbe_dev_read,
48375 + .enable_int = xgbe_enable_int,
48376 + .disable_int = xgbe_disable_int,
48377 + .init = xgbe_init,
48378 + .exit = xgbe_exit,
48379
48380 /* Descriptor related Sequences have to be initialized here */
48381 - hw_if->tx_desc_init = xgbe_tx_desc_init;
48382 - hw_if->rx_desc_init = xgbe_rx_desc_init;
48383 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
48384 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
48385 - hw_if->is_last_desc = xgbe_is_last_desc;
48386 - hw_if->is_context_desc = xgbe_is_context_desc;
48387 + .tx_desc_init = xgbe_tx_desc_init,
48388 + .rx_desc_init = xgbe_rx_desc_init,
48389 + .tx_desc_reset = xgbe_tx_desc_reset,
48390 + .rx_desc_reset = xgbe_rx_desc_reset,
48391 + .is_last_desc = xgbe_is_last_desc,
48392 + .is_context_desc = xgbe_is_context_desc,
48393
48394 /* For FLOW ctrl */
48395 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
48396 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
48397 + .config_tx_flow_control = xgbe_config_tx_flow_control,
48398 + .config_rx_flow_control = xgbe_config_rx_flow_control,
48399
48400 /* For RX coalescing */
48401 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
48402 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
48403 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
48404 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
48405 + .config_rx_coalesce = xgbe_config_rx_coalesce,
48406 + .config_tx_coalesce = xgbe_config_tx_coalesce,
48407 + .usec_to_riwt = xgbe_usec_to_riwt,
48408 + .riwt_to_usec = xgbe_riwt_to_usec,
48409
48410 /* For RX and TX threshold config */
48411 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
48412 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
48413 + .config_rx_threshold = xgbe_config_rx_threshold,
48414 + .config_tx_threshold = xgbe_config_tx_threshold,
48415
48416 /* For RX and TX Store and Forward Mode config */
48417 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
48418 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
48419 + .config_rsf_mode = xgbe_config_rsf_mode,
48420 + .config_tsf_mode = xgbe_config_tsf_mode,
48421
48422 /* For TX DMA Operating on Second Frame config */
48423 - hw_if->config_osp_mode = xgbe_config_osp_mode;
48424 + .config_osp_mode = xgbe_config_osp_mode,
48425
48426 /* For RX and TX PBL config */
48427 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
48428 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
48429 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
48430 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
48431 - hw_if->config_pblx8 = xgbe_config_pblx8;
48432 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
48433 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
48434 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
48435 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
48436 + .config_pblx8 = xgbe_config_pblx8,
48437
48438 /* For MMC statistics support */
48439 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
48440 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
48441 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
48442 -
48443 - DBGPR("<--xgbe_init_function_ptrs\n");
48444 -}
48445 + .tx_mmc_int = xgbe_tx_mmc_int,
48446 + .rx_mmc_int = xgbe_rx_mmc_int,
48447 + .read_mmc_stats = xgbe_read_mmc_stats,
48448 +};
48449 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48450 index cfe3d93..07a78ae 100644
48451 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48452 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48453 @@ -153,7 +153,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
48454
48455 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48456 {
48457 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48458 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48459 struct xgbe_channel *channel;
48460 unsigned int i;
48461
48462 @@ -170,7 +170,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48463
48464 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48465 {
48466 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48467 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48468 struct xgbe_channel *channel;
48469 unsigned int i;
48470
48471 @@ -188,7 +188,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48472 static irqreturn_t xgbe_isr(int irq, void *data)
48473 {
48474 struct xgbe_prv_data *pdata = data;
48475 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48476 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48477 struct xgbe_channel *channel;
48478 unsigned int dma_isr, dma_ch_isr;
48479 unsigned int mac_isr;
48480 @@ -403,7 +403,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata)
48481
48482 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48483 {
48484 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48485 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48486
48487 DBGPR("-->xgbe_init_tx_coalesce\n");
48488
48489 @@ -417,7 +417,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48490
48491 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48492 {
48493 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48494 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48495
48496 DBGPR("-->xgbe_init_rx_coalesce\n");
48497
48498 @@ -431,7 +431,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48499
48500 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48501 {
48502 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48503 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48504 struct xgbe_channel *channel;
48505 struct xgbe_ring *ring;
48506 struct xgbe_ring_data *rdata;
48507 @@ -456,7 +456,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48508
48509 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48510 {
48511 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48512 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48513 struct xgbe_channel *channel;
48514 struct xgbe_ring *ring;
48515 struct xgbe_ring_data *rdata;
48516 @@ -482,7 +482,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48517 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48518 {
48519 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48520 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48521 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48522 unsigned long flags;
48523
48524 DBGPR("-->xgbe_powerdown\n");
48525 @@ -520,7 +520,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48526 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48527 {
48528 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48529 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48530 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48531 unsigned long flags;
48532
48533 DBGPR("-->xgbe_powerup\n");
48534 @@ -557,7 +557,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48535
48536 static int xgbe_start(struct xgbe_prv_data *pdata)
48537 {
48538 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48539 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48540 struct net_device *netdev = pdata->netdev;
48541
48542 DBGPR("-->xgbe_start\n");
48543 @@ -583,7 +583,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
48544
48545 static void xgbe_stop(struct xgbe_prv_data *pdata)
48546 {
48547 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48548 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48549 struct net_device *netdev = pdata->netdev;
48550
48551 DBGPR("-->xgbe_stop\n");
48552 @@ -603,7 +603,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
48553
48554 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
48555 {
48556 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48557 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48558
48559 DBGPR("-->xgbe_restart_dev\n");
48560
48561 @@ -741,8 +741,8 @@ static void xgbe_packet_info(struct xgbe_ring *ring, struct sk_buff *skb,
48562 static int xgbe_open(struct net_device *netdev)
48563 {
48564 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48565 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48566 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48567 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48568 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48569 int ret;
48570
48571 DBGPR("-->xgbe_open\n");
48572 @@ -804,8 +804,8 @@ err_clk:
48573 static int xgbe_close(struct net_device *netdev)
48574 {
48575 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48576 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48577 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48578 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48579 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48580
48581 DBGPR("-->xgbe_close\n");
48582
48583 @@ -835,8 +835,8 @@ static int xgbe_close(struct net_device *netdev)
48584 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
48585 {
48586 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48587 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48588 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48589 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48590 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48591 struct xgbe_channel *channel;
48592 struct xgbe_ring *ring;
48593 struct xgbe_packet_data *packet;
48594 @@ -903,7 +903,7 @@ tx_netdev_return:
48595 static void xgbe_set_rx_mode(struct net_device *netdev)
48596 {
48597 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48598 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48599 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48600 unsigned int pr_mode, am_mode;
48601
48602 DBGPR("-->xgbe_set_rx_mode\n");
48603 @@ -930,7 +930,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
48604 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
48605 {
48606 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48607 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48608 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48609 struct sockaddr *saddr = addr;
48610
48611 DBGPR("-->xgbe_set_mac_address\n");
48612 @@ -976,7 +976,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
48613
48614 DBGPR("-->%s\n", __func__);
48615
48616 - pdata->hw_if.read_mmc_stats(pdata);
48617 + pdata->hw_if->read_mmc_stats(pdata);
48618
48619 s->rx_packets = pstats->rxframecount_gb;
48620 s->rx_bytes = pstats->rxoctetcount_gb;
48621 @@ -1020,7 +1020,7 @@ static int xgbe_set_features(struct net_device *netdev,
48622 netdev_features_t features)
48623 {
48624 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48625 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48626 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48627 unsigned int rxcsum_enabled, rxvlan_enabled;
48628
48629 rxcsum_enabled = !!(pdata->netdev_features & NETIF_F_RXCSUM);
48630 @@ -1072,8 +1072,8 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
48631 static int xgbe_tx_poll(struct xgbe_channel *channel)
48632 {
48633 struct xgbe_prv_data *pdata = channel->pdata;
48634 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48635 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48636 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48637 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48638 struct xgbe_ring *ring = channel->tx_ring;
48639 struct xgbe_ring_data *rdata;
48640 struct xgbe_ring_desc *rdesc;
48641 @@ -1124,8 +1124,8 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
48642 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
48643 {
48644 struct xgbe_prv_data *pdata = channel->pdata;
48645 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48646 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48647 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48648 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48649 struct xgbe_ring *ring = channel->rx_ring;
48650 struct xgbe_ring_data *rdata;
48651 struct xgbe_packet_data *packet;
48652 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48653 index 8909f2b..719e767 100644
48654 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48655 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48656 @@ -202,7 +202,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
48657
48658 DBGPR("-->%s\n", __func__);
48659
48660 - pdata->hw_if.read_mmc_stats(pdata);
48661 + pdata->hw_if->read_mmc_stats(pdata);
48662 for (i = 0; i < XGBE_STATS_COUNT; i++) {
48663 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
48664 *data++ = *(u64 *)stat;
48665 @@ -387,7 +387,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
48666 struct ethtool_coalesce *ec)
48667 {
48668 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48669 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48670 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48671 unsigned int riwt;
48672
48673 DBGPR("-->xgbe_get_coalesce\n");
48674 @@ -410,7 +410,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
48675 struct ethtool_coalesce *ec)
48676 {
48677 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48678 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48679 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48680 unsigned int rx_frames, rx_riwt, rx_usecs;
48681 unsigned int tx_frames, tx_usecs;
48682
48683 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48684 index 5a1891f..1b7888e 100644
48685 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48686 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48687 @@ -210,12 +210,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
48688 DBGPR("<--xgbe_default_config\n");
48689 }
48690
48691 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
48692 -{
48693 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
48694 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
48695 -}
48696 -
48697 static int xgbe_probe(struct platform_device *pdev)
48698 {
48699 struct xgbe_prv_data *pdata;
48700 @@ -306,9 +300,8 @@ static int xgbe_probe(struct platform_device *pdev)
48701 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
48702
48703 /* Set all the function pointers */
48704 - xgbe_init_all_fptrs(pdata);
48705 - hw_if = &pdata->hw_if;
48706 - desc_if = &pdata->desc_if;
48707 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
48708 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
48709
48710 /* Issue software reset to device */
48711 hw_if->exit(pdata);
48712 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48713 index ea7a5d6..d10a742 100644
48714 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48715 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48716 @@ -128,7 +128,7 @@
48717 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
48718 {
48719 struct xgbe_prv_data *pdata = mii->priv;
48720 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48721 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48722 int mmd_data;
48723
48724 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
48725 @@ -145,7 +145,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48726 u16 mmd_val)
48727 {
48728 struct xgbe_prv_data *pdata = mii->priv;
48729 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48730 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48731 int mmd_data = mmd_val;
48732
48733 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
48734 @@ -161,7 +161,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48735 static void xgbe_adjust_link(struct net_device *netdev)
48736 {
48737 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48738 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48739 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48740 struct phy_device *phydev = pdata->phydev;
48741 unsigned long flags;
48742 int new_state = 0;
48743 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
48744 index ab06271..a560fa7 100644
48745 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
48746 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
48747 @@ -527,8 +527,8 @@ struct xgbe_prv_data {
48748
48749 int irq_number;
48750
48751 - struct xgbe_hw_if hw_if;
48752 - struct xgbe_desc_if desc_if;
48753 + const struct xgbe_hw_if *hw_if;
48754 + const struct xgbe_desc_if *desc_if;
48755
48756 /* Rings for Tx/Rx on a DMA channel */
48757 struct xgbe_channel *channel;
48758 @@ -611,6 +611,9 @@ struct xgbe_prv_data {
48759 #endif
48760 };
48761
48762 +extern const struct xgbe_hw_if default_xgbe_hw_if;
48763 +extern const struct xgbe_desc_if default_xgbe_desc_if;
48764 +
48765 /* Function prototypes*/
48766
48767 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
48768 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48769 index 571427c..e9fe9e7 100644
48770 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48771 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48772 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
48773 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
48774 {
48775 /* RX_MODE controlling object */
48776 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
48777 + bnx2x_init_rx_mode_obj(bp);
48778
48779 /* multicast configuration controlling object */
48780 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48781 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48782 index b193604..8873bfd 100644
48783 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48784 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48785 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48786 return rc;
48787 }
48788
48789 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48790 - struct bnx2x_rx_mode_obj *o)
48791 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48792 {
48793 if (CHIP_IS_E1x(bp)) {
48794 - o->wait_comp = bnx2x_empty_rx_mode_wait;
48795 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48796 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48797 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48798 } else {
48799 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48800 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
48801 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48802 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48803 }
48804 }
48805
48806 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48807 index 718ecd2..2183b2f 100644
48808 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48809 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48810 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48811
48812 /********************* RX MODE ****************/
48813
48814 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48815 - struct bnx2x_rx_mode_obj *o);
48816 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48817
48818 /**
48819 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48820 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48821 index 461acca..2b546ba 100644
48822 --- a/drivers/net/ethernet/broadcom/tg3.h
48823 +++ b/drivers/net/ethernet/broadcom/tg3.h
48824 @@ -150,6 +150,7 @@
48825 #define CHIPREV_ID_5750_A0 0x4000
48826 #define CHIPREV_ID_5750_A1 0x4001
48827 #define CHIPREV_ID_5750_A3 0x4003
48828 +#define CHIPREV_ID_5750_C1 0x4201
48829 #define CHIPREV_ID_5750_C2 0x4202
48830 #define CHIPREV_ID_5752_A0_HW 0x5000
48831 #define CHIPREV_ID_5752_A0 0x6000
48832 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48833 index 13f9636..228040f 100644
48834 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48835 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48836 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
48837 }
48838
48839 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48840 - bna_cb_ioceth_enable,
48841 - bna_cb_ioceth_disable,
48842 - bna_cb_ioceth_hbfail,
48843 - bna_cb_ioceth_reset
48844 + .enable_cbfn = bna_cb_ioceth_enable,
48845 + .disable_cbfn = bna_cb_ioceth_disable,
48846 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
48847 + .reset_cbfn = bna_cb_ioceth_reset
48848 };
48849
48850 static void bna_attr_init(struct bna_ioceth *ioceth)
48851 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48852 index 8cffcdf..aadf043 100644
48853 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48854 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48855 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48856 */
48857 struct l2t_skb_cb {
48858 arp_failure_handler_func arp_failure_handler;
48859 -};
48860 +} __no_const;
48861
48862 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48863
48864 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48865 index a83271c..cf00874 100644
48866 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48867 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48868 @@ -2174,7 +2174,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48869
48870 int i;
48871 struct adapter *ap = netdev2adap(dev);
48872 - static const unsigned int *reg_ranges;
48873 + const unsigned int *reg_ranges;
48874 int arr_size = 0, buf_size = 0;
48875
48876 if (is_t4(ap->params.chip)) {
48877 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48878 index c05b66d..ed69872 100644
48879 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
48880 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48881 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48882 for (i=0; i<ETH_ALEN; i++) {
48883 tmp.addr[i] = dev->dev_addr[i];
48884 }
48885 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48886 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48887 break;
48888
48889 case DE4X5_SET_HWADDR: /* Set the hardware address */
48890 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48891 spin_lock_irqsave(&lp->lock, flags);
48892 memcpy(&statbuf, &lp->pktStats, ioc->len);
48893 spin_unlock_irqrestore(&lp->lock, flags);
48894 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
48895 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48896 return -EFAULT;
48897 break;
48898 }
48899 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48900 index 1e187fb..d024547 100644
48901 --- a/drivers/net/ethernet/emulex/benet/be_main.c
48902 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
48903 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48904
48905 if (wrapped)
48906 newacc += 65536;
48907 - ACCESS_ONCE(*acc) = newacc;
48908 + ACCESS_ONCE_RW(*acc) = newacc;
48909 }
48910
48911 static void populate_erx_stats(struct be_adapter *adapter,
48912 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48913 index c77fa4a..7fd42fc 100644
48914 --- a/drivers/net/ethernet/faraday/ftgmac100.c
48915 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
48916 @@ -30,6 +30,8 @@
48917 #include <linux/netdevice.h>
48918 #include <linux/phy.h>
48919 #include <linux/platform_device.h>
48920 +#include <linux/interrupt.h>
48921 +#include <linux/irqreturn.h>
48922 #include <net/ip.h>
48923
48924 #include "ftgmac100.h"
48925 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48926 index 4ff1adc..0ea6bf4 100644
48927 --- a/drivers/net/ethernet/faraday/ftmac100.c
48928 +++ b/drivers/net/ethernet/faraday/ftmac100.c
48929 @@ -31,6 +31,8 @@
48930 #include <linux/module.h>
48931 #include <linux/netdevice.h>
48932 #include <linux/platform_device.h>
48933 +#include <linux/interrupt.h>
48934 +#include <linux/irqreturn.h>
48935
48936 #include "ftmac100.h"
48937
48938 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48939 index 101f439..59e7ec6 100644
48940 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48941 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48942 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48943 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48944
48945 /* Update the base adjustement value. */
48946 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
48947 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48948 smp_mb(); /* Force the above update. */
48949 }
48950
48951 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48952 index 68f87ec..241dbe3 100644
48953 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48954 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48955 @@ -792,7 +792,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48956 }
48957
48958 /* update the base incval used to calculate frequency adjustment */
48959 - ACCESS_ONCE(adapter->base_incval) = incval;
48960 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
48961 smp_mb();
48962
48963 /* need lock to prevent incorrect read while modifying cyclecounter */
48964 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48965 index 2bbd01f..e8baa64 100644
48966 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48967 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48968 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48969 struct __vxge_hw_fifo *fifo;
48970 struct vxge_hw_fifo_config *config;
48971 u32 txdl_size, txdl_per_memblock;
48972 - struct vxge_hw_mempool_cbs fifo_mp_callback;
48973 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48974 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48975 + };
48976 +
48977 struct __vxge_hw_virtualpath *vpath;
48978
48979 if ((vp == NULL) || (attr == NULL)) {
48980 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48981 goto exit;
48982 }
48983
48984 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48985 -
48986 fifo->mempool =
48987 __vxge_hw_mempool_create(vpath->hldev,
48988 fifo->config->memblock_size,
48989 diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
48990 index 73e6683..464e910 100644
48991 --- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
48992 +++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
48993 @@ -120,6 +120,10 @@ static void pch_gbe_mdio_write(struct net_device *netdev, int addr, int reg,
48994 int data);
48995 static void pch_gbe_set_multi(struct net_device *netdev);
48996
48997 +static struct sock_filter ptp_filter[] = {
48998 + PTP_FILTER
48999 +};
49000 +
49001 static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49002 {
49003 u8 *data = skb->data;
49004 @@ -127,7 +131,7 @@ static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49005 u16 *hi, *id;
49006 u32 lo;
49007
49008 - if (ptp_classify_raw(skb) == PTP_CLASS_NONE)
49009 + if (sk_run_filter(skb, ptp_filter) == PTP_CLASS_NONE)
49010 return 0;
49011
49012 offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
49013 @@ -2631,6 +2635,11 @@ static int pch_gbe_probe(struct pci_dev *pdev,
49014
49015 adapter->ptp_pdev = pci_get_bus_and_slot(adapter->pdev->bus->number,
49016 PCI_DEVFN(12, 4));
49017 + if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
49018 + dev_err(&pdev->dev, "Bad ptp filter\n");
49019 + ret = -EINVAL;
49020 + goto err_free_netdev;
49021 + }
49022
49023 netdev->netdev_ops = &pch_gbe_netdev_ops;
49024 netdev->watchdog_timeo = PCH_GBE_WATCHDOG_PERIOD;
49025 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49026 index f33559b..c7f50ac 100644
49027 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49028 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49029 @@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
49030 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
49031 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
49032 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
49033 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
49034 + pax_open_kernel();
49035 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
49036 + pax_close_kernel();
49037 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49038 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
49039 max_tx_rings = QLCNIC_MAX_TX_RINGS;
49040 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49041 index be7d7a6..a8983f8 100644
49042 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49043 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49044 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
49045 case QLCNIC_NON_PRIV_FUNC:
49046 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
49047 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49048 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
49049 + pax_open_kernel();
49050 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
49051 + pax_close_kernel();
49052 break;
49053 case QLCNIC_PRIV_FUNC:
49054 ahw->op_mode = QLCNIC_PRIV_FUNC;
49055 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
49056 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
49057 + pax_open_kernel();
49058 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
49059 + pax_close_kernel();
49060 break;
49061 case QLCNIC_MGMT_FUNC:
49062 ahw->op_mode = QLCNIC_MGMT_FUNC;
49063 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49064 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
49065 + pax_open_kernel();
49066 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
49067 + pax_close_kernel();
49068 break;
49069 default:
49070 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
49071 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49072 index e46fc39..abe135b 100644
49073 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49074 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49075 @@ -1228,7 +1228,7 @@ flash_temp:
49076 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
49077 {
49078 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
49079 - static const struct qlcnic_dump_operations *fw_dump_ops;
49080 + const struct qlcnic_dump_operations *fw_dump_ops;
49081 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
49082 u32 entry_offset, dump, no_entries, buf_offset = 0;
49083 int i, k, ops_cnt, ops_index, dump_size = 0;
49084 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
49085 index 61623e9..ac97c27 100644
49086 --- a/drivers/net/ethernet/realtek/r8169.c
49087 +++ b/drivers/net/ethernet/realtek/r8169.c
49088 @@ -759,22 +759,22 @@ struct rtl8169_private {
49089 struct mdio_ops {
49090 void (*write)(struct rtl8169_private *, int, int);
49091 int (*read)(struct rtl8169_private *, int);
49092 - } mdio_ops;
49093 + } __no_const mdio_ops;
49094
49095 struct pll_power_ops {
49096 void (*down)(struct rtl8169_private *);
49097 void (*up)(struct rtl8169_private *);
49098 - } pll_power_ops;
49099 + } __no_const pll_power_ops;
49100
49101 struct jumbo_ops {
49102 void (*enable)(struct rtl8169_private *);
49103 void (*disable)(struct rtl8169_private *);
49104 - } jumbo_ops;
49105 + } __no_const jumbo_ops;
49106
49107 struct csi_ops {
49108 void (*write)(struct rtl8169_private *, int, int);
49109 u32 (*read)(struct rtl8169_private *, int);
49110 - } csi_ops;
49111 + } __no_const csi_ops;
49112
49113 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
49114 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
49115 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
49116 index 6b861e3..204ac86 100644
49117 --- a/drivers/net/ethernet/sfc/ptp.c
49118 +++ b/drivers/net/ethernet/sfc/ptp.c
49119 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
49120 ptp->start.dma_addr);
49121
49122 /* Clear flag that signals MC ready */
49123 - ACCESS_ONCE(*start) = 0;
49124 + ACCESS_ONCE_RW(*start) = 0;
49125 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
49126 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
49127 EFX_BUG_ON_PARANOID(rc);
49128 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49129 index 50617c5..b13724c 100644
49130 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49131 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49132 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
49133
49134 writel(value, ioaddr + MMC_CNTRL);
49135
49136 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
49137 - MMC_CNTRL, value);
49138 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
49139 +// MMC_CNTRL, value);
49140 }
49141
49142 /* To mask all all interrupts.*/
49143 diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
49144 index 6b56f85..50e285f 100644
49145 --- a/drivers/net/ethernet/ti/cpts.c
49146 +++ b/drivers/net/ethernet/ti/cpts.c
49147 @@ -33,6 +33,10 @@
49148
49149 #ifdef CONFIG_TI_CPTS
49150
49151 +static struct sock_filter ptp_filter[] = {
49152 + PTP_FILTER
49153 +};
49154 +
49155 #define cpts_read32(c, r) __raw_readl(&c->reg->r)
49156 #define cpts_write32(c, v, r) __raw_writel(v, &c->reg->r)
49157
49158 @@ -296,7 +300,7 @@ static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, int ev_type)
49159 u64 ns = 0;
49160 struct cpts_event *event;
49161 struct list_head *this, *next;
49162 - unsigned int class = ptp_classify_raw(skb);
49163 + unsigned int class = sk_run_filter(skb, ptp_filter);
49164 unsigned long flags;
49165 u16 seqid;
49166 u8 mtype;
49167 @@ -367,6 +371,10 @@ int cpts_register(struct device *dev, struct cpts *cpts,
49168 int err, i;
49169 unsigned long flags;
49170
49171 + if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
49172 + pr_err("cpts: bad ptp filter\n");
49173 + return -EINVAL;
49174 + }
49175 cpts->info = cpts_info;
49176 cpts->clock = ptp_clock_register(&cpts->info, dev);
49177 if (IS_ERR(cpts->clock)) {
49178 diff --git a/drivers/net/ethernet/xscale/Kconfig b/drivers/net/ethernet/xscale/Kconfig
49179 index b81bc9f..3f43101 100644
49180 --- a/drivers/net/ethernet/xscale/Kconfig
49181 +++ b/drivers/net/ethernet/xscale/Kconfig
49182 @@ -23,7 +23,6 @@ config IXP4XX_ETH
49183 tristate "Intel IXP4xx Ethernet support"
49184 depends on ARM && ARCH_IXP4XX && IXP4XX_NPE && IXP4XX_QMGR
49185 select PHYLIB
49186 - select NET_PTP_CLASSIFY
49187 ---help---
49188 Say Y here if you want to use built-in Ethernet ports
49189 on IXP4xx processor.
49190 diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
49191 index f7e0f0f..25283f1 100644
49192 --- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
49193 +++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
49194 @@ -256,6 +256,10 @@ static int ports_open;
49195 static struct port *npe_port_tab[MAX_NPES];
49196 static struct dma_pool *dma_pool;
49197
49198 +static struct sock_filter ptp_filter[] = {
49199 + PTP_FILTER
49200 +};
49201 +
49202 static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49203 {
49204 u8 *data = skb->data;
49205 @@ -263,7 +267,7 @@ static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49206 u16 *hi, *id;
49207 u32 lo;
49208
49209 - if (ptp_classify_raw(skb) != PTP_CLASS_V1_IPV4)
49210 + if (sk_run_filter(skb, ptp_filter) != PTP_CLASS_V1_IPV4)
49211 return 0;
49212
49213 offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
49214 @@ -1409,6 +1413,11 @@ static int eth_init_one(struct platform_device *pdev)
49215 char phy_id[MII_BUS_ID_SIZE + 3];
49216 int err;
49217
49218 + if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
49219 + pr_err("ixp4xx_eth: bad ptp filter\n");
49220 + return -EINVAL;
49221 + }
49222 +
49223 if (!(dev = alloc_etherdev(sizeof(struct port))))
49224 return -ENOMEM;
49225
49226 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
49227 index 6cc37c1..fdd9d77 100644
49228 --- a/drivers/net/hyperv/hyperv_net.h
49229 +++ b/drivers/net/hyperv/hyperv_net.h
49230 @@ -170,7 +170,7 @@ struct rndis_device {
49231
49232 enum rndis_device_state state;
49233 bool link_state;
49234 - atomic_t new_req_id;
49235 + atomic_unchecked_t new_req_id;
49236
49237 spinlock_t request_lock;
49238 struct list_head req_list;
49239 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
49240 index 99c527a..6a2ce38 100644
49241 --- a/drivers/net/hyperv/rndis_filter.c
49242 +++ b/drivers/net/hyperv/rndis_filter.c
49243 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
49244 * template
49245 */
49246 set = &rndis_msg->msg.set_req;
49247 - set->req_id = atomic_inc_return(&dev->new_req_id);
49248 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
49249
49250 /* Add to the request list */
49251 spin_lock_irqsave(&dev->request_lock, flags);
49252 @@ -930,7 +930,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
49253
49254 /* Setup the rndis set */
49255 halt = &request->request_msg.msg.halt_req;
49256 - halt->req_id = atomic_inc_return(&dev->new_req_id);
49257 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
49258
49259 /* Ignore return since this msg is optional. */
49260 rndis_filter_send_request(dev, request);
49261 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
49262 index 78f18be..1d19c62 100644
49263 --- a/drivers/net/ieee802154/fakehard.c
49264 +++ b/drivers/net/ieee802154/fakehard.c
49265 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
49266 phy->transmit_power = 0xbf;
49267
49268 dev->netdev_ops = &fake_ops;
49269 - dev->ml_priv = &fake_mlme;
49270 + dev->ml_priv = (void *)&fake_mlme;
49271
49272 priv = netdev_priv(dev);
49273 priv->phy = phy;
49274 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
49275 index ef8a5c2..76877d6 100644
49276 --- a/drivers/net/macvlan.c
49277 +++ b/drivers/net/macvlan.c
49278 @@ -264,7 +264,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
49279 free_nskb:
49280 kfree_skb(nskb);
49281 err:
49282 - atomic_long_inc(&skb->dev->rx_dropped);
49283 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
49284 }
49285
49286 /* called under rcu_read_lock() from netif_receive_skb */
49287 @@ -1134,13 +1134,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
49288 int macvlan_link_register(struct rtnl_link_ops *ops)
49289 {
49290 /* common fields */
49291 - ops->priv_size = sizeof(struct macvlan_dev);
49292 - ops->validate = macvlan_validate;
49293 - ops->maxtype = IFLA_MACVLAN_MAX;
49294 - ops->policy = macvlan_policy;
49295 - ops->changelink = macvlan_changelink;
49296 - ops->get_size = macvlan_get_size;
49297 - ops->fill_info = macvlan_fill_info;
49298 + pax_open_kernel();
49299 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
49300 + *(void **)&ops->validate = macvlan_validate;
49301 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
49302 + *(const void **)&ops->policy = macvlan_policy;
49303 + *(void **)&ops->changelink = macvlan_changelink;
49304 + *(void **)&ops->get_size = macvlan_get_size;
49305 + *(void **)&ops->fill_info = macvlan_fill_info;
49306 + pax_close_kernel();
49307
49308 return rtnl_link_register(ops);
49309 };
49310 @@ -1220,7 +1222,7 @@ static int macvlan_device_event(struct notifier_block *unused,
49311 return NOTIFY_DONE;
49312 }
49313
49314 -static struct notifier_block macvlan_notifier_block __read_mostly = {
49315 +static struct notifier_block macvlan_notifier_block = {
49316 .notifier_call = macvlan_device_event,
49317 };
49318
49319 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
49320 index 3381c4f..dea5fd5 100644
49321 --- a/drivers/net/macvtap.c
49322 +++ b/drivers/net/macvtap.c
49323 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
49324 }
49325
49326 ret = 0;
49327 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49328 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49329 put_user(q->flags, &ifr->ifr_flags))
49330 ret = -EFAULT;
49331 macvtap_put_vlan(vlan);
49332 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
49333 return NOTIFY_DONE;
49334 }
49335
49336 -static struct notifier_block macvtap_notifier_block __read_mostly = {
49337 +static struct notifier_block macvtap_notifier_block = {
49338 .notifier_call = macvtap_device_event,
49339 };
49340
49341 diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
49342 index 9408157..d53b924 100644
49343 --- a/drivers/net/phy/dp83640.c
49344 +++ b/drivers/net/phy/dp83640.c
49345 @@ -27,7 +27,6 @@
49346 #include <linux/module.h>
49347 #include <linux/net_tstamp.h>
49348 #include <linux/netdevice.h>
49349 -#include <linux/if_vlan.h>
49350 #include <linux/phy.h>
49351 #include <linux/ptp_classify.h>
49352 #include <linux/ptp_clock_kernel.h>
49353 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
49354 index d5b77ef..72ff14b 100644
49355 --- a/drivers/net/ppp/ppp_generic.c
49356 +++ b/drivers/net/ppp/ppp_generic.c
49357 @@ -143,8 +143,9 @@ struct ppp {
49358 struct sk_buff_head mrq; /* MP: receive reconstruction queue */
49359 #endif /* CONFIG_PPP_MULTILINK */
49360 #ifdef CONFIG_PPP_FILTER
49361 - struct sk_filter *pass_filter; /* filter for packets to pass */
49362 - struct sk_filter *active_filter;/* filter for pkts to reset idle */
49363 + struct sock_filter *pass_filter; /* filter for packets to pass */
49364 + struct sock_filter *active_filter;/* filter for pkts to reset idle */
49365 + unsigned pass_len, active_len;
49366 #endif /* CONFIG_PPP_FILTER */
49367 struct net *ppp_net; /* the net we belong to */
49368 struct ppp_link_stats stats64; /* 64 bit network stats */
49369 @@ -539,7 +540,7 @@ static int get_filter(void __user *arg, struct sock_filter **p)
49370 {
49371 struct sock_fprog uprog;
49372 struct sock_filter *code = NULL;
49373 - int len;
49374 + int len, err;
49375
49376 if (copy_from_user(&uprog, arg, sizeof(uprog)))
49377 return -EFAULT;
49378 @@ -554,6 +555,12 @@ static int get_filter(void __user *arg, struct sock_filter **p)
49379 if (IS_ERR(code))
49380 return PTR_ERR(code);
49381
49382 + err = sk_chk_filter(code, uprog.len);
49383 + if (err) {
49384 + kfree(code);
49385 + return err;
49386 + }
49387 +
49388 *p = code;
49389 return uprog.len;
49390 }
49391 @@ -748,52 +755,28 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
49392 case PPPIOCSPASS:
49393 {
49394 struct sock_filter *code;
49395 -
49396 err = get_filter(argp, &code);
49397 if (err >= 0) {
49398 - struct sock_fprog_kern fprog = {
49399 - .len = err,
49400 - .filter = code,
49401 - };
49402 -
49403 ppp_lock(ppp);
49404 - if (ppp->pass_filter) {
49405 - sk_unattached_filter_destroy(ppp->pass_filter);
49406 - ppp->pass_filter = NULL;
49407 - }
49408 - if (fprog.filter != NULL)
49409 - err = sk_unattached_filter_create(&ppp->pass_filter,
49410 - &fprog);
49411 - else
49412 - err = 0;
49413 - kfree(code);
49414 + kfree(ppp->pass_filter);
49415 + ppp->pass_filter = code;
49416 + ppp->pass_len = err;
49417 ppp_unlock(ppp);
49418 + err = 0;
49419 }
49420 break;
49421 }
49422 case PPPIOCSACTIVE:
49423 {
49424 struct sock_filter *code;
49425 -
49426 err = get_filter(argp, &code);
49427 if (err >= 0) {
49428 - struct sock_fprog_kern fprog = {
49429 - .len = err,
49430 - .filter = code,
49431 - };
49432 -
49433 ppp_lock(ppp);
49434 - if (ppp->active_filter) {
49435 - sk_unattached_filter_destroy(ppp->active_filter);
49436 - ppp->active_filter = NULL;
49437 - }
49438 - if (fprog.filter != NULL)
49439 - err = sk_unattached_filter_create(&ppp->active_filter,
49440 - &fprog);
49441 - else
49442 - err = 0;
49443 - kfree(code);
49444 + kfree(ppp->active_filter);
49445 + ppp->active_filter = code;
49446 + ppp->active_len = err;
49447 ppp_unlock(ppp);
49448 + err = 0;
49449 }
49450 break;
49451 }
49452 @@ -1201,7 +1184,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
49453 a four-byte PPP header on each packet */
49454 *skb_push(skb, 2) = 1;
49455 if (ppp->pass_filter &&
49456 - SK_RUN_FILTER(ppp->pass_filter, skb) == 0) {
49457 + sk_run_filter(skb, ppp->pass_filter) == 0) {
49458 if (ppp->debug & 1)
49459 netdev_printk(KERN_DEBUG, ppp->dev,
49460 "PPP: outbound frame "
49461 @@ -1211,7 +1194,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
49462 }
49463 /* if this packet passes the active filter, record the time */
49464 if (!(ppp->active_filter &&
49465 - SK_RUN_FILTER(ppp->active_filter, skb) == 0))
49466 + sk_run_filter(skb, ppp->active_filter) == 0))
49467 ppp->last_xmit = jiffies;
49468 skb_pull(skb, 2);
49469 #else
49470 @@ -1835,7 +1818,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
49471
49472 *skb_push(skb, 2) = 0;
49473 if (ppp->pass_filter &&
49474 - SK_RUN_FILTER(ppp->pass_filter, skb) == 0) {
49475 + sk_run_filter(skb, ppp->pass_filter) == 0) {
49476 if (ppp->debug & 1)
49477 netdev_printk(KERN_DEBUG, ppp->dev,
49478 "PPP: inbound frame "
49479 @@ -1844,7 +1827,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
49480 return;
49481 }
49482 if (!(ppp->active_filter &&
49483 - SK_RUN_FILTER(ppp->active_filter, skb) == 0))
49484 + sk_run_filter(skb, ppp->active_filter) == 0))
49485 ppp->last_recv = jiffies;
49486 __skb_pull(skb, 2);
49487 } else
49488 @@ -2689,10 +2672,6 @@ ppp_create_interface(struct net *net, int unit, int *retp)
49489 ppp->minseq = -1;
49490 skb_queue_head_init(&ppp->mrq);
49491 #endif /* CONFIG_PPP_MULTILINK */
49492 -#ifdef CONFIG_PPP_FILTER
49493 - ppp->pass_filter = NULL;
49494 - ppp->active_filter = NULL;
49495 -#endif /* CONFIG_PPP_FILTER */
49496
49497 /*
49498 * drum roll: don't forget to set
49499 @@ -2823,15 +2802,10 @@ static void ppp_destroy_interface(struct ppp *ppp)
49500 skb_queue_purge(&ppp->mrq);
49501 #endif /* CONFIG_PPP_MULTILINK */
49502 #ifdef CONFIG_PPP_FILTER
49503 - if (ppp->pass_filter) {
49504 - sk_unattached_filter_destroy(ppp->pass_filter);
49505 - ppp->pass_filter = NULL;
49506 - }
49507 -
49508 - if (ppp->active_filter) {
49509 - sk_unattached_filter_destroy(ppp->active_filter);
49510 - ppp->active_filter = NULL;
49511 - }
49512 + kfree(ppp->pass_filter);
49513 + ppp->pass_filter = NULL;
49514 + kfree(ppp->active_filter);
49515 + ppp->active_filter = NULL;
49516 #endif /* CONFIG_PPP_FILTER */
49517
49518 kfree_skb(ppp->xmit_pending);
49519 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
49520 index 1252d9c..80e660b 100644
49521 --- a/drivers/net/slip/slhc.c
49522 +++ b/drivers/net/slip/slhc.c
49523 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
49524 register struct tcphdr *thp;
49525 register struct iphdr *ip;
49526 register struct cstate *cs;
49527 - int len, hdrlen;
49528 + long len, hdrlen;
49529 unsigned char *cp = icp;
49530
49531 /* We've got a compressed packet; read the change byte */
49532 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
49533 index b4958c7..277cb96 100644
49534 --- a/drivers/net/team/team.c
49535 +++ b/drivers/net/team/team.c
49536 @@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
49537 return NOTIFY_DONE;
49538 }
49539
49540 -static struct notifier_block team_notifier_block __read_mostly = {
49541 +static struct notifier_block team_notifier_block = {
49542 .notifier_call = team_device_event,
49543 };
49544
49545 diff --git a/drivers/net/team/team_mode_loadbalance.c b/drivers/net/team/team_mode_loadbalance.c
49546 index a58dfeb..dbde341 100644
49547 --- a/drivers/net/team/team_mode_loadbalance.c
49548 +++ b/drivers/net/team/team_mode_loadbalance.c
49549 @@ -49,7 +49,7 @@ struct lb_port_mapping {
49550 struct lb_priv_ex {
49551 struct team *team;
49552 struct lb_port_mapping tx_hash_to_port_mapping[LB_TX_HASHTABLE_SIZE];
49553 - struct sock_fprog_kern *orig_fprog;
49554 + struct sock_fprog *orig_fprog;
49555 struct {
49556 unsigned int refresh_interval; /* in tenths of second */
49557 struct delayed_work refresh_dw;
49558 @@ -241,15 +241,15 @@ static int lb_bpf_func_get(struct team *team, struct team_gsetter_ctx *ctx)
49559 return 0;
49560 }
49561
49562 -static int __fprog_create(struct sock_fprog_kern **pfprog, u32 data_len,
49563 +static int __fprog_create(struct sock_fprog **pfprog, u32 data_len,
49564 const void *data)
49565 {
49566 - struct sock_fprog_kern *fprog;
49567 + struct sock_fprog *fprog;
49568 struct sock_filter *filter = (struct sock_filter *) data;
49569
49570 if (data_len % sizeof(struct sock_filter))
49571 return -EINVAL;
49572 - fprog = kmalloc(sizeof(*fprog), GFP_KERNEL);
49573 + fprog = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
49574 if (!fprog)
49575 return -ENOMEM;
49576 fprog->filter = kmemdup(filter, data_len, GFP_KERNEL);
49577 @@ -262,7 +262,7 @@ static int __fprog_create(struct sock_fprog_kern **pfprog, u32 data_len,
49578 return 0;
49579 }
49580
49581 -static void __fprog_destroy(struct sock_fprog_kern *fprog)
49582 +static void __fprog_destroy(struct sock_fprog *fprog)
49583 {
49584 kfree(fprog->filter);
49585 kfree(fprog);
49586 @@ -273,7 +273,7 @@ static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx)
49587 struct lb_priv *lb_priv = get_lb_priv(team);
49588 struct sk_filter *fp = NULL;
49589 struct sk_filter *orig_fp;
49590 - struct sock_fprog_kern *fprog = NULL;
49591 + struct sock_fprog *fprog = NULL;
49592 int err;
49593
49594 if (ctx->data.bin_val.len) {
49595 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
49596 index 98bad1f..f197d7a 100644
49597 --- a/drivers/net/tun.c
49598 +++ b/drivers/net/tun.c
49599 @@ -1854,7 +1854,7 @@ unlock:
49600 }
49601
49602 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49603 - unsigned long arg, int ifreq_len)
49604 + unsigned long arg, size_t ifreq_len)
49605 {
49606 struct tun_file *tfile = file->private_data;
49607 struct tun_struct *tun;
49608 @@ -1867,6 +1867,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49609 unsigned int ifindex;
49610 int ret;
49611
49612 + if (ifreq_len > sizeof ifr)
49613 + return -EFAULT;
49614 +
49615 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
49616 if (copy_from_user(&ifr, argp, ifreq_len))
49617 return -EFAULT;
49618 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
49619 index a4272ed..cdd69ff 100644
49620 --- a/drivers/net/usb/hso.c
49621 +++ b/drivers/net/usb/hso.c
49622 @@ -71,7 +71,7 @@
49623 #include <asm/byteorder.h>
49624 #include <linux/serial_core.h>
49625 #include <linux/serial.h>
49626 -
49627 +#include <asm/local.h>
49628
49629 #define MOD_AUTHOR "Option Wireless"
49630 #define MOD_DESCRIPTION "USB High Speed Option driver"
49631 @@ -1177,7 +1177,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
49632 struct urb *urb;
49633
49634 urb = serial->rx_urb[0];
49635 - if (serial->port.count > 0) {
49636 + if (atomic_read(&serial->port.count) > 0) {
49637 count = put_rxbuf_data(urb, serial);
49638 if (count == -1)
49639 return;
49640 @@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
49641 DUMP1(urb->transfer_buffer, urb->actual_length);
49642
49643 /* Anyone listening? */
49644 - if (serial->port.count == 0)
49645 + if (atomic_read(&serial->port.count) == 0)
49646 return;
49647
49648 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
49649 @@ -1277,8 +1277,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49650 tty_port_tty_set(&serial->port, tty);
49651
49652 /* check for port already opened, if not set the termios */
49653 - serial->port.count++;
49654 - if (serial->port.count == 1) {
49655 + if (atomic_inc_return(&serial->port.count) == 1) {
49656 serial->rx_state = RX_IDLE;
49657 /* Force default termio settings */
49658 _hso_serial_set_termios(tty, NULL);
49659 @@ -1288,7 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49660 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
49661 if (result) {
49662 hso_stop_serial_device(serial->parent);
49663 - serial->port.count--;
49664 + atomic_dec(&serial->port.count);
49665 kref_put(&serial->parent->ref, hso_serial_ref_free);
49666 }
49667 } else {
49668 @@ -1325,10 +1324,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
49669
49670 /* reset the rts and dtr */
49671 /* do the actual close */
49672 - serial->port.count--;
49673 + atomic_dec(&serial->port.count);
49674
49675 - if (serial->port.count <= 0) {
49676 - serial->port.count = 0;
49677 + if (atomic_read(&serial->port.count) <= 0) {
49678 + atomic_set(&serial->port.count, 0);
49679 tty_port_tty_set(&serial->port, NULL);
49680 if (!usb_gone)
49681 hso_stop_serial_device(serial->parent);
49682 @@ -1403,7 +1402,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
49683
49684 /* the actual setup */
49685 spin_lock_irqsave(&serial->serial_lock, flags);
49686 - if (serial->port.count)
49687 + if (atomic_read(&serial->port.count))
49688 _hso_serial_set_termios(tty, old);
49689 else
49690 tty->termios = *old;
49691 @@ -1872,7 +1871,7 @@ static void intr_callback(struct urb *urb)
49692 D1("Pending read interrupt on port %d\n", i);
49693 spin_lock(&serial->serial_lock);
49694 if (serial->rx_state == RX_IDLE &&
49695 - serial->port.count > 0) {
49696 + atomic_read(&serial->port.count) > 0) {
49697 /* Setup and send a ctrl req read on
49698 * port i */
49699 if (!serial->rx_urb_filled[0]) {
49700 @@ -3045,7 +3044,7 @@ static int hso_resume(struct usb_interface *iface)
49701 /* Start all serial ports */
49702 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
49703 if (serial_table[i] && (serial_table[i]->interface == iface)) {
49704 - if (dev2ser(serial_table[i])->port.count) {
49705 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
49706 result =
49707 hso_start_serial_device(serial_table[i], GFP_NOIO);
49708 hso_kick_transmit(dev2ser(serial_table[i]));
49709 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
49710 index 3eab74c..fb6097c 100644
49711 --- a/drivers/net/usb/r8152.c
49712 +++ b/drivers/net/usb/r8152.c
49713 @@ -567,7 +567,7 @@ struct r8152 {
49714 void (*up)(struct r8152 *);
49715 void (*down)(struct r8152 *);
49716 void (*unload)(struct r8152 *);
49717 - } rtl_ops;
49718 + } __no_const rtl_ops;
49719
49720 int intr_interval;
49721 u32 saved_wolopts;
49722 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
49723 index a2515887..6d13233 100644
49724 --- a/drivers/net/usb/sierra_net.c
49725 +++ b/drivers/net/usb/sierra_net.c
49726 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
49727 /* atomic counter partially included in MAC address to make sure 2 devices
49728 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
49729 */
49730 -static atomic_t iface_counter = ATOMIC_INIT(0);
49731 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
49732
49733 /*
49734 * SYNC Timer Delay definition used to set the expiry time
49735 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
49736 dev->net->netdev_ops = &sierra_net_device_ops;
49737
49738 /* change MAC addr to include, ifacenum, and to be unique */
49739 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
49740 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
49741 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
49742
49743 /* we will have to manufacture ethernet headers, prepare template */
49744 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
49745 index 7d9f84a..7f690da 100644
49746 --- a/drivers/net/virtio_net.c
49747 +++ b/drivers/net/virtio_net.c
49748 @@ -47,7 +47,7 @@ module_param(gso, bool, 0444);
49749 #define RECEIVE_AVG_WEIGHT 64
49750
49751 /* Minimum alignment for mergeable packet buffers. */
49752 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
49753 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
49754
49755 #define VIRTNET_DRIVER_VERSION "1.0.0"
49756
49757 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
49758 index 9f79192..838cf95 100644
49759 --- a/drivers/net/vxlan.c
49760 +++ b/drivers/net/vxlan.c
49761 @@ -2838,7 +2838,7 @@ nla_put_failure:
49762 return -EMSGSIZE;
49763 }
49764
49765 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
49766 +static struct rtnl_link_ops vxlan_link_ops = {
49767 .kind = "vxlan",
49768 .maxtype = IFLA_VXLAN_MAX,
49769 .policy = vxlan_policy,
49770 @@ -2885,7 +2885,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
49771 return NOTIFY_DONE;
49772 }
49773
49774 -static struct notifier_block vxlan_notifier_block __read_mostly = {
49775 +static struct notifier_block vxlan_notifier_block = {
49776 .notifier_call = vxlan_lowerdev_event,
49777 };
49778
49779 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
49780 index 5920c99..ff2e4a5 100644
49781 --- a/drivers/net/wan/lmc/lmc_media.c
49782 +++ b/drivers/net/wan/lmc/lmc_media.c
49783 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
49784 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
49785
49786 lmc_media_t lmc_ds3_media = {
49787 - lmc_ds3_init, /* special media init stuff */
49788 - lmc_ds3_default, /* reset to default state */
49789 - lmc_ds3_set_status, /* reset status to state provided */
49790 - lmc_dummy_set_1, /* set clock source */
49791 - lmc_dummy_set2_1, /* set line speed */
49792 - lmc_ds3_set_100ft, /* set cable length */
49793 - lmc_ds3_set_scram, /* set scrambler */
49794 - lmc_ds3_get_link_status, /* get link status */
49795 - lmc_dummy_set_1, /* set link status */
49796 - lmc_ds3_set_crc_length, /* set CRC length */
49797 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49798 - lmc_ds3_watchdog
49799 + .init = lmc_ds3_init, /* special media init stuff */
49800 + .defaults = lmc_ds3_default, /* reset to default state */
49801 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
49802 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
49803 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49804 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
49805 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
49806 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
49807 + .set_link_status = lmc_dummy_set_1, /* set link status */
49808 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
49809 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49810 + .watchdog = lmc_ds3_watchdog
49811 };
49812
49813 lmc_media_t lmc_hssi_media = {
49814 - lmc_hssi_init, /* special media init stuff */
49815 - lmc_hssi_default, /* reset to default state */
49816 - lmc_hssi_set_status, /* reset status to state provided */
49817 - lmc_hssi_set_clock, /* set clock source */
49818 - lmc_dummy_set2_1, /* set line speed */
49819 - lmc_dummy_set_1, /* set cable length */
49820 - lmc_dummy_set_1, /* set scrambler */
49821 - lmc_hssi_get_link_status, /* get link status */
49822 - lmc_hssi_set_link_status, /* set link status */
49823 - lmc_hssi_set_crc_length, /* set CRC length */
49824 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49825 - lmc_hssi_watchdog
49826 + .init = lmc_hssi_init, /* special media init stuff */
49827 + .defaults = lmc_hssi_default, /* reset to default state */
49828 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
49829 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
49830 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49831 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49832 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49833 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
49834 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
49835 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
49836 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49837 + .watchdog = lmc_hssi_watchdog
49838 };
49839
49840 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
49841 - lmc_ssi_default, /* reset to default state */
49842 - lmc_ssi_set_status, /* reset status to state provided */
49843 - lmc_ssi_set_clock, /* set clock source */
49844 - lmc_ssi_set_speed, /* set line speed */
49845 - lmc_dummy_set_1, /* set cable length */
49846 - lmc_dummy_set_1, /* set scrambler */
49847 - lmc_ssi_get_link_status, /* get link status */
49848 - lmc_ssi_set_link_status, /* set link status */
49849 - lmc_ssi_set_crc_length, /* set CRC length */
49850 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49851 - lmc_ssi_watchdog
49852 +lmc_media_t lmc_ssi_media = {
49853 + .init = lmc_ssi_init, /* special media init stuff */
49854 + .defaults = lmc_ssi_default, /* reset to default state */
49855 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
49856 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
49857 + .set_speed = lmc_ssi_set_speed, /* set line speed */
49858 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49859 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49860 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
49861 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
49862 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
49863 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49864 + .watchdog = lmc_ssi_watchdog
49865 };
49866
49867 lmc_media_t lmc_t1_media = {
49868 - lmc_t1_init, /* special media init stuff */
49869 - lmc_t1_default, /* reset to default state */
49870 - lmc_t1_set_status, /* reset status to state provided */
49871 - lmc_t1_set_clock, /* set clock source */
49872 - lmc_dummy_set2_1, /* set line speed */
49873 - lmc_dummy_set_1, /* set cable length */
49874 - lmc_dummy_set_1, /* set scrambler */
49875 - lmc_t1_get_link_status, /* get link status */
49876 - lmc_dummy_set_1, /* set link status */
49877 - lmc_t1_set_crc_length, /* set CRC length */
49878 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49879 - lmc_t1_watchdog
49880 + .init = lmc_t1_init, /* special media init stuff */
49881 + .defaults = lmc_t1_default, /* reset to default state */
49882 + .set_status = lmc_t1_set_status, /* reset status to state provided */
49883 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
49884 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49885 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49886 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49887 + .get_link_status = lmc_t1_get_link_status, /* get link status */
49888 + .set_link_status = lmc_dummy_set_1, /* set link status */
49889 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
49890 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49891 + .watchdog = lmc_t1_watchdog
49892 };
49893
49894 static void
49895 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
49896 index feacc3b..5bac0de 100644
49897 --- a/drivers/net/wan/z85230.c
49898 +++ b/drivers/net/wan/z85230.c
49899 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
49900
49901 struct z8530_irqhandler z8530_sync =
49902 {
49903 - z8530_rx,
49904 - z8530_tx,
49905 - z8530_status
49906 + .rx = z8530_rx,
49907 + .tx = z8530_tx,
49908 + .status = z8530_status
49909 };
49910
49911 EXPORT_SYMBOL(z8530_sync);
49912 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
49913 }
49914
49915 static struct z8530_irqhandler z8530_dma_sync = {
49916 - z8530_dma_rx,
49917 - z8530_dma_tx,
49918 - z8530_dma_status
49919 + .rx = z8530_dma_rx,
49920 + .tx = z8530_dma_tx,
49921 + .status = z8530_dma_status
49922 };
49923
49924 static struct z8530_irqhandler z8530_txdma_sync = {
49925 - z8530_rx,
49926 - z8530_dma_tx,
49927 - z8530_dma_status
49928 + .rx = z8530_rx,
49929 + .tx = z8530_dma_tx,
49930 + .status = z8530_dma_status
49931 };
49932
49933 /**
49934 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
49935
49936 struct z8530_irqhandler z8530_nop=
49937 {
49938 - z8530_rx_clear,
49939 - z8530_tx_clear,
49940 - z8530_status_clear
49941 + .rx = z8530_rx_clear,
49942 + .tx = z8530_tx_clear,
49943 + .status = z8530_status_clear
49944 };
49945
49946
49947 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
49948 index 0b60295..b8bfa5b 100644
49949 --- a/drivers/net/wimax/i2400m/rx.c
49950 +++ b/drivers/net/wimax/i2400m/rx.c
49951 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
49952 if (i2400m->rx_roq == NULL)
49953 goto error_roq_alloc;
49954
49955 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
49956 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
49957 GFP_KERNEL);
49958 if (rd == NULL) {
49959 result = -ENOMEM;
49960 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
49961 index 64747d4..17c4cf3 100644
49962 --- a/drivers/net/wireless/airo.c
49963 +++ b/drivers/net/wireless/airo.c
49964 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
49965 struct airo_info *ai = dev->ml_priv;
49966 int ridcode;
49967 int enabled;
49968 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49969 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49970 unsigned char *iobuf;
49971
49972 /* Only super-user can write RIDs */
49973 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
49974 index d48776e..373d049 100644
49975 --- a/drivers/net/wireless/at76c50x-usb.c
49976 +++ b/drivers/net/wireless/at76c50x-usb.c
49977 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
49978 }
49979
49980 /* Convert timeout from the DFU status to jiffies */
49981 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
49982 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
49983 {
49984 return msecs_to_jiffies((s->poll_timeout[2] << 16)
49985 | (s->poll_timeout[1] << 8)
49986 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
49987 index e493db4..2c1853a 100644
49988 --- a/drivers/net/wireless/ath/ath10k/htc.c
49989 +++ b/drivers/net/wireless/ath/ath10k/htc.c
49990 @@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
49991 /* registered target arrival callback from the HIF layer */
49992 int ath10k_htc_init(struct ath10k *ar)
49993 {
49994 - struct ath10k_hif_cb htc_callbacks;
49995 + static struct ath10k_hif_cb htc_callbacks = {
49996 + .rx_completion = ath10k_htc_rx_completion_handler,
49997 + .tx_completion = ath10k_htc_tx_completion_handler,
49998 + };
49999 struct ath10k_htc_ep *ep = NULL;
50000 struct ath10k_htc *htc = &ar->htc;
50001
50002 @@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
50003 ath10k_htc_reset_endpoint_states(htc);
50004
50005 /* setup HIF layer callbacks */
50006 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
50007 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
50008 htc->ar = ar;
50009
50010 /* Get HIF default pipe for HTC message exchange */
50011 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
50012 index 4716d33..a688310 100644
50013 --- a/drivers/net/wireless/ath/ath10k/htc.h
50014 +++ b/drivers/net/wireless/ath/ath10k/htc.h
50015 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
50016
50017 struct ath10k_htc_ops {
50018 void (*target_send_suspend_complete)(struct ath10k *ar);
50019 -};
50020 +} __no_const;
50021
50022 struct ath10k_htc_ep_ops {
50023 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
50024 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
50025 void (*ep_tx_credits)(struct ath10k *);
50026 -};
50027 +} __no_const;
50028
50029 /* service connection information */
50030 struct ath10k_htc_svc_conn_req {
50031 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50032 index 741b38d..b7ae41b 100644
50033 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50034 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50035 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50036 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
50037 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
50038
50039 - ACCESS_ONCE(ads->ds_link) = i->link;
50040 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
50041 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
50042 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
50043
50044 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
50045 ctl6 = SM(i->keytype, AR_EncrType);
50046 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50047
50048 if ((i->is_first || i->is_last) &&
50049 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
50050 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
50051 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
50052 | set11nTries(i->rates, 1)
50053 | set11nTries(i->rates, 2)
50054 | set11nTries(i->rates, 3)
50055 | (i->dur_update ? AR_DurUpdateEna : 0)
50056 | SM(0, AR_BurstDur);
50057
50058 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
50059 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
50060 | set11nRate(i->rates, 1)
50061 | set11nRate(i->rates, 2)
50062 | set11nRate(i->rates, 3);
50063 } else {
50064 - ACCESS_ONCE(ads->ds_ctl2) = 0;
50065 - ACCESS_ONCE(ads->ds_ctl3) = 0;
50066 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
50067 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
50068 }
50069
50070 if (!i->is_first) {
50071 - ACCESS_ONCE(ads->ds_ctl0) = 0;
50072 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
50073 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
50074 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
50075 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
50076 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
50077 return;
50078 }
50079
50080 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50081 break;
50082 }
50083
50084 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
50085 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
50086 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
50087 | SM(i->txpower, AR_XmitPower)
50088 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
50089 @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50090 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
50091 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
50092
50093 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
50094 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
50095 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
50096 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
50097
50098 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
50099 return;
50100
50101 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
50102 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
50103 | set11nPktDurRTSCTS(i->rates, 1);
50104
50105 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
50106 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
50107 | set11nPktDurRTSCTS(i->rates, 3);
50108
50109 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
50110 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
50111 | set11nRateFlags(i->rates, 1)
50112 | set11nRateFlags(i->rates, 2)
50113 | set11nRateFlags(i->rates, 3)
50114 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50115 index 729ffbf..49f50e3 100644
50116 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50117 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50118 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50119 (i->qcu << AR_TxQcuNum_S) | desc_len;
50120
50121 checksum += val;
50122 - ACCESS_ONCE(ads->info) = val;
50123 + ACCESS_ONCE_RW(ads->info) = val;
50124
50125 checksum += i->link;
50126 - ACCESS_ONCE(ads->link) = i->link;
50127 + ACCESS_ONCE_RW(ads->link) = i->link;
50128
50129 checksum += i->buf_addr[0];
50130 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
50131 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
50132 checksum += i->buf_addr[1];
50133 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
50134 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
50135 checksum += i->buf_addr[2];
50136 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
50137 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
50138 checksum += i->buf_addr[3];
50139 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
50140 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
50141
50142 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
50143 - ACCESS_ONCE(ads->ctl3) = val;
50144 + ACCESS_ONCE_RW(ads->ctl3) = val;
50145 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
50146 - ACCESS_ONCE(ads->ctl5) = val;
50147 + ACCESS_ONCE_RW(ads->ctl5) = val;
50148 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
50149 - ACCESS_ONCE(ads->ctl7) = val;
50150 + ACCESS_ONCE_RW(ads->ctl7) = val;
50151 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
50152 - ACCESS_ONCE(ads->ctl9) = val;
50153 + ACCESS_ONCE_RW(ads->ctl9) = val;
50154
50155 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
50156 - ACCESS_ONCE(ads->ctl10) = checksum;
50157 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
50158
50159 if (i->is_first || i->is_last) {
50160 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
50161 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
50162 | set11nTries(i->rates, 1)
50163 | set11nTries(i->rates, 2)
50164 | set11nTries(i->rates, 3)
50165 | (i->dur_update ? AR_DurUpdateEna : 0)
50166 | SM(0, AR_BurstDur);
50167
50168 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
50169 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
50170 | set11nRate(i->rates, 1)
50171 | set11nRate(i->rates, 2)
50172 | set11nRate(i->rates, 3);
50173 } else {
50174 - ACCESS_ONCE(ads->ctl13) = 0;
50175 - ACCESS_ONCE(ads->ctl14) = 0;
50176 + ACCESS_ONCE_RW(ads->ctl13) = 0;
50177 + ACCESS_ONCE_RW(ads->ctl14) = 0;
50178 }
50179
50180 ads->ctl20 = 0;
50181 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50182
50183 ctl17 = SM(i->keytype, AR_EncrType);
50184 if (!i->is_first) {
50185 - ACCESS_ONCE(ads->ctl11) = 0;
50186 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
50187 - ACCESS_ONCE(ads->ctl15) = 0;
50188 - ACCESS_ONCE(ads->ctl16) = 0;
50189 - ACCESS_ONCE(ads->ctl17) = ctl17;
50190 - ACCESS_ONCE(ads->ctl18) = 0;
50191 - ACCESS_ONCE(ads->ctl19) = 0;
50192 + ACCESS_ONCE_RW(ads->ctl11) = 0;
50193 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
50194 + ACCESS_ONCE_RW(ads->ctl15) = 0;
50195 + ACCESS_ONCE_RW(ads->ctl16) = 0;
50196 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
50197 + ACCESS_ONCE_RW(ads->ctl18) = 0;
50198 + ACCESS_ONCE_RW(ads->ctl19) = 0;
50199 return;
50200 }
50201
50202 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
50203 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
50204 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
50205 | SM(i->txpower, AR_XmitPower)
50206 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
50207 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50208 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
50209 ctl12 |= SM(val, AR_PAPRDChainMask);
50210
50211 - ACCESS_ONCE(ads->ctl12) = ctl12;
50212 - ACCESS_ONCE(ads->ctl17) = ctl17;
50213 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
50214 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
50215
50216 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
50217 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
50218 | set11nPktDurRTSCTS(i->rates, 1);
50219
50220 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
50221 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
50222 | set11nPktDurRTSCTS(i->rates, 3);
50223
50224 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
50225 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
50226 | set11nRateFlags(i->rates, 1)
50227 | set11nRateFlags(i->rates, 2)
50228 | set11nRateFlags(i->rates, 3)
50229 | SM(i->rtscts_rate, AR_RTSCTSRate);
50230
50231 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
50232 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
50233 }
50234
50235 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
50236 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
50237 index 0acd4b5..0591c91 100644
50238 --- a/drivers/net/wireless/ath/ath9k/hw.h
50239 +++ b/drivers/net/wireless/ath/ath9k/hw.h
50240 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
50241
50242 /* ANI */
50243 void (*ani_cache_ini_regs)(struct ath_hw *ah);
50244 -};
50245 +} __no_const;
50246
50247 /**
50248 * struct ath_spec_scan - parameters for Atheros spectral scan
50249 @@ -706,7 +706,7 @@ struct ath_hw_ops {
50250 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
50251 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
50252 #endif
50253 -};
50254 +} __no_const;
50255
50256 struct ath_nf_limits {
50257 s16 max;
50258 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
50259 index 92190da..f3a4c4c 100644
50260 --- a/drivers/net/wireless/b43/phy_lp.c
50261 +++ b/drivers/net/wireless/b43/phy_lp.c
50262 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
50263 {
50264 struct ssb_bus *bus = dev->dev->sdev->bus;
50265
50266 - static const struct b206x_channel *chandata = NULL;
50267 + const struct b206x_channel *chandata = NULL;
50268 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
50269 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
50270 u16 old_comm15, scale;
50271 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
50272 index dc1d20c..f7a4f06 100644
50273 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
50274 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
50275 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
50276 */
50277 if (il3945_mod_params.disable_hw_scan) {
50278 D_INFO("Disabling hw_scan\n");
50279 - il3945_mac_ops.hw_scan = NULL;
50280 + pax_open_kernel();
50281 + *(void **)&il3945_mac_ops.hw_scan = NULL;
50282 + pax_close_kernel();
50283 }
50284
50285 D_INFO("*** LOAD DRIVER ***\n");
50286 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50287 index 0ffb6ff..c0b7f0e 100644
50288 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50289 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50290 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
50291 {
50292 struct iwl_priv *priv = file->private_data;
50293 char buf[64];
50294 - int buf_size;
50295 + size_t buf_size;
50296 u32 offset, len;
50297
50298 memset(buf, 0, sizeof(buf));
50299 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
50300 struct iwl_priv *priv = file->private_data;
50301
50302 char buf[8];
50303 - int buf_size;
50304 + size_t buf_size;
50305 u32 reset_flag;
50306
50307 memset(buf, 0, sizeof(buf));
50308 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
50309 {
50310 struct iwl_priv *priv = file->private_data;
50311 char buf[8];
50312 - int buf_size;
50313 + size_t buf_size;
50314 int ht40;
50315
50316 memset(buf, 0, sizeof(buf));
50317 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
50318 {
50319 struct iwl_priv *priv = file->private_data;
50320 char buf[8];
50321 - int buf_size;
50322 + size_t buf_size;
50323 int value;
50324
50325 memset(buf, 0, sizeof(buf));
50326 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
50327 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
50328 DEBUGFS_READ_FILE_OPS(current_sleep_command);
50329
50330 -static const char *fmt_value = " %-30s %10u\n";
50331 -static const char *fmt_hex = " %-30s 0x%02X\n";
50332 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
50333 -static const char *fmt_header =
50334 +static const char fmt_value[] = " %-30s %10u\n";
50335 +static const char fmt_hex[] = " %-30s 0x%02X\n";
50336 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
50337 +static const char fmt_header[] =
50338 "%-32s current cumulative delta max\n";
50339
50340 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
50341 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
50342 {
50343 struct iwl_priv *priv = file->private_data;
50344 char buf[8];
50345 - int buf_size;
50346 + size_t buf_size;
50347 int clear;
50348
50349 memset(buf, 0, sizeof(buf));
50350 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
50351 {
50352 struct iwl_priv *priv = file->private_data;
50353 char buf[8];
50354 - int buf_size;
50355 + size_t buf_size;
50356 int trace;
50357
50358 memset(buf, 0, sizeof(buf));
50359 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
50360 {
50361 struct iwl_priv *priv = file->private_data;
50362 char buf[8];
50363 - int buf_size;
50364 + size_t buf_size;
50365 int missed;
50366
50367 memset(buf, 0, sizeof(buf));
50368 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
50369
50370 struct iwl_priv *priv = file->private_data;
50371 char buf[8];
50372 - int buf_size;
50373 + size_t buf_size;
50374 int plcp;
50375
50376 memset(buf, 0, sizeof(buf));
50377 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
50378
50379 struct iwl_priv *priv = file->private_data;
50380 char buf[8];
50381 - int buf_size;
50382 + size_t buf_size;
50383 int flush;
50384
50385 memset(buf, 0, sizeof(buf));
50386 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
50387
50388 struct iwl_priv *priv = file->private_data;
50389 char buf[8];
50390 - int buf_size;
50391 + size_t buf_size;
50392 int rts;
50393
50394 if (!priv->cfg->ht_params)
50395 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
50396 {
50397 struct iwl_priv *priv = file->private_data;
50398 char buf[8];
50399 - int buf_size;
50400 + size_t buf_size;
50401
50402 memset(buf, 0, sizeof(buf));
50403 buf_size = min(count, sizeof(buf) - 1);
50404 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
50405 struct iwl_priv *priv = file->private_data;
50406 u32 event_log_flag;
50407 char buf[8];
50408 - int buf_size;
50409 + size_t buf_size;
50410
50411 /* check that the interface is up */
50412 if (!iwl_is_ready(priv))
50413 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
50414 struct iwl_priv *priv = file->private_data;
50415 char buf[8];
50416 u32 calib_disabled;
50417 - int buf_size;
50418 + size_t buf_size;
50419
50420 memset(buf, 0, sizeof(buf));
50421 buf_size = min(count, sizeof(buf) - 1);
50422 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
50423 index 788085b..0bc852a 100644
50424 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
50425 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
50426 @@ -1598,7 +1598,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
50427 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
50428
50429 char buf[8];
50430 - int buf_size;
50431 + size_t buf_size;
50432 u32 reset_flag;
50433
50434 memset(buf, 0, sizeof(buf));
50435 @@ -1619,7 +1619,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
50436 {
50437 struct iwl_trans *trans = file->private_data;
50438 char buf[8];
50439 - int buf_size;
50440 + size_t buf_size;
50441 int csr;
50442
50443 memset(buf, 0, sizeof(buf));
50444 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
50445 index a312c65..162b13a 100644
50446 --- a/drivers/net/wireless/mac80211_hwsim.c
50447 +++ b/drivers/net/wireless/mac80211_hwsim.c
50448 @@ -2573,20 +2573,20 @@ static int __init init_mac80211_hwsim(void)
50449 if (channels < 1)
50450 return -EINVAL;
50451
50452 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
50453 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50454 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50455 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50456 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50457 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50458 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50459 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50460 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50461 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50462 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
50463 - mac80211_hwsim_assign_vif_chanctx;
50464 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
50465 - mac80211_hwsim_unassign_vif_chanctx;
50466 + pax_open_kernel();
50467 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
50468 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50469 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50470 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50471 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50472 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50473 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50474 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50475 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50476 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50477 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
50478 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
50479 + pax_close_kernel();
50480
50481 spin_lock_init(&hwsim_radio_lock);
50482 INIT_LIST_HEAD(&hwsim_radios);
50483 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
50484 index d2a9a08..0cb175d 100644
50485 --- a/drivers/net/wireless/rndis_wlan.c
50486 +++ b/drivers/net/wireless/rndis_wlan.c
50487 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
50488
50489 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
50490
50491 - if (rts_threshold < 0 || rts_threshold > 2347)
50492 + if (rts_threshold > 2347)
50493 rts_threshold = 2347;
50494
50495 tmp = cpu_to_le32(rts_threshold);
50496 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
50497 index d13f25c..2573994 100644
50498 --- a/drivers/net/wireless/rt2x00/rt2x00.h
50499 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
50500 @@ -375,7 +375,7 @@ struct rt2x00_intf {
50501 * for hardware which doesn't support hardware
50502 * sequence counting.
50503 */
50504 - atomic_t seqno;
50505 + atomic_unchecked_t seqno;
50506 };
50507
50508 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
50509 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
50510 index 5642ccc..01f03eb 100644
50511 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
50512 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
50513 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
50514 * sequence counter given by mac80211.
50515 */
50516 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
50517 - seqno = atomic_add_return(0x10, &intf->seqno);
50518 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
50519 else
50520 - seqno = atomic_read(&intf->seqno);
50521 + seqno = atomic_read_unchecked(&intf->seqno);
50522
50523 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
50524 hdr->seq_ctrl |= cpu_to_le16(seqno);
50525 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
50526 index b661f896..ddf7d2b 100644
50527 --- a/drivers/net/wireless/ti/wl1251/sdio.c
50528 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
50529 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
50530
50531 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
50532
50533 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50534 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50535 + pax_open_kernel();
50536 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50537 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50538 + pax_close_kernel();
50539
50540 wl1251_info("using dedicated interrupt line");
50541 } else {
50542 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50543 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50544 + pax_open_kernel();
50545 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50546 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50547 + pax_close_kernel();
50548
50549 wl1251_info("using SDIO interrupt");
50550 }
50551 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
50552 index d50dfac..0a6f5be3 100644
50553 --- a/drivers/net/wireless/ti/wl12xx/main.c
50554 +++ b/drivers/net/wireless/ti/wl12xx/main.c
50555 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50556 sizeof(wl->conf.mem));
50557
50558 /* read data preparation is only needed by wl127x */
50559 - wl->ops->prepare_read = wl127x_prepare_read;
50560 + pax_open_kernel();
50561 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50562 + pax_close_kernel();
50563
50564 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50565 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50566 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50567 sizeof(wl->conf.mem));
50568
50569 /* read data preparation is only needed by wl127x */
50570 - wl->ops->prepare_read = wl127x_prepare_read;
50571 + pax_open_kernel();
50572 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50573 + pax_close_kernel();
50574
50575 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50576 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50577 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
50578 index de5b4fa..7996ec6 100644
50579 --- a/drivers/net/wireless/ti/wl18xx/main.c
50580 +++ b/drivers/net/wireless/ti/wl18xx/main.c
50581 @@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
50582 }
50583
50584 if (!checksum_param) {
50585 - wl18xx_ops.set_rx_csum = NULL;
50586 - wl18xx_ops.init_vif = NULL;
50587 + pax_open_kernel();
50588 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
50589 + *(void **)&wl18xx_ops.init_vif = NULL;
50590 + pax_close_kernel();
50591 }
50592
50593 /* Enable 11a Band only if we have 5G antennas */
50594 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
50595 index a912dc0..a8225ba 100644
50596 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
50597 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
50598 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
50599 {
50600 struct zd_usb *usb = urb->context;
50601 struct zd_usb_interrupt *intr = &usb->intr;
50602 - int len;
50603 + unsigned int len;
50604 u16 int_num;
50605
50606 ZD_ASSERT(in_interrupt());
50607 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
50608 index 683671a..4519fc2 100644
50609 --- a/drivers/nfc/nfcwilink.c
50610 +++ b/drivers/nfc/nfcwilink.c
50611 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
50612
50613 static int nfcwilink_probe(struct platform_device *pdev)
50614 {
50615 - static struct nfcwilink *drv;
50616 + struct nfcwilink *drv;
50617 int rc;
50618 __u32 protocols;
50619
50620 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
50621 index d93b2b6..ae50401 100644
50622 --- a/drivers/oprofile/buffer_sync.c
50623 +++ b/drivers/oprofile/buffer_sync.c
50624 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
50625 if (cookie == NO_COOKIE)
50626 offset = pc;
50627 if (cookie == INVALID_COOKIE) {
50628 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50629 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50630 offset = pc;
50631 }
50632 if (cookie != last_cookie) {
50633 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
50634 /* add userspace sample */
50635
50636 if (!mm) {
50637 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
50638 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
50639 return 0;
50640 }
50641
50642 cookie = lookup_dcookie(mm, s->eip, &offset);
50643
50644 if (cookie == INVALID_COOKIE) {
50645 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50646 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50647 return 0;
50648 }
50649
50650 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
50651 /* ignore backtraces if failed to add a sample */
50652 if (state == sb_bt_start) {
50653 state = sb_bt_ignore;
50654 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
50655 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
50656 }
50657 }
50658 release_mm(mm);
50659 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
50660 index c0cc4e7..44d4e54 100644
50661 --- a/drivers/oprofile/event_buffer.c
50662 +++ b/drivers/oprofile/event_buffer.c
50663 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
50664 }
50665
50666 if (buffer_pos == buffer_size) {
50667 - atomic_inc(&oprofile_stats.event_lost_overflow);
50668 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
50669 return;
50670 }
50671
50672 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
50673 index ed2c3ec..deda85a 100644
50674 --- a/drivers/oprofile/oprof.c
50675 +++ b/drivers/oprofile/oprof.c
50676 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
50677 if (oprofile_ops.switch_events())
50678 return;
50679
50680 - atomic_inc(&oprofile_stats.multiplex_counter);
50681 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
50682 start_switch_worker();
50683 }
50684
50685 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
50686 index ee2cfce..7f8f699 100644
50687 --- a/drivers/oprofile/oprofile_files.c
50688 +++ b/drivers/oprofile/oprofile_files.c
50689 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
50690
50691 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
50692
50693 -static ssize_t timeout_read(struct file *file, char __user *buf,
50694 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
50695 size_t count, loff_t *offset)
50696 {
50697 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
50698 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
50699 index 59659ce..6c860a0 100644
50700 --- a/drivers/oprofile/oprofile_stats.c
50701 +++ b/drivers/oprofile/oprofile_stats.c
50702 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
50703 cpu_buf->sample_invalid_eip = 0;
50704 }
50705
50706 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
50707 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
50708 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
50709 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
50710 - atomic_set(&oprofile_stats.multiplex_counter, 0);
50711 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
50712 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
50713 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
50714 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
50715 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
50716 }
50717
50718
50719 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
50720 index 1fc622b..8c48fc3 100644
50721 --- a/drivers/oprofile/oprofile_stats.h
50722 +++ b/drivers/oprofile/oprofile_stats.h
50723 @@ -13,11 +13,11 @@
50724 #include <linux/atomic.h>
50725
50726 struct oprofile_stat_struct {
50727 - atomic_t sample_lost_no_mm;
50728 - atomic_t sample_lost_no_mapping;
50729 - atomic_t bt_lost_no_mapping;
50730 - atomic_t event_lost_overflow;
50731 - atomic_t multiplex_counter;
50732 + atomic_unchecked_t sample_lost_no_mm;
50733 + atomic_unchecked_t sample_lost_no_mapping;
50734 + atomic_unchecked_t bt_lost_no_mapping;
50735 + atomic_unchecked_t event_lost_overflow;
50736 + atomic_unchecked_t multiplex_counter;
50737 };
50738
50739 extern struct oprofile_stat_struct oprofile_stats;
50740 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
50741 index 3f49345..c750d0b 100644
50742 --- a/drivers/oprofile/oprofilefs.c
50743 +++ b/drivers/oprofile/oprofilefs.c
50744 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
50745
50746 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
50747 {
50748 - atomic_t *val = file->private_data;
50749 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
50750 + atomic_unchecked_t *val = file->private_data;
50751 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
50752 }
50753
50754
50755 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
50756
50757
50758 int oprofilefs_create_ro_atomic(struct dentry *root,
50759 - char const *name, atomic_t *val)
50760 + char const *name, atomic_unchecked_t *val)
50761 {
50762 return __oprofilefs_create_file(root, name,
50763 &atomic_ro_fops, 0444, val);
50764 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
50765 index 61be1d9..dec05d7 100644
50766 --- a/drivers/oprofile/timer_int.c
50767 +++ b/drivers/oprofile/timer_int.c
50768 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
50769 return NOTIFY_OK;
50770 }
50771
50772 -static struct notifier_block __refdata oprofile_cpu_notifier = {
50773 +static struct notifier_block oprofile_cpu_notifier = {
50774 .notifier_call = oprofile_cpu_notify,
50775 };
50776
50777 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
50778 index 3b47080..6cd05dd 100644
50779 --- a/drivers/parport/procfs.c
50780 +++ b/drivers/parport/procfs.c
50781 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
50782
50783 *ppos += len;
50784
50785 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
50786 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
50787 }
50788
50789 #ifdef CONFIG_PARPORT_1284
50790 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
50791
50792 *ppos += len;
50793
50794 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
50795 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
50796 }
50797 #endif /* IEEE1284.3 support. */
50798
50799 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
50800 index 8dcccff..35d701d 100644
50801 --- a/drivers/pci/hotplug/acpiphp_ibm.c
50802 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
50803 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
50804 goto init_cleanup;
50805 }
50806
50807 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50808 + pax_open_kernel();
50809 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50810 + pax_close_kernel();
50811 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
50812
50813 return retval;
50814 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
50815 index 04fcd78..39e83f1 100644
50816 --- a/drivers/pci/hotplug/cpcihp_generic.c
50817 +++ b/drivers/pci/hotplug/cpcihp_generic.c
50818 @@ -73,7 +73,6 @@ static u16 port;
50819 static unsigned int enum_bit;
50820 static u8 enum_mask;
50821
50822 -static struct cpci_hp_controller_ops generic_hpc_ops;
50823 static struct cpci_hp_controller generic_hpc;
50824
50825 static int __init validate_parameters(void)
50826 @@ -139,6 +138,10 @@ static int query_enum(void)
50827 return ((value & enum_mask) == enum_mask);
50828 }
50829
50830 +static struct cpci_hp_controller_ops generic_hpc_ops = {
50831 + .query_enum = query_enum,
50832 +};
50833 +
50834 static int __init cpcihp_generic_init(void)
50835 {
50836 int status;
50837 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
50838 pci_dev_put(dev);
50839
50840 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
50841 - generic_hpc_ops.query_enum = query_enum;
50842 generic_hpc.ops = &generic_hpc_ops;
50843
50844 status = cpci_hp_register_controller(&generic_hpc);
50845 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
50846 index 6757b3e..d3bad62 100644
50847 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
50848 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50849 @@ -59,7 +59,6 @@
50850 /* local variables */
50851 static bool debug;
50852 static bool poll;
50853 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
50854 static struct cpci_hp_controller zt5550_hpc;
50855
50856 /* Primary cPCI bus bridge device */
50857 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
50858 return 0;
50859 }
50860
50861 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50862 + .query_enum = zt5550_hc_query_enum,
50863 +};
50864 +
50865 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50866 {
50867 int status;
50868 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50869 dbg("returned from zt5550_hc_config");
50870
50871 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50872 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50873 zt5550_hpc.ops = &zt5550_hpc_ops;
50874 if(!poll) {
50875 zt5550_hpc.irq = hc_dev->irq;
50876 zt5550_hpc.irq_flags = IRQF_SHARED;
50877 zt5550_hpc.dev_id = hc_dev;
50878
50879 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50880 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50881 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50882 + pax_open_kernel();
50883 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50884 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50885 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50886 + pax_open_kernel();
50887 } else {
50888 info("using ENUM# polling mode");
50889 }
50890 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
50891 index 0968a9b..5a00edf 100644
50892 --- a/drivers/pci/hotplug/cpqphp_nvram.c
50893 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
50894 @@ -427,9 +427,13 @@ static u32 store_HRT (void __iomem *rom_start)
50895
50896 void compaq_nvram_init (void __iomem *rom_start)
50897 {
50898 +
50899 +#ifndef CONFIG_PAX_KERNEXEC
50900 if (rom_start) {
50901 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
50902 }
50903 +#endif
50904 +
50905 dbg("int15 entry = %p\n", compaq_int15_entry_point);
50906
50907 /* initialize our int15 lock */
50908 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
50909 index 56d8486..f26113f 100644
50910 --- a/drivers/pci/hotplug/pci_hotplug_core.c
50911 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
50912 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
50913 return -EINVAL;
50914 }
50915
50916 - slot->ops->owner = owner;
50917 - slot->ops->mod_name = mod_name;
50918 + pax_open_kernel();
50919 + *(struct module **)&slot->ops->owner = owner;
50920 + *(const char **)&slot->ops->mod_name = mod_name;
50921 + pax_close_kernel();
50922
50923 mutex_lock(&pci_hp_mutex);
50924 /*
50925 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
50926 index a2297db..7c7d161 100644
50927 --- a/drivers/pci/hotplug/pciehp_core.c
50928 +++ b/drivers/pci/hotplug/pciehp_core.c
50929 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
50930 struct slot *slot = ctrl->slot;
50931 struct hotplug_slot *hotplug = NULL;
50932 struct hotplug_slot_info *info = NULL;
50933 - struct hotplug_slot_ops *ops = NULL;
50934 + hotplug_slot_ops_no_const *ops = NULL;
50935 char name[SLOT_NAME_SIZE];
50936 int retval = -ENOMEM;
50937
50938 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
50939 index 13f3d30..363cb44 100644
50940 --- a/drivers/pci/msi.c
50941 +++ b/drivers/pci/msi.c
50942 @@ -523,8 +523,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
50943 {
50944 struct attribute **msi_attrs;
50945 struct attribute *msi_attr;
50946 - struct device_attribute *msi_dev_attr;
50947 - struct attribute_group *msi_irq_group;
50948 + device_attribute_no_const *msi_dev_attr;
50949 + attribute_group_no_const *msi_irq_group;
50950 const struct attribute_group **msi_irq_groups;
50951 struct msi_desc *entry;
50952 int ret = -ENOMEM;
50953 @@ -584,7 +584,7 @@ error_attrs:
50954 count = 0;
50955 msi_attr = msi_attrs[count];
50956 while (msi_attr) {
50957 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
50958 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
50959 kfree(msi_attr->name);
50960 kfree(msi_dev_attr);
50961 ++count;
50962 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
50963 index 9ff0a90..e819dda 100644
50964 --- a/drivers/pci/pci-sysfs.c
50965 +++ b/drivers/pci/pci-sysfs.c
50966 @@ -1134,7 +1134,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
50967 {
50968 /* allocate attribute structure, piggyback attribute name */
50969 int name_len = write_combine ? 13 : 10;
50970 - struct bin_attribute *res_attr;
50971 + bin_attribute_no_const *res_attr;
50972 int retval;
50973
50974 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
50975 @@ -1311,7 +1311,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
50976 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
50977 {
50978 int retval;
50979 - struct bin_attribute *attr;
50980 + bin_attribute_no_const *attr;
50981
50982 /* If the device has VPD, try to expose it in sysfs. */
50983 if (dev->vpd) {
50984 @@ -1358,7 +1358,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
50985 {
50986 int retval;
50987 int rom_size = 0;
50988 - struct bin_attribute *attr;
50989 + bin_attribute_no_const *attr;
50990
50991 if (!sysfs_initialized)
50992 return -EACCES;
50993 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
50994 index 0601890..dc15007 100644
50995 --- a/drivers/pci/pci.h
50996 +++ b/drivers/pci/pci.h
50997 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
50998 struct pci_vpd {
50999 unsigned int len;
51000 const struct pci_vpd_ops *ops;
51001 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
51002 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
51003 };
51004
51005 int pci_vpd_pci22_init(struct pci_dev *dev);
51006 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
51007 index e1e7026..d28dd33 100644
51008 --- a/drivers/pci/pcie/aspm.c
51009 +++ b/drivers/pci/pcie/aspm.c
51010 @@ -27,9 +27,9 @@
51011 #define MODULE_PARAM_PREFIX "pcie_aspm."
51012
51013 /* Note: those are not register definitions */
51014 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
51015 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
51016 -#define ASPM_STATE_L1 (4) /* L1 state */
51017 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
51018 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
51019 +#define ASPM_STATE_L1 (4U) /* L1 state */
51020 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
51021 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
51022
51023 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
51024 index e3cf8a2..be1baf0 100644
51025 --- a/drivers/pci/probe.c
51026 +++ b/drivers/pci/probe.c
51027 @@ -176,7 +176,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
51028 struct pci_bus_region region, inverted_region;
51029 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
51030
51031 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
51032 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
51033
51034 /* No printks while decoding is disabled! */
51035 if (!dev->mmio_always_on) {
51036 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
51037 index 3f155e7..0f4b1f0 100644
51038 --- a/drivers/pci/proc.c
51039 +++ b/drivers/pci/proc.c
51040 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
51041 static int __init pci_proc_init(void)
51042 {
51043 struct pci_dev *dev = NULL;
51044 +
51045 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51046 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51047 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
51048 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51049 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51050 +#endif
51051 +#else
51052 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
51053 +#endif
51054 proc_create("devices", 0, proc_bus_pci_dir,
51055 &proc_bus_pci_dev_operations);
51056 proc_initialized = 1;
51057 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
51058 index 7f1a2e2..bc4b405 100644
51059 --- a/drivers/platform/chrome/chromeos_laptop.c
51060 +++ b/drivers/platform/chrome/chromeos_laptop.c
51061 @@ -395,7 +395,7 @@ static struct chromeos_laptop cr48 = {
51062 .callback = chromeos_laptop_dmi_matched, \
51063 .driver_data = (void *)&board_
51064
51065 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
51066 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
51067 {
51068 .ident = "Samsung Series 5 550",
51069 .matches = {
51070 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
51071 index 297b664..ab91e39 100644
51072 --- a/drivers/platform/x86/alienware-wmi.c
51073 +++ b/drivers/platform/x86/alienware-wmi.c
51074 @@ -133,7 +133,7 @@ struct wmax_led_args {
51075 } __packed;
51076
51077 static struct platform_device *platform_device;
51078 -static struct device_attribute *zone_dev_attrs;
51079 +static device_attribute_no_const *zone_dev_attrs;
51080 static struct attribute **zone_attrs;
51081 static struct platform_zone *zone_data;
51082
51083 @@ -144,7 +144,7 @@ static struct platform_driver platform_driver = {
51084 }
51085 };
51086
51087 -static struct attribute_group zone_attribute_group = {
51088 +static attribute_group_no_const zone_attribute_group = {
51089 .name = "rgb_zones",
51090 };
51091
51092 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
51093 index 3c6cced..12e0771 100644
51094 --- a/drivers/platform/x86/asus-wmi.c
51095 +++ b/drivers/platform/x86/asus-wmi.c
51096 @@ -1592,6 +1592,10 @@ static int show_dsts(struct seq_file *m, void *data)
51097 int err;
51098 u32 retval = -1;
51099
51100 +#ifdef CONFIG_GRKERNSEC_KMEM
51101 + return -EPERM;
51102 +#endif
51103 +
51104 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
51105
51106 if (err < 0)
51107 @@ -1608,6 +1612,10 @@ static int show_devs(struct seq_file *m, void *data)
51108 int err;
51109 u32 retval = -1;
51110
51111 +#ifdef CONFIG_GRKERNSEC_KMEM
51112 + return -EPERM;
51113 +#endif
51114 +
51115 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
51116 &retval);
51117
51118 @@ -1632,6 +1640,10 @@ static int show_call(struct seq_file *m, void *data)
51119 union acpi_object *obj;
51120 acpi_status status;
51121
51122 +#ifdef CONFIG_GRKERNSEC_KMEM
51123 + return -EPERM;
51124 +#endif
51125 +
51126 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
51127 1, asus->debug.method_id,
51128 &input, &output);
51129 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
51130 index 62f8030..c7f2a45 100644
51131 --- a/drivers/platform/x86/msi-laptop.c
51132 +++ b/drivers/platform/x86/msi-laptop.c
51133 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
51134
51135 if (!quirks->ec_read_only) {
51136 /* allow userland write sysfs file */
51137 - dev_attr_bluetooth.store = store_bluetooth;
51138 - dev_attr_wlan.store = store_wlan;
51139 - dev_attr_threeg.store = store_threeg;
51140 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
51141 - dev_attr_wlan.attr.mode |= S_IWUSR;
51142 - dev_attr_threeg.attr.mode |= S_IWUSR;
51143 + pax_open_kernel();
51144 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
51145 + *(void **)&dev_attr_wlan.store = store_wlan;
51146 + *(void **)&dev_attr_threeg.store = store_threeg;
51147 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
51148 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
51149 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
51150 + pax_close_kernel();
51151 }
51152
51153 /* disable hardware control by fn key */
51154 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
51155 index 70222f2..8c8ce66 100644
51156 --- a/drivers/platform/x86/msi-wmi.c
51157 +++ b/drivers/platform/x86/msi-wmi.c
51158 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
51159 static void msi_wmi_notify(u32 value, void *context)
51160 {
51161 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
51162 - static struct key_entry *key;
51163 + struct key_entry *key;
51164 union acpi_object *obj;
51165 acpi_status status;
51166
51167 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
51168 index 9c5a074..06c976a 100644
51169 --- a/drivers/platform/x86/sony-laptop.c
51170 +++ b/drivers/platform/x86/sony-laptop.c
51171 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
51172 }
51173
51174 /* High speed charging function */
51175 -static struct device_attribute *hsc_handle;
51176 +static device_attribute_no_const *hsc_handle;
51177
51178 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
51179 struct device_attribute *attr,
51180 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
51181 }
51182
51183 /* low battery function */
51184 -static struct device_attribute *lowbatt_handle;
51185 +static device_attribute_no_const *lowbatt_handle;
51186
51187 static ssize_t sony_nc_lowbatt_store(struct device *dev,
51188 struct device_attribute *attr,
51189 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
51190 }
51191
51192 /* fan speed function */
51193 -static struct device_attribute *fan_handle, *hsf_handle;
51194 +static device_attribute_no_const *fan_handle, *hsf_handle;
51195
51196 static ssize_t sony_nc_hsfan_store(struct device *dev,
51197 struct device_attribute *attr,
51198 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
51199 }
51200
51201 /* USB charge function */
51202 -static struct device_attribute *uc_handle;
51203 +static device_attribute_no_const *uc_handle;
51204
51205 static ssize_t sony_nc_usb_charge_store(struct device *dev,
51206 struct device_attribute *attr,
51207 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
51208 }
51209
51210 /* Panel ID function */
51211 -static struct device_attribute *panel_handle;
51212 +static device_attribute_no_const *panel_handle;
51213
51214 static ssize_t sony_nc_panelid_show(struct device *dev,
51215 struct device_attribute *attr, char *buffer)
51216 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
51217 }
51218
51219 /* smart connect function */
51220 -static struct device_attribute *sc_handle;
51221 +static device_attribute_no_const *sc_handle;
51222
51223 static ssize_t sony_nc_smart_conn_store(struct device *dev,
51224 struct device_attribute *attr,
51225 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
51226 index d82f196..5458f34 100644
51227 --- a/drivers/platform/x86/thinkpad_acpi.c
51228 +++ b/drivers/platform/x86/thinkpad_acpi.c
51229 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
51230 return 0;
51231 }
51232
51233 -void static hotkey_mask_warn_incomplete_mask(void)
51234 +static void hotkey_mask_warn_incomplete_mask(void)
51235 {
51236 /* log only what the user can fix... */
51237 const u32 wantedmask = hotkey_driver_mask &
51238 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
51239 && !tp_features.bright_unkfw)
51240 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
51241 }
51242 +}
51243
51244 #undef TPACPI_COMPARE_KEY
51245 #undef TPACPI_MAY_SEND_KEY
51246 -}
51247
51248 /*
51249 * Polling driver
51250 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
51251 index 438d4c7..ca8a2fb 100644
51252 --- a/drivers/pnp/pnpbios/bioscalls.c
51253 +++ b/drivers/pnp/pnpbios/bioscalls.c
51254 @@ -59,7 +59,7 @@ do { \
51255 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
51256 } while(0)
51257
51258 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
51259 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
51260 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
51261
51262 /*
51263 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
51264
51265 cpu = get_cpu();
51266 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
51267 +
51268 + pax_open_kernel();
51269 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
51270 + pax_close_kernel();
51271
51272 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
51273 spin_lock_irqsave(&pnp_bios_lock, flags);
51274 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
51275 :"memory");
51276 spin_unlock_irqrestore(&pnp_bios_lock, flags);
51277
51278 + pax_open_kernel();
51279 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
51280 + pax_close_kernel();
51281 +
51282 put_cpu();
51283
51284 /* If we get here and this is set then the PnP BIOS faulted on us. */
51285 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
51286 return status;
51287 }
51288
51289 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
51290 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
51291 {
51292 int i;
51293
51294 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
51295 pnp_bios_callpoint.offset = header->fields.pm16offset;
51296 pnp_bios_callpoint.segment = PNP_CS16;
51297
51298 + pax_open_kernel();
51299 +
51300 for_each_possible_cpu(i) {
51301 struct desc_struct *gdt = get_cpu_gdt_table(i);
51302 if (!gdt)
51303 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
51304 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
51305 (unsigned long)__va(header->fields.pm16dseg));
51306 }
51307 +
51308 + pax_close_kernel();
51309 }
51310 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
51311 index 0c52e2a..3421ab7 100644
51312 --- a/drivers/power/pda_power.c
51313 +++ b/drivers/power/pda_power.c
51314 @@ -37,7 +37,11 @@ static int polling;
51315
51316 #if IS_ENABLED(CONFIG_USB_PHY)
51317 static struct usb_phy *transceiver;
51318 -static struct notifier_block otg_nb;
51319 +static int otg_handle_notification(struct notifier_block *nb,
51320 + unsigned long event, void *unused);
51321 +static struct notifier_block otg_nb = {
51322 + .notifier_call = otg_handle_notification
51323 +};
51324 #endif
51325
51326 static struct regulator *ac_draw;
51327 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
51328
51329 #if IS_ENABLED(CONFIG_USB_PHY)
51330 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
51331 - otg_nb.notifier_call = otg_handle_notification;
51332 ret = usb_register_notifier(transceiver, &otg_nb);
51333 if (ret) {
51334 dev_err(dev, "failure to register otg notifier\n");
51335 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
51336 index cc439fd..8fa30df 100644
51337 --- a/drivers/power/power_supply.h
51338 +++ b/drivers/power/power_supply.h
51339 @@ -16,12 +16,12 @@ struct power_supply;
51340
51341 #ifdef CONFIG_SYSFS
51342
51343 -extern void power_supply_init_attrs(struct device_type *dev_type);
51344 +extern void power_supply_init_attrs(void);
51345 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
51346
51347 #else
51348
51349 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
51350 +static inline void power_supply_init_attrs(void) {}
51351 #define power_supply_uevent NULL
51352
51353 #endif /* CONFIG_SYSFS */
51354 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
51355 index 5a5a24e..f7a3754 100644
51356 --- a/drivers/power/power_supply_core.c
51357 +++ b/drivers/power/power_supply_core.c
51358 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
51359 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
51360 EXPORT_SYMBOL_GPL(power_supply_notifier);
51361
51362 -static struct device_type power_supply_dev_type;
51363 +extern const struct attribute_group *power_supply_attr_groups[];
51364 +static struct device_type power_supply_dev_type = {
51365 + .groups = power_supply_attr_groups,
51366 +};
51367
51368 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
51369 struct power_supply *supply)
51370 @@ -639,7 +642,7 @@ static int __init power_supply_class_init(void)
51371 return PTR_ERR(power_supply_class);
51372
51373 power_supply_class->dev_uevent = power_supply_uevent;
51374 - power_supply_init_attrs(&power_supply_dev_type);
51375 + power_supply_init_attrs();
51376
51377 return 0;
51378 }
51379 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
51380 index 44420d1..967126e 100644
51381 --- a/drivers/power/power_supply_sysfs.c
51382 +++ b/drivers/power/power_supply_sysfs.c
51383 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
51384 .is_visible = power_supply_attr_is_visible,
51385 };
51386
51387 -static const struct attribute_group *power_supply_attr_groups[] = {
51388 +const struct attribute_group *power_supply_attr_groups[] = {
51389 &power_supply_attr_group,
51390 NULL,
51391 };
51392
51393 -void power_supply_init_attrs(struct device_type *dev_type)
51394 +void power_supply_init_attrs(void)
51395 {
51396 int i;
51397
51398 - dev_type->groups = power_supply_attr_groups;
51399 -
51400 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
51401 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
51402 }
51403 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
51404 index 84419af..268ede8 100644
51405 --- a/drivers/powercap/powercap_sys.c
51406 +++ b/drivers/powercap/powercap_sys.c
51407 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
51408 struct device_attribute name_attr;
51409 };
51410
51411 +static ssize_t show_constraint_name(struct device *dev,
51412 + struct device_attribute *dev_attr,
51413 + char *buf);
51414 +
51415 static struct powercap_constraint_attr
51416 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
51417 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
51418 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
51419 + .power_limit_attr = {
51420 + .attr = {
51421 + .name = NULL,
51422 + .mode = S_IWUSR | S_IRUGO
51423 + },
51424 + .show = show_constraint_power_limit_uw,
51425 + .store = store_constraint_power_limit_uw
51426 + },
51427 +
51428 + .time_window_attr = {
51429 + .attr = {
51430 + .name = NULL,
51431 + .mode = S_IWUSR | S_IRUGO
51432 + },
51433 + .show = show_constraint_time_window_us,
51434 + .store = store_constraint_time_window_us
51435 + },
51436 +
51437 + .max_power_attr = {
51438 + .attr = {
51439 + .name = NULL,
51440 + .mode = S_IRUGO
51441 + },
51442 + .show = show_constraint_max_power_uw,
51443 + .store = NULL
51444 + },
51445 +
51446 + .min_power_attr = {
51447 + .attr = {
51448 + .name = NULL,
51449 + .mode = S_IRUGO
51450 + },
51451 + .show = show_constraint_min_power_uw,
51452 + .store = NULL
51453 + },
51454 +
51455 + .max_time_window_attr = {
51456 + .attr = {
51457 + .name = NULL,
51458 + .mode = S_IRUGO
51459 + },
51460 + .show = show_constraint_max_time_window_us,
51461 + .store = NULL
51462 + },
51463 +
51464 + .min_time_window_attr = {
51465 + .attr = {
51466 + .name = NULL,
51467 + .mode = S_IRUGO
51468 + },
51469 + .show = show_constraint_min_time_window_us,
51470 + .store = NULL
51471 + },
51472 +
51473 + .name_attr = {
51474 + .attr = {
51475 + .name = NULL,
51476 + .mode = S_IRUGO
51477 + },
51478 + .show = show_constraint_name,
51479 + .store = NULL
51480 + }
51481 + }
51482 +};
51483
51484 /* A list of powercap control_types */
51485 static LIST_HEAD(powercap_cntrl_list);
51486 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
51487 }
51488
51489 static int create_constraint_attribute(int id, const char *name,
51490 - int mode,
51491 - struct device_attribute *dev_attr,
51492 - ssize_t (*show)(struct device *,
51493 - struct device_attribute *, char *),
51494 - ssize_t (*store)(struct device *,
51495 - struct device_attribute *,
51496 - const char *, size_t)
51497 - )
51498 + struct device_attribute *dev_attr)
51499 {
51500 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
51501
51502 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
51503 - id, name);
51504 - if (!dev_attr->attr.name)
51505 + if (!name)
51506 return -ENOMEM;
51507 - dev_attr->attr.mode = mode;
51508 - dev_attr->show = show;
51509 - dev_attr->store = store;
51510 +
51511 + pax_open_kernel();
51512 + *(const char **)&dev_attr->attr.name = name;
51513 + pax_close_kernel();
51514
51515 return 0;
51516 }
51517 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
51518
51519 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
51520 ret = create_constraint_attribute(i, "power_limit_uw",
51521 - S_IWUSR | S_IRUGO,
51522 - &constraint_attrs[i].power_limit_attr,
51523 - show_constraint_power_limit_uw,
51524 - store_constraint_power_limit_uw);
51525 + &constraint_attrs[i].power_limit_attr);
51526 if (ret)
51527 goto err_alloc;
51528 ret = create_constraint_attribute(i, "time_window_us",
51529 - S_IWUSR | S_IRUGO,
51530 - &constraint_attrs[i].time_window_attr,
51531 - show_constraint_time_window_us,
51532 - store_constraint_time_window_us);
51533 + &constraint_attrs[i].time_window_attr);
51534 if (ret)
51535 goto err_alloc;
51536 - ret = create_constraint_attribute(i, "name", S_IRUGO,
51537 - &constraint_attrs[i].name_attr,
51538 - show_constraint_name,
51539 - NULL);
51540 + ret = create_constraint_attribute(i, "name",
51541 + &constraint_attrs[i].name_attr);
51542 if (ret)
51543 goto err_alloc;
51544 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
51545 - &constraint_attrs[i].max_power_attr,
51546 - show_constraint_max_power_uw,
51547 - NULL);
51548 + ret = create_constraint_attribute(i, "max_power_uw",
51549 + &constraint_attrs[i].max_power_attr);
51550 if (ret)
51551 goto err_alloc;
51552 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
51553 - &constraint_attrs[i].min_power_attr,
51554 - show_constraint_min_power_uw,
51555 - NULL);
51556 + ret = create_constraint_attribute(i, "min_power_uw",
51557 + &constraint_attrs[i].min_power_attr);
51558 if (ret)
51559 goto err_alloc;
51560 ret = create_constraint_attribute(i, "max_time_window_us",
51561 - S_IRUGO,
51562 - &constraint_attrs[i].max_time_window_attr,
51563 - show_constraint_max_time_window_us,
51564 - NULL);
51565 + &constraint_attrs[i].max_time_window_attr);
51566 if (ret)
51567 goto err_alloc;
51568 ret = create_constraint_attribute(i, "min_time_window_us",
51569 - S_IRUGO,
51570 - &constraint_attrs[i].min_time_window_attr,
51571 - show_constraint_min_time_window_us,
51572 - NULL);
51573 + &constraint_attrs[i].min_time_window_attr);
51574 if (ret)
51575 goto err_alloc;
51576
51577 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
51578 power_zone->zone_dev_attrs[count++] =
51579 &dev_attr_max_energy_range_uj.attr;
51580 if (power_zone->ops->get_energy_uj) {
51581 + pax_open_kernel();
51582 if (power_zone->ops->reset_energy_uj)
51583 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51584 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51585 else
51586 - dev_attr_energy_uj.attr.mode = S_IRUGO;
51587 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
51588 + pax_close_kernel();
51589 power_zone->zone_dev_attrs[count++] =
51590 &dev_attr_energy_uj.attr;
51591 }
51592 diff --git a/drivers/ptp/Kconfig b/drivers/ptp/Kconfig
51593 index ee3de34..bec7285 100644
51594 --- a/drivers/ptp/Kconfig
51595 +++ b/drivers/ptp/Kconfig
51596 @@ -8,7 +8,6 @@ config PTP_1588_CLOCK
51597 tristate "PTP clock support"
51598 depends on NET
51599 select PPS
51600 - select NET_PTP_CLASSIFY
51601 help
51602 The IEEE 1588 standard defines a method to precisely
51603 synchronize distributed clocks over Ethernet networks. The
51604 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
51605 index 9c5d414..c7900ce 100644
51606 --- a/drivers/ptp/ptp_private.h
51607 +++ b/drivers/ptp/ptp_private.h
51608 @@ -51,7 +51,7 @@ struct ptp_clock {
51609 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
51610 wait_queue_head_t tsev_wq;
51611 int defunct; /* tells readers to go away when clock is being removed */
51612 - struct device_attribute *pin_dev_attr;
51613 + device_attribute_no_const *pin_dev_attr;
51614 struct attribute **pin_attr;
51615 struct attribute_group pin_attr_group;
51616 };
51617 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
51618 index 302e626..12579af 100644
51619 --- a/drivers/ptp/ptp_sysfs.c
51620 +++ b/drivers/ptp/ptp_sysfs.c
51621 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
51622 goto no_pin_attr;
51623
51624 for (i = 0; i < n_pins; i++) {
51625 - struct device_attribute *da = &ptp->pin_dev_attr[i];
51626 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
51627 sysfs_attr_init(&da->attr);
51628 da->attr.name = info->pin_config[i].name;
51629 da->attr.mode = 0644;
51630 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
51631 index 4c1f999..11078c9 100644
51632 --- a/drivers/regulator/core.c
51633 +++ b/drivers/regulator/core.c
51634 @@ -3391,7 +3391,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51635 {
51636 const struct regulation_constraints *constraints = NULL;
51637 const struct regulator_init_data *init_data;
51638 - static atomic_t regulator_no = ATOMIC_INIT(0);
51639 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
51640 struct regulator_dev *rdev;
51641 struct device *dev;
51642 int ret, i;
51643 @@ -3461,7 +3461,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51644 rdev->dev.of_node = of_node_get(config->of_node);
51645 rdev->dev.parent = dev;
51646 dev_set_name(&rdev->dev, "regulator.%d",
51647 - atomic_inc_return(&regulator_no) - 1);
51648 + atomic_inc_return_unchecked(&regulator_no) - 1);
51649 ret = device_register(&rdev->dev);
51650 if (ret != 0) {
51651 put_device(&rdev->dev);
51652 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
51653 index 2fc4111..6aa88ca 100644
51654 --- a/drivers/regulator/max8660.c
51655 +++ b/drivers/regulator/max8660.c
51656 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
51657 max8660->shadow_regs[MAX8660_OVER1] = 5;
51658 } else {
51659 /* Otherwise devices can be toggled via software */
51660 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
51661 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
51662 + pax_open_kernel();
51663 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
51664 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
51665 + pax_close_kernel();
51666 }
51667
51668 /*
51669 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
51670 index dbedf17..18ff6b7 100644
51671 --- a/drivers/regulator/max8973-regulator.c
51672 +++ b/drivers/regulator/max8973-regulator.c
51673 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
51674 if (!pdata || !pdata->enable_ext_control) {
51675 max->desc.enable_reg = MAX8973_VOUT;
51676 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
51677 - max->ops.enable = regulator_enable_regmap;
51678 - max->ops.disable = regulator_disable_regmap;
51679 - max->ops.is_enabled = regulator_is_enabled_regmap;
51680 + pax_open_kernel();
51681 + *(void **)&max->ops.enable = regulator_enable_regmap;
51682 + *(void **)&max->ops.disable = regulator_disable_regmap;
51683 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
51684 + pax_close_kernel();
51685 }
51686
51687 if (pdata) {
51688 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
51689 index f374fa5..26f0683 100644
51690 --- a/drivers/regulator/mc13892-regulator.c
51691 +++ b/drivers/regulator/mc13892-regulator.c
51692 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
51693 }
51694 mc13xxx_unlock(mc13892);
51695
51696 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51697 + pax_open_kernel();
51698 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51699 = mc13892_vcam_set_mode;
51700 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51701 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51702 = mc13892_vcam_get_mode;
51703 + pax_close_kernel();
51704
51705 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
51706 ARRAY_SIZE(mc13892_regulators));
51707 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
51708 index b0e4a3e..e5dc11e 100644
51709 --- a/drivers/rtc/rtc-cmos.c
51710 +++ b/drivers/rtc/rtc-cmos.c
51711 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
51712 hpet_rtc_timer_init();
51713
51714 /* export at least the first block of NVRAM */
51715 - nvram.size = address_space - NVRAM_OFFSET;
51716 + pax_open_kernel();
51717 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
51718 + pax_close_kernel();
51719 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
51720 if (retval < 0) {
51721 dev_dbg(dev, "can't create nvram file? %d\n", retval);
51722 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
51723 index d049393..bb20be0 100644
51724 --- a/drivers/rtc/rtc-dev.c
51725 +++ b/drivers/rtc/rtc-dev.c
51726 @@ -16,6 +16,7 @@
51727 #include <linux/module.h>
51728 #include <linux/rtc.h>
51729 #include <linux/sched.h>
51730 +#include <linux/grsecurity.h>
51731 #include "rtc-core.h"
51732
51733 static dev_t rtc_devt;
51734 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
51735 if (copy_from_user(&tm, uarg, sizeof(tm)))
51736 return -EFAULT;
51737
51738 + gr_log_timechange();
51739 +
51740 return rtc_set_time(rtc, &tm);
51741
51742 case RTC_PIE_ON:
51743 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
51744 index f03d5ba..8325bf6 100644
51745 --- a/drivers/rtc/rtc-ds1307.c
51746 +++ b/drivers/rtc/rtc-ds1307.c
51747 @@ -107,7 +107,7 @@ struct ds1307 {
51748 u8 offset; /* register's offset */
51749 u8 regs[11];
51750 u16 nvram_offset;
51751 - struct bin_attribute *nvram;
51752 + bin_attribute_no_const *nvram;
51753 enum ds_type type;
51754 unsigned long flags;
51755 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
51756 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
51757 index 11880c1..b823aa4 100644
51758 --- a/drivers/rtc/rtc-m48t59.c
51759 +++ b/drivers/rtc/rtc-m48t59.c
51760 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
51761 if (IS_ERR(m48t59->rtc))
51762 return PTR_ERR(m48t59->rtc);
51763
51764 - m48t59_nvram_attr.size = pdata->offset;
51765 + pax_open_kernel();
51766 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
51767 + pax_close_kernel();
51768
51769 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
51770 if (ret)
51771 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
51772 index e693af6..2e525b6 100644
51773 --- a/drivers/scsi/bfa/bfa_fcpim.h
51774 +++ b/drivers/scsi/bfa/bfa_fcpim.h
51775 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
51776
51777 struct bfa_itn_s {
51778 bfa_isr_func_t isr;
51779 -};
51780 +} __no_const;
51781
51782 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
51783 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
51784 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
51785 index a3ab5cc..8143622 100644
51786 --- a/drivers/scsi/bfa/bfa_fcs.c
51787 +++ b/drivers/scsi/bfa/bfa_fcs.c
51788 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
51789 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
51790
51791 static struct bfa_fcs_mod_s fcs_modules[] = {
51792 - { bfa_fcs_port_attach, NULL, NULL },
51793 - { bfa_fcs_uf_attach, NULL, NULL },
51794 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
51795 - bfa_fcs_fabric_modexit },
51796 + {
51797 + .attach = bfa_fcs_port_attach,
51798 + .modinit = NULL,
51799 + .modexit = NULL
51800 + },
51801 + {
51802 + .attach = bfa_fcs_uf_attach,
51803 + .modinit = NULL,
51804 + .modexit = NULL
51805 + },
51806 + {
51807 + .attach = bfa_fcs_fabric_attach,
51808 + .modinit = bfa_fcs_fabric_modinit,
51809 + .modexit = bfa_fcs_fabric_modexit
51810 + },
51811 };
51812
51813 /*
51814 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
51815 index ff75ef8..2dfe00a 100644
51816 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
51817 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
51818 @@ -89,15 +89,26 @@ static struct {
51819 void (*offline) (struct bfa_fcs_lport_s *port);
51820 } __port_action[] = {
51821 {
51822 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
51823 - bfa_fcs_lport_unknown_offline}, {
51824 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
51825 - bfa_fcs_lport_fab_offline}, {
51826 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
51827 - bfa_fcs_lport_n2n_offline}, {
51828 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
51829 - bfa_fcs_lport_loop_offline},
51830 - };
51831 + .init = bfa_fcs_lport_unknown_init,
51832 + .online = bfa_fcs_lport_unknown_online,
51833 + .offline = bfa_fcs_lport_unknown_offline
51834 + },
51835 + {
51836 + .init = bfa_fcs_lport_fab_init,
51837 + .online = bfa_fcs_lport_fab_online,
51838 + .offline = bfa_fcs_lport_fab_offline
51839 + },
51840 + {
51841 + .init = bfa_fcs_lport_n2n_init,
51842 + .online = bfa_fcs_lport_n2n_online,
51843 + .offline = bfa_fcs_lport_n2n_offline
51844 + },
51845 + {
51846 + .init = bfa_fcs_lport_loop_init,
51847 + .online = bfa_fcs_lport_loop_online,
51848 + .offline = bfa_fcs_lport_loop_offline
51849 + },
51850 +};
51851
51852 /*
51853 * fcs_port_sm FCS logical port state machine
51854 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
51855 index 2e28392..9d865b6 100644
51856 --- a/drivers/scsi/bfa/bfa_ioc.h
51857 +++ b/drivers/scsi/bfa/bfa_ioc.h
51858 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
51859 bfa_ioc_disable_cbfn_t disable_cbfn;
51860 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
51861 bfa_ioc_reset_cbfn_t reset_cbfn;
51862 -};
51863 +} __no_const;
51864
51865 /*
51866 * IOC event notification mechanism.
51867 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51868 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51869 enum bfi_ioc_state fwstate);
51870 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
51871 -};
51872 +} __no_const;
51873
51874 /*
51875 * Queue element to wait for room in request queue. FIFO order is
51876 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51877 index a14c784..6de6790 100644
51878 --- a/drivers/scsi/bfa/bfa_modules.h
51879 +++ b/drivers/scsi/bfa/bfa_modules.h
51880 @@ -78,12 +78,12 @@ enum {
51881 \
51882 extern struct bfa_module_s hal_mod_ ## __mod; \
51883 struct bfa_module_s hal_mod_ ## __mod = { \
51884 - bfa_ ## __mod ## _meminfo, \
51885 - bfa_ ## __mod ## _attach, \
51886 - bfa_ ## __mod ## _detach, \
51887 - bfa_ ## __mod ## _start, \
51888 - bfa_ ## __mod ## _stop, \
51889 - bfa_ ## __mod ## _iocdisable, \
51890 + .meminfo = bfa_ ## __mod ## _meminfo, \
51891 + .attach = bfa_ ## __mod ## _attach, \
51892 + .detach = bfa_ ## __mod ## _detach, \
51893 + .start = bfa_ ## __mod ## _start, \
51894 + .stop = bfa_ ## __mod ## _stop, \
51895 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
51896 }
51897
51898 #define BFA_CACHELINE_SZ (256)
51899 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
51900 index 045c4e1..13de803 100644
51901 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
51902 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
51903 @@ -33,8 +33,8 @@
51904 */
51905 #include "libfcoe.h"
51906
51907 -static atomic_t ctlr_num;
51908 -static atomic_t fcf_num;
51909 +static atomic_unchecked_t ctlr_num;
51910 +static atomic_unchecked_t fcf_num;
51911
51912 /*
51913 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
51914 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
51915 if (!ctlr)
51916 goto out;
51917
51918 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
51919 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
51920 ctlr->f = f;
51921 ctlr->mode = FIP_CONN_TYPE_FABRIC;
51922 INIT_LIST_HEAD(&ctlr->fcfs);
51923 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
51924 fcf->dev.parent = &ctlr->dev;
51925 fcf->dev.bus = &fcoe_bus_type;
51926 fcf->dev.type = &fcoe_fcf_device_type;
51927 - fcf->id = atomic_inc_return(&fcf_num) - 1;
51928 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
51929 fcf->state = FCOE_FCF_STATE_UNKNOWN;
51930
51931 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
51932 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
51933 {
51934 int error;
51935
51936 - atomic_set(&ctlr_num, 0);
51937 - atomic_set(&fcf_num, 0);
51938 + atomic_set_unchecked(&ctlr_num, 0);
51939 + atomic_set_unchecked(&fcf_num, 0);
51940
51941 error = bus_register(&fcoe_bus_type);
51942 if (error)
51943 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
51944 index 3cbb57a..95e47a3 100644
51945 --- a/drivers/scsi/hosts.c
51946 +++ b/drivers/scsi/hosts.c
51947 @@ -42,7 +42,7 @@
51948 #include "scsi_logging.h"
51949
51950
51951 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51952 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51953
51954
51955 static void scsi_host_cls_release(struct device *dev)
51956 @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
51957 * subtract one because we increment first then return, but we need to
51958 * know what the next host number was before increment
51959 */
51960 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
51961 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
51962 shost->dma_channel = 0xff;
51963
51964 /* These three are default values which can be overridden */
51965 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
51966 index 489e83b..193815b 100644
51967 --- a/drivers/scsi/hpsa.c
51968 +++ b/drivers/scsi/hpsa.c
51969 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
51970 unsigned long flags;
51971
51972 if (h->transMethod & CFGTBL_Trans_io_accel1)
51973 - return h->access.command_completed(h, q);
51974 + return h->access->command_completed(h, q);
51975
51976 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
51977 - return h->access.command_completed(h, q);
51978 + return h->access->command_completed(h, q);
51979
51980 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
51981 a = rq->head[rq->current_entry];
51982 @@ -5455,7 +5455,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51983 while (!list_empty(&h->reqQ)) {
51984 c = list_entry(h->reqQ.next, struct CommandList, list);
51985 /* can't do anything if fifo is full */
51986 - if ((h->access.fifo_full(h))) {
51987 + if ((h->access->fifo_full(h))) {
51988 h->fifo_recently_full = 1;
51989 dev_warn(&h->pdev->dev, "fifo full\n");
51990 break;
51991 @@ -5477,7 +5477,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51992
51993 /* Tell the controller execute command */
51994 spin_unlock_irqrestore(&h->lock, *flags);
51995 - h->access.submit_command(h, c);
51996 + h->access->submit_command(h, c);
51997 spin_lock_irqsave(&h->lock, *flags);
51998 }
51999 }
52000 @@ -5493,17 +5493,17 @@ static void lock_and_start_io(struct ctlr_info *h)
52001
52002 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
52003 {
52004 - return h->access.command_completed(h, q);
52005 + return h->access->command_completed(h, q);
52006 }
52007
52008 static inline bool interrupt_pending(struct ctlr_info *h)
52009 {
52010 - return h->access.intr_pending(h);
52011 + return h->access->intr_pending(h);
52012 }
52013
52014 static inline long interrupt_not_for_us(struct ctlr_info *h)
52015 {
52016 - return (h->access.intr_pending(h) == 0) ||
52017 + return (h->access->intr_pending(h) == 0) ||
52018 (h->interrupts_enabled == 0);
52019 }
52020
52021 @@ -6459,7 +6459,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
52022 if (prod_index < 0)
52023 return -ENODEV;
52024 h->product_name = products[prod_index].product_name;
52025 - h->access = *(products[prod_index].access);
52026 + h->access = products[prod_index].access;
52027
52028 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
52029 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
52030 @@ -6781,7 +6781,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
52031 unsigned long flags;
52032 u32 lockup_detected;
52033
52034 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52035 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52036 spin_lock_irqsave(&h->lock, flags);
52037 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
52038 if (!lockup_detected) {
52039 @@ -7022,7 +7022,7 @@ reinit_after_soft_reset:
52040 }
52041
52042 /* make sure the board interrupts are off */
52043 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52044 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52045
52046 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
52047 goto clean2;
52048 @@ -7057,7 +7057,7 @@ reinit_after_soft_reset:
52049 * fake ones to scoop up any residual completions.
52050 */
52051 spin_lock_irqsave(&h->lock, flags);
52052 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52053 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52054 spin_unlock_irqrestore(&h->lock, flags);
52055 free_irqs(h);
52056 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
52057 @@ -7076,9 +7076,9 @@ reinit_after_soft_reset:
52058 dev_info(&h->pdev->dev, "Board READY.\n");
52059 dev_info(&h->pdev->dev,
52060 "Waiting for stale completions to drain.\n");
52061 - h->access.set_intr_mask(h, HPSA_INTR_ON);
52062 + h->access->set_intr_mask(h, HPSA_INTR_ON);
52063 msleep(10000);
52064 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52065 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52066
52067 rc = controller_reset_failed(h->cfgtable);
52068 if (rc)
52069 @@ -7104,7 +7104,7 @@ reinit_after_soft_reset:
52070 h->drv_req_rescan = 0;
52071
52072 /* Turn the interrupts on so we can service requests */
52073 - h->access.set_intr_mask(h, HPSA_INTR_ON);
52074 + h->access->set_intr_mask(h, HPSA_INTR_ON);
52075
52076 hpsa_hba_inquiry(h);
52077 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
52078 @@ -7169,7 +7169,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
52079 * To write all data in the battery backed cache to disks
52080 */
52081 hpsa_flush_cache(h);
52082 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52083 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52084 hpsa_free_irqs_and_disable_msix(h);
52085 }
52086
52087 @@ -7287,7 +7287,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52088 CFGTBL_Trans_enable_directed_msix |
52089 (trans_support & (CFGTBL_Trans_io_accel1 |
52090 CFGTBL_Trans_io_accel2));
52091 - struct access_method access = SA5_performant_access;
52092 + struct access_method *access = &SA5_performant_access;
52093
52094 /* This is a bit complicated. There are 8 registers on
52095 * the controller which we write to to tell it 8 different
52096 @@ -7329,7 +7329,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52097 * perform the superfluous readl() after each command submission.
52098 */
52099 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
52100 - access = SA5_performant_access_no_read;
52101 + access = &SA5_performant_access_no_read;
52102
52103 /* Controller spec: zero out this buffer. */
52104 for (i = 0; i < h->nreply_queues; i++)
52105 @@ -7359,12 +7359,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52106 * enable outbound interrupt coalescing in accelerator mode;
52107 */
52108 if (trans_support & CFGTBL_Trans_io_accel1) {
52109 - access = SA5_ioaccel_mode1_access;
52110 + access = &SA5_ioaccel_mode1_access;
52111 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
52112 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
52113 } else {
52114 if (trans_support & CFGTBL_Trans_io_accel2) {
52115 - access = SA5_ioaccel_mode2_access;
52116 + access = &SA5_ioaccel_mode2_access;
52117 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
52118 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
52119 }
52120 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
52121 index 24472ce..8782caf 100644
52122 --- a/drivers/scsi/hpsa.h
52123 +++ b/drivers/scsi/hpsa.h
52124 @@ -127,7 +127,7 @@ struct ctlr_info {
52125 unsigned int msix_vector;
52126 unsigned int msi_vector;
52127 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
52128 - struct access_method access;
52129 + struct access_method *access;
52130 char hba_mode_enabled;
52131
52132 /* queue and queue Info */
52133 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
52134 }
52135
52136 static struct access_method SA5_access = {
52137 - SA5_submit_command,
52138 - SA5_intr_mask,
52139 - SA5_fifo_full,
52140 - SA5_intr_pending,
52141 - SA5_completed,
52142 + .submit_command = SA5_submit_command,
52143 + .set_intr_mask = SA5_intr_mask,
52144 + .fifo_full = SA5_fifo_full,
52145 + .intr_pending = SA5_intr_pending,
52146 + .command_completed = SA5_completed,
52147 };
52148
52149 static struct access_method SA5_ioaccel_mode1_access = {
52150 - SA5_submit_command,
52151 - SA5_performant_intr_mask,
52152 - SA5_fifo_full,
52153 - SA5_ioaccel_mode1_intr_pending,
52154 - SA5_ioaccel_mode1_completed,
52155 + .submit_command = SA5_submit_command,
52156 + .set_intr_mask = SA5_performant_intr_mask,
52157 + .fifo_full = SA5_fifo_full,
52158 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
52159 + .command_completed = SA5_ioaccel_mode1_completed,
52160 };
52161
52162 static struct access_method SA5_ioaccel_mode2_access = {
52163 - SA5_submit_command_ioaccel2,
52164 - SA5_performant_intr_mask,
52165 - SA5_fifo_full,
52166 - SA5_performant_intr_pending,
52167 - SA5_performant_completed,
52168 + .submit_command = SA5_submit_command_ioaccel2,
52169 + .set_intr_mask = SA5_performant_intr_mask,
52170 + .fifo_full = SA5_fifo_full,
52171 + .intr_pending = SA5_performant_intr_pending,
52172 + .command_completed = SA5_performant_completed,
52173 };
52174
52175 static struct access_method SA5_performant_access = {
52176 - SA5_submit_command,
52177 - SA5_performant_intr_mask,
52178 - SA5_fifo_full,
52179 - SA5_performant_intr_pending,
52180 - SA5_performant_completed,
52181 + .submit_command = SA5_submit_command,
52182 + .set_intr_mask = SA5_performant_intr_mask,
52183 + .fifo_full = SA5_fifo_full,
52184 + .intr_pending = SA5_performant_intr_pending,
52185 + .command_completed = SA5_performant_completed,
52186 };
52187
52188 static struct access_method SA5_performant_access_no_read = {
52189 - SA5_submit_command_no_read,
52190 - SA5_performant_intr_mask,
52191 - SA5_fifo_full,
52192 - SA5_performant_intr_pending,
52193 - SA5_performant_completed,
52194 + .submit_command = SA5_submit_command_no_read,
52195 + .set_intr_mask = SA5_performant_intr_mask,
52196 + .fifo_full = SA5_fifo_full,
52197 + .intr_pending = SA5_performant_intr_pending,
52198 + .command_completed = SA5_performant_completed,
52199 };
52200
52201 struct board_type {
52202 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
52203 index 1b3a094..068e683 100644
52204 --- a/drivers/scsi/libfc/fc_exch.c
52205 +++ b/drivers/scsi/libfc/fc_exch.c
52206 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
52207 u16 pool_max_index;
52208
52209 struct {
52210 - atomic_t no_free_exch;
52211 - atomic_t no_free_exch_xid;
52212 - atomic_t xid_not_found;
52213 - atomic_t xid_busy;
52214 - atomic_t seq_not_found;
52215 - atomic_t non_bls_resp;
52216 + atomic_unchecked_t no_free_exch;
52217 + atomic_unchecked_t no_free_exch_xid;
52218 + atomic_unchecked_t xid_not_found;
52219 + atomic_unchecked_t xid_busy;
52220 + atomic_unchecked_t seq_not_found;
52221 + atomic_unchecked_t non_bls_resp;
52222 } stats;
52223 };
52224
52225 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
52226 /* allocate memory for exchange */
52227 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
52228 if (!ep) {
52229 - atomic_inc(&mp->stats.no_free_exch);
52230 + atomic_inc_unchecked(&mp->stats.no_free_exch);
52231 goto out;
52232 }
52233 memset(ep, 0, sizeof(*ep));
52234 @@ -874,7 +874,7 @@ out:
52235 return ep;
52236 err:
52237 spin_unlock_bh(&pool->lock);
52238 - atomic_inc(&mp->stats.no_free_exch_xid);
52239 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
52240 mempool_free(ep, mp->ep_pool);
52241 return NULL;
52242 }
52243 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52244 xid = ntohs(fh->fh_ox_id); /* we originated exch */
52245 ep = fc_exch_find(mp, xid);
52246 if (!ep) {
52247 - atomic_inc(&mp->stats.xid_not_found);
52248 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52249 reject = FC_RJT_OX_ID;
52250 goto out;
52251 }
52252 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52253 ep = fc_exch_find(mp, xid);
52254 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
52255 if (ep) {
52256 - atomic_inc(&mp->stats.xid_busy);
52257 + atomic_inc_unchecked(&mp->stats.xid_busy);
52258 reject = FC_RJT_RX_ID;
52259 goto rel;
52260 }
52261 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52262 }
52263 xid = ep->xid; /* get our XID */
52264 } else if (!ep) {
52265 - atomic_inc(&mp->stats.xid_not_found);
52266 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52267 reject = FC_RJT_RX_ID; /* XID not found */
52268 goto out;
52269 }
52270 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52271 } else {
52272 sp = &ep->seq;
52273 if (sp->id != fh->fh_seq_id) {
52274 - atomic_inc(&mp->stats.seq_not_found);
52275 + atomic_inc_unchecked(&mp->stats.seq_not_found);
52276 if (f_ctl & FC_FC_END_SEQ) {
52277 /*
52278 * Update sequence_id based on incoming last
52279 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52280
52281 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
52282 if (!ep) {
52283 - atomic_inc(&mp->stats.xid_not_found);
52284 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52285 goto out;
52286 }
52287 if (ep->esb_stat & ESB_ST_COMPLETE) {
52288 - atomic_inc(&mp->stats.xid_not_found);
52289 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52290 goto rel;
52291 }
52292 if (ep->rxid == FC_XID_UNKNOWN)
52293 ep->rxid = ntohs(fh->fh_rx_id);
52294 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
52295 - atomic_inc(&mp->stats.xid_not_found);
52296 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52297 goto rel;
52298 }
52299 if (ep->did != ntoh24(fh->fh_s_id) &&
52300 ep->did != FC_FID_FLOGI) {
52301 - atomic_inc(&mp->stats.xid_not_found);
52302 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52303 goto rel;
52304 }
52305 sof = fr_sof(fp);
52306 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52307 sp->ssb_stat |= SSB_ST_RESP;
52308 sp->id = fh->fh_seq_id;
52309 } else if (sp->id != fh->fh_seq_id) {
52310 - atomic_inc(&mp->stats.seq_not_found);
52311 + atomic_inc_unchecked(&mp->stats.seq_not_found);
52312 goto rel;
52313 }
52314
52315 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52316 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
52317
52318 if (!sp)
52319 - atomic_inc(&mp->stats.xid_not_found);
52320 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52321 else
52322 - atomic_inc(&mp->stats.non_bls_resp);
52323 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
52324
52325 fc_frame_free(fp);
52326 }
52327 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
52328
52329 list_for_each_entry(ema, &lport->ema_list, ema_list) {
52330 mp = ema->mp;
52331 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
52332 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
52333 st->fc_no_free_exch_xid +=
52334 - atomic_read(&mp->stats.no_free_exch_xid);
52335 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
52336 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
52337 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
52338 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
52339 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
52340 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
52341 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
52342 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
52343 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
52344 }
52345 }
52346 EXPORT_SYMBOL(fc_exch_update_stats);
52347 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
52348 index 766098a..1c6c971 100644
52349 --- a/drivers/scsi/libsas/sas_ata.c
52350 +++ b/drivers/scsi/libsas/sas_ata.c
52351 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
52352 .postreset = ata_std_postreset,
52353 .error_handler = ata_std_error_handler,
52354 .post_internal_cmd = sas_ata_post_internal,
52355 - .qc_defer = ata_std_qc_defer,
52356 + .qc_defer = ata_std_qc_defer,
52357 .qc_prep = ata_noop_qc_prep,
52358 .qc_issue = sas_ata_qc_issue,
52359 .qc_fill_rtf = sas_ata_qc_fill_rtf,
52360 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
52361 index 434e903..5a4a79b 100644
52362 --- a/drivers/scsi/lpfc/lpfc.h
52363 +++ b/drivers/scsi/lpfc/lpfc.h
52364 @@ -430,7 +430,7 @@ struct lpfc_vport {
52365 struct dentry *debug_nodelist;
52366 struct dentry *vport_debugfs_root;
52367 struct lpfc_debugfs_trc *disc_trc;
52368 - atomic_t disc_trc_cnt;
52369 + atomic_unchecked_t disc_trc_cnt;
52370 #endif
52371 uint8_t stat_data_enabled;
52372 uint8_t stat_data_blocked;
52373 @@ -880,8 +880,8 @@ struct lpfc_hba {
52374 struct timer_list fabric_block_timer;
52375 unsigned long bit_flags;
52376 #define FABRIC_COMANDS_BLOCKED 0
52377 - atomic_t num_rsrc_err;
52378 - atomic_t num_cmd_success;
52379 + atomic_unchecked_t num_rsrc_err;
52380 + atomic_unchecked_t num_cmd_success;
52381 unsigned long last_rsrc_error_time;
52382 unsigned long last_ramp_down_time;
52383 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
52384 @@ -916,7 +916,7 @@ struct lpfc_hba {
52385
52386 struct dentry *debug_slow_ring_trc;
52387 struct lpfc_debugfs_trc *slow_ring_trc;
52388 - atomic_t slow_ring_trc_cnt;
52389 + atomic_unchecked_t slow_ring_trc_cnt;
52390 /* iDiag debugfs sub-directory */
52391 struct dentry *idiag_root;
52392 struct dentry *idiag_pci_cfg;
52393 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
52394 index b0aedce..89c6ca6 100644
52395 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
52396 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
52397 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
52398
52399 #include <linux/debugfs.h>
52400
52401 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52402 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52403 static unsigned long lpfc_debugfs_start_time = 0L;
52404
52405 /* iDiag */
52406 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
52407 lpfc_debugfs_enable = 0;
52408
52409 len = 0;
52410 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
52411 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
52412 (lpfc_debugfs_max_disc_trc - 1);
52413 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
52414 dtp = vport->disc_trc + i;
52415 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
52416 lpfc_debugfs_enable = 0;
52417
52418 len = 0;
52419 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
52420 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
52421 (lpfc_debugfs_max_slow_ring_trc - 1);
52422 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
52423 dtp = phba->slow_ring_trc + i;
52424 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
52425 !vport || !vport->disc_trc)
52426 return;
52427
52428 - index = atomic_inc_return(&vport->disc_trc_cnt) &
52429 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
52430 (lpfc_debugfs_max_disc_trc - 1);
52431 dtp = vport->disc_trc + index;
52432 dtp->fmt = fmt;
52433 dtp->data1 = data1;
52434 dtp->data2 = data2;
52435 dtp->data3 = data3;
52436 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52437 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52438 dtp->jif = jiffies;
52439 #endif
52440 return;
52441 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
52442 !phba || !phba->slow_ring_trc)
52443 return;
52444
52445 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
52446 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
52447 (lpfc_debugfs_max_slow_ring_trc - 1);
52448 dtp = phba->slow_ring_trc + index;
52449 dtp->fmt = fmt;
52450 dtp->data1 = data1;
52451 dtp->data2 = data2;
52452 dtp->data3 = data3;
52453 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52454 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52455 dtp->jif = jiffies;
52456 #endif
52457 return;
52458 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52459 "slow_ring buffer\n");
52460 goto debug_failed;
52461 }
52462 - atomic_set(&phba->slow_ring_trc_cnt, 0);
52463 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
52464 memset(phba->slow_ring_trc, 0,
52465 (sizeof(struct lpfc_debugfs_trc) *
52466 lpfc_debugfs_max_slow_ring_trc));
52467 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52468 "buffer\n");
52469 goto debug_failed;
52470 }
52471 - atomic_set(&vport->disc_trc_cnt, 0);
52472 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
52473
52474 snprintf(name, sizeof(name), "discovery_trace");
52475 vport->debug_disc_trc =
52476 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
52477 index 06f9a5b..82812092 100644
52478 --- a/drivers/scsi/lpfc/lpfc_init.c
52479 +++ b/drivers/scsi/lpfc/lpfc_init.c
52480 @@ -11296,8 +11296,10 @@ lpfc_init(void)
52481 "misc_register returned with status %d", error);
52482
52483 if (lpfc_enable_npiv) {
52484 - lpfc_transport_functions.vport_create = lpfc_vport_create;
52485 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52486 + pax_open_kernel();
52487 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
52488 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52489 + pax_close_kernel();
52490 }
52491 lpfc_transport_template =
52492 fc_attach_transport(&lpfc_transport_functions);
52493 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
52494 index 2df11da..e660a2c 100644
52495 --- a/drivers/scsi/lpfc/lpfc_scsi.c
52496 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
52497 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
52498 uint32_t evt_posted;
52499
52500 spin_lock_irqsave(&phba->hbalock, flags);
52501 - atomic_inc(&phba->num_rsrc_err);
52502 + atomic_inc_unchecked(&phba->num_rsrc_err);
52503 phba->last_rsrc_error_time = jiffies;
52504
52505 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
52506 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52507 unsigned long num_rsrc_err, num_cmd_success;
52508 int i;
52509
52510 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
52511 - num_cmd_success = atomic_read(&phba->num_cmd_success);
52512 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
52513 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
52514
52515 /*
52516 * The error and success command counters are global per
52517 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52518 }
52519 }
52520 lpfc_destroy_vport_work_array(phba, vports);
52521 - atomic_set(&phba->num_rsrc_err, 0);
52522 - atomic_set(&phba->num_cmd_success, 0);
52523 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
52524 + atomic_set_unchecked(&phba->num_cmd_success, 0);
52525 }
52526
52527 /**
52528 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52529 index 5055f92..376cd98 100644
52530 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52531 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52532 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
52533 {
52534 struct scsi_device *sdev = to_scsi_device(dev);
52535 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52536 - static struct _raid_device *raid_device;
52537 + struct _raid_device *raid_device;
52538 unsigned long flags;
52539 Mpi2RaidVolPage0_t vol_pg0;
52540 Mpi2ConfigReply_t mpi_reply;
52541 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
52542 {
52543 struct scsi_device *sdev = to_scsi_device(dev);
52544 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52545 - static struct _raid_device *raid_device;
52546 + struct _raid_device *raid_device;
52547 unsigned long flags;
52548 Mpi2RaidVolPage0_t vol_pg0;
52549 Mpi2ConfigReply_t mpi_reply;
52550 @@ -6631,7 +6631,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
52551 struct fw_event_work *fw_event)
52552 {
52553 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
52554 - static struct _raid_device *raid_device;
52555 + struct _raid_device *raid_device;
52556 unsigned long flags;
52557 u16 handle;
52558
52559 @@ -7102,7 +7102,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
52560 u64 sas_address;
52561 struct _sas_device *sas_device;
52562 struct _sas_node *expander_device;
52563 - static struct _raid_device *raid_device;
52564 + struct _raid_device *raid_device;
52565 u8 retry_count;
52566 unsigned long flags;
52567
52568 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
52569 index be8ce54..94ed33a 100644
52570 --- a/drivers/scsi/pmcraid.c
52571 +++ b/drivers/scsi/pmcraid.c
52572 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
52573 res->scsi_dev = scsi_dev;
52574 scsi_dev->hostdata = res;
52575 res->change_detected = 0;
52576 - atomic_set(&res->read_failures, 0);
52577 - atomic_set(&res->write_failures, 0);
52578 + atomic_set_unchecked(&res->read_failures, 0);
52579 + atomic_set_unchecked(&res->write_failures, 0);
52580 rc = 0;
52581 }
52582 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
52583 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
52584
52585 /* If this was a SCSI read/write command keep count of errors */
52586 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
52587 - atomic_inc(&res->read_failures);
52588 + atomic_inc_unchecked(&res->read_failures);
52589 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
52590 - atomic_inc(&res->write_failures);
52591 + atomic_inc_unchecked(&res->write_failures);
52592
52593 if (!RES_IS_GSCSI(res->cfg_entry) &&
52594 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
52595 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
52596 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52597 * hrrq_id assigned here in queuecommand
52598 */
52599 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52600 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52601 pinstance->num_hrrq;
52602 cmd->cmd_done = pmcraid_io_done;
52603
52604 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
52605 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52606 * hrrq_id assigned here in queuecommand
52607 */
52608 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52609 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52610 pinstance->num_hrrq;
52611
52612 if (request_size) {
52613 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
52614
52615 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
52616 /* add resources only after host is added into system */
52617 - if (!atomic_read(&pinstance->expose_resources))
52618 + if (!atomic_read_unchecked(&pinstance->expose_resources))
52619 return;
52620
52621 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
52622 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
52623 init_waitqueue_head(&pinstance->reset_wait_q);
52624
52625 atomic_set(&pinstance->outstanding_cmds, 0);
52626 - atomic_set(&pinstance->last_message_id, 0);
52627 - atomic_set(&pinstance->expose_resources, 0);
52628 + atomic_set_unchecked(&pinstance->last_message_id, 0);
52629 + atomic_set_unchecked(&pinstance->expose_resources, 0);
52630
52631 INIT_LIST_HEAD(&pinstance->free_res_q);
52632 INIT_LIST_HEAD(&pinstance->used_res_q);
52633 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
52634 /* Schedule worker thread to handle CCN and take care of adding and
52635 * removing devices to OS
52636 */
52637 - atomic_set(&pinstance->expose_resources, 1);
52638 + atomic_set_unchecked(&pinstance->expose_resources, 1);
52639 schedule_work(&pinstance->worker_q);
52640 return rc;
52641
52642 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
52643 index e1d150f..6c6df44 100644
52644 --- a/drivers/scsi/pmcraid.h
52645 +++ b/drivers/scsi/pmcraid.h
52646 @@ -748,7 +748,7 @@ struct pmcraid_instance {
52647 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
52648
52649 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
52650 - atomic_t last_message_id;
52651 + atomic_unchecked_t last_message_id;
52652
52653 /* configuration table */
52654 struct pmcraid_config_table *cfg_table;
52655 @@ -777,7 +777,7 @@ struct pmcraid_instance {
52656 atomic_t outstanding_cmds;
52657
52658 /* should add/delete resources to mid-layer now ?*/
52659 - atomic_t expose_resources;
52660 + atomic_unchecked_t expose_resources;
52661
52662
52663
52664 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
52665 struct pmcraid_config_table_entry_ext cfg_entry_ext;
52666 };
52667 struct scsi_device *scsi_dev; /* Link scsi_device structure */
52668 - atomic_t read_failures; /* count of failed READ commands */
52669 - atomic_t write_failures; /* count of failed WRITE commands */
52670 + atomic_unchecked_t read_failures; /* count of failed READ commands */
52671 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
52672
52673 /* To indicate add/delete/modify during CCN */
52674 u8 change_detected;
52675 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
52676 index 16fe519..3b1ec82 100644
52677 --- a/drivers/scsi/qla2xxx/qla_attr.c
52678 +++ b/drivers/scsi/qla2xxx/qla_attr.c
52679 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
52680 return 0;
52681 }
52682
52683 -struct fc_function_template qla2xxx_transport_functions = {
52684 +fc_function_template_no_const qla2xxx_transport_functions = {
52685
52686 .show_host_node_name = 1,
52687 .show_host_port_name = 1,
52688 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
52689 .bsg_timeout = qla24xx_bsg_timeout,
52690 };
52691
52692 -struct fc_function_template qla2xxx_transport_vport_functions = {
52693 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
52694
52695 .show_host_node_name = 1,
52696 .show_host_port_name = 1,
52697 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
52698 index d48dea8..0845f78 100644
52699 --- a/drivers/scsi/qla2xxx/qla_gbl.h
52700 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
52701 @@ -569,8 +569,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
52702 struct device_attribute;
52703 extern struct device_attribute *qla2x00_host_attrs[];
52704 struct fc_function_template;
52705 -extern struct fc_function_template qla2xxx_transport_functions;
52706 -extern struct fc_function_template qla2xxx_transport_vport_functions;
52707 +extern fc_function_template_no_const qla2xxx_transport_functions;
52708 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
52709 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
52710 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
52711 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
52712 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
52713 index d96bfb5..d7afe90 100644
52714 --- a/drivers/scsi/qla2xxx/qla_os.c
52715 +++ b/drivers/scsi/qla2xxx/qla_os.c
52716 @@ -1490,8 +1490,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
52717 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
52718 /* Ok, a 64bit DMA mask is applicable. */
52719 ha->flags.enable_64bit_addressing = 1;
52720 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52721 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52722 + pax_open_kernel();
52723 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52724 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52725 + pax_close_kernel();
52726 return;
52727 }
52728 }
52729 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
52730 index 8f6d0fb..1b21097 100644
52731 --- a/drivers/scsi/qla4xxx/ql4_def.h
52732 +++ b/drivers/scsi/qla4xxx/ql4_def.h
52733 @@ -305,7 +305,7 @@ struct ddb_entry {
52734 * (4000 only) */
52735 atomic_t relogin_timer; /* Max Time to wait for
52736 * relogin to complete */
52737 - atomic_t relogin_retry_count; /* Num of times relogin has been
52738 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
52739 * retried */
52740 uint32_t default_time2wait; /* Default Min time between
52741 * relogins (+aens) */
52742 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
52743 index 3202063..f9f0ff6 100644
52744 --- a/drivers/scsi/qla4xxx/ql4_os.c
52745 +++ b/drivers/scsi/qla4xxx/ql4_os.c
52746 @@ -4494,12 +4494,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
52747 */
52748 if (!iscsi_is_session_online(cls_sess)) {
52749 /* Reset retry relogin timer */
52750 - atomic_inc(&ddb_entry->relogin_retry_count);
52751 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
52752 DEBUG2(ql4_printk(KERN_INFO, ha,
52753 "%s: index[%d] relogin timed out-retrying"
52754 " relogin (%d), retry (%d)\n", __func__,
52755 ddb_entry->fw_ddb_index,
52756 - atomic_read(&ddb_entry->relogin_retry_count),
52757 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
52758 ddb_entry->default_time2wait + 4));
52759 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
52760 atomic_set(&ddb_entry->retry_relogin_timer,
52761 @@ -6607,7 +6607,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
52762
52763 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
52764 atomic_set(&ddb_entry->relogin_timer, 0);
52765 - atomic_set(&ddb_entry->relogin_retry_count, 0);
52766 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
52767 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
52768 ddb_entry->default_relogin_timeout =
52769 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
52770 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
52771 index 88d46fe..7351be5 100644
52772 --- a/drivers/scsi/scsi.c
52773 +++ b/drivers/scsi/scsi.c
52774 @@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
52775 struct Scsi_Host *host = cmd->device->host;
52776 int rtn = 0;
52777
52778 - atomic_inc(&cmd->device->iorequest_cnt);
52779 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52780
52781 /* check if the device is still usable */
52782 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
52783 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
52784 index 3f50dfc..86af487 100644
52785 --- a/drivers/scsi/scsi_lib.c
52786 +++ b/drivers/scsi/scsi_lib.c
52787 @@ -1423,7 +1423,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
52788 shost = sdev->host;
52789 scsi_init_cmd_errh(cmd);
52790 cmd->result = DID_NO_CONNECT << 16;
52791 - atomic_inc(&cmd->device->iorequest_cnt);
52792 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52793
52794 /*
52795 * SCSI request completion path will do scsi_device_unbusy(),
52796 @@ -1449,9 +1449,9 @@ static void scsi_softirq_done(struct request *rq)
52797
52798 INIT_LIST_HEAD(&cmd->eh_entry);
52799
52800 - atomic_inc(&cmd->device->iodone_cnt);
52801 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
52802 if (cmd->result)
52803 - atomic_inc(&cmd->device->ioerr_cnt);
52804 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
52805
52806 disposition = scsi_decide_disposition(cmd);
52807 if (disposition != SUCCESS &&
52808 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
52809 index 074e8cc..f612e5c 100644
52810 --- a/drivers/scsi/scsi_sysfs.c
52811 +++ b/drivers/scsi/scsi_sysfs.c
52812 @@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
52813 char *buf) \
52814 { \
52815 struct scsi_device *sdev = to_scsi_device(dev); \
52816 - unsigned long long count = atomic_read(&sdev->field); \
52817 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
52818 return snprintf(buf, 20, "0x%llx\n", count); \
52819 } \
52820 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
52821 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
52822 index e51add0..1e06a96 100644
52823 --- a/drivers/scsi/scsi_tgt_lib.c
52824 +++ b/drivers/scsi/scsi_tgt_lib.c
52825 @@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
52826 int err;
52827
52828 dprintk("%lx %u\n", uaddr, len);
52829 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
52830 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
52831 if (err) {
52832 /*
52833 * TODO: need to fixup sg_tablesize, max_segment_size,
52834 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
52835 index 521f583..6b15966 100644
52836 --- a/drivers/scsi/scsi_transport_fc.c
52837 +++ b/drivers/scsi/scsi_transport_fc.c
52838 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
52839 * Netlink Infrastructure
52840 */
52841
52842 -static atomic_t fc_event_seq;
52843 +static atomic_unchecked_t fc_event_seq;
52844
52845 /**
52846 * fc_get_event_number - Obtain the next sequential FC event number
52847 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
52848 u32
52849 fc_get_event_number(void)
52850 {
52851 - return atomic_add_return(1, &fc_event_seq);
52852 + return atomic_add_return_unchecked(1, &fc_event_seq);
52853 }
52854 EXPORT_SYMBOL(fc_get_event_number);
52855
52856 @@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
52857 {
52858 int error;
52859
52860 - atomic_set(&fc_event_seq, 0);
52861 + atomic_set_unchecked(&fc_event_seq, 0);
52862
52863 error = transport_class_register(&fc_host_class);
52864 if (error)
52865 @@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
52866 char *cp;
52867
52868 *val = simple_strtoul(buf, &cp, 0);
52869 - if ((*cp && (*cp != '\n')) || (*val < 0))
52870 + if (*cp && (*cp != '\n'))
52871 return -EINVAL;
52872 /*
52873 * Check for overflow; dev_loss_tmo is u32
52874 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
52875 index 0102a2d..cc3f8e9 100644
52876 --- a/drivers/scsi/scsi_transport_iscsi.c
52877 +++ b/drivers/scsi/scsi_transport_iscsi.c
52878 @@ -79,7 +79,7 @@ struct iscsi_internal {
52879 struct transport_container session_cont;
52880 };
52881
52882 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
52883 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
52884 static struct workqueue_struct *iscsi_eh_timer_workq;
52885
52886 static DEFINE_IDA(iscsi_sess_ida);
52887 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
52888 int err;
52889
52890 ihost = shost->shost_data;
52891 - session->sid = atomic_add_return(1, &iscsi_session_nr);
52892 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
52893
52894 if (target_id == ISCSI_MAX_TARGET) {
52895 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
52896 @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
52897 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
52898 ISCSI_TRANSPORT_VERSION);
52899
52900 - atomic_set(&iscsi_session_nr, 0);
52901 + atomic_set_unchecked(&iscsi_session_nr, 0);
52902
52903 err = class_register(&iscsi_transport_class);
52904 if (err)
52905 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
52906 index 13e8983..d306a68 100644
52907 --- a/drivers/scsi/scsi_transport_srp.c
52908 +++ b/drivers/scsi/scsi_transport_srp.c
52909 @@ -36,7 +36,7 @@
52910 #include "scsi_transport_srp_internal.h"
52911
52912 struct srp_host_attrs {
52913 - atomic_t next_port_id;
52914 + atomic_unchecked_t next_port_id;
52915 };
52916 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
52917
52918 @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
52919 struct Scsi_Host *shost = dev_to_shost(dev);
52920 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
52921
52922 - atomic_set(&srp_host->next_port_id, 0);
52923 + atomic_set_unchecked(&srp_host->next_port_id, 0);
52924 return 0;
52925 }
52926
52927 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
52928 rport_fast_io_fail_timedout);
52929 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
52930
52931 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
52932 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
52933 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
52934
52935 transport_setup_device(&rport->dev);
52936 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
52937 index 6825eda..be470c4 100644
52938 --- a/drivers/scsi/sd.c
52939 +++ b/drivers/scsi/sd.c
52940 @@ -2954,7 +2954,7 @@ static int sd_probe(struct device *dev)
52941 sdkp->disk = gd;
52942 sdkp->index = index;
52943 atomic_set(&sdkp->openers, 0);
52944 - atomic_set(&sdkp->device->ioerr_cnt, 0);
52945 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
52946
52947 if (!sdp->request_queue->rq_timeout) {
52948 if (sdp->type != TYPE_MOD)
52949 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
52950 index 53268aab..17c2764 100644
52951 --- a/drivers/scsi/sg.c
52952 +++ b/drivers/scsi/sg.c
52953 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
52954 sdp->disk->disk_name,
52955 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
52956 NULL,
52957 - (char *)arg);
52958 + (char __user *)arg);
52959 case BLKTRACESTART:
52960 return blk_trace_startstop(sdp->device->request_queue, 1);
52961 case BLKTRACESTOP:
52962 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
52963 index d4f9670..d37b662 100644
52964 --- a/drivers/spi/spi.c
52965 +++ b/drivers/spi/spi.c
52966 @@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
52967 EXPORT_SYMBOL_GPL(spi_bus_unlock);
52968
52969 /* portable code must never pass more than 32 bytes */
52970 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
52971 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
52972
52973 static u8 *buf;
52974
52975 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
52976 index c341ac1..bf9799f 100644
52977 --- a/drivers/staging/android/timed_output.c
52978 +++ b/drivers/staging/android/timed_output.c
52979 @@ -25,7 +25,7 @@
52980 #include "timed_output.h"
52981
52982 static struct class *timed_output_class;
52983 -static atomic_t device_count;
52984 +static atomic_unchecked_t device_count;
52985
52986 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
52987 char *buf)
52988 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
52989 timed_output_class = class_create(THIS_MODULE, "timed_output");
52990 if (IS_ERR(timed_output_class))
52991 return PTR_ERR(timed_output_class);
52992 - atomic_set(&device_count, 0);
52993 + atomic_set_unchecked(&device_count, 0);
52994 timed_output_class->dev_groups = timed_output_groups;
52995 }
52996
52997 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
52998 if (ret < 0)
52999 return ret;
53000
53001 - tdev->index = atomic_inc_return(&device_count);
53002 + tdev->index = atomic_inc_return_unchecked(&device_count);
53003 tdev->dev = device_create(timed_output_class, NULL,
53004 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
53005 if (IS_ERR(tdev->dev))
53006 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
53007 index fe47cd3..19a1bd1 100644
53008 --- a/drivers/staging/gdm724x/gdm_tty.c
53009 +++ b/drivers/staging/gdm724x/gdm_tty.c
53010 @@ -44,7 +44,7 @@
53011 #define gdm_tty_send_control(n, r, v, d, l) (\
53012 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
53013
53014 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
53015 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
53016
53017 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
53018 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
53019 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
53020 index def8280..e3fd96a 100644
53021 --- a/drivers/staging/imx-drm/imx-drm-core.c
53022 +++ b/drivers/staging/imx-drm/imx-drm-core.c
53023 @@ -355,7 +355,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
53024 if (imxdrm->pipes >= MAX_CRTC)
53025 return -EINVAL;
53026
53027 - if (imxdrm->drm->open_count)
53028 + if (local_read(&imxdrm->drm->open_count))
53029 return -EBUSY;
53030
53031 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
53032 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
53033 index 3f8020c..649fded 100644
53034 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
53035 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
53036 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
53037 return 0;
53038 }
53039
53040 -sfw_test_client_ops_t brw_test_client;
53041 -void brw_init_test_client(void)
53042 -{
53043 - brw_test_client.tso_init = brw_client_init;
53044 - brw_test_client.tso_fini = brw_client_fini;
53045 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
53046 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
53047 +sfw_test_client_ops_t brw_test_client = {
53048 + .tso_init = brw_client_init,
53049 + .tso_fini = brw_client_fini,
53050 + .tso_prep_rpc = brw_client_prep_rpc,
53051 + .tso_done_rpc = brw_client_done_rpc,
53052 };
53053
53054 srpc_service_t brw_test_service;
53055 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
53056 index 050723a..fa6fdf1 100644
53057 --- a/drivers/staging/lustre/lnet/selftest/framework.c
53058 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
53059 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
53060
53061 extern sfw_test_client_ops_t ping_test_client;
53062 extern srpc_service_t ping_test_service;
53063 -extern void ping_init_test_client(void);
53064 extern void ping_init_test_service(void);
53065
53066 extern sfw_test_client_ops_t brw_test_client;
53067 extern srpc_service_t brw_test_service;
53068 -extern void brw_init_test_client(void);
53069 extern void brw_init_test_service(void);
53070
53071
53072 @@ -1684,12 +1682,10 @@ sfw_startup (void)
53073 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
53074 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
53075
53076 - brw_init_test_client();
53077 brw_init_test_service();
53078 rc = sfw_register_test(&brw_test_service, &brw_test_client);
53079 LASSERT (rc == 0);
53080
53081 - ping_init_test_client();
53082 ping_init_test_service();
53083 rc = sfw_register_test(&ping_test_service, &ping_test_client);
53084 LASSERT (rc == 0);
53085 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
53086 index 750cac4..e4d751f 100644
53087 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
53088 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
53089 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
53090 return 0;
53091 }
53092
53093 -sfw_test_client_ops_t ping_test_client;
53094 -void ping_init_test_client(void)
53095 -{
53096 - ping_test_client.tso_init = ping_client_init;
53097 - ping_test_client.tso_fini = ping_client_fini;
53098 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
53099 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
53100 -}
53101 +sfw_test_client_ops_t ping_test_client = {
53102 + .tso_init = ping_client_init,
53103 + .tso_fini = ping_client_fini,
53104 + .tso_prep_rpc = ping_client_prep_rpc,
53105 + .tso_done_rpc = ping_client_done_rpc,
53106 +};
53107
53108 srpc_service_t ping_test_service;
53109 void ping_init_test_service(void)
53110 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
53111 index 0c6b784..c64235c 100644
53112 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
53113 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
53114 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
53115 ldlm_completion_callback lcs_completion;
53116 ldlm_blocking_callback lcs_blocking;
53117 ldlm_glimpse_callback lcs_glimpse;
53118 -};
53119 +} __no_const;
53120
53121 /* ldlm_lockd.c */
53122 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
53123 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
53124 index d5c4613..a341678 100644
53125 --- a/drivers/staging/lustre/lustre/include/obd.h
53126 +++ b/drivers/staging/lustre/lustre/include/obd.h
53127 @@ -1439,7 +1439,7 @@ struct md_ops {
53128 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
53129 * wrapper function in include/linux/obd_class.h.
53130 */
53131 -};
53132 +} __no_const;
53133
53134 struct lsm_operations {
53135 void (*lsm_free)(struct lov_stripe_md *);
53136 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53137 index 986bf38..eab2558f 100644
53138 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53139 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53140 @@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
53141 int added = (mode == LCK_NL);
53142 int overlaps = 0;
53143 int splitted = 0;
53144 - const struct ldlm_callback_suite null_cbs = { NULL };
53145 + const struct ldlm_callback_suite null_cbs = { };
53146
53147 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
53148 LPU64" end "LPU64"\n", *flags,
53149 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53150 index e947b91..f408990 100644
53151 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53152 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53153 @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
53154 int LL_PROC_PROTO(proc_console_max_delay_cs)
53155 {
53156 int rc, max_delay_cs;
53157 - ctl_table_t dummy = *table;
53158 + ctl_table_no_const dummy = *table;
53159 cfs_duration_t d;
53160
53161 dummy.data = &max_delay_cs;
53162 @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
53163 int LL_PROC_PROTO(proc_console_min_delay_cs)
53164 {
53165 int rc, min_delay_cs;
53166 - ctl_table_t dummy = *table;
53167 + ctl_table_no_const dummy = *table;
53168 cfs_duration_t d;
53169
53170 dummy.data = &min_delay_cs;
53171 @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
53172 int LL_PROC_PROTO(proc_console_backoff)
53173 {
53174 int rc, backoff;
53175 - ctl_table_t dummy = *table;
53176 + ctl_table_no_const dummy = *table;
53177
53178 dummy.data = &backoff;
53179 dummy.proc_handler = &proc_dointvec;
53180 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
53181 index b16ee08..a3db5c6 100644
53182 --- a/drivers/staging/lustre/lustre/libcfs/module.c
53183 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
53184 @@ -314,11 +314,11 @@ out:
53185
53186
53187 struct cfs_psdev_ops libcfs_psdev_ops = {
53188 - libcfs_psdev_open,
53189 - libcfs_psdev_release,
53190 - NULL,
53191 - NULL,
53192 - libcfs_ioctl
53193 + .p_open = libcfs_psdev_open,
53194 + .p_close = libcfs_psdev_release,
53195 + .p_read = NULL,
53196 + .p_write = NULL,
53197 + .p_ioctl = libcfs_ioctl
53198 };
53199
53200 extern int insert_proc(void);
53201 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
53202 index ae6f61a..03c3d5d 100644
53203 --- a/drivers/staging/lustre/lustre/llite/dir.c
53204 +++ b/drivers/staging/lustre/lustre/llite/dir.c
53205 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
53206 int mode;
53207 int err;
53208
53209 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
53210 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
53211 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
53212 strlen(filename), mode, LUSTRE_OPC_MKDIR,
53213 lump);
53214 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
53215 index f670469..03b7438 100644
53216 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
53217 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
53218 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
53219
53220 static int solo_sysfs_init(struct solo_dev *solo_dev)
53221 {
53222 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
53223 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
53224 struct device *dev = &solo_dev->dev;
53225 const char *driver;
53226 int i;
53227 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
53228 index 74f037b..5b5bb76 100644
53229 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
53230 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
53231 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
53232
53233 int solo_g723_init(struct solo_dev *solo_dev)
53234 {
53235 - static struct snd_device_ops ops = { NULL };
53236 + static struct snd_device_ops ops = { };
53237 struct snd_card *card;
53238 struct snd_kcontrol_new kctl;
53239 char name[32];
53240 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
53241 index 7f2f247..d999137 100644
53242 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
53243 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
53244 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
53245
53246 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
53247 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
53248 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
53249 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
53250 if (p2m_id < 0)
53251 p2m_id = -p2m_id;
53252 }
53253 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
53254 index 8964f8b..36eb087 100644
53255 --- a/drivers/staging/media/solo6x10/solo6x10.h
53256 +++ b/drivers/staging/media/solo6x10/solo6x10.h
53257 @@ -237,7 +237,7 @@ struct solo_dev {
53258
53259 /* P2M DMA Engine */
53260 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
53261 - atomic_t p2m_count;
53262 + atomic_unchecked_t p2m_count;
53263 int p2m_jiffies;
53264 unsigned int p2m_timeouts;
53265
53266 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
53267 index a0f4868..139f1fb 100644
53268 --- a/drivers/staging/octeon/ethernet-rx.c
53269 +++ b/drivers/staging/octeon/ethernet-rx.c
53270 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
53271 /* Increment RX stats for virtual ports */
53272 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
53273 #ifdef CONFIG_64BIT
53274 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
53275 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
53276 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
53277 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
53278 #else
53279 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
53280 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
53281 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
53282 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
53283 #endif
53284 }
53285 netif_receive_skb(skb);
53286 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
53287 dev->name);
53288 */
53289 #ifdef CONFIG_64BIT
53290 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
53291 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
53292 #else
53293 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
53294 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
53295 #endif
53296 dev_kfree_skb_irq(skb);
53297 }
53298 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
53299 index da9dd6b..8e3e0f5 100644
53300 --- a/drivers/staging/octeon/ethernet.c
53301 +++ b/drivers/staging/octeon/ethernet.c
53302 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
53303 * since the RX tasklet also increments it.
53304 */
53305 #ifdef CONFIG_64BIT
53306 - atomic64_add(rx_status.dropped_packets,
53307 - (atomic64_t *)&priv->stats.rx_dropped);
53308 + atomic64_add_unchecked(rx_status.dropped_packets,
53309 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
53310 #else
53311 - atomic_add(rx_status.dropped_packets,
53312 - (atomic_t *)&priv->stats.rx_dropped);
53313 + atomic_add_unchecked(rx_status.dropped_packets,
53314 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
53315 #endif
53316 }
53317
53318 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
53319 index c59fccd..79f8fc2 100644
53320 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
53321 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
53322 @@ -267,7 +267,7 @@ struct hal_ops {
53323 s32 (*c2h_handler)(struct adapter *padapter,
53324 struct c2h_evt_hdr *c2h_evt);
53325 c2h_id_filter c2h_id_filter_ccx;
53326 -};
53327 +} __no_const;
53328
53329 enum rt_eeprom_type {
53330 EEPROM_93C46,
53331 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
53332 index e8790f8..b4a5980 100644
53333 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
53334 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
53335 @@ -124,7 +124,7 @@ struct _io_ops {
53336 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
53337 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
53338 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
53339 -};
53340 +} __no_const;
53341
53342 struct io_req {
53343 struct list_head list;
53344 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
53345 index dc23395..cf7e9b1 100644
53346 --- a/drivers/staging/rtl8712/rtl871x_io.h
53347 +++ b/drivers/staging/rtl8712/rtl871x_io.h
53348 @@ -108,7 +108,7 @@ struct _io_ops {
53349 u8 *pmem);
53350 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
53351 u8 *pmem);
53352 -};
53353 +} __no_const;
53354
53355 struct io_req {
53356 struct list_head list;
53357 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
53358 index a863a98..d272795 100644
53359 --- a/drivers/staging/usbip/vhci.h
53360 +++ b/drivers/staging/usbip/vhci.h
53361 @@ -83,7 +83,7 @@ struct vhci_hcd {
53362 unsigned resuming:1;
53363 unsigned long re_timeout;
53364
53365 - atomic_t seqnum;
53366 + atomic_unchecked_t seqnum;
53367
53368 /*
53369 * NOTE:
53370 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
53371 index 0007d30..c06a693 100644
53372 --- a/drivers/staging/usbip/vhci_hcd.c
53373 +++ b/drivers/staging/usbip/vhci_hcd.c
53374 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
53375
53376 spin_lock(&vdev->priv_lock);
53377
53378 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
53379 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
53380 if (priv->seqnum == 0xffff)
53381 dev_info(&urb->dev->dev, "seqnum max\n");
53382
53383 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
53384 return -ENOMEM;
53385 }
53386
53387 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
53388 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
53389 if (unlink->seqnum == 0xffff)
53390 pr_info("seqnum max\n");
53391
53392 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
53393 vdev->rhport = rhport;
53394 }
53395
53396 - atomic_set(&vhci->seqnum, 0);
53397 + atomic_set_unchecked(&vhci->seqnum, 0);
53398 spin_lock_init(&vhci->lock);
53399
53400 hcd->power_budget = 0; /* no limit */
53401 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
53402 index d07fcb5..358e1e1 100644
53403 --- a/drivers/staging/usbip/vhci_rx.c
53404 +++ b/drivers/staging/usbip/vhci_rx.c
53405 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
53406 if (!urb) {
53407 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
53408 pr_info("max seqnum %d\n",
53409 - atomic_read(&the_controller->seqnum));
53410 + atomic_read_unchecked(&the_controller->seqnum));
53411 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
53412 return;
53413 }
53414 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
53415 index 317c2a8..ffeb4ef 100644
53416 --- a/drivers/staging/vt6655/hostap.c
53417 +++ b/drivers/staging/vt6655/hostap.c
53418 @@ -68,14 +68,13 @@ static int msglevel = MSG_LEVEL_INFO;
53419 *
53420 */
53421
53422 +static net_device_ops_no_const apdev_netdev_ops;
53423 +
53424 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53425 {
53426 PSDevice apdev_priv;
53427 struct net_device *dev = pDevice->dev;
53428 int ret;
53429 - const struct net_device_ops apdev_netdev_ops = {
53430 - .ndo_start_xmit = pDevice->tx_80211,
53431 - };
53432
53433 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
53434
53435 @@ -87,6 +86,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53436 *apdev_priv = *pDevice;
53437 eth_hw_addr_inherit(pDevice->apdev, dev);
53438
53439 + /* only half broken now */
53440 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
53441 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
53442
53443 pDevice->apdev->type = ARPHRD_IEEE80211;
53444 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
53445 index e7e9372..161f530 100644
53446 --- a/drivers/target/sbp/sbp_target.c
53447 +++ b/drivers/target/sbp/sbp_target.c
53448 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
53449
53450 #define SESSION_MAINTENANCE_INTERVAL HZ
53451
53452 -static atomic_t login_id = ATOMIC_INIT(0);
53453 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
53454
53455 static void session_maintenance_work(struct work_struct *);
53456 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
53457 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
53458 login->lun = se_lun;
53459 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
53460 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
53461 - login->login_id = atomic_inc_return(&login_id);
53462 + login->login_id = atomic_inc_return_unchecked(&login_id);
53463
53464 login->tgt_agt = sbp_target_agent_register(login);
53465 if (IS_ERR(login->tgt_agt)) {
53466 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
53467 index 98da901..bb443e8 100644
53468 --- a/drivers/target/target_core_device.c
53469 +++ b/drivers/target/target_core_device.c
53470 @@ -1525,7 +1525,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
53471 spin_lock_init(&dev->se_tmr_lock);
53472 spin_lock_init(&dev->qf_cmd_lock);
53473 sema_init(&dev->caw_sem, 1);
53474 - atomic_set(&dev->dev_ordered_id, 0);
53475 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
53476 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
53477 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
53478 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
53479 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
53480 index 7fa62fc..abdd041 100644
53481 --- a/drivers/target/target_core_transport.c
53482 +++ b/drivers/target/target_core_transport.c
53483 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
53484 * Used to determine when ORDERED commands should go from
53485 * Dormant to Active status.
53486 */
53487 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
53488 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
53489 smp_mb__after_atomic();
53490 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
53491 cmd->se_ordered_id, cmd->sam_task_attr,
53492 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
53493 index 4b2b999..cad9fa5 100644
53494 --- a/drivers/thermal/of-thermal.c
53495 +++ b/drivers/thermal/of-thermal.c
53496 @@ -30,6 +30,7 @@
53497 #include <linux/err.h>
53498 #include <linux/export.h>
53499 #include <linux/string.h>
53500 +#include <linux/mm.h>
53501
53502 #include "thermal_core.h"
53503
53504 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
53505 tz->get_trend = get_trend;
53506 tz->sensor_data = data;
53507
53508 - tzd->ops->get_temp = of_thermal_get_temp;
53509 - tzd->ops->get_trend = of_thermal_get_trend;
53510 + pax_open_kernel();
53511 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
53512 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
53513 + pax_close_kernel();
53514 mutex_unlock(&tzd->lock);
53515
53516 return tzd;
53517 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
53518 return;
53519
53520 mutex_lock(&tzd->lock);
53521 - tzd->ops->get_temp = NULL;
53522 - tzd->ops->get_trend = NULL;
53523 + pax_open_kernel();
53524 + *(void **)&tzd->ops->get_temp = NULL;
53525 + *(void **)&tzd->ops->get_trend = NULL;
53526 + pax_close_kernel();
53527
53528 tz->get_temp = NULL;
53529 tz->get_trend = NULL;
53530 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
53531 index a57bb5a..1f727d33 100644
53532 --- a/drivers/tty/cyclades.c
53533 +++ b/drivers/tty/cyclades.c
53534 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
53535 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
53536 info->port.count);
53537 #endif
53538 - info->port.count++;
53539 + atomic_inc(&info->port.count);
53540 #ifdef CY_DEBUG_COUNT
53541 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
53542 - current->pid, info->port.count);
53543 + current->pid, atomic_read(&info->port.count));
53544 #endif
53545
53546 /*
53547 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
53548 for (j = 0; j < cy_card[i].nports; j++) {
53549 info = &cy_card[i].ports[j];
53550
53551 - if (info->port.count) {
53552 + if (atomic_read(&info->port.count)) {
53553 /* XXX is the ldisc num worth this? */
53554 struct tty_struct *tty;
53555 struct tty_ldisc *ld;
53556 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
53557 index 4fcec1d..5a036f7 100644
53558 --- a/drivers/tty/hvc/hvc_console.c
53559 +++ b/drivers/tty/hvc/hvc_console.c
53560 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
53561
53562 spin_lock_irqsave(&hp->port.lock, flags);
53563 /* Check and then increment for fast path open. */
53564 - if (hp->port.count++ > 0) {
53565 + if (atomic_inc_return(&hp->port.count) > 1) {
53566 spin_unlock_irqrestore(&hp->port.lock, flags);
53567 hvc_kick();
53568 return 0;
53569 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53570
53571 spin_lock_irqsave(&hp->port.lock, flags);
53572
53573 - if (--hp->port.count == 0) {
53574 + if (atomic_dec_return(&hp->port.count) == 0) {
53575 spin_unlock_irqrestore(&hp->port.lock, flags);
53576 /* We are done with the tty pointer now. */
53577 tty_port_tty_set(&hp->port, NULL);
53578 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53579 */
53580 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
53581 } else {
53582 - if (hp->port.count < 0)
53583 + if (atomic_read(&hp->port.count) < 0)
53584 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
53585 - hp->vtermno, hp->port.count);
53586 + hp->vtermno, atomic_read(&hp->port.count));
53587 spin_unlock_irqrestore(&hp->port.lock, flags);
53588 }
53589 }
53590 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
53591 * open->hangup case this can be called after the final close so prevent
53592 * that from happening for now.
53593 */
53594 - if (hp->port.count <= 0) {
53595 + if (atomic_read(&hp->port.count) <= 0) {
53596 spin_unlock_irqrestore(&hp->port.lock, flags);
53597 return;
53598 }
53599
53600 - hp->port.count = 0;
53601 + atomic_set(&hp->port.count, 0);
53602 spin_unlock_irqrestore(&hp->port.lock, flags);
53603 tty_port_tty_set(&hp->port, NULL);
53604
53605 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
53606 return -EPIPE;
53607
53608 /* FIXME what's this (unprotected) check for? */
53609 - if (hp->port.count <= 0)
53610 + if (atomic_read(&hp->port.count) <= 0)
53611 return -EIO;
53612
53613 spin_lock_irqsave(&hp->lock, flags);
53614 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
53615 index 81e939e..95ead10 100644
53616 --- a/drivers/tty/hvc/hvcs.c
53617 +++ b/drivers/tty/hvc/hvcs.c
53618 @@ -83,6 +83,7 @@
53619 #include <asm/hvcserver.h>
53620 #include <asm/uaccess.h>
53621 #include <asm/vio.h>
53622 +#include <asm/local.h>
53623
53624 /*
53625 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
53626 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
53627
53628 spin_lock_irqsave(&hvcsd->lock, flags);
53629
53630 - if (hvcsd->port.count > 0) {
53631 + if (atomic_read(&hvcsd->port.count) > 0) {
53632 spin_unlock_irqrestore(&hvcsd->lock, flags);
53633 printk(KERN_INFO "HVCS: vterm state unchanged. "
53634 "The hvcs device node is still in use.\n");
53635 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
53636 }
53637 }
53638
53639 - hvcsd->port.count = 0;
53640 + atomic_set(&hvcsd->port.count, 0);
53641 hvcsd->port.tty = tty;
53642 tty->driver_data = hvcsd;
53643
53644 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
53645 unsigned long flags;
53646
53647 spin_lock_irqsave(&hvcsd->lock, flags);
53648 - hvcsd->port.count++;
53649 + atomic_inc(&hvcsd->port.count);
53650 hvcsd->todo_mask |= HVCS_SCHED_READ;
53651 spin_unlock_irqrestore(&hvcsd->lock, flags);
53652
53653 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53654 hvcsd = tty->driver_data;
53655
53656 spin_lock_irqsave(&hvcsd->lock, flags);
53657 - if (--hvcsd->port.count == 0) {
53658 + if (atomic_dec_and_test(&hvcsd->port.count)) {
53659
53660 vio_disable_interrupts(hvcsd->vdev);
53661
53662 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53663
53664 free_irq(irq, hvcsd);
53665 return;
53666 - } else if (hvcsd->port.count < 0) {
53667 + } else if (atomic_read(&hvcsd->port.count) < 0) {
53668 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
53669 " is missmanaged.\n",
53670 - hvcsd->vdev->unit_address, hvcsd->port.count);
53671 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
53672 }
53673
53674 spin_unlock_irqrestore(&hvcsd->lock, flags);
53675 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53676
53677 spin_lock_irqsave(&hvcsd->lock, flags);
53678 /* Preserve this so that we know how many kref refs to put */
53679 - temp_open_count = hvcsd->port.count;
53680 + temp_open_count = atomic_read(&hvcsd->port.count);
53681
53682 /*
53683 * Don't kref put inside the spinlock because the destruction
53684 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53685 tty->driver_data = NULL;
53686 hvcsd->port.tty = NULL;
53687
53688 - hvcsd->port.count = 0;
53689 + atomic_set(&hvcsd->port.count, 0);
53690
53691 /* This will drop any buffered data on the floor which is OK in a hangup
53692 * scenario. */
53693 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
53694 * the middle of a write operation? This is a crummy place to do this
53695 * but we want to keep it all in the spinlock.
53696 */
53697 - if (hvcsd->port.count <= 0) {
53698 + if (atomic_read(&hvcsd->port.count) <= 0) {
53699 spin_unlock_irqrestore(&hvcsd->lock, flags);
53700 return -ENODEV;
53701 }
53702 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
53703 {
53704 struct hvcs_struct *hvcsd = tty->driver_data;
53705
53706 - if (!hvcsd || hvcsd->port.count <= 0)
53707 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
53708 return 0;
53709
53710 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
53711 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
53712 index 4190199..06d5bfa 100644
53713 --- a/drivers/tty/hvc/hvsi.c
53714 +++ b/drivers/tty/hvc/hvsi.c
53715 @@ -85,7 +85,7 @@ struct hvsi_struct {
53716 int n_outbuf;
53717 uint32_t vtermno;
53718 uint32_t virq;
53719 - atomic_t seqno; /* HVSI packet sequence number */
53720 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
53721 uint16_t mctrl;
53722 uint8_t state; /* HVSI protocol state */
53723 uint8_t flags;
53724 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
53725
53726 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
53727 packet.hdr.len = sizeof(struct hvsi_query_response);
53728 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53729 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53730 packet.verb = VSV_SEND_VERSION_NUMBER;
53731 packet.u.version = HVSI_VERSION;
53732 packet.query_seqno = query_seqno+1;
53733 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
53734
53735 packet.hdr.type = VS_QUERY_PACKET_HEADER;
53736 packet.hdr.len = sizeof(struct hvsi_query);
53737 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53738 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53739 packet.verb = verb;
53740
53741 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
53742 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
53743 int wrote;
53744
53745 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
53746 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53747 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53748 packet.hdr.len = sizeof(struct hvsi_control);
53749 packet.verb = VSV_SET_MODEM_CTL;
53750 packet.mask = HVSI_TSDTR;
53751 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
53752 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
53753
53754 packet.hdr.type = VS_DATA_PACKET_HEADER;
53755 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53756 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53757 packet.hdr.len = count + sizeof(struct hvsi_header);
53758 memcpy(&packet.data, buf, count);
53759
53760 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
53761 struct hvsi_control packet __ALIGNED__;
53762
53763 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
53764 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53765 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53766 packet.hdr.len = 6;
53767 packet.verb = VSV_CLOSE_PROTOCOL;
53768
53769 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
53770
53771 tty_port_tty_set(&hp->port, tty);
53772 spin_lock_irqsave(&hp->lock, flags);
53773 - hp->port.count++;
53774 + atomic_inc(&hp->port.count);
53775 atomic_set(&hp->seqno, 0);
53776 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
53777 spin_unlock_irqrestore(&hp->lock, flags);
53778 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53779
53780 spin_lock_irqsave(&hp->lock, flags);
53781
53782 - if (--hp->port.count == 0) {
53783 + if (atomic_dec_return(&hp->port.count) == 0) {
53784 tty_port_tty_set(&hp->port, NULL);
53785 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
53786
53787 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53788
53789 spin_lock_irqsave(&hp->lock, flags);
53790 }
53791 - } else if (hp->port.count < 0)
53792 + } else if (atomic_read(&hp->port.count) < 0)
53793 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
53794 - hp - hvsi_ports, hp->port.count);
53795 + hp - hvsi_ports, atomic_read(&hp->port.count));
53796
53797 spin_unlock_irqrestore(&hp->lock, flags);
53798 }
53799 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
53800 tty_port_tty_set(&hp->port, NULL);
53801
53802 spin_lock_irqsave(&hp->lock, flags);
53803 - hp->port.count = 0;
53804 + atomic_set(&hp->port.count, 0);
53805 hp->n_outbuf = 0;
53806 spin_unlock_irqrestore(&hp->lock, flags);
53807 }
53808 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
53809 index 7ae6c29..05c6dba 100644
53810 --- a/drivers/tty/hvc/hvsi_lib.c
53811 +++ b/drivers/tty/hvc/hvsi_lib.c
53812 @@ -8,7 +8,7 @@
53813
53814 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53815 {
53816 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53817 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53818
53819 /* Assumes that always succeeds, works in practice */
53820 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53821 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53822
53823 /* Reset state */
53824 pv->established = 0;
53825 - atomic_set(&pv->seqno, 0);
53826 + atomic_set_unchecked(&pv->seqno, 0);
53827
53828 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53829
53830 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53831 index 17ee3bf..8d2520d 100644
53832 --- a/drivers/tty/ipwireless/tty.c
53833 +++ b/drivers/tty/ipwireless/tty.c
53834 @@ -28,6 +28,7 @@
53835 #include <linux/tty_driver.h>
53836 #include <linux/tty_flip.h>
53837 #include <linux/uaccess.h>
53838 +#include <asm/local.h>
53839
53840 #include "tty.h"
53841 #include "network.h"
53842 @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53843 mutex_unlock(&tty->ipw_tty_mutex);
53844 return -ENODEV;
53845 }
53846 - if (tty->port.count == 0)
53847 + if (atomic_read(&tty->port.count) == 0)
53848 tty->tx_bytes_queued = 0;
53849
53850 - tty->port.count++;
53851 + atomic_inc(&tty->port.count);
53852
53853 tty->port.tty = linux_tty;
53854 linux_tty->driver_data = tty;
53855 @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53856
53857 static void do_ipw_close(struct ipw_tty *tty)
53858 {
53859 - tty->port.count--;
53860 -
53861 - if (tty->port.count == 0) {
53862 + if (atomic_dec_return(&tty->port.count) == 0) {
53863 struct tty_struct *linux_tty = tty->port.tty;
53864
53865 if (linux_tty != NULL) {
53866 @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53867 return;
53868
53869 mutex_lock(&tty->ipw_tty_mutex);
53870 - if (tty->port.count == 0) {
53871 + if (atomic_read(&tty->port.count) == 0) {
53872 mutex_unlock(&tty->ipw_tty_mutex);
53873 return;
53874 }
53875 @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53876
53877 mutex_lock(&tty->ipw_tty_mutex);
53878
53879 - if (!tty->port.count) {
53880 + if (!atomic_read(&tty->port.count)) {
53881 mutex_unlock(&tty->ipw_tty_mutex);
53882 return;
53883 }
53884 @@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53885 return -ENODEV;
53886
53887 mutex_lock(&tty->ipw_tty_mutex);
53888 - if (!tty->port.count) {
53889 + if (!atomic_read(&tty->port.count)) {
53890 mutex_unlock(&tty->ipw_tty_mutex);
53891 return -EINVAL;
53892 }
53893 @@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53894 if (!tty)
53895 return -ENODEV;
53896
53897 - if (!tty->port.count)
53898 + if (!atomic_read(&tty->port.count))
53899 return -EINVAL;
53900
53901 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53902 @@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53903 if (!tty)
53904 return 0;
53905
53906 - if (!tty->port.count)
53907 + if (!atomic_read(&tty->port.count))
53908 return 0;
53909
53910 return tty->tx_bytes_queued;
53911 @@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53912 if (!tty)
53913 return -ENODEV;
53914
53915 - if (!tty->port.count)
53916 + if (!atomic_read(&tty->port.count))
53917 return -EINVAL;
53918
53919 return get_control_lines(tty);
53920 @@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
53921 if (!tty)
53922 return -ENODEV;
53923
53924 - if (!tty->port.count)
53925 + if (!atomic_read(&tty->port.count))
53926 return -EINVAL;
53927
53928 return set_control_lines(tty, set, clear);
53929 @@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
53930 if (!tty)
53931 return -ENODEV;
53932
53933 - if (!tty->port.count)
53934 + if (!atomic_read(&tty->port.count))
53935 return -EINVAL;
53936
53937 /* FIXME: Exactly how is the tty object locked here .. */
53938 @@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
53939 * are gone */
53940 mutex_lock(&ttyj->ipw_tty_mutex);
53941 }
53942 - while (ttyj->port.count)
53943 + while (atomic_read(&ttyj->port.count))
53944 do_ipw_close(ttyj);
53945 ipwireless_disassociate_network_ttys(network,
53946 ttyj->channel_idx);
53947 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
53948 index 1deaca4..c8582d4 100644
53949 --- a/drivers/tty/moxa.c
53950 +++ b/drivers/tty/moxa.c
53951 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
53952 }
53953
53954 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
53955 - ch->port.count++;
53956 + atomic_inc(&ch->port.count);
53957 tty->driver_data = ch;
53958 tty_port_tty_set(&ch->port, tty);
53959 mutex_lock(&ch->port.mutex);
53960 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
53961 index 2ebe47b..3205833 100644
53962 --- a/drivers/tty/n_gsm.c
53963 +++ b/drivers/tty/n_gsm.c
53964 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
53965 spin_lock_init(&dlci->lock);
53966 mutex_init(&dlci->mutex);
53967 dlci->fifo = &dlci->_fifo;
53968 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
53969 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
53970 kfree(dlci);
53971 return NULL;
53972 }
53973 @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
53974 struct gsm_dlci *dlci = tty->driver_data;
53975 struct tty_port *port = &dlci->port;
53976
53977 - port->count++;
53978 + atomic_inc(&port->count);
53979 tty_port_tty_set(port, tty);
53980
53981 dlci->modem_rx = 0;
53982 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
53983 index f44f1ba..a8d5915 100644
53984 --- a/drivers/tty/n_tty.c
53985 +++ b/drivers/tty/n_tty.c
53986 @@ -115,7 +115,7 @@ struct n_tty_data {
53987 int minimum_to_wake;
53988
53989 /* consumer-published */
53990 - size_t read_tail;
53991 + size_t read_tail __intentional_overflow(-1);
53992 size_t line_start;
53993
53994 /* protected by output lock */
53995 @@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
53996 {
53997 *ops = tty_ldisc_N_TTY;
53998 ops->owner = NULL;
53999 - ops->refcount = ops->flags = 0;
54000 + atomic_set(&ops->refcount, 0);
54001 + ops->flags = 0;
54002 }
54003 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
54004 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
54005 index 25c9bc7..24077b7 100644
54006 --- a/drivers/tty/pty.c
54007 +++ b/drivers/tty/pty.c
54008 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
54009 panic("Couldn't register Unix98 pts driver");
54010
54011 /* Now create the /dev/ptmx special device */
54012 + pax_open_kernel();
54013 tty_default_fops(&ptmx_fops);
54014 - ptmx_fops.open = ptmx_open;
54015 + *(void **)&ptmx_fops.open = ptmx_open;
54016 + pax_close_kernel();
54017
54018 cdev_init(&ptmx_cdev, &ptmx_fops);
54019 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
54020 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
54021 index 383c4c7..d408e21 100644
54022 --- a/drivers/tty/rocket.c
54023 +++ b/drivers/tty/rocket.c
54024 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
54025 tty->driver_data = info;
54026 tty_port_tty_set(port, tty);
54027
54028 - if (port->count++ == 0) {
54029 + if (atomic_inc_return(&port->count) == 1) {
54030 atomic_inc(&rp_num_ports_open);
54031
54032 #ifdef ROCKET_DEBUG_OPEN
54033 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
54034 #endif
54035 }
54036 #ifdef ROCKET_DEBUG_OPEN
54037 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
54038 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
54039 #endif
54040
54041 /*
54042 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
54043 spin_unlock_irqrestore(&info->port.lock, flags);
54044 return;
54045 }
54046 - if (info->port.count)
54047 + if (atomic_read(&info->port.count))
54048 atomic_dec(&rp_num_ports_open);
54049 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
54050 spin_unlock_irqrestore(&info->port.lock, flags);
54051 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
54052 index 1274499..f541382 100644
54053 --- a/drivers/tty/serial/ioc4_serial.c
54054 +++ b/drivers/tty/serial/ioc4_serial.c
54055 @@ -437,7 +437,7 @@ struct ioc4_soft {
54056 } is_intr_info[MAX_IOC4_INTR_ENTS];
54057
54058 /* Number of entries active in the above array */
54059 - atomic_t is_num_intrs;
54060 + atomic_unchecked_t is_num_intrs;
54061 } is_intr_type[IOC4_NUM_INTR_TYPES];
54062
54063 /* is_ir_lock must be held while
54064 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
54065 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
54066 || (type == IOC4_OTHER_INTR_TYPE)));
54067
54068 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
54069 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
54070 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
54071
54072 /* Save off the lower level interrupt handler */
54073 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
54074
54075 soft = arg;
54076 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
54077 - num_intrs = (int)atomic_read(
54078 + num_intrs = (int)atomic_read_unchecked(
54079 &soft->is_intr_type[intr_type].is_num_intrs);
54080
54081 this_mir = this_ir = pending_intrs(soft, intr_type);
54082 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
54083 index cfadf29..8cf4595 100644
54084 --- a/drivers/tty/serial/kgdb_nmi.c
54085 +++ b/drivers/tty/serial/kgdb_nmi.c
54086 @@ -51,7 +51,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
54087 * I/O utilities that messages sent to the console will automatically
54088 * be displayed on the dbg_io.
54089 */
54090 - dbg_io_ops->is_console = true;
54091 + pax_open_kernel();
54092 + *(int *)&dbg_io_ops->is_console = true;
54093 + pax_close_kernel();
54094
54095 return 0;
54096 }
54097 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
54098 index a260cde..6b2b5ce 100644
54099 --- a/drivers/tty/serial/kgdboc.c
54100 +++ b/drivers/tty/serial/kgdboc.c
54101 @@ -24,8 +24,9 @@
54102 #define MAX_CONFIG_LEN 40
54103
54104 static struct kgdb_io kgdboc_io_ops;
54105 +static struct kgdb_io kgdboc_io_ops_console;
54106
54107 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
54108 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
54109 static int configured = -1;
54110
54111 static char config[MAX_CONFIG_LEN];
54112 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
54113 kgdboc_unregister_kbd();
54114 if (configured == 1)
54115 kgdb_unregister_io_module(&kgdboc_io_ops);
54116 + else if (configured == 2)
54117 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
54118 }
54119
54120 static int configure_kgdboc(void)
54121 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
54122 int err;
54123 char *cptr = config;
54124 struct console *cons;
54125 + int is_console = 0;
54126
54127 err = kgdboc_option_setup(config);
54128 if (err || !strlen(config) || isspace(config[0]))
54129 goto noconfig;
54130
54131 err = -ENODEV;
54132 - kgdboc_io_ops.is_console = 0;
54133 kgdb_tty_driver = NULL;
54134
54135 kgdboc_use_kms = 0;
54136 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
54137 int idx;
54138 if (cons->device && cons->device(cons, &idx) == p &&
54139 idx == tty_line) {
54140 - kgdboc_io_ops.is_console = 1;
54141 + is_console = 1;
54142 break;
54143 }
54144 cons = cons->next;
54145 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
54146 kgdb_tty_line = tty_line;
54147
54148 do_register:
54149 - err = kgdb_register_io_module(&kgdboc_io_ops);
54150 + if (is_console) {
54151 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
54152 + configured = 2;
54153 + } else {
54154 + err = kgdb_register_io_module(&kgdboc_io_ops);
54155 + configured = 1;
54156 + }
54157 if (err)
54158 goto noconfig;
54159
54160 @@ -205,8 +214,6 @@ do_register:
54161 if (err)
54162 goto nmi_con_failed;
54163
54164 - configured = 1;
54165 -
54166 return 0;
54167
54168 nmi_con_failed:
54169 @@ -223,7 +230,7 @@ noconfig:
54170 static int __init init_kgdboc(void)
54171 {
54172 /* Already configured? */
54173 - if (configured == 1)
54174 + if (configured >= 1)
54175 return 0;
54176
54177 return configure_kgdboc();
54178 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
54179 if (config[len - 1] == '\n')
54180 config[len - 1] = '\0';
54181
54182 - if (configured == 1)
54183 + if (configured >= 1)
54184 cleanup_kgdboc();
54185
54186 /* Go and configure with the new params. */
54187 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
54188 .post_exception = kgdboc_post_exp_handler,
54189 };
54190
54191 +static struct kgdb_io kgdboc_io_ops_console = {
54192 + .name = "kgdboc",
54193 + .read_char = kgdboc_get_char,
54194 + .write_char = kgdboc_put_char,
54195 + .pre_exception = kgdboc_pre_exp_handler,
54196 + .post_exception = kgdboc_post_exp_handler,
54197 + .is_console = 1
54198 +};
54199 +
54200 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
54201 /* This is only available if kgdboc is a built in for early debugging */
54202 static int __init kgdboc_early_init(char *opt)
54203 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
54204 index 72000a6..a190bc4 100644
54205 --- a/drivers/tty/serial/msm_serial.c
54206 +++ b/drivers/tty/serial/msm_serial.c
54207 @@ -981,7 +981,7 @@ static struct uart_driver msm_uart_driver = {
54208 .cons = MSM_CONSOLE,
54209 };
54210
54211 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
54212 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
54213
54214 static const struct of_device_id msm_uartdm_table[] = {
54215 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
54216 @@ -1000,7 +1000,7 @@ static int msm_serial_probe(struct platform_device *pdev)
54217 int irq;
54218
54219 if (pdev->id == -1)
54220 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
54221 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
54222
54223 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
54224 return -ENXIO;
54225 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
54226 index c1d3ebd..f618a93 100644
54227 --- a/drivers/tty/serial/samsung.c
54228 +++ b/drivers/tty/serial/samsung.c
54229 @@ -486,11 +486,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
54230 }
54231 }
54232
54233 +static int s3c64xx_serial_startup(struct uart_port *port);
54234 static int s3c24xx_serial_startup(struct uart_port *port)
54235 {
54236 struct s3c24xx_uart_port *ourport = to_ourport(port);
54237 int ret;
54238
54239 + /* Startup sequence is different for s3c64xx and higher SoC's */
54240 + if (s3c24xx_serial_has_interrupt_mask(port))
54241 + return s3c64xx_serial_startup(port);
54242 +
54243 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
54244 port, (unsigned long long)port->mapbase, port->membase);
54245
54246 @@ -1164,10 +1169,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
54247 /* setup info for port */
54248 port->dev = &platdev->dev;
54249
54250 - /* Startup sequence is different for s3c64xx and higher SoC's */
54251 - if (s3c24xx_serial_has_interrupt_mask(port))
54252 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
54253 -
54254 port->uartclk = 1;
54255
54256 if (cfg->uart_flags & UPF_CONS_FLOW) {
54257 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
54258 index ef2fb36..238d80c 100644
54259 --- a/drivers/tty/serial/serial_core.c
54260 +++ b/drivers/tty/serial/serial_core.c
54261 @@ -1336,7 +1336,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
54262
54263 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
54264
54265 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
54266 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
54267 return;
54268
54269 /*
54270 @@ -1463,7 +1463,7 @@ static void uart_hangup(struct tty_struct *tty)
54271 uart_flush_buffer(tty);
54272 uart_shutdown(tty, state);
54273 spin_lock_irqsave(&port->lock, flags);
54274 - port->count = 0;
54275 + atomic_set(&port->count, 0);
54276 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
54277 spin_unlock_irqrestore(&port->lock, flags);
54278 tty_port_tty_set(port, NULL);
54279 @@ -1561,7 +1561,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
54280 goto end;
54281 }
54282
54283 - port->count++;
54284 + atomic_inc(&port->count);
54285 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
54286 retval = -ENXIO;
54287 goto err_dec_count;
54288 @@ -1601,7 +1601,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
54289 end:
54290 return retval;
54291 err_dec_count:
54292 - port->count--;
54293 + atomic_inc(&port->count);
54294 mutex_unlock(&port->mutex);
54295 goto end;
54296 }
54297 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
54298 index d48e040..0f52764 100644
54299 --- a/drivers/tty/synclink.c
54300 +++ b/drivers/tty/synclink.c
54301 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
54302
54303 if (debug_level >= DEBUG_LEVEL_INFO)
54304 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
54305 - __FILE__,__LINE__, info->device_name, info->port.count);
54306 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
54307
54308 if (tty_port_close_start(&info->port, tty, filp) == 0)
54309 goto cleanup;
54310 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
54311 cleanup:
54312 if (debug_level >= DEBUG_LEVEL_INFO)
54313 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
54314 - tty->driver->name, info->port.count);
54315 + tty->driver->name, atomic_read(&info->port.count));
54316
54317 } /* end of mgsl_close() */
54318
54319 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
54320
54321 mgsl_flush_buffer(tty);
54322 shutdown(info);
54323 -
54324 - info->port.count = 0;
54325 +
54326 + atomic_set(&info->port.count, 0);
54327 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54328 info->port.tty = NULL;
54329
54330 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54331
54332 if (debug_level >= DEBUG_LEVEL_INFO)
54333 printk("%s(%d):block_til_ready before block on %s count=%d\n",
54334 - __FILE__,__LINE__, tty->driver->name, port->count );
54335 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54336
54337 spin_lock_irqsave(&info->irq_spinlock, flags);
54338 if (!tty_hung_up_p(filp)) {
54339 extra_count = true;
54340 - port->count--;
54341 + atomic_dec(&port->count);
54342 }
54343 spin_unlock_irqrestore(&info->irq_spinlock, flags);
54344 port->blocked_open++;
54345 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54346
54347 if (debug_level >= DEBUG_LEVEL_INFO)
54348 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
54349 - __FILE__,__LINE__, tty->driver->name, port->count );
54350 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54351
54352 tty_unlock(tty);
54353 schedule();
54354 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54355
54356 /* FIXME: Racy on hangup during close wait */
54357 if (extra_count)
54358 - port->count++;
54359 + atomic_inc(&port->count);
54360 port->blocked_open--;
54361
54362 if (debug_level >= DEBUG_LEVEL_INFO)
54363 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
54364 - __FILE__,__LINE__, tty->driver->name, port->count );
54365 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54366
54367 if (!retval)
54368 port->flags |= ASYNC_NORMAL_ACTIVE;
54369 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
54370
54371 if (debug_level >= DEBUG_LEVEL_INFO)
54372 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
54373 - __FILE__,__LINE__,tty->driver->name, info->port.count);
54374 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
54375
54376 /* If port is closing, signal caller to try again */
54377 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
54378 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
54379 spin_unlock_irqrestore(&info->netlock, flags);
54380 goto cleanup;
54381 }
54382 - info->port.count++;
54383 + atomic_inc(&info->port.count);
54384 spin_unlock_irqrestore(&info->netlock, flags);
54385
54386 - if (info->port.count == 1) {
54387 + if (atomic_read(&info->port.count) == 1) {
54388 /* 1st open on this device, init hardware */
54389 retval = startup(info);
54390 if (retval < 0)
54391 @@ -3446,8 +3446,8 @@ cleanup:
54392 if (retval) {
54393 if (tty->count == 1)
54394 info->port.tty = NULL; /* tty layer will release tty struct */
54395 - if(info->port.count)
54396 - info->port.count--;
54397 + if (atomic_read(&info->port.count))
54398 + atomic_dec(&info->port.count);
54399 }
54400
54401 return retval;
54402 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54403 unsigned short new_crctype;
54404
54405 /* return error if TTY interface open */
54406 - if (info->port.count)
54407 + if (atomic_read(&info->port.count))
54408 return -EBUSY;
54409
54410 switch (encoding)
54411 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
54412
54413 /* arbitrate between network and tty opens */
54414 spin_lock_irqsave(&info->netlock, flags);
54415 - if (info->port.count != 0 || info->netcount != 0) {
54416 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54417 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54418 spin_unlock_irqrestore(&info->netlock, flags);
54419 return -EBUSY;
54420 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54421 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54422
54423 /* return error if TTY interface open */
54424 - if (info->port.count)
54425 + if (atomic_read(&info->port.count))
54426 return -EBUSY;
54427
54428 if (cmd != SIOCWANDEV)
54429 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
54430 index c359a91..959fc26 100644
54431 --- a/drivers/tty/synclink_gt.c
54432 +++ b/drivers/tty/synclink_gt.c
54433 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54434 tty->driver_data = info;
54435 info->port.tty = tty;
54436
54437 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
54438 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
54439
54440 /* If port is closing, signal caller to try again */
54441 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
54442 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54443 mutex_unlock(&info->port.mutex);
54444 goto cleanup;
54445 }
54446 - info->port.count++;
54447 + atomic_inc(&info->port.count);
54448 spin_unlock_irqrestore(&info->netlock, flags);
54449
54450 - if (info->port.count == 1) {
54451 + if (atomic_read(&info->port.count) == 1) {
54452 /* 1st open on this device, init hardware */
54453 retval = startup(info);
54454 if (retval < 0) {
54455 @@ -715,8 +715,8 @@ cleanup:
54456 if (retval) {
54457 if (tty->count == 1)
54458 info->port.tty = NULL; /* tty layer will release tty struct */
54459 - if(info->port.count)
54460 - info->port.count--;
54461 + if(atomic_read(&info->port.count))
54462 + atomic_dec(&info->port.count);
54463 }
54464
54465 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
54466 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54467
54468 if (sanity_check(info, tty->name, "close"))
54469 return;
54470 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
54471 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
54472
54473 if (tty_port_close_start(&info->port, tty, filp) == 0)
54474 goto cleanup;
54475 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54476 tty_port_close_end(&info->port, tty);
54477 info->port.tty = NULL;
54478 cleanup:
54479 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
54480 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
54481 }
54482
54483 static void hangup(struct tty_struct *tty)
54484 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
54485 shutdown(info);
54486
54487 spin_lock_irqsave(&info->port.lock, flags);
54488 - info->port.count = 0;
54489 + atomic_set(&info->port.count, 0);
54490 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54491 info->port.tty = NULL;
54492 spin_unlock_irqrestore(&info->port.lock, flags);
54493 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54494 unsigned short new_crctype;
54495
54496 /* return error if TTY interface open */
54497 - if (info->port.count)
54498 + if (atomic_read(&info->port.count))
54499 return -EBUSY;
54500
54501 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
54502 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
54503
54504 /* arbitrate between network and tty opens */
54505 spin_lock_irqsave(&info->netlock, flags);
54506 - if (info->port.count != 0 || info->netcount != 0) {
54507 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54508 DBGINFO(("%s hdlc_open busy\n", dev->name));
54509 spin_unlock_irqrestore(&info->netlock, flags);
54510 return -EBUSY;
54511 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54512 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
54513
54514 /* return error if TTY interface open */
54515 - if (info->port.count)
54516 + if (atomic_read(&info->port.count))
54517 return -EBUSY;
54518
54519 if (cmd != SIOCWANDEV)
54520 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
54521 if (port == NULL)
54522 continue;
54523 spin_lock(&port->lock);
54524 - if ((port->port.count || port->netcount) &&
54525 + if ((atomic_read(&port->port.count) || port->netcount) &&
54526 port->pending_bh && !port->bh_running &&
54527 !port->bh_requested) {
54528 DBGISR(("%s bh queued\n", port->device_name));
54529 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54530 spin_lock_irqsave(&info->lock, flags);
54531 if (!tty_hung_up_p(filp)) {
54532 extra_count = true;
54533 - port->count--;
54534 + atomic_dec(&port->count);
54535 }
54536 spin_unlock_irqrestore(&info->lock, flags);
54537 port->blocked_open++;
54538 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54539 remove_wait_queue(&port->open_wait, &wait);
54540
54541 if (extra_count)
54542 - port->count++;
54543 + atomic_inc(&port->count);
54544 port->blocked_open--;
54545
54546 if (!retval)
54547 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
54548 index 53ba853..3c30f6d 100644
54549 --- a/drivers/tty/synclinkmp.c
54550 +++ b/drivers/tty/synclinkmp.c
54551 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54552
54553 if (debug_level >= DEBUG_LEVEL_INFO)
54554 printk("%s(%d):%s open(), old ref count = %d\n",
54555 - __FILE__,__LINE__,tty->driver->name, info->port.count);
54556 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
54557
54558 /* If port is closing, signal caller to try again */
54559 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
54560 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54561 spin_unlock_irqrestore(&info->netlock, flags);
54562 goto cleanup;
54563 }
54564 - info->port.count++;
54565 + atomic_inc(&info->port.count);
54566 spin_unlock_irqrestore(&info->netlock, flags);
54567
54568 - if (info->port.count == 1) {
54569 + if (atomic_read(&info->port.count) == 1) {
54570 /* 1st open on this device, init hardware */
54571 retval = startup(info);
54572 if (retval < 0)
54573 @@ -796,8 +796,8 @@ cleanup:
54574 if (retval) {
54575 if (tty->count == 1)
54576 info->port.tty = NULL; /* tty layer will release tty struct */
54577 - if(info->port.count)
54578 - info->port.count--;
54579 + if(atomic_read(&info->port.count))
54580 + atomic_dec(&info->port.count);
54581 }
54582
54583 return retval;
54584 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54585
54586 if (debug_level >= DEBUG_LEVEL_INFO)
54587 printk("%s(%d):%s close() entry, count=%d\n",
54588 - __FILE__,__LINE__, info->device_name, info->port.count);
54589 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
54590
54591 if (tty_port_close_start(&info->port, tty, filp) == 0)
54592 goto cleanup;
54593 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54594 cleanup:
54595 if (debug_level >= DEBUG_LEVEL_INFO)
54596 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
54597 - tty->driver->name, info->port.count);
54598 + tty->driver->name, atomic_read(&info->port.count));
54599 }
54600
54601 /* Called by tty_hangup() when a hangup is signaled.
54602 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
54603 shutdown(info);
54604
54605 spin_lock_irqsave(&info->port.lock, flags);
54606 - info->port.count = 0;
54607 + atomic_set(&info->port.count, 0);
54608 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54609 info->port.tty = NULL;
54610 spin_unlock_irqrestore(&info->port.lock, flags);
54611 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54612 unsigned short new_crctype;
54613
54614 /* return error if TTY interface open */
54615 - if (info->port.count)
54616 + if (atomic_read(&info->port.count))
54617 return -EBUSY;
54618
54619 switch (encoding)
54620 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
54621
54622 /* arbitrate between network and tty opens */
54623 spin_lock_irqsave(&info->netlock, flags);
54624 - if (info->port.count != 0 || info->netcount != 0) {
54625 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54626 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54627 spin_unlock_irqrestore(&info->netlock, flags);
54628 return -EBUSY;
54629 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54630 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54631
54632 /* return error if TTY interface open */
54633 - if (info->port.count)
54634 + if (atomic_read(&info->port.count))
54635 return -EBUSY;
54636
54637 if (cmd != SIOCWANDEV)
54638 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
54639 * do not request bottom half processing if the
54640 * device is not open in a normal mode.
54641 */
54642 - if ( port && (port->port.count || port->netcount) &&
54643 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
54644 port->pending_bh && !port->bh_running &&
54645 !port->bh_requested ) {
54646 if ( debug_level >= DEBUG_LEVEL_ISR )
54647 @@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54648
54649 if (debug_level >= DEBUG_LEVEL_INFO)
54650 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
54651 - __FILE__,__LINE__, tty->driver->name, port->count );
54652 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54653
54654 spin_lock_irqsave(&info->lock, flags);
54655 if (!tty_hung_up_p(filp)) {
54656 extra_count = true;
54657 - port->count--;
54658 + atomic_dec(&port->count);
54659 }
54660 spin_unlock_irqrestore(&info->lock, flags);
54661 port->blocked_open++;
54662 @@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54663
54664 if (debug_level >= DEBUG_LEVEL_INFO)
54665 printk("%s(%d):%s block_til_ready() count=%d\n",
54666 - __FILE__,__LINE__, tty->driver->name, port->count );
54667 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54668
54669 tty_unlock(tty);
54670 schedule();
54671 @@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54672 remove_wait_queue(&port->open_wait, &wait);
54673
54674 if (extra_count)
54675 - port->count++;
54676 + atomic_inc(&port->count);
54677 port->blocked_open--;
54678
54679 if (debug_level >= DEBUG_LEVEL_INFO)
54680 printk("%s(%d):%s block_til_ready() after, count=%d\n",
54681 - __FILE__,__LINE__, tty->driver->name, port->count );
54682 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54683
54684 if (!retval)
54685 port->flags |= ASYNC_NORMAL_ACTIVE;
54686 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
54687 index 454b658..57b1430 100644
54688 --- a/drivers/tty/sysrq.c
54689 +++ b/drivers/tty/sysrq.c
54690 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
54691 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
54692 size_t count, loff_t *ppos)
54693 {
54694 - if (count) {
54695 + if (count && capable(CAP_SYS_ADMIN)) {
54696 char c;
54697
54698 if (get_user(c, buf))
54699 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
54700 index 3411071..86f2cf2 100644
54701 --- a/drivers/tty/tty_io.c
54702 +++ b/drivers/tty/tty_io.c
54703 @@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
54704
54705 void tty_default_fops(struct file_operations *fops)
54706 {
54707 - *fops = tty_fops;
54708 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
54709 }
54710
54711 /*
54712 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
54713 index 2d822aa..a566234 100644
54714 --- a/drivers/tty/tty_ldisc.c
54715 +++ b/drivers/tty/tty_ldisc.c
54716 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
54717 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54718 tty_ldiscs[disc] = new_ldisc;
54719 new_ldisc->num = disc;
54720 - new_ldisc->refcount = 0;
54721 + atomic_set(&new_ldisc->refcount, 0);
54722 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54723
54724 return ret;
54725 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
54726 return -EINVAL;
54727
54728 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54729 - if (tty_ldiscs[disc]->refcount)
54730 + if (atomic_read(&tty_ldiscs[disc]->refcount))
54731 ret = -EBUSY;
54732 else
54733 tty_ldiscs[disc] = NULL;
54734 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
54735 if (ldops) {
54736 ret = ERR_PTR(-EAGAIN);
54737 if (try_module_get(ldops->owner)) {
54738 - ldops->refcount++;
54739 + atomic_inc(&ldops->refcount);
54740 ret = ldops;
54741 }
54742 }
54743 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
54744 unsigned long flags;
54745
54746 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54747 - ldops->refcount--;
54748 + atomic_dec(&ldops->refcount);
54749 module_put(ldops->owner);
54750 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54751 }
54752 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
54753 index 3f746c8..2f2fcaa 100644
54754 --- a/drivers/tty/tty_port.c
54755 +++ b/drivers/tty/tty_port.c
54756 @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
54757 unsigned long flags;
54758
54759 spin_lock_irqsave(&port->lock, flags);
54760 - port->count = 0;
54761 + atomic_set(&port->count, 0);
54762 port->flags &= ~ASYNC_NORMAL_ACTIVE;
54763 tty = port->tty;
54764 if (tty)
54765 @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54766 /* The port lock protects the port counts */
54767 spin_lock_irqsave(&port->lock, flags);
54768 if (!tty_hung_up_p(filp))
54769 - port->count--;
54770 + atomic_dec(&port->count);
54771 port->blocked_open++;
54772 spin_unlock_irqrestore(&port->lock, flags);
54773
54774 @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54775 we must not mess that up further */
54776 spin_lock_irqsave(&port->lock, flags);
54777 if (!tty_hung_up_p(filp))
54778 - port->count++;
54779 + atomic_inc(&port->count);
54780 port->blocked_open--;
54781 if (retval == 0)
54782 port->flags |= ASYNC_NORMAL_ACTIVE;
54783 @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
54784 return 0;
54785 }
54786
54787 - if (tty->count == 1 && port->count != 1) {
54788 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
54789 printk(KERN_WARNING
54790 "tty_port_close_start: tty->count = 1 port count = %d.\n",
54791 - port->count);
54792 - port->count = 1;
54793 + atomic_read(&port->count));
54794 + atomic_set(&port->count, 1);
54795 }
54796 - if (--port->count < 0) {
54797 + if (atomic_dec_return(&port->count) < 0) {
54798 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
54799 - port->count);
54800 - port->count = 0;
54801 + atomic_read(&port->count));
54802 + atomic_set(&port->count, 0);
54803 }
54804
54805 - if (port->count) {
54806 + if (atomic_read(&port->count)) {
54807 spin_unlock_irqrestore(&port->lock, flags);
54808 return 0;
54809 }
54810 @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
54811 {
54812 spin_lock_irq(&port->lock);
54813 if (!tty_hung_up_p(filp))
54814 - ++port->count;
54815 + atomic_inc(&port->count);
54816 spin_unlock_irq(&port->lock);
54817 tty_port_tty_set(port, tty);
54818
54819 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54820 index d0e3a44..5f8b754 100644
54821 --- a/drivers/tty/vt/keyboard.c
54822 +++ b/drivers/tty/vt/keyboard.c
54823 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54824 kbd->kbdmode == VC_OFF) &&
54825 value != KVAL(K_SAK))
54826 return; /* SAK is allowed even in raw mode */
54827 +
54828 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54829 + {
54830 + void *func = fn_handler[value];
54831 + if (func == fn_show_state || func == fn_show_ptregs ||
54832 + func == fn_show_mem)
54833 + return;
54834 + }
54835 +#endif
54836 +
54837 fn_handler[value](vc);
54838 }
54839
54840 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54841 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54842 return -EFAULT;
54843
54844 - if (!capable(CAP_SYS_TTY_CONFIG))
54845 - perm = 0;
54846 -
54847 switch (cmd) {
54848 case KDGKBENT:
54849 /* Ensure another thread doesn't free it under us */
54850 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54851 spin_unlock_irqrestore(&kbd_event_lock, flags);
54852 return put_user(val, &user_kbe->kb_value);
54853 case KDSKBENT:
54854 + if (!capable(CAP_SYS_TTY_CONFIG))
54855 + perm = 0;
54856 +
54857 if (!perm)
54858 return -EPERM;
54859 if (!i && v == K_NOSUCHMAP) {
54860 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54861 int i, j, k;
54862 int ret;
54863
54864 - if (!capable(CAP_SYS_TTY_CONFIG))
54865 - perm = 0;
54866 -
54867 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54868 if (!kbs) {
54869 ret = -ENOMEM;
54870 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54871 kfree(kbs);
54872 return ((p && *p) ? -EOVERFLOW : 0);
54873 case KDSKBSENT:
54874 + if (!capable(CAP_SYS_TTY_CONFIG))
54875 + perm = 0;
54876 +
54877 if (!perm) {
54878 ret = -EPERM;
54879 goto reterr;
54880 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54881 index a673e5b..36e5d32 100644
54882 --- a/drivers/uio/uio.c
54883 +++ b/drivers/uio/uio.c
54884 @@ -25,6 +25,7 @@
54885 #include <linux/kobject.h>
54886 #include <linux/cdev.h>
54887 #include <linux/uio_driver.h>
54888 +#include <asm/local.h>
54889
54890 #define UIO_MAX_DEVICES (1U << MINORBITS)
54891
54892 @@ -32,7 +33,7 @@ struct uio_device {
54893 struct module *owner;
54894 struct device *dev;
54895 int minor;
54896 - atomic_t event;
54897 + atomic_unchecked_t event;
54898 struct fasync_struct *async_queue;
54899 wait_queue_head_t wait;
54900 struct uio_info *info;
54901 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
54902 struct device_attribute *attr, char *buf)
54903 {
54904 struct uio_device *idev = dev_get_drvdata(dev);
54905 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54906 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54907 }
54908 static DEVICE_ATTR_RO(event);
54909
54910 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
54911 {
54912 struct uio_device *idev = info->uio_dev;
54913
54914 - atomic_inc(&idev->event);
54915 + atomic_inc_unchecked(&idev->event);
54916 wake_up_interruptible(&idev->wait);
54917 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54918 }
54919 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54920 }
54921
54922 listener->dev = idev;
54923 - listener->event_count = atomic_read(&idev->event);
54924 + listener->event_count = atomic_read_unchecked(&idev->event);
54925 filep->private_data = listener;
54926
54927 if (idev->info->open) {
54928 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
54929 return -EIO;
54930
54931 poll_wait(filep, &idev->wait, wait);
54932 - if (listener->event_count != atomic_read(&idev->event))
54933 + if (listener->event_count != atomic_read_unchecked(&idev->event))
54934 return POLLIN | POLLRDNORM;
54935 return 0;
54936 }
54937 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
54938 do {
54939 set_current_state(TASK_INTERRUPTIBLE);
54940
54941 - event_count = atomic_read(&idev->event);
54942 + event_count = atomic_read_unchecked(&idev->event);
54943 if (event_count != listener->event_count) {
54944 if (copy_to_user(buf, &event_count, count))
54945 retval = -EFAULT;
54946 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
54947 static int uio_find_mem_index(struct vm_area_struct *vma)
54948 {
54949 struct uio_device *idev = vma->vm_private_data;
54950 + unsigned long size;
54951
54952 if (vma->vm_pgoff < MAX_UIO_MAPS) {
54953 - if (idev->info->mem[vma->vm_pgoff].size == 0)
54954 + size = idev->info->mem[vma->vm_pgoff].size;
54955 + if (size == 0)
54956 + return -1;
54957 + if (vma->vm_end - vma->vm_start > size)
54958 return -1;
54959 return (int)vma->vm_pgoff;
54960 }
54961 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
54962 idev->owner = owner;
54963 idev->info = info;
54964 init_waitqueue_head(&idev->wait);
54965 - atomic_set(&idev->event, 0);
54966 + atomic_set_unchecked(&idev->event, 0);
54967
54968 ret = uio_get_minor(idev);
54969 if (ret)
54970 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
54971 index 813d4d3..a71934f 100644
54972 --- a/drivers/usb/atm/cxacru.c
54973 +++ b/drivers/usb/atm/cxacru.c
54974 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
54975 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
54976 if (ret < 2)
54977 return -EINVAL;
54978 - if (index < 0 || index > 0x7f)
54979 + if (index > 0x7f)
54980 return -EINVAL;
54981 pos += tmp;
54982
54983 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
54984 index dada014..1d0d517 100644
54985 --- a/drivers/usb/atm/usbatm.c
54986 +++ b/drivers/usb/atm/usbatm.c
54987 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54988 if (printk_ratelimit())
54989 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
54990 __func__, vpi, vci);
54991 - atomic_inc(&vcc->stats->rx_err);
54992 + atomic_inc_unchecked(&vcc->stats->rx_err);
54993 return;
54994 }
54995
54996 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54997 if (length > ATM_MAX_AAL5_PDU) {
54998 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
54999 __func__, length, vcc);
55000 - atomic_inc(&vcc->stats->rx_err);
55001 + atomic_inc_unchecked(&vcc->stats->rx_err);
55002 goto out;
55003 }
55004
55005 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55006 if (sarb->len < pdu_length) {
55007 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
55008 __func__, pdu_length, sarb->len, vcc);
55009 - atomic_inc(&vcc->stats->rx_err);
55010 + atomic_inc_unchecked(&vcc->stats->rx_err);
55011 goto out;
55012 }
55013
55014 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
55015 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
55016 __func__, vcc);
55017 - atomic_inc(&vcc->stats->rx_err);
55018 + atomic_inc_unchecked(&vcc->stats->rx_err);
55019 goto out;
55020 }
55021
55022 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55023 if (printk_ratelimit())
55024 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
55025 __func__, length);
55026 - atomic_inc(&vcc->stats->rx_drop);
55027 + atomic_inc_unchecked(&vcc->stats->rx_drop);
55028 goto out;
55029 }
55030
55031 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55032
55033 vcc->push(vcc, skb);
55034
55035 - atomic_inc(&vcc->stats->rx);
55036 + atomic_inc_unchecked(&vcc->stats->rx);
55037 out:
55038 skb_trim(sarb, 0);
55039 }
55040 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
55041 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
55042
55043 usbatm_pop(vcc, skb);
55044 - atomic_inc(&vcc->stats->tx);
55045 + atomic_inc_unchecked(&vcc->stats->tx);
55046
55047 skb = skb_dequeue(&instance->sndqueue);
55048 }
55049 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
55050 if (!left--)
55051 return sprintf(page,
55052 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
55053 - atomic_read(&atm_dev->stats.aal5.tx),
55054 - atomic_read(&atm_dev->stats.aal5.tx_err),
55055 - atomic_read(&atm_dev->stats.aal5.rx),
55056 - atomic_read(&atm_dev->stats.aal5.rx_err),
55057 - atomic_read(&atm_dev->stats.aal5.rx_drop));
55058 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
55059 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
55060 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
55061 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
55062 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
55063
55064 if (!left--) {
55065 if (instance->disconnected)
55066 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
55067 index 2a3bbdf..91d72cf 100644
55068 --- a/drivers/usb/core/devices.c
55069 +++ b/drivers/usb/core/devices.c
55070 @@ -126,7 +126,7 @@ static const char format_endpt[] =
55071 * time it gets called.
55072 */
55073 static struct device_connect_event {
55074 - atomic_t count;
55075 + atomic_unchecked_t count;
55076 wait_queue_head_t wait;
55077 } device_event = {
55078 .count = ATOMIC_INIT(1),
55079 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
55080
55081 void usbfs_conn_disc_event(void)
55082 {
55083 - atomic_add(2, &device_event.count);
55084 + atomic_add_unchecked(2, &device_event.count);
55085 wake_up(&device_event.wait);
55086 }
55087
55088 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
55089
55090 poll_wait(file, &device_event.wait, wait);
55091
55092 - event_count = atomic_read(&device_event.count);
55093 + event_count = atomic_read_unchecked(&device_event.count);
55094 if (file->f_version != event_count) {
55095 file->f_version = event_count;
55096 return POLLIN | POLLRDNORM;
55097 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
55098 index 0b59731..46ee7d1 100644
55099 --- a/drivers/usb/core/devio.c
55100 +++ b/drivers/usb/core/devio.c
55101 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
55102 struct usb_dev_state *ps = file->private_data;
55103 struct usb_device *dev = ps->dev;
55104 ssize_t ret = 0;
55105 - unsigned len;
55106 + size_t len;
55107 loff_t pos;
55108 int i;
55109
55110 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
55111 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
55112 struct usb_config_descriptor *config =
55113 (struct usb_config_descriptor *)dev->rawdescriptors[i];
55114 - unsigned int length = le16_to_cpu(config->wTotalLength);
55115 + size_t length = le16_to_cpu(config->wTotalLength);
55116
55117 if (*ppos < pos + length) {
55118
55119 /* The descriptor may claim to be longer than it
55120 * really is. Here is the actual allocated length. */
55121 - unsigned alloclen =
55122 + size_t alloclen =
55123 le16_to_cpu(dev->config[i].desc.wTotalLength);
55124
55125 - len = length - (*ppos - pos);
55126 + len = length + pos - *ppos;
55127 if (len > nbytes)
55128 len = nbytes;
55129
55130 /* Simply don't write (skip over) unallocated parts */
55131 if (alloclen > (*ppos - pos)) {
55132 - alloclen -= (*ppos - pos);
55133 + alloclen = alloclen + pos - *ppos;
55134 if (copy_to_user(buf,
55135 dev->rawdescriptors[i] + (*ppos - pos),
55136 min(len, alloclen))) {
55137 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
55138 index bec31e2..b8091cd 100644
55139 --- a/drivers/usb/core/hcd.c
55140 +++ b/drivers/usb/core/hcd.c
55141 @@ -1554,7 +1554,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
55142 */
55143 usb_get_urb(urb);
55144 atomic_inc(&urb->use_count);
55145 - atomic_inc(&urb->dev->urbnum);
55146 + atomic_inc_unchecked(&urb->dev->urbnum);
55147 usbmon_urb_submit(&hcd->self, urb);
55148
55149 /* NOTE requirements on root-hub callers (usbfs and the hub
55150 @@ -1581,7 +1581,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
55151 urb->hcpriv = NULL;
55152 INIT_LIST_HEAD(&urb->urb_list);
55153 atomic_dec(&urb->use_count);
55154 - atomic_dec(&urb->dev->urbnum);
55155 + atomic_dec_unchecked(&urb->dev->urbnum);
55156 if (atomic_read(&urb->reject))
55157 wake_up(&usb_kill_urb_queue);
55158 usb_put_urb(urb);
55159 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
55160 index 27f2171..e3dfc22 100644
55161 --- a/drivers/usb/core/hub.c
55162 +++ b/drivers/usb/core/hub.c
55163 @@ -27,6 +27,7 @@
55164 #include <linux/freezer.h>
55165 #include <linux/random.h>
55166 #include <linux/pm_qos.h>
55167 +#include <linux/grsecurity.h>
55168
55169 #include <asm/uaccess.h>
55170 #include <asm/byteorder.h>
55171 @@ -4644,6 +4645,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
55172 goto done;
55173 return;
55174 }
55175 +
55176 + if (gr_handle_new_usb())
55177 + goto done;
55178 +
55179 if (hub_is_superspeed(hub->hdev))
55180 unit_load = 150;
55181 else
55182 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
55183 index 0c8a7fc..c45b40a 100644
55184 --- a/drivers/usb/core/message.c
55185 +++ b/drivers/usb/core/message.c
55186 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
55187 * Return: If successful, the number of bytes transferred. Otherwise, a negative
55188 * error number.
55189 */
55190 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
55191 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
55192 __u8 requesttype, __u16 value, __u16 index, void *data,
55193 __u16 size, int timeout)
55194 {
55195 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
55196 * If successful, 0. Otherwise a negative error number. The number of actual
55197 * bytes transferred will be stored in the @actual_length parameter.
55198 */
55199 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
55200 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
55201 void *data, int len, int *actual_length, int timeout)
55202 {
55203 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
55204 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
55205 * bytes transferred will be stored in the @actual_length parameter.
55206 *
55207 */
55208 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
55209 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
55210 void *data, int len, int *actual_length, int timeout)
55211 {
55212 struct urb *urb;
55213 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
55214 index 1236c60..d47a51c 100644
55215 --- a/drivers/usb/core/sysfs.c
55216 +++ b/drivers/usb/core/sysfs.c
55217 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
55218 struct usb_device *udev;
55219
55220 udev = to_usb_device(dev);
55221 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
55222 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
55223 }
55224 static DEVICE_ATTR_RO(urbnum);
55225
55226 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
55227 index 4d11449..f4ccabf 100644
55228 --- a/drivers/usb/core/usb.c
55229 +++ b/drivers/usb/core/usb.c
55230 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
55231 set_dev_node(&dev->dev, dev_to_node(bus->controller));
55232 dev->state = USB_STATE_ATTACHED;
55233 dev->lpm_disable_count = 1;
55234 - atomic_set(&dev->urbnum, 0);
55235 + atomic_set_unchecked(&dev->urbnum, 0);
55236
55237 INIT_LIST_HEAD(&dev->ep0.urb_list);
55238 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
55239 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
55240 index dab7927..6f53afc 100644
55241 --- a/drivers/usb/dwc3/gadget.c
55242 +++ b/drivers/usb/dwc3/gadget.c
55243 @@ -615,8 +615,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
55244 if (!usb_endpoint_xfer_isoc(desc))
55245 return 0;
55246
55247 - memset(&trb_link, 0, sizeof(trb_link));
55248 -
55249 /* Link TRB for ISOC. The HWO bit is never reset */
55250 trb_st_hw = &dep->trb_pool[0];
55251
55252 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
55253 index 8cfc319..4868255 100644
55254 --- a/drivers/usb/early/ehci-dbgp.c
55255 +++ b/drivers/usb/early/ehci-dbgp.c
55256 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
55257
55258 #ifdef CONFIG_KGDB
55259 static struct kgdb_io kgdbdbgp_io_ops;
55260 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
55261 +static struct kgdb_io kgdbdbgp_io_ops_console;
55262 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
55263 #else
55264 #define dbgp_kgdb_mode (0)
55265 #endif
55266 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
55267 .write_char = kgdbdbgp_write_char,
55268 };
55269
55270 +static struct kgdb_io kgdbdbgp_io_ops_console = {
55271 + .name = "kgdbdbgp",
55272 + .read_char = kgdbdbgp_read_char,
55273 + .write_char = kgdbdbgp_write_char,
55274 + .is_console = 1
55275 +};
55276 +
55277 static int kgdbdbgp_wait_time;
55278
55279 static int __init kgdbdbgp_parse_config(char *str)
55280 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
55281 ptr++;
55282 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
55283 }
55284 - kgdb_register_io_module(&kgdbdbgp_io_ops);
55285 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
55286 + if (early_dbgp_console.index != -1)
55287 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
55288 + else
55289 + kgdb_register_io_module(&kgdbdbgp_io_ops);
55290
55291 return 0;
55292 }
55293 diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
55294 index 2b4c82d..06a8ee6 100644
55295 --- a/drivers/usb/gadget/f_uac1.c
55296 +++ b/drivers/usb/gadget/f_uac1.c
55297 @@ -13,6 +13,7 @@
55298 #include <linux/kernel.h>
55299 #include <linux/device.h>
55300 #include <linux/atomic.h>
55301 +#include <linux/module.h>
55302
55303 #include "u_uac1.h"
55304
55305 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
55306 index ad0aca8..8ff84865 100644
55307 --- a/drivers/usb/gadget/u_serial.c
55308 +++ b/drivers/usb/gadget/u_serial.c
55309 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
55310 spin_lock_irq(&port->port_lock);
55311
55312 /* already open? Great. */
55313 - if (port->port.count) {
55314 + if (atomic_read(&port->port.count)) {
55315 status = 0;
55316 - port->port.count++;
55317 + atomic_inc(&port->port.count);
55318
55319 /* currently opening/closing? wait ... */
55320 } else if (port->openclose) {
55321 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
55322 tty->driver_data = port;
55323 port->port.tty = tty;
55324
55325 - port->port.count = 1;
55326 + atomic_set(&port->port.count, 1);
55327 port->openclose = false;
55328
55329 /* if connected, start the I/O stream */
55330 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
55331
55332 spin_lock_irq(&port->port_lock);
55333
55334 - if (port->port.count != 1) {
55335 - if (port->port.count == 0)
55336 + if (atomic_read(&port->port.count) != 1) {
55337 + if (atomic_read(&port->port.count) == 0)
55338 WARN_ON(1);
55339 else
55340 - --port->port.count;
55341 + atomic_dec(&port->port.count);
55342 goto exit;
55343 }
55344
55345 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
55346 * and sleep if necessary
55347 */
55348 port->openclose = true;
55349 - port->port.count = 0;
55350 + atomic_set(&port->port.count, 0);
55351
55352 gser = port->port_usb;
55353 if (gser && gser->disconnect)
55354 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
55355 int cond;
55356
55357 spin_lock_irq(&port->port_lock);
55358 - cond = (port->port.count == 0) && !port->openclose;
55359 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
55360 spin_unlock_irq(&port->port_lock);
55361 return cond;
55362 }
55363 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
55364 /* if it's already open, start I/O ... and notify the serial
55365 * protocol about open/close status (connect/disconnect).
55366 */
55367 - if (port->port.count) {
55368 + if (atomic_read(&port->port.count)) {
55369 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
55370 gs_start_io(port);
55371 if (gser->connect)
55372 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
55373
55374 port->port_usb = NULL;
55375 gser->ioport = NULL;
55376 - if (port->port.count > 0 || port->openclose) {
55377 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
55378 wake_up_interruptible(&port->drain_wait);
55379 if (port->port.tty)
55380 tty_hangup(port->port.tty);
55381 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
55382
55383 /* finally, free any unused/unusable I/O buffers */
55384 spin_lock_irqsave(&port->port_lock, flags);
55385 - if (port->port.count == 0 && !port->openclose)
55386 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
55387 gs_buf_free(&port->port_write_buf);
55388 gs_free_requests(gser->out, &port->read_pool, NULL);
55389 gs_free_requests(gser->out, &port->read_queue, NULL);
55390 diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
55391 index 7a55fea..cc0ed4f 100644
55392 --- a/drivers/usb/gadget/u_uac1.c
55393 +++ b/drivers/usb/gadget/u_uac1.c
55394 @@ -16,6 +16,7 @@
55395 #include <linux/ctype.h>
55396 #include <linux/random.h>
55397 #include <linux/syscalls.h>
55398 +#include <linux/module.h>
55399
55400 #include "u_uac1.h"
55401
55402 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
55403 index 6130b75..3b60008 100644
55404 --- a/drivers/usb/host/ehci-hub.c
55405 +++ b/drivers/usb/host/ehci-hub.c
55406 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
55407 urb->transfer_flags = URB_DIR_IN;
55408 usb_get_urb(urb);
55409 atomic_inc(&urb->use_count);
55410 - atomic_inc(&urb->dev->urbnum);
55411 + atomic_inc_unchecked(&urb->dev->urbnum);
55412 urb->setup_dma = dma_map_single(
55413 hcd->self.controller,
55414 urb->setup_packet,
55415 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
55416 urb->status = -EINPROGRESS;
55417 usb_get_urb(urb);
55418 atomic_inc(&urb->use_count);
55419 - atomic_inc(&urb->dev->urbnum);
55420 + atomic_inc_unchecked(&urb->dev->urbnum);
55421 retval = submit_single_step_set_feature(hcd, urb, 0);
55422 if (!retval && !wait_for_completion_timeout(&done,
55423 msecs_to_jiffies(2000))) {
55424 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
55425 index d0d8fad..668ef7b 100644
55426 --- a/drivers/usb/host/hwa-hc.c
55427 +++ b/drivers/usb/host/hwa-hc.c
55428 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
55429 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
55430 struct wahc *wa = &hwahc->wa;
55431 struct device *dev = &wa->usb_iface->dev;
55432 - u8 mas_le[UWB_NUM_MAS/8];
55433 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
55434 +
55435 + if (mas_le == NULL)
55436 + return -ENOMEM;
55437
55438 /* Set the stream index */
55439 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
55440 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
55441 WUSB_REQ_SET_WUSB_MAS,
55442 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
55443 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
55444 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
55445 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
55446 if (result < 0)
55447 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
55448 out:
55449 + kfree(mas_le);
55450 +
55451 return result;
55452 }
55453
55454 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
55455 index b3d245e..99549ed 100644
55456 --- a/drivers/usb/misc/appledisplay.c
55457 +++ b/drivers/usb/misc/appledisplay.c
55458 @@ -84,7 +84,7 @@ struct appledisplay {
55459 struct mutex sysfslock; /* concurrent read and write */
55460 };
55461
55462 -static atomic_t count_displays = ATOMIC_INIT(0);
55463 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
55464 static struct workqueue_struct *wq;
55465
55466 static void appledisplay_complete(struct urb *urb)
55467 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
55468
55469 /* Register backlight device */
55470 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
55471 - atomic_inc_return(&count_displays) - 1);
55472 + atomic_inc_return_unchecked(&count_displays) - 1);
55473 memset(&props, 0, sizeof(struct backlight_properties));
55474 props.type = BACKLIGHT_RAW;
55475 props.max_brightness = 0xff;
55476 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
55477 index 8d7fc48..01c4986 100644
55478 --- a/drivers/usb/serial/console.c
55479 +++ b/drivers/usb/serial/console.c
55480 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
55481
55482 info->port = port;
55483
55484 - ++port->port.count;
55485 + atomic_inc(&port->port.count);
55486 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
55487 if (serial->type->set_termios) {
55488 /*
55489 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
55490 }
55491 /* Now that any required fake tty operations are completed restore
55492 * the tty port count */
55493 - --port->port.count;
55494 + atomic_dec(&port->port.count);
55495 /* The console is special in terms of closing the device so
55496 * indicate this port is now acting as a system console. */
55497 port->port.console = 1;
55498 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
55499 free_tty:
55500 kfree(tty);
55501 reset_open_count:
55502 - port->port.count = 0;
55503 + atomic_set(&port->port.count, 0);
55504 usb_autopm_put_interface(serial->interface);
55505 error_get_interface:
55506 usb_serial_put(serial);
55507 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
55508 static void usb_console_write(struct console *co,
55509 const char *buf, unsigned count)
55510 {
55511 - static struct usbcons_info *info = &usbcons_info;
55512 + struct usbcons_info *info = &usbcons_info;
55513 struct usb_serial_port *port = info->port;
55514 struct usb_serial *serial;
55515 int retval = -ENODEV;
55516 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
55517 index 307e339..6aa97cb 100644
55518 --- a/drivers/usb/storage/usb.h
55519 +++ b/drivers/usb/storage/usb.h
55520 @@ -63,7 +63,7 @@ struct us_unusual_dev {
55521 __u8 useProtocol;
55522 __u8 useTransport;
55523 int (*initFunction)(struct us_data *);
55524 -};
55525 +} __do_const;
55526
55527
55528 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
55529 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
55530 index f2a8d29..7bc3fe7 100644
55531 --- a/drivers/usb/wusbcore/wa-hc.h
55532 +++ b/drivers/usb/wusbcore/wa-hc.h
55533 @@ -240,7 +240,7 @@ struct wahc {
55534 spinlock_t xfer_list_lock;
55535 struct work_struct xfer_enqueue_work;
55536 struct work_struct xfer_error_work;
55537 - atomic_t xfer_id_count;
55538 + atomic_unchecked_t xfer_id_count;
55539
55540 kernel_ulong_t quirks;
55541 };
55542 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
55543 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
55544 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
55545 wa->dto_in_use = 0;
55546 - atomic_set(&wa->xfer_id_count, 1);
55547 + atomic_set_unchecked(&wa->xfer_id_count, 1);
55548 /* init the buf in URBs */
55549 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
55550 usb_init_urb(&(wa->buf_in_urbs[index]));
55551 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
55552 index 3e2e4ed..060c9b8 100644
55553 --- a/drivers/usb/wusbcore/wa-xfer.c
55554 +++ b/drivers/usb/wusbcore/wa-xfer.c
55555 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
55556 */
55557 static void wa_xfer_id_init(struct wa_xfer *xfer)
55558 {
55559 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
55560 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
55561 }
55562
55563 /* Return the xfer's ID. */
55564 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
55565 index f018d8d..ccab63f 100644
55566 --- a/drivers/vfio/vfio.c
55567 +++ b/drivers/vfio/vfio.c
55568 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
55569 return 0;
55570
55571 /* TODO Prevent device auto probing */
55572 - WARN("Device %s added to live group %d!\n", dev_name(dev),
55573 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
55574 iommu_group_id(group->iommu_group));
55575
55576 return 0;
55577 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
55578 index 5174eba..451e6bc 100644
55579 --- a/drivers/vhost/vringh.c
55580 +++ b/drivers/vhost/vringh.c
55581 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
55582 /* Userspace access helpers: in this case, addresses are really userspace. */
55583 static inline int getu16_user(u16 *val, const u16 *p)
55584 {
55585 - return get_user(*val, (__force u16 __user *)p);
55586 + return get_user(*val, (u16 __force_user *)p);
55587 }
55588
55589 static inline int putu16_user(u16 *p, u16 val)
55590 {
55591 - return put_user(val, (__force u16 __user *)p);
55592 + return put_user(val, (u16 __force_user *)p);
55593 }
55594
55595 static inline int copydesc_user(void *dst, const void *src, size_t len)
55596 {
55597 - return copy_from_user(dst, (__force void __user *)src, len) ?
55598 + return copy_from_user(dst, (void __force_user *)src, len) ?
55599 -EFAULT : 0;
55600 }
55601
55602 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
55603 const struct vring_used_elem *src,
55604 unsigned int num)
55605 {
55606 - return copy_to_user((__force void __user *)dst, src,
55607 + return copy_to_user((void __force_user *)dst, src,
55608 sizeof(*dst) * num) ? -EFAULT : 0;
55609 }
55610
55611 static inline int xfer_from_user(void *src, void *dst, size_t len)
55612 {
55613 - return copy_from_user(dst, (__force void __user *)src, len) ?
55614 + return copy_from_user(dst, (void __force_user *)src, len) ?
55615 -EFAULT : 0;
55616 }
55617
55618 static inline int xfer_to_user(void *dst, void *src, size_t len)
55619 {
55620 - return copy_to_user((__force void __user *)dst, src, len) ?
55621 + return copy_to_user((void __force_user *)dst, src, len) ?
55622 -EFAULT : 0;
55623 }
55624
55625 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
55626 vrh->last_used_idx = 0;
55627 vrh->vring.num = num;
55628 /* vring expects kernel addresses, but only used via accessors. */
55629 - vrh->vring.desc = (__force struct vring_desc *)desc;
55630 - vrh->vring.avail = (__force struct vring_avail *)avail;
55631 - vrh->vring.used = (__force struct vring_used *)used;
55632 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
55633 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
55634 + vrh->vring.used = (__force_kernel struct vring_used *)used;
55635 return 0;
55636 }
55637 EXPORT_SYMBOL(vringh_init_user);
55638 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
55639
55640 static inline int putu16_kern(u16 *p, u16 val)
55641 {
55642 - ACCESS_ONCE(*p) = val;
55643 + ACCESS_ONCE_RW(*p) = val;
55644 return 0;
55645 }
55646
55647 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
55648 index 84a110a..96312c3 100644
55649 --- a/drivers/video/backlight/kb3886_bl.c
55650 +++ b/drivers/video/backlight/kb3886_bl.c
55651 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
55652 static unsigned long kb3886bl_flags;
55653 #define KB3886BL_SUSPENDED 0x01
55654
55655 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
55656 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
55657 {
55658 .ident = "Sahara Touch-iT",
55659 .matches = {
55660 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
55661 index 1b0b233..6f34c2c 100644
55662 --- a/drivers/video/fbdev/arcfb.c
55663 +++ b/drivers/video/fbdev/arcfb.c
55664 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
55665 return -ENOSPC;
55666
55667 err = 0;
55668 - if ((count + p) > fbmemlength) {
55669 + if (count > (fbmemlength - p)) {
55670 count = fbmemlength - p;
55671 err = -ENOSPC;
55672 }
55673 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
55674 index 52108be..c7c110d 100644
55675 --- a/drivers/video/fbdev/aty/aty128fb.c
55676 +++ b/drivers/video/fbdev/aty/aty128fb.c
55677 @@ -149,7 +149,7 @@ enum {
55678 };
55679
55680 /* Must match above enum */
55681 -static char * const r128_family[] = {
55682 +static const char * const r128_family[] = {
55683 "AGP",
55684 "PCI",
55685 "PRO AGP",
55686 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
55687 index c3d0074..0b9077e 100644
55688 --- a/drivers/video/fbdev/aty/atyfb_base.c
55689 +++ b/drivers/video/fbdev/aty/atyfb_base.c
55690 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
55691 par->accel_flags = var->accel_flags; /* hack */
55692
55693 if (var->accel_flags) {
55694 - info->fbops->fb_sync = atyfb_sync;
55695 + pax_open_kernel();
55696 + *(void **)&info->fbops->fb_sync = atyfb_sync;
55697 + pax_close_kernel();
55698 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55699 } else {
55700 - info->fbops->fb_sync = NULL;
55701 + pax_open_kernel();
55702 + *(void **)&info->fbops->fb_sync = NULL;
55703 + pax_close_kernel();
55704 info->flags |= FBINFO_HWACCEL_DISABLED;
55705 }
55706
55707 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
55708 index 2fa0317..4983f2a 100644
55709 --- a/drivers/video/fbdev/aty/mach64_cursor.c
55710 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
55711 @@ -8,6 +8,7 @@
55712 #include "../core/fb_draw.h"
55713
55714 #include <asm/io.h>
55715 +#include <asm/pgtable.h>
55716
55717 #ifdef __sparc__
55718 #include <asm/fbio.h>
55719 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
55720 info->sprite.buf_align = 16; /* and 64 lines tall. */
55721 info->sprite.flags = FB_PIXMAP_IO;
55722
55723 - info->fbops->fb_cursor = atyfb_cursor;
55724 + pax_open_kernel();
55725 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
55726 + pax_close_kernel();
55727
55728 return 0;
55729 }
55730 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
55731 index 900aa4e..6d49418 100644
55732 --- a/drivers/video/fbdev/core/fb_defio.c
55733 +++ b/drivers/video/fbdev/core/fb_defio.c
55734 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
55735
55736 BUG_ON(!fbdefio);
55737 mutex_init(&fbdefio->lock);
55738 - info->fbops->fb_mmap = fb_deferred_io_mmap;
55739 + pax_open_kernel();
55740 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
55741 + pax_close_kernel();
55742 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
55743 INIT_LIST_HEAD(&fbdefio->pagelist);
55744 if (fbdefio->delay == 0) /* set a default of 1 s */
55745 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
55746 page->mapping = NULL;
55747 }
55748
55749 - info->fbops->fb_mmap = NULL;
55750 + *(void **)&info->fbops->fb_mmap = NULL;
55751 mutex_destroy(&fbdefio->lock);
55752 }
55753 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
55754 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
55755 index b5e85f6..290f8c7 100644
55756 --- a/drivers/video/fbdev/core/fbmem.c
55757 +++ b/drivers/video/fbdev/core/fbmem.c
55758 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
55759 __u32 data;
55760 int err;
55761
55762 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
55763 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
55764
55765 data = (__u32) (unsigned long) fix->smem_start;
55766 err |= put_user(data, &fix32->smem_start);
55767 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
55768 index e23392e..8a77540 100644
55769 --- a/drivers/video/fbdev/hyperv_fb.c
55770 +++ b/drivers/video/fbdev/hyperv_fb.c
55771 @@ -235,7 +235,7 @@ static uint screen_fb_size;
55772 static inline int synthvid_send(struct hv_device *hdev,
55773 struct synthvid_msg *msg)
55774 {
55775 - static atomic64_t request_id = ATOMIC64_INIT(0);
55776 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55777 int ret;
55778
55779 msg->pipe_hdr.type = PIPE_MSG_DATA;
55780 @@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55781
55782 ret = vmbus_sendpacket(hdev->channel, msg,
55783 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55784 - atomic64_inc_return(&request_id),
55785 + atomic64_inc_return_unchecked(&request_id),
55786 VM_PKT_DATA_INBAND, 0);
55787
55788 if (ret)
55789 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55790 index 7672d2e..b56437f 100644
55791 --- a/drivers/video/fbdev/i810/i810_accel.c
55792 +++ b/drivers/video/fbdev/i810/i810_accel.c
55793 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55794 }
55795 }
55796 printk("ringbuffer lockup!!!\n");
55797 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55798 i810_report_error(mmio);
55799 par->dev_flags |= LOCKUP;
55800 info->pixmap.scan_align = 1;
55801 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55802 index a01147f..5d896f8 100644
55803 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55804 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55805 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55806
55807 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55808 struct matrox_switch matrox_mystique = {
55809 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55810 + .preinit = MGA1064_preinit,
55811 + .reset = MGA1064_reset,
55812 + .init = MGA1064_init,
55813 + .restore = MGA1064_restore,
55814 };
55815 EXPORT_SYMBOL(matrox_mystique);
55816 #endif
55817
55818 #ifdef CONFIG_FB_MATROX_G
55819 struct matrox_switch matrox_G100 = {
55820 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55821 + .preinit = MGAG100_preinit,
55822 + .reset = MGAG100_reset,
55823 + .init = MGAG100_init,
55824 + .restore = MGAG100_restore,
55825 };
55826 EXPORT_SYMBOL(matrox_G100);
55827 #endif
55828 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55829 index 195ad7c..09743fc 100644
55830 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55831 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55832 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55833 }
55834
55835 struct matrox_switch matrox_millennium = {
55836 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55837 + .preinit = Ti3026_preinit,
55838 + .reset = Ti3026_reset,
55839 + .init = Ti3026_init,
55840 + .restore = Ti3026_restore
55841 };
55842 EXPORT_SYMBOL(matrox_millennium);
55843 #endif
55844 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55845 index fe92eed..106e085 100644
55846 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55847 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55848 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55849 struct mb862xxfb_par *par = info->par;
55850
55851 if (info->var.bits_per_pixel == 32) {
55852 - info->fbops->fb_fillrect = cfb_fillrect;
55853 - info->fbops->fb_copyarea = cfb_copyarea;
55854 - info->fbops->fb_imageblit = cfb_imageblit;
55855 + pax_open_kernel();
55856 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55857 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55858 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55859 + pax_close_kernel();
55860 } else {
55861 outreg(disp, GC_L0EM, 3);
55862 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55863 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55864 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55865 + pax_open_kernel();
55866 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55867 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55868 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55869 + pax_close_kernel();
55870 }
55871 outreg(draw, GDC_REG_DRAW_BASE, 0);
55872 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55873 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55874 index def0412..fed6529 100644
55875 --- a/drivers/video/fbdev/nvidia/nvidia.c
55876 +++ b/drivers/video/fbdev/nvidia/nvidia.c
55877 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55878 info->fix.line_length = (info->var.xres_virtual *
55879 info->var.bits_per_pixel) >> 3;
55880 if (info->var.accel_flags) {
55881 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55882 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55883 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55884 - info->fbops->fb_sync = nvidiafb_sync;
55885 + pax_open_kernel();
55886 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55887 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55888 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55889 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55890 + pax_close_kernel();
55891 info->pixmap.scan_align = 4;
55892 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55893 info->flags |= FBINFO_READS_FAST;
55894 NVResetGraphics(info);
55895 } else {
55896 - info->fbops->fb_imageblit = cfb_imageblit;
55897 - info->fbops->fb_fillrect = cfb_fillrect;
55898 - info->fbops->fb_copyarea = cfb_copyarea;
55899 - info->fbops->fb_sync = NULL;
55900 + pax_open_kernel();
55901 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55902 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55903 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55904 + *(void **)&info->fbops->fb_sync = NULL;
55905 + pax_close_kernel();
55906 info->pixmap.scan_align = 1;
55907 info->flags |= FBINFO_HWACCEL_DISABLED;
55908 info->flags &= ~FBINFO_READS_FAST;
55909 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55910 info->pixmap.size = 8 * 1024;
55911 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55912
55913 - if (!hwcur)
55914 - info->fbops->fb_cursor = NULL;
55915 + if (!hwcur) {
55916 + pax_open_kernel();
55917 + *(void **)&info->fbops->fb_cursor = NULL;
55918 + pax_close_kernel();
55919 + }
55920
55921 info->var.accel_flags = (!noaccel);
55922
55923 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
55924 index 2412a0d..294215b 100644
55925 --- a/drivers/video/fbdev/omap2/dss/display.c
55926 +++ b/drivers/video/fbdev/omap2/dss/display.c
55927 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55928 if (dssdev->name == NULL)
55929 dssdev->name = dssdev->alias;
55930
55931 + pax_open_kernel();
55932 if (drv && drv->get_resolution == NULL)
55933 - drv->get_resolution = omapdss_default_get_resolution;
55934 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55935 if (drv && drv->get_recommended_bpp == NULL)
55936 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55937 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55938 if (drv && drv->get_timings == NULL)
55939 - drv->get_timings = omapdss_default_get_timings;
55940 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55941 + pax_close_kernel();
55942
55943 mutex_lock(&panel_list_mutex);
55944 list_add_tail(&dssdev->panel_list, &panel_list);
55945 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
55946 index 83433cb..71e9b98 100644
55947 --- a/drivers/video/fbdev/s1d13xxxfb.c
55948 +++ b/drivers/video/fbdev/s1d13xxxfb.c
55949 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55950
55951 switch(prod_id) {
55952 case S1D13506_PROD_ID: /* activate acceleration */
55953 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55954 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55955 + pax_open_kernel();
55956 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55957 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55958 + pax_close_kernel();
55959 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55960 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55961 break;
55962 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55963 index 2bcc84a..29dd1ea 100644
55964 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
55965 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55966 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55967 }
55968
55969 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55970 - lcdc_sys_write_index,
55971 - lcdc_sys_write_data,
55972 - lcdc_sys_read_data,
55973 + .write_index = lcdc_sys_write_index,
55974 + .write_data = lcdc_sys_write_data,
55975 + .read_data = lcdc_sys_read_data,
55976 };
55977
55978 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55979 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
55980 index d513ed6..90b0de9 100644
55981 --- a/drivers/video/fbdev/smscufx.c
55982 +++ b/drivers/video/fbdev/smscufx.c
55983 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55984 fb_deferred_io_cleanup(info);
55985 kfree(info->fbdefio);
55986 info->fbdefio = NULL;
55987 - info->fbops->fb_mmap = ufx_ops_mmap;
55988 + pax_open_kernel();
55989 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55990 + pax_close_kernel();
55991 }
55992
55993 pr_debug("released /dev/fb%d user=%d count=%d",
55994 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
55995 index 77b890e..458e666 100644
55996 --- a/drivers/video/fbdev/udlfb.c
55997 +++ b/drivers/video/fbdev/udlfb.c
55998 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55999 dlfb_urb_completion(urb);
56000
56001 error:
56002 - atomic_add(bytes_sent, &dev->bytes_sent);
56003 - atomic_add(bytes_identical, &dev->bytes_identical);
56004 - atomic_add(width*height*2, &dev->bytes_rendered);
56005 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56006 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56007 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
56008 end_cycles = get_cycles();
56009 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
56010 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56011 >> 10)), /* Kcycles */
56012 &dev->cpu_kcycles_used);
56013
56014 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
56015 dlfb_urb_completion(urb);
56016
56017 error:
56018 - atomic_add(bytes_sent, &dev->bytes_sent);
56019 - atomic_add(bytes_identical, &dev->bytes_identical);
56020 - atomic_add(bytes_rendered, &dev->bytes_rendered);
56021 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56022 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56023 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
56024 end_cycles = get_cycles();
56025 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
56026 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56027 >> 10)), /* Kcycles */
56028 &dev->cpu_kcycles_used);
56029 }
56030 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
56031 fb_deferred_io_cleanup(info);
56032 kfree(info->fbdefio);
56033 info->fbdefio = NULL;
56034 - info->fbops->fb_mmap = dlfb_ops_mmap;
56035 + pax_open_kernel();
56036 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
56037 + pax_close_kernel();
56038 }
56039
56040 pr_warn("released /dev/fb%d user=%d count=%d\n",
56041 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
56042 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56043 struct dlfb_data *dev = fb_info->par;
56044 return snprintf(buf, PAGE_SIZE, "%u\n",
56045 - atomic_read(&dev->bytes_rendered));
56046 + atomic_read_unchecked(&dev->bytes_rendered));
56047 }
56048
56049 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56050 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56051 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56052 struct dlfb_data *dev = fb_info->par;
56053 return snprintf(buf, PAGE_SIZE, "%u\n",
56054 - atomic_read(&dev->bytes_identical));
56055 + atomic_read_unchecked(&dev->bytes_identical));
56056 }
56057
56058 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56059 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56060 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56061 struct dlfb_data *dev = fb_info->par;
56062 return snprintf(buf, PAGE_SIZE, "%u\n",
56063 - atomic_read(&dev->bytes_sent));
56064 + atomic_read_unchecked(&dev->bytes_sent));
56065 }
56066
56067 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56068 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56069 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56070 struct dlfb_data *dev = fb_info->par;
56071 return snprintf(buf, PAGE_SIZE, "%u\n",
56072 - atomic_read(&dev->cpu_kcycles_used));
56073 + atomic_read_unchecked(&dev->cpu_kcycles_used));
56074 }
56075
56076 static ssize_t edid_show(
56077 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
56078 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56079 struct dlfb_data *dev = fb_info->par;
56080
56081 - atomic_set(&dev->bytes_rendered, 0);
56082 - atomic_set(&dev->bytes_identical, 0);
56083 - atomic_set(&dev->bytes_sent, 0);
56084 - atomic_set(&dev->cpu_kcycles_used, 0);
56085 + atomic_set_unchecked(&dev->bytes_rendered, 0);
56086 + atomic_set_unchecked(&dev->bytes_identical, 0);
56087 + atomic_set_unchecked(&dev->bytes_sent, 0);
56088 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
56089
56090 return count;
56091 }
56092 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
56093 index 509d452..7c9d2de 100644
56094 --- a/drivers/video/fbdev/uvesafb.c
56095 +++ b/drivers/video/fbdev/uvesafb.c
56096 @@ -19,6 +19,7 @@
56097 #include <linux/io.h>
56098 #include <linux/mutex.h>
56099 #include <linux/slab.h>
56100 +#include <linux/moduleloader.h>
56101 #include <video/edid.h>
56102 #include <video/uvesafb.h>
56103 #ifdef CONFIG_X86
56104 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
56105 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
56106 par->pmi_setpal = par->ypan = 0;
56107 } else {
56108 +
56109 +#ifdef CONFIG_PAX_KERNEXEC
56110 +#ifdef CONFIG_MODULES
56111 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
56112 +#endif
56113 + if (!par->pmi_code) {
56114 + par->pmi_setpal = par->ypan = 0;
56115 + return 0;
56116 + }
56117 +#endif
56118 +
56119 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
56120 + task->t.regs.edi);
56121 +
56122 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56123 + pax_open_kernel();
56124 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
56125 + pax_close_kernel();
56126 +
56127 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
56128 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
56129 +#else
56130 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
56131 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
56132 +#endif
56133 +
56134 printk(KERN_INFO "uvesafb: protected mode interface info at "
56135 "%04x:%04x\n",
56136 (u16)task->t.regs.es, (u16)task->t.regs.edi);
56137 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
56138 par->ypan = ypan;
56139
56140 if (par->pmi_setpal || par->ypan) {
56141 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
56142 if (__supported_pte_mask & _PAGE_NX) {
56143 par->pmi_setpal = par->ypan = 0;
56144 printk(KERN_WARNING "uvesafb: NX protection is active, "
56145 "better not use the PMI.\n");
56146 - } else {
56147 + } else
56148 +#endif
56149 uvesafb_vbe_getpmi(task, par);
56150 - }
56151 }
56152 #else
56153 /* The protected mode interface is not available on non-x86. */
56154 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56155 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
56156
56157 /* Disable blanking if the user requested so. */
56158 - if (!blank)
56159 - info->fbops->fb_blank = NULL;
56160 + if (!blank) {
56161 + pax_open_kernel();
56162 + *(void **)&info->fbops->fb_blank = NULL;
56163 + pax_close_kernel();
56164 + }
56165
56166 /*
56167 * Find out how much IO memory is required for the mode with
56168 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56169 info->flags = FBINFO_FLAG_DEFAULT |
56170 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
56171
56172 - if (!par->ypan)
56173 - info->fbops->fb_pan_display = NULL;
56174 + if (!par->ypan) {
56175 + pax_open_kernel();
56176 + *(void **)&info->fbops->fb_pan_display = NULL;
56177 + pax_close_kernel();
56178 + }
56179 }
56180
56181 static void uvesafb_init_mtrr(struct fb_info *info)
56182 @@ -1787,6 +1817,11 @@ out_mode:
56183 out:
56184 kfree(par->vbe_modes);
56185
56186 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56187 + if (par->pmi_code)
56188 + module_free_exec(NULL, par->pmi_code);
56189 +#endif
56190 +
56191 framebuffer_release(info);
56192 return err;
56193 }
56194 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
56195 kfree(par->vbe_state_orig);
56196 kfree(par->vbe_state_saved);
56197
56198 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56199 + if (par->pmi_code)
56200 + module_free_exec(NULL, par->pmi_code);
56201 +#endif
56202 +
56203 framebuffer_release(info);
56204 }
56205 return 0;
56206 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
56207 index 6170e7f..dd63031 100644
56208 --- a/drivers/video/fbdev/vesafb.c
56209 +++ b/drivers/video/fbdev/vesafb.c
56210 @@ -9,6 +9,7 @@
56211 */
56212
56213 #include <linux/module.h>
56214 +#include <linux/moduleloader.h>
56215 #include <linux/kernel.h>
56216 #include <linux/errno.h>
56217 #include <linux/string.h>
56218 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
56219 static int vram_total; /* Set total amount of memory */
56220 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
56221 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
56222 -static void (*pmi_start)(void) __read_mostly;
56223 -static void (*pmi_pal) (void) __read_mostly;
56224 +static void (*pmi_start)(void) __read_only;
56225 +static void (*pmi_pal) (void) __read_only;
56226 static int depth __read_mostly;
56227 static int vga_compat __read_mostly;
56228 /* --------------------------------------------------------------------- */
56229 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
56230 unsigned int size_remap;
56231 unsigned int size_total;
56232 char *option = NULL;
56233 + void *pmi_code = NULL;
56234
56235 /* ignore error return of fb_get_options */
56236 fb_get_options("vesafb", &option);
56237 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
56238 size_remap = size_total;
56239 vesafb_fix.smem_len = size_remap;
56240
56241 -#ifndef __i386__
56242 - screen_info.vesapm_seg = 0;
56243 -#endif
56244 -
56245 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
56246 printk(KERN_WARNING
56247 "vesafb: cannot reserve video memory at 0x%lx\n",
56248 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
56249 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
56250 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
56251
56252 +#ifdef __i386__
56253 +
56254 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56255 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
56256 + if (!pmi_code)
56257 +#elif !defined(CONFIG_PAX_KERNEXEC)
56258 + if (0)
56259 +#endif
56260 +
56261 +#endif
56262 + screen_info.vesapm_seg = 0;
56263 +
56264 if (screen_info.vesapm_seg) {
56265 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
56266 - screen_info.vesapm_seg,screen_info.vesapm_off);
56267 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
56268 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
56269 }
56270
56271 if (screen_info.vesapm_seg < 0xc000)
56272 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
56273
56274 if (ypan || pmi_setpal) {
56275 unsigned short *pmi_base;
56276 +
56277 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
56278 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
56279 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
56280 +
56281 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56282 + pax_open_kernel();
56283 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
56284 +#else
56285 + pmi_code = pmi_base;
56286 +#endif
56287 +
56288 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
56289 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
56290 +
56291 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56292 + pmi_start = ktva_ktla(pmi_start);
56293 + pmi_pal = ktva_ktla(pmi_pal);
56294 + pax_close_kernel();
56295 +#endif
56296 +
56297 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
56298 if (pmi_base[3]) {
56299 printk(KERN_INFO "vesafb: pmi: ports = ");
56300 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
56301 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
56302 (ypan ? FBINFO_HWACCEL_YPAN : 0);
56303
56304 - if (!ypan)
56305 - info->fbops->fb_pan_display = NULL;
56306 + if (!ypan) {
56307 + pax_open_kernel();
56308 + *(void **)&info->fbops->fb_pan_display = NULL;
56309 + pax_close_kernel();
56310 + }
56311
56312 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
56313 err = -ENOMEM;
56314 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
56315 fb_info(info, "%s frame buffer device\n", info->fix.id);
56316 return 0;
56317 err:
56318 +
56319 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56320 + module_free_exec(NULL, pmi_code);
56321 +#endif
56322 +
56323 if (info->screen_base)
56324 iounmap(info->screen_base);
56325 framebuffer_release(info);
56326 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
56327 index 88714ae..16c2e11 100644
56328 --- a/drivers/video/fbdev/via/via_clock.h
56329 +++ b/drivers/video/fbdev/via/via_clock.h
56330 @@ -56,7 +56,7 @@ struct via_clock {
56331
56332 void (*set_engine_pll_state)(u8 state);
56333 void (*set_engine_pll)(struct via_pll_config config);
56334 -};
56335 +} __no_const;
56336
56337
56338 static inline u32 get_pll_internal_frequency(u32 ref_freq,
56339 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
56340 index 3c14e43..2630570 100644
56341 --- a/drivers/video/logo/logo_linux_clut224.ppm
56342 +++ b/drivers/video/logo/logo_linux_clut224.ppm
56343 @@ -2,1603 +2,1123 @@ P3
56344 # Standard 224-color Linux logo
56345 80 80
56346 255
56347 - 0 0 0 0 0 0 0 0 0 0 0 0
56348 - 0 0 0 0 0 0 0 0 0 0 0 0
56349 - 0 0 0 0 0 0 0 0 0 0 0 0
56350 - 0 0 0 0 0 0 0 0 0 0 0 0
56351 - 0 0 0 0 0 0 0 0 0 0 0 0
56352 - 0 0 0 0 0 0 0 0 0 0 0 0
56353 - 0 0 0 0 0 0 0 0 0 0 0 0
56354 - 0 0 0 0 0 0 0 0 0 0 0 0
56355 - 0 0 0 0 0 0 0 0 0 0 0 0
56356 - 6 6 6 6 6 6 10 10 10 10 10 10
56357 - 10 10 10 6 6 6 6 6 6 6 6 6
56358 - 0 0 0 0 0 0 0 0 0 0 0 0
56359 - 0 0 0 0 0 0 0 0 0 0 0 0
56360 - 0 0 0 0 0 0 0 0 0 0 0 0
56361 - 0 0 0 0 0 0 0 0 0 0 0 0
56362 - 0 0 0 0 0 0 0 0 0 0 0 0
56363 - 0 0 0 0 0 0 0 0 0 0 0 0
56364 - 0 0 0 0 0 0 0 0 0 0 0 0
56365 - 0 0 0 0 0 0 0 0 0 0 0 0
56366 - 0 0 0 0 0 0 0 0 0 0 0 0
56367 - 0 0 0 0 0 0 0 0 0 0 0 0
56368 - 0 0 0 0 0 0 0 0 0 0 0 0
56369 - 0 0 0 0 0 0 0 0 0 0 0 0
56370 - 0 0 0 0 0 0 0 0 0 0 0 0
56371 - 0 0 0 0 0 0 0 0 0 0 0 0
56372 - 0 0 0 0 0 0 0 0 0 0 0 0
56373 - 0 0 0 0 0 0 0 0 0 0 0 0
56374 - 0 0 0 0 0 0 0 0 0 0 0 0
56375 - 0 0 0 6 6 6 10 10 10 14 14 14
56376 - 22 22 22 26 26 26 30 30 30 34 34 34
56377 - 30 30 30 30 30 30 26 26 26 18 18 18
56378 - 14 14 14 10 10 10 6 6 6 0 0 0
56379 - 0 0 0 0 0 0 0 0 0 0 0 0
56380 - 0 0 0 0 0 0 0 0 0 0 0 0
56381 - 0 0 0 0 0 0 0 0 0 0 0 0
56382 - 0 0 0 0 0 0 0 0 0 0 0 0
56383 - 0 0 0 0 0 0 0 0 0 0 0 0
56384 - 0 0 0 0 0 0 0 0 0 0 0 0
56385 - 0 0 0 0 0 0 0 0 0 0 0 0
56386 - 0 0 0 0 0 0 0 0 0 0 0 0
56387 - 0 0 0 0 0 0 0 0 0 0 0 0
56388 - 0 0 0 0 0 1 0 0 1 0 0 0
56389 - 0 0 0 0 0 0 0 0 0 0 0 0
56390 - 0 0 0 0 0 0 0 0 0 0 0 0
56391 - 0 0 0 0 0 0 0 0 0 0 0 0
56392 - 0 0 0 0 0 0 0 0 0 0 0 0
56393 - 0 0 0 0 0 0 0 0 0 0 0 0
56394 - 0 0 0 0 0 0 0 0 0 0 0 0
56395 - 6 6 6 14 14 14 26 26 26 42 42 42
56396 - 54 54 54 66 66 66 78 78 78 78 78 78
56397 - 78 78 78 74 74 74 66 66 66 54 54 54
56398 - 42 42 42 26 26 26 18 18 18 10 10 10
56399 - 6 6 6 0 0 0 0 0 0 0 0 0
56400 - 0 0 0 0 0 0 0 0 0 0 0 0
56401 - 0 0 0 0 0 0 0 0 0 0 0 0
56402 - 0 0 0 0 0 0 0 0 0 0 0 0
56403 - 0 0 0 0 0 0 0 0 0 0 0 0
56404 - 0 0 0 0 0 0 0 0 0 0 0 0
56405 - 0 0 0 0 0 0 0 0 0 0 0 0
56406 - 0 0 0 0 0 0 0 0 0 0 0 0
56407 - 0 0 0 0 0 0 0 0 0 0 0 0
56408 - 0 0 1 0 0 0 0 0 0 0 0 0
56409 - 0 0 0 0 0 0 0 0 0 0 0 0
56410 - 0 0 0 0 0 0 0 0 0 0 0 0
56411 - 0 0 0 0 0 0 0 0 0 0 0 0
56412 - 0 0 0 0 0 0 0 0 0 0 0 0
56413 - 0 0 0 0 0 0 0 0 0 0 0 0
56414 - 0 0 0 0 0 0 0 0 0 10 10 10
56415 - 22 22 22 42 42 42 66 66 66 86 86 86
56416 - 66 66 66 38 38 38 38 38 38 22 22 22
56417 - 26 26 26 34 34 34 54 54 54 66 66 66
56418 - 86 86 86 70 70 70 46 46 46 26 26 26
56419 - 14 14 14 6 6 6 0 0 0 0 0 0
56420 - 0 0 0 0 0 0 0 0 0 0 0 0
56421 - 0 0 0 0 0 0 0 0 0 0 0 0
56422 - 0 0 0 0 0 0 0 0 0 0 0 0
56423 - 0 0 0 0 0 0 0 0 0 0 0 0
56424 - 0 0 0 0 0 0 0 0 0 0 0 0
56425 - 0 0 0 0 0 0 0 0 0 0 0 0
56426 - 0 0 0 0 0 0 0 0 0 0 0 0
56427 - 0 0 0 0 0 0 0 0 0 0 0 0
56428 - 0 0 1 0 0 1 0 0 1 0 0 0
56429 - 0 0 0 0 0 0 0 0 0 0 0 0
56430 - 0 0 0 0 0 0 0 0 0 0 0 0
56431 - 0 0 0 0 0 0 0 0 0 0 0 0
56432 - 0 0 0 0 0 0 0 0 0 0 0 0
56433 - 0 0 0 0 0 0 0 0 0 0 0 0
56434 - 0 0 0 0 0 0 10 10 10 26 26 26
56435 - 50 50 50 82 82 82 58 58 58 6 6 6
56436 - 2 2 6 2 2 6 2 2 6 2 2 6
56437 - 2 2 6 2 2 6 2 2 6 2 2 6
56438 - 6 6 6 54 54 54 86 86 86 66 66 66
56439 - 38 38 38 18 18 18 6 6 6 0 0 0
56440 - 0 0 0 0 0 0 0 0 0 0 0 0
56441 - 0 0 0 0 0 0 0 0 0 0 0 0
56442 - 0 0 0 0 0 0 0 0 0 0 0 0
56443 - 0 0 0 0 0 0 0 0 0 0 0 0
56444 - 0 0 0 0 0 0 0 0 0 0 0 0
56445 - 0 0 0 0 0 0 0 0 0 0 0 0
56446 - 0 0 0 0 0 0 0 0 0 0 0 0
56447 - 0 0 0 0 0 0 0 0 0 0 0 0
56448 - 0 0 0 0 0 0 0 0 0 0 0 0
56449 - 0 0 0 0 0 0 0 0 0 0 0 0
56450 - 0 0 0 0 0 0 0 0 0 0 0 0
56451 - 0 0 0 0 0 0 0 0 0 0 0 0
56452 - 0 0 0 0 0 0 0 0 0 0 0 0
56453 - 0 0 0 0 0 0 0 0 0 0 0 0
56454 - 0 0 0 6 6 6 22 22 22 50 50 50
56455 - 78 78 78 34 34 34 2 2 6 2 2 6
56456 - 2 2 6 2 2 6 2 2 6 2 2 6
56457 - 2 2 6 2 2 6 2 2 6 2 2 6
56458 - 2 2 6 2 2 6 6 6 6 70 70 70
56459 - 78 78 78 46 46 46 22 22 22 6 6 6
56460 - 0 0 0 0 0 0 0 0 0 0 0 0
56461 - 0 0 0 0 0 0 0 0 0 0 0 0
56462 - 0 0 0 0 0 0 0 0 0 0 0 0
56463 - 0 0 0 0 0 0 0 0 0 0 0 0
56464 - 0 0 0 0 0 0 0 0 0 0 0 0
56465 - 0 0 0 0 0 0 0 0 0 0 0 0
56466 - 0 0 0 0 0 0 0 0 0 0 0 0
56467 - 0 0 0 0 0 0 0 0 0 0 0 0
56468 - 0 0 1 0 0 1 0 0 1 0 0 0
56469 - 0 0 0 0 0 0 0 0 0 0 0 0
56470 - 0 0 0 0 0 0 0 0 0 0 0 0
56471 - 0 0 0 0 0 0 0 0 0 0 0 0
56472 - 0 0 0 0 0 0 0 0 0 0 0 0
56473 - 0 0 0 0 0 0 0 0 0 0 0 0
56474 - 6 6 6 18 18 18 42 42 42 82 82 82
56475 - 26 26 26 2 2 6 2 2 6 2 2 6
56476 - 2 2 6 2 2 6 2 2 6 2 2 6
56477 - 2 2 6 2 2 6 2 2 6 14 14 14
56478 - 46 46 46 34 34 34 6 6 6 2 2 6
56479 - 42 42 42 78 78 78 42 42 42 18 18 18
56480 - 6 6 6 0 0 0 0 0 0 0 0 0
56481 - 0 0 0 0 0 0 0 0 0 0 0 0
56482 - 0 0 0 0 0 0 0 0 0 0 0 0
56483 - 0 0 0 0 0 0 0 0 0 0 0 0
56484 - 0 0 0 0 0 0 0 0 0 0 0 0
56485 - 0 0 0 0 0 0 0 0 0 0 0 0
56486 - 0 0 0 0 0 0 0 0 0 0 0 0
56487 - 0 0 0 0 0 0 0 0 0 0 0 0
56488 - 0 0 1 0 0 0 0 0 1 0 0 0
56489 - 0 0 0 0 0 0 0 0 0 0 0 0
56490 - 0 0 0 0 0 0 0 0 0 0 0 0
56491 - 0 0 0 0 0 0 0 0 0 0 0 0
56492 - 0 0 0 0 0 0 0 0 0 0 0 0
56493 - 0 0 0 0 0 0 0 0 0 0 0 0
56494 - 10 10 10 30 30 30 66 66 66 58 58 58
56495 - 2 2 6 2 2 6 2 2 6 2 2 6
56496 - 2 2 6 2 2 6 2 2 6 2 2 6
56497 - 2 2 6 2 2 6 2 2 6 26 26 26
56498 - 86 86 86 101 101 101 46 46 46 10 10 10
56499 - 2 2 6 58 58 58 70 70 70 34 34 34
56500 - 10 10 10 0 0 0 0 0 0 0 0 0
56501 - 0 0 0 0 0 0 0 0 0 0 0 0
56502 - 0 0 0 0 0 0 0 0 0 0 0 0
56503 - 0 0 0 0 0 0 0 0 0 0 0 0
56504 - 0 0 0 0 0 0 0 0 0 0 0 0
56505 - 0 0 0 0 0 0 0 0 0 0 0 0
56506 - 0 0 0 0 0 0 0 0 0 0 0 0
56507 - 0 0 0 0 0 0 0 0 0 0 0 0
56508 - 0 0 1 0 0 1 0 0 1 0 0 0
56509 - 0 0 0 0 0 0 0 0 0 0 0 0
56510 - 0 0 0 0 0 0 0 0 0 0 0 0
56511 - 0 0 0 0 0 0 0 0 0 0 0 0
56512 - 0 0 0 0 0 0 0 0 0 0 0 0
56513 - 0 0 0 0 0 0 0 0 0 0 0 0
56514 - 14 14 14 42 42 42 86 86 86 10 10 10
56515 - 2 2 6 2 2 6 2 2 6 2 2 6
56516 - 2 2 6 2 2 6 2 2 6 2 2 6
56517 - 2 2 6 2 2 6 2 2 6 30 30 30
56518 - 94 94 94 94 94 94 58 58 58 26 26 26
56519 - 2 2 6 6 6 6 78 78 78 54 54 54
56520 - 22 22 22 6 6 6 0 0 0 0 0 0
56521 - 0 0 0 0 0 0 0 0 0 0 0 0
56522 - 0 0 0 0 0 0 0 0 0 0 0 0
56523 - 0 0 0 0 0 0 0 0 0 0 0 0
56524 - 0 0 0 0 0 0 0 0 0 0 0 0
56525 - 0 0 0 0 0 0 0 0 0 0 0 0
56526 - 0 0 0 0 0 0 0 0 0 0 0 0
56527 - 0 0 0 0 0 0 0 0 0 0 0 0
56528 - 0 0 0 0 0 0 0 0 0 0 0 0
56529 - 0 0 0 0 0 0 0 0 0 0 0 0
56530 - 0 0 0 0 0 0 0 0 0 0 0 0
56531 - 0 0 0 0 0 0 0 0 0 0 0 0
56532 - 0 0 0 0 0 0 0 0 0 0 0 0
56533 - 0 0 0 0 0 0 0 0 0 6 6 6
56534 - 22 22 22 62 62 62 62 62 62 2 2 6
56535 - 2 2 6 2 2 6 2 2 6 2 2 6
56536 - 2 2 6 2 2 6 2 2 6 2 2 6
56537 - 2 2 6 2 2 6 2 2 6 26 26 26
56538 - 54 54 54 38 38 38 18 18 18 10 10 10
56539 - 2 2 6 2 2 6 34 34 34 82 82 82
56540 - 38 38 38 14 14 14 0 0 0 0 0 0
56541 - 0 0 0 0 0 0 0 0 0 0 0 0
56542 - 0 0 0 0 0 0 0 0 0 0 0 0
56543 - 0 0 0 0 0 0 0 0 0 0 0 0
56544 - 0 0 0 0 0 0 0 0 0 0 0 0
56545 - 0 0 0 0 0 0 0 0 0 0 0 0
56546 - 0 0 0 0 0 0 0 0 0 0 0 0
56547 - 0 0 0 0 0 0 0 0 0 0 0 0
56548 - 0 0 0 0 0 1 0 0 1 0 0 0
56549 - 0 0 0 0 0 0 0 0 0 0 0 0
56550 - 0 0 0 0 0 0 0 0 0 0 0 0
56551 - 0 0 0 0 0 0 0 0 0 0 0 0
56552 - 0 0 0 0 0 0 0 0 0 0 0 0
56553 - 0 0 0 0 0 0 0 0 0 6 6 6
56554 - 30 30 30 78 78 78 30 30 30 2 2 6
56555 - 2 2 6 2 2 6 2 2 6 2 2 6
56556 - 2 2 6 2 2 6 2 2 6 2 2 6
56557 - 2 2 6 2 2 6 2 2 6 10 10 10
56558 - 10 10 10 2 2 6 2 2 6 2 2 6
56559 - 2 2 6 2 2 6 2 2 6 78 78 78
56560 - 50 50 50 18 18 18 6 6 6 0 0 0
56561 - 0 0 0 0 0 0 0 0 0 0 0 0
56562 - 0 0 0 0 0 0 0 0 0 0 0 0
56563 - 0 0 0 0 0 0 0 0 0 0 0 0
56564 - 0 0 0 0 0 0 0 0 0 0 0 0
56565 - 0 0 0 0 0 0 0 0 0 0 0 0
56566 - 0 0 0 0 0 0 0 0 0 0 0 0
56567 - 0 0 0 0 0 0 0 0 0 0 0 0
56568 - 0 0 1 0 0 0 0 0 0 0 0 0
56569 - 0 0 0 0 0 0 0 0 0 0 0 0
56570 - 0 0 0 0 0 0 0 0 0 0 0 0
56571 - 0 0 0 0 0 0 0 0 0 0 0 0
56572 - 0 0 0 0 0 0 0 0 0 0 0 0
56573 - 0 0 0 0 0 0 0 0 0 10 10 10
56574 - 38 38 38 86 86 86 14 14 14 2 2 6
56575 - 2 2 6 2 2 6 2 2 6 2 2 6
56576 - 2 2 6 2 2 6 2 2 6 2 2 6
56577 - 2 2 6 2 2 6 2 2 6 2 2 6
56578 - 2 2 6 2 2 6 2 2 6 2 2 6
56579 - 2 2 6 2 2 6 2 2 6 54 54 54
56580 - 66 66 66 26 26 26 6 6 6 0 0 0
56581 - 0 0 0 0 0 0 0 0 0 0 0 0
56582 - 0 0 0 0 0 0 0 0 0 0 0 0
56583 - 0 0 0 0 0 0 0 0 0 0 0 0
56584 - 0 0 0 0 0 0 0 0 0 0 0 0
56585 - 0 0 0 0 0 0 0 0 0 0 0 0
56586 - 0 0 0 0 0 0 0 0 0 0 0 0
56587 - 0 0 0 0 0 0 0 0 0 0 0 0
56588 - 0 0 0 0 0 1 0 0 1 0 0 0
56589 - 0 0 0 0 0 0 0 0 0 0 0 0
56590 - 0 0 0 0 0 0 0 0 0 0 0 0
56591 - 0 0 0 0 0 0 0 0 0 0 0 0
56592 - 0 0 0 0 0 0 0 0 0 0 0 0
56593 - 0 0 0 0 0 0 0 0 0 14 14 14
56594 - 42 42 42 82 82 82 2 2 6 2 2 6
56595 - 2 2 6 6 6 6 10 10 10 2 2 6
56596 - 2 2 6 2 2 6 2 2 6 2 2 6
56597 - 2 2 6 2 2 6 2 2 6 6 6 6
56598 - 14 14 14 10 10 10 2 2 6 2 2 6
56599 - 2 2 6 2 2 6 2 2 6 18 18 18
56600 - 82 82 82 34 34 34 10 10 10 0 0 0
56601 - 0 0 0 0 0 0 0 0 0 0 0 0
56602 - 0 0 0 0 0 0 0 0 0 0 0 0
56603 - 0 0 0 0 0 0 0 0 0 0 0 0
56604 - 0 0 0 0 0 0 0 0 0 0 0 0
56605 - 0 0 0 0 0 0 0 0 0 0 0 0
56606 - 0 0 0 0 0 0 0 0 0 0 0 0
56607 - 0 0 0 0 0 0 0 0 0 0 0 0
56608 - 0 0 1 0 0 0 0 0 0 0 0 0
56609 - 0 0 0 0 0 0 0 0 0 0 0 0
56610 - 0 0 0 0 0 0 0 0 0 0 0 0
56611 - 0 0 0 0 0 0 0 0 0 0 0 0
56612 - 0 0 0 0 0 0 0 0 0 0 0 0
56613 - 0 0 0 0 0 0 0 0 0 14 14 14
56614 - 46 46 46 86 86 86 2 2 6 2 2 6
56615 - 6 6 6 6 6 6 22 22 22 34 34 34
56616 - 6 6 6 2 2 6 2 2 6 2 2 6
56617 - 2 2 6 2 2 6 18 18 18 34 34 34
56618 - 10 10 10 50 50 50 22 22 22 2 2 6
56619 - 2 2 6 2 2 6 2 2 6 10 10 10
56620 - 86 86 86 42 42 42 14 14 14 0 0 0
56621 - 0 0 0 0 0 0 0 0 0 0 0 0
56622 - 0 0 0 0 0 0 0 0 0 0 0 0
56623 - 0 0 0 0 0 0 0 0 0 0 0 0
56624 - 0 0 0 0 0 0 0 0 0 0 0 0
56625 - 0 0 0 0 0 0 0 0 0 0 0 0
56626 - 0 0 0 0 0 0 0 0 0 0 0 0
56627 - 0 0 0 0 0 0 0 0 0 0 0 0
56628 - 0 0 1 0 0 1 0 0 1 0 0 0
56629 - 0 0 0 0 0 0 0 0 0 0 0 0
56630 - 0 0 0 0 0 0 0 0 0 0 0 0
56631 - 0 0 0 0 0 0 0 0 0 0 0 0
56632 - 0 0 0 0 0 0 0 0 0 0 0 0
56633 - 0 0 0 0 0 0 0 0 0 14 14 14
56634 - 46 46 46 86 86 86 2 2 6 2 2 6
56635 - 38 38 38 116 116 116 94 94 94 22 22 22
56636 - 22 22 22 2 2 6 2 2 6 2 2 6
56637 - 14 14 14 86 86 86 138 138 138 162 162 162
56638 -154 154 154 38 38 38 26 26 26 6 6 6
56639 - 2 2 6 2 2 6 2 2 6 2 2 6
56640 - 86 86 86 46 46 46 14 14 14 0 0 0
56641 - 0 0 0 0 0 0 0 0 0 0 0 0
56642 - 0 0 0 0 0 0 0 0 0 0 0 0
56643 - 0 0 0 0 0 0 0 0 0 0 0 0
56644 - 0 0 0 0 0 0 0 0 0 0 0 0
56645 - 0 0 0 0 0 0 0 0 0 0 0 0
56646 - 0 0 0 0 0 0 0 0 0 0 0 0
56647 - 0 0 0 0 0 0 0 0 0 0 0 0
56648 - 0 0 0 0 0 0 0 0 0 0 0 0
56649 - 0 0 0 0 0 0 0 0 0 0 0 0
56650 - 0 0 0 0 0 0 0 0 0 0 0 0
56651 - 0 0 0 0 0 0 0 0 0 0 0 0
56652 - 0 0 0 0 0 0 0 0 0 0 0 0
56653 - 0 0 0 0 0 0 0 0 0 14 14 14
56654 - 46 46 46 86 86 86 2 2 6 14 14 14
56655 -134 134 134 198 198 198 195 195 195 116 116 116
56656 - 10 10 10 2 2 6 2 2 6 6 6 6
56657 -101 98 89 187 187 187 210 210 210 218 218 218
56658 -214 214 214 134 134 134 14 14 14 6 6 6
56659 - 2 2 6 2 2 6 2 2 6 2 2 6
56660 - 86 86 86 50 50 50 18 18 18 6 6 6
56661 - 0 0 0 0 0 0 0 0 0 0 0 0
56662 - 0 0 0 0 0 0 0 0 0 0 0 0
56663 - 0 0 0 0 0 0 0 0 0 0 0 0
56664 - 0 0 0 0 0 0 0 0 0 0 0 0
56665 - 0 0 0 0 0 0 0 0 0 0 0 0
56666 - 0 0 0 0 0 0 0 0 0 0 0 0
56667 - 0 0 0 0 0 0 0 0 1 0 0 0
56668 - 0 0 1 0 0 1 0 0 1 0 0 0
56669 - 0 0 0 0 0 0 0 0 0 0 0 0
56670 - 0 0 0 0 0 0 0 0 0 0 0 0
56671 - 0 0 0 0 0 0 0 0 0 0 0 0
56672 - 0 0 0 0 0 0 0 0 0 0 0 0
56673 - 0 0 0 0 0 0 0 0 0 14 14 14
56674 - 46 46 46 86 86 86 2 2 6 54 54 54
56675 -218 218 218 195 195 195 226 226 226 246 246 246
56676 - 58 58 58 2 2 6 2 2 6 30 30 30
56677 -210 210 210 253 253 253 174 174 174 123 123 123
56678 -221 221 221 234 234 234 74 74 74 2 2 6
56679 - 2 2 6 2 2 6 2 2 6 2 2 6
56680 - 70 70 70 58 58 58 22 22 22 6 6 6
56681 - 0 0 0 0 0 0 0 0 0 0 0 0
56682 - 0 0 0 0 0 0 0 0 0 0 0 0
56683 - 0 0 0 0 0 0 0 0 0 0 0 0
56684 - 0 0 0 0 0 0 0 0 0 0 0 0
56685 - 0 0 0 0 0 0 0 0 0 0 0 0
56686 - 0 0 0 0 0 0 0 0 0 0 0 0
56687 - 0 0 0 0 0 0 0 0 0 0 0 0
56688 - 0 0 0 0 0 0 0 0 0 0 0 0
56689 - 0 0 0 0 0 0 0 0 0 0 0 0
56690 - 0 0 0 0 0 0 0 0 0 0 0 0
56691 - 0 0 0 0 0 0 0 0 0 0 0 0
56692 - 0 0 0 0 0 0 0 0 0 0 0 0
56693 - 0 0 0 0 0 0 0 0 0 14 14 14
56694 - 46 46 46 82 82 82 2 2 6 106 106 106
56695 -170 170 170 26 26 26 86 86 86 226 226 226
56696 -123 123 123 10 10 10 14 14 14 46 46 46
56697 -231 231 231 190 190 190 6 6 6 70 70 70
56698 - 90 90 90 238 238 238 158 158 158 2 2 6
56699 - 2 2 6 2 2 6 2 2 6 2 2 6
56700 - 70 70 70 58 58 58 22 22 22 6 6 6
56701 - 0 0 0 0 0 0 0 0 0 0 0 0
56702 - 0 0 0 0 0 0 0 0 0 0 0 0
56703 - 0 0 0 0 0 0 0 0 0 0 0 0
56704 - 0 0 0 0 0 0 0 0 0 0 0 0
56705 - 0 0 0 0 0 0 0 0 0 0 0 0
56706 - 0 0 0 0 0 0 0 0 0 0 0 0
56707 - 0 0 0 0 0 0 0 0 1 0 0 0
56708 - 0 0 1 0 0 1 0 0 1 0 0 0
56709 - 0 0 0 0 0 0 0 0 0 0 0 0
56710 - 0 0 0 0 0 0 0 0 0 0 0 0
56711 - 0 0 0 0 0 0 0 0 0 0 0 0
56712 - 0 0 0 0 0 0 0 0 0 0 0 0
56713 - 0 0 0 0 0 0 0 0 0 14 14 14
56714 - 42 42 42 86 86 86 6 6 6 116 116 116
56715 -106 106 106 6 6 6 70 70 70 149 149 149
56716 -128 128 128 18 18 18 38 38 38 54 54 54
56717 -221 221 221 106 106 106 2 2 6 14 14 14
56718 - 46 46 46 190 190 190 198 198 198 2 2 6
56719 - 2 2 6 2 2 6 2 2 6 2 2 6
56720 - 74 74 74 62 62 62 22 22 22 6 6 6
56721 - 0 0 0 0 0 0 0 0 0 0 0 0
56722 - 0 0 0 0 0 0 0 0 0 0 0 0
56723 - 0 0 0 0 0 0 0 0 0 0 0 0
56724 - 0 0 0 0 0 0 0 0 0 0 0 0
56725 - 0 0 0 0 0 0 0 0 0 0 0 0
56726 - 0 0 0 0 0 0 0 0 0 0 0 0
56727 - 0 0 0 0 0 0 0 0 1 0 0 0
56728 - 0 0 1 0 0 0 0 0 1 0 0 0
56729 - 0 0 0 0 0 0 0 0 0 0 0 0
56730 - 0 0 0 0 0 0 0 0 0 0 0 0
56731 - 0 0 0 0 0 0 0 0 0 0 0 0
56732 - 0 0 0 0 0 0 0 0 0 0 0 0
56733 - 0 0 0 0 0 0 0 0 0 14 14 14
56734 - 42 42 42 94 94 94 14 14 14 101 101 101
56735 -128 128 128 2 2 6 18 18 18 116 116 116
56736 -118 98 46 121 92 8 121 92 8 98 78 10
56737 -162 162 162 106 106 106 2 2 6 2 2 6
56738 - 2 2 6 195 195 195 195 195 195 6 6 6
56739 - 2 2 6 2 2 6 2 2 6 2 2 6
56740 - 74 74 74 62 62 62 22 22 22 6 6 6
56741 - 0 0 0 0 0 0 0 0 0 0 0 0
56742 - 0 0 0 0 0 0 0 0 0 0 0 0
56743 - 0 0 0 0 0 0 0 0 0 0 0 0
56744 - 0 0 0 0 0 0 0 0 0 0 0 0
56745 - 0 0 0 0 0 0 0 0 0 0 0 0
56746 - 0 0 0 0 0 0 0 0 0 0 0 0
56747 - 0 0 0 0 0 0 0 0 1 0 0 1
56748 - 0 0 1 0 0 0 0 0 1 0 0 0
56749 - 0 0 0 0 0 0 0 0 0 0 0 0
56750 - 0 0 0 0 0 0 0 0 0 0 0 0
56751 - 0 0 0 0 0 0 0 0 0 0 0 0
56752 - 0 0 0 0 0 0 0 0 0 0 0 0
56753 - 0 0 0 0 0 0 0 0 0 10 10 10
56754 - 38 38 38 90 90 90 14 14 14 58 58 58
56755 -210 210 210 26 26 26 54 38 6 154 114 10
56756 -226 170 11 236 186 11 225 175 15 184 144 12
56757 -215 174 15 175 146 61 37 26 9 2 2 6
56758 - 70 70 70 246 246 246 138 138 138 2 2 6
56759 - 2 2 6 2 2 6 2 2 6 2 2 6
56760 - 70 70 70 66 66 66 26 26 26 6 6 6
56761 - 0 0 0 0 0 0 0 0 0 0 0 0
56762 - 0 0 0 0 0 0 0 0 0 0 0 0
56763 - 0 0 0 0 0 0 0 0 0 0 0 0
56764 - 0 0 0 0 0 0 0 0 0 0 0 0
56765 - 0 0 0 0 0 0 0 0 0 0 0 0
56766 - 0 0 0 0 0 0 0 0 0 0 0 0
56767 - 0 0 0 0 0 0 0 0 0 0 0 0
56768 - 0 0 0 0 0 0 0 0 0 0 0 0
56769 - 0 0 0 0 0 0 0 0 0 0 0 0
56770 - 0 0 0 0 0 0 0 0 0 0 0 0
56771 - 0 0 0 0 0 0 0 0 0 0 0 0
56772 - 0 0 0 0 0 0 0 0 0 0 0 0
56773 - 0 0 0 0 0 0 0 0 0 10 10 10
56774 - 38 38 38 86 86 86 14 14 14 10 10 10
56775 -195 195 195 188 164 115 192 133 9 225 175 15
56776 -239 182 13 234 190 10 232 195 16 232 200 30
56777 -245 207 45 241 208 19 232 195 16 184 144 12
56778 -218 194 134 211 206 186 42 42 42 2 2 6
56779 - 2 2 6 2 2 6 2 2 6 2 2 6
56780 - 50 50 50 74 74 74 30 30 30 6 6 6
56781 - 0 0 0 0 0 0 0 0 0 0 0 0
56782 - 0 0 0 0 0 0 0 0 0 0 0 0
56783 - 0 0 0 0 0 0 0 0 0 0 0 0
56784 - 0 0 0 0 0 0 0 0 0 0 0 0
56785 - 0 0 0 0 0 0 0 0 0 0 0 0
56786 - 0 0 0 0 0 0 0 0 0 0 0 0
56787 - 0 0 0 0 0 0 0 0 0 0 0 0
56788 - 0 0 0 0 0 0 0 0 0 0 0 0
56789 - 0 0 0 0 0 0 0 0 0 0 0 0
56790 - 0 0 0 0 0 0 0 0 0 0 0 0
56791 - 0 0 0 0 0 0 0 0 0 0 0 0
56792 - 0 0 0 0 0 0 0 0 0 0 0 0
56793 - 0 0 0 0 0 0 0 0 0 10 10 10
56794 - 34 34 34 86 86 86 14 14 14 2 2 6
56795 -121 87 25 192 133 9 219 162 10 239 182 13
56796 -236 186 11 232 195 16 241 208 19 244 214 54
56797 -246 218 60 246 218 38 246 215 20 241 208 19
56798 -241 208 19 226 184 13 121 87 25 2 2 6
56799 - 2 2 6 2 2 6 2 2 6 2 2 6
56800 - 50 50 50 82 82 82 34 34 34 10 10 10
56801 - 0 0 0 0 0 0 0 0 0 0 0 0
56802 - 0 0 0 0 0 0 0 0 0 0 0 0
56803 - 0 0 0 0 0 0 0 0 0 0 0 0
56804 - 0 0 0 0 0 0 0 0 0 0 0 0
56805 - 0 0 0 0 0 0 0 0 0 0 0 0
56806 - 0 0 0 0 0 0 0 0 0 0 0 0
56807 - 0 0 0 0 0 0 0 0 0 0 0 0
56808 - 0 0 0 0 0 0 0 0 0 0 0 0
56809 - 0 0 0 0 0 0 0 0 0 0 0 0
56810 - 0 0 0 0 0 0 0 0 0 0 0 0
56811 - 0 0 0 0 0 0 0 0 0 0 0 0
56812 - 0 0 0 0 0 0 0 0 0 0 0 0
56813 - 0 0 0 0 0 0 0 0 0 10 10 10
56814 - 34 34 34 82 82 82 30 30 30 61 42 6
56815 -180 123 7 206 145 10 230 174 11 239 182 13
56816 -234 190 10 238 202 15 241 208 19 246 218 74
56817 -246 218 38 246 215 20 246 215 20 246 215 20
56818 -226 184 13 215 174 15 184 144 12 6 6 6
56819 - 2 2 6 2 2 6 2 2 6 2 2 6
56820 - 26 26 26 94 94 94 42 42 42 14 14 14
56821 - 0 0 0 0 0 0 0 0 0 0 0 0
56822 - 0 0 0 0 0 0 0 0 0 0 0 0
56823 - 0 0 0 0 0 0 0 0 0 0 0 0
56824 - 0 0 0 0 0 0 0 0 0 0 0 0
56825 - 0 0 0 0 0 0 0 0 0 0 0 0
56826 - 0 0 0 0 0 0 0 0 0 0 0 0
56827 - 0 0 0 0 0 0 0 0 0 0 0 0
56828 - 0 0 0 0 0 0 0 0 0 0 0 0
56829 - 0 0 0 0 0 0 0 0 0 0 0 0
56830 - 0 0 0 0 0 0 0 0 0 0 0 0
56831 - 0 0 0 0 0 0 0 0 0 0 0 0
56832 - 0 0 0 0 0 0 0 0 0 0 0 0
56833 - 0 0 0 0 0 0 0 0 0 10 10 10
56834 - 30 30 30 78 78 78 50 50 50 104 69 6
56835 -192 133 9 216 158 10 236 178 12 236 186 11
56836 -232 195 16 241 208 19 244 214 54 245 215 43
56837 -246 215 20 246 215 20 241 208 19 198 155 10
56838 -200 144 11 216 158 10 156 118 10 2 2 6
56839 - 2 2 6 2 2 6 2 2 6 2 2 6
56840 - 6 6 6 90 90 90 54 54 54 18 18 18
56841 - 6 6 6 0 0 0 0 0 0 0 0 0
56842 - 0 0 0 0 0 0 0 0 0 0 0 0
56843 - 0 0 0 0 0 0 0 0 0 0 0 0
56844 - 0 0 0 0 0 0 0 0 0 0 0 0
56845 - 0 0 0 0 0 0 0 0 0 0 0 0
56846 - 0 0 0 0 0 0 0 0 0 0 0 0
56847 - 0 0 0 0 0 0 0 0 0 0 0 0
56848 - 0 0 0 0 0 0 0 0 0 0 0 0
56849 - 0 0 0 0 0 0 0 0 0 0 0 0
56850 - 0 0 0 0 0 0 0 0 0 0 0 0
56851 - 0 0 0 0 0 0 0 0 0 0 0 0
56852 - 0 0 0 0 0 0 0 0 0 0 0 0
56853 - 0 0 0 0 0 0 0 0 0 10 10 10
56854 - 30 30 30 78 78 78 46 46 46 22 22 22
56855 -137 92 6 210 162 10 239 182 13 238 190 10
56856 -238 202 15 241 208 19 246 215 20 246 215 20
56857 -241 208 19 203 166 17 185 133 11 210 150 10
56858 -216 158 10 210 150 10 102 78 10 2 2 6
56859 - 6 6 6 54 54 54 14 14 14 2 2 6
56860 - 2 2 6 62 62 62 74 74 74 30 30 30
56861 - 10 10 10 0 0 0 0 0 0 0 0 0
56862 - 0 0 0 0 0 0 0 0 0 0 0 0
56863 - 0 0 0 0 0 0 0 0 0 0 0 0
56864 - 0 0 0 0 0 0 0 0 0 0 0 0
56865 - 0 0 0 0 0 0 0 0 0 0 0 0
56866 - 0 0 0 0 0 0 0 0 0 0 0 0
56867 - 0 0 0 0 0 0 0 0 0 0 0 0
56868 - 0 0 0 0 0 0 0 0 0 0 0 0
56869 - 0 0 0 0 0 0 0 0 0 0 0 0
56870 - 0 0 0 0 0 0 0 0 0 0 0 0
56871 - 0 0 0 0 0 0 0 0 0 0 0 0
56872 - 0 0 0 0 0 0 0 0 0 0 0 0
56873 - 0 0 0 0 0 0 0 0 0 10 10 10
56874 - 34 34 34 78 78 78 50 50 50 6 6 6
56875 - 94 70 30 139 102 15 190 146 13 226 184 13
56876 -232 200 30 232 195 16 215 174 15 190 146 13
56877 -168 122 10 192 133 9 210 150 10 213 154 11
56878 -202 150 34 182 157 106 101 98 89 2 2 6
56879 - 2 2 6 78 78 78 116 116 116 58 58 58
56880 - 2 2 6 22 22 22 90 90 90 46 46 46
56881 - 18 18 18 6 6 6 0 0 0 0 0 0
56882 - 0 0 0 0 0 0 0 0 0 0 0 0
56883 - 0 0 0 0 0 0 0 0 0 0 0 0
56884 - 0 0 0 0 0 0 0 0 0 0 0 0
56885 - 0 0 0 0 0 0 0 0 0 0 0 0
56886 - 0 0 0 0 0 0 0 0 0 0 0 0
56887 - 0 0 0 0 0 0 0 0 0 0 0 0
56888 - 0 0 0 0 0 0 0 0 0 0 0 0
56889 - 0 0 0 0 0 0 0 0 0 0 0 0
56890 - 0 0 0 0 0 0 0 0 0 0 0 0
56891 - 0 0 0 0 0 0 0 0 0 0 0 0
56892 - 0 0 0 0 0 0 0 0 0 0 0 0
56893 - 0 0 0 0 0 0 0 0 0 10 10 10
56894 - 38 38 38 86 86 86 50 50 50 6 6 6
56895 -128 128 128 174 154 114 156 107 11 168 122 10
56896 -198 155 10 184 144 12 197 138 11 200 144 11
56897 -206 145 10 206 145 10 197 138 11 188 164 115
56898 -195 195 195 198 198 198 174 174 174 14 14 14
56899 - 2 2 6 22 22 22 116 116 116 116 116 116
56900 - 22 22 22 2 2 6 74 74 74 70 70 70
56901 - 30 30 30 10 10 10 0 0 0 0 0 0
56902 - 0 0 0 0 0 0 0 0 0 0 0 0
56903 - 0 0 0 0 0 0 0 0 0 0 0 0
56904 - 0 0 0 0 0 0 0 0 0 0 0 0
56905 - 0 0 0 0 0 0 0 0 0 0 0 0
56906 - 0 0 0 0 0 0 0 0 0 0 0 0
56907 - 0 0 0 0 0 0 0 0 0 0 0 0
56908 - 0 0 0 0 0 0 0 0 0 0 0 0
56909 - 0 0 0 0 0 0 0 0 0 0 0 0
56910 - 0 0 0 0 0 0 0 0 0 0 0 0
56911 - 0 0 0 0 0 0 0 0 0 0 0 0
56912 - 0 0 0 0 0 0 0 0 0 0 0 0
56913 - 0 0 0 0 0 0 6 6 6 18 18 18
56914 - 50 50 50 101 101 101 26 26 26 10 10 10
56915 -138 138 138 190 190 190 174 154 114 156 107 11
56916 -197 138 11 200 144 11 197 138 11 192 133 9
56917 -180 123 7 190 142 34 190 178 144 187 187 187
56918 -202 202 202 221 221 221 214 214 214 66 66 66
56919 - 2 2 6 2 2 6 50 50 50 62 62 62
56920 - 6 6 6 2 2 6 10 10 10 90 90 90
56921 - 50 50 50 18 18 18 6 6 6 0 0 0
56922 - 0 0 0 0 0 0 0 0 0 0 0 0
56923 - 0 0 0 0 0 0 0 0 0 0 0 0
56924 - 0 0 0 0 0 0 0 0 0 0 0 0
56925 - 0 0 0 0 0 0 0 0 0 0 0 0
56926 - 0 0 0 0 0 0 0 0 0 0 0 0
56927 - 0 0 0 0 0 0 0 0 0 0 0 0
56928 - 0 0 0 0 0 0 0 0 0 0 0 0
56929 - 0 0 0 0 0 0 0 0 0 0 0 0
56930 - 0 0 0 0 0 0 0 0 0 0 0 0
56931 - 0 0 0 0 0 0 0 0 0 0 0 0
56932 - 0 0 0 0 0 0 0 0 0 0 0 0
56933 - 0 0 0 0 0 0 10 10 10 34 34 34
56934 - 74 74 74 74 74 74 2 2 6 6 6 6
56935 -144 144 144 198 198 198 190 190 190 178 166 146
56936 -154 121 60 156 107 11 156 107 11 168 124 44
56937 -174 154 114 187 187 187 190 190 190 210 210 210
56938 -246 246 246 253 253 253 253 253 253 182 182 182
56939 - 6 6 6 2 2 6 2 2 6 2 2 6
56940 - 2 2 6 2 2 6 2 2 6 62 62 62
56941 - 74 74 74 34 34 34 14 14 14 0 0 0
56942 - 0 0 0 0 0 0 0 0 0 0 0 0
56943 - 0 0 0 0 0 0 0 0 0 0 0 0
56944 - 0 0 0 0 0 0 0 0 0 0 0 0
56945 - 0 0 0 0 0 0 0 0 0 0 0 0
56946 - 0 0 0 0 0 0 0 0 0 0 0 0
56947 - 0 0 0 0 0 0 0 0 0 0 0 0
56948 - 0 0 0 0 0 0 0 0 0 0 0 0
56949 - 0 0 0 0 0 0 0 0 0 0 0 0
56950 - 0 0 0 0 0 0 0 0 0 0 0 0
56951 - 0 0 0 0 0 0 0 0 0 0 0 0
56952 - 0 0 0 0 0 0 0 0 0 0 0 0
56953 - 0 0 0 10 10 10 22 22 22 54 54 54
56954 - 94 94 94 18 18 18 2 2 6 46 46 46
56955 -234 234 234 221 221 221 190 190 190 190 190 190
56956 -190 190 190 187 187 187 187 187 187 190 190 190
56957 -190 190 190 195 195 195 214 214 214 242 242 242
56958 -253 253 253 253 253 253 253 253 253 253 253 253
56959 - 82 82 82 2 2 6 2 2 6 2 2 6
56960 - 2 2 6 2 2 6 2 2 6 14 14 14
56961 - 86 86 86 54 54 54 22 22 22 6 6 6
56962 - 0 0 0 0 0 0 0 0 0 0 0 0
56963 - 0 0 0 0 0 0 0 0 0 0 0 0
56964 - 0 0 0 0 0 0 0 0 0 0 0 0
56965 - 0 0 0 0 0 0 0 0 0 0 0 0
56966 - 0 0 0 0 0 0 0 0 0 0 0 0
56967 - 0 0 0 0 0 0 0 0 0 0 0 0
56968 - 0 0 0 0 0 0 0 0 0 0 0 0
56969 - 0 0 0 0 0 0 0 0 0 0 0 0
56970 - 0 0 0 0 0 0 0 0 0 0 0 0
56971 - 0 0 0 0 0 0 0 0 0 0 0 0
56972 - 0 0 0 0 0 0 0 0 0 0 0 0
56973 - 6 6 6 18 18 18 46 46 46 90 90 90
56974 - 46 46 46 18 18 18 6 6 6 182 182 182
56975 -253 253 253 246 246 246 206 206 206 190 190 190
56976 -190 190 190 190 190 190 190 190 190 190 190 190
56977 -206 206 206 231 231 231 250 250 250 253 253 253
56978 -253 253 253 253 253 253 253 253 253 253 253 253
56979 -202 202 202 14 14 14 2 2 6 2 2 6
56980 - 2 2 6 2 2 6 2 2 6 2 2 6
56981 - 42 42 42 86 86 86 42 42 42 18 18 18
56982 - 6 6 6 0 0 0 0 0 0 0 0 0
56983 - 0 0 0 0 0 0 0 0 0 0 0 0
56984 - 0 0 0 0 0 0 0 0 0 0 0 0
56985 - 0 0 0 0 0 0 0 0 0 0 0 0
56986 - 0 0 0 0 0 0 0 0 0 0 0 0
56987 - 0 0 0 0 0 0 0 0 0 0 0 0
56988 - 0 0 0 0 0 0 0 0 0 0 0 0
56989 - 0 0 0 0 0 0 0 0 0 0 0 0
56990 - 0 0 0 0 0 0 0 0 0 0 0 0
56991 - 0 0 0 0 0 0 0 0 0 0 0 0
56992 - 0 0 0 0 0 0 0 0 0 6 6 6
56993 - 14 14 14 38 38 38 74 74 74 66 66 66
56994 - 2 2 6 6 6 6 90 90 90 250 250 250
56995 -253 253 253 253 253 253 238 238 238 198 198 198
56996 -190 190 190 190 190 190 195 195 195 221 221 221
56997 -246 246 246 253 253 253 253 253 253 253 253 253
56998 -253 253 253 253 253 253 253 253 253 253 253 253
56999 -253 253 253 82 82 82 2 2 6 2 2 6
57000 - 2 2 6 2 2 6 2 2 6 2 2 6
57001 - 2 2 6 78 78 78 70 70 70 34 34 34
57002 - 14 14 14 6 6 6 0 0 0 0 0 0
57003 - 0 0 0 0 0 0 0 0 0 0 0 0
57004 - 0 0 0 0 0 0 0 0 0 0 0 0
57005 - 0 0 0 0 0 0 0 0 0 0 0 0
57006 - 0 0 0 0 0 0 0 0 0 0 0 0
57007 - 0 0 0 0 0 0 0 0 0 0 0 0
57008 - 0 0 0 0 0 0 0 0 0 0 0 0
57009 - 0 0 0 0 0 0 0 0 0 0 0 0
57010 - 0 0 0 0 0 0 0 0 0 0 0 0
57011 - 0 0 0 0 0 0 0 0 0 0 0 0
57012 - 0 0 0 0 0 0 0 0 0 14 14 14
57013 - 34 34 34 66 66 66 78 78 78 6 6 6
57014 - 2 2 6 18 18 18 218 218 218 253 253 253
57015 -253 253 253 253 253 253 253 253 253 246 246 246
57016 -226 226 226 231 231 231 246 246 246 253 253 253
57017 -253 253 253 253 253 253 253 253 253 253 253 253
57018 -253 253 253 253 253 253 253 253 253 253 253 253
57019 -253 253 253 178 178 178 2 2 6 2 2 6
57020 - 2 2 6 2 2 6 2 2 6 2 2 6
57021 - 2 2 6 18 18 18 90 90 90 62 62 62
57022 - 30 30 30 10 10 10 0 0 0 0 0 0
57023 - 0 0 0 0 0 0 0 0 0 0 0 0
57024 - 0 0 0 0 0 0 0 0 0 0 0 0
57025 - 0 0 0 0 0 0 0 0 0 0 0 0
57026 - 0 0 0 0 0 0 0 0 0 0 0 0
57027 - 0 0 0 0 0 0 0 0 0 0 0 0
57028 - 0 0 0 0 0 0 0 0 0 0 0 0
57029 - 0 0 0 0 0 0 0 0 0 0 0 0
57030 - 0 0 0 0 0 0 0 0 0 0 0 0
57031 - 0 0 0 0 0 0 0 0 0 0 0 0
57032 - 0 0 0 0 0 0 10 10 10 26 26 26
57033 - 58 58 58 90 90 90 18 18 18 2 2 6
57034 - 2 2 6 110 110 110 253 253 253 253 253 253
57035 -253 253 253 253 253 253 253 253 253 253 253 253
57036 -250 250 250 253 253 253 253 253 253 253 253 253
57037 -253 253 253 253 253 253 253 253 253 253 253 253
57038 -253 253 253 253 253 253 253 253 253 253 253 253
57039 -253 253 253 231 231 231 18 18 18 2 2 6
57040 - 2 2 6 2 2 6 2 2 6 2 2 6
57041 - 2 2 6 2 2 6 18 18 18 94 94 94
57042 - 54 54 54 26 26 26 10 10 10 0 0 0
57043 - 0 0 0 0 0 0 0 0 0 0 0 0
57044 - 0 0 0 0 0 0 0 0 0 0 0 0
57045 - 0 0 0 0 0 0 0 0 0 0 0 0
57046 - 0 0 0 0 0 0 0 0 0 0 0 0
57047 - 0 0 0 0 0 0 0 0 0 0 0 0
57048 - 0 0 0 0 0 0 0 0 0 0 0 0
57049 - 0 0 0 0 0 0 0 0 0 0 0 0
57050 - 0 0 0 0 0 0 0 0 0 0 0 0
57051 - 0 0 0 0 0 0 0 0 0 0 0 0
57052 - 0 0 0 6 6 6 22 22 22 50 50 50
57053 - 90 90 90 26 26 26 2 2 6 2 2 6
57054 - 14 14 14 195 195 195 250 250 250 253 253 253
57055 -253 253 253 253 253 253 253 253 253 253 253 253
57056 -253 253 253 253 253 253 253 253 253 253 253 253
57057 -253 253 253 253 253 253 253 253 253 253 253 253
57058 -253 253 253 253 253 253 253 253 253 253 253 253
57059 -250 250 250 242 242 242 54 54 54 2 2 6
57060 - 2 2 6 2 2 6 2 2 6 2 2 6
57061 - 2 2 6 2 2 6 2 2 6 38 38 38
57062 - 86 86 86 50 50 50 22 22 22 6 6 6
57063 - 0 0 0 0 0 0 0 0 0 0 0 0
57064 - 0 0 0 0 0 0 0 0 0 0 0 0
57065 - 0 0 0 0 0 0 0 0 0 0 0 0
57066 - 0 0 0 0 0 0 0 0 0 0 0 0
57067 - 0 0 0 0 0 0 0 0 0 0 0 0
57068 - 0 0 0 0 0 0 0 0 0 0 0 0
57069 - 0 0 0 0 0 0 0 0 0 0 0 0
57070 - 0 0 0 0 0 0 0 0 0 0 0 0
57071 - 0 0 0 0 0 0 0 0 0 0 0 0
57072 - 6 6 6 14 14 14 38 38 38 82 82 82
57073 - 34 34 34 2 2 6 2 2 6 2 2 6
57074 - 42 42 42 195 195 195 246 246 246 253 253 253
57075 -253 253 253 253 253 253 253 253 253 250 250 250
57076 -242 242 242 242 242 242 250 250 250 253 253 253
57077 -253 253 253 253 253 253 253 253 253 253 253 253
57078 -253 253 253 250 250 250 246 246 246 238 238 238
57079 -226 226 226 231 231 231 101 101 101 6 6 6
57080 - 2 2 6 2 2 6 2 2 6 2 2 6
57081 - 2 2 6 2 2 6 2 2 6 2 2 6
57082 - 38 38 38 82 82 82 42 42 42 14 14 14
57083 - 6 6 6 0 0 0 0 0 0 0 0 0
57084 - 0 0 0 0 0 0 0 0 0 0 0 0
57085 - 0 0 0 0 0 0 0 0 0 0 0 0
57086 - 0 0 0 0 0 0 0 0 0 0 0 0
57087 - 0 0 0 0 0 0 0 0 0 0 0 0
57088 - 0 0 0 0 0 0 0 0 0 0 0 0
57089 - 0 0 0 0 0 0 0 0 0 0 0 0
57090 - 0 0 0 0 0 0 0 0 0 0 0 0
57091 - 0 0 0 0 0 0 0 0 0 0 0 0
57092 - 10 10 10 26 26 26 62 62 62 66 66 66
57093 - 2 2 6 2 2 6 2 2 6 6 6 6
57094 - 70 70 70 170 170 170 206 206 206 234 234 234
57095 -246 246 246 250 250 250 250 250 250 238 238 238
57096 -226 226 226 231 231 231 238 238 238 250 250 250
57097 -250 250 250 250 250 250 246 246 246 231 231 231
57098 -214 214 214 206 206 206 202 202 202 202 202 202
57099 -198 198 198 202 202 202 182 182 182 18 18 18
57100 - 2 2 6 2 2 6 2 2 6 2 2 6
57101 - 2 2 6 2 2 6 2 2 6 2 2 6
57102 - 2 2 6 62 62 62 66 66 66 30 30 30
57103 - 10 10 10 0 0 0 0 0 0 0 0 0
57104 - 0 0 0 0 0 0 0 0 0 0 0 0
57105 - 0 0 0 0 0 0 0 0 0 0 0 0
57106 - 0 0 0 0 0 0 0 0 0 0 0 0
57107 - 0 0 0 0 0 0 0 0 0 0 0 0
57108 - 0 0 0 0 0 0 0 0 0 0 0 0
57109 - 0 0 0 0 0 0 0 0 0 0 0 0
57110 - 0 0 0 0 0 0 0 0 0 0 0 0
57111 - 0 0 0 0 0 0 0 0 0 0 0 0
57112 - 14 14 14 42 42 42 82 82 82 18 18 18
57113 - 2 2 6 2 2 6 2 2 6 10 10 10
57114 - 94 94 94 182 182 182 218 218 218 242 242 242
57115 -250 250 250 253 253 253 253 253 253 250 250 250
57116 -234 234 234 253 253 253 253 253 253 253 253 253
57117 -253 253 253 253 253 253 253 253 253 246 246 246
57118 -238 238 238 226 226 226 210 210 210 202 202 202
57119 -195 195 195 195 195 195 210 210 210 158 158 158
57120 - 6 6 6 14 14 14 50 50 50 14 14 14
57121 - 2 2 6 2 2 6 2 2 6 2 2 6
57122 - 2 2 6 6 6 6 86 86 86 46 46 46
57123 - 18 18 18 6 6 6 0 0 0 0 0 0
57124 - 0 0 0 0 0 0 0 0 0 0 0 0
57125 - 0 0 0 0 0 0 0 0 0 0 0 0
57126 - 0 0 0 0 0 0 0 0 0 0 0 0
57127 - 0 0 0 0 0 0 0 0 0 0 0 0
57128 - 0 0 0 0 0 0 0 0 0 0 0 0
57129 - 0 0 0 0 0 0 0 0 0 0 0 0
57130 - 0 0 0 0 0 0 0 0 0 0 0 0
57131 - 0 0 0 0 0 0 0 0 0 6 6 6
57132 - 22 22 22 54 54 54 70 70 70 2 2 6
57133 - 2 2 6 10 10 10 2 2 6 22 22 22
57134 -166 166 166 231 231 231 250 250 250 253 253 253
57135 -253 253 253 253 253 253 253 253 253 250 250 250
57136 -242 242 242 253 253 253 253 253 253 253 253 253
57137 -253 253 253 253 253 253 253 253 253 253 253 253
57138 -253 253 253 253 253 253 253 253 253 246 246 246
57139 -231 231 231 206 206 206 198 198 198 226 226 226
57140 - 94 94 94 2 2 6 6 6 6 38 38 38
57141 - 30 30 30 2 2 6 2 2 6 2 2 6
57142 - 2 2 6 2 2 6 62 62 62 66 66 66
57143 - 26 26 26 10 10 10 0 0 0 0 0 0
57144 - 0 0 0 0 0 0 0 0 0 0 0 0
57145 - 0 0 0 0 0 0 0 0 0 0 0 0
57146 - 0 0 0 0 0 0 0 0 0 0 0 0
57147 - 0 0 0 0 0 0 0 0 0 0 0 0
57148 - 0 0 0 0 0 0 0 0 0 0 0 0
57149 - 0 0 0 0 0 0 0 0 0 0 0 0
57150 - 0 0 0 0 0 0 0 0 0 0 0 0
57151 - 0 0 0 0 0 0 0 0 0 10 10 10
57152 - 30 30 30 74 74 74 50 50 50 2 2 6
57153 - 26 26 26 26 26 26 2 2 6 106 106 106
57154 -238 238 238 253 253 253 253 253 253 253 253 253
57155 -253 253 253 253 253 253 253 253 253 253 253 253
57156 -253 253 253 253 253 253 253 253 253 253 253 253
57157 -253 253 253 253 253 253 253 253 253 253 253 253
57158 -253 253 253 253 253 253 253 253 253 253 253 253
57159 -253 253 253 246 246 246 218 218 218 202 202 202
57160 -210 210 210 14 14 14 2 2 6 2 2 6
57161 - 30 30 30 22 22 22 2 2 6 2 2 6
57162 - 2 2 6 2 2 6 18 18 18 86 86 86
57163 - 42 42 42 14 14 14 0 0 0 0 0 0
57164 - 0 0 0 0 0 0 0 0 0 0 0 0
57165 - 0 0 0 0 0 0 0 0 0 0 0 0
57166 - 0 0 0 0 0 0 0 0 0 0 0 0
57167 - 0 0 0 0 0 0 0 0 0 0 0 0
57168 - 0 0 0 0 0 0 0 0 0 0 0 0
57169 - 0 0 0 0 0 0 0 0 0 0 0 0
57170 - 0 0 0 0 0 0 0 0 0 0 0 0
57171 - 0 0 0 0 0 0 0 0 0 14 14 14
57172 - 42 42 42 90 90 90 22 22 22 2 2 6
57173 - 42 42 42 2 2 6 18 18 18 218 218 218
57174 -253 253 253 253 253 253 253 253 253 253 253 253
57175 -253 253 253 253 253 253 253 253 253 253 253 253
57176 -253 253 253 253 253 253 253 253 253 253 253 253
57177 -253 253 253 253 253 253 253 253 253 253 253 253
57178 -253 253 253 253 253 253 253 253 253 253 253 253
57179 -253 253 253 253 253 253 250 250 250 221 221 221
57180 -218 218 218 101 101 101 2 2 6 14 14 14
57181 - 18 18 18 38 38 38 10 10 10 2 2 6
57182 - 2 2 6 2 2 6 2 2 6 78 78 78
57183 - 58 58 58 22 22 22 6 6 6 0 0 0
57184 - 0 0 0 0 0 0 0 0 0 0 0 0
57185 - 0 0 0 0 0 0 0 0 0 0 0 0
57186 - 0 0 0 0 0 0 0 0 0 0 0 0
57187 - 0 0 0 0 0 0 0 0 0 0 0 0
57188 - 0 0 0 0 0 0 0 0 0 0 0 0
57189 - 0 0 0 0 0 0 0 0 0 0 0 0
57190 - 0 0 0 0 0 0 0 0 0 0 0 0
57191 - 0 0 0 0 0 0 6 6 6 18 18 18
57192 - 54 54 54 82 82 82 2 2 6 26 26 26
57193 - 22 22 22 2 2 6 123 123 123 253 253 253
57194 -253 253 253 253 253 253 253 253 253 253 253 253
57195 -253 253 253 253 253 253 253 253 253 253 253 253
57196 -253 253 253 253 253 253 253 253 253 253 253 253
57197 -253 253 253 253 253 253 253 253 253 253 253 253
57198 -253 253 253 253 253 253 253 253 253 253 253 253
57199 -253 253 253 253 253 253 253 253 253 250 250 250
57200 -238 238 238 198 198 198 6 6 6 38 38 38
57201 - 58 58 58 26 26 26 38 38 38 2 2 6
57202 - 2 2 6 2 2 6 2 2 6 46 46 46
57203 - 78 78 78 30 30 30 10 10 10 0 0 0
57204 - 0 0 0 0 0 0 0 0 0 0 0 0
57205 - 0 0 0 0 0 0 0 0 0 0 0 0
57206 - 0 0 0 0 0 0 0 0 0 0 0 0
57207 - 0 0 0 0 0 0 0 0 0 0 0 0
57208 - 0 0 0 0 0 0 0 0 0 0 0 0
57209 - 0 0 0 0 0 0 0 0 0 0 0 0
57210 - 0 0 0 0 0 0 0 0 0 0 0 0
57211 - 0 0 0 0 0 0 10 10 10 30 30 30
57212 - 74 74 74 58 58 58 2 2 6 42 42 42
57213 - 2 2 6 22 22 22 231 231 231 253 253 253
57214 -253 253 253 253 253 253 253 253 253 253 253 253
57215 -253 253 253 253 253 253 253 253 253 250 250 250
57216 -253 253 253 253 253 253 253 253 253 253 253 253
57217 -253 253 253 253 253 253 253 253 253 253 253 253
57218 -253 253 253 253 253 253 253 253 253 253 253 253
57219 -253 253 253 253 253 253 253 253 253 253 253 253
57220 -253 253 253 246 246 246 46 46 46 38 38 38
57221 - 42 42 42 14 14 14 38 38 38 14 14 14
57222 - 2 2 6 2 2 6 2 2 6 6 6 6
57223 - 86 86 86 46 46 46 14 14 14 0 0 0
57224 - 0 0 0 0 0 0 0 0 0 0 0 0
57225 - 0 0 0 0 0 0 0 0 0 0 0 0
57226 - 0 0 0 0 0 0 0 0 0 0 0 0
57227 - 0 0 0 0 0 0 0 0 0 0 0 0
57228 - 0 0 0 0 0 0 0 0 0 0 0 0
57229 - 0 0 0 0 0 0 0 0 0 0 0 0
57230 - 0 0 0 0 0 0 0 0 0 0 0 0
57231 - 0 0 0 6 6 6 14 14 14 42 42 42
57232 - 90 90 90 18 18 18 18 18 18 26 26 26
57233 - 2 2 6 116 116 116 253 253 253 253 253 253
57234 -253 253 253 253 253 253 253 253 253 253 253 253
57235 -253 253 253 253 253 253 250 250 250 238 238 238
57236 -253 253 253 253 253 253 253 253 253 253 253 253
57237 -253 253 253 253 253 253 253 253 253 253 253 253
57238 -253 253 253 253 253 253 253 253 253 253 253 253
57239 -253 253 253 253 253 253 253 253 253 253 253 253
57240 -253 253 253 253 253 253 94 94 94 6 6 6
57241 - 2 2 6 2 2 6 10 10 10 34 34 34
57242 - 2 2 6 2 2 6 2 2 6 2 2 6
57243 - 74 74 74 58 58 58 22 22 22 6 6 6
57244 - 0 0 0 0 0 0 0 0 0 0 0 0
57245 - 0 0 0 0 0 0 0 0 0 0 0 0
57246 - 0 0 0 0 0 0 0 0 0 0 0 0
57247 - 0 0 0 0 0 0 0 0 0 0 0 0
57248 - 0 0 0 0 0 0 0 0 0 0 0 0
57249 - 0 0 0 0 0 0 0 0 0 0 0 0
57250 - 0 0 0 0 0 0 0 0 0 0 0 0
57251 - 0 0 0 10 10 10 26 26 26 66 66 66
57252 - 82 82 82 2 2 6 38 38 38 6 6 6
57253 - 14 14 14 210 210 210 253 253 253 253 253 253
57254 -253 253 253 253 253 253 253 253 253 253 253 253
57255 -253 253 253 253 253 253 246 246 246 242 242 242
57256 -253 253 253 253 253 253 253 253 253 253 253 253
57257 -253 253 253 253 253 253 253 253 253 253 253 253
57258 -253 253 253 253 253 253 253 253 253 253 253 253
57259 -253 253 253 253 253 253 253 253 253 253 253 253
57260 -253 253 253 253 253 253 144 144 144 2 2 6
57261 - 2 2 6 2 2 6 2 2 6 46 46 46
57262 - 2 2 6 2 2 6 2 2 6 2 2 6
57263 - 42 42 42 74 74 74 30 30 30 10 10 10
57264 - 0 0 0 0 0 0 0 0 0 0 0 0
57265 - 0 0 0 0 0 0 0 0 0 0 0 0
57266 - 0 0 0 0 0 0 0 0 0 0 0 0
57267 - 0 0 0 0 0 0 0 0 0 0 0 0
57268 - 0 0 0 0 0 0 0 0 0 0 0 0
57269 - 0 0 0 0 0 0 0 0 0 0 0 0
57270 - 0 0 0 0 0 0 0 0 0 0 0 0
57271 - 6 6 6 14 14 14 42 42 42 90 90 90
57272 - 26 26 26 6 6 6 42 42 42 2 2 6
57273 - 74 74 74 250 250 250 253 253 253 253 253 253
57274 -253 253 253 253 253 253 253 253 253 253 253 253
57275 -253 253 253 253 253 253 242 242 242 242 242 242
57276 -253 253 253 253 253 253 253 253 253 253 253 253
57277 -253 253 253 253 253 253 253 253 253 253 253 253
57278 -253 253 253 253 253 253 253 253 253 253 253 253
57279 -253 253 253 253 253 253 253 253 253 253 253 253
57280 -253 253 253 253 253 253 182 182 182 2 2 6
57281 - 2 2 6 2 2 6 2 2 6 46 46 46
57282 - 2 2 6 2 2 6 2 2 6 2 2 6
57283 - 10 10 10 86 86 86 38 38 38 10 10 10
57284 - 0 0 0 0 0 0 0 0 0 0 0 0
57285 - 0 0 0 0 0 0 0 0 0 0 0 0
57286 - 0 0 0 0 0 0 0 0 0 0 0 0
57287 - 0 0 0 0 0 0 0 0 0 0 0 0
57288 - 0 0 0 0 0 0 0 0 0 0 0 0
57289 - 0 0 0 0 0 0 0 0 0 0 0 0
57290 - 0 0 0 0 0 0 0 0 0 0 0 0
57291 - 10 10 10 26 26 26 66 66 66 82 82 82
57292 - 2 2 6 22 22 22 18 18 18 2 2 6
57293 -149 149 149 253 253 253 253 253 253 253 253 253
57294 -253 253 253 253 253 253 253 253 253 253 253 253
57295 -253 253 253 253 253 253 234 234 234 242 242 242
57296 -253 253 253 253 253 253 253 253 253 253 253 253
57297 -253 253 253 253 253 253 253 253 253 253 253 253
57298 -253 253 253 253 253 253 253 253 253 253 253 253
57299 -253 253 253 253 253 253 253 253 253 253 253 253
57300 -253 253 253 253 253 253 206 206 206 2 2 6
57301 - 2 2 6 2 2 6 2 2 6 38 38 38
57302 - 2 2 6 2 2 6 2 2 6 2 2 6
57303 - 6 6 6 86 86 86 46 46 46 14 14 14
57304 - 0 0 0 0 0 0 0 0 0 0 0 0
57305 - 0 0 0 0 0 0 0 0 0 0 0 0
57306 - 0 0 0 0 0 0 0 0 0 0 0 0
57307 - 0 0 0 0 0 0 0 0 0 0 0 0
57308 - 0 0 0 0 0 0 0 0 0 0 0 0
57309 - 0 0 0 0 0 0 0 0 0 0 0 0
57310 - 0 0 0 0 0 0 0 0 0 6 6 6
57311 - 18 18 18 46 46 46 86 86 86 18 18 18
57312 - 2 2 6 34 34 34 10 10 10 6 6 6
57313 -210 210 210 253 253 253 253 253 253 253 253 253
57314 -253 253 253 253 253 253 253 253 253 253 253 253
57315 -253 253 253 253 253 253 234 234 234 242 242 242
57316 -253 253 253 253 253 253 253 253 253 253 253 253
57317 -253 253 253 253 253 253 253 253 253 253 253 253
57318 -253 253 253 253 253 253 253 253 253 253 253 253
57319 -253 253 253 253 253 253 253 253 253 253 253 253
57320 -253 253 253 253 253 253 221 221 221 6 6 6
57321 - 2 2 6 2 2 6 6 6 6 30 30 30
57322 - 2 2 6 2 2 6 2 2 6 2 2 6
57323 - 2 2 6 82 82 82 54 54 54 18 18 18
57324 - 6 6 6 0 0 0 0 0 0 0 0 0
57325 - 0 0 0 0 0 0 0 0 0 0 0 0
57326 - 0 0 0 0 0 0 0 0 0 0 0 0
57327 - 0 0 0 0 0 0 0 0 0 0 0 0
57328 - 0 0 0 0 0 0 0 0 0 0 0 0
57329 - 0 0 0 0 0 0 0 0 0 0 0 0
57330 - 0 0 0 0 0 0 0 0 0 10 10 10
57331 - 26 26 26 66 66 66 62 62 62 2 2 6
57332 - 2 2 6 38 38 38 10 10 10 26 26 26
57333 -238 238 238 253 253 253 253 253 253 253 253 253
57334 -253 253 253 253 253 253 253 253 253 253 253 253
57335 -253 253 253 253 253 253 231 231 231 238 238 238
57336 -253 253 253 253 253 253 253 253 253 253 253 253
57337 -253 253 253 253 253 253 253 253 253 253 253 253
57338 -253 253 253 253 253 253 253 253 253 253 253 253
57339 -253 253 253 253 253 253 253 253 253 253 253 253
57340 -253 253 253 253 253 253 231 231 231 6 6 6
57341 - 2 2 6 2 2 6 10 10 10 30 30 30
57342 - 2 2 6 2 2 6 2 2 6 2 2 6
57343 - 2 2 6 66 66 66 58 58 58 22 22 22
57344 - 6 6 6 0 0 0 0 0 0 0 0 0
57345 - 0 0 0 0 0 0 0 0 0 0 0 0
57346 - 0 0 0 0 0 0 0 0 0 0 0 0
57347 - 0 0 0 0 0 0 0 0 0 0 0 0
57348 - 0 0 0 0 0 0 0 0 0 0 0 0
57349 - 0 0 0 0 0 0 0 0 0 0 0 0
57350 - 0 0 0 0 0 0 0 0 0 10 10 10
57351 - 38 38 38 78 78 78 6 6 6 2 2 6
57352 - 2 2 6 46 46 46 14 14 14 42 42 42
57353 -246 246 246 253 253 253 253 253 253 253 253 253
57354 -253 253 253 253 253 253 253 253 253 253 253 253
57355 -253 253 253 253 253 253 231 231 231 242 242 242
57356 -253 253 253 253 253 253 253 253 253 253 253 253
57357 -253 253 253 253 253 253 253 253 253 253 253 253
57358 -253 253 253 253 253 253 253 253 253 253 253 253
57359 -253 253 253 253 253 253 253 253 253 253 253 253
57360 -253 253 253 253 253 253 234 234 234 10 10 10
57361 - 2 2 6 2 2 6 22 22 22 14 14 14
57362 - 2 2 6 2 2 6 2 2 6 2 2 6
57363 - 2 2 6 66 66 66 62 62 62 22 22 22
57364 - 6 6 6 0 0 0 0 0 0 0 0 0
57365 - 0 0 0 0 0 0 0 0 0 0 0 0
57366 - 0 0 0 0 0 0 0 0 0 0 0 0
57367 - 0 0 0 0 0 0 0 0 0 0 0 0
57368 - 0 0 0 0 0 0 0 0 0 0 0 0
57369 - 0 0 0 0 0 0 0 0 0 0 0 0
57370 - 0 0 0 0 0 0 6 6 6 18 18 18
57371 - 50 50 50 74 74 74 2 2 6 2 2 6
57372 - 14 14 14 70 70 70 34 34 34 62 62 62
57373 -250 250 250 253 253 253 253 253 253 253 253 253
57374 -253 253 253 253 253 253 253 253 253 253 253 253
57375 -253 253 253 253 253 253 231 231 231 246 246 246
57376 -253 253 253 253 253 253 253 253 253 253 253 253
57377 -253 253 253 253 253 253 253 253 253 253 253 253
57378 -253 253 253 253 253 253 253 253 253 253 253 253
57379 -253 253 253 253 253 253 253 253 253 253 253 253
57380 -253 253 253 253 253 253 234 234 234 14 14 14
57381 - 2 2 6 2 2 6 30 30 30 2 2 6
57382 - 2 2 6 2 2 6 2 2 6 2 2 6
57383 - 2 2 6 66 66 66 62 62 62 22 22 22
57384 - 6 6 6 0 0 0 0 0 0 0 0 0
57385 - 0 0 0 0 0 0 0 0 0 0 0 0
57386 - 0 0 0 0 0 0 0 0 0 0 0 0
57387 - 0 0 0 0 0 0 0 0 0 0 0 0
57388 - 0 0 0 0 0 0 0 0 0 0 0 0
57389 - 0 0 0 0 0 0 0 0 0 0 0 0
57390 - 0 0 0 0 0 0 6 6 6 18 18 18
57391 - 54 54 54 62 62 62 2 2 6 2 2 6
57392 - 2 2 6 30 30 30 46 46 46 70 70 70
57393 -250 250 250 253 253 253 253 253 253 253 253 253
57394 -253 253 253 253 253 253 253 253 253 253 253 253
57395 -253 253 253 253 253 253 231 231 231 246 246 246
57396 -253 253 253 253 253 253 253 253 253 253 253 253
57397 -253 253 253 253 253 253 253 253 253 253 253 253
57398 -253 253 253 253 253 253 253 253 253 253 253 253
57399 -253 253 253 253 253 253 253 253 253 253 253 253
57400 -253 253 253 253 253 253 226 226 226 10 10 10
57401 - 2 2 6 6 6 6 30 30 30 2 2 6
57402 - 2 2 6 2 2 6 2 2 6 2 2 6
57403 - 2 2 6 66 66 66 58 58 58 22 22 22
57404 - 6 6 6 0 0 0 0 0 0 0 0 0
57405 - 0 0 0 0 0 0 0 0 0 0 0 0
57406 - 0 0 0 0 0 0 0 0 0 0 0 0
57407 - 0 0 0 0 0 0 0 0 0 0 0 0
57408 - 0 0 0 0 0 0 0 0 0 0 0 0
57409 - 0 0 0 0 0 0 0 0 0 0 0 0
57410 - 0 0 0 0 0 0 6 6 6 22 22 22
57411 - 58 58 58 62 62 62 2 2 6 2 2 6
57412 - 2 2 6 2 2 6 30 30 30 78 78 78
57413 -250 250 250 253 253 253 253 253 253 253 253 253
57414 -253 253 253 253 253 253 253 253 253 253 253 253
57415 -253 253 253 253 253 253 231 231 231 246 246 246
57416 -253 253 253 253 253 253 253 253 253 253 253 253
57417 -253 253 253 253 253 253 253 253 253 253 253 253
57418 -253 253 253 253 253 253 253 253 253 253 253 253
57419 -253 253 253 253 253 253 253 253 253 253 253 253
57420 -253 253 253 253 253 253 206 206 206 2 2 6
57421 - 22 22 22 34 34 34 18 14 6 22 22 22
57422 - 26 26 26 18 18 18 6 6 6 2 2 6
57423 - 2 2 6 82 82 82 54 54 54 18 18 18
57424 - 6 6 6 0 0 0 0 0 0 0 0 0
57425 - 0 0 0 0 0 0 0 0 0 0 0 0
57426 - 0 0 0 0 0 0 0 0 0 0 0 0
57427 - 0 0 0 0 0 0 0 0 0 0 0 0
57428 - 0 0 0 0 0 0 0 0 0 0 0 0
57429 - 0 0 0 0 0 0 0 0 0 0 0 0
57430 - 0 0 0 0 0 0 6 6 6 26 26 26
57431 - 62 62 62 106 106 106 74 54 14 185 133 11
57432 -210 162 10 121 92 8 6 6 6 62 62 62
57433 -238 238 238 253 253 253 253 253 253 253 253 253
57434 -253 253 253 253 253 253 253 253 253 253 253 253
57435 -253 253 253 253 253 253 231 231 231 246 246 246
57436 -253 253 253 253 253 253 253 253 253 253 253 253
57437 -253 253 253 253 253 253 253 253 253 253 253 253
57438 -253 253 253 253 253 253 253 253 253 253 253 253
57439 -253 253 253 253 253 253 253 253 253 253 253 253
57440 -253 253 253 253 253 253 158 158 158 18 18 18
57441 - 14 14 14 2 2 6 2 2 6 2 2 6
57442 - 6 6 6 18 18 18 66 66 66 38 38 38
57443 - 6 6 6 94 94 94 50 50 50 18 18 18
57444 - 6 6 6 0 0 0 0 0 0 0 0 0
57445 - 0 0 0 0 0 0 0 0 0 0 0 0
57446 - 0 0 0 0 0 0 0 0 0 0 0 0
57447 - 0 0 0 0 0 0 0 0 0 0 0 0
57448 - 0 0 0 0 0 0 0 0 0 0 0 0
57449 - 0 0 0 0 0 0 0 0 0 6 6 6
57450 - 10 10 10 10 10 10 18 18 18 38 38 38
57451 - 78 78 78 142 134 106 216 158 10 242 186 14
57452 -246 190 14 246 190 14 156 118 10 10 10 10
57453 - 90 90 90 238 238 238 253 253 253 253 253 253
57454 -253 253 253 253 253 253 253 253 253 253 253 253
57455 -253 253 253 253 253 253 231 231 231 250 250 250
57456 -253 253 253 253 253 253 253 253 253 253 253 253
57457 -253 253 253 253 253 253 253 253 253 253 253 253
57458 -253 253 253 253 253 253 253 253 253 253 253 253
57459 -253 253 253 253 253 253 253 253 253 246 230 190
57460 -238 204 91 238 204 91 181 142 44 37 26 9
57461 - 2 2 6 2 2 6 2 2 6 2 2 6
57462 - 2 2 6 2 2 6 38 38 38 46 46 46
57463 - 26 26 26 106 106 106 54 54 54 18 18 18
57464 - 6 6 6 0 0 0 0 0 0 0 0 0
57465 - 0 0 0 0 0 0 0 0 0 0 0 0
57466 - 0 0 0 0 0 0 0 0 0 0 0 0
57467 - 0 0 0 0 0 0 0 0 0 0 0 0
57468 - 0 0 0 0 0 0 0 0 0 0 0 0
57469 - 0 0 0 6 6 6 14 14 14 22 22 22
57470 - 30 30 30 38 38 38 50 50 50 70 70 70
57471 -106 106 106 190 142 34 226 170 11 242 186 14
57472 -246 190 14 246 190 14 246 190 14 154 114 10
57473 - 6 6 6 74 74 74 226 226 226 253 253 253
57474 -253 253 253 253 253 253 253 253 253 253 253 253
57475 -253 253 253 253 253 253 231 231 231 250 250 250
57476 -253 253 253 253 253 253 253 253 253 253 253 253
57477 -253 253 253 253 253 253 253 253 253 253 253 253
57478 -253 253 253 253 253 253 253 253 253 253 253 253
57479 -253 253 253 253 253 253 253 253 253 228 184 62
57480 -241 196 14 241 208 19 232 195 16 38 30 10
57481 - 2 2 6 2 2 6 2 2 6 2 2 6
57482 - 2 2 6 6 6 6 30 30 30 26 26 26
57483 -203 166 17 154 142 90 66 66 66 26 26 26
57484 - 6 6 6 0 0 0 0 0 0 0 0 0
57485 - 0 0 0 0 0 0 0 0 0 0 0 0
57486 - 0 0 0 0 0 0 0 0 0 0 0 0
57487 - 0 0 0 0 0 0 0 0 0 0 0 0
57488 - 0 0 0 0 0 0 0 0 0 0 0 0
57489 - 6 6 6 18 18 18 38 38 38 58 58 58
57490 - 78 78 78 86 86 86 101 101 101 123 123 123
57491 -175 146 61 210 150 10 234 174 13 246 186 14
57492 -246 190 14 246 190 14 246 190 14 238 190 10
57493 -102 78 10 2 2 6 46 46 46 198 198 198
57494 -253 253 253 253 253 253 253 253 253 253 253 253
57495 -253 253 253 253 253 253 234 234 234 242 242 242
57496 -253 253 253 253 253 253 253 253 253 253 253 253
57497 -253 253 253 253 253 253 253 253 253 253 253 253
57498 -253 253 253 253 253 253 253 253 253 253 253 253
57499 -253 253 253 253 253 253 253 253 253 224 178 62
57500 -242 186 14 241 196 14 210 166 10 22 18 6
57501 - 2 2 6 2 2 6 2 2 6 2 2 6
57502 - 2 2 6 2 2 6 6 6 6 121 92 8
57503 -238 202 15 232 195 16 82 82 82 34 34 34
57504 - 10 10 10 0 0 0 0 0 0 0 0 0
57505 - 0 0 0 0 0 0 0 0 0 0 0 0
57506 - 0 0 0 0 0 0 0 0 0 0 0 0
57507 - 0 0 0 0 0 0 0 0 0 0 0 0
57508 - 0 0 0 0 0 0 0 0 0 0 0 0
57509 - 14 14 14 38 38 38 70 70 70 154 122 46
57510 -190 142 34 200 144 11 197 138 11 197 138 11
57511 -213 154 11 226 170 11 242 186 14 246 190 14
57512 -246 190 14 246 190 14 246 190 14 246 190 14
57513 -225 175 15 46 32 6 2 2 6 22 22 22
57514 -158 158 158 250 250 250 253 253 253 253 253 253
57515 -253 253 253 253 253 253 253 253 253 253 253 253
57516 -253 253 253 253 253 253 253 253 253 253 253 253
57517 -253 253 253 253 253 253 253 253 253 253 253 253
57518 -253 253 253 253 253 253 253 253 253 253 253 253
57519 -253 253 253 250 250 250 242 242 242 224 178 62
57520 -239 182 13 236 186 11 213 154 11 46 32 6
57521 - 2 2 6 2 2 6 2 2 6 2 2 6
57522 - 2 2 6 2 2 6 61 42 6 225 175 15
57523 -238 190 10 236 186 11 112 100 78 42 42 42
57524 - 14 14 14 0 0 0 0 0 0 0 0 0
57525 - 0 0 0 0 0 0 0 0 0 0 0 0
57526 - 0 0 0 0 0 0 0 0 0 0 0 0
57527 - 0 0 0 0 0 0 0 0 0 0 0 0
57528 - 0 0 0 0 0 0 0 0 0 6 6 6
57529 - 22 22 22 54 54 54 154 122 46 213 154 11
57530 -226 170 11 230 174 11 226 170 11 226 170 11
57531 -236 178 12 242 186 14 246 190 14 246 190 14
57532 -246 190 14 246 190 14 246 190 14 246 190 14
57533 -241 196 14 184 144 12 10 10 10 2 2 6
57534 - 6 6 6 116 116 116 242 242 242 253 253 253
57535 -253 253 253 253 253 253 253 253 253 253 253 253
57536 -253 253 253 253 253 253 253 253 253 253 253 253
57537 -253 253 253 253 253 253 253 253 253 253 253 253
57538 -253 253 253 253 253 253 253 253 253 253 253 253
57539 -253 253 253 231 231 231 198 198 198 214 170 54
57540 -236 178 12 236 178 12 210 150 10 137 92 6
57541 - 18 14 6 2 2 6 2 2 6 2 2 6
57542 - 6 6 6 70 47 6 200 144 11 236 178 12
57543 -239 182 13 239 182 13 124 112 88 58 58 58
57544 - 22 22 22 6 6 6 0 0 0 0 0 0
57545 - 0 0 0 0 0 0 0 0 0 0 0 0
57546 - 0 0 0 0 0 0 0 0 0 0 0 0
57547 - 0 0 0 0 0 0 0 0 0 0 0 0
57548 - 0 0 0 0 0 0 0 0 0 10 10 10
57549 - 30 30 30 70 70 70 180 133 36 226 170 11
57550 -239 182 13 242 186 14 242 186 14 246 186 14
57551 -246 190 14 246 190 14 246 190 14 246 190 14
57552 -246 190 14 246 190 14 246 190 14 246 190 14
57553 -246 190 14 232 195 16 98 70 6 2 2 6
57554 - 2 2 6 2 2 6 66 66 66 221 221 221
57555 -253 253 253 253 253 253 253 253 253 253 253 253
57556 -253 253 253 253 253 253 253 253 253 253 253 253
57557 -253 253 253 253 253 253 253 253 253 253 253 253
57558 -253 253 253 253 253 253 253 253 253 253 253 253
57559 -253 253 253 206 206 206 198 198 198 214 166 58
57560 -230 174 11 230 174 11 216 158 10 192 133 9
57561 -163 110 8 116 81 8 102 78 10 116 81 8
57562 -167 114 7 197 138 11 226 170 11 239 182 13
57563 -242 186 14 242 186 14 162 146 94 78 78 78
57564 - 34 34 34 14 14 14 6 6 6 0 0 0
57565 - 0 0 0 0 0 0 0 0 0 0 0 0
57566 - 0 0 0 0 0 0 0 0 0 0 0 0
57567 - 0 0 0 0 0 0 0 0 0 0 0 0
57568 - 0 0 0 0 0 0 0 0 0 6 6 6
57569 - 30 30 30 78 78 78 190 142 34 226 170 11
57570 -239 182 13 246 190 14 246 190 14 246 190 14
57571 -246 190 14 246 190 14 246 190 14 246 190 14
57572 -246 190 14 246 190 14 246 190 14 246 190 14
57573 -246 190 14 241 196 14 203 166 17 22 18 6
57574 - 2 2 6 2 2 6 2 2 6 38 38 38
57575 -218 218 218 253 253 253 253 253 253 253 253 253
57576 -253 253 253 253 253 253 253 253 253 253 253 253
57577 -253 253 253 253 253 253 253 253 253 253 253 253
57578 -253 253 253 253 253 253 253 253 253 253 253 253
57579 -250 250 250 206 206 206 198 198 198 202 162 69
57580 -226 170 11 236 178 12 224 166 10 210 150 10
57581 -200 144 11 197 138 11 192 133 9 197 138 11
57582 -210 150 10 226 170 11 242 186 14 246 190 14
57583 -246 190 14 246 186 14 225 175 15 124 112 88
57584 - 62 62 62 30 30 30 14 14 14 6 6 6
57585 - 0 0 0 0 0 0 0 0 0 0 0 0
57586 - 0 0 0 0 0 0 0 0 0 0 0 0
57587 - 0 0 0 0 0 0 0 0 0 0 0 0
57588 - 0 0 0 0 0 0 0 0 0 10 10 10
57589 - 30 30 30 78 78 78 174 135 50 224 166 10
57590 -239 182 13 246 190 14 246 190 14 246 190 14
57591 -246 190 14 246 190 14 246 190 14 246 190 14
57592 -246 190 14 246 190 14 246 190 14 246 190 14
57593 -246 190 14 246 190 14 241 196 14 139 102 15
57594 - 2 2 6 2 2 6 2 2 6 2 2 6
57595 - 78 78 78 250 250 250 253 253 253 253 253 253
57596 -253 253 253 253 253 253 253 253 253 253 253 253
57597 -253 253 253 253 253 253 253 253 253 253 253 253
57598 -253 253 253 253 253 253 253 253 253 253 253 253
57599 -250 250 250 214 214 214 198 198 198 190 150 46
57600 -219 162 10 236 178 12 234 174 13 224 166 10
57601 -216 158 10 213 154 11 213 154 11 216 158 10
57602 -226 170 11 239 182 13 246 190 14 246 190 14
57603 -246 190 14 246 190 14 242 186 14 206 162 42
57604 -101 101 101 58 58 58 30 30 30 14 14 14
57605 - 6 6 6 0 0 0 0 0 0 0 0 0
57606 - 0 0 0 0 0 0 0 0 0 0 0 0
57607 - 0 0 0 0 0 0 0 0 0 0 0 0
57608 - 0 0 0 0 0 0 0 0 0 10 10 10
57609 - 30 30 30 74 74 74 174 135 50 216 158 10
57610 -236 178 12 246 190 14 246 190 14 246 190 14
57611 -246 190 14 246 190 14 246 190 14 246 190 14
57612 -246 190 14 246 190 14 246 190 14 246 190 14
57613 -246 190 14 246 190 14 241 196 14 226 184 13
57614 - 61 42 6 2 2 6 2 2 6 2 2 6
57615 - 22 22 22 238 238 238 253 253 253 253 253 253
57616 -253 253 253 253 253 253 253 253 253 253 253 253
57617 -253 253 253 253 253 253 253 253 253 253 253 253
57618 -253 253 253 253 253 253 253 253 253 253 253 253
57619 -253 253 253 226 226 226 187 187 187 180 133 36
57620 -216 158 10 236 178 12 239 182 13 236 178 12
57621 -230 174 11 226 170 11 226 170 11 230 174 11
57622 -236 178 12 242 186 14 246 190 14 246 190 14
57623 -246 190 14 246 190 14 246 186 14 239 182 13
57624 -206 162 42 106 106 106 66 66 66 34 34 34
57625 - 14 14 14 6 6 6 0 0 0 0 0 0
57626 - 0 0 0 0 0 0 0 0 0 0 0 0
57627 - 0 0 0 0 0 0 0 0 0 0 0 0
57628 - 0 0 0 0 0 0 0 0 0 6 6 6
57629 - 26 26 26 70 70 70 163 133 67 213 154 11
57630 -236 178 12 246 190 14 246 190 14 246 190 14
57631 -246 190 14 246 190 14 246 190 14 246 190 14
57632 -246 190 14 246 190 14 246 190 14 246 190 14
57633 -246 190 14 246 190 14 246 190 14 241 196 14
57634 -190 146 13 18 14 6 2 2 6 2 2 6
57635 - 46 46 46 246 246 246 253 253 253 253 253 253
57636 -253 253 253 253 253 253 253 253 253 253 253 253
57637 -253 253 253 253 253 253 253 253 253 253 253 253
57638 -253 253 253 253 253 253 253 253 253 253 253 253
57639 -253 253 253 221 221 221 86 86 86 156 107 11
57640 -216 158 10 236 178 12 242 186 14 246 186 14
57641 -242 186 14 239 182 13 239 182 13 242 186 14
57642 -242 186 14 246 186 14 246 190 14 246 190 14
57643 -246 190 14 246 190 14 246 190 14 246 190 14
57644 -242 186 14 225 175 15 142 122 72 66 66 66
57645 - 30 30 30 10 10 10 0 0 0 0 0 0
57646 - 0 0 0 0 0 0 0 0 0 0 0 0
57647 - 0 0 0 0 0 0 0 0 0 0 0 0
57648 - 0 0 0 0 0 0 0 0 0 6 6 6
57649 - 26 26 26 70 70 70 163 133 67 210 150 10
57650 -236 178 12 246 190 14 246 190 14 246 190 14
57651 -246 190 14 246 190 14 246 190 14 246 190 14
57652 -246 190 14 246 190 14 246 190 14 246 190 14
57653 -246 190 14 246 190 14 246 190 14 246 190 14
57654 -232 195 16 121 92 8 34 34 34 106 106 106
57655 -221 221 221 253 253 253 253 253 253 253 253 253
57656 -253 253 253 253 253 253 253 253 253 253 253 253
57657 -253 253 253 253 253 253 253 253 253 253 253 253
57658 -253 253 253 253 253 253 253 253 253 253 253 253
57659 -242 242 242 82 82 82 18 14 6 163 110 8
57660 -216 158 10 236 178 12 242 186 14 246 190 14
57661 -246 190 14 246 190 14 246 190 14 246 190 14
57662 -246 190 14 246 190 14 246 190 14 246 190 14
57663 -246 190 14 246 190 14 246 190 14 246 190 14
57664 -246 190 14 246 190 14 242 186 14 163 133 67
57665 - 46 46 46 18 18 18 6 6 6 0 0 0
57666 - 0 0 0 0 0 0 0 0 0 0 0 0
57667 - 0 0 0 0 0 0 0 0 0 0 0 0
57668 - 0 0 0 0 0 0 0 0 0 10 10 10
57669 - 30 30 30 78 78 78 163 133 67 210 150 10
57670 -236 178 12 246 186 14 246 190 14 246 190 14
57671 -246 190 14 246 190 14 246 190 14 246 190 14
57672 -246 190 14 246 190 14 246 190 14 246 190 14
57673 -246 190 14 246 190 14 246 190 14 246 190 14
57674 -241 196 14 215 174 15 190 178 144 253 253 253
57675 -253 253 253 253 253 253 253 253 253 253 253 253
57676 -253 253 253 253 253 253 253 253 253 253 253 253
57677 -253 253 253 253 253 253 253 253 253 253 253 253
57678 -253 253 253 253 253 253 253 253 253 218 218 218
57679 - 58 58 58 2 2 6 22 18 6 167 114 7
57680 -216 158 10 236 178 12 246 186 14 246 190 14
57681 -246 190 14 246 190 14 246 190 14 246 190 14
57682 -246 190 14 246 190 14 246 190 14 246 190 14
57683 -246 190 14 246 190 14 246 190 14 246 190 14
57684 -246 190 14 246 186 14 242 186 14 190 150 46
57685 - 54 54 54 22 22 22 6 6 6 0 0 0
57686 - 0 0 0 0 0 0 0 0 0 0 0 0
57687 - 0 0 0 0 0 0 0 0 0 0 0 0
57688 - 0 0 0 0 0 0 0 0 0 14 14 14
57689 - 38 38 38 86 86 86 180 133 36 213 154 11
57690 -236 178 12 246 186 14 246 190 14 246 190 14
57691 -246 190 14 246 190 14 246 190 14 246 190 14
57692 -246 190 14 246 190 14 246 190 14 246 190 14
57693 -246 190 14 246 190 14 246 190 14 246 190 14
57694 -246 190 14 232 195 16 190 146 13 214 214 214
57695 -253 253 253 253 253 253 253 253 253 253 253 253
57696 -253 253 253 253 253 253 253 253 253 253 253 253
57697 -253 253 253 253 253 253 253 253 253 253 253 253
57698 -253 253 253 250 250 250 170 170 170 26 26 26
57699 - 2 2 6 2 2 6 37 26 9 163 110 8
57700 -219 162 10 239 182 13 246 186 14 246 190 14
57701 -246 190 14 246 190 14 246 190 14 246 190 14
57702 -246 190 14 246 190 14 246 190 14 246 190 14
57703 -246 190 14 246 190 14 246 190 14 246 190 14
57704 -246 186 14 236 178 12 224 166 10 142 122 72
57705 - 46 46 46 18 18 18 6 6 6 0 0 0
57706 - 0 0 0 0 0 0 0 0 0 0 0 0
57707 - 0 0 0 0 0 0 0 0 0 0 0 0
57708 - 0 0 0 0 0 0 6 6 6 18 18 18
57709 - 50 50 50 109 106 95 192 133 9 224 166 10
57710 -242 186 14 246 190 14 246 190 14 246 190 14
57711 -246 190 14 246 190 14 246 190 14 246 190 14
57712 -246 190 14 246 190 14 246 190 14 246 190 14
57713 -246 190 14 246 190 14 246 190 14 246 190 14
57714 -242 186 14 226 184 13 210 162 10 142 110 46
57715 -226 226 226 253 253 253 253 253 253 253 253 253
57716 -253 253 253 253 253 253 253 253 253 253 253 253
57717 -253 253 253 253 253 253 253 253 253 253 253 253
57718 -198 198 198 66 66 66 2 2 6 2 2 6
57719 - 2 2 6 2 2 6 50 34 6 156 107 11
57720 -219 162 10 239 182 13 246 186 14 246 190 14
57721 -246 190 14 246 190 14 246 190 14 246 190 14
57722 -246 190 14 246 190 14 246 190 14 246 190 14
57723 -246 190 14 246 190 14 246 190 14 242 186 14
57724 -234 174 13 213 154 11 154 122 46 66 66 66
57725 - 30 30 30 10 10 10 0 0 0 0 0 0
57726 - 0 0 0 0 0 0 0 0 0 0 0 0
57727 - 0 0 0 0 0 0 0 0 0 0 0 0
57728 - 0 0 0 0 0 0 6 6 6 22 22 22
57729 - 58 58 58 154 121 60 206 145 10 234 174 13
57730 -242 186 14 246 186 14 246 190 14 246 190 14
57731 -246 190 14 246 190 14 246 190 14 246 190 14
57732 -246 190 14 246 190 14 246 190 14 246 190 14
57733 -246 190 14 246 190 14 246 190 14 246 190 14
57734 -246 186 14 236 178 12 210 162 10 163 110 8
57735 - 61 42 6 138 138 138 218 218 218 250 250 250
57736 -253 253 253 253 253 253 253 253 253 250 250 250
57737 -242 242 242 210 210 210 144 144 144 66 66 66
57738 - 6 6 6 2 2 6 2 2 6 2 2 6
57739 - 2 2 6 2 2 6 61 42 6 163 110 8
57740 -216 158 10 236 178 12 246 190 14 246 190 14
57741 -246 190 14 246 190 14 246 190 14 246 190 14
57742 -246 190 14 246 190 14 246 190 14 246 190 14
57743 -246 190 14 239 182 13 230 174 11 216 158 10
57744 -190 142 34 124 112 88 70 70 70 38 38 38
57745 - 18 18 18 6 6 6 0 0 0 0 0 0
57746 - 0 0 0 0 0 0 0 0 0 0 0 0
57747 - 0 0 0 0 0 0 0 0 0 0 0 0
57748 - 0 0 0 0 0 0 6 6 6 22 22 22
57749 - 62 62 62 168 124 44 206 145 10 224 166 10
57750 -236 178 12 239 182 13 242 186 14 242 186 14
57751 -246 186 14 246 190 14 246 190 14 246 190 14
57752 -246 190 14 246 190 14 246 190 14 246 190 14
57753 -246 190 14 246 190 14 246 190 14 246 190 14
57754 -246 190 14 236 178 12 216 158 10 175 118 6
57755 - 80 54 7 2 2 6 6 6 6 30 30 30
57756 - 54 54 54 62 62 62 50 50 50 38 38 38
57757 - 14 14 14 2 2 6 2 2 6 2 2 6
57758 - 2 2 6 2 2 6 2 2 6 2 2 6
57759 - 2 2 6 6 6 6 80 54 7 167 114 7
57760 -213 154 11 236 178 12 246 190 14 246 190 14
57761 -246 190 14 246 190 14 246 190 14 246 190 14
57762 -246 190 14 242 186 14 239 182 13 239 182 13
57763 -230 174 11 210 150 10 174 135 50 124 112 88
57764 - 82 82 82 54 54 54 34 34 34 18 18 18
57765 - 6 6 6 0 0 0 0 0 0 0 0 0
57766 - 0 0 0 0 0 0 0 0 0 0 0 0
57767 - 0 0 0 0 0 0 0 0 0 0 0 0
57768 - 0 0 0 0 0 0 6 6 6 18 18 18
57769 - 50 50 50 158 118 36 192 133 9 200 144 11
57770 -216 158 10 219 162 10 224 166 10 226 170 11
57771 -230 174 11 236 178 12 239 182 13 239 182 13
57772 -242 186 14 246 186 14 246 190 14 246 190 14
57773 -246 190 14 246 190 14 246 190 14 246 190 14
57774 -246 186 14 230 174 11 210 150 10 163 110 8
57775 -104 69 6 10 10 10 2 2 6 2 2 6
57776 - 2 2 6 2 2 6 2 2 6 2 2 6
57777 - 2 2 6 2 2 6 2 2 6 2 2 6
57778 - 2 2 6 2 2 6 2 2 6 2 2 6
57779 - 2 2 6 6 6 6 91 60 6 167 114 7
57780 -206 145 10 230 174 11 242 186 14 246 190 14
57781 -246 190 14 246 190 14 246 186 14 242 186 14
57782 -239 182 13 230 174 11 224 166 10 213 154 11
57783 -180 133 36 124 112 88 86 86 86 58 58 58
57784 - 38 38 38 22 22 22 10 10 10 6 6 6
57785 - 0 0 0 0 0 0 0 0 0 0 0 0
57786 - 0 0 0 0 0 0 0 0 0 0 0 0
57787 - 0 0 0 0 0 0 0 0 0 0 0 0
57788 - 0 0 0 0 0 0 0 0 0 14 14 14
57789 - 34 34 34 70 70 70 138 110 50 158 118 36
57790 -167 114 7 180 123 7 192 133 9 197 138 11
57791 -200 144 11 206 145 10 213 154 11 219 162 10
57792 -224 166 10 230 174 11 239 182 13 242 186 14
57793 -246 186 14 246 186 14 246 186 14 246 186 14
57794 -239 182 13 216 158 10 185 133 11 152 99 6
57795 -104 69 6 18 14 6 2 2 6 2 2 6
57796 - 2 2 6 2 2 6 2 2 6 2 2 6
57797 - 2 2 6 2 2 6 2 2 6 2 2 6
57798 - 2 2 6 2 2 6 2 2 6 2 2 6
57799 - 2 2 6 6 6 6 80 54 7 152 99 6
57800 -192 133 9 219 162 10 236 178 12 239 182 13
57801 -246 186 14 242 186 14 239 182 13 236 178 12
57802 -224 166 10 206 145 10 192 133 9 154 121 60
57803 - 94 94 94 62 62 62 42 42 42 22 22 22
57804 - 14 14 14 6 6 6 0 0 0 0 0 0
57805 - 0 0 0 0 0 0 0 0 0 0 0 0
57806 - 0 0 0 0 0 0 0 0 0 0 0 0
57807 - 0 0 0 0 0 0 0 0 0 0 0 0
57808 - 0 0 0 0 0 0 0 0 0 6 6 6
57809 - 18 18 18 34 34 34 58 58 58 78 78 78
57810 -101 98 89 124 112 88 142 110 46 156 107 11
57811 -163 110 8 167 114 7 175 118 6 180 123 7
57812 -185 133 11 197 138 11 210 150 10 219 162 10
57813 -226 170 11 236 178 12 236 178 12 234 174 13
57814 -219 162 10 197 138 11 163 110 8 130 83 6
57815 - 91 60 6 10 10 10 2 2 6 2 2 6
57816 - 18 18 18 38 38 38 38 38 38 38 38 38
57817 - 38 38 38 38 38 38 38 38 38 38 38 38
57818 - 38 38 38 38 38 38 26 26 26 2 2 6
57819 - 2 2 6 6 6 6 70 47 6 137 92 6
57820 -175 118 6 200 144 11 219 162 10 230 174 11
57821 -234 174 13 230 174 11 219 162 10 210 150 10
57822 -192 133 9 163 110 8 124 112 88 82 82 82
57823 - 50 50 50 30 30 30 14 14 14 6 6 6
57824 - 0 0 0 0 0 0 0 0 0 0 0 0
57825 - 0 0 0 0 0 0 0 0 0 0 0 0
57826 - 0 0 0 0 0 0 0 0 0 0 0 0
57827 - 0 0 0 0 0 0 0 0 0 0 0 0
57828 - 0 0 0 0 0 0 0 0 0 0 0 0
57829 - 6 6 6 14 14 14 22 22 22 34 34 34
57830 - 42 42 42 58 58 58 74 74 74 86 86 86
57831 -101 98 89 122 102 70 130 98 46 121 87 25
57832 -137 92 6 152 99 6 163 110 8 180 123 7
57833 -185 133 11 197 138 11 206 145 10 200 144 11
57834 -180 123 7 156 107 11 130 83 6 104 69 6
57835 - 50 34 6 54 54 54 110 110 110 101 98 89
57836 - 86 86 86 82 82 82 78 78 78 78 78 78
57837 - 78 78 78 78 78 78 78 78 78 78 78 78
57838 - 78 78 78 82 82 82 86 86 86 94 94 94
57839 -106 106 106 101 101 101 86 66 34 124 80 6
57840 -156 107 11 180 123 7 192 133 9 200 144 11
57841 -206 145 10 200 144 11 192 133 9 175 118 6
57842 -139 102 15 109 106 95 70 70 70 42 42 42
57843 - 22 22 22 10 10 10 0 0 0 0 0 0
57844 - 0 0 0 0 0 0 0 0 0 0 0 0
57845 - 0 0 0 0 0 0 0 0 0 0 0 0
57846 - 0 0 0 0 0 0 0 0 0 0 0 0
57847 - 0 0 0 0 0 0 0 0 0 0 0 0
57848 - 0 0 0 0 0 0 0 0 0 0 0 0
57849 - 0 0 0 0 0 0 6 6 6 10 10 10
57850 - 14 14 14 22 22 22 30 30 30 38 38 38
57851 - 50 50 50 62 62 62 74 74 74 90 90 90
57852 -101 98 89 112 100 78 121 87 25 124 80 6
57853 -137 92 6 152 99 6 152 99 6 152 99 6
57854 -138 86 6 124 80 6 98 70 6 86 66 30
57855 -101 98 89 82 82 82 58 58 58 46 46 46
57856 - 38 38 38 34 34 34 34 34 34 34 34 34
57857 - 34 34 34 34 34 34 34 34 34 34 34 34
57858 - 34 34 34 34 34 34 38 38 38 42 42 42
57859 - 54 54 54 82 82 82 94 86 76 91 60 6
57860 -134 86 6 156 107 11 167 114 7 175 118 6
57861 -175 118 6 167 114 7 152 99 6 121 87 25
57862 -101 98 89 62 62 62 34 34 34 18 18 18
57863 - 6 6 6 0 0 0 0 0 0 0 0 0
57864 - 0 0 0 0 0 0 0 0 0 0 0 0
57865 - 0 0 0 0 0 0 0 0 0 0 0 0
57866 - 0 0 0 0 0 0 0 0 0 0 0 0
57867 - 0 0 0 0 0 0 0 0 0 0 0 0
57868 - 0 0 0 0 0 0 0 0 0 0 0 0
57869 - 0 0 0 0 0 0 0 0 0 0 0 0
57870 - 0 0 0 6 6 6 6 6 6 10 10 10
57871 - 18 18 18 22 22 22 30 30 30 42 42 42
57872 - 50 50 50 66 66 66 86 86 86 101 98 89
57873 -106 86 58 98 70 6 104 69 6 104 69 6
57874 -104 69 6 91 60 6 82 62 34 90 90 90
57875 - 62 62 62 38 38 38 22 22 22 14 14 14
57876 - 10 10 10 10 10 10 10 10 10 10 10 10
57877 - 10 10 10 10 10 10 6 6 6 10 10 10
57878 - 10 10 10 10 10 10 10 10 10 14 14 14
57879 - 22 22 22 42 42 42 70 70 70 89 81 66
57880 - 80 54 7 104 69 6 124 80 6 137 92 6
57881 -134 86 6 116 81 8 100 82 52 86 86 86
57882 - 58 58 58 30 30 30 14 14 14 6 6 6
57883 - 0 0 0 0 0 0 0 0 0 0 0 0
57884 - 0 0 0 0 0 0 0 0 0 0 0 0
57885 - 0 0 0 0 0 0 0 0 0 0 0 0
57886 - 0 0 0 0 0 0 0 0 0 0 0 0
57887 - 0 0 0 0 0 0 0 0 0 0 0 0
57888 - 0 0 0 0 0 0 0 0 0 0 0 0
57889 - 0 0 0 0 0 0 0 0 0 0 0 0
57890 - 0 0 0 0 0 0 0 0 0 0 0 0
57891 - 0 0 0 6 6 6 10 10 10 14 14 14
57892 - 18 18 18 26 26 26 38 38 38 54 54 54
57893 - 70 70 70 86 86 86 94 86 76 89 81 66
57894 - 89 81 66 86 86 86 74 74 74 50 50 50
57895 - 30 30 30 14 14 14 6 6 6 0 0 0
57896 - 0 0 0 0 0 0 0 0 0 0 0 0
57897 - 0 0 0 0 0 0 0 0 0 0 0 0
57898 - 0 0 0 0 0 0 0 0 0 0 0 0
57899 - 6 6 6 18 18 18 34 34 34 58 58 58
57900 - 82 82 82 89 81 66 89 81 66 89 81 66
57901 - 94 86 66 94 86 76 74 74 74 50 50 50
57902 - 26 26 26 14 14 14 6 6 6 0 0 0
57903 - 0 0 0 0 0 0 0 0 0 0 0 0
57904 - 0 0 0 0 0 0 0 0 0 0 0 0
57905 - 0 0 0 0 0 0 0 0 0 0 0 0
57906 - 0 0 0 0 0 0 0 0 0 0 0 0
57907 - 0 0 0 0 0 0 0 0 0 0 0 0
57908 - 0 0 0 0 0 0 0 0 0 0 0 0
57909 - 0 0 0 0 0 0 0 0 0 0 0 0
57910 - 0 0 0 0 0 0 0 0 0 0 0 0
57911 - 0 0 0 0 0 0 0 0 0 0 0 0
57912 - 6 6 6 6 6 6 14 14 14 18 18 18
57913 - 30 30 30 38 38 38 46 46 46 54 54 54
57914 - 50 50 50 42 42 42 30 30 30 18 18 18
57915 - 10 10 10 0 0 0 0 0 0 0 0 0
57916 - 0 0 0 0 0 0 0 0 0 0 0 0
57917 - 0 0 0 0 0 0 0 0 0 0 0 0
57918 - 0 0 0 0 0 0 0 0 0 0 0 0
57919 - 0 0 0 6 6 6 14 14 14 26 26 26
57920 - 38 38 38 50 50 50 58 58 58 58 58 58
57921 - 54 54 54 42 42 42 30 30 30 18 18 18
57922 - 10 10 10 0 0 0 0 0 0 0 0 0
57923 - 0 0 0 0 0 0 0 0 0 0 0 0
57924 - 0 0 0 0 0 0 0 0 0 0 0 0
57925 - 0 0 0 0 0 0 0 0 0 0 0 0
57926 - 0 0 0 0 0 0 0 0 0 0 0 0
57927 - 0 0 0 0 0 0 0 0 0 0 0 0
57928 - 0 0 0 0 0 0 0 0 0 0 0 0
57929 - 0 0 0 0 0 0 0 0 0 0 0 0
57930 - 0 0 0 0 0 0 0 0 0 0 0 0
57931 - 0 0 0 0 0 0 0 0 0 0 0 0
57932 - 0 0 0 0 0 0 0 0 0 6 6 6
57933 - 6 6 6 10 10 10 14 14 14 18 18 18
57934 - 18 18 18 14 14 14 10 10 10 6 6 6
57935 - 0 0 0 0 0 0 0 0 0 0 0 0
57936 - 0 0 0 0 0 0 0 0 0 0 0 0
57937 - 0 0 0 0 0 0 0 0 0 0 0 0
57938 - 0 0 0 0 0 0 0 0 0 0 0 0
57939 - 0 0 0 0 0 0 0 0 0 6 6 6
57940 - 14 14 14 18 18 18 22 22 22 22 22 22
57941 - 18 18 18 14 14 14 10 10 10 6 6 6
57942 - 0 0 0 0 0 0 0 0 0 0 0 0
57943 - 0 0 0 0 0 0 0 0 0 0 0 0
57944 - 0 0 0 0 0 0 0 0 0 0 0 0
57945 - 0 0 0 0 0 0 0 0 0 0 0 0
57946 - 0 0 0 0 0 0 0 0 0 0 0 0
57947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57960 +4 4 4 4 4 4
57961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57974 +4 4 4 4 4 4
57975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57988 +4 4 4 4 4 4
57989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58002 +4 4 4 4 4 4
58003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58016 +4 4 4 4 4 4
58017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58030 +4 4 4 4 4 4
58031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58035 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
58036 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
58037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58040 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
58041 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58042 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
58043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58044 +4 4 4 4 4 4
58045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58049 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
58050 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
58051 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58054 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
58055 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
58056 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
58057 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58058 +4 4 4 4 4 4
58059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58063 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
58064 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
58065 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58068 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
58069 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
58070 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
58071 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
58072 +4 4 4 4 4 4
58073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58076 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
58077 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
58078 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
58079 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
58080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58081 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
58082 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
58083 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
58084 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
58085 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
58086 +4 4 4 4 4 4
58087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58090 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
58091 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
58092 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
58093 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
58094 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58095 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
58096 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
58097 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
58098 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
58099 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
58100 +4 4 4 4 4 4
58101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58104 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
58105 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
58106 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
58107 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
58108 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58109 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
58110 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
58111 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
58112 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
58113 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
58114 +4 4 4 4 4 4
58115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58117 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
58118 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
58119 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
58120 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
58121 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
58122 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
58123 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
58124 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
58125 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
58126 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
58127 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
58128 +4 4 4 4 4 4
58129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58131 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
58132 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
58133 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
58134 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
58135 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
58136 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
58137 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
58138 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
58139 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
58140 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
58141 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
58142 +4 4 4 4 4 4
58143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58145 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
58146 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
58147 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
58148 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
58149 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
58150 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
58151 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
58152 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
58153 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
58154 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
58155 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58156 +4 4 4 4 4 4
58157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58159 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
58160 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
58161 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
58162 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
58163 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
58164 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
58165 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
58166 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
58167 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
58168 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
58169 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
58170 +4 4 4 4 4 4
58171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58172 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
58173 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
58174 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
58175 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
58176 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
58177 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
58178 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
58179 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
58180 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
58181 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
58182 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
58183 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
58184 +4 4 4 4 4 4
58185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58186 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
58187 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
58188 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
58189 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58190 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
58191 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
58192 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
58193 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
58194 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
58195 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
58196 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
58197 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
58198 +0 0 0 4 4 4
58199 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
58200 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
58201 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
58202 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
58203 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
58204 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
58205 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
58206 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
58207 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
58208 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
58209 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
58210 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
58211 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
58212 +2 0 0 0 0 0
58213 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
58214 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
58215 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
58216 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
58217 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
58218 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
58219 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
58220 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
58221 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
58222 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
58223 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
58224 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
58225 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
58226 +37 38 37 0 0 0
58227 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
58228 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
58229 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
58230 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
58231 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
58232 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
58233 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
58234 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
58235 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
58236 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
58237 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
58238 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
58239 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
58240 +85 115 134 4 0 0
58241 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
58242 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
58243 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
58244 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
58245 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
58246 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
58247 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
58248 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
58249 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
58250 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
58251 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
58252 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
58253 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
58254 +60 73 81 4 0 0
58255 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
58256 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
58257 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
58258 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
58259 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
58260 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
58261 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
58262 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
58263 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
58264 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
58265 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
58266 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
58267 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
58268 +16 19 21 4 0 0
58269 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
58270 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
58271 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
58272 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
58273 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
58274 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
58275 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
58276 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
58277 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
58278 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
58279 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
58280 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
58281 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
58282 +4 0 0 4 3 3
58283 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
58284 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
58285 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
58286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
58287 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
58288 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
58289 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
58290 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
58291 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
58292 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
58293 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
58294 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
58295 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
58296 +3 2 2 4 4 4
58297 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
58298 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
58299 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
58300 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
58301 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
58302 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
58303 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
58304 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
58305 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
58306 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
58307 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
58308 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
58309 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
58310 +4 4 4 4 4 4
58311 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
58312 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
58313 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
58314 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
58315 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
58316 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
58317 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
58318 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
58319 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
58320 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
58321 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
58322 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
58323 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
58324 +4 4 4 4 4 4
58325 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
58326 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
58327 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
58328 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
58329 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
58330 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
58331 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
58332 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
58333 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
58334 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
58335 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
58336 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
58337 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
58338 +5 5 5 5 5 5
58339 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
58340 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
58341 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
58342 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
58343 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
58344 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58345 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
58346 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
58347 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
58348 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
58349 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
58350 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
58351 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58352 +5 5 5 4 4 4
58353 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
58354 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
58355 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
58356 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
58357 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58358 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
58359 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
58360 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
58361 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
58362 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
58363 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
58364 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58366 +4 4 4 4 4 4
58367 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
58368 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
58369 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
58370 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
58371 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
58372 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58373 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58374 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
58375 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
58376 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
58377 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
58378 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
58379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58380 +4 4 4 4 4 4
58381 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
58382 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
58383 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
58384 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
58385 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58386 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
58387 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
58388 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
58389 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
58390 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
58391 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
58392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58394 +4 4 4 4 4 4
58395 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
58396 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
58397 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
58398 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
58399 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58400 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58401 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58402 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
58403 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
58404 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
58405 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
58406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58408 +4 4 4 4 4 4
58409 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
58410 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
58411 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
58412 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
58413 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58414 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
58415 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
58416 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
58417 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
58418 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
58419 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58422 +4 4 4 4 4 4
58423 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
58424 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
58425 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
58426 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
58427 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58428 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
58429 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
58430 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
58431 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
58432 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
58433 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
58434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58436 +4 4 4 4 4 4
58437 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
58438 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
58439 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
58440 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
58441 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58442 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
58443 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
58444 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
58445 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
58446 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
58447 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
58448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58450 +4 4 4 4 4 4
58451 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
58452 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
58453 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
58454 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58455 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
58456 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
58457 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
58458 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
58459 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
58460 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
58461 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58464 +4 4 4 4 4 4
58465 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
58466 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
58467 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
58468 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58469 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58470 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
58471 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
58472 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
58473 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
58474 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
58475 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58478 +4 4 4 4 4 4
58479 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
58480 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
58481 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58482 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58483 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58484 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
58485 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
58486 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
58487 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
58488 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
58489 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58492 +4 4 4 4 4 4
58493 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
58494 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
58495 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58496 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58497 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58498 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
58499 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
58500 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
58501 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58502 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58503 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58506 +4 4 4 4 4 4
58507 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58508 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
58509 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58510 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
58511 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
58512 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
58513 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
58514 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
58515 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58516 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58517 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58520 +4 4 4 4 4 4
58521 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58522 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
58523 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58524 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
58525 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58526 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
58527 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
58528 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
58529 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58530 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58531 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58534 +4 4 4 4 4 4
58535 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
58536 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
58537 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58538 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
58539 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
58540 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
58541 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
58542 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
58543 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58544 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58545 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58548 +4 4 4 4 4 4
58549 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
58550 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
58551 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58552 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
58553 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
58554 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
58555 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
58556 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
58557 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58558 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58559 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58562 +4 4 4 4 4 4
58563 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58564 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
58565 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58566 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
58567 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
58568 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
58569 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
58570 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
58571 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58572 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58573 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58576 +4 4 4 4 4 4
58577 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
58578 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
58579 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58580 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
58581 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
58582 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
58583 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
58584 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
58585 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
58586 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58587 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58590 +4 4 4 4 4 4
58591 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58592 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
58593 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
58594 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
58595 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
58596 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
58597 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
58598 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
58599 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58600 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58601 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58604 +4 4 4 4 4 4
58605 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58606 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
58607 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58608 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
58609 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
58610 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
58611 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
58612 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
58613 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58614 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58615 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58618 +4 4 4 4 4 4
58619 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58620 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
58621 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
58622 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
58623 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
58624 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
58625 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58626 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
58627 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58628 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58629 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58632 +4 4 4 4 4 4
58633 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58634 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
58635 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
58636 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58637 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
58638 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
58639 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58640 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
58641 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58642 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58643 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58646 +4 4 4 4 4 4
58647 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58648 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
58649 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
58650 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
58651 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
58652 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
58653 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
58654 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
58655 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
58656 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58657 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58660 +4 4 4 4 4 4
58661 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58662 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
58663 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
58664 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
58665 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
58666 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
58667 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
58668 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
58669 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
58670 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58671 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58674 +4 4 4 4 4 4
58675 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
58676 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
58677 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
58678 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
58679 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58680 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
58681 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
58682 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
58683 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
58684 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58685 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58688 +4 4 4 4 4 4
58689 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58690 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
58691 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
58692 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
58693 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
58694 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
58695 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
58696 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
58697 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
58698 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58699 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58702 +4 4 4 4 4 4
58703 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
58704 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
58705 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
58706 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
58707 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
58708 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
58709 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
58710 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
58711 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
58712 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
58713 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58716 +4 4 4 4 4 4
58717 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
58718 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58719 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
58720 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
58721 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
58722 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
58723 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
58724 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
58725 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
58726 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
58727 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58730 +4 4 4 4 4 4
58731 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
58732 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58733 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
58734 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
58735 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
58736 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
58737 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58738 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
58739 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
58740 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
58741 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58744 +4 4 4 4 4 4
58745 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
58746 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
58747 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
58748 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
58749 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
58750 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
58751 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
58752 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
58753 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
58754 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
58755 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58758 +4 4 4 4 4 4
58759 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
58760 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
58761 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58762 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
58763 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
58764 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
58765 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
58766 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
58767 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
58768 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
58769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58772 +4 4 4 4 4 4
58773 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58774 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58775 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58776 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58777 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58778 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58779 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58780 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58781 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58782 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58786 +4 4 4 4 4 4
58787 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58788 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58789 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58790 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58791 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58792 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58793 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58794 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58795 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58796 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58800 +4 4 4 4 4 4
58801 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58802 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58803 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58804 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58805 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58806 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58807 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58808 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58809 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58810 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58814 +4 4 4 4 4 4
58815 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58816 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58817 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58818 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58819 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58820 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58821 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58822 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58823 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58828 +4 4 4 4 4 4
58829 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58830 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58831 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58832 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58833 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58834 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58835 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58836 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58837 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58842 +4 4 4 4 4 4
58843 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58844 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58845 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58846 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58847 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58848 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58849 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58850 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58851 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58856 +4 4 4 4 4 4
58857 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58858 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58859 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58860 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58861 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58862 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58863 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58864 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58870 +4 4 4 4 4 4
58871 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58872 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58873 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58874 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58875 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58876 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58877 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58878 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58884 +4 4 4 4 4 4
58885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58886 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
58887 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58888 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
58889 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
58890 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
58891 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
58892 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
58893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58898 +4 4 4 4 4 4
58899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58900 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
58901 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
58902 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
58903 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
58904 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
58905 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
58906 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
58907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58912 +4 4 4 4 4 4
58913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58914 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58915 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
58916 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58917 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
58918 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
58919 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
58920 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58926 +4 4 4 4 4 4
58927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58929 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58930 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
58931 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
58932 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
58933 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
58934 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58940 +4 4 4 4 4 4
58941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58944 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58945 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
58946 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
58947 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
58948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58954 +4 4 4 4 4 4
58955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58958 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58959 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58960 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
58961 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
58962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58968 +4 4 4 4 4 4
58969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58972 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58973 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58974 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58975 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
58976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58982 +4 4 4 4 4 4
58983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58986 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
58987 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
58988 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
58989 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
58990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58996 +4 4 4 4 4 4
58997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
59001 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
59002 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59003 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
59004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59010 +4 4 4 4 4 4
59011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59015 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
59016 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
59017 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
59018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59024 +4 4 4 4 4 4
59025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59029 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
59030 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
59031 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59038 +4 4 4 4 4 4
59039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59043 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
59044 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
59045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59052 +4 4 4 4 4 4
59053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59057 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
59058 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
59059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59066 +4 4 4 4 4 4
59067 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
59068 index fef20db..d28b1ab 100644
59069 --- a/drivers/xen/xenfs/xenstored.c
59070 +++ b/drivers/xen/xenfs/xenstored.c
59071 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
59072 static int xsd_kva_open(struct inode *inode, struct file *file)
59073 {
59074 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
59075 +#ifdef CONFIG_GRKERNSEC_HIDESYM
59076 + NULL);
59077 +#else
59078 xen_store_interface);
59079 +#endif
59080 +
59081 if (!file->private_data)
59082 return -ENOMEM;
59083 return 0;
59084 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
59085 index cc1cfae..41158ad 100644
59086 --- a/fs/9p/vfs_addr.c
59087 +++ b/fs/9p/vfs_addr.c
59088 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
59089
59090 retval = v9fs_file_write_internal(inode,
59091 v9inode->writeback_fid,
59092 - (__force const char __user *)buffer,
59093 + (const char __force_user *)buffer,
59094 len, &offset, 0);
59095 if (retval > 0)
59096 retval = 0;
59097 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
59098 index 7fa4f7a..a7ebf8c 100644
59099 --- a/fs/9p/vfs_inode.c
59100 +++ b/fs/9p/vfs_inode.c
59101 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
59102 void
59103 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
59104 {
59105 - char *s = nd_get_link(nd);
59106 + const char *s = nd_get_link(nd);
59107
59108 p9_debug(P9_DEBUG_VFS, " %s %s\n",
59109 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
59110 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
59111 index 370b24c..ff0be7b 100644
59112 --- a/fs/Kconfig.binfmt
59113 +++ b/fs/Kconfig.binfmt
59114 @@ -103,7 +103,7 @@ config HAVE_AOUT
59115
59116 config BINFMT_AOUT
59117 tristate "Kernel support for a.out and ECOFF binaries"
59118 - depends on HAVE_AOUT
59119 + depends on HAVE_AOUT && BROKEN
59120 ---help---
59121 A.out (Assembler.OUTput) is a set of formats for libraries and
59122 executables used in the earliest versions of UNIX. Linux used
59123 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
59124 index 2946712..f737435 100644
59125 --- a/fs/afs/inode.c
59126 +++ b/fs/afs/inode.c
59127 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
59128 struct afs_vnode *vnode;
59129 struct super_block *sb;
59130 struct inode *inode;
59131 - static atomic_t afs_autocell_ino;
59132 + static atomic_unchecked_t afs_autocell_ino;
59133
59134 _enter("{%x:%u},%*.*s,",
59135 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
59136 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
59137 data.fid.unique = 0;
59138 data.fid.vnode = 0;
59139
59140 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
59141 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
59142 afs_iget5_autocell_test, afs_iget5_set,
59143 &data);
59144 if (!inode) {
59145 diff --git a/fs/aio.c b/fs/aio.c
59146 index 1c9c5f0..c935d6e 100644
59147 --- a/fs/aio.c
59148 +++ b/fs/aio.c
59149 @@ -141,6 +141,7 @@ struct kioctx {
59150
59151 struct {
59152 unsigned tail;
59153 + unsigned completed_events;
59154 spinlock_t completion_lock;
59155 } ____cacheline_aligned_in_smp;
59156
59157 @@ -380,7 +381,7 @@ static int aio_setup_ring(struct kioctx *ctx)
59158 size += sizeof(struct io_event) * nr_events;
59159
59160 nr_pages = PFN_UP(size);
59161 - if (nr_pages < 0)
59162 + if (nr_pages <= 0)
59163 return -EINVAL;
59164
59165 file = aio_private_file(ctx, nr_pages);
59166 @@ -880,6 +881,68 @@ out:
59167 return ret;
59168 }
59169
59170 +/* refill_reqs_available
59171 + * Updates the reqs_available reference counts used for tracking the
59172 + * number of free slots in the completion ring. This can be called
59173 + * from aio_complete() (to optimistically update reqs_available) or
59174 + * from aio_get_req() (the we're out of events case). It must be
59175 + * called holding ctx->completion_lock.
59176 + */
59177 +static void refill_reqs_available(struct kioctx *ctx, unsigned head,
59178 + unsigned tail)
59179 +{
59180 + unsigned events_in_ring, completed;
59181 +
59182 + /* Clamp head since userland can write to it. */
59183 + head %= ctx->nr_events;
59184 + if (head <= tail)
59185 + events_in_ring = tail - head;
59186 + else
59187 + events_in_ring = ctx->nr_events - (head - tail);
59188 +
59189 + completed = ctx->completed_events;
59190 + if (events_in_ring < completed)
59191 + completed -= events_in_ring;
59192 + else
59193 + completed = 0;
59194 +
59195 + if (!completed)
59196 + return;
59197 +
59198 + ctx->completed_events -= completed;
59199 + put_reqs_available(ctx, completed);
59200 +}
59201 +
59202 +/* user_refill_reqs_available
59203 + * Called to refill reqs_available when aio_get_req() encounters an
59204 + * out of space in the completion ring.
59205 + */
59206 +static void user_refill_reqs_available(struct kioctx *ctx)
59207 +{
59208 + spin_lock_irq(&ctx->completion_lock);
59209 + if (ctx->completed_events) {
59210 + struct aio_ring *ring;
59211 + unsigned head;
59212 +
59213 + /* Access of ring->head may race with aio_read_events_ring()
59214 + * here, but that's okay since whether we read the old version
59215 + * or the new version, and either will be valid. The important
59216 + * part is that head cannot pass tail since we prevent
59217 + * aio_complete() from updating tail by holding
59218 + * ctx->completion_lock. Even if head is invalid, the check
59219 + * against ctx->completed_events below will make sure we do the
59220 + * safe/right thing.
59221 + */
59222 + ring = kmap_atomic(ctx->ring_pages[0]);
59223 + head = ring->head;
59224 + kunmap_atomic(ring);
59225 +
59226 + refill_reqs_available(ctx, head, ctx->tail);
59227 + }
59228 +
59229 + spin_unlock_irq(&ctx->completion_lock);
59230 +}
59231 +
59232 /* aio_get_req
59233 * Allocate a slot for an aio request.
59234 * Returns NULL if no requests are free.
59235 @@ -888,8 +951,11 @@ static inline struct kiocb *aio_get_req(struct kioctx *ctx)
59236 {
59237 struct kiocb *req;
59238
59239 - if (!get_reqs_available(ctx))
59240 - return NULL;
59241 + if (!get_reqs_available(ctx)) {
59242 + user_refill_reqs_available(ctx);
59243 + if (!get_reqs_available(ctx))
59244 + return NULL;
59245 + }
59246
59247 req = kmem_cache_alloc(kiocb_cachep, GFP_KERNEL|__GFP_ZERO);
59248 if (unlikely(!req))
59249 @@ -948,8 +1014,8 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
59250 struct kioctx *ctx = iocb->ki_ctx;
59251 struct aio_ring *ring;
59252 struct io_event *ev_page, *event;
59253 + unsigned tail, pos, head;
59254 unsigned long flags;
59255 - unsigned tail, pos;
59256
59257 /*
59258 * Special case handling for sync iocbs:
59259 @@ -1010,10 +1076,14 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
59260 ctx->tail = tail;
59261
59262 ring = kmap_atomic(ctx->ring_pages[0]);
59263 + head = ring->head;
59264 ring->tail = tail;
59265 kunmap_atomic(ring);
59266 flush_dcache_page(ctx->ring_pages[0]);
59267
59268 + ctx->completed_events++;
59269 + if (ctx->completed_events > 1)
59270 + refill_reqs_available(ctx, head, tail);
59271 spin_unlock_irqrestore(&ctx->completion_lock, flags);
59272
59273 pr_debug("added to ring %p at [%u]\n", iocb, tail);
59274 @@ -1028,7 +1098,6 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
59275
59276 /* everything turned out well, dispose of the aiocb. */
59277 kiocb_free(iocb);
59278 - put_reqs_available(ctx, 1);
59279
59280 /*
59281 * We have to order our ring_info tail store above and test
59282 @@ -1065,6 +1134,12 @@ static long aio_read_events_ring(struct kioctx *ctx,
59283 tail = ring->tail;
59284 kunmap_atomic(ring);
59285
59286 + /*
59287 + * Ensure that once we've read the current tail pointer, that
59288 + * we also see the events that were stored up to the tail.
59289 + */
59290 + smp_rmb();
59291 +
59292 pr_debug("h%u t%u m%u\n", head, tail, ctx->nr_events);
59293
59294 if (head == tail)
59295 diff --git a/fs/attr.c b/fs/attr.c
59296 index 6530ced..4a827e2 100644
59297 --- a/fs/attr.c
59298 +++ b/fs/attr.c
59299 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
59300 unsigned long limit;
59301
59302 limit = rlimit(RLIMIT_FSIZE);
59303 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
59304 if (limit != RLIM_INFINITY && offset > limit)
59305 goto out_sig;
59306 if (offset > inode->i_sb->s_maxbytes)
59307 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
59308 index 116fd38..c04182da 100644
59309 --- a/fs/autofs4/waitq.c
59310 +++ b/fs/autofs4/waitq.c
59311 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
59312 {
59313 unsigned long sigpipe, flags;
59314 mm_segment_t fs;
59315 - const char *data = (const char *)addr;
59316 + const char __user *data = (const char __force_user *)addr;
59317 ssize_t wr = 0;
59318
59319 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
59320 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
59321 return 1;
59322 }
59323
59324 +#ifdef CONFIG_GRKERNSEC_HIDESYM
59325 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
59326 +#endif
59327 +
59328 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
59329 enum autofs_notify notify)
59330 {
59331 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
59332
59333 /* If this is a direct mount request create a dummy name */
59334 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
59335 +#ifdef CONFIG_GRKERNSEC_HIDESYM
59336 + /* this name does get written to userland via autofs4_write() */
59337 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
59338 +#else
59339 qstr.len = sprintf(name, "%p", dentry);
59340 +#endif
59341 else {
59342 qstr.len = autofs4_getpath(sbi, dentry, &name);
59343 if (!qstr.len) {
59344 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
59345 index 2722387..56059b5 100644
59346 --- a/fs/befs/endian.h
59347 +++ b/fs/befs/endian.h
59348 @@ -11,7 +11,7 @@
59349
59350 #include <asm/byteorder.h>
59351
59352 -static inline u64
59353 +static inline u64 __intentional_overflow(-1)
59354 fs64_to_cpu(const struct super_block *sb, fs64 n)
59355 {
59356 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59357 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
59358 return (__force fs64)cpu_to_be64(n);
59359 }
59360
59361 -static inline u32
59362 +static inline u32 __intentional_overflow(-1)
59363 fs32_to_cpu(const struct super_block *sb, fs32 n)
59364 {
59365 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59366 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
59367 return (__force fs32)cpu_to_be32(n);
59368 }
59369
59370 -static inline u16
59371 +static inline u16 __intentional_overflow(-1)
59372 fs16_to_cpu(const struct super_block *sb, fs16 n)
59373 {
59374 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59375 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
59376 index ca0ba15..0fa3257 100644
59377 --- a/fs/binfmt_aout.c
59378 +++ b/fs/binfmt_aout.c
59379 @@ -16,6 +16,7 @@
59380 #include <linux/string.h>
59381 #include <linux/fs.h>
59382 #include <linux/file.h>
59383 +#include <linux/security.h>
59384 #include <linux/stat.h>
59385 #include <linux/fcntl.h>
59386 #include <linux/ptrace.h>
59387 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
59388 #endif
59389 # define START_STACK(u) ((void __user *)u.start_stack)
59390
59391 + memset(&dump, 0, sizeof(dump));
59392 +
59393 fs = get_fs();
59394 set_fs(KERNEL_DS);
59395 has_dumped = 1;
59396 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
59397
59398 /* If the size of the dump file exceeds the rlimit, then see what would happen
59399 if we wrote the stack, but not the data area. */
59400 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
59401 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
59402 dump.u_dsize = 0;
59403
59404 /* Make sure we have enough room to write the stack and data areas. */
59405 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
59406 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
59407 dump.u_ssize = 0;
59408
59409 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
59410 rlim = rlimit(RLIMIT_DATA);
59411 if (rlim >= RLIM_INFINITY)
59412 rlim = ~0;
59413 +
59414 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
59415 if (ex.a_data + ex.a_bss > rlim)
59416 return -ENOMEM;
59417
59418 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
59419
59420 install_exec_creds(bprm);
59421
59422 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59423 + current->mm->pax_flags = 0UL;
59424 +#endif
59425 +
59426 +#ifdef CONFIG_PAX_PAGEEXEC
59427 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
59428 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
59429 +
59430 +#ifdef CONFIG_PAX_EMUTRAMP
59431 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
59432 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
59433 +#endif
59434 +
59435 +#ifdef CONFIG_PAX_MPROTECT
59436 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
59437 + current->mm->pax_flags |= MF_PAX_MPROTECT;
59438 +#endif
59439 +
59440 + }
59441 +#endif
59442 +
59443 if (N_MAGIC(ex) == OMAGIC) {
59444 unsigned long text_addr, map_size;
59445 loff_t pos;
59446 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
59447 }
59448
59449 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
59450 - PROT_READ | PROT_WRITE | PROT_EXEC,
59451 + PROT_READ | PROT_WRITE,
59452 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
59453 fd_offset + ex.a_text);
59454 if (error != N_DATADDR(ex)) {
59455 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
59456 index 3892c1a..4e27c04 100644
59457 --- a/fs/binfmt_elf.c
59458 +++ b/fs/binfmt_elf.c
59459 @@ -34,6 +34,7 @@
59460 #include <linux/utsname.h>
59461 #include <linux/coredump.h>
59462 #include <linux/sched.h>
59463 +#include <linux/xattr.h>
59464 #include <asm/uaccess.h>
59465 #include <asm/param.h>
59466 #include <asm/page.h>
59467 @@ -47,7 +48,7 @@
59468
59469 static int load_elf_binary(struct linux_binprm *bprm);
59470 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
59471 - int, int, unsigned long);
59472 + int, int, unsigned long) __intentional_overflow(-1);
59473
59474 #ifdef CONFIG_USELIB
59475 static int load_elf_library(struct file *);
59476 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
59477 #define elf_core_dump NULL
59478 #endif
59479
59480 +#ifdef CONFIG_PAX_MPROTECT
59481 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
59482 +#endif
59483 +
59484 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59485 +static void elf_handle_mmap(struct file *file);
59486 +#endif
59487 +
59488 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
59489 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
59490 #else
59491 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
59492 .load_binary = load_elf_binary,
59493 .load_shlib = load_elf_library,
59494 .core_dump = elf_core_dump,
59495 +
59496 +#ifdef CONFIG_PAX_MPROTECT
59497 + .handle_mprotect= elf_handle_mprotect,
59498 +#endif
59499 +
59500 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59501 + .handle_mmap = elf_handle_mmap,
59502 +#endif
59503 +
59504 .min_coredump = ELF_EXEC_PAGESIZE,
59505 };
59506
59507 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
59508
59509 static int set_brk(unsigned long start, unsigned long end)
59510 {
59511 + unsigned long e = end;
59512 +
59513 start = ELF_PAGEALIGN(start);
59514 end = ELF_PAGEALIGN(end);
59515 if (end > start) {
59516 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
59517 if (BAD_ADDR(addr))
59518 return addr;
59519 }
59520 - current->mm->start_brk = current->mm->brk = end;
59521 + current->mm->start_brk = current->mm->brk = e;
59522 return 0;
59523 }
59524
59525 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59526 elf_addr_t __user *u_rand_bytes;
59527 const char *k_platform = ELF_PLATFORM;
59528 const char *k_base_platform = ELF_BASE_PLATFORM;
59529 - unsigned char k_rand_bytes[16];
59530 + u32 k_rand_bytes[4];
59531 int items;
59532 elf_addr_t *elf_info;
59533 int ei_index = 0;
59534 const struct cred *cred = current_cred();
59535 struct vm_area_struct *vma;
59536 + unsigned long saved_auxv[AT_VECTOR_SIZE];
59537
59538 /*
59539 * In some cases (e.g. Hyper-Threading), we want to avoid L1
59540 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59541 * Generate 16 random bytes for userspace PRNG seeding.
59542 */
59543 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
59544 - u_rand_bytes = (elf_addr_t __user *)
59545 - STACK_ALLOC(p, sizeof(k_rand_bytes));
59546 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
59547 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
59548 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
59549 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
59550 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
59551 + u_rand_bytes = (elf_addr_t __user *) p;
59552 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
59553 return -EFAULT;
59554
59555 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59556 return -EFAULT;
59557 current->mm->env_end = p;
59558
59559 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
59560 +
59561 /* Put the elf_info on the stack in the right place. */
59562 sp = (elf_addr_t __user *)envp + 1;
59563 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
59564 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
59565 return -EFAULT;
59566 return 0;
59567 }
59568 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
59569 an ELF header */
59570
59571 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59572 - struct file *interpreter, unsigned long *interp_map_addr,
59573 - unsigned long no_base)
59574 + struct file *interpreter, unsigned long no_base)
59575 {
59576 struct elf_phdr *elf_phdata;
59577 struct elf_phdr *eppnt;
59578 - unsigned long load_addr = 0;
59579 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
59580 int load_addr_set = 0;
59581 unsigned long last_bss = 0, elf_bss = 0;
59582 - unsigned long error = ~0UL;
59583 + unsigned long error = -EINVAL;
59584 unsigned long total_size;
59585 int retval, i, size;
59586
59587 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59588 goto out_close;
59589 }
59590
59591 +#ifdef CONFIG_PAX_SEGMEXEC
59592 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
59593 + pax_task_size = SEGMEXEC_TASK_SIZE;
59594 +#endif
59595 +
59596 eppnt = elf_phdata;
59597 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
59598 if (eppnt->p_type == PT_LOAD) {
59599 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59600 map_addr = elf_map(interpreter, load_addr + vaddr,
59601 eppnt, elf_prot, elf_type, total_size);
59602 total_size = 0;
59603 - if (!*interp_map_addr)
59604 - *interp_map_addr = map_addr;
59605 error = map_addr;
59606 if (BAD_ADDR(map_addr))
59607 goto out_close;
59608 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59609 k = load_addr + eppnt->p_vaddr;
59610 if (BAD_ADDR(k) ||
59611 eppnt->p_filesz > eppnt->p_memsz ||
59612 - eppnt->p_memsz > TASK_SIZE ||
59613 - TASK_SIZE - eppnt->p_memsz < k) {
59614 + eppnt->p_memsz > pax_task_size ||
59615 + pax_task_size - eppnt->p_memsz < k) {
59616 error = -ENOMEM;
59617 goto out_close;
59618 }
59619 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59620 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
59621
59622 /* Map the last of the bss segment */
59623 - error = vm_brk(elf_bss, last_bss - elf_bss);
59624 - if (BAD_ADDR(error))
59625 - goto out_close;
59626 + if (last_bss > elf_bss) {
59627 + error = vm_brk(elf_bss, last_bss - elf_bss);
59628 + if (BAD_ADDR(error))
59629 + goto out_close;
59630 + }
59631 }
59632
59633 error = load_addr;
59634 @@ -543,6 +574,336 @@ out:
59635 return error;
59636 }
59637
59638 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59639 +#ifdef CONFIG_PAX_SOFTMODE
59640 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
59641 +{
59642 + unsigned long pax_flags = 0UL;
59643 +
59644 +#ifdef CONFIG_PAX_PAGEEXEC
59645 + if (elf_phdata->p_flags & PF_PAGEEXEC)
59646 + pax_flags |= MF_PAX_PAGEEXEC;
59647 +#endif
59648 +
59649 +#ifdef CONFIG_PAX_SEGMEXEC
59650 + if (elf_phdata->p_flags & PF_SEGMEXEC)
59651 + pax_flags |= MF_PAX_SEGMEXEC;
59652 +#endif
59653 +
59654 +#ifdef CONFIG_PAX_EMUTRAMP
59655 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59656 + pax_flags |= MF_PAX_EMUTRAMP;
59657 +#endif
59658 +
59659 +#ifdef CONFIG_PAX_MPROTECT
59660 + if (elf_phdata->p_flags & PF_MPROTECT)
59661 + pax_flags |= MF_PAX_MPROTECT;
59662 +#endif
59663 +
59664 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59665 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
59666 + pax_flags |= MF_PAX_RANDMMAP;
59667 +#endif
59668 +
59669 + return pax_flags;
59670 +}
59671 +#endif
59672 +
59673 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
59674 +{
59675 + unsigned long pax_flags = 0UL;
59676 +
59677 +#ifdef CONFIG_PAX_PAGEEXEC
59678 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
59679 + pax_flags |= MF_PAX_PAGEEXEC;
59680 +#endif
59681 +
59682 +#ifdef CONFIG_PAX_SEGMEXEC
59683 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
59684 + pax_flags |= MF_PAX_SEGMEXEC;
59685 +#endif
59686 +
59687 +#ifdef CONFIG_PAX_EMUTRAMP
59688 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
59689 + pax_flags |= MF_PAX_EMUTRAMP;
59690 +#endif
59691 +
59692 +#ifdef CONFIG_PAX_MPROTECT
59693 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
59694 + pax_flags |= MF_PAX_MPROTECT;
59695 +#endif
59696 +
59697 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59698 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
59699 + pax_flags |= MF_PAX_RANDMMAP;
59700 +#endif
59701 +
59702 + return pax_flags;
59703 +}
59704 +#endif
59705 +
59706 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59707 +#ifdef CONFIG_PAX_SOFTMODE
59708 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
59709 +{
59710 + unsigned long pax_flags = 0UL;
59711 +
59712 +#ifdef CONFIG_PAX_PAGEEXEC
59713 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
59714 + pax_flags |= MF_PAX_PAGEEXEC;
59715 +#endif
59716 +
59717 +#ifdef CONFIG_PAX_SEGMEXEC
59718 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
59719 + pax_flags |= MF_PAX_SEGMEXEC;
59720 +#endif
59721 +
59722 +#ifdef CONFIG_PAX_EMUTRAMP
59723 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59724 + pax_flags |= MF_PAX_EMUTRAMP;
59725 +#endif
59726 +
59727 +#ifdef CONFIG_PAX_MPROTECT
59728 + if (pax_flags_softmode & MF_PAX_MPROTECT)
59729 + pax_flags |= MF_PAX_MPROTECT;
59730 +#endif
59731 +
59732 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59733 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
59734 + pax_flags |= MF_PAX_RANDMMAP;
59735 +#endif
59736 +
59737 + return pax_flags;
59738 +}
59739 +#endif
59740 +
59741 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
59742 +{
59743 + unsigned long pax_flags = 0UL;
59744 +
59745 +#ifdef CONFIG_PAX_PAGEEXEC
59746 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
59747 + pax_flags |= MF_PAX_PAGEEXEC;
59748 +#endif
59749 +
59750 +#ifdef CONFIG_PAX_SEGMEXEC
59751 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
59752 + pax_flags |= MF_PAX_SEGMEXEC;
59753 +#endif
59754 +
59755 +#ifdef CONFIG_PAX_EMUTRAMP
59756 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
59757 + pax_flags |= MF_PAX_EMUTRAMP;
59758 +#endif
59759 +
59760 +#ifdef CONFIG_PAX_MPROTECT
59761 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
59762 + pax_flags |= MF_PAX_MPROTECT;
59763 +#endif
59764 +
59765 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59766 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
59767 + pax_flags |= MF_PAX_RANDMMAP;
59768 +#endif
59769 +
59770 + return pax_flags;
59771 +}
59772 +#endif
59773 +
59774 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59775 +static unsigned long pax_parse_defaults(void)
59776 +{
59777 + unsigned long pax_flags = 0UL;
59778 +
59779 +#ifdef CONFIG_PAX_SOFTMODE
59780 + if (pax_softmode)
59781 + return pax_flags;
59782 +#endif
59783 +
59784 +#ifdef CONFIG_PAX_PAGEEXEC
59785 + pax_flags |= MF_PAX_PAGEEXEC;
59786 +#endif
59787 +
59788 +#ifdef CONFIG_PAX_SEGMEXEC
59789 + pax_flags |= MF_PAX_SEGMEXEC;
59790 +#endif
59791 +
59792 +#ifdef CONFIG_PAX_MPROTECT
59793 + pax_flags |= MF_PAX_MPROTECT;
59794 +#endif
59795 +
59796 +#ifdef CONFIG_PAX_RANDMMAP
59797 + if (randomize_va_space)
59798 + pax_flags |= MF_PAX_RANDMMAP;
59799 +#endif
59800 +
59801 + return pax_flags;
59802 +}
59803 +
59804 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
59805 +{
59806 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
59807 +
59808 +#ifdef CONFIG_PAX_EI_PAX
59809 +
59810 +#ifdef CONFIG_PAX_SOFTMODE
59811 + if (pax_softmode)
59812 + return pax_flags;
59813 +#endif
59814 +
59815 + pax_flags = 0UL;
59816 +
59817 +#ifdef CONFIG_PAX_PAGEEXEC
59818 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
59819 + pax_flags |= MF_PAX_PAGEEXEC;
59820 +#endif
59821 +
59822 +#ifdef CONFIG_PAX_SEGMEXEC
59823 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
59824 + pax_flags |= MF_PAX_SEGMEXEC;
59825 +#endif
59826 +
59827 +#ifdef CONFIG_PAX_EMUTRAMP
59828 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
59829 + pax_flags |= MF_PAX_EMUTRAMP;
59830 +#endif
59831 +
59832 +#ifdef CONFIG_PAX_MPROTECT
59833 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
59834 + pax_flags |= MF_PAX_MPROTECT;
59835 +#endif
59836 +
59837 +#ifdef CONFIG_PAX_ASLR
59838 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
59839 + pax_flags |= MF_PAX_RANDMMAP;
59840 +#endif
59841 +
59842 +#endif
59843 +
59844 + return pax_flags;
59845 +
59846 +}
59847 +
59848 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
59849 +{
59850 +
59851 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59852 + unsigned long i;
59853 +
59854 + for (i = 0UL; i < elf_ex->e_phnum; i++)
59855 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
59856 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
59857 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
59858 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
59859 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
59860 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
59861 + return PAX_PARSE_FLAGS_FALLBACK;
59862 +
59863 +#ifdef CONFIG_PAX_SOFTMODE
59864 + if (pax_softmode)
59865 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
59866 + else
59867 +#endif
59868 +
59869 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
59870 + break;
59871 + }
59872 +#endif
59873 +
59874 + return PAX_PARSE_FLAGS_FALLBACK;
59875 +}
59876 +
59877 +static unsigned long pax_parse_xattr_pax(struct file * const file)
59878 +{
59879 +
59880 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59881 + ssize_t xattr_size, i;
59882 + unsigned char xattr_value[sizeof("pemrs") - 1];
59883 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
59884 +
59885 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
59886 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
59887 + return PAX_PARSE_FLAGS_FALLBACK;
59888 +
59889 + for (i = 0; i < xattr_size; i++)
59890 + switch (xattr_value[i]) {
59891 + default:
59892 + return PAX_PARSE_FLAGS_FALLBACK;
59893 +
59894 +#define parse_flag(option1, option2, flag) \
59895 + case option1: \
59896 + if (pax_flags_hardmode & MF_PAX_##flag) \
59897 + return PAX_PARSE_FLAGS_FALLBACK;\
59898 + pax_flags_hardmode |= MF_PAX_##flag; \
59899 + break; \
59900 + case option2: \
59901 + if (pax_flags_softmode & MF_PAX_##flag) \
59902 + return PAX_PARSE_FLAGS_FALLBACK;\
59903 + pax_flags_softmode |= MF_PAX_##flag; \
59904 + break;
59905 +
59906 + parse_flag('p', 'P', PAGEEXEC);
59907 + parse_flag('e', 'E', EMUTRAMP);
59908 + parse_flag('m', 'M', MPROTECT);
59909 + parse_flag('r', 'R', RANDMMAP);
59910 + parse_flag('s', 'S', SEGMEXEC);
59911 +
59912 +#undef parse_flag
59913 + }
59914 +
59915 + if (pax_flags_hardmode & pax_flags_softmode)
59916 + return PAX_PARSE_FLAGS_FALLBACK;
59917 +
59918 +#ifdef CONFIG_PAX_SOFTMODE
59919 + if (pax_softmode)
59920 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
59921 + else
59922 +#endif
59923 +
59924 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
59925 +#else
59926 + return PAX_PARSE_FLAGS_FALLBACK;
59927 +#endif
59928 +
59929 +}
59930 +
59931 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
59932 +{
59933 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
59934 +
59935 + pax_flags = pax_parse_defaults();
59936 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
59937 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
59938 + xattr_pax_flags = pax_parse_xattr_pax(file);
59939 +
59940 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59941 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59942 + pt_pax_flags != xattr_pax_flags)
59943 + return -EINVAL;
59944 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59945 + pax_flags = xattr_pax_flags;
59946 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59947 + pax_flags = pt_pax_flags;
59948 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59949 + pax_flags = ei_pax_flags;
59950 +
59951 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59952 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59953 + if ((__supported_pte_mask & _PAGE_NX))
59954 + pax_flags &= ~MF_PAX_SEGMEXEC;
59955 + else
59956 + pax_flags &= ~MF_PAX_PAGEEXEC;
59957 + }
59958 +#endif
59959 +
59960 + if (0 > pax_check_flags(&pax_flags))
59961 + return -EINVAL;
59962 +
59963 + current->mm->pax_flags = pax_flags;
59964 + return 0;
59965 +}
59966 +#endif
59967 +
59968 /*
59969 * These are the functions used to load ELF style executables and shared
59970 * libraries. There is no binary dependent code anywhere else.
59971 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59972 {
59973 unsigned int random_variable = 0;
59974
59975 +#ifdef CONFIG_PAX_RANDUSTACK
59976 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59977 + return stack_top - current->mm->delta_stack;
59978 +#endif
59979 +
59980 if ((current->flags & PF_RANDOMIZE) &&
59981 !(current->personality & ADDR_NO_RANDOMIZE)) {
59982 random_variable = get_random_int() & STACK_RND_MASK;
59983 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59984 unsigned long load_addr = 0, load_bias = 0;
59985 int load_addr_set = 0;
59986 char * elf_interpreter = NULL;
59987 - unsigned long error;
59988 + unsigned long error = 0;
59989 struct elf_phdr *elf_ppnt, *elf_phdata;
59990 unsigned long elf_bss, elf_brk;
59991 int retval, i;
59992 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59993 struct elfhdr elf_ex;
59994 struct elfhdr interp_elf_ex;
59995 } *loc;
59996 + unsigned long pax_task_size;
59997
59998 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59999 if (!loc) {
60000 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
60001 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
60002 may depend on the personality. */
60003 SET_PERSONALITY(loc->elf_ex);
60004 +
60005 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60006 + current->mm->pax_flags = 0UL;
60007 +#endif
60008 +
60009 +#ifdef CONFIG_PAX_DLRESOLVE
60010 + current->mm->call_dl_resolve = 0UL;
60011 +#endif
60012 +
60013 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
60014 + current->mm->call_syscall = 0UL;
60015 +#endif
60016 +
60017 +#ifdef CONFIG_PAX_ASLR
60018 + current->mm->delta_mmap = 0UL;
60019 + current->mm->delta_stack = 0UL;
60020 +#endif
60021 +
60022 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60023 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
60024 + send_sig(SIGKILL, current, 0);
60025 + goto out_free_dentry;
60026 + }
60027 +#endif
60028 +
60029 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60030 + pax_set_initial_flags(bprm);
60031 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
60032 + if (pax_set_initial_flags_func)
60033 + (pax_set_initial_flags_func)(bprm);
60034 +#endif
60035 +
60036 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60037 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
60038 + current->mm->context.user_cs_limit = PAGE_SIZE;
60039 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
60040 + }
60041 +#endif
60042 +
60043 +#ifdef CONFIG_PAX_SEGMEXEC
60044 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
60045 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
60046 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
60047 + pax_task_size = SEGMEXEC_TASK_SIZE;
60048 + current->mm->def_flags |= VM_NOHUGEPAGE;
60049 + } else
60050 +#endif
60051 +
60052 + pax_task_size = TASK_SIZE;
60053 +
60054 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
60055 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60056 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
60057 + put_cpu();
60058 + }
60059 +#endif
60060 +
60061 +#ifdef CONFIG_PAX_ASLR
60062 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
60063 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
60064 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
60065 + }
60066 +#endif
60067 +
60068 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
60069 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60070 + executable_stack = EXSTACK_DISABLE_X;
60071 + current->personality &= ~READ_IMPLIES_EXEC;
60072 + } else
60073 +#endif
60074 +
60075 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
60076 current->personality |= READ_IMPLIES_EXEC;
60077
60078 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
60079 #else
60080 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
60081 #endif
60082 +
60083 +#ifdef CONFIG_PAX_RANDMMAP
60084 + /* PaX: randomize base address at the default exe base if requested */
60085 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
60086 +#ifdef CONFIG_SPARC64
60087 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
60088 +#else
60089 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
60090 +#endif
60091 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
60092 + elf_flags |= MAP_FIXED;
60093 + }
60094 +#endif
60095 +
60096 }
60097
60098 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
60099 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
60100 * allowed task size. Note that p_filesz must always be
60101 * <= p_memsz so it is only necessary to check p_memsz.
60102 */
60103 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
60104 - elf_ppnt->p_memsz > TASK_SIZE ||
60105 - TASK_SIZE - elf_ppnt->p_memsz < k) {
60106 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
60107 + elf_ppnt->p_memsz > pax_task_size ||
60108 + pax_task_size - elf_ppnt->p_memsz < k) {
60109 /* set_brk can never work. Avoid overflows. */
60110 send_sig(SIGKILL, current, 0);
60111 retval = -EINVAL;
60112 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
60113 goto out_free_dentry;
60114 }
60115 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
60116 - send_sig(SIGSEGV, current, 0);
60117 - retval = -EFAULT; /* Nobody gets to see this, but.. */
60118 - goto out_free_dentry;
60119 + /*
60120 + * This bss-zeroing can fail if the ELF
60121 + * file specifies odd protections. So
60122 + * we don't check the return value
60123 + */
60124 }
60125
60126 +#ifdef CONFIG_PAX_RANDMMAP
60127 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
60128 + unsigned long start, size, flags;
60129 + vm_flags_t vm_flags;
60130 +
60131 + start = ELF_PAGEALIGN(elf_brk);
60132 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
60133 + flags = MAP_FIXED | MAP_PRIVATE;
60134 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
60135 +
60136 + down_write(&current->mm->mmap_sem);
60137 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
60138 + retval = -ENOMEM;
60139 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
60140 +// if (current->personality & ADDR_NO_RANDOMIZE)
60141 +// vm_flags |= VM_READ | VM_MAYREAD;
60142 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
60143 + retval = IS_ERR_VALUE(start) ? start : 0;
60144 + }
60145 + up_write(&current->mm->mmap_sem);
60146 + if (retval == 0)
60147 + retval = set_brk(start + size, start + size + PAGE_SIZE);
60148 + if (retval < 0) {
60149 + send_sig(SIGKILL, current, 0);
60150 + goto out_free_dentry;
60151 + }
60152 + }
60153 +#endif
60154 +
60155 if (elf_interpreter) {
60156 - unsigned long interp_map_addr = 0;
60157 -
60158 elf_entry = load_elf_interp(&loc->interp_elf_ex,
60159 interpreter,
60160 - &interp_map_addr,
60161 load_bias);
60162 if (!IS_ERR((void *)elf_entry)) {
60163 /*
60164 @@ -1130,7 +1610,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
60165 * Decide what to dump of a segment, part, all or none.
60166 */
60167 static unsigned long vma_dump_size(struct vm_area_struct *vma,
60168 - unsigned long mm_flags)
60169 + unsigned long mm_flags, long signr)
60170 {
60171 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
60172
60173 @@ -1168,7 +1648,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
60174 if (vma->vm_file == NULL)
60175 return 0;
60176
60177 - if (FILTER(MAPPED_PRIVATE))
60178 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
60179 goto whole;
60180
60181 /*
60182 @@ -1375,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
60183 {
60184 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
60185 int i = 0;
60186 - do
60187 + do {
60188 i += 2;
60189 - while (auxv[i - 2] != AT_NULL);
60190 + } while (auxv[i - 2] != AT_NULL);
60191 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
60192 }
60193
60194 @@ -1386,7 +1866,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
60195 {
60196 mm_segment_t old_fs = get_fs();
60197 set_fs(KERNEL_DS);
60198 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
60199 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
60200 set_fs(old_fs);
60201 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
60202 }
60203 @@ -2010,14 +2490,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
60204 }
60205
60206 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
60207 - unsigned long mm_flags)
60208 + struct coredump_params *cprm)
60209 {
60210 struct vm_area_struct *vma;
60211 size_t size = 0;
60212
60213 for (vma = first_vma(current, gate_vma); vma != NULL;
60214 vma = next_vma(vma, gate_vma))
60215 - size += vma_dump_size(vma, mm_flags);
60216 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60217 return size;
60218 }
60219
60220 @@ -2108,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60221
60222 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
60223
60224 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
60225 + offset += elf_core_vma_data_size(gate_vma, cprm);
60226 offset += elf_core_extra_data_size();
60227 e_shoff = offset;
60228
60229 @@ -2136,7 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60230 phdr.p_offset = offset;
60231 phdr.p_vaddr = vma->vm_start;
60232 phdr.p_paddr = 0;
60233 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
60234 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60235 phdr.p_memsz = vma->vm_end - vma->vm_start;
60236 offset += phdr.p_filesz;
60237 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
60238 @@ -2169,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60239 unsigned long addr;
60240 unsigned long end;
60241
60242 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
60243 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60244
60245 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
60246 struct page *page;
60247 @@ -2210,6 +2690,167 @@ out:
60248
60249 #endif /* CONFIG_ELF_CORE */
60250
60251 +#ifdef CONFIG_PAX_MPROTECT
60252 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
60253 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
60254 + * we'll remove VM_MAYWRITE for good on RELRO segments.
60255 + *
60256 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
60257 + * basis because we want to allow the common case and not the special ones.
60258 + */
60259 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
60260 +{
60261 + struct elfhdr elf_h;
60262 + struct elf_phdr elf_p;
60263 + unsigned long i;
60264 + unsigned long oldflags;
60265 + bool is_textrel_rw, is_textrel_rx, is_relro;
60266 +
60267 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
60268 + return;
60269 +
60270 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
60271 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
60272 +
60273 +#ifdef CONFIG_PAX_ELFRELOCS
60274 + /* possible TEXTREL */
60275 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
60276 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
60277 +#else
60278 + is_textrel_rw = false;
60279 + is_textrel_rx = false;
60280 +#endif
60281 +
60282 + /* possible RELRO */
60283 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
60284 +
60285 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
60286 + return;
60287 +
60288 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
60289 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
60290 +
60291 +#ifdef CONFIG_PAX_ETEXECRELOCS
60292 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
60293 +#else
60294 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
60295 +#endif
60296 +
60297 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
60298 + !elf_check_arch(&elf_h) ||
60299 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
60300 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
60301 + return;
60302 +
60303 + for (i = 0UL; i < elf_h.e_phnum; i++) {
60304 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
60305 + return;
60306 + switch (elf_p.p_type) {
60307 + case PT_DYNAMIC:
60308 + if (!is_textrel_rw && !is_textrel_rx)
60309 + continue;
60310 + i = 0UL;
60311 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
60312 + elf_dyn dyn;
60313 +
60314 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
60315 + break;
60316 + if (dyn.d_tag == DT_NULL)
60317 + break;
60318 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
60319 + gr_log_textrel(vma);
60320 + if (is_textrel_rw)
60321 + vma->vm_flags |= VM_MAYWRITE;
60322 + else
60323 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
60324 + vma->vm_flags &= ~VM_MAYWRITE;
60325 + break;
60326 + }
60327 + i++;
60328 + }
60329 + is_textrel_rw = false;
60330 + is_textrel_rx = false;
60331 + continue;
60332 +
60333 + case PT_GNU_RELRO:
60334 + if (!is_relro)
60335 + continue;
60336 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
60337 + vma->vm_flags &= ~VM_MAYWRITE;
60338 + is_relro = false;
60339 + continue;
60340 +
60341 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
60342 + case PT_PAX_FLAGS: {
60343 + const char *msg_mprotect = "", *msg_emutramp = "";
60344 + char *buffer_lib, *buffer_exe;
60345 +
60346 + if (elf_p.p_flags & PF_NOMPROTECT)
60347 + msg_mprotect = "MPROTECT disabled";
60348 +
60349 +#ifdef CONFIG_PAX_EMUTRAMP
60350 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
60351 + msg_emutramp = "EMUTRAMP enabled";
60352 +#endif
60353 +
60354 + if (!msg_mprotect[0] && !msg_emutramp[0])
60355 + continue;
60356 +
60357 + if (!printk_ratelimit())
60358 + continue;
60359 +
60360 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
60361 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
60362 + if (buffer_lib && buffer_exe) {
60363 + char *path_lib, *path_exe;
60364 +
60365 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
60366 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
60367 +
60368 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
60369 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
60370 +
60371 + }
60372 + free_page((unsigned long)buffer_exe);
60373 + free_page((unsigned long)buffer_lib);
60374 + continue;
60375 + }
60376 +#endif
60377 +
60378 + }
60379 + }
60380 +}
60381 +#endif
60382 +
60383 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60384 +
60385 +extern int grsec_enable_log_rwxmaps;
60386 +
60387 +static void elf_handle_mmap(struct file *file)
60388 +{
60389 + struct elfhdr elf_h;
60390 + struct elf_phdr elf_p;
60391 + unsigned long i;
60392 +
60393 + if (!grsec_enable_log_rwxmaps)
60394 + return;
60395 +
60396 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
60397 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
60398 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
60399 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
60400 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
60401 + return;
60402 +
60403 + for (i = 0UL; i < elf_h.e_phnum; i++) {
60404 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
60405 + return;
60406 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
60407 + gr_log_ptgnustack(file);
60408 + }
60409 +}
60410 +#endif
60411 +
60412 static int __init init_elf_binfmt(void)
60413 {
60414 register_binfmt(&elf_format);
60415 diff --git a/fs/block_dev.c b/fs/block_dev.c
60416 index 6d72746..536d1db 100644
60417 --- a/fs/block_dev.c
60418 +++ b/fs/block_dev.c
60419 @@ -701,7 +701,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
60420 else if (bdev->bd_contains == bdev)
60421 return true; /* is a whole device which isn't held */
60422
60423 - else if (whole->bd_holder == bd_may_claim)
60424 + else if (whole->bd_holder == (void *)bd_may_claim)
60425 return true; /* is a partition of a device that is being partitioned */
60426 else if (whole->bd_holder != NULL)
60427 return false; /* is a partition of a held device */
60428 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
60429 index aeab453..48dbafc 100644
60430 --- a/fs/btrfs/ctree.c
60431 +++ b/fs/btrfs/ctree.c
60432 @@ -1184,9 +1184,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
60433 free_extent_buffer(buf);
60434 add_root_to_dirty_list(root);
60435 } else {
60436 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
60437 - parent_start = parent->start;
60438 - else
60439 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
60440 + if (parent)
60441 + parent_start = parent->start;
60442 + else
60443 + parent_start = 0;
60444 + } else
60445 parent_start = 0;
60446
60447 WARN_ON(trans->transid != btrfs_header_generation(parent));
60448 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
60449 index a2e90f8..5135e5f 100644
60450 --- a/fs/btrfs/delayed-inode.c
60451 +++ b/fs/btrfs/delayed-inode.c
60452 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
60453
60454 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
60455 {
60456 - int seq = atomic_inc_return(&delayed_root->items_seq);
60457 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
60458 if ((atomic_dec_return(&delayed_root->items) <
60459 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
60460 waitqueue_active(&delayed_root->wait))
60461 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
60462
60463 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
60464 {
60465 - int val = atomic_read(&delayed_root->items_seq);
60466 + int val = atomic_read_unchecked(&delayed_root->items_seq);
60467
60468 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
60469 return 1;
60470 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
60471 int seq;
60472 int ret;
60473
60474 - seq = atomic_read(&delayed_root->items_seq);
60475 + seq = atomic_read_unchecked(&delayed_root->items_seq);
60476
60477 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
60478 if (ret)
60479 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
60480 index f70119f..ab5894d 100644
60481 --- a/fs/btrfs/delayed-inode.h
60482 +++ b/fs/btrfs/delayed-inode.h
60483 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
60484 */
60485 struct list_head prepare_list;
60486 atomic_t items; /* for delayed items */
60487 - atomic_t items_seq; /* for delayed items */
60488 + atomic_unchecked_t items_seq; /* for delayed items */
60489 int nodes; /* for delayed nodes */
60490 wait_queue_head_t wait;
60491 };
60492 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
60493 struct btrfs_delayed_root *delayed_root)
60494 {
60495 atomic_set(&delayed_root->items, 0);
60496 - atomic_set(&delayed_root->items_seq, 0);
60497 + atomic_set_unchecked(&delayed_root->items_seq, 0);
60498 delayed_root->nodes = 0;
60499 spin_lock_init(&delayed_root->lock);
60500 init_waitqueue_head(&delayed_root->wait);
60501 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
60502 index 47aceb4..7d28b1c 100644
60503 --- a/fs/btrfs/ioctl.c
60504 +++ b/fs/btrfs/ioctl.c
60505 @@ -3965,9 +3965,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
60506 for (i = 0; i < num_types; i++) {
60507 struct btrfs_space_info *tmp;
60508
60509 + /* Don't copy in more than we allocated */
60510 if (!slot_count)
60511 break;
60512
60513 + slot_count--;
60514 +
60515 info = NULL;
60516 rcu_read_lock();
60517 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
60518 @@ -3989,10 +3992,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
60519 memcpy(dest, &space, sizeof(space));
60520 dest++;
60521 space_args.total_spaces++;
60522 - slot_count--;
60523 }
60524 - if (!slot_count)
60525 - break;
60526 }
60527 up_read(&info->groups_sem);
60528 }
60529 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
60530 index 8e16bca..6eabd9e 100644
60531 --- a/fs/btrfs/super.c
60532 +++ b/fs/btrfs/super.c
60533 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
60534 function, line, errstr);
60535 return;
60536 }
60537 - ACCESS_ONCE(trans->transaction->aborted) = errno;
60538 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
60539 /* Wake up anybody who may be waiting on this transaction */
60540 wake_up(&root->fs_info->transaction_wait);
60541 wake_up(&root->fs_info->transaction_blocked_wait);
60542 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
60543 index 7869936..7e153dc 100644
60544 --- a/fs/btrfs/sysfs.c
60545 +++ b/fs/btrfs/sysfs.c
60546 @@ -475,7 +475,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
60547 for (set = 0; set < FEAT_MAX; set++) {
60548 int i;
60549 struct attribute *attrs[2];
60550 - struct attribute_group agroup = {
60551 + attribute_group_no_const agroup = {
60552 .name = "features",
60553 .attrs = attrs,
60554 };
60555 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
60556 index 7f5b41b..e589c13 100644
60557 --- a/fs/btrfs/tree-log.h
60558 +++ b/fs/btrfs/tree-log.h
60559 @@ -41,7 +41,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
60560 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
60561 struct btrfs_trans_handle *trans)
60562 {
60563 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
60564 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
60565 }
60566
60567 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
60568 diff --git a/fs/buffer.c b/fs/buffer.c
60569 index eba6e4f..af1182c 100644
60570 --- a/fs/buffer.c
60571 +++ b/fs/buffer.c
60572 @@ -3429,7 +3429,7 @@ void __init buffer_init(void)
60573 bh_cachep = kmem_cache_create("buffer_head",
60574 sizeof(struct buffer_head), 0,
60575 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
60576 - SLAB_MEM_SPREAD),
60577 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
60578 NULL);
60579
60580 /*
60581 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
60582 index d749731..dd333a6 100644
60583 --- a/fs/cachefiles/bind.c
60584 +++ b/fs/cachefiles/bind.c
60585 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
60586 args);
60587
60588 /* start by checking things over */
60589 - ASSERT(cache->fstop_percent >= 0 &&
60590 - cache->fstop_percent < cache->fcull_percent &&
60591 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
60592 cache->fcull_percent < cache->frun_percent &&
60593 cache->frun_percent < 100);
60594
60595 - ASSERT(cache->bstop_percent >= 0 &&
60596 - cache->bstop_percent < cache->bcull_percent &&
60597 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
60598 cache->bcull_percent < cache->brun_percent &&
60599 cache->brun_percent < 100);
60600
60601 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
60602 index b078d30..db23012 100644
60603 --- a/fs/cachefiles/daemon.c
60604 +++ b/fs/cachefiles/daemon.c
60605 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
60606 if (n > buflen)
60607 return -EMSGSIZE;
60608
60609 - if (copy_to_user(_buffer, buffer, n) != 0)
60610 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
60611 return -EFAULT;
60612
60613 return n;
60614 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
60615 if (test_bit(CACHEFILES_DEAD, &cache->flags))
60616 return -EIO;
60617
60618 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
60619 + if (datalen > PAGE_SIZE - 1)
60620 return -EOPNOTSUPP;
60621
60622 /* drag the command string into the kernel so we can parse it */
60623 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
60624 if (args[0] != '%' || args[1] != '\0')
60625 return -EINVAL;
60626
60627 - if (fstop < 0 || fstop >= cache->fcull_percent)
60628 + if (fstop >= cache->fcull_percent)
60629 return cachefiles_daemon_range_error(cache, args);
60630
60631 cache->fstop_percent = fstop;
60632 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
60633 if (args[0] != '%' || args[1] != '\0')
60634 return -EINVAL;
60635
60636 - if (bstop < 0 || bstop >= cache->bcull_percent)
60637 + if (bstop >= cache->bcull_percent)
60638 return cachefiles_daemon_range_error(cache, args);
60639
60640 cache->bstop_percent = bstop;
60641 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
60642 index 3d50998..0550d67 100644
60643 --- a/fs/cachefiles/internal.h
60644 +++ b/fs/cachefiles/internal.h
60645 @@ -66,7 +66,7 @@ struct cachefiles_cache {
60646 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
60647 struct rb_root active_nodes; /* active nodes (can't be culled) */
60648 rwlock_t active_lock; /* lock for active_nodes */
60649 - atomic_t gravecounter; /* graveyard uniquifier */
60650 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
60651 unsigned frun_percent; /* when to stop culling (% files) */
60652 unsigned fcull_percent; /* when to start culling (% files) */
60653 unsigned fstop_percent; /* when to stop allocating (% files) */
60654 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
60655 * proc.c
60656 */
60657 #ifdef CONFIG_CACHEFILES_HISTOGRAM
60658 -extern atomic_t cachefiles_lookup_histogram[HZ];
60659 -extern atomic_t cachefiles_mkdir_histogram[HZ];
60660 -extern atomic_t cachefiles_create_histogram[HZ];
60661 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60662 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60663 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
60664
60665 extern int __init cachefiles_proc_init(void);
60666 extern void cachefiles_proc_cleanup(void);
60667 static inline
60668 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
60669 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
60670 {
60671 unsigned long jif = jiffies - start_jif;
60672 if (jif >= HZ)
60673 jif = HZ - 1;
60674 - atomic_inc(&histogram[jif]);
60675 + atomic_inc_unchecked(&histogram[jif]);
60676 }
60677
60678 #else
60679 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
60680 index 5bf2b41..85b93f9 100644
60681 --- a/fs/cachefiles/namei.c
60682 +++ b/fs/cachefiles/namei.c
60683 @@ -312,7 +312,7 @@ try_again:
60684 /* first step is to make up a grave dentry in the graveyard */
60685 sprintf(nbuffer, "%08x%08x",
60686 (uint32_t) get_seconds(),
60687 - (uint32_t) atomic_inc_return(&cache->gravecounter));
60688 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
60689
60690 /* do the multiway lock magic */
60691 trap = lock_rename(cache->graveyard, dir);
60692 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
60693 index eccd339..4c1d995 100644
60694 --- a/fs/cachefiles/proc.c
60695 +++ b/fs/cachefiles/proc.c
60696 @@ -14,9 +14,9 @@
60697 #include <linux/seq_file.h>
60698 #include "internal.h"
60699
60700 -atomic_t cachefiles_lookup_histogram[HZ];
60701 -atomic_t cachefiles_mkdir_histogram[HZ];
60702 -atomic_t cachefiles_create_histogram[HZ];
60703 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60704 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60705 +atomic_unchecked_t cachefiles_create_histogram[HZ];
60706
60707 /*
60708 * display the latency histogram
60709 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
60710 return 0;
60711 default:
60712 index = (unsigned long) v - 3;
60713 - x = atomic_read(&cachefiles_lookup_histogram[index]);
60714 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
60715 - z = atomic_read(&cachefiles_create_histogram[index]);
60716 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
60717 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
60718 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
60719 if (x == 0 && y == 0 && z == 0)
60720 return 0;
60721
60722 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
60723 index 4b1fb5c..0d2a699 100644
60724 --- a/fs/cachefiles/rdwr.c
60725 +++ b/fs/cachefiles/rdwr.c
60726 @@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
60727 old_fs = get_fs();
60728 set_fs(KERNEL_DS);
60729 ret = file->f_op->write(
60730 - file, (const void __user *) data, len, &pos);
60731 + file, (const void __force_user *) data, len, &pos);
60732 set_fs(old_fs);
60733 kunmap(page);
60734 file_end_write(file);
60735 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
60736 index c29d6ae..719b9bb 100644
60737 --- a/fs/ceph/dir.c
60738 +++ b/fs/ceph/dir.c
60739 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
60740 struct dentry *dentry, *last;
60741 struct ceph_dentry_info *di;
60742 int err = 0;
60743 + char d_name[DNAME_INLINE_LEN];
60744 + const unsigned char *name;
60745
60746 /* claim ref on last dentry we returned */
60747 last = fi->dentry;
60748 @@ -192,7 +194,12 @@ more:
60749
60750 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
60751 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
60752 - if (!dir_emit(ctx, dentry->d_name.name,
60753 + name = dentry->d_name.name;
60754 + if (name == dentry->d_iname) {
60755 + memcpy(d_name, name, dentry->d_name.len);
60756 + name = d_name;
60757 + }
60758 + if (!dir_emit(ctx, name,
60759 dentry->d_name.len,
60760 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
60761 dentry->d_inode->i_mode >> 12)) {
60762 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
60763 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
60764 struct ceph_mds_client *mdsc = fsc->mdsc;
60765 unsigned frag = fpos_frag(ctx->pos);
60766 - int off = fpos_off(ctx->pos);
60767 + unsigned int off = fpos_off(ctx->pos);
60768 int err;
60769 u32 ftype;
60770 struct ceph_mds_reply_info_parsed *rinfo;
60771 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
60772 index 06150fd..192061b 100644
60773 --- a/fs/ceph/super.c
60774 +++ b/fs/ceph/super.c
60775 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
60776 /*
60777 * construct our own bdi so we can control readahead, etc.
60778 */
60779 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
60780 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
60781
60782 static int ceph_register_bdi(struct super_block *sb,
60783 struct ceph_fs_client *fsc)
60784 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
60785 default_backing_dev_info.ra_pages;
60786
60787 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
60788 - atomic_long_inc_return(&bdi_seq));
60789 + atomic_long_inc_return_unchecked(&bdi_seq));
60790 if (!err)
60791 sb->s_bdi = &fsc->backing_dev_info;
60792 return err;
60793 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
60794 index f3ac415..3d2420c 100644
60795 --- a/fs/cifs/cifs_debug.c
60796 +++ b/fs/cifs/cifs_debug.c
60797 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60798
60799 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
60800 #ifdef CONFIG_CIFS_STATS2
60801 - atomic_set(&totBufAllocCount, 0);
60802 - atomic_set(&totSmBufAllocCount, 0);
60803 + atomic_set_unchecked(&totBufAllocCount, 0);
60804 + atomic_set_unchecked(&totSmBufAllocCount, 0);
60805 #endif /* CONFIG_CIFS_STATS2 */
60806 spin_lock(&cifs_tcp_ses_lock);
60807 list_for_each(tmp1, &cifs_tcp_ses_list) {
60808 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60809 tcon = list_entry(tmp3,
60810 struct cifs_tcon,
60811 tcon_list);
60812 - atomic_set(&tcon->num_smbs_sent, 0);
60813 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
60814 if (server->ops->clear_stats)
60815 server->ops->clear_stats(tcon);
60816 }
60817 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60818 smBufAllocCount.counter, cifs_min_small);
60819 #ifdef CONFIG_CIFS_STATS2
60820 seq_printf(m, "Total Large %d Small %d Allocations\n",
60821 - atomic_read(&totBufAllocCount),
60822 - atomic_read(&totSmBufAllocCount));
60823 + atomic_read_unchecked(&totBufAllocCount),
60824 + atomic_read_unchecked(&totSmBufAllocCount));
60825 #endif /* CONFIG_CIFS_STATS2 */
60826
60827 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
60828 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60829 if (tcon->need_reconnect)
60830 seq_puts(m, "\tDISCONNECTED ");
60831 seq_printf(m, "\nSMBs: %d",
60832 - atomic_read(&tcon->num_smbs_sent));
60833 + atomic_read_unchecked(&tcon->num_smbs_sent));
60834 if (server->ops->print_stats)
60835 server->ops->print_stats(m, tcon);
60836 }
60837 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
60838 index 8883980..c8ade72 100644
60839 --- a/fs/cifs/cifsfs.c
60840 +++ b/fs/cifs/cifsfs.c
60841 @@ -1072,7 +1072,7 @@ cifs_init_request_bufs(void)
60842 */
60843 cifs_req_cachep = kmem_cache_create("cifs_request",
60844 CIFSMaxBufSize + max_hdr_size, 0,
60845 - SLAB_HWCACHE_ALIGN, NULL);
60846 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
60847 if (cifs_req_cachep == NULL)
60848 return -ENOMEM;
60849
60850 @@ -1099,7 +1099,7 @@ cifs_init_request_bufs(void)
60851 efficient to alloc 1 per page off the slab compared to 17K (5page)
60852 alloc of large cifs buffers even when page debugging is on */
60853 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
60854 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
60855 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
60856 NULL);
60857 if (cifs_sm_req_cachep == NULL) {
60858 mempool_destroy(cifs_req_poolp);
60859 @@ -1184,8 +1184,8 @@ init_cifs(void)
60860 atomic_set(&bufAllocCount, 0);
60861 atomic_set(&smBufAllocCount, 0);
60862 #ifdef CONFIG_CIFS_STATS2
60863 - atomic_set(&totBufAllocCount, 0);
60864 - atomic_set(&totSmBufAllocCount, 0);
60865 + atomic_set_unchecked(&totBufAllocCount, 0);
60866 + atomic_set_unchecked(&totSmBufAllocCount, 0);
60867 #endif /* CONFIG_CIFS_STATS2 */
60868
60869 atomic_set(&midCount, 0);
60870 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
60871 index de6aed8..a0a76fd 100644
60872 --- a/fs/cifs/cifsglob.h
60873 +++ b/fs/cifs/cifsglob.h
60874 @@ -807,35 +807,35 @@ struct cifs_tcon {
60875 __u16 Flags; /* optional support bits */
60876 enum statusEnum tidStatus;
60877 #ifdef CONFIG_CIFS_STATS
60878 - atomic_t num_smbs_sent;
60879 + atomic_unchecked_t num_smbs_sent;
60880 union {
60881 struct {
60882 - atomic_t num_writes;
60883 - atomic_t num_reads;
60884 - atomic_t num_flushes;
60885 - atomic_t num_oplock_brks;
60886 - atomic_t num_opens;
60887 - atomic_t num_closes;
60888 - atomic_t num_deletes;
60889 - atomic_t num_mkdirs;
60890 - atomic_t num_posixopens;
60891 - atomic_t num_posixmkdirs;
60892 - atomic_t num_rmdirs;
60893 - atomic_t num_renames;
60894 - atomic_t num_t2renames;
60895 - atomic_t num_ffirst;
60896 - atomic_t num_fnext;
60897 - atomic_t num_fclose;
60898 - atomic_t num_hardlinks;
60899 - atomic_t num_symlinks;
60900 - atomic_t num_locks;
60901 - atomic_t num_acl_get;
60902 - atomic_t num_acl_set;
60903 + atomic_unchecked_t num_writes;
60904 + atomic_unchecked_t num_reads;
60905 + atomic_unchecked_t num_flushes;
60906 + atomic_unchecked_t num_oplock_brks;
60907 + atomic_unchecked_t num_opens;
60908 + atomic_unchecked_t num_closes;
60909 + atomic_unchecked_t num_deletes;
60910 + atomic_unchecked_t num_mkdirs;
60911 + atomic_unchecked_t num_posixopens;
60912 + atomic_unchecked_t num_posixmkdirs;
60913 + atomic_unchecked_t num_rmdirs;
60914 + atomic_unchecked_t num_renames;
60915 + atomic_unchecked_t num_t2renames;
60916 + atomic_unchecked_t num_ffirst;
60917 + atomic_unchecked_t num_fnext;
60918 + atomic_unchecked_t num_fclose;
60919 + atomic_unchecked_t num_hardlinks;
60920 + atomic_unchecked_t num_symlinks;
60921 + atomic_unchecked_t num_locks;
60922 + atomic_unchecked_t num_acl_get;
60923 + atomic_unchecked_t num_acl_set;
60924 } cifs_stats;
60925 #ifdef CONFIG_CIFS_SMB2
60926 struct {
60927 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60928 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60929 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60930 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60931 } smb2_stats;
60932 #endif /* CONFIG_CIFS_SMB2 */
60933 } stats;
60934 @@ -1172,7 +1172,7 @@ convert_delimiter(char *path, char delim)
60935 }
60936
60937 #ifdef CONFIG_CIFS_STATS
60938 -#define cifs_stats_inc atomic_inc
60939 +#define cifs_stats_inc atomic_inc_unchecked
60940
60941 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60942 unsigned int bytes)
60943 @@ -1538,8 +1538,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60944 /* Various Debug counters */
60945 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60946 #ifdef CONFIG_CIFS_STATS2
60947 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60948 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60949 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60950 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60951 #endif
60952 GLOBAL_EXTERN atomic_t smBufAllocCount;
60953 GLOBAL_EXTERN atomic_t midCount;
60954 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60955 index e90a1e9..908699d 100644
60956 --- a/fs/cifs/file.c
60957 +++ b/fs/cifs/file.c
60958 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
60959 index = mapping->writeback_index; /* Start from prev offset */
60960 end = -1;
60961 } else {
60962 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
60963 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
60964 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60965 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60966 range_whole = true;
60967 + index = 0;
60968 + end = ULONG_MAX;
60969 + } else {
60970 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
60971 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
60972 + }
60973 scanned = true;
60974 }
60975 retry:
60976 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60977 index 3b0c62e..f7d090c 100644
60978 --- a/fs/cifs/misc.c
60979 +++ b/fs/cifs/misc.c
60980 @@ -170,7 +170,7 @@ cifs_buf_get(void)
60981 memset(ret_buf, 0, buf_size + 3);
60982 atomic_inc(&bufAllocCount);
60983 #ifdef CONFIG_CIFS_STATS2
60984 - atomic_inc(&totBufAllocCount);
60985 + atomic_inc_unchecked(&totBufAllocCount);
60986 #endif /* CONFIG_CIFS_STATS2 */
60987 }
60988
60989 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60990 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60991 atomic_inc(&smBufAllocCount);
60992 #ifdef CONFIG_CIFS_STATS2
60993 - atomic_inc(&totSmBufAllocCount);
60994 + atomic_inc_unchecked(&totSmBufAllocCount);
60995 #endif /* CONFIG_CIFS_STATS2 */
60996
60997 }
60998 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60999 index d1fdfa8..94558f8 100644
61000 --- a/fs/cifs/smb1ops.c
61001 +++ b/fs/cifs/smb1ops.c
61002 @@ -626,27 +626,27 @@ static void
61003 cifs_clear_stats(struct cifs_tcon *tcon)
61004 {
61005 #ifdef CONFIG_CIFS_STATS
61006 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
61007 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
61008 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
61009 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
61010 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
61011 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
61012 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
61013 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
61014 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
61015 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
61016 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
61017 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
61018 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
61019 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
61020 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
61021 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
61022 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
61023 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
61024 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
61025 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
61026 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
61027 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
61028 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
61029 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
61030 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
61031 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
61032 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
61033 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
61034 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
61035 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
61036 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
61037 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
61038 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
61039 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
61040 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
61041 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
61042 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
61043 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
61044 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
61045 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
61046 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
61047 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
61048 #endif
61049 }
61050
61051 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
61052 {
61053 #ifdef CONFIG_CIFS_STATS
61054 seq_printf(m, " Oplocks breaks: %d",
61055 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
61056 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
61057 seq_printf(m, "\nReads: %d Bytes: %llu",
61058 - atomic_read(&tcon->stats.cifs_stats.num_reads),
61059 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
61060 (long long)(tcon->bytes_read));
61061 seq_printf(m, "\nWrites: %d Bytes: %llu",
61062 - atomic_read(&tcon->stats.cifs_stats.num_writes),
61063 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
61064 (long long)(tcon->bytes_written));
61065 seq_printf(m, "\nFlushes: %d",
61066 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
61067 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
61068 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
61069 - atomic_read(&tcon->stats.cifs_stats.num_locks),
61070 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
61071 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
61072 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
61073 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
61074 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
61075 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
61076 - atomic_read(&tcon->stats.cifs_stats.num_opens),
61077 - atomic_read(&tcon->stats.cifs_stats.num_closes),
61078 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
61079 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
61080 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
61081 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
61082 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
61083 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
61084 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
61085 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
61086 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
61087 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
61088 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
61089 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
61090 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
61091 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
61092 seq_printf(m, "\nRenames: %d T2 Renames %d",
61093 - atomic_read(&tcon->stats.cifs_stats.num_renames),
61094 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
61095 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
61096 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
61097 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
61098 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
61099 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
61100 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
61101 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
61102 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
61103 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
61104 #endif
61105 }
61106
61107 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
61108 index 787844b..8e7bc7d 100644
61109 --- a/fs/cifs/smb2ops.c
61110 +++ b/fs/cifs/smb2ops.c
61111 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
61112 #ifdef CONFIG_CIFS_STATS
61113 int i;
61114 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
61115 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
61116 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
61117 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
61118 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
61119 }
61120 #endif
61121 }
61122 @@ -405,65 +405,65 @@ static void
61123 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
61124 {
61125 #ifdef CONFIG_CIFS_STATS
61126 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
61127 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
61128 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
61129 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
61130 seq_printf(m, "\nNegotiates: %d sent %d failed",
61131 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
61132 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
61133 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
61134 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
61135 seq_printf(m, "\nSessionSetups: %d sent %d failed",
61136 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
61137 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
61138 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
61139 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
61140 seq_printf(m, "\nLogoffs: %d sent %d failed",
61141 - atomic_read(&sent[SMB2_LOGOFF_HE]),
61142 - atomic_read(&failed[SMB2_LOGOFF_HE]));
61143 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
61144 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
61145 seq_printf(m, "\nTreeConnects: %d sent %d failed",
61146 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
61147 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
61148 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
61149 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
61150 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
61151 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
61152 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
61153 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
61154 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
61155 seq_printf(m, "\nCreates: %d sent %d failed",
61156 - atomic_read(&sent[SMB2_CREATE_HE]),
61157 - atomic_read(&failed[SMB2_CREATE_HE]));
61158 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
61159 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
61160 seq_printf(m, "\nCloses: %d sent %d failed",
61161 - atomic_read(&sent[SMB2_CLOSE_HE]),
61162 - atomic_read(&failed[SMB2_CLOSE_HE]));
61163 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
61164 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
61165 seq_printf(m, "\nFlushes: %d sent %d failed",
61166 - atomic_read(&sent[SMB2_FLUSH_HE]),
61167 - atomic_read(&failed[SMB2_FLUSH_HE]));
61168 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
61169 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
61170 seq_printf(m, "\nReads: %d sent %d failed",
61171 - atomic_read(&sent[SMB2_READ_HE]),
61172 - atomic_read(&failed[SMB2_READ_HE]));
61173 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
61174 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
61175 seq_printf(m, "\nWrites: %d sent %d failed",
61176 - atomic_read(&sent[SMB2_WRITE_HE]),
61177 - atomic_read(&failed[SMB2_WRITE_HE]));
61178 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
61179 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
61180 seq_printf(m, "\nLocks: %d sent %d failed",
61181 - atomic_read(&sent[SMB2_LOCK_HE]),
61182 - atomic_read(&failed[SMB2_LOCK_HE]));
61183 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
61184 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
61185 seq_printf(m, "\nIOCTLs: %d sent %d failed",
61186 - atomic_read(&sent[SMB2_IOCTL_HE]),
61187 - atomic_read(&failed[SMB2_IOCTL_HE]));
61188 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
61189 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
61190 seq_printf(m, "\nCancels: %d sent %d failed",
61191 - atomic_read(&sent[SMB2_CANCEL_HE]),
61192 - atomic_read(&failed[SMB2_CANCEL_HE]));
61193 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
61194 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
61195 seq_printf(m, "\nEchos: %d sent %d failed",
61196 - atomic_read(&sent[SMB2_ECHO_HE]),
61197 - atomic_read(&failed[SMB2_ECHO_HE]));
61198 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
61199 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
61200 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
61201 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
61202 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
61203 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
61204 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
61205 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
61206 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
61207 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
61208 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
61209 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
61210 seq_printf(m, "\nQueryInfos: %d sent %d failed",
61211 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
61212 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
61213 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
61214 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
61215 seq_printf(m, "\nSetInfos: %d sent %d failed",
61216 - atomic_read(&sent[SMB2_SET_INFO_HE]),
61217 - atomic_read(&failed[SMB2_SET_INFO_HE]));
61218 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
61219 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
61220 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
61221 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
61222 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
61223 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
61224 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
61225 #endif
61226 }
61227
61228 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
61229 index b0b260d..c8927e1 100644
61230 --- a/fs/cifs/smb2pdu.c
61231 +++ b/fs/cifs/smb2pdu.c
61232 @@ -2105,8 +2105,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
61233 default:
61234 cifs_dbg(VFS, "info level %u isn't supported\n",
61235 srch_inf->info_level);
61236 - rc = -EINVAL;
61237 - goto qdir_exit;
61238 + return -EINVAL;
61239 }
61240
61241 req->FileIndex = cpu_to_le32(index);
61242 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
61243 index 1da168c..8bc7ff6 100644
61244 --- a/fs/coda/cache.c
61245 +++ b/fs/coda/cache.c
61246 @@ -24,7 +24,7 @@
61247 #include "coda_linux.h"
61248 #include "coda_cache.h"
61249
61250 -static atomic_t permission_epoch = ATOMIC_INIT(0);
61251 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
61252
61253 /* replace or extend an acl cache hit */
61254 void coda_cache_enter(struct inode *inode, int mask)
61255 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
61256 struct coda_inode_info *cii = ITOC(inode);
61257
61258 spin_lock(&cii->c_lock);
61259 - cii->c_cached_epoch = atomic_read(&permission_epoch);
61260 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
61261 if (!uid_eq(cii->c_uid, current_fsuid())) {
61262 cii->c_uid = current_fsuid();
61263 cii->c_cached_perm = mask;
61264 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
61265 {
61266 struct coda_inode_info *cii = ITOC(inode);
61267 spin_lock(&cii->c_lock);
61268 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
61269 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
61270 spin_unlock(&cii->c_lock);
61271 }
61272
61273 /* remove all acl caches */
61274 void coda_cache_clear_all(struct super_block *sb)
61275 {
61276 - atomic_inc(&permission_epoch);
61277 + atomic_inc_unchecked(&permission_epoch);
61278 }
61279
61280
61281 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
61282 spin_lock(&cii->c_lock);
61283 hit = (mask & cii->c_cached_perm) == mask &&
61284 uid_eq(cii->c_uid, current_fsuid()) &&
61285 - cii->c_cached_epoch == atomic_read(&permission_epoch);
61286 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
61287 spin_unlock(&cii->c_lock);
61288
61289 return hit;
61290 diff --git a/fs/compat.c b/fs/compat.c
61291 index 66d3d3c..9c10175 100644
61292 --- a/fs/compat.c
61293 +++ b/fs/compat.c
61294 @@ -54,7 +54,7 @@
61295 #include <asm/ioctls.h>
61296 #include "internal.h"
61297
61298 -int compat_log = 1;
61299 +int compat_log = 0;
61300
61301 int compat_printk(const char *fmt, ...)
61302 {
61303 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
61304
61305 set_fs(KERNEL_DS);
61306 /* The __user pointer cast is valid because of the set_fs() */
61307 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
61308 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
61309 set_fs(oldfs);
61310 /* truncating is ok because it's a user address */
61311 if (!ret)
61312 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
61313 goto out;
61314
61315 ret = -EINVAL;
61316 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
61317 + if (nr_segs > UIO_MAXIOV)
61318 goto out;
61319 if (nr_segs > fast_segs) {
61320 ret = -ENOMEM;
61321 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
61322 struct compat_readdir_callback {
61323 struct dir_context ctx;
61324 struct compat_old_linux_dirent __user *dirent;
61325 + struct file * file;
61326 int result;
61327 };
61328
61329 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
61330 buf->result = -EOVERFLOW;
61331 return -EOVERFLOW;
61332 }
61333 +
61334 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61335 + return 0;
61336 +
61337 buf->result++;
61338 dirent = buf->dirent;
61339 if (!access_ok(VERIFY_WRITE, dirent,
61340 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
61341 if (!f.file)
61342 return -EBADF;
61343
61344 + buf.file = f.file;
61345 error = iterate_dir(f.file, &buf.ctx);
61346 if (buf.result)
61347 error = buf.result;
61348 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
61349 struct dir_context ctx;
61350 struct compat_linux_dirent __user *current_dir;
61351 struct compat_linux_dirent __user *previous;
61352 + struct file * file;
61353 int count;
61354 int error;
61355 };
61356 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
61357 buf->error = -EOVERFLOW;
61358 return -EOVERFLOW;
61359 }
61360 +
61361 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61362 + return 0;
61363 +
61364 dirent = buf->previous;
61365 if (dirent) {
61366 if (__put_user(offset, &dirent->d_off))
61367 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
61368 if (!f.file)
61369 return -EBADF;
61370
61371 + buf.file = f.file;
61372 error = iterate_dir(f.file, &buf.ctx);
61373 if (error >= 0)
61374 error = buf.error;
61375 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
61376 struct dir_context ctx;
61377 struct linux_dirent64 __user *current_dir;
61378 struct linux_dirent64 __user *previous;
61379 + struct file * file;
61380 int count;
61381 int error;
61382 };
61383 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
61384 buf->error = -EINVAL; /* only used if we fail.. */
61385 if (reclen > buf->count)
61386 return -EINVAL;
61387 +
61388 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61389 + return 0;
61390 +
61391 dirent = buf->previous;
61392
61393 if (dirent) {
61394 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
61395 if (!f.file)
61396 return -EBADF;
61397
61398 + buf.file = f.file;
61399 error = iterate_dir(f.file, &buf.ctx);
61400 if (error >= 0)
61401 error = buf.error;
61402 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
61403 index 4d24d17..4f8c09e 100644
61404 --- a/fs/compat_binfmt_elf.c
61405 +++ b/fs/compat_binfmt_elf.c
61406 @@ -30,11 +30,13 @@
61407 #undef elf_phdr
61408 #undef elf_shdr
61409 #undef elf_note
61410 +#undef elf_dyn
61411 #undef elf_addr_t
61412 #define elfhdr elf32_hdr
61413 #define elf_phdr elf32_phdr
61414 #define elf_shdr elf32_shdr
61415 #define elf_note elf32_note
61416 +#define elf_dyn Elf32_Dyn
61417 #define elf_addr_t Elf32_Addr
61418
61419 /*
61420 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
61421 index e822890..fed89d9 100644
61422 --- a/fs/compat_ioctl.c
61423 +++ b/fs/compat_ioctl.c
61424 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
61425 return -EFAULT;
61426 if (__get_user(udata, &ss32->iomem_base))
61427 return -EFAULT;
61428 - ss.iomem_base = compat_ptr(udata);
61429 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
61430 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
61431 __get_user(ss.port_high, &ss32->port_high))
61432 return -EFAULT;
61433 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
61434 for (i = 0; i < nmsgs; i++) {
61435 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
61436 return -EFAULT;
61437 - if (get_user(datap, &umsgs[i].buf) ||
61438 - put_user(compat_ptr(datap), &tmsgs[i].buf))
61439 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
61440 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
61441 return -EFAULT;
61442 }
61443 return sys_ioctl(fd, cmd, (unsigned long)tdata);
61444 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
61445 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
61446 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
61447 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
61448 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
61449 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
61450 return -EFAULT;
61451
61452 return ioctl_preallocate(file, p);
61453 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
61454 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
61455 {
61456 unsigned int a, b;
61457 - a = *(unsigned int *)p;
61458 - b = *(unsigned int *)q;
61459 + a = *(const unsigned int *)p;
61460 + b = *(const unsigned int *)q;
61461 if (a > b)
61462 return 1;
61463 if (a < b)
61464 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
61465 index 668dcab..daebcd6 100644
61466 --- a/fs/configfs/dir.c
61467 +++ b/fs/configfs/dir.c
61468 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
61469 }
61470 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
61471 struct configfs_dirent *next;
61472 - const char *name;
61473 + const unsigned char * name;
61474 + char d_name[sizeof(next->s_dentry->d_iname)];
61475 int len;
61476 struct inode *inode = NULL;
61477
61478 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
61479 continue;
61480
61481 name = configfs_get_name(next);
61482 - len = strlen(name);
61483 + if (next->s_dentry && name == next->s_dentry->d_iname) {
61484 + len = next->s_dentry->d_name.len;
61485 + memcpy(d_name, name, len);
61486 + name = d_name;
61487 + } else
61488 + len = strlen(name);
61489
61490 /*
61491 * We'll have a dentry and an inode for
61492 diff --git a/fs/coredump.c b/fs/coredump.c
61493 index a93f7e6..d58bcbe 100644
61494 --- a/fs/coredump.c
61495 +++ b/fs/coredump.c
61496 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
61497 struct pipe_inode_info *pipe = file->private_data;
61498
61499 pipe_lock(pipe);
61500 - pipe->readers++;
61501 - pipe->writers--;
61502 + atomic_inc(&pipe->readers);
61503 + atomic_dec(&pipe->writers);
61504 wake_up_interruptible_sync(&pipe->wait);
61505 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61506 pipe_unlock(pipe);
61507 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
61508 * We actually want wait_event_freezable() but then we need
61509 * to clear TIF_SIGPENDING and improve dump_interrupted().
61510 */
61511 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
61512 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
61513
61514 pipe_lock(pipe);
61515 - pipe->readers--;
61516 - pipe->writers++;
61517 + atomic_dec(&pipe->readers);
61518 + atomic_inc(&pipe->writers);
61519 pipe_unlock(pipe);
61520 }
61521
61522 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
61523 struct files_struct *displaced;
61524 bool need_nonrelative = false;
61525 bool core_dumped = false;
61526 - static atomic_t core_dump_count = ATOMIC_INIT(0);
61527 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
61528 + long signr = siginfo->si_signo;
61529 + int dumpable;
61530 struct coredump_params cprm = {
61531 .siginfo = siginfo,
61532 .regs = signal_pt_regs(),
61533 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
61534 .mm_flags = mm->flags,
61535 };
61536
61537 - audit_core_dumps(siginfo->si_signo);
61538 + audit_core_dumps(signr);
61539 +
61540 + dumpable = __get_dumpable(cprm.mm_flags);
61541 +
61542 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
61543 + gr_handle_brute_attach(dumpable);
61544
61545 binfmt = mm->binfmt;
61546 if (!binfmt || !binfmt->core_dump)
61547 goto fail;
61548 - if (!__get_dumpable(cprm.mm_flags))
61549 + if (!dumpable)
61550 goto fail;
61551
61552 cred = prepare_creds();
61553 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
61554 need_nonrelative = true;
61555 }
61556
61557 - retval = coredump_wait(siginfo->si_signo, &core_state);
61558 + retval = coredump_wait(signr, &core_state);
61559 if (retval < 0)
61560 goto fail_creds;
61561
61562 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
61563 }
61564 cprm.limit = RLIM_INFINITY;
61565
61566 - dump_count = atomic_inc_return(&core_dump_count);
61567 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
61568 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
61569 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
61570 task_tgid_vnr(current), current->comm);
61571 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
61572 } else {
61573 struct inode *inode;
61574
61575 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
61576 +
61577 if (cprm.limit < binfmt->min_coredump)
61578 goto fail_unlock;
61579
61580 @@ -673,7 +682,7 @@ close_fail:
61581 filp_close(cprm.file, NULL);
61582 fail_dropcount:
61583 if (ispipe)
61584 - atomic_dec(&core_dump_count);
61585 + atomic_dec_unchecked(&core_dump_count);
61586 fail_unlock:
61587 kfree(cn.corename);
61588 coredump_finish(mm, core_dumped);
61589 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
61590 struct file *file = cprm->file;
61591 loff_t pos = file->f_pos;
61592 ssize_t n;
61593 +
61594 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
61595 if (cprm->written + nr > cprm->limit)
61596 return 0;
61597 while (nr) {
61598 diff --git a/fs/dcache.c b/fs/dcache.c
61599 index 06f6585..f95a6d1 100644
61600 --- a/fs/dcache.c
61601 +++ b/fs/dcache.c
61602 @@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
61603 */
61604 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
61605 if (name->len > DNAME_INLINE_LEN-1) {
61606 - dname = kmalloc(name->len + 1, GFP_KERNEL);
61607 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
61608 if (!dname) {
61609 kmem_cache_free(dentry_cache, dentry);
61610 return NULL;
61611 @@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
61612 mempages -= reserve;
61613
61614 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
61615 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
61616 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
61617 + SLAB_NO_SANITIZE, NULL);
61618
61619 dcache_init();
61620 inode_init();
61621 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
61622 index 16a46b6..41696fd 100644
61623 --- a/fs/debugfs/inode.c
61624 +++ b/fs/debugfs/inode.c
61625 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
61626 */
61627 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
61628 {
61629 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
61630 + return __create_file(name, S_IFDIR | S_IRWXU,
61631 +#else
61632 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
61633 +#endif
61634 parent, NULL, NULL);
61635 }
61636 EXPORT_SYMBOL_GPL(debugfs_create_dir);
61637 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
61638 index d4a9431..77f9b2e 100644
61639 --- a/fs/ecryptfs/inode.c
61640 +++ b/fs/ecryptfs/inode.c
61641 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
61642 old_fs = get_fs();
61643 set_fs(get_ds());
61644 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
61645 - (char __user *)lower_buf,
61646 + (char __force_user *)lower_buf,
61647 PATH_MAX);
61648 set_fs(old_fs);
61649 if (rc < 0)
61650 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
61651 index e4141f2..d8263e8 100644
61652 --- a/fs/ecryptfs/miscdev.c
61653 +++ b/fs/ecryptfs/miscdev.c
61654 @@ -304,7 +304,7 @@ check_list:
61655 goto out_unlock_msg_ctx;
61656 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
61657 if (msg_ctx->msg) {
61658 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
61659 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
61660 goto out_unlock_msg_ctx;
61661 i += packet_length_size;
61662 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
61663 diff --git a/fs/exec.c b/fs/exec.c
61664 index a3d33fe..49e9bc9 100644
61665 --- a/fs/exec.c
61666 +++ b/fs/exec.c
61667 @@ -56,8 +56,20 @@
61668 #include <linux/pipe_fs_i.h>
61669 #include <linux/oom.h>
61670 #include <linux/compat.h>
61671 +#include <linux/random.h>
61672 +#include <linux/seq_file.h>
61673 +#include <linux/coredump.h>
61674 +#include <linux/mman.h>
61675 +
61676 +#ifdef CONFIG_PAX_REFCOUNT
61677 +#include <linux/kallsyms.h>
61678 +#include <linux/kdebug.h>
61679 +#endif
61680 +
61681 +#include <trace/events/fs.h>
61682
61683 #include <asm/uaccess.h>
61684 +#include <asm/sections.h>
61685 #include <asm/mmu_context.h>
61686 #include <asm/tlb.h>
61687
61688 @@ -66,19 +78,34 @@
61689
61690 #include <trace/events/sched.h>
61691
61692 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61693 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
61694 +{
61695 + pr_warn_once("PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
61696 +}
61697 +#endif
61698 +
61699 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
61700 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
61701 +EXPORT_SYMBOL(pax_set_initial_flags_func);
61702 +#endif
61703 +
61704 int suid_dumpable = 0;
61705
61706 static LIST_HEAD(formats);
61707 static DEFINE_RWLOCK(binfmt_lock);
61708
61709 +extern int gr_process_kernel_exec_ban(void);
61710 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61711 +
61712 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61713 {
61714 BUG_ON(!fmt);
61715 if (WARN_ON(!fmt->load_binary))
61716 return;
61717 write_lock(&binfmt_lock);
61718 - insert ? list_add(&fmt->lh, &formats) :
61719 - list_add_tail(&fmt->lh, &formats);
61720 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61721 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61722 write_unlock(&binfmt_lock);
61723 }
61724
61725 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61726 void unregister_binfmt(struct linux_binfmt * fmt)
61727 {
61728 write_lock(&binfmt_lock);
61729 - list_del(&fmt->lh);
61730 + pax_list_del((struct list_head *)&fmt->lh);
61731 write_unlock(&binfmt_lock);
61732 }
61733
61734 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61735 int write)
61736 {
61737 struct page *page;
61738 - int ret;
61739
61740 -#ifdef CONFIG_STACK_GROWSUP
61741 - if (write) {
61742 - ret = expand_downwards(bprm->vma, pos);
61743 - if (ret < 0)
61744 - return NULL;
61745 - }
61746 -#endif
61747 - ret = get_user_pages(current, bprm->mm, pos,
61748 - 1, write, 1, &page, NULL);
61749 - if (ret <= 0)
61750 + if (0 > expand_downwards(bprm->vma, pos))
61751 + return NULL;
61752 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61753 return NULL;
61754
61755 if (write) {
61756 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61757 if (size <= ARG_MAX)
61758 return page;
61759
61760 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61761 + // only allow 512KB for argv+env on suid/sgid binaries
61762 + // to prevent easy ASLR exhaustion
61763 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61764 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
61765 + (size > (512 * 1024))) {
61766 + put_page(page);
61767 + return NULL;
61768 + }
61769 +#endif
61770 +
61771 /*
61772 * Limit to 1/4-th the stack size for the argv+env strings.
61773 * This ensures that:
61774 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61775 vma->vm_end = STACK_TOP_MAX;
61776 vma->vm_start = vma->vm_end - PAGE_SIZE;
61777 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61778 +
61779 +#ifdef CONFIG_PAX_SEGMEXEC
61780 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61781 +#endif
61782 +
61783 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61784 INIT_LIST_HEAD(&vma->anon_vma_chain);
61785
61786 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61787 mm->stack_vm = mm->total_vm = 1;
61788 up_write(&mm->mmap_sem);
61789 bprm->p = vma->vm_end - sizeof(void *);
61790 +
61791 +#ifdef CONFIG_PAX_RANDUSTACK
61792 + if (randomize_va_space)
61793 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
61794 +#endif
61795 +
61796 return 0;
61797 err:
61798 up_write(&mm->mmap_sem);
61799 @@ -399,7 +440,7 @@ struct user_arg_ptr {
61800 } ptr;
61801 };
61802
61803 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61804 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61805 {
61806 const char __user *native;
61807
61808 @@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61809 compat_uptr_t compat;
61810
61811 if (get_user(compat, argv.ptr.compat + nr))
61812 - return ERR_PTR(-EFAULT);
61813 + return (const char __force_user *)ERR_PTR(-EFAULT);
61814
61815 return compat_ptr(compat);
61816 }
61817 #endif
61818
61819 if (get_user(native, argv.ptr.native + nr))
61820 - return ERR_PTR(-EFAULT);
61821 + return (const char __force_user *)ERR_PTR(-EFAULT);
61822
61823 return native;
61824 }
61825 @@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
61826 if (!p)
61827 break;
61828
61829 - if (IS_ERR(p))
61830 + if (IS_ERR((const char __force_kernel *)p))
61831 return -EFAULT;
61832
61833 if (i >= max)
61834 @@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61835
61836 ret = -EFAULT;
61837 str = get_user_arg_ptr(argv, argc);
61838 - if (IS_ERR(str))
61839 + if (IS_ERR((const char __force_kernel *)str))
61840 goto out;
61841
61842 len = strnlen_user(str, MAX_ARG_STRLEN);
61843 @@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61844 int r;
61845 mm_segment_t oldfs = get_fs();
61846 struct user_arg_ptr argv = {
61847 - .ptr.native = (const char __user *const __user *)__argv,
61848 + .ptr.native = (const char __user * const __force_user *)__argv,
61849 };
61850
61851 set_fs(KERNEL_DS);
61852 @@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61853 unsigned long new_end = old_end - shift;
61854 struct mmu_gather tlb;
61855
61856 - BUG_ON(new_start > new_end);
61857 + if (new_start >= new_end || new_start < mmap_min_addr)
61858 + return -ENOMEM;
61859
61860 /*
61861 * ensure there are no vmas between where we want to go
61862 @@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61863 if (vma != find_vma(mm, new_start))
61864 return -EFAULT;
61865
61866 +#ifdef CONFIG_PAX_SEGMEXEC
61867 + BUG_ON(pax_find_mirror_vma(vma));
61868 +#endif
61869 +
61870 /*
61871 * cover the whole range: [new_start, old_end)
61872 */
61873 @@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61874 stack_top = arch_align_stack(stack_top);
61875 stack_top = PAGE_ALIGN(stack_top);
61876
61877 - if (unlikely(stack_top < mmap_min_addr) ||
61878 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61879 - return -ENOMEM;
61880 -
61881 stack_shift = vma->vm_end - stack_top;
61882
61883 bprm->p -= stack_shift;
61884 @@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61885 bprm->exec -= stack_shift;
61886
61887 down_write(&mm->mmap_sem);
61888 +
61889 + /* Move stack pages down in memory. */
61890 + if (stack_shift) {
61891 + ret = shift_arg_pages(vma, stack_shift);
61892 + if (ret)
61893 + goto out_unlock;
61894 + }
61895 +
61896 vm_flags = VM_STACK_FLAGS;
61897
61898 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61899 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
61900 + vm_flags &= ~VM_EXEC;
61901 +
61902 +#ifdef CONFIG_PAX_MPROTECT
61903 + if (mm->pax_flags & MF_PAX_MPROTECT)
61904 + vm_flags &= ~VM_MAYEXEC;
61905 +#endif
61906 +
61907 + }
61908 +#endif
61909 +
61910 /*
61911 * Adjust stack execute permissions; explicitly enable for
61912 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
61913 @@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61914 goto out_unlock;
61915 BUG_ON(prev != vma);
61916
61917 - /* Move stack pages down in memory. */
61918 - if (stack_shift) {
61919 - ret = shift_arg_pages(vma, stack_shift);
61920 - if (ret)
61921 - goto out_unlock;
61922 - }
61923 -
61924 /* mprotect_fixup is overkill to remove the temporary stack flags */
61925 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
61926
61927 @@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
61928 #endif
61929 current->mm->start_stack = bprm->p;
61930 ret = expand_stack(vma, stack_base);
61931 +
61932 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
61933 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
61934 + unsigned long size;
61935 + vm_flags_t vm_flags;
61936 +
61937 + size = STACK_TOP - vma->vm_end;
61938 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
61939 +
61940 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
61941 +
61942 +#ifdef CONFIG_X86
61943 + if (!ret) {
61944 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
61945 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
61946 + }
61947 +#endif
61948 +
61949 + }
61950 +#endif
61951 +
61952 if (ret)
61953 ret = -EFAULT;
61954
61955 @@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
61956
61957 fsnotify_open(file);
61958
61959 + trace_open_exec(name->name);
61960 +
61961 err = deny_write_access(file);
61962 if (err)
61963 goto exit;
61964 @@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
61965 old_fs = get_fs();
61966 set_fs(get_ds());
61967 /* The cast to a user pointer is valid due to the set_fs() */
61968 - result = vfs_read(file, (void __user *)addr, count, &pos);
61969 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
61970 set_fs(old_fs);
61971 return result;
61972 }
61973 @@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
61974 tsk->mm = mm;
61975 tsk->active_mm = mm;
61976 activate_mm(active_mm, mm);
61977 + populate_stack();
61978 tsk->mm->vmacache_seqnum = 0;
61979 vmacache_flush(tsk);
61980 task_unlock(tsk);
61981 @@ -1247,7 +1326,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
61982 }
61983 rcu_read_unlock();
61984
61985 - if (p->fs->users > n_fs)
61986 + if (atomic_read(&p->fs->users) > n_fs)
61987 bprm->unsafe |= LSM_UNSAFE_SHARE;
61988 else
61989 p->fs->in_exec = 1;
61990 @@ -1423,6 +1502,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61991 return ret;
61992 }
61993
61994 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61995 +static DEFINE_PER_CPU(u64, exec_counter);
61996 +static int __init init_exec_counters(void)
61997 +{
61998 + unsigned int cpu;
61999 +
62000 + for_each_possible_cpu(cpu) {
62001 + per_cpu(exec_counter, cpu) = (u64)cpu;
62002 + }
62003 +
62004 + return 0;
62005 +}
62006 +early_initcall(init_exec_counters);
62007 +static inline void increment_exec_counter(void)
62008 +{
62009 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
62010 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
62011 +}
62012 +#else
62013 +static inline void increment_exec_counter(void) {}
62014 +#endif
62015 +
62016 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
62017 + struct user_arg_ptr argv);
62018 +
62019 /*
62020 * sys_execve() executes a new program.
62021 */
62022 @@ -1430,6 +1534,11 @@ static int do_execve_common(struct filename *filename,
62023 struct user_arg_ptr argv,
62024 struct user_arg_ptr envp)
62025 {
62026 +#ifdef CONFIG_GRKERNSEC
62027 + struct file *old_exec_file;
62028 + struct acl_subject_label *old_acl;
62029 + struct rlimit old_rlim[RLIM_NLIMITS];
62030 +#endif
62031 struct linux_binprm *bprm;
62032 struct file *file;
62033 struct files_struct *displaced;
62034 @@ -1438,6 +1547,8 @@ static int do_execve_common(struct filename *filename,
62035 if (IS_ERR(filename))
62036 return PTR_ERR(filename);
62037
62038 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
62039 +
62040 /*
62041 * We move the actual failure in case of RLIMIT_NPROC excess from
62042 * set*uid() to execve() because too many poorly written programs
62043 @@ -1475,11 +1586,21 @@ static int do_execve_common(struct filename *filename,
62044 if (IS_ERR(file))
62045 goto out_unmark;
62046
62047 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
62048 + retval = -EPERM;
62049 + goto out_unmark;
62050 + }
62051 +
62052 sched_exec();
62053
62054 bprm->file = file;
62055 bprm->filename = bprm->interp = filename->name;
62056
62057 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
62058 + retval = -EACCES;
62059 + goto out_unmark;
62060 + }
62061 +
62062 retval = bprm_mm_init(bprm);
62063 if (retval)
62064 goto out_unmark;
62065 @@ -1496,24 +1617,70 @@ static int do_execve_common(struct filename *filename,
62066 if (retval < 0)
62067 goto out;
62068
62069 +#ifdef CONFIG_GRKERNSEC
62070 + old_acl = current->acl;
62071 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
62072 + old_exec_file = current->exec_file;
62073 + get_file(file);
62074 + current->exec_file = file;
62075 +#endif
62076 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62077 + /* limit suid stack to 8MB
62078 + * we saved the old limits above and will restore them if this exec fails
62079 + */
62080 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
62081 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
62082 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
62083 +#endif
62084 +
62085 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
62086 + retval = -EPERM;
62087 + goto out_fail;
62088 + }
62089 +
62090 + if (!gr_tpe_allow(file)) {
62091 + retval = -EACCES;
62092 + goto out_fail;
62093 + }
62094 +
62095 + if (gr_check_crash_exec(file)) {
62096 + retval = -EACCES;
62097 + goto out_fail;
62098 + }
62099 +
62100 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
62101 + bprm->unsafe);
62102 + if (retval < 0)
62103 + goto out_fail;
62104 +
62105 retval = copy_strings_kernel(1, &bprm->filename, bprm);
62106 if (retval < 0)
62107 - goto out;
62108 + goto out_fail;
62109
62110 bprm->exec = bprm->p;
62111 retval = copy_strings(bprm->envc, envp, bprm);
62112 if (retval < 0)
62113 - goto out;
62114 + goto out_fail;
62115
62116 retval = copy_strings(bprm->argc, argv, bprm);
62117 if (retval < 0)
62118 - goto out;
62119 + goto out_fail;
62120 +
62121 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
62122 +
62123 + gr_handle_exec_args(bprm, argv);
62124
62125 retval = exec_binprm(bprm);
62126 if (retval < 0)
62127 - goto out;
62128 + goto out_fail;
62129 +#ifdef CONFIG_GRKERNSEC
62130 + if (old_exec_file)
62131 + fput(old_exec_file);
62132 +#endif
62133
62134 /* execve succeeded */
62135 +
62136 + increment_exec_counter();
62137 current->fs->in_exec = 0;
62138 current->in_execve = 0;
62139 acct_update_integrals(current);
62140 @@ -1524,6 +1691,14 @@ static int do_execve_common(struct filename *filename,
62141 put_files_struct(displaced);
62142 return retval;
62143
62144 +out_fail:
62145 +#ifdef CONFIG_GRKERNSEC
62146 + current->acl = old_acl;
62147 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
62148 + fput(current->exec_file);
62149 + current->exec_file = old_exec_file;
62150 +#endif
62151 +
62152 out:
62153 if (bprm->mm) {
62154 acct_arg_size(bprm, 0);
62155 @@ -1615,3 +1790,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
62156 return compat_do_execve(getname(filename), argv, envp);
62157 }
62158 #endif
62159 +
62160 +int pax_check_flags(unsigned long *flags)
62161 +{
62162 + int retval = 0;
62163 +
62164 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
62165 + if (*flags & MF_PAX_SEGMEXEC)
62166 + {
62167 + *flags &= ~MF_PAX_SEGMEXEC;
62168 + retval = -EINVAL;
62169 + }
62170 +#endif
62171 +
62172 + if ((*flags & MF_PAX_PAGEEXEC)
62173 +
62174 +#ifdef CONFIG_PAX_PAGEEXEC
62175 + && (*flags & MF_PAX_SEGMEXEC)
62176 +#endif
62177 +
62178 + )
62179 + {
62180 + *flags &= ~MF_PAX_PAGEEXEC;
62181 + retval = -EINVAL;
62182 + }
62183 +
62184 + if ((*flags & MF_PAX_MPROTECT)
62185 +
62186 +#ifdef CONFIG_PAX_MPROTECT
62187 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
62188 +#endif
62189 +
62190 + )
62191 + {
62192 + *flags &= ~MF_PAX_MPROTECT;
62193 + retval = -EINVAL;
62194 + }
62195 +
62196 + if ((*flags & MF_PAX_EMUTRAMP)
62197 +
62198 +#ifdef CONFIG_PAX_EMUTRAMP
62199 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
62200 +#endif
62201 +
62202 + )
62203 + {
62204 + *flags &= ~MF_PAX_EMUTRAMP;
62205 + retval = -EINVAL;
62206 + }
62207 +
62208 + return retval;
62209 +}
62210 +
62211 +EXPORT_SYMBOL(pax_check_flags);
62212 +
62213 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
62214 +char *pax_get_path(const struct path *path, char *buf, int buflen)
62215 +{
62216 + char *pathname = d_path(path, buf, buflen);
62217 +
62218 + if (IS_ERR(pathname))
62219 + goto toolong;
62220 +
62221 + pathname = mangle_path(buf, pathname, "\t\n\\");
62222 + if (!pathname)
62223 + goto toolong;
62224 +
62225 + *pathname = 0;
62226 + return buf;
62227 +
62228 +toolong:
62229 + return "<path too long>";
62230 +}
62231 +EXPORT_SYMBOL(pax_get_path);
62232 +
62233 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
62234 +{
62235 + struct task_struct *tsk = current;
62236 + struct mm_struct *mm = current->mm;
62237 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
62238 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
62239 + char *path_exec = NULL;
62240 + char *path_fault = NULL;
62241 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
62242 + siginfo_t info = { };
62243 +
62244 + if (buffer_exec && buffer_fault) {
62245 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
62246 +
62247 + down_read(&mm->mmap_sem);
62248 + vma = mm->mmap;
62249 + while (vma && (!vma_exec || !vma_fault)) {
62250 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
62251 + vma_exec = vma;
62252 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
62253 + vma_fault = vma;
62254 + vma = vma->vm_next;
62255 + }
62256 + if (vma_exec)
62257 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
62258 + if (vma_fault) {
62259 + start = vma_fault->vm_start;
62260 + end = vma_fault->vm_end;
62261 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
62262 + if (vma_fault->vm_file)
62263 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
62264 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
62265 + path_fault = "<heap>";
62266 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
62267 + path_fault = "<stack>";
62268 + else
62269 + path_fault = "<anonymous mapping>";
62270 + }
62271 + up_read(&mm->mmap_sem);
62272 + }
62273 + if (tsk->signal->curr_ip)
62274 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
62275 + else
62276 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
62277 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
62278 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
62279 + free_page((unsigned long)buffer_exec);
62280 + free_page((unsigned long)buffer_fault);
62281 + pax_report_insns(regs, pc, sp);
62282 + info.si_signo = SIGKILL;
62283 + info.si_errno = 0;
62284 + info.si_code = SI_KERNEL;
62285 + info.si_pid = 0;
62286 + info.si_uid = 0;
62287 + do_coredump(&info);
62288 +}
62289 +#endif
62290 +
62291 +#ifdef CONFIG_PAX_REFCOUNT
62292 +void pax_report_refcount_overflow(struct pt_regs *regs)
62293 +{
62294 + if (current->signal->curr_ip)
62295 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
62296 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
62297 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
62298 + else
62299 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
62300 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
62301 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
62302 + preempt_disable();
62303 + show_regs(regs);
62304 + preempt_enable();
62305 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
62306 +}
62307 +#endif
62308 +
62309 +#ifdef CONFIG_PAX_USERCOPY
62310 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
62311 +static noinline int check_stack_object(const void *obj, unsigned long len)
62312 +{
62313 + const void * const stack = task_stack_page(current);
62314 + const void * const stackend = stack + THREAD_SIZE;
62315 +
62316 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
62317 + const void *frame = NULL;
62318 + const void *oldframe;
62319 +#endif
62320 +
62321 + if (obj + len < obj)
62322 + return -1;
62323 +
62324 + if (obj + len <= stack || stackend <= obj)
62325 + return 0;
62326 +
62327 + if (obj < stack || stackend < obj + len)
62328 + return -1;
62329 +
62330 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
62331 + oldframe = __builtin_frame_address(1);
62332 + if (oldframe)
62333 + frame = __builtin_frame_address(2);
62334 + /*
62335 + low ----------------------------------------------> high
62336 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
62337 + ^----------------^
62338 + allow copies only within here
62339 + */
62340 + while (stack <= frame && frame < stackend) {
62341 + /* if obj + len extends past the last frame, this
62342 + check won't pass and the next frame will be 0,
62343 + causing us to bail out and correctly report
62344 + the copy as invalid
62345 + */
62346 + if (obj + len <= frame)
62347 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
62348 + oldframe = frame;
62349 + frame = *(const void * const *)frame;
62350 + }
62351 + return -1;
62352 +#else
62353 + return 1;
62354 +#endif
62355 +}
62356 +
62357 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
62358 +{
62359 + if (current->signal->curr_ip)
62360 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
62361 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
62362 + else
62363 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
62364 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
62365 + dump_stack();
62366 + gr_handle_kernel_exploit();
62367 + do_group_exit(SIGKILL);
62368 +}
62369 +#endif
62370 +
62371 +#ifdef CONFIG_PAX_USERCOPY
62372 +
62373 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
62374 +{
62375 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
62376 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
62377 +#ifdef CONFIG_MODULES
62378 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
62379 +#else
62380 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
62381 +#endif
62382 +
62383 +#else
62384 + unsigned long textlow = (unsigned long)_stext;
62385 + unsigned long texthigh = (unsigned long)_etext;
62386 +
62387 +#ifdef CONFIG_X86_64
62388 + /* check against linear mapping as well */
62389 + if (high > (unsigned long)__va(__pa(textlow)) &&
62390 + low < (unsigned long)__va(__pa(texthigh)))
62391 + return true;
62392 +#endif
62393 +
62394 +#endif
62395 +
62396 + if (high <= textlow || low >= texthigh)
62397 + return false;
62398 + else
62399 + return true;
62400 +}
62401 +#endif
62402 +
62403 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
62404 +{
62405 +#ifdef CONFIG_PAX_USERCOPY
62406 + const char *type;
62407 +#endif
62408 +
62409 +#ifndef CONFIG_STACK_GROWSUP
62410 + unsigned long stackstart = (unsigned long)task_stack_page(current);
62411 + unsigned long currentsp = (unsigned long)&stackstart;
62412 + if (unlikely((currentsp < stackstart + 512 ||
62413 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
62414 + BUG();
62415 +#endif
62416 +
62417 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
62418 + if (const_size)
62419 + return;
62420 +#endif
62421 +
62422 +#ifdef CONFIG_PAX_USERCOPY
62423 + if (!n)
62424 + return;
62425 +
62426 + type = check_heap_object(ptr, n);
62427 + if (!type) {
62428 + int ret = check_stack_object(ptr, n);
62429 + if (ret == 1 || ret == 2)
62430 + return;
62431 + if (ret == 0) {
62432 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
62433 + type = "<kernel text>";
62434 + else
62435 + return;
62436 + } else
62437 + type = "<process stack>";
62438 + }
62439 +
62440 + pax_report_usercopy(ptr, n, to_user, type);
62441 +#endif
62442 +
62443 +}
62444 +EXPORT_SYMBOL(__check_object_size);
62445 +
62446 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
62447 +void pax_track_stack(void)
62448 +{
62449 + unsigned long sp = (unsigned long)&sp;
62450 + if (sp < current_thread_info()->lowest_stack &&
62451 + sp > (unsigned long)task_stack_page(current))
62452 + current_thread_info()->lowest_stack = sp;
62453 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
62454 + BUG();
62455 +}
62456 +EXPORT_SYMBOL(pax_track_stack);
62457 +#endif
62458 +
62459 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
62460 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
62461 +{
62462 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
62463 + dump_stack();
62464 + do_group_exit(SIGKILL);
62465 +}
62466 +EXPORT_SYMBOL(report_size_overflow);
62467 +#endif
62468 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
62469 index 9f9992b..8b59411 100644
62470 --- a/fs/ext2/balloc.c
62471 +++ b/fs/ext2/balloc.c
62472 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
62473
62474 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62475 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62476 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62477 + if (free_blocks < root_blocks + 1 &&
62478 !uid_eq(sbi->s_resuid, current_fsuid()) &&
62479 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62480 - !in_group_p (sbi->s_resgid))) {
62481 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62482 return 0;
62483 }
62484 return 1;
62485 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
62486 index 9142614..97484fa 100644
62487 --- a/fs/ext2/xattr.c
62488 +++ b/fs/ext2/xattr.c
62489 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
62490 struct buffer_head *bh = NULL;
62491 struct ext2_xattr_entry *entry;
62492 char *end;
62493 - size_t rest = buffer_size;
62494 + size_t rest = buffer_size, total_size = 0;
62495 int error;
62496
62497 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
62498 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
62499 buffer += size;
62500 }
62501 rest -= size;
62502 + total_size += size;
62503 }
62504 }
62505 - error = buffer_size - rest; /* total size */
62506 + error = total_size;
62507
62508 cleanup:
62509 brelse(bh);
62510 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
62511 index 158b5d4..2432610 100644
62512 --- a/fs/ext3/balloc.c
62513 +++ b/fs/ext3/balloc.c
62514 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
62515
62516 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62517 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62518 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62519 + if (free_blocks < root_blocks + 1 &&
62520 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
62521 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62522 - !in_group_p (sbi->s_resgid))) {
62523 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62524 return 0;
62525 }
62526 return 1;
62527 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
62528 index c6874be..f8a6ae8 100644
62529 --- a/fs/ext3/xattr.c
62530 +++ b/fs/ext3/xattr.c
62531 @@ -330,7 +330,7 @@ static int
62532 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62533 char *buffer, size_t buffer_size)
62534 {
62535 - size_t rest = buffer_size;
62536 + size_t rest = buffer_size, total_size = 0;
62537
62538 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
62539 const struct xattr_handler *handler =
62540 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62541 buffer += size;
62542 }
62543 rest -= size;
62544 + total_size += size;
62545 }
62546 }
62547 - return buffer_size - rest;
62548 + return total_size;
62549 }
62550
62551 static int
62552 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
62553 index fca3820..e1ea241 100644
62554 --- a/fs/ext4/balloc.c
62555 +++ b/fs/ext4/balloc.c
62556 @@ -553,8 +553,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
62557 /* Hm, nope. Are (enough) root reserved clusters available? */
62558 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
62559 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
62560 - capable(CAP_SYS_RESOURCE) ||
62561 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
62562 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
62563 + capable_nolog(CAP_SYS_RESOURCE)) {
62564
62565 if (free_clusters >= (nclusters + dirty_clusters +
62566 resv_clusters))
62567 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
62568 index 1bbe7c3..c7442e2 100644
62569 --- a/fs/ext4/ext4.h
62570 +++ b/fs/ext4/ext4.h
62571 @@ -1276,19 +1276,19 @@ struct ext4_sb_info {
62572 unsigned long s_mb_last_start;
62573
62574 /* stats for buddy allocator */
62575 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
62576 - atomic_t s_bal_success; /* we found long enough chunks */
62577 - atomic_t s_bal_allocated; /* in blocks */
62578 - atomic_t s_bal_ex_scanned; /* total extents scanned */
62579 - atomic_t s_bal_goals; /* goal hits */
62580 - atomic_t s_bal_breaks; /* too long searches */
62581 - atomic_t s_bal_2orders; /* 2^order hits */
62582 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
62583 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
62584 + atomic_unchecked_t s_bal_allocated; /* in blocks */
62585 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
62586 + atomic_unchecked_t s_bal_goals; /* goal hits */
62587 + atomic_unchecked_t s_bal_breaks; /* too long searches */
62588 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
62589 spinlock_t s_bal_lock;
62590 unsigned long s_mb_buddies_generated;
62591 unsigned long long s_mb_generation_time;
62592 - atomic_t s_mb_lost_chunks;
62593 - atomic_t s_mb_preallocated;
62594 - atomic_t s_mb_discarded;
62595 + atomic_unchecked_t s_mb_lost_chunks;
62596 + atomic_unchecked_t s_mb_preallocated;
62597 + atomic_unchecked_t s_mb_discarded;
62598 atomic_t s_lock_busy;
62599
62600 /* locality groups */
62601 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
62602 index c3e7418..f62cab3 100644
62603 --- a/fs/ext4/mballoc.c
62604 +++ b/fs/ext4/mballoc.c
62605 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
62606 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
62607
62608 if (EXT4_SB(sb)->s_mb_stats)
62609 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
62610 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
62611
62612 break;
62613 }
62614 @@ -2211,7 +2211,7 @@ repeat:
62615 ac->ac_status = AC_STATUS_CONTINUE;
62616 ac->ac_flags |= EXT4_MB_HINT_FIRST;
62617 cr = 3;
62618 - atomic_inc(&sbi->s_mb_lost_chunks);
62619 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
62620 goto repeat;
62621 }
62622 }
62623 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
62624 if (sbi->s_mb_stats) {
62625 ext4_msg(sb, KERN_INFO,
62626 "mballoc: %u blocks %u reqs (%u success)",
62627 - atomic_read(&sbi->s_bal_allocated),
62628 - atomic_read(&sbi->s_bal_reqs),
62629 - atomic_read(&sbi->s_bal_success));
62630 + atomic_read_unchecked(&sbi->s_bal_allocated),
62631 + atomic_read_unchecked(&sbi->s_bal_reqs),
62632 + atomic_read_unchecked(&sbi->s_bal_success));
62633 ext4_msg(sb, KERN_INFO,
62634 "mballoc: %u extents scanned, %u goal hits, "
62635 "%u 2^N hits, %u breaks, %u lost",
62636 - atomic_read(&sbi->s_bal_ex_scanned),
62637 - atomic_read(&sbi->s_bal_goals),
62638 - atomic_read(&sbi->s_bal_2orders),
62639 - atomic_read(&sbi->s_bal_breaks),
62640 - atomic_read(&sbi->s_mb_lost_chunks));
62641 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
62642 + atomic_read_unchecked(&sbi->s_bal_goals),
62643 + atomic_read_unchecked(&sbi->s_bal_2orders),
62644 + atomic_read_unchecked(&sbi->s_bal_breaks),
62645 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
62646 ext4_msg(sb, KERN_INFO,
62647 "mballoc: %lu generated and it took %Lu",
62648 sbi->s_mb_buddies_generated,
62649 sbi->s_mb_generation_time);
62650 ext4_msg(sb, KERN_INFO,
62651 "mballoc: %u preallocated, %u discarded",
62652 - atomic_read(&sbi->s_mb_preallocated),
62653 - atomic_read(&sbi->s_mb_discarded));
62654 + atomic_read_unchecked(&sbi->s_mb_preallocated),
62655 + atomic_read_unchecked(&sbi->s_mb_discarded));
62656 }
62657
62658 free_percpu(sbi->s_locality_groups);
62659 @@ -3191,16 +3191,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
62660 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
62661
62662 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
62663 - atomic_inc(&sbi->s_bal_reqs);
62664 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62665 + atomic_inc_unchecked(&sbi->s_bal_reqs);
62666 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62667 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
62668 - atomic_inc(&sbi->s_bal_success);
62669 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
62670 + atomic_inc_unchecked(&sbi->s_bal_success);
62671 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62672 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62673 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62674 - atomic_inc(&sbi->s_bal_goals);
62675 + atomic_inc_unchecked(&sbi->s_bal_goals);
62676 if (ac->ac_found > sbi->s_mb_max_to_scan)
62677 - atomic_inc(&sbi->s_bal_breaks);
62678 + atomic_inc_unchecked(&sbi->s_bal_breaks);
62679 }
62680
62681 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62682 @@ -3627,7 +3627,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62683 trace_ext4_mb_new_inode_pa(ac, pa);
62684
62685 ext4_mb_use_inode_pa(ac, pa);
62686 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62687 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62688
62689 ei = EXT4_I(ac->ac_inode);
62690 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62691 @@ -3687,7 +3687,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62692 trace_ext4_mb_new_group_pa(ac, pa);
62693
62694 ext4_mb_use_group_pa(ac, pa);
62695 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62696 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62697
62698 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62699 lg = ac->ac_lg;
62700 @@ -3776,7 +3776,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62701 * from the bitmap and continue.
62702 */
62703 }
62704 - atomic_add(free, &sbi->s_mb_discarded);
62705 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
62706
62707 return err;
62708 }
62709 @@ -3794,7 +3794,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62710 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62711 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62712 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62713 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62714 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62715 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62716
62717 return 0;
62718 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62719 index 32bce84..112d969 100644
62720 --- a/fs/ext4/mmp.c
62721 +++ b/fs/ext4/mmp.c
62722 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62723 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62724 const char *function, unsigned int line, const char *msg)
62725 {
62726 - __ext4_warning(sb, function, line, msg);
62727 + __ext4_warning(sb, function, line, "%s", msg);
62728 __ext4_warning(sb, function, line,
62729 "MMP failure info: last update time: %llu, last update "
62730 "node: %s, last update device: %s\n",
62731 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62732 index beeb5c4..998c28d 100644
62733 --- a/fs/ext4/super.c
62734 +++ b/fs/ext4/super.c
62735 @@ -1276,7 +1276,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62736 }
62737
62738 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62739 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62740 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62741 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62742
62743 #ifdef CONFIG_QUOTA
62744 @@ -2464,7 +2464,7 @@ struct ext4_attr {
62745 int offset;
62746 int deprecated_val;
62747 } u;
62748 -};
62749 +} __do_const;
62750
62751 static int parse_strtoull(const char *buf,
62752 unsigned long long max, unsigned long long *value)
62753 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62754 index e738733..9843a6c 100644
62755 --- a/fs/ext4/xattr.c
62756 +++ b/fs/ext4/xattr.c
62757 @@ -386,7 +386,7 @@ static int
62758 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62759 char *buffer, size_t buffer_size)
62760 {
62761 - size_t rest = buffer_size;
62762 + size_t rest = buffer_size, total_size = 0;
62763
62764 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62765 const struct xattr_handler *handler =
62766 @@ -403,9 +403,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62767 buffer += size;
62768 }
62769 rest -= size;
62770 + total_size += size;
62771 }
62772 }
62773 - return buffer_size - rest;
62774 + return total_size;
62775 }
62776
62777 static int
62778 diff --git a/fs/fcntl.c b/fs/fcntl.c
62779 index 72c82f6..a18b263 100644
62780 --- a/fs/fcntl.c
62781 +++ b/fs/fcntl.c
62782 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62783 if (err)
62784 return err;
62785
62786 + if (gr_handle_chroot_fowner(pid, type))
62787 + return -ENOENT;
62788 + if (gr_check_protected_task_fowner(pid, type))
62789 + return -EACCES;
62790 +
62791 f_modown(filp, pid, type, force);
62792 return 0;
62793 }
62794 diff --git a/fs/fhandle.c b/fs/fhandle.c
62795 index 999ff5c..ac037c9 100644
62796 --- a/fs/fhandle.c
62797 +++ b/fs/fhandle.c
62798 @@ -8,6 +8,7 @@
62799 #include <linux/fs_struct.h>
62800 #include <linux/fsnotify.h>
62801 #include <linux/personality.h>
62802 +#include <linux/grsecurity.h>
62803 #include <asm/uaccess.h>
62804 #include "internal.h"
62805 #include "mount.h"
62806 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62807 } else
62808 retval = 0;
62809 /* copy the mount id */
62810 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62811 - sizeof(*mnt_id)) ||
62812 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62813 copy_to_user(ufh, handle,
62814 sizeof(struct file_handle) + handle_bytes))
62815 retval = -EFAULT;
62816 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62817 * the directory. Ideally we would like CAP_DAC_SEARCH.
62818 * But we don't have that
62819 */
62820 - if (!capable(CAP_DAC_READ_SEARCH)) {
62821 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62822 retval = -EPERM;
62823 goto out_err;
62824 }
62825 diff --git a/fs/file.c b/fs/file.c
62826 index 66923fe..2849783 100644
62827 --- a/fs/file.c
62828 +++ b/fs/file.c
62829 @@ -16,6 +16,7 @@
62830 #include <linux/slab.h>
62831 #include <linux/vmalloc.h>
62832 #include <linux/file.h>
62833 +#include <linux/security.h>
62834 #include <linux/fdtable.h>
62835 #include <linux/bitops.h>
62836 #include <linux/interrupt.h>
62837 @@ -139,7 +140,7 @@ out:
62838 * Return <0 error code on error; 1 on successful completion.
62839 * The files->file_lock should be held on entry, and will be held on exit.
62840 */
62841 -static int expand_fdtable(struct files_struct *files, int nr)
62842 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
62843 __releases(files->file_lock)
62844 __acquires(files->file_lock)
62845 {
62846 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62847 * expanded and execution may have blocked.
62848 * The files->file_lock should be held on entry, and will be held on exit.
62849 */
62850 -static int expand_files(struct files_struct *files, int nr)
62851 +static int expand_files(struct files_struct *files, unsigned int nr)
62852 {
62853 struct fdtable *fdt;
62854
62855 @@ -799,6 +800,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62856 if (!file)
62857 return __close_fd(files, fd);
62858
62859 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62860 if (fd >= rlimit(RLIMIT_NOFILE))
62861 return -EBADF;
62862
62863 @@ -825,6 +827,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62864 if (unlikely(oldfd == newfd))
62865 return -EINVAL;
62866
62867 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62868 if (newfd >= rlimit(RLIMIT_NOFILE))
62869 return -EBADF;
62870
62871 @@ -880,6 +883,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62872 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62873 {
62874 int err;
62875 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62876 if (from >= rlimit(RLIMIT_NOFILE))
62877 return -EINVAL;
62878 err = alloc_fd(from, flags);
62879 diff --git a/fs/filesystems.c b/fs/filesystems.c
62880 index 5797d45..7d7d79a 100644
62881 --- a/fs/filesystems.c
62882 +++ b/fs/filesystems.c
62883 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62884 int len = dot ? dot - name : strlen(name);
62885
62886 fs = __get_fs_type(name, len);
62887 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
62888 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62889 +#else
62890 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62891 +#endif
62892 fs = __get_fs_type(name, len);
62893
62894 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
62895 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
62896 index 7dca743..543d620 100644
62897 --- a/fs/fs_struct.c
62898 +++ b/fs/fs_struct.c
62899 @@ -4,6 +4,7 @@
62900 #include <linux/path.h>
62901 #include <linux/slab.h>
62902 #include <linux/fs_struct.h>
62903 +#include <linux/grsecurity.h>
62904 #include "internal.h"
62905
62906 /*
62907 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
62908 write_seqcount_begin(&fs->seq);
62909 old_root = fs->root;
62910 fs->root = *path;
62911 + gr_set_chroot_entries(current, path);
62912 write_seqcount_end(&fs->seq);
62913 spin_unlock(&fs->lock);
62914 if (old_root.dentry)
62915 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62916 int hits = 0;
62917 spin_lock(&fs->lock);
62918 write_seqcount_begin(&fs->seq);
62919 + /* this root replacement is only done by pivot_root,
62920 + leave grsec's chroot tagging alone for this task
62921 + so that a pivoted root isn't treated as a chroot
62922 + */
62923 hits += replace_path(&fs->root, old_root, new_root);
62924 hits += replace_path(&fs->pwd, old_root, new_root);
62925 write_seqcount_end(&fs->seq);
62926 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
62927 task_lock(tsk);
62928 spin_lock(&fs->lock);
62929 tsk->fs = NULL;
62930 - kill = !--fs->users;
62931 + gr_clear_chroot_entries(tsk);
62932 + kill = !atomic_dec_return(&fs->users);
62933 spin_unlock(&fs->lock);
62934 task_unlock(tsk);
62935 if (kill)
62936 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62937 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62938 /* We don't need to lock fs - think why ;-) */
62939 if (fs) {
62940 - fs->users = 1;
62941 + atomic_set(&fs->users, 1);
62942 fs->in_exec = 0;
62943 spin_lock_init(&fs->lock);
62944 seqcount_init(&fs->seq);
62945 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62946 spin_lock(&old->lock);
62947 fs->root = old->root;
62948 path_get(&fs->root);
62949 + /* instead of calling gr_set_chroot_entries here,
62950 + we call it from every caller of this function
62951 + */
62952 fs->pwd = old->pwd;
62953 path_get(&fs->pwd);
62954 spin_unlock(&old->lock);
62955 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
62956
62957 task_lock(current);
62958 spin_lock(&fs->lock);
62959 - kill = !--fs->users;
62960 + kill = !atomic_dec_return(&fs->users);
62961 current->fs = new_fs;
62962 + gr_set_chroot_entries(current, &new_fs->root);
62963 spin_unlock(&fs->lock);
62964 task_unlock(current);
62965
62966 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62967
62968 int current_umask(void)
62969 {
62970 - return current->fs->umask;
62971 + return current->fs->umask | gr_acl_umask();
62972 }
62973 EXPORT_SYMBOL(current_umask);
62974
62975 /* to be mentioned only in INIT_TASK */
62976 struct fs_struct init_fs = {
62977 - .users = 1,
62978 + .users = ATOMIC_INIT(1),
62979 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62980 .seq = SEQCNT_ZERO(init_fs.seq),
62981 .umask = 0022,
62982 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62983 index aec01be..cf81ff9 100644
62984 --- a/fs/fscache/cookie.c
62985 +++ b/fs/fscache/cookie.c
62986 @@ -19,7 +19,7 @@
62987
62988 struct kmem_cache *fscache_cookie_jar;
62989
62990 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62991 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62992
62993 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62994 static int fscache_alloc_object(struct fscache_cache *cache,
62995 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62996 parent ? (char *) parent->def->name : "<no-parent>",
62997 def->name, netfs_data, enable);
62998
62999 - fscache_stat(&fscache_n_acquires);
63000 + fscache_stat_unchecked(&fscache_n_acquires);
63001
63002 /* if there's no parent cookie, then we don't create one here either */
63003 if (!parent) {
63004 - fscache_stat(&fscache_n_acquires_null);
63005 + fscache_stat_unchecked(&fscache_n_acquires_null);
63006 _leave(" [no parent]");
63007 return NULL;
63008 }
63009 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63010 /* allocate and initialise a cookie */
63011 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
63012 if (!cookie) {
63013 - fscache_stat(&fscache_n_acquires_oom);
63014 + fscache_stat_unchecked(&fscache_n_acquires_oom);
63015 _leave(" [ENOMEM]");
63016 return NULL;
63017 }
63018 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
63019
63020 switch (cookie->def->type) {
63021 case FSCACHE_COOKIE_TYPE_INDEX:
63022 - fscache_stat(&fscache_n_cookie_index);
63023 + fscache_stat_unchecked(&fscache_n_cookie_index);
63024 break;
63025 case FSCACHE_COOKIE_TYPE_DATAFILE:
63026 - fscache_stat(&fscache_n_cookie_data);
63027 + fscache_stat_unchecked(&fscache_n_cookie_data);
63028 break;
63029 default:
63030 - fscache_stat(&fscache_n_cookie_special);
63031 + fscache_stat_unchecked(&fscache_n_cookie_special);
63032 break;
63033 }
63034
63035 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63036 } else {
63037 atomic_dec(&parent->n_children);
63038 __fscache_cookie_put(cookie);
63039 - fscache_stat(&fscache_n_acquires_nobufs);
63040 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
63041 _leave(" = NULL");
63042 return NULL;
63043 }
63044 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63045 }
63046 }
63047
63048 - fscache_stat(&fscache_n_acquires_ok);
63049 + fscache_stat_unchecked(&fscache_n_acquires_ok);
63050 _leave(" = %p", cookie);
63051 return cookie;
63052 }
63053 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
63054 cache = fscache_select_cache_for_object(cookie->parent);
63055 if (!cache) {
63056 up_read(&fscache_addremove_sem);
63057 - fscache_stat(&fscache_n_acquires_no_cache);
63058 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
63059 _leave(" = -ENOMEDIUM [no cache]");
63060 return -ENOMEDIUM;
63061 }
63062 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
63063 object = cache->ops->alloc_object(cache, cookie);
63064 fscache_stat_d(&fscache_n_cop_alloc_object);
63065 if (IS_ERR(object)) {
63066 - fscache_stat(&fscache_n_object_no_alloc);
63067 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
63068 ret = PTR_ERR(object);
63069 goto error;
63070 }
63071
63072 - fscache_stat(&fscache_n_object_alloc);
63073 + fscache_stat_unchecked(&fscache_n_object_alloc);
63074
63075 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
63076 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
63077
63078 _debug("ALLOC OBJ%x: %s {%lx}",
63079 object->debug_id, cookie->def->name, object->events);
63080 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
63081
63082 _enter("{%s}", cookie->def->name);
63083
63084 - fscache_stat(&fscache_n_invalidates);
63085 + fscache_stat_unchecked(&fscache_n_invalidates);
63086
63087 /* Only permit invalidation of data files. Invalidating an index will
63088 * require the caller to release all its attachments to the tree rooted
63089 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
63090 {
63091 struct fscache_object *object;
63092
63093 - fscache_stat(&fscache_n_updates);
63094 + fscache_stat_unchecked(&fscache_n_updates);
63095
63096 if (!cookie) {
63097 - fscache_stat(&fscache_n_updates_null);
63098 + fscache_stat_unchecked(&fscache_n_updates_null);
63099 _leave(" [no cookie]");
63100 return;
63101 }
63102 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
63103 */
63104 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
63105 {
63106 - fscache_stat(&fscache_n_relinquishes);
63107 + fscache_stat_unchecked(&fscache_n_relinquishes);
63108 if (retire)
63109 - fscache_stat(&fscache_n_relinquishes_retire);
63110 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
63111
63112 if (!cookie) {
63113 - fscache_stat(&fscache_n_relinquishes_null);
63114 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
63115 _leave(" [no cookie]");
63116 return;
63117 }
63118 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
63119 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
63120 goto inconsistent;
63121
63122 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63123 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63124
63125 __fscache_use_cookie(cookie);
63126 if (fscache_submit_op(object, op) < 0)
63127 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
63128 index bc6c08f..09c0d96 100644
63129 --- a/fs/fscache/internal.h
63130 +++ b/fs/fscache/internal.h
63131 @@ -139,8 +139,8 @@ extern void fscache_operation_gc(struct work_struct *);
63132 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
63133 extern int fscache_wait_for_operation_activation(struct fscache_object *,
63134 struct fscache_operation *,
63135 - atomic_t *,
63136 - atomic_t *,
63137 + atomic_unchecked_t *,
63138 + atomic_unchecked_t *,
63139 void (*)(struct fscache_operation *));
63140 extern void fscache_invalidate_writes(struct fscache_cookie *);
63141
63142 @@ -159,101 +159,101 @@ extern void fscache_proc_cleanup(void);
63143 * stats.c
63144 */
63145 #ifdef CONFIG_FSCACHE_STATS
63146 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
63147 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
63148 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
63149 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
63150
63151 -extern atomic_t fscache_n_op_pend;
63152 -extern atomic_t fscache_n_op_run;
63153 -extern atomic_t fscache_n_op_enqueue;
63154 -extern atomic_t fscache_n_op_deferred_release;
63155 -extern atomic_t fscache_n_op_release;
63156 -extern atomic_t fscache_n_op_gc;
63157 -extern atomic_t fscache_n_op_cancelled;
63158 -extern atomic_t fscache_n_op_rejected;
63159 +extern atomic_unchecked_t fscache_n_op_pend;
63160 +extern atomic_unchecked_t fscache_n_op_run;
63161 +extern atomic_unchecked_t fscache_n_op_enqueue;
63162 +extern atomic_unchecked_t fscache_n_op_deferred_release;
63163 +extern atomic_unchecked_t fscache_n_op_release;
63164 +extern atomic_unchecked_t fscache_n_op_gc;
63165 +extern atomic_unchecked_t fscache_n_op_cancelled;
63166 +extern atomic_unchecked_t fscache_n_op_rejected;
63167
63168 -extern atomic_t fscache_n_attr_changed;
63169 -extern atomic_t fscache_n_attr_changed_ok;
63170 -extern atomic_t fscache_n_attr_changed_nobufs;
63171 -extern atomic_t fscache_n_attr_changed_nomem;
63172 -extern atomic_t fscache_n_attr_changed_calls;
63173 +extern atomic_unchecked_t fscache_n_attr_changed;
63174 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
63175 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
63176 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
63177 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
63178
63179 -extern atomic_t fscache_n_allocs;
63180 -extern atomic_t fscache_n_allocs_ok;
63181 -extern atomic_t fscache_n_allocs_wait;
63182 -extern atomic_t fscache_n_allocs_nobufs;
63183 -extern atomic_t fscache_n_allocs_intr;
63184 -extern atomic_t fscache_n_allocs_object_dead;
63185 -extern atomic_t fscache_n_alloc_ops;
63186 -extern atomic_t fscache_n_alloc_op_waits;
63187 +extern atomic_unchecked_t fscache_n_allocs;
63188 +extern atomic_unchecked_t fscache_n_allocs_ok;
63189 +extern atomic_unchecked_t fscache_n_allocs_wait;
63190 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
63191 +extern atomic_unchecked_t fscache_n_allocs_intr;
63192 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
63193 +extern atomic_unchecked_t fscache_n_alloc_ops;
63194 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
63195
63196 -extern atomic_t fscache_n_retrievals;
63197 -extern atomic_t fscache_n_retrievals_ok;
63198 -extern atomic_t fscache_n_retrievals_wait;
63199 -extern atomic_t fscache_n_retrievals_nodata;
63200 -extern atomic_t fscache_n_retrievals_nobufs;
63201 -extern atomic_t fscache_n_retrievals_intr;
63202 -extern atomic_t fscache_n_retrievals_nomem;
63203 -extern atomic_t fscache_n_retrievals_object_dead;
63204 -extern atomic_t fscache_n_retrieval_ops;
63205 -extern atomic_t fscache_n_retrieval_op_waits;
63206 +extern atomic_unchecked_t fscache_n_retrievals;
63207 +extern atomic_unchecked_t fscache_n_retrievals_ok;
63208 +extern atomic_unchecked_t fscache_n_retrievals_wait;
63209 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
63210 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
63211 +extern atomic_unchecked_t fscache_n_retrievals_intr;
63212 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
63213 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
63214 +extern atomic_unchecked_t fscache_n_retrieval_ops;
63215 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
63216
63217 -extern atomic_t fscache_n_stores;
63218 -extern atomic_t fscache_n_stores_ok;
63219 -extern atomic_t fscache_n_stores_again;
63220 -extern atomic_t fscache_n_stores_nobufs;
63221 -extern atomic_t fscache_n_stores_oom;
63222 -extern atomic_t fscache_n_store_ops;
63223 -extern atomic_t fscache_n_store_calls;
63224 -extern atomic_t fscache_n_store_pages;
63225 -extern atomic_t fscache_n_store_radix_deletes;
63226 -extern atomic_t fscache_n_store_pages_over_limit;
63227 +extern atomic_unchecked_t fscache_n_stores;
63228 +extern atomic_unchecked_t fscache_n_stores_ok;
63229 +extern atomic_unchecked_t fscache_n_stores_again;
63230 +extern atomic_unchecked_t fscache_n_stores_nobufs;
63231 +extern atomic_unchecked_t fscache_n_stores_oom;
63232 +extern atomic_unchecked_t fscache_n_store_ops;
63233 +extern atomic_unchecked_t fscache_n_store_calls;
63234 +extern atomic_unchecked_t fscache_n_store_pages;
63235 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
63236 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
63237
63238 -extern atomic_t fscache_n_store_vmscan_not_storing;
63239 -extern atomic_t fscache_n_store_vmscan_gone;
63240 -extern atomic_t fscache_n_store_vmscan_busy;
63241 -extern atomic_t fscache_n_store_vmscan_cancelled;
63242 -extern atomic_t fscache_n_store_vmscan_wait;
63243 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63244 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
63245 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
63246 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63247 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
63248
63249 -extern atomic_t fscache_n_marks;
63250 -extern atomic_t fscache_n_uncaches;
63251 +extern atomic_unchecked_t fscache_n_marks;
63252 +extern atomic_unchecked_t fscache_n_uncaches;
63253
63254 -extern atomic_t fscache_n_acquires;
63255 -extern atomic_t fscache_n_acquires_null;
63256 -extern atomic_t fscache_n_acquires_no_cache;
63257 -extern atomic_t fscache_n_acquires_ok;
63258 -extern atomic_t fscache_n_acquires_nobufs;
63259 -extern atomic_t fscache_n_acquires_oom;
63260 +extern atomic_unchecked_t fscache_n_acquires;
63261 +extern atomic_unchecked_t fscache_n_acquires_null;
63262 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
63263 +extern atomic_unchecked_t fscache_n_acquires_ok;
63264 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
63265 +extern atomic_unchecked_t fscache_n_acquires_oom;
63266
63267 -extern atomic_t fscache_n_invalidates;
63268 -extern atomic_t fscache_n_invalidates_run;
63269 +extern atomic_unchecked_t fscache_n_invalidates;
63270 +extern atomic_unchecked_t fscache_n_invalidates_run;
63271
63272 -extern atomic_t fscache_n_updates;
63273 -extern atomic_t fscache_n_updates_null;
63274 -extern atomic_t fscache_n_updates_run;
63275 +extern atomic_unchecked_t fscache_n_updates;
63276 +extern atomic_unchecked_t fscache_n_updates_null;
63277 +extern atomic_unchecked_t fscache_n_updates_run;
63278
63279 -extern atomic_t fscache_n_relinquishes;
63280 -extern atomic_t fscache_n_relinquishes_null;
63281 -extern atomic_t fscache_n_relinquishes_waitcrt;
63282 -extern atomic_t fscache_n_relinquishes_retire;
63283 +extern atomic_unchecked_t fscache_n_relinquishes;
63284 +extern atomic_unchecked_t fscache_n_relinquishes_null;
63285 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63286 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
63287
63288 -extern atomic_t fscache_n_cookie_index;
63289 -extern atomic_t fscache_n_cookie_data;
63290 -extern atomic_t fscache_n_cookie_special;
63291 +extern atomic_unchecked_t fscache_n_cookie_index;
63292 +extern atomic_unchecked_t fscache_n_cookie_data;
63293 +extern atomic_unchecked_t fscache_n_cookie_special;
63294
63295 -extern atomic_t fscache_n_object_alloc;
63296 -extern atomic_t fscache_n_object_no_alloc;
63297 -extern atomic_t fscache_n_object_lookups;
63298 -extern atomic_t fscache_n_object_lookups_negative;
63299 -extern atomic_t fscache_n_object_lookups_positive;
63300 -extern atomic_t fscache_n_object_lookups_timed_out;
63301 -extern atomic_t fscache_n_object_created;
63302 -extern atomic_t fscache_n_object_avail;
63303 -extern atomic_t fscache_n_object_dead;
63304 +extern atomic_unchecked_t fscache_n_object_alloc;
63305 +extern atomic_unchecked_t fscache_n_object_no_alloc;
63306 +extern atomic_unchecked_t fscache_n_object_lookups;
63307 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
63308 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
63309 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
63310 +extern atomic_unchecked_t fscache_n_object_created;
63311 +extern atomic_unchecked_t fscache_n_object_avail;
63312 +extern atomic_unchecked_t fscache_n_object_dead;
63313
63314 -extern atomic_t fscache_n_checkaux_none;
63315 -extern atomic_t fscache_n_checkaux_okay;
63316 -extern atomic_t fscache_n_checkaux_update;
63317 -extern atomic_t fscache_n_checkaux_obsolete;
63318 +extern atomic_unchecked_t fscache_n_checkaux_none;
63319 +extern atomic_unchecked_t fscache_n_checkaux_okay;
63320 +extern atomic_unchecked_t fscache_n_checkaux_update;
63321 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
63322
63323 extern atomic_t fscache_n_cop_alloc_object;
63324 extern atomic_t fscache_n_cop_lookup_object;
63325 @@ -278,6 +278,11 @@ static inline void fscache_stat(atomic_t *stat)
63326 atomic_inc(stat);
63327 }
63328
63329 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
63330 +{
63331 + atomic_inc_unchecked(stat);
63332 +}
63333 +
63334 static inline void fscache_stat_d(atomic_t *stat)
63335 {
63336 atomic_dec(stat);
63337 @@ -290,6 +295,7 @@ extern const struct file_operations fscache_stats_fops;
63338
63339 #define __fscache_stat(stat) (NULL)
63340 #define fscache_stat(stat) do {} while (0)
63341 +#define fscache_stat_unchecked(stat) do {} while (0)
63342 #define fscache_stat_d(stat) do {} while (0)
63343 #endif
63344
63345 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
63346 index d3b4539..ed0c659 100644
63347 --- a/fs/fscache/object.c
63348 +++ b/fs/fscache/object.c
63349 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
63350 _debug("LOOKUP \"%s\" in \"%s\"",
63351 cookie->def->name, object->cache->tag->name);
63352
63353 - fscache_stat(&fscache_n_object_lookups);
63354 + fscache_stat_unchecked(&fscache_n_object_lookups);
63355 fscache_stat(&fscache_n_cop_lookup_object);
63356 ret = object->cache->ops->lookup_object(object);
63357 fscache_stat_d(&fscache_n_cop_lookup_object);
63358 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
63359 if (ret == -ETIMEDOUT) {
63360 /* probably stuck behind another object, so move this one to
63361 * the back of the queue */
63362 - fscache_stat(&fscache_n_object_lookups_timed_out);
63363 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
63364 _leave(" [timeout]");
63365 return NO_TRANSIT;
63366 }
63367 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
63368 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
63369
63370 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
63371 - fscache_stat(&fscache_n_object_lookups_negative);
63372 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
63373
63374 /* Allow write requests to begin stacking up and read requests to begin
63375 * returning ENODATA.
63376 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
63377 /* if we were still looking up, then we must have a positive lookup
63378 * result, in which case there may be data available */
63379 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
63380 - fscache_stat(&fscache_n_object_lookups_positive);
63381 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
63382
63383 /* We do (presumably) have data */
63384 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
63385 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
63386 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
63387 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
63388 } else {
63389 - fscache_stat(&fscache_n_object_created);
63390 + fscache_stat_unchecked(&fscache_n_object_created);
63391 }
63392
63393 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
63394 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
63395 fscache_stat_d(&fscache_n_cop_lookup_complete);
63396
63397 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
63398 - fscache_stat(&fscache_n_object_avail);
63399 + fscache_stat_unchecked(&fscache_n_object_avail);
63400
63401 _leave("");
63402 return transit_to(JUMPSTART_DEPS);
63403 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
63404
63405 /* this just shifts the object release to the work processor */
63406 fscache_put_object(object);
63407 - fscache_stat(&fscache_n_object_dead);
63408 + fscache_stat_unchecked(&fscache_n_object_dead);
63409
63410 _leave("");
63411 return transit_to(OBJECT_DEAD);
63412 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63413 enum fscache_checkaux result;
63414
63415 if (!object->cookie->def->check_aux) {
63416 - fscache_stat(&fscache_n_checkaux_none);
63417 + fscache_stat_unchecked(&fscache_n_checkaux_none);
63418 return FSCACHE_CHECKAUX_OKAY;
63419 }
63420
63421 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63422 switch (result) {
63423 /* entry okay as is */
63424 case FSCACHE_CHECKAUX_OKAY:
63425 - fscache_stat(&fscache_n_checkaux_okay);
63426 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
63427 break;
63428
63429 /* entry requires update */
63430 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
63431 - fscache_stat(&fscache_n_checkaux_update);
63432 + fscache_stat_unchecked(&fscache_n_checkaux_update);
63433 break;
63434
63435 /* entry requires deletion */
63436 case FSCACHE_CHECKAUX_OBSOLETE:
63437 - fscache_stat(&fscache_n_checkaux_obsolete);
63438 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
63439 break;
63440
63441 default:
63442 @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
63443 {
63444 const struct fscache_state *s;
63445
63446 - fscache_stat(&fscache_n_invalidates_run);
63447 + fscache_stat_unchecked(&fscache_n_invalidates_run);
63448 fscache_stat(&fscache_n_cop_invalidate_object);
63449 s = _fscache_invalidate_object(object, event);
63450 fscache_stat_d(&fscache_n_cop_invalidate_object);
63451 @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
63452 {
63453 _enter("{OBJ%x},%d", object->debug_id, event);
63454
63455 - fscache_stat(&fscache_n_updates_run);
63456 + fscache_stat_unchecked(&fscache_n_updates_run);
63457 fscache_stat(&fscache_n_cop_update_object);
63458 object->cache->ops->update_object(object);
63459 fscache_stat_d(&fscache_n_cop_update_object);
63460 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
63461 index e7b87a0..a85d47a 100644
63462 --- a/fs/fscache/operation.c
63463 +++ b/fs/fscache/operation.c
63464 @@ -17,7 +17,7 @@
63465 #include <linux/slab.h>
63466 #include "internal.h"
63467
63468 -atomic_t fscache_op_debug_id;
63469 +atomic_unchecked_t fscache_op_debug_id;
63470 EXPORT_SYMBOL(fscache_op_debug_id);
63471
63472 /**
63473 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
63474 ASSERTCMP(atomic_read(&op->usage), >, 0);
63475 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
63476
63477 - fscache_stat(&fscache_n_op_enqueue);
63478 + fscache_stat_unchecked(&fscache_n_op_enqueue);
63479 switch (op->flags & FSCACHE_OP_TYPE) {
63480 case FSCACHE_OP_ASYNC:
63481 _debug("queue async");
63482 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
63483 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
63484 if (op->processor)
63485 fscache_enqueue_operation(op);
63486 - fscache_stat(&fscache_n_op_run);
63487 + fscache_stat_unchecked(&fscache_n_op_run);
63488 }
63489
63490 /*
63491 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63492 if (object->n_in_progress > 0) {
63493 atomic_inc(&op->usage);
63494 list_add_tail(&op->pend_link, &object->pending_ops);
63495 - fscache_stat(&fscache_n_op_pend);
63496 + fscache_stat_unchecked(&fscache_n_op_pend);
63497 } else if (!list_empty(&object->pending_ops)) {
63498 atomic_inc(&op->usage);
63499 list_add_tail(&op->pend_link, &object->pending_ops);
63500 - fscache_stat(&fscache_n_op_pend);
63501 + fscache_stat_unchecked(&fscache_n_op_pend);
63502 fscache_start_operations(object);
63503 } else {
63504 ASSERTCMP(object->n_in_progress, ==, 0);
63505 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63506 object->n_exclusive++; /* reads and writes must wait */
63507 atomic_inc(&op->usage);
63508 list_add_tail(&op->pend_link, &object->pending_ops);
63509 - fscache_stat(&fscache_n_op_pend);
63510 + fscache_stat_unchecked(&fscache_n_op_pend);
63511 ret = 0;
63512 } else {
63513 /* If we're in any other state, there must have been an I/O
63514 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
63515 if (object->n_exclusive > 0) {
63516 atomic_inc(&op->usage);
63517 list_add_tail(&op->pend_link, &object->pending_ops);
63518 - fscache_stat(&fscache_n_op_pend);
63519 + fscache_stat_unchecked(&fscache_n_op_pend);
63520 } else if (!list_empty(&object->pending_ops)) {
63521 atomic_inc(&op->usage);
63522 list_add_tail(&op->pend_link, &object->pending_ops);
63523 - fscache_stat(&fscache_n_op_pend);
63524 + fscache_stat_unchecked(&fscache_n_op_pend);
63525 fscache_start_operations(object);
63526 } else {
63527 ASSERTCMP(object->n_exclusive, ==, 0);
63528 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
63529 object->n_ops++;
63530 atomic_inc(&op->usage);
63531 list_add_tail(&op->pend_link, &object->pending_ops);
63532 - fscache_stat(&fscache_n_op_pend);
63533 + fscache_stat_unchecked(&fscache_n_op_pend);
63534 ret = 0;
63535 } else if (fscache_object_is_dying(object)) {
63536 - fscache_stat(&fscache_n_op_rejected);
63537 + fscache_stat_unchecked(&fscache_n_op_rejected);
63538 op->state = FSCACHE_OP_ST_CANCELLED;
63539 ret = -ENOBUFS;
63540 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
63541 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
63542 ret = -EBUSY;
63543 if (op->state == FSCACHE_OP_ST_PENDING) {
63544 ASSERT(!list_empty(&op->pend_link));
63545 - fscache_stat(&fscache_n_op_cancelled);
63546 + fscache_stat_unchecked(&fscache_n_op_cancelled);
63547 list_del_init(&op->pend_link);
63548 if (do_cancel)
63549 do_cancel(op);
63550 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
63551 while (!list_empty(&object->pending_ops)) {
63552 op = list_entry(object->pending_ops.next,
63553 struct fscache_operation, pend_link);
63554 - fscache_stat(&fscache_n_op_cancelled);
63555 + fscache_stat_unchecked(&fscache_n_op_cancelled);
63556 list_del_init(&op->pend_link);
63557
63558 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
63559 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
63560 op->state, ==, FSCACHE_OP_ST_CANCELLED);
63561 op->state = FSCACHE_OP_ST_DEAD;
63562
63563 - fscache_stat(&fscache_n_op_release);
63564 + fscache_stat_unchecked(&fscache_n_op_release);
63565
63566 if (op->release) {
63567 op->release(op);
63568 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
63569 * lock, and defer it otherwise */
63570 if (!spin_trylock(&object->lock)) {
63571 _debug("defer put");
63572 - fscache_stat(&fscache_n_op_deferred_release);
63573 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
63574
63575 cache = object->cache;
63576 spin_lock(&cache->op_gc_list_lock);
63577 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
63578
63579 _debug("GC DEFERRED REL OBJ%x OP%x",
63580 object->debug_id, op->debug_id);
63581 - fscache_stat(&fscache_n_op_gc);
63582 + fscache_stat_unchecked(&fscache_n_op_gc);
63583
63584 ASSERTCMP(atomic_read(&op->usage), ==, 0);
63585 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
63586 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
63587 index ed70714..67f4982 100644
63588 --- a/fs/fscache/page.c
63589 +++ b/fs/fscache/page.c
63590 @@ -61,7 +61,7 @@ try_again:
63591 val = radix_tree_lookup(&cookie->stores, page->index);
63592 if (!val) {
63593 rcu_read_unlock();
63594 - fscache_stat(&fscache_n_store_vmscan_not_storing);
63595 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
63596 __fscache_uncache_page(cookie, page);
63597 return true;
63598 }
63599 @@ -91,11 +91,11 @@ try_again:
63600 spin_unlock(&cookie->stores_lock);
63601
63602 if (xpage) {
63603 - fscache_stat(&fscache_n_store_vmscan_cancelled);
63604 - fscache_stat(&fscache_n_store_radix_deletes);
63605 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
63606 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63607 ASSERTCMP(xpage, ==, page);
63608 } else {
63609 - fscache_stat(&fscache_n_store_vmscan_gone);
63610 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
63611 }
63612
63613 wake_up_bit(&cookie->flags, 0);
63614 @@ -110,11 +110,11 @@ page_busy:
63615 * sleeping on memory allocation, so we may need to impose a timeout
63616 * too. */
63617 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
63618 - fscache_stat(&fscache_n_store_vmscan_busy);
63619 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
63620 return false;
63621 }
63622
63623 - fscache_stat(&fscache_n_store_vmscan_wait);
63624 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
63625 __fscache_wait_on_page_write(cookie, page);
63626 gfp &= ~__GFP_WAIT;
63627 goto try_again;
63628 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63629 FSCACHE_COOKIE_STORING_TAG);
63630 if (!radix_tree_tag_get(&cookie->stores, page->index,
63631 FSCACHE_COOKIE_PENDING_TAG)) {
63632 - fscache_stat(&fscache_n_store_radix_deletes);
63633 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63634 xpage = radix_tree_delete(&cookie->stores, page->index);
63635 }
63636 spin_unlock(&cookie->stores_lock);
63637 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63638
63639 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63640
63641 - fscache_stat(&fscache_n_attr_changed_calls);
63642 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63643
63644 if (fscache_object_is_active(object)) {
63645 fscache_stat(&fscache_n_cop_attr_changed);
63646 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63647
63648 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63649
63650 - fscache_stat(&fscache_n_attr_changed);
63651 + fscache_stat_unchecked(&fscache_n_attr_changed);
63652
63653 op = kzalloc(sizeof(*op), GFP_KERNEL);
63654 if (!op) {
63655 - fscache_stat(&fscache_n_attr_changed_nomem);
63656 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63657 _leave(" = -ENOMEM");
63658 return -ENOMEM;
63659 }
63660 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63661 if (fscache_submit_exclusive_op(object, op) < 0)
63662 goto nobufs;
63663 spin_unlock(&cookie->lock);
63664 - fscache_stat(&fscache_n_attr_changed_ok);
63665 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63666 fscache_put_operation(op);
63667 _leave(" = 0");
63668 return 0;
63669 @@ -225,7 +225,7 @@ nobufs:
63670 kfree(op);
63671 if (wake_cookie)
63672 __fscache_wake_unused_cookie(cookie);
63673 - fscache_stat(&fscache_n_attr_changed_nobufs);
63674 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63675 _leave(" = %d", -ENOBUFS);
63676 return -ENOBUFS;
63677 }
63678 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63679 /* allocate a retrieval operation and attempt to submit it */
63680 op = kzalloc(sizeof(*op), GFP_NOIO);
63681 if (!op) {
63682 - fscache_stat(&fscache_n_retrievals_nomem);
63683 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63684 return NULL;
63685 }
63686
63687 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63688 return 0;
63689 }
63690
63691 - fscache_stat(&fscache_n_retrievals_wait);
63692 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
63693
63694 jif = jiffies;
63695 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63696 fscache_wait_bit_interruptible,
63697 TASK_INTERRUPTIBLE) != 0) {
63698 - fscache_stat(&fscache_n_retrievals_intr);
63699 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63700 _leave(" = -ERESTARTSYS");
63701 return -ERESTARTSYS;
63702 }
63703 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63704 */
63705 int fscache_wait_for_operation_activation(struct fscache_object *object,
63706 struct fscache_operation *op,
63707 - atomic_t *stat_op_waits,
63708 - atomic_t *stat_object_dead,
63709 + atomic_unchecked_t *stat_op_waits,
63710 + atomic_unchecked_t *stat_object_dead,
63711 void (*do_cancel)(struct fscache_operation *))
63712 {
63713 int ret;
63714 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63715
63716 _debug(">>> WT");
63717 if (stat_op_waits)
63718 - fscache_stat(stat_op_waits);
63719 + fscache_stat_unchecked(stat_op_waits);
63720 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63721 fscache_wait_bit_interruptible,
63722 TASK_INTERRUPTIBLE) != 0) {
63723 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63724 check_if_dead:
63725 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63726 if (stat_object_dead)
63727 - fscache_stat(stat_object_dead);
63728 + fscache_stat_unchecked(stat_object_dead);
63729 _leave(" = -ENOBUFS [cancelled]");
63730 return -ENOBUFS;
63731 }
63732 @@ -366,7 +366,7 @@ check_if_dead:
63733 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63734 fscache_cancel_op(op, do_cancel);
63735 if (stat_object_dead)
63736 - fscache_stat(stat_object_dead);
63737 + fscache_stat_unchecked(stat_object_dead);
63738 return -ENOBUFS;
63739 }
63740 return 0;
63741 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63742
63743 _enter("%p,%p,,,", cookie, page);
63744
63745 - fscache_stat(&fscache_n_retrievals);
63746 + fscache_stat_unchecked(&fscache_n_retrievals);
63747
63748 if (hlist_empty(&cookie->backing_objects))
63749 goto nobufs;
63750 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63751 goto nobufs_unlock_dec;
63752 spin_unlock(&cookie->lock);
63753
63754 - fscache_stat(&fscache_n_retrieval_ops);
63755 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63756
63757 /* pin the netfs read context in case we need to do the actual netfs
63758 * read because we've encountered a cache read failure */
63759 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63760
63761 error:
63762 if (ret == -ENOMEM)
63763 - fscache_stat(&fscache_n_retrievals_nomem);
63764 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63765 else if (ret == -ERESTARTSYS)
63766 - fscache_stat(&fscache_n_retrievals_intr);
63767 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63768 else if (ret == -ENODATA)
63769 - fscache_stat(&fscache_n_retrievals_nodata);
63770 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63771 else if (ret < 0)
63772 - fscache_stat(&fscache_n_retrievals_nobufs);
63773 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63774 else
63775 - fscache_stat(&fscache_n_retrievals_ok);
63776 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63777
63778 fscache_put_retrieval(op);
63779 _leave(" = %d", ret);
63780 @@ -490,7 +490,7 @@ nobufs_unlock:
63781 __fscache_wake_unused_cookie(cookie);
63782 kfree(op);
63783 nobufs:
63784 - fscache_stat(&fscache_n_retrievals_nobufs);
63785 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63786 _leave(" = -ENOBUFS");
63787 return -ENOBUFS;
63788 }
63789 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63790
63791 _enter("%p,,%d,,,", cookie, *nr_pages);
63792
63793 - fscache_stat(&fscache_n_retrievals);
63794 + fscache_stat_unchecked(&fscache_n_retrievals);
63795
63796 if (hlist_empty(&cookie->backing_objects))
63797 goto nobufs;
63798 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63799 goto nobufs_unlock_dec;
63800 spin_unlock(&cookie->lock);
63801
63802 - fscache_stat(&fscache_n_retrieval_ops);
63803 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63804
63805 /* pin the netfs read context in case we need to do the actual netfs
63806 * read because we've encountered a cache read failure */
63807 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63808
63809 error:
63810 if (ret == -ENOMEM)
63811 - fscache_stat(&fscache_n_retrievals_nomem);
63812 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63813 else if (ret == -ERESTARTSYS)
63814 - fscache_stat(&fscache_n_retrievals_intr);
63815 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63816 else if (ret == -ENODATA)
63817 - fscache_stat(&fscache_n_retrievals_nodata);
63818 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63819 else if (ret < 0)
63820 - fscache_stat(&fscache_n_retrievals_nobufs);
63821 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63822 else
63823 - fscache_stat(&fscache_n_retrievals_ok);
63824 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63825
63826 fscache_put_retrieval(op);
63827 _leave(" = %d", ret);
63828 @@ -621,7 +621,7 @@ nobufs_unlock:
63829 if (wake_cookie)
63830 __fscache_wake_unused_cookie(cookie);
63831 nobufs:
63832 - fscache_stat(&fscache_n_retrievals_nobufs);
63833 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63834 _leave(" = -ENOBUFS");
63835 return -ENOBUFS;
63836 }
63837 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63838
63839 _enter("%p,%p,,,", cookie, page);
63840
63841 - fscache_stat(&fscache_n_allocs);
63842 + fscache_stat_unchecked(&fscache_n_allocs);
63843
63844 if (hlist_empty(&cookie->backing_objects))
63845 goto nobufs;
63846 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63847 goto nobufs_unlock_dec;
63848 spin_unlock(&cookie->lock);
63849
63850 - fscache_stat(&fscache_n_alloc_ops);
63851 + fscache_stat_unchecked(&fscache_n_alloc_ops);
63852
63853 ret = fscache_wait_for_operation_activation(
63854 object, &op->op,
63855 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63856
63857 error:
63858 if (ret == -ERESTARTSYS)
63859 - fscache_stat(&fscache_n_allocs_intr);
63860 + fscache_stat_unchecked(&fscache_n_allocs_intr);
63861 else if (ret < 0)
63862 - fscache_stat(&fscache_n_allocs_nobufs);
63863 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63864 else
63865 - fscache_stat(&fscache_n_allocs_ok);
63866 + fscache_stat_unchecked(&fscache_n_allocs_ok);
63867
63868 fscache_put_retrieval(op);
63869 _leave(" = %d", ret);
63870 @@ -715,7 +715,7 @@ nobufs_unlock:
63871 if (wake_cookie)
63872 __fscache_wake_unused_cookie(cookie);
63873 nobufs:
63874 - fscache_stat(&fscache_n_allocs_nobufs);
63875 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63876 _leave(" = -ENOBUFS");
63877 return -ENOBUFS;
63878 }
63879 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63880
63881 spin_lock(&cookie->stores_lock);
63882
63883 - fscache_stat(&fscache_n_store_calls);
63884 + fscache_stat_unchecked(&fscache_n_store_calls);
63885
63886 /* find a page to store */
63887 page = NULL;
63888 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63889 page = results[0];
63890 _debug("gang %d [%lx]", n, page->index);
63891 if (page->index > op->store_limit) {
63892 - fscache_stat(&fscache_n_store_pages_over_limit);
63893 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
63894 goto superseded;
63895 }
63896
63897 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63898 spin_unlock(&cookie->stores_lock);
63899 spin_unlock(&object->lock);
63900
63901 - fscache_stat(&fscache_n_store_pages);
63902 + fscache_stat_unchecked(&fscache_n_store_pages);
63903 fscache_stat(&fscache_n_cop_write_page);
63904 ret = object->cache->ops->write_page(op, page);
63905 fscache_stat_d(&fscache_n_cop_write_page);
63906 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63907 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63908 ASSERT(PageFsCache(page));
63909
63910 - fscache_stat(&fscache_n_stores);
63911 + fscache_stat_unchecked(&fscache_n_stores);
63912
63913 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
63914 _leave(" = -ENOBUFS [invalidating]");
63915 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63916 spin_unlock(&cookie->stores_lock);
63917 spin_unlock(&object->lock);
63918
63919 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
63920 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63921 op->store_limit = object->store_limit;
63922
63923 __fscache_use_cookie(cookie);
63924 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63925
63926 spin_unlock(&cookie->lock);
63927 radix_tree_preload_end();
63928 - fscache_stat(&fscache_n_store_ops);
63929 - fscache_stat(&fscache_n_stores_ok);
63930 + fscache_stat_unchecked(&fscache_n_store_ops);
63931 + fscache_stat_unchecked(&fscache_n_stores_ok);
63932
63933 /* the work queue now carries its own ref on the object */
63934 fscache_put_operation(&op->op);
63935 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63936 return 0;
63937
63938 already_queued:
63939 - fscache_stat(&fscache_n_stores_again);
63940 + fscache_stat_unchecked(&fscache_n_stores_again);
63941 already_pending:
63942 spin_unlock(&cookie->stores_lock);
63943 spin_unlock(&object->lock);
63944 spin_unlock(&cookie->lock);
63945 radix_tree_preload_end();
63946 kfree(op);
63947 - fscache_stat(&fscache_n_stores_ok);
63948 + fscache_stat_unchecked(&fscache_n_stores_ok);
63949 _leave(" = 0");
63950 return 0;
63951
63952 @@ -1024,14 +1024,14 @@ nobufs:
63953 kfree(op);
63954 if (wake_cookie)
63955 __fscache_wake_unused_cookie(cookie);
63956 - fscache_stat(&fscache_n_stores_nobufs);
63957 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
63958 _leave(" = -ENOBUFS");
63959 return -ENOBUFS;
63960
63961 nomem_free:
63962 kfree(op);
63963 nomem:
63964 - fscache_stat(&fscache_n_stores_oom);
63965 + fscache_stat_unchecked(&fscache_n_stores_oom);
63966 _leave(" = -ENOMEM");
63967 return -ENOMEM;
63968 }
63969 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63970 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63971 ASSERTCMP(page, !=, NULL);
63972
63973 - fscache_stat(&fscache_n_uncaches);
63974 + fscache_stat_unchecked(&fscache_n_uncaches);
63975
63976 /* cache withdrawal may beat us to it */
63977 if (!PageFsCache(page))
63978 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63979 struct fscache_cookie *cookie = op->op.object->cookie;
63980
63981 #ifdef CONFIG_FSCACHE_STATS
63982 - atomic_inc(&fscache_n_marks);
63983 + atomic_inc_unchecked(&fscache_n_marks);
63984 #endif
63985
63986 _debug("- mark %p{%lx}", page, page->index);
63987 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63988 index 40d13c7..ddf52b9 100644
63989 --- a/fs/fscache/stats.c
63990 +++ b/fs/fscache/stats.c
63991 @@ -18,99 +18,99 @@
63992 /*
63993 * operation counters
63994 */
63995 -atomic_t fscache_n_op_pend;
63996 -atomic_t fscache_n_op_run;
63997 -atomic_t fscache_n_op_enqueue;
63998 -atomic_t fscache_n_op_requeue;
63999 -atomic_t fscache_n_op_deferred_release;
64000 -atomic_t fscache_n_op_release;
64001 -atomic_t fscache_n_op_gc;
64002 -atomic_t fscache_n_op_cancelled;
64003 -atomic_t fscache_n_op_rejected;
64004 +atomic_unchecked_t fscache_n_op_pend;
64005 +atomic_unchecked_t fscache_n_op_run;
64006 +atomic_unchecked_t fscache_n_op_enqueue;
64007 +atomic_unchecked_t fscache_n_op_requeue;
64008 +atomic_unchecked_t fscache_n_op_deferred_release;
64009 +atomic_unchecked_t fscache_n_op_release;
64010 +atomic_unchecked_t fscache_n_op_gc;
64011 +atomic_unchecked_t fscache_n_op_cancelled;
64012 +atomic_unchecked_t fscache_n_op_rejected;
64013
64014 -atomic_t fscache_n_attr_changed;
64015 -atomic_t fscache_n_attr_changed_ok;
64016 -atomic_t fscache_n_attr_changed_nobufs;
64017 -atomic_t fscache_n_attr_changed_nomem;
64018 -atomic_t fscache_n_attr_changed_calls;
64019 +atomic_unchecked_t fscache_n_attr_changed;
64020 +atomic_unchecked_t fscache_n_attr_changed_ok;
64021 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
64022 +atomic_unchecked_t fscache_n_attr_changed_nomem;
64023 +atomic_unchecked_t fscache_n_attr_changed_calls;
64024
64025 -atomic_t fscache_n_allocs;
64026 -atomic_t fscache_n_allocs_ok;
64027 -atomic_t fscache_n_allocs_wait;
64028 -atomic_t fscache_n_allocs_nobufs;
64029 -atomic_t fscache_n_allocs_intr;
64030 -atomic_t fscache_n_allocs_object_dead;
64031 -atomic_t fscache_n_alloc_ops;
64032 -atomic_t fscache_n_alloc_op_waits;
64033 +atomic_unchecked_t fscache_n_allocs;
64034 +atomic_unchecked_t fscache_n_allocs_ok;
64035 +atomic_unchecked_t fscache_n_allocs_wait;
64036 +atomic_unchecked_t fscache_n_allocs_nobufs;
64037 +atomic_unchecked_t fscache_n_allocs_intr;
64038 +atomic_unchecked_t fscache_n_allocs_object_dead;
64039 +atomic_unchecked_t fscache_n_alloc_ops;
64040 +atomic_unchecked_t fscache_n_alloc_op_waits;
64041
64042 -atomic_t fscache_n_retrievals;
64043 -atomic_t fscache_n_retrievals_ok;
64044 -atomic_t fscache_n_retrievals_wait;
64045 -atomic_t fscache_n_retrievals_nodata;
64046 -atomic_t fscache_n_retrievals_nobufs;
64047 -atomic_t fscache_n_retrievals_intr;
64048 -atomic_t fscache_n_retrievals_nomem;
64049 -atomic_t fscache_n_retrievals_object_dead;
64050 -atomic_t fscache_n_retrieval_ops;
64051 -atomic_t fscache_n_retrieval_op_waits;
64052 +atomic_unchecked_t fscache_n_retrievals;
64053 +atomic_unchecked_t fscache_n_retrievals_ok;
64054 +atomic_unchecked_t fscache_n_retrievals_wait;
64055 +atomic_unchecked_t fscache_n_retrievals_nodata;
64056 +atomic_unchecked_t fscache_n_retrievals_nobufs;
64057 +atomic_unchecked_t fscache_n_retrievals_intr;
64058 +atomic_unchecked_t fscache_n_retrievals_nomem;
64059 +atomic_unchecked_t fscache_n_retrievals_object_dead;
64060 +atomic_unchecked_t fscache_n_retrieval_ops;
64061 +atomic_unchecked_t fscache_n_retrieval_op_waits;
64062
64063 -atomic_t fscache_n_stores;
64064 -atomic_t fscache_n_stores_ok;
64065 -atomic_t fscache_n_stores_again;
64066 -atomic_t fscache_n_stores_nobufs;
64067 -atomic_t fscache_n_stores_oom;
64068 -atomic_t fscache_n_store_ops;
64069 -atomic_t fscache_n_store_calls;
64070 -atomic_t fscache_n_store_pages;
64071 -atomic_t fscache_n_store_radix_deletes;
64072 -atomic_t fscache_n_store_pages_over_limit;
64073 +atomic_unchecked_t fscache_n_stores;
64074 +atomic_unchecked_t fscache_n_stores_ok;
64075 +atomic_unchecked_t fscache_n_stores_again;
64076 +atomic_unchecked_t fscache_n_stores_nobufs;
64077 +atomic_unchecked_t fscache_n_stores_oom;
64078 +atomic_unchecked_t fscache_n_store_ops;
64079 +atomic_unchecked_t fscache_n_store_calls;
64080 +atomic_unchecked_t fscache_n_store_pages;
64081 +atomic_unchecked_t fscache_n_store_radix_deletes;
64082 +atomic_unchecked_t fscache_n_store_pages_over_limit;
64083
64084 -atomic_t fscache_n_store_vmscan_not_storing;
64085 -atomic_t fscache_n_store_vmscan_gone;
64086 -atomic_t fscache_n_store_vmscan_busy;
64087 -atomic_t fscache_n_store_vmscan_cancelled;
64088 -atomic_t fscache_n_store_vmscan_wait;
64089 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
64090 +atomic_unchecked_t fscache_n_store_vmscan_gone;
64091 +atomic_unchecked_t fscache_n_store_vmscan_busy;
64092 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
64093 +atomic_unchecked_t fscache_n_store_vmscan_wait;
64094
64095 -atomic_t fscache_n_marks;
64096 -atomic_t fscache_n_uncaches;
64097 +atomic_unchecked_t fscache_n_marks;
64098 +atomic_unchecked_t fscache_n_uncaches;
64099
64100 -atomic_t fscache_n_acquires;
64101 -atomic_t fscache_n_acquires_null;
64102 -atomic_t fscache_n_acquires_no_cache;
64103 -atomic_t fscache_n_acquires_ok;
64104 -atomic_t fscache_n_acquires_nobufs;
64105 -atomic_t fscache_n_acquires_oom;
64106 +atomic_unchecked_t fscache_n_acquires;
64107 +atomic_unchecked_t fscache_n_acquires_null;
64108 +atomic_unchecked_t fscache_n_acquires_no_cache;
64109 +atomic_unchecked_t fscache_n_acquires_ok;
64110 +atomic_unchecked_t fscache_n_acquires_nobufs;
64111 +atomic_unchecked_t fscache_n_acquires_oom;
64112
64113 -atomic_t fscache_n_invalidates;
64114 -atomic_t fscache_n_invalidates_run;
64115 +atomic_unchecked_t fscache_n_invalidates;
64116 +atomic_unchecked_t fscache_n_invalidates_run;
64117
64118 -atomic_t fscache_n_updates;
64119 -atomic_t fscache_n_updates_null;
64120 -atomic_t fscache_n_updates_run;
64121 +atomic_unchecked_t fscache_n_updates;
64122 +atomic_unchecked_t fscache_n_updates_null;
64123 +atomic_unchecked_t fscache_n_updates_run;
64124
64125 -atomic_t fscache_n_relinquishes;
64126 -atomic_t fscache_n_relinquishes_null;
64127 -atomic_t fscache_n_relinquishes_waitcrt;
64128 -atomic_t fscache_n_relinquishes_retire;
64129 +atomic_unchecked_t fscache_n_relinquishes;
64130 +atomic_unchecked_t fscache_n_relinquishes_null;
64131 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
64132 +atomic_unchecked_t fscache_n_relinquishes_retire;
64133
64134 -atomic_t fscache_n_cookie_index;
64135 -atomic_t fscache_n_cookie_data;
64136 -atomic_t fscache_n_cookie_special;
64137 +atomic_unchecked_t fscache_n_cookie_index;
64138 +atomic_unchecked_t fscache_n_cookie_data;
64139 +atomic_unchecked_t fscache_n_cookie_special;
64140
64141 -atomic_t fscache_n_object_alloc;
64142 -atomic_t fscache_n_object_no_alloc;
64143 -atomic_t fscache_n_object_lookups;
64144 -atomic_t fscache_n_object_lookups_negative;
64145 -atomic_t fscache_n_object_lookups_positive;
64146 -atomic_t fscache_n_object_lookups_timed_out;
64147 -atomic_t fscache_n_object_created;
64148 -atomic_t fscache_n_object_avail;
64149 -atomic_t fscache_n_object_dead;
64150 +atomic_unchecked_t fscache_n_object_alloc;
64151 +atomic_unchecked_t fscache_n_object_no_alloc;
64152 +atomic_unchecked_t fscache_n_object_lookups;
64153 +atomic_unchecked_t fscache_n_object_lookups_negative;
64154 +atomic_unchecked_t fscache_n_object_lookups_positive;
64155 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
64156 +atomic_unchecked_t fscache_n_object_created;
64157 +atomic_unchecked_t fscache_n_object_avail;
64158 +atomic_unchecked_t fscache_n_object_dead;
64159
64160 -atomic_t fscache_n_checkaux_none;
64161 -atomic_t fscache_n_checkaux_okay;
64162 -atomic_t fscache_n_checkaux_update;
64163 -atomic_t fscache_n_checkaux_obsolete;
64164 +atomic_unchecked_t fscache_n_checkaux_none;
64165 +atomic_unchecked_t fscache_n_checkaux_okay;
64166 +atomic_unchecked_t fscache_n_checkaux_update;
64167 +atomic_unchecked_t fscache_n_checkaux_obsolete;
64168
64169 atomic_t fscache_n_cop_alloc_object;
64170 atomic_t fscache_n_cop_lookup_object;
64171 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
64172 seq_puts(m, "FS-Cache statistics\n");
64173
64174 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
64175 - atomic_read(&fscache_n_cookie_index),
64176 - atomic_read(&fscache_n_cookie_data),
64177 - atomic_read(&fscache_n_cookie_special));
64178 + atomic_read_unchecked(&fscache_n_cookie_index),
64179 + atomic_read_unchecked(&fscache_n_cookie_data),
64180 + atomic_read_unchecked(&fscache_n_cookie_special));
64181
64182 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
64183 - atomic_read(&fscache_n_object_alloc),
64184 - atomic_read(&fscache_n_object_no_alloc),
64185 - atomic_read(&fscache_n_object_avail),
64186 - atomic_read(&fscache_n_object_dead));
64187 + atomic_read_unchecked(&fscache_n_object_alloc),
64188 + atomic_read_unchecked(&fscache_n_object_no_alloc),
64189 + atomic_read_unchecked(&fscache_n_object_avail),
64190 + atomic_read_unchecked(&fscache_n_object_dead));
64191 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
64192 - atomic_read(&fscache_n_checkaux_none),
64193 - atomic_read(&fscache_n_checkaux_okay),
64194 - atomic_read(&fscache_n_checkaux_update),
64195 - atomic_read(&fscache_n_checkaux_obsolete));
64196 + atomic_read_unchecked(&fscache_n_checkaux_none),
64197 + atomic_read_unchecked(&fscache_n_checkaux_okay),
64198 + atomic_read_unchecked(&fscache_n_checkaux_update),
64199 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
64200
64201 seq_printf(m, "Pages : mrk=%u unc=%u\n",
64202 - atomic_read(&fscache_n_marks),
64203 - atomic_read(&fscache_n_uncaches));
64204 + atomic_read_unchecked(&fscache_n_marks),
64205 + atomic_read_unchecked(&fscache_n_uncaches));
64206
64207 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
64208 " oom=%u\n",
64209 - atomic_read(&fscache_n_acquires),
64210 - atomic_read(&fscache_n_acquires_null),
64211 - atomic_read(&fscache_n_acquires_no_cache),
64212 - atomic_read(&fscache_n_acquires_ok),
64213 - atomic_read(&fscache_n_acquires_nobufs),
64214 - atomic_read(&fscache_n_acquires_oom));
64215 + atomic_read_unchecked(&fscache_n_acquires),
64216 + atomic_read_unchecked(&fscache_n_acquires_null),
64217 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
64218 + atomic_read_unchecked(&fscache_n_acquires_ok),
64219 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
64220 + atomic_read_unchecked(&fscache_n_acquires_oom));
64221
64222 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
64223 - atomic_read(&fscache_n_object_lookups),
64224 - atomic_read(&fscache_n_object_lookups_negative),
64225 - atomic_read(&fscache_n_object_lookups_positive),
64226 - atomic_read(&fscache_n_object_created),
64227 - atomic_read(&fscache_n_object_lookups_timed_out));
64228 + atomic_read_unchecked(&fscache_n_object_lookups),
64229 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
64230 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
64231 + atomic_read_unchecked(&fscache_n_object_created),
64232 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
64233
64234 seq_printf(m, "Invals : n=%u run=%u\n",
64235 - atomic_read(&fscache_n_invalidates),
64236 - atomic_read(&fscache_n_invalidates_run));
64237 + atomic_read_unchecked(&fscache_n_invalidates),
64238 + atomic_read_unchecked(&fscache_n_invalidates_run));
64239
64240 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
64241 - atomic_read(&fscache_n_updates),
64242 - atomic_read(&fscache_n_updates_null),
64243 - atomic_read(&fscache_n_updates_run));
64244 + atomic_read_unchecked(&fscache_n_updates),
64245 + atomic_read_unchecked(&fscache_n_updates_null),
64246 + atomic_read_unchecked(&fscache_n_updates_run));
64247
64248 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
64249 - atomic_read(&fscache_n_relinquishes),
64250 - atomic_read(&fscache_n_relinquishes_null),
64251 - atomic_read(&fscache_n_relinquishes_waitcrt),
64252 - atomic_read(&fscache_n_relinquishes_retire));
64253 + atomic_read_unchecked(&fscache_n_relinquishes),
64254 + atomic_read_unchecked(&fscache_n_relinquishes_null),
64255 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
64256 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
64257
64258 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
64259 - atomic_read(&fscache_n_attr_changed),
64260 - atomic_read(&fscache_n_attr_changed_ok),
64261 - atomic_read(&fscache_n_attr_changed_nobufs),
64262 - atomic_read(&fscache_n_attr_changed_nomem),
64263 - atomic_read(&fscache_n_attr_changed_calls));
64264 + atomic_read_unchecked(&fscache_n_attr_changed),
64265 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
64266 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
64267 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
64268 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
64269
64270 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
64271 - atomic_read(&fscache_n_allocs),
64272 - atomic_read(&fscache_n_allocs_ok),
64273 - atomic_read(&fscache_n_allocs_wait),
64274 - atomic_read(&fscache_n_allocs_nobufs),
64275 - atomic_read(&fscache_n_allocs_intr));
64276 + atomic_read_unchecked(&fscache_n_allocs),
64277 + atomic_read_unchecked(&fscache_n_allocs_ok),
64278 + atomic_read_unchecked(&fscache_n_allocs_wait),
64279 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
64280 + atomic_read_unchecked(&fscache_n_allocs_intr));
64281 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
64282 - atomic_read(&fscache_n_alloc_ops),
64283 - atomic_read(&fscache_n_alloc_op_waits),
64284 - atomic_read(&fscache_n_allocs_object_dead));
64285 + atomic_read_unchecked(&fscache_n_alloc_ops),
64286 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
64287 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
64288
64289 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
64290 " int=%u oom=%u\n",
64291 - atomic_read(&fscache_n_retrievals),
64292 - atomic_read(&fscache_n_retrievals_ok),
64293 - atomic_read(&fscache_n_retrievals_wait),
64294 - atomic_read(&fscache_n_retrievals_nodata),
64295 - atomic_read(&fscache_n_retrievals_nobufs),
64296 - atomic_read(&fscache_n_retrievals_intr),
64297 - atomic_read(&fscache_n_retrievals_nomem));
64298 + atomic_read_unchecked(&fscache_n_retrievals),
64299 + atomic_read_unchecked(&fscache_n_retrievals_ok),
64300 + atomic_read_unchecked(&fscache_n_retrievals_wait),
64301 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
64302 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
64303 + atomic_read_unchecked(&fscache_n_retrievals_intr),
64304 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
64305 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
64306 - atomic_read(&fscache_n_retrieval_ops),
64307 - atomic_read(&fscache_n_retrieval_op_waits),
64308 - atomic_read(&fscache_n_retrievals_object_dead));
64309 + atomic_read_unchecked(&fscache_n_retrieval_ops),
64310 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
64311 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
64312
64313 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
64314 - atomic_read(&fscache_n_stores),
64315 - atomic_read(&fscache_n_stores_ok),
64316 - atomic_read(&fscache_n_stores_again),
64317 - atomic_read(&fscache_n_stores_nobufs),
64318 - atomic_read(&fscache_n_stores_oom));
64319 + atomic_read_unchecked(&fscache_n_stores),
64320 + atomic_read_unchecked(&fscache_n_stores_ok),
64321 + atomic_read_unchecked(&fscache_n_stores_again),
64322 + atomic_read_unchecked(&fscache_n_stores_nobufs),
64323 + atomic_read_unchecked(&fscache_n_stores_oom));
64324 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
64325 - atomic_read(&fscache_n_store_ops),
64326 - atomic_read(&fscache_n_store_calls),
64327 - atomic_read(&fscache_n_store_pages),
64328 - atomic_read(&fscache_n_store_radix_deletes),
64329 - atomic_read(&fscache_n_store_pages_over_limit));
64330 + atomic_read_unchecked(&fscache_n_store_ops),
64331 + atomic_read_unchecked(&fscache_n_store_calls),
64332 + atomic_read_unchecked(&fscache_n_store_pages),
64333 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
64334 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
64335
64336 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
64337 - atomic_read(&fscache_n_store_vmscan_not_storing),
64338 - atomic_read(&fscache_n_store_vmscan_gone),
64339 - atomic_read(&fscache_n_store_vmscan_busy),
64340 - atomic_read(&fscache_n_store_vmscan_cancelled),
64341 - atomic_read(&fscache_n_store_vmscan_wait));
64342 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
64343 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
64344 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
64345 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
64346 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
64347
64348 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
64349 - atomic_read(&fscache_n_op_pend),
64350 - atomic_read(&fscache_n_op_run),
64351 - atomic_read(&fscache_n_op_enqueue),
64352 - atomic_read(&fscache_n_op_cancelled),
64353 - atomic_read(&fscache_n_op_rejected));
64354 + atomic_read_unchecked(&fscache_n_op_pend),
64355 + atomic_read_unchecked(&fscache_n_op_run),
64356 + atomic_read_unchecked(&fscache_n_op_enqueue),
64357 + atomic_read_unchecked(&fscache_n_op_cancelled),
64358 + atomic_read_unchecked(&fscache_n_op_rejected));
64359 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
64360 - atomic_read(&fscache_n_op_deferred_release),
64361 - atomic_read(&fscache_n_op_release),
64362 - atomic_read(&fscache_n_op_gc));
64363 + atomic_read_unchecked(&fscache_n_op_deferred_release),
64364 + atomic_read_unchecked(&fscache_n_op_release),
64365 + atomic_read_unchecked(&fscache_n_op_gc));
64366
64367 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
64368 atomic_read(&fscache_n_cop_alloc_object),
64369 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
64370 index 966ace8..030a03a 100644
64371 --- a/fs/fuse/cuse.c
64372 +++ b/fs/fuse/cuse.c
64373 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
64374 INIT_LIST_HEAD(&cuse_conntbl[i]);
64375
64376 /* inherit and extend fuse_dev_operations */
64377 - cuse_channel_fops = fuse_dev_operations;
64378 - cuse_channel_fops.owner = THIS_MODULE;
64379 - cuse_channel_fops.open = cuse_channel_open;
64380 - cuse_channel_fops.release = cuse_channel_release;
64381 + pax_open_kernel();
64382 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
64383 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
64384 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
64385 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
64386 + pax_close_kernel();
64387
64388 cuse_class = class_create(THIS_MODULE, "cuse");
64389 if (IS_ERR(cuse_class))
64390 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
64391 index ca88731..8e9c55d 100644
64392 --- a/fs/fuse/dev.c
64393 +++ b/fs/fuse/dev.c
64394 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64395 ret = 0;
64396 pipe_lock(pipe);
64397
64398 - if (!pipe->readers) {
64399 + if (!atomic_read(&pipe->readers)) {
64400 send_sig(SIGPIPE, current, 0);
64401 if (!ret)
64402 ret = -EPIPE;
64403 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64404 page_nr++;
64405 ret += buf->len;
64406
64407 - if (pipe->files)
64408 + if (atomic_read(&pipe->files))
64409 do_wakeup = 1;
64410 }
64411
64412 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
64413 index 0c60482..025724f 100644
64414 --- a/fs/fuse/dir.c
64415 +++ b/fs/fuse/dir.c
64416 @@ -1485,7 +1485,7 @@ static char *read_link(struct dentry *dentry)
64417 return link;
64418 }
64419
64420 -static void free_link(char *link)
64421 +static void free_link(const char *link)
64422 {
64423 if (!IS_ERR(link))
64424 free_page((unsigned long) link);
64425 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
64426 index bb529f3..454c253 100644
64427 --- a/fs/hostfs/hostfs_kern.c
64428 +++ b/fs/hostfs/hostfs_kern.c
64429 @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64430
64431 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
64432 {
64433 - char *s = nd_get_link(nd);
64434 + const char *s = nd_get_link(nd);
64435 if (!IS_ERR(s))
64436 __putname(s);
64437 }
64438 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
64439 index 1e2872b..7aea000 100644
64440 --- a/fs/hugetlbfs/inode.c
64441 +++ b/fs/hugetlbfs/inode.c
64442 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64443 struct mm_struct *mm = current->mm;
64444 struct vm_area_struct *vma;
64445 struct hstate *h = hstate_file(file);
64446 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
64447 struct vm_unmapped_area_info info;
64448
64449 if (len & ~huge_page_mask(h))
64450 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64451 return addr;
64452 }
64453
64454 +#ifdef CONFIG_PAX_RANDMMAP
64455 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
64456 +#endif
64457 +
64458 if (addr) {
64459 addr = ALIGN(addr, huge_page_size(h));
64460 vma = find_vma(mm, addr);
64461 - if (TASK_SIZE - len >= addr &&
64462 - (!vma || addr + len <= vma->vm_start))
64463 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
64464 return addr;
64465 }
64466
64467 info.flags = 0;
64468 info.length = len;
64469 info.low_limit = TASK_UNMAPPED_BASE;
64470 +
64471 +#ifdef CONFIG_PAX_RANDMMAP
64472 + if (mm->pax_flags & MF_PAX_RANDMMAP)
64473 + info.low_limit += mm->delta_mmap;
64474 +#endif
64475 +
64476 info.high_limit = TASK_SIZE;
64477 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
64478 info.align_offset = 0;
64479 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
64480 };
64481 MODULE_ALIAS_FS("hugetlbfs");
64482
64483 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64484 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64485
64486 static int can_do_hugetlb_shm(void)
64487 {
64488 diff --git a/fs/inode.c b/fs/inode.c
64489 index 6eecb7f..abec305 100644
64490 --- a/fs/inode.c
64491 +++ b/fs/inode.c
64492 @@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
64493 unsigned int *p = &get_cpu_var(last_ino);
64494 unsigned int res = *p;
64495
64496 +start:
64497 +
64498 #ifdef CONFIG_SMP
64499 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
64500 - static atomic_t shared_last_ino;
64501 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
64502 + static atomic_unchecked_t shared_last_ino;
64503 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
64504
64505 res = next - LAST_INO_BATCH;
64506 }
64507 #endif
64508
64509 - *p = ++res;
64510 + if (unlikely(!++res))
64511 + goto start; /* never zero */
64512 + *p = res;
64513 put_cpu_var(last_ino);
64514 return res;
64515 }
64516 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
64517 index 4a6cf28..d3a29d3 100644
64518 --- a/fs/jffs2/erase.c
64519 +++ b/fs/jffs2/erase.c
64520 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
64521 struct jffs2_unknown_node marker = {
64522 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
64523 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64524 - .totlen = cpu_to_je32(c->cleanmarker_size)
64525 + .totlen = cpu_to_je32(c->cleanmarker_size),
64526 + .hdr_crc = cpu_to_je32(0)
64527 };
64528
64529 jffs2_prealloc_raw_node_refs(c, jeb, 1);
64530 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
64531 index a6597d6..41b30ec 100644
64532 --- a/fs/jffs2/wbuf.c
64533 +++ b/fs/jffs2/wbuf.c
64534 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
64535 {
64536 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
64537 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64538 - .totlen = constant_cpu_to_je32(8)
64539 + .totlen = constant_cpu_to_je32(8),
64540 + .hdr_crc = constant_cpu_to_je32(0)
64541 };
64542
64543 /*
64544 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
64545 index adf8cb0..bb935fa 100644
64546 --- a/fs/jfs/super.c
64547 +++ b/fs/jfs/super.c
64548 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
64549
64550 jfs_inode_cachep =
64551 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
64552 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
64553 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
64554 init_once);
64555 if (jfs_inode_cachep == NULL)
64556 return -ENOMEM;
64557 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
64558 index a693f5b..82276a1 100644
64559 --- a/fs/kernfs/dir.c
64560 +++ b/fs/kernfs/dir.c
64561 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
64562 *
64563 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64564 */
64565 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
64566 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
64567 {
64568 unsigned long hash = init_name_hash();
64569 unsigned int len = strlen(name);
64570 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
64571 index d895b4b..0b8af77 100644
64572 --- a/fs/kernfs/file.c
64573 +++ b/fs/kernfs/file.c
64574 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
64575
64576 struct kernfs_open_node {
64577 atomic_t refcnt;
64578 - atomic_t event;
64579 + atomic_unchecked_t event;
64580 wait_queue_head_t poll;
64581 struct list_head files; /* goes through kernfs_open_file.list */
64582 };
64583 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
64584 {
64585 struct kernfs_open_file *of = sf->private;
64586
64587 - of->event = atomic_read(&of->kn->attr.open->event);
64588 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
64589
64590 return of->kn->attr.ops->seq_show(sf, v);
64591 }
64592 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
64593 return ret;
64594 }
64595
64596 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64597 - void *buf, int len, int write)
64598 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64599 + void *buf, size_t len, int write)
64600 {
64601 struct file *file = vma->vm_file;
64602 struct kernfs_open_file *of = kernfs_of(file);
64603 - int ret;
64604 + ssize_t ret;
64605
64606 if (!of->vm_ops)
64607 return -EINVAL;
64608 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
64609 return -ENOMEM;
64610
64611 atomic_set(&new_on->refcnt, 0);
64612 - atomic_set(&new_on->event, 1);
64613 + atomic_set_unchecked(&new_on->event, 1);
64614 init_waitqueue_head(&new_on->poll);
64615 INIT_LIST_HEAD(&new_on->files);
64616 goto retry;
64617 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
64618
64619 kernfs_put_active(kn);
64620
64621 - if (of->event != atomic_read(&on->event))
64622 + if (of->event != atomic_read_unchecked(&on->event))
64623 goto trigger;
64624
64625 return DEFAULT_POLLMASK;
64626 @@ -818,7 +818,7 @@ repeat:
64627
64628 on = kn->attr.open;
64629 if (on) {
64630 - atomic_inc(&on->event);
64631 + atomic_inc_unchecked(&on->event);
64632 wake_up_interruptible(&on->poll);
64633 }
64634
64635 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64636 index 8a19889..4c3069a 100644
64637 --- a/fs/kernfs/symlink.c
64638 +++ b/fs/kernfs/symlink.c
64639 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64640 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64641 void *cookie)
64642 {
64643 - char *page = nd_get_link(nd);
64644 + const char *page = nd_get_link(nd);
64645 if (!IS_ERR(page))
64646 free_page((unsigned long)page);
64647 }
64648 diff --git a/fs/libfs.c b/fs/libfs.c
64649 index 88e3e00..979c262 100644
64650 --- a/fs/libfs.c
64651 +++ b/fs/libfs.c
64652 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64653
64654 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64655 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
64656 + char d_name[sizeof(next->d_iname)];
64657 + const unsigned char *name;
64658 +
64659 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64660 if (!simple_positive(next)) {
64661 spin_unlock(&next->d_lock);
64662 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64663
64664 spin_unlock(&next->d_lock);
64665 spin_unlock(&dentry->d_lock);
64666 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64667 + name = next->d_name.name;
64668 + if (name == next->d_iname) {
64669 + memcpy(d_name, name, next->d_name.len);
64670 + name = d_name;
64671 + }
64672 + if (!dir_emit(ctx, name, next->d_name.len,
64673 next->d_inode->i_ino, dt_type(next->d_inode)))
64674 return 0;
64675 spin_lock(&dentry->d_lock);
64676 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64677 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64678 void *cookie)
64679 {
64680 - char *s = nd_get_link(nd);
64681 + const char *s = nd_get_link(nd);
64682 if (!IS_ERR(s))
64683 kfree(s);
64684 }
64685 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64686 index acd3947..1f896e2 100644
64687 --- a/fs/lockd/clntproc.c
64688 +++ b/fs/lockd/clntproc.c
64689 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64690 /*
64691 * Cookie counter for NLM requests
64692 */
64693 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64694 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64695
64696 void nlmclnt_next_cookie(struct nlm_cookie *c)
64697 {
64698 - u32 cookie = atomic_inc_return(&nlm_cookie);
64699 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64700
64701 memcpy(c->data, &cookie, 4);
64702 c->len=4;
64703 diff --git a/fs/locks.c b/fs/locks.c
64704 index 717fbc4..74628c3 100644
64705 --- a/fs/locks.c
64706 +++ b/fs/locks.c
64707 @@ -2327,7 +2327,7 @@ void locks_remove_file(struct file *filp)
64708 locks_remove_posix(filp, (fl_owner_t)filp);
64709
64710 if (filp->f_op->flock) {
64711 - struct file_lock fl = {
64712 + struct file_lock flock = {
64713 .fl_owner = (fl_owner_t)filp,
64714 .fl_pid = current->tgid,
64715 .fl_file = filp,
64716 @@ -2335,9 +2335,9 @@ void locks_remove_file(struct file *filp)
64717 .fl_type = F_UNLCK,
64718 .fl_end = OFFSET_MAX,
64719 };
64720 - filp->f_op->flock(filp, F_SETLKW, &fl);
64721 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
64722 - fl.fl_ops->fl_release_private(&fl);
64723 + filp->f_op->flock(filp, F_SETLKW, &flock);
64724 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
64725 + flock.fl_ops->fl_release_private(&flock);
64726 }
64727
64728 spin_lock(&inode->i_lock);
64729 diff --git a/fs/mount.h b/fs/mount.h
64730 index d55297f..f5b28c5 100644
64731 --- a/fs/mount.h
64732 +++ b/fs/mount.h
64733 @@ -11,7 +11,7 @@ struct mnt_namespace {
64734 u64 seq; /* Sequence number to prevent loops */
64735 wait_queue_head_t poll;
64736 u64 event;
64737 -};
64738 +} __randomize_layout;
64739
64740 struct mnt_pcp {
64741 int mnt_count;
64742 @@ -57,7 +57,7 @@ struct mount {
64743 int mnt_expiry_mark; /* true if marked for expiry */
64744 int mnt_pinned;
64745 struct path mnt_ex_mountpoint;
64746 -};
64747 +} __randomize_layout;
64748
64749 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64750
64751 diff --git a/fs/namei.c b/fs/namei.c
64752 index 9eb787e..5f520b67 100644
64753 --- a/fs/namei.c
64754 +++ b/fs/namei.c
64755 @@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
64756 if (ret != -EACCES)
64757 return ret;
64758
64759 +#ifdef CONFIG_GRKERNSEC
64760 + /* we'll block if we have to log due to a denied capability use */
64761 + if (mask & MAY_NOT_BLOCK)
64762 + return -ECHILD;
64763 +#endif
64764 +
64765 if (S_ISDIR(inode->i_mode)) {
64766 /* DACs are overridable for directories */
64767 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64768 - return 0;
64769 if (!(mask & MAY_WRITE))
64770 - if (capable_wrt_inode_uidgid(inode,
64771 - CAP_DAC_READ_SEARCH))
64772 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64773 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64774 return 0;
64775 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64776 + return 0;
64777 return -EACCES;
64778 }
64779 /*
64780 + * Searching includes executable on directories, else just read.
64781 + */
64782 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64783 + if (mask == MAY_READ)
64784 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64785 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64786 + return 0;
64787 +
64788 + /*
64789 * Read/write DACs are always overridable.
64790 * Executable DACs are overridable when there is
64791 * at least one exec bit set.
64792 @@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
64793 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64794 return 0;
64795
64796 - /*
64797 - * Searching includes executable on directories, else just read.
64798 - */
64799 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64800 - if (mask == MAY_READ)
64801 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64802 - return 0;
64803 -
64804 return -EACCES;
64805 }
64806 EXPORT_SYMBOL(generic_permission);
64807 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64808 {
64809 struct dentry *dentry = link->dentry;
64810 int error;
64811 - char *s;
64812 + const char *s;
64813
64814 BUG_ON(nd->flags & LOOKUP_RCU);
64815
64816 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64817 if (error)
64818 goto out_put_nd_path;
64819
64820 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
64821 + dentry->d_inode, dentry, nd->path.mnt)) {
64822 + error = -EACCES;
64823 + goto out_put_nd_path;
64824 + }
64825 +
64826 nd->last_type = LAST_BIND;
64827 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
64828 error = PTR_ERR(*p);
64829 @@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
64830 if (res)
64831 break;
64832 res = walk_component(nd, path, LOOKUP_FOLLOW);
64833 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
64834 + res = -EACCES;
64835 put_link(nd, &link, cookie);
64836 } while (res > 0);
64837
64838 @@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
64839 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
64840 {
64841 unsigned long a, b, adata, bdata, mask, hash, len;
64842 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64843 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64844
64845 hash = a = 0;
64846 len = -sizeof(unsigned long);
64847 @@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
64848 if (err)
64849 break;
64850 err = lookup_last(nd, &path);
64851 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
64852 + err = -EACCES;
64853 put_link(nd, &link, cookie);
64854 }
64855 }
64856 @@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
64857 if (!err)
64858 err = complete_walk(nd);
64859
64860 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
64861 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64862 + path_put(&nd->path);
64863 + err = -ENOENT;
64864 + }
64865 + }
64866 +
64867 if (!err && nd->flags & LOOKUP_DIRECTORY) {
64868 if (!d_can_lookup(nd->path.dentry)) {
64869 path_put(&nd->path);
64870 @@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
64871 retval = path_lookupat(dfd, name->name,
64872 flags | LOOKUP_REVAL, nd);
64873
64874 - if (likely(!retval))
64875 + if (likely(!retval)) {
64876 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
64877 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
64878 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
64879 + path_put(&nd->path);
64880 + return -ENOENT;
64881 + }
64882 + }
64883 + }
64884 return retval;
64885 }
64886
64887 @@ -2570,6 +2601,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
64888 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
64889 return -EPERM;
64890
64891 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
64892 + return -EPERM;
64893 + if (gr_handle_rawio(inode))
64894 + return -EPERM;
64895 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
64896 + return -EACCES;
64897 +
64898 return 0;
64899 }
64900
64901 @@ -2801,7 +2839,7 @@ looked_up:
64902 * cleared otherwise prior to returning.
64903 */
64904 static int lookup_open(struct nameidata *nd, struct path *path,
64905 - struct file *file,
64906 + struct path *link, struct file *file,
64907 const struct open_flags *op,
64908 bool got_write, int *opened)
64909 {
64910 @@ -2836,6 +2874,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64911 /* Negative dentry, just create the file */
64912 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64913 umode_t mode = op->mode;
64914 +
64915 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64916 + error = -EACCES;
64917 + goto out_dput;
64918 + }
64919 +
64920 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64921 + error = -EACCES;
64922 + goto out_dput;
64923 + }
64924 +
64925 if (!IS_POSIXACL(dir->d_inode))
64926 mode &= ~current_umask();
64927 /*
64928 @@ -2857,6 +2906,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64929 nd->flags & LOOKUP_EXCL);
64930 if (error)
64931 goto out_dput;
64932 + else
64933 + gr_handle_create(dentry, nd->path.mnt);
64934 }
64935 out_no_open:
64936 path->dentry = dentry;
64937 @@ -2871,7 +2922,7 @@ out_dput:
64938 /*
64939 * Handle the last step of open()
64940 */
64941 -static int do_last(struct nameidata *nd, struct path *path,
64942 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64943 struct file *file, const struct open_flags *op,
64944 int *opened, struct filename *name)
64945 {
64946 @@ -2921,6 +2972,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64947 if (error)
64948 return error;
64949
64950 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64951 + error = -ENOENT;
64952 + goto out;
64953 + }
64954 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64955 + error = -EACCES;
64956 + goto out;
64957 + }
64958 +
64959 audit_inode(name, dir, LOOKUP_PARENT);
64960 error = -EISDIR;
64961 /* trailing slashes? */
64962 @@ -2940,7 +3000,7 @@ retry_lookup:
64963 */
64964 }
64965 mutex_lock(&dir->d_inode->i_mutex);
64966 - error = lookup_open(nd, path, file, op, got_write, opened);
64967 + error = lookup_open(nd, path, link, file, op, got_write, opened);
64968 mutex_unlock(&dir->d_inode->i_mutex);
64969
64970 if (error <= 0) {
64971 @@ -2964,11 +3024,28 @@ retry_lookup:
64972 goto finish_open_created;
64973 }
64974
64975 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64976 + error = -ENOENT;
64977 + goto exit_dput;
64978 + }
64979 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64980 + error = -EACCES;
64981 + goto exit_dput;
64982 + }
64983 +
64984 /*
64985 * create/update audit record if it already exists.
64986 */
64987 - if (d_is_positive(path->dentry))
64988 + if (d_is_positive(path->dentry)) {
64989 + /* only check if O_CREAT is specified, all other checks need to go
64990 + into may_open */
64991 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64992 + error = -EACCES;
64993 + goto exit_dput;
64994 + }
64995 +
64996 audit_inode(name, path->dentry, 0);
64997 + }
64998
64999 /*
65000 * If atomic_open() acquired write access it is dropped now due to
65001 @@ -3009,6 +3086,11 @@ finish_lookup:
65002 }
65003 }
65004 BUG_ON(inode != path->dentry->d_inode);
65005 + /* if we're resolving a symlink to another symlink */
65006 + if (link && gr_handle_symlink_owner(link, inode)) {
65007 + error = -EACCES;
65008 + goto out;
65009 + }
65010 return 1;
65011 }
65012
65013 @@ -3018,7 +3100,6 @@ finish_lookup:
65014 save_parent.dentry = nd->path.dentry;
65015 save_parent.mnt = mntget(path->mnt);
65016 nd->path.dentry = path->dentry;
65017 -
65018 }
65019 nd->inode = inode;
65020 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
65021 @@ -3028,7 +3109,18 @@ finish_open:
65022 path_put(&save_parent);
65023 return error;
65024 }
65025 +
65026 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
65027 + error = -ENOENT;
65028 + goto out;
65029 + }
65030 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
65031 + error = -EACCES;
65032 + goto out;
65033 + }
65034 +
65035 audit_inode(name, nd->path.dentry, 0);
65036 +
65037 error = -EISDIR;
65038 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
65039 goto out;
65040 @@ -3191,7 +3283,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
65041 if (unlikely(error))
65042 goto out;
65043
65044 - error = do_last(nd, &path, file, op, &opened, pathname);
65045 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
65046 while (unlikely(error > 0)) { /* trailing symlink */
65047 struct path link = path;
65048 void *cookie;
65049 @@ -3209,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
65050 error = follow_link(&link, nd, &cookie);
65051 if (unlikely(error))
65052 break;
65053 - error = do_last(nd, &path, file, op, &opened, pathname);
65054 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
65055 put_link(nd, &link, cookie);
65056 }
65057 out:
65058 @@ -3309,9 +3401,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
65059 goto unlock;
65060
65061 error = -EEXIST;
65062 - if (d_is_positive(dentry))
65063 + if (d_is_positive(dentry)) {
65064 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
65065 + error = -ENOENT;
65066 goto fail;
65067 -
65068 + }
65069 /*
65070 * Special case - lookup gave negative, but... we had foo/bar/
65071 * From the vfs_mknod() POV we just have a negative dentry -
65072 @@ -3363,6 +3457,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
65073 }
65074 EXPORT_SYMBOL(user_path_create);
65075
65076 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
65077 +{
65078 + struct filename *tmp = getname(pathname);
65079 + struct dentry *res;
65080 + if (IS_ERR(tmp))
65081 + return ERR_CAST(tmp);
65082 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
65083 + if (IS_ERR(res))
65084 + putname(tmp);
65085 + else
65086 + *to = tmp;
65087 + return res;
65088 +}
65089 +
65090 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
65091 {
65092 int error = may_create(dir, dentry);
65093 @@ -3426,6 +3534,17 @@ retry:
65094
65095 if (!IS_POSIXACL(path.dentry->d_inode))
65096 mode &= ~current_umask();
65097 +
65098 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
65099 + error = -EPERM;
65100 + goto out;
65101 + }
65102 +
65103 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
65104 + error = -EACCES;
65105 + goto out;
65106 + }
65107 +
65108 error = security_path_mknod(&path, dentry, mode, dev);
65109 if (error)
65110 goto out;
65111 @@ -3442,6 +3561,8 @@ retry:
65112 break;
65113 }
65114 out:
65115 + if (!error)
65116 + gr_handle_create(dentry, path.mnt);
65117 done_path_create(&path, dentry);
65118 if (retry_estale(error, lookup_flags)) {
65119 lookup_flags |= LOOKUP_REVAL;
65120 @@ -3495,9 +3616,16 @@ retry:
65121
65122 if (!IS_POSIXACL(path.dentry->d_inode))
65123 mode &= ~current_umask();
65124 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
65125 + error = -EACCES;
65126 + goto out;
65127 + }
65128 error = security_path_mkdir(&path, dentry, mode);
65129 if (!error)
65130 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
65131 + if (!error)
65132 + gr_handle_create(dentry, path.mnt);
65133 +out:
65134 done_path_create(&path, dentry);
65135 if (retry_estale(error, lookup_flags)) {
65136 lookup_flags |= LOOKUP_REVAL;
65137 @@ -3580,6 +3708,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
65138 struct filename *name;
65139 struct dentry *dentry;
65140 struct nameidata nd;
65141 + ino_t saved_ino = 0;
65142 + dev_t saved_dev = 0;
65143 unsigned int lookup_flags = 0;
65144 retry:
65145 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
65146 @@ -3612,10 +3742,21 @@ retry:
65147 error = -ENOENT;
65148 goto exit3;
65149 }
65150 +
65151 + saved_ino = dentry->d_inode->i_ino;
65152 + saved_dev = gr_get_dev_from_dentry(dentry);
65153 +
65154 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
65155 + error = -EACCES;
65156 + goto exit3;
65157 + }
65158 +
65159 error = security_path_rmdir(&nd.path, dentry);
65160 if (error)
65161 goto exit3;
65162 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
65163 + if (!error && (saved_dev || saved_ino))
65164 + gr_handle_delete(saved_ino, saved_dev);
65165 exit3:
65166 dput(dentry);
65167 exit2:
65168 @@ -3706,6 +3847,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
65169 struct nameidata nd;
65170 struct inode *inode = NULL;
65171 struct inode *delegated_inode = NULL;
65172 + ino_t saved_ino = 0;
65173 + dev_t saved_dev = 0;
65174 unsigned int lookup_flags = 0;
65175 retry:
65176 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
65177 @@ -3732,10 +3875,22 @@ retry_deleg:
65178 if (d_is_negative(dentry))
65179 goto slashes;
65180 ihold(inode);
65181 +
65182 + if (inode->i_nlink <= 1) {
65183 + saved_ino = inode->i_ino;
65184 + saved_dev = gr_get_dev_from_dentry(dentry);
65185 + }
65186 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
65187 + error = -EACCES;
65188 + goto exit2;
65189 + }
65190 +
65191 error = security_path_unlink(&nd.path, dentry);
65192 if (error)
65193 goto exit2;
65194 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
65195 + if (!error && (saved_ino || saved_dev))
65196 + gr_handle_delete(saved_ino, saved_dev);
65197 exit2:
65198 dput(dentry);
65199 }
65200 @@ -3824,9 +3979,17 @@ retry:
65201 if (IS_ERR(dentry))
65202 goto out_putname;
65203
65204 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
65205 + error = -EACCES;
65206 + goto out;
65207 + }
65208 +
65209 error = security_path_symlink(&path, dentry, from->name);
65210 if (!error)
65211 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
65212 + if (!error)
65213 + gr_handle_create(dentry, path.mnt);
65214 +out:
65215 done_path_create(&path, dentry);
65216 if (retry_estale(error, lookup_flags)) {
65217 lookup_flags |= LOOKUP_REVAL;
65218 @@ -3930,6 +4093,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
65219 struct dentry *new_dentry;
65220 struct path old_path, new_path;
65221 struct inode *delegated_inode = NULL;
65222 + struct filename *to = NULL;
65223 int how = 0;
65224 int error;
65225
65226 @@ -3953,7 +4117,7 @@ retry:
65227 if (error)
65228 return error;
65229
65230 - new_dentry = user_path_create(newdfd, newname, &new_path,
65231 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
65232 (how & LOOKUP_REVAL));
65233 error = PTR_ERR(new_dentry);
65234 if (IS_ERR(new_dentry))
65235 @@ -3965,11 +4129,28 @@ retry:
65236 error = may_linkat(&old_path);
65237 if (unlikely(error))
65238 goto out_dput;
65239 +
65240 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
65241 + old_path.dentry->d_inode,
65242 + old_path.dentry->d_inode->i_mode, to)) {
65243 + error = -EACCES;
65244 + goto out_dput;
65245 + }
65246 +
65247 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
65248 + old_path.dentry, old_path.mnt, to)) {
65249 + error = -EACCES;
65250 + goto out_dput;
65251 + }
65252 +
65253 error = security_path_link(old_path.dentry, &new_path, new_dentry);
65254 if (error)
65255 goto out_dput;
65256 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
65257 + if (!error)
65258 + gr_handle_create(new_dentry, new_path.mnt);
65259 out_dput:
65260 + putname(to);
65261 done_path_create(&new_path, new_dentry);
65262 if (delegated_inode) {
65263 error = break_deleg_wait(&delegated_inode);
65264 @@ -4279,6 +4460,12 @@ retry_deleg:
65265 if (new_dentry == trap)
65266 goto exit5;
65267
65268 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
65269 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
65270 + to, flags);
65271 + if (error)
65272 + goto exit5;
65273 +
65274 error = security_path_rename(&oldnd.path, old_dentry,
65275 &newnd.path, new_dentry, flags);
65276 if (error)
65277 @@ -4286,6 +4473,9 @@ retry_deleg:
65278 error = vfs_rename(old_dir->d_inode, old_dentry,
65279 new_dir->d_inode, new_dentry,
65280 &delegated_inode, flags);
65281 + if (!error)
65282 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
65283 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
65284 exit5:
65285 dput(new_dentry);
65286 exit4:
65287 @@ -4328,14 +4518,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
65288
65289 int readlink_copy(char __user *buffer, int buflen, const char *link)
65290 {
65291 + char tmpbuf[64];
65292 + const char *newlink;
65293 int len = PTR_ERR(link);
65294 +
65295 if (IS_ERR(link))
65296 goto out;
65297
65298 len = strlen(link);
65299 if (len > (unsigned) buflen)
65300 len = buflen;
65301 - if (copy_to_user(buffer, link, len))
65302 +
65303 + if (len < sizeof(tmpbuf)) {
65304 + memcpy(tmpbuf, link, len);
65305 + newlink = tmpbuf;
65306 + } else
65307 + newlink = link;
65308 +
65309 + if (copy_to_user(buffer, newlink, len))
65310 len = -EFAULT;
65311 out:
65312 return len;
65313 diff --git a/fs/namespace.c b/fs/namespace.c
65314 index 182bc41..72e3cf1 100644
65315 --- a/fs/namespace.c
65316 +++ b/fs/namespace.c
65317 @@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
65318 if (!(sb->s_flags & MS_RDONLY))
65319 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
65320 up_write(&sb->s_umount);
65321 +
65322 + gr_log_remount(mnt->mnt_devname, retval);
65323 +
65324 return retval;
65325 }
65326
65327 @@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
65328 }
65329 unlock_mount_hash();
65330 namespace_unlock();
65331 +
65332 + gr_log_unmount(mnt->mnt_devname, retval);
65333 +
65334 return retval;
65335 }
65336
65337 @@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
65338 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
65339 */
65340
65341 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
65342 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
65343 {
65344 struct path path;
65345 struct mount *mnt;
65346 @@ -1431,7 +1437,7 @@ out:
65347 /*
65348 * The 2.0 compatible umount. No flags.
65349 */
65350 -SYSCALL_DEFINE1(oldumount, char __user *, name)
65351 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
65352 {
65353 return sys_umount(name, 0);
65354 }
65355 @@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
65356 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
65357 MS_STRICTATIME);
65358
65359 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
65360 + retval = -EPERM;
65361 + goto dput_out;
65362 + }
65363 +
65364 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
65365 + retval = -EPERM;
65366 + goto dput_out;
65367 + }
65368 +
65369 if (flags & MS_REMOUNT)
65370 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
65371 data_page);
65372 @@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
65373 dev_name, data_page);
65374 dput_out:
65375 path_put(&path);
65376 +
65377 + gr_log_mount(dev_name, dir_name, retval);
65378 +
65379 return retval;
65380 }
65381
65382 @@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
65383 * number incrementing at 10Ghz will take 12,427 years to wrap which
65384 * is effectively never, so we can ignore the possibility.
65385 */
65386 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
65387 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
65388
65389 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65390 {
65391 @@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65392 kfree(new_ns);
65393 return ERR_PTR(ret);
65394 }
65395 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
65396 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
65397 atomic_set(&new_ns->count, 1);
65398 new_ns->root = NULL;
65399 INIT_LIST_HEAD(&new_ns->list);
65400 @@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65401 return new_ns;
65402 }
65403
65404 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65405 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65406 struct user_namespace *user_ns, struct fs_struct *new_fs)
65407 {
65408 struct mnt_namespace *new_ns;
65409 @@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
65410 }
65411 EXPORT_SYMBOL(mount_subtree);
65412
65413 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
65414 - char __user *, type, unsigned long, flags, void __user *, data)
65415 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
65416 + const char __user *, type, unsigned long, flags, void __user *, data)
65417 {
65418 int ret;
65419 char *kernel_type;
65420 @@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
65421 if (error)
65422 goto out2;
65423
65424 + if (gr_handle_chroot_pivot()) {
65425 + error = -EPERM;
65426 + goto out2;
65427 + }
65428 +
65429 get_fs_root(current->fs, &root);
65430 old_mp = lock_mount(&old);
65431 error = PTR_ERR(old_mp);
65432 @@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
65433 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
65434 return -EPERM;
65435
65436 - if (fs->users != 1)
65437 + if (atomic_read(&fs->users) != 1)
65438 return -EINVAL;
65439
65440 get_mnt_ns(mnt_ns);
65441 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
65442 index f4ccfe6..a5cf064 100644
65443 --- a/fs/nfs/callback_xdr.c
65444 +++ b/fs/nfs/callback_xdr.c
65445 @@ -51,7 +51,7 @@ struct callback_op {
65446 callback_decode_arg_t decode_args;
65447 callback_encode_res_t encode_res;
65448 long res_maxsize;
65449 -};
65450 +} __do_const;
65451
65452 static struct callback_op callback_ops[];
65453
65454 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
65455 index 9927913..faffc5c 100644
65456 --- a/fs/nfs/inode.c
65457 +++ b/fs/nfs/inode.c
65458 @@ -1219,16 +1219,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
65459 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
65460 }
65461
65462 -static atomic_long_t nfs_attr_generation_counter;
65463 +static atomic_long_unchecked_t nfs_attr_generation_counter;
65464
65465 static unsigned long nfs_read_attr_generation_counter(void)
65466 {
65467 - return atomic_long_read(&nfs_attr_generation_counter);
65468 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
65469 }
65470
65471 unsigned long nfs_inc_attr_generation_counter(void)
65472 {
65473 - return atomic_long_inc_return(&nfs_attr_generation_counter);
65474 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
65475 }
65476
65477 void nfs_fattr_init(struct nfs_fattr *fattr)
65478 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
65479 index 8f029db..3688b84 100644
65480 --- a/fs/nfsd/nfs4proc.c
65481 +++ b/fs/nfsd/nfs4proc.c
65482 @@ -1157,7 +1157,7 @@ struct nfsd4_operation {
65483 nfsd4op_rsize op_rsize_bop;
65484 stateid_getter op_get_currentstateid;
65485 stateid_setter op_set_currentstateid;
65486 -};
65487 +} __do_const;
65488
65489 static struct nfsd4_operation nfsd4_ops[];
65490
65491 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
65492 index 944275c..6fc40a7 100644
65493 --- a/fs/nfsd/nfs4xdr.c
65494 +++ b/fs/nfsd/nfs4xdr.c
65495 @@ -1539,7 +1539,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
65496
65497 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
65498
65499 -static nfsd4_dec nfsd4_dec_ops[] = {
65500 +static const nfsd4_dec nfsd4_dec_ops[] = {
65501 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
65502 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
65503 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
65504 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
65505 index 6040da8..4348565 100644
65506 --- a/fs/nfsd/nfscache.c
65507 +++ b/fs/nfsd/nfscache.c
65508 @@ -518,17 +518,20 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65509 {
65510 struct svc_cacherep *rp = rqstp->rq_cacherep;
65511 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
65512 - int len;
65513 + long len;
65514 size_t bufsize = 0;
65515
65516 if (!rp)
65517 return;
65518
65519 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
65520 - len >>= 2;
65521 + if (statp) {
65522 + len = (char*)statp - (char*)resv->iov_base;
65523 + len = resv->iov_len - len;
65524 + len >>= 2;
65525 + }
65526
65527 /* Don't cache excessive amounts of data and XDR failures */
65528 - if (!statp || len > (256 >> 2)) {
65529 + if (!statp || len > (256 >> 2) || len < 0) {
65530 nfsd_reply_cache_free(rp);
65531 return;
65532 }
65533 @@ -536,7 +539,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65534 switch (cachetype) {
65535 case RC_REPLSTAT:
65536 if (len != 1)
65537 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
65538 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
65539 rp->c_replstat = *statp;
65540 break;
65541 case RC_REPLBUFF:
65542 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
65543 index 140c496..e9cbf14 100644
65544 --- a/fs/nfsd/vfs.c
65545 +++ b/fs/nfsd/vfs.c
65546 @@ -855,7 +855,7 @@ int nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
65547
65548 oldfs = get_fs();
65549 set_fs(KERNEL_DS);
65550 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
65551 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
65552 set_fs(oldfs);
65553 return nfsd_finish_read(file, count, host_err);
65554 }
65555 @@ -943,7 +943,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
65556
65557 /* Write the data. */
65558 oldfs = get_fs(); set_fs(KERNEL_DS);
65559 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
65560 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
65561 set_fs(oldfs);
65562 if (host_err < 0)
65563 goto out_nfserr;
65564 @@ -1482,7 +1482,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
65565 */
65566
65567 oldfs = get_fs(); set_fs(KERNEL_DS);
65568 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
65569 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
65570 set_fs(oldfs);
65571
65572 if (host_err < 0)
65573 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
65574 index 52ccd34..7a6b202 100644
65575 --- a/fs/nls/nls_base.c
65576 +++ b/fs/nls/nls_base.c
65577 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
65578
65579 int __register_nls(struct nls_table *nls, struct module *owner)
65580 {
65581 - struct nls_table ** tmp = &tables;
65582 + struct nls_table *tmp = tables;
65583
65584 if (nls->next)
65585 return -EBUSY;
65586
65587 - nls->owner = owner;
65588 + pax_open_kernel();
65589 + *(void **)&nls->owner = owner;
65590 + pax_close_kernel();
65591 spin_lock(&nls_lock);
65592 - while (*tmp) {
65593 - if (nls == *tmp) {
65594 + while (tmp) {
65595 + if (nls == tmp) {
65596 spin_unlock(&nls_lock);
65597 return -EBUSY;
65598 }
65599 - tmp = &(*tmp)->next;
65600 + tmp = tmp->next;
65601 }
65602 - nls->next = tables;
65603 + pax_open_kernel();
65604 + *(struct nls_table **)&nls->next = tables;
65605 + pax_close_kernel();
65606 tables = nls;
65607 spin_unlock(&nls_lock);
65608 return 0;
65609 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
65610
65611 int unregister_nls(struct nls_table * nls)
65612 {
65613 - struct nls_table ** tmp = &tables;
65614 + struct nls_table * const * tmp = &tables;
65615
65616 spin_lock(&nls_lock);
65617 while (*tmp) {
65618 if (nls == *tmp) {
65619 - *tmp = nls->next;
65620 + pax_open_kernel();
65621 + *(struct nls_table **)tmp = nls->next;
65622 + pax_close_kernel();
65623 spin_unlock(&nls_lock);
65624 return 0;
65625 }
65626 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65627 return -EINVAL;
65628 }
65629
65630 -static struct nls_table *find_nls(char *charset)
65631 +static struct nls_table *find_nls(const char *charset)
65632 {
65633 struct nls_table *nls;
65634 spin_lock(&nls_lock);
65635 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65636 return nls;
65637 }
65638
65639 -struct nls_table *load_nls(char *charset)
65640 +struct nls_table *load_nls(const char *charset)
65641 {
65642 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65643 }
65644 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65645 index 162b3f1..6076a7c 100644
65646 --- a/fs/nls/nls_euc-jp.c
65647 +++ b/fs/nls/nls_euc-jp.c
65648 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65649 p_nls = load_nls("cp932");
65650
65651 if (p_nls) {
65652 - table.charset2upper = p_nls->charset2upper;
65653 - table.charset2lower = p_nls->charset2lower;
65654 + pax_open_kernel();
65655 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65656 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65657 + pax_close_kernel();
65658 return register_nls(&table);
65659 }
65660
65661 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65662 index a80a741..7b96e1b 100644
65663 --- a/fs/nls/nls_koi8-ru.c
65664 +++ b/fs/nls/nls_koi8-ru.c
65665 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65666 p_nls = load_nls("koi8-u");
65667
65668 if (p_nls) {
65669 - table.charset2upper = p_nls->charset2upper;
65670 - table.charset2lower = p_nls->charset2lower;
65671 + pax_open_kernel();
65672 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65673 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65674 + pax_close_kernel();
65675 return register_nls(&table);
65676 }
65677
65678 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65679 index 3fdc8a3..5888623 100644
65680 --- a/fs/notify/fanotify/fanotify_user.c
65681 +++ b/fs/notify/fanotify/fanotify_user.c
65682 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65683
65684 fd = fanotify_event_metadata.fd;
65685 ret = -EFAULT;
65686 - if (copy_to_user(buf, &fanotify_event_metadata,
65687 - fanotify_event_metadata.event_len))
65688 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65689 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65690 goto out_close_fd;
65691
65692 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65693 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65694 index 1e58402..bb2d6f4 100644
65695 --- a/fs/notify/notification.c
65696 +++ b/fs/notify/notification.c
65697 @@ -48,7 +48,7 @@
65698 #include <linux/fsnotify_backend.h>
65699 #include "fsnotify.h"
65700
65701 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65702 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65703
65704 /**
65705 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
65706 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65707 */
65708 u32 fsnotify_get_cookie(void)
65709 {
65710 - return atomic_inc_return(&fsnotify_sync_cookie);
65711 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
65712 }
65713 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
65714
65715 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65716 index 9e38daf..5727cae 100644
65717 --- a/fs/ntfs/dir.c
65718 +++ b/fs/ntfs/dir.c
65719 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
65720 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65721 ~(s64)(ndir->itype.index.block_size - 1)));
65722 /* Bounds checks. */
65723 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65724 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65725 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65726 "inode 0x%lx or driver bug.", vdir->i_ino);
65727 goto err_out;
65728 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
65729 index 5c9e2c8..96e4ba0 100644
65730 --- a/fs/ntfs/file.c
65731 +++ b/fs/ntfs/file.c
65732 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
65733 char *addr;
65734 size_t total = 0;
65735 unsigned len;
65736 - int left;
65737 + unsigned left;
65738
65739 do {
65740 len = PAGE_CACHE_SIZE - ofs;
65741 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
65742 index 6c3296e..c0b99f0 100644
65743 --- a/fs/ntfs/super.c
65744 +++ b/fs/ntfs/super.c
65745 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65746 if (!silent)
65747 ntfs_error(sb, "Primary boot sector is invalid.");
65748 } else if (!silent)
65749 - ntfs_error(sb, read_err_str, "primary");
65750 + ntfs_error(sb, read_err_str, "%s", "primary");
65751 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
65752 if (bh_primary)
65753 brelse(bh_primary);
65754 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65755 goto hotfix_primary_boot_sector;
65756 brelse(bh_backup);
65757 } else if (!silent)
65758 - ntfs_error(sb, read_err_str, "backup");
65759 + ntfs_error(sb, read_err_str, "%s", "backup");
65760 /* Try to read NT3.51- backup boot sector. */
65761 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
65762 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
65763 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65764 "sector.");
65765 brelse(bh_backup);
65766 } else if (!silent)
65767 - ntfs_error(sb, read_err_str, "backup");
65768 + ntfs_error(sb, read_err_str, "%s", "backup");
65769 /* We failed. Cleanup and return. */
65770 if (bh_primary)
65771 brelse(bh_primary);
65772 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
65773 index 0440134..d52c93a 100644
65774 --- a/fs/ocfs2/localalloc.c
65775 +++ b/fs/ocfs2/localalloc.c
65776 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
65777 goto bail;
65778 }
65779
65780 - atomic_inc(&osb->alloc_stats.moves);
65781 + atomic_inc_unchecked(&osb->alloc_stats.moves);
65782
65783 bail:
65784 if (handle)
65785 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
65786 index bbec539..7b266d5 100644
65787 --- a/fs/ocfs2/ocfs2.h
65788 +++ b/fs/ocfs2/ocfs2.h
65789 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
65790
65791 struct ocfs2_alloc_stats
65792 {
65793 - atomic_t moves;
65794 - atomic_t local_data;
65795 - atomic_t bitmap_data;
65796 - atomic_t bg_allocs;
65797 - atomic_t bg_extends;
65798 + atomic_unchecked_t moves;
65799 + atomic_unchecked_t local_data;
65800 + atomic_unchecked_t bitmap_data;
65801 + atomic_unchecked_t bg_allocs;
65802 + atomic_unchecked_t bg_extends;
65803 };
65804
65805 enum ocfs2_local_alloc_state
65806 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
65807 index 0cb889a..6a26b24 100644
65808 --- a/fs/ocfs2/suballoc.c
65809 +++ b/fs/ocfs2/suballoc.c
65810 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
65811 mlog_errno(status);
65812 goto bail;
65813 }
65814 - atomic_inc(&osb->alloc_stats.bg_extends);
65815 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
65816
65817 /* You should never ask for this much metadata */
65818 BUG_ON(bits_wanted >
65819 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
65820 mlog_errno(status);
65821 goto bail;
65822 }
65823 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65824 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65825
65826 *suballoc_loc = res.sr_bg_blkno;
65827 *suballoc_bit_start = res.sr_bit_offset;
65828 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
65829 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
65830 res->sr_bits);
65831
65832 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65833 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65834
65835 BUG_ON(res->sr_bits != 1);
65836
65837 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
65838 mlog_errno(status);
65839 goto bail;
65840 }
65841 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65842 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65843
65844 BUG_ON(res.sr_bits != 1);
65845
65846 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65847 cluster_start,
65848 num_clusters);
65849 if (!status)
65850 - atomic_inc(&osb->alloc_stats.local_data);
65851 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
65852 } else {
65853 if (min_clusters > (osb->bitmap_cpg - 1)) {
65854 /* The only paths asking for contiguousness
65855 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65856 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
65857 res.sr_bg_blkno,
65858 res.sr_bit_offset);
65859 - atomic_inc(&osb->alloc_stats.bitmap_data);
65860 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
65861 *num_clusters = res.sr_bits;
65862 }
65863 }
65864 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
65865 index ddb662b..f701c83 100644
65866 --- a/fs/ocfs2/super.c
65867 +++ b/fs/ocfs2/super.c
65868 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
65869 "%10s => GlobalAllocs: %d LocalAllocs: %d "
65870 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
65871 "Stats",
65872 - atomic_read(&osb->alloc_stats.bitmap_data),
65873 - atomic_read(&osb->alloc_stats.local_data),
65874 - atomic_read(&osb->alloc_stats.bg_allocs),
65875 - atomic_read(&osb->alloc_stats.moves),
65876 - atomic_read(&osb->alloc_stats.bg_extends));
65877 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
65878 + atomic_read_unchecked(&osb->alloc_stats.local_data),
65879 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
65880 + atomic_read_unchecked(&osb->alloc_stats.moves),
65881 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
65882
65883 out += snprintf(buf + out, len - out,
65884 "%10s => State: %u Descriptor: %llu Size: %u bits "
65885 @@ -2100,11 +2100,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
65886
65887 mutex_init(&osb->system_file_mutex);
65888
65889 - atomic_set(&osb->alloc_stats.moves, 0);
65890 - atomic_set(&osb->alloc_stats.local_data, 0);
65891 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
65892 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
65893 - atomic_set(&osb->alloc_stats.bg_extends, 0);
65894 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
65895 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
65896 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65897 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65898 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65899
65900 /* Copy the blockcheck stats from the superblock probe */
65901 osb->osb_ecc_stats = *stats;
65902 diff --git a/fs/open.c b/fs/open.c
65903 index d6fd3ac..6ccf474 100644
65904 --- a/fs/open.c
65905 +++ b/fs/open.c
65906 @@ -32,6 +32,8 @@
65907 #include <linux/dnotify.h>
65908 #include <linux/compat.h>
65909
65910 +#define CREATE_TRACE_POINTS
65911 +#include <trace/events/fs.h>
65912 #include "internal.h"
65913
65914 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65915 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65916 error = locks_verify_truncate(inode, NULL, length);
65917 if (!error)
65918 error = security_path_truncate(path);
65919 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65920 + error = -EACCES;
65921 if (!error)
65922 error = do_truncate(path->dentry, length, 0, NULL);
65923
65924 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65925 error = locks_verify_truncate(inode, f.file, length);
65926 if (!error)
65927 error = security_path_truncate(&f.file->f_path);
65928 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65929 + error = -EACCES;
65930 if (!error)
65931 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65932 sb_end_write(inode->i_sb);
65933 @@ -380,6 +386,9 @@ retry:
65934 if (__mnt_is_readonly(path.mnt))
65935 res = -EROFS;
65936
65937 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65938 + res = -EACCES;
65939 +
65940 out_path_release:
65941 path_put(&path);
65942 if (retry_estale(res, lookup_flags)) {
65943 @@ -411,6 +420,8 @@ retry:
65944 if (error)
65945 goto dput_and_out;
65946
65947 + gr_log_chdir(path.dentry, path.mnt);
65948 +
65949 set_fs_pwd(current->fs, &path);
65950
65951 dput_and_out:
65952 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65953 goto out_putf;
65954
65955 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65956 +
65957 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65958 + error = -EPERM;
65959 +
65960 + if (!error)
65961 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65962 +
65963 if (!error)
65964 set_fs_pwd(current->fs, &f.file->f_path);
65965 out_putf:
65966 @@ -469,7 +487,13 @@ retry:
65967 if (error)
65968 goto dput_and_out;
65969
65970 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65971 + goto dput_and_out;
65972 +
65973 set_fs_root(current->fs, &path);
65974 +
65975 + gr_handle_chroot_chdir(&path);
65976 +
65977 error = 0;
65978 dput_and_out:
65979 path_put(&path);
65980 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65981 return error;
65982 retry_deleg:
65983 mutex_lock(&inode->i_mutex);
65984 +
65985 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65986 + error = -EACCES;
65987 + goto out_unlock;
65988 + }
65989 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65990 + error = -EACCES;
65991 + goto out_unlock;
65992 + }
65993 +
65994 error = security_path_chmod(path, mode);
65995 if (error)
65996 goto out_unlock;
65997 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65998 uid = make_kuid(current_user_ns(), user);
65999 gid = make_kgid(current_user_ns(), group);
66000
66001 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
66002 + return -EACCES;
66003 +
66004 newattrs.ia_valid = ATTR_CTIME;
66005 if (user != (uid_t) -1) {
66006 if (!uid_valid(uid))
66007 @@ -983,6 +1020,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
66008 } else {
66009 fsnotify_open(f);
66010 fd_install(fd, f);
66011 + trace_do_sys_open(tmp->name, flags, mode);
66012 }
66013 }
66014 putname(tmp);
66015 diff --git a/fs/pipe.c b/fs/pipe.c
66016 index 21981e5..3d5f55c 100644
66017 --- a/fs/pipe.c
66018 +++ b/fs/pipe.c
66019 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
66020
66021 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
66022 {
66023 - if (pipe->files)
66024 + if (atomic_read(&pipe->files))
66025 mutex_lock_nested(&pipe->mutex, subclass);
66026 }
66027
66028 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
66029
66030 void pipe_unlock(struct pipe_inode_info *pipe)
66031 {
66032 - if (pipe->files)
66033 + if (atomic_read(&pipe->files))
66034 mutex_unlock(&pipe->mutex);
66035 }
66036 EXPORT_SYMBOL(pipe_unlock);
66037 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
66038 }
66039 if (bufs) /* More to do? */
66040 continue;
66041 - if (!pipe->writers)
66042 + if (!atomic_read(&pipe->writers))
66043 break;
66044 - if (!pipe->waiting_writers) {
66045 + if (!atomic_read(&pipe->waiting_writers)) {
66046 /* syscall merging: Usually we must not sleep
66047 * if O_NONBLOCK is set, or if we got some data.
66048 * But if a writer sleeps in kernel space, then
66049 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66050
66051 __pipe_lock(pipe);
66052
66053 - if (!pipe->readers) {
66054 + if (!atomic_read(&pipe->readers)) {
66055 send_sig(SIGPIPE, current, 0);
66056 ret = -EPIPE;
66057 goto out;
66058 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66059 for (;;) {
66060 int bufs;
66061
66062 - if (!pipe->readers) {
66063 + if (!atomic_read(&pipe->readers)) {
66064 send_sig(SIGPIPE, current, 0);
66065 if (!ret)
66066 ret = -EPIPE;
66067 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66068 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
66069 do_wakeup = 0;
66070 }
66071 - pipe->waiting_writers++;
66072 + atomic_inc(&pipe->waiting_writers);
66073 pipe_wait(pipe);
66074 - pipe->waiting_writers--;
66075 + atomic_dec(&pipe->waiting_writers);
66076 }
66077 out:
66078 __pipe_unlock(pipe);
66079 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
66080 mask = 0;
66081 if (filp->f_mode & FMODE_READ) {
66082 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
66083 - if (!pipe->writers && filp->f_version != pipe->w_counter)
66084 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
66085 mask |= POLLHUP;
66086 }
66087
66088 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
66089 * Most Unices do not set POLLERR for FIFOs but on Linux they
66090 * behave exactly like pipes for poll().
66091 */
66092 - if (!pipe->readers)
66093 + if (!atomic_read(&pipe->readers))
66094 mask |= POLLERR;
66095 }
66096
66097 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
66098 int kill = 0;
66099
66100 spin_lock(&inode->i_lock);
66101 - if (!--pipe->files) {
66102 + if (atomic_dec_and_test(&pipe->files)) {
66103 inode->i_pipe = NULL;
66104 kill = 1;
66105 }
66106 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
66107
66108 __pipe_lock(pipe);
66109 if (file->f_mode & FMODE_READ)
66110 - pipe->readers--;
66111 + atomic_dec(&pipe->readers);
66112 if (file->f_mode & FMODE_WRITE)
66113 - pipe->writers--;
66114 + atomic_dec(&pipe->writers);
66115
66116 - if (pipe->readers || pipe->writers) {
66117 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
66118 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
66119 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
66120 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
66121 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
66122 kfree(pipe);
66123 }
66124
66125 -static struct vfsmount *pipe_mnt __read_mostly;
66126 +struct vfsmount *pipe_mnt __read_mostly;
66127
66128 /*
66129 * pipefs_dname() is called from d_path().
66130 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
66131 goto fail_iput;
66132
66133 inode->i_pipe = pipe;
66134 - pipe->files = 2;
66135 - pipe->readers = pipe->writers = 1;
66136 + atomic_set(&pipe->files, 2);
66137 + atomic_set(&pipe->readers, 1);
66138 + atomic_set(&pipe->writers, 1);
66139 inode->i_fop = &pipefifo_fops;
66140
66141 /*
66142 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
66143 spin_lock(&inode->i_lock);
66144 if (inode->i_pipe) {
66145 pipe = inode->i_pipe;
66146 - pipe->files++;
66147 + atomic_inc(&pipe->files);
66148 spin_unlock(&inode->i_lock);
66149 } else {
66150 spin_unlock(&inode->i_lock);
66151 pipe = alloc_pipe_info();
66152 if (!pipe)
66153 return -ENOMEM;
66154 - pipe->files = 1;
66155 + atomic_set(&pipe->files, 1);
66156 spin_lock(&inode->i_lock);
66157 if (unlikely(inode->i_pipe)) {
66158 - inode->i_pipe->files++;
66159 + atomic_inc(&inode->i_pipe->files);
66160 spin_unlock(&inode->i_lock);
66161 free_pipe_info(pipe);
66162 pipe = inode->i_pipe;
66163 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
66164 * opened, even when there is no process writing the FIFO.
66165 */
66166 pipe->r_counter++;
66167 - if (pipe->readers++ == 0)
66168 + if (atomic_inc_return(&pipe->readers) == 1)
66169 wake_up_partner(pipe);
66170
66171 - if (!is_pipe && !pipe->writers) {
66172 + if (!is_pipe && !atomic_read(&pipe->writers)) {
66173 if ((filp->f_flags & O_NONBLOCK)) {
66174 /* suppress POLLHUP until we have
66175 * seen a writer */
66176 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
66177 * errno=ENXIO when there is no process reading the FIFO.
66178 */
66179 ret = -ENXIO;
66180 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
66181 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
66182 goto err;
66183
66184 pipe->w_counter++;
66185 - if (!pipe->writers++)
66186 + if (atomic_inc_return(&pipe->writers) == 1)
66187 wake_up_partner(pipe);
66188
66189 - if (!is_pipe && !pipe->readers) {
66190 + if (!is_pipe && !atomic_read(&pipe->readers)) {
66191 if (wait_for_partner(pipe, &pipe->r_counter))
66192 goto err_wr;
66193 }
66194 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
66195 * the process can at least talk to itself.
66196 */
66197
66198 - pipe->readers++;
66199 - pipe->writers++;
66200 + atomic_inc(&pipe->readers);
66201 + atomic_inc(&pipe->writers);
66202 pipe->r_counter++;
66203 pipe->w_counter++;
66204 - if (pipe->readers == 1 || pipe->writers == 1)
66205 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
66206 wake_up_partner(pipe);
66207 break;
66208
66209 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
66210 return 0;
66211
66212 err_rd:
66213 - if (!--pipe->readers)
66214 + if (atomic_dec_and_test(&pipe->readers))
66215 wake_up_interruptible(&pipe->wait);
66216 ret = -ERESTARTSYS;
66217 goto err;
66218
66219 err_wr:
66220 - if (!--pipe->writers)
66221 + if (atomic_dec_and_test(&pipe->writers))
66222 wake_up_interruptible(&pipe->wait);
66223 ret = -ERESTARTSYS;
66224 goto err;
66225 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
66226 index 0855f77..6787d50 100644
66227 --- a/fs/posix_acl.c
66228 +++ b/fs/posix_acl.c
66229 @@ -20,6 +20,7 @@
66230 #include <linux/xattr.h>
66231 #include <linux/export.h>
66232 #include <linux/user_namespace.h>
66233 +#include <linux/grsecurity.h>
66234
66235 struct posix_acl **acl_by_type(struct inode *inode, int type)
66236 {
66237 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
66238 }
66239 }
66240 if (mode_p)
66241 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
66242 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
66243 return not_equiv;
66244 }
66245 EXPORT_SYMBOL(posix_acl_equiv_mode);
66246 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
66247 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
66248 }
66249
66250 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
66251 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
66252 return not_equiv;
66253 }
66254
66255 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
66256 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
66257 int err = -ENOMEM;
66258 if (clone) {
66259 + *mode_p &= ~gr_acl_umask();
66260 +
66261 err = posix_acl_create_masq(clone, mode_p);
66262 if (err < 0) {
66263 posix_acl_release(clone);
66264 @@ -659,11 +662,12 @@ struct posix_acl *
66265 posix_acl_from_xattr(struct user_namespace *user_ns,
66266 const void *value, size_t size)
66267 {
66268 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
66269 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
66270 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
66271 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
66272 int count;
66273 struct posix_acl *acl;
66274 struct posix_acl_entry *acl_e;
66275 + umode_t umask = gr_acl_umask();
66276
66277 if (!value)
66278 return NULL;
66279 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
66280
66281 switch(acl_e->e_tag) {
66282 case ACL_USER_OBJ:
66283 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
66284 + break;
66285 case ACL_GROUP_OBJ:
66286 case ACL_MASK:
66287 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
66288 + break;
66289 case ACL_OTHER:
66290 + acl_e->e_perm &= ~(umask & S_IRWXO);
66291 break;
66292
66293 case ACL_USER:
66294 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
66295 acl_e->e_uid =
66296 make_kuid(user_ns,
66297 le32_to_cpu(entry->e_id));
66298 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
66299 goto fail;
66300 break;
66301 case ACL_GROUP:
66302 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
66303 acl_e->e_gid =
66304 make_kgid(user_ns,
66305 le32_to_cpu(entry->e_id));
66306 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
66307 index 2183fcf..3c32a98 100644
66308 --- a/fs/proc/Kconfig
66309 +++ b/fs/proc/Kconfig
66310 @@ -30,7 +30,7 @@ config PROC_FS
66311
66312 config PROC_KCORE
66313 bool "/proc/kcore support" if !ARM
66314 - depends on PROC_FS && MMU
66315 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
66316 help
66317 Provides a virtual ELF core file of the live kernel. This can
66318 be read with gdb and other ELF tools. No modifications can be
66319 @@ -38,8 +38,8 @@ config PROC_KCORE
66320
66321 config PROC_VMCORE
66322 bool "/proc/vmcore support"
66323 - depends on PROC_FS && CRASH_DUMP
66324 - default y
66325 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
66326 + default n
66327 help
66328 Exports the dump image of crashed kernel in ELF format.
66329
66330 @@ -63,8 +63,8 @@ config PROC_SYSCTL
66331 limited in memory.
66332
66333 config PROC_PAGE_MONITOR
66334 - default y
66335 - depends on PROC_FS && MMU
66336 + default n
66337 + depends on PROC_FS && MMU && !GRKERNSEC
66338 bool "Enable /proc page monitoring" if EXPERT
66339 help
66340 Various /proc files exist to monitor process memory utilization:
66341 diff --git a/fs/proc/array.c b/fs/proc/array.c
66342 index 64db2bc..a8185d6 100644
66343 --- a/fs/proc/array.c
66344 +++ b/fs/proc/array.c
66345 @@ -60,6 +60,7 @@
66346 #include <linux/tty.h>
66347 #include <linux/string.h>
66348 #include <linux/mman.h>
66349 +#include <linux/grsecurity.h>
66350 #include <linux/proc_fs.h>
66351 #include <linux/ioport.h>
66352 #include <linux/uaccess.h>
66353 @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
66354 seq_putc(m, '\n');
66355 }
66356
66357 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66358 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
66359 +{
66360 + if (p->mm)
66361 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
66362 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
66363 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
66364 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
66365 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
66366 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
66367 + else
66368 + seq_printf(m, "PaX:\t-----\n");
66369 +}
66370 +#endif
66371 +
66372 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66373 struct pid *pid, struct task_struct *task)
66374 {
66375 @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66376 task_cpus_allowed(m, task);
66377 cpuset_task_status_allowed(m, task);
66378 task_context_switch_counts(m, task);
66379 +
66380 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66381 + task_pax(m, task);
66382 +#endif
66383 +
66384 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
66385 + task_grsec_rbac(m, task);
66386 +#endif
66387 +
66388 return 0;
66389 }
66390
66391 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66392 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66393 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
66394 + _mm->pax_flags & MF_PAX_SEGMEXEC))
66395 +#endif
66396 +
66397 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66398 struct pid *pid, struct task_struct *task, int whole)
66399 {
66400 @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66401 char tcomm[sizeof(task->comm)];
66402 unsigned long flags;
66403
66404 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66405 + if (current->exec_id != m->exec_id) {
66406 + gr_log_badprocpid("stat");
66407 + return 0;
66408 + }
66409 +#endif
66410 +
66411 state = *get_task_state(task);
66412 vsize = eip = esp = 0;
66413 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66414 @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66415 gtime = task_gtime(task);
66416 }
66417
66418 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66419 + if (PAX_RAND_FLAGS(mm)) {
66420 + eip = 0;
66421 + esp = 0;
66422 + wchan = 0;
66423 + }
66424 +#endif
66425 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66426 + wchan = 0;
66427 + eip =0;
66428 + esp =0;
66429 +#endif
66430 +
66431 /* scale priority and nice values from timeslices to -20..20 */
66432 /* to make it look like a "normal" Unix priority/nice value */
66433 priority = task_prio(task);
66434 @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66435 seq_put_decimal_ull(m, ' ', vsize);
66436 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
66437 seq_put_decimal_ull(m, ' ', rsslim);
66438 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66439 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
66440 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
66441 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
66442 +#else
66443 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
66444 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
66445 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
66446 +#endif
66447 seq_put_decimal_ull(m, ' ', esp);
66448 seq_put_decimal_ull(m, ' ', eip);
66449 /* The signal information here is obsolete.
66450 @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66451 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
66452 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
66453
66454 - if (mm && permitted) {
66455 + if (mm && permitted
66456 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66457 + && !PAX_RAND_FLAGS(mm)
66458 +#endif
66459 + ) {
66460 seq_put_decimal_ull(m, ' ', mm->start_data);
66461 seq_put_decimal_ull(m, ' ', mm->end_data);
66462 seq_put_decimal_ull(m, ' ', mm->start_brk);
66463 @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66464 struct pid *pid, struct task_struct *task)
66465 {
66466 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
66467 - struct mm_struct *mm = get_task_mm(task);
66468 + struct mm_struct *mm;
66469
66470 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66471 + if (current->exec_id != m->exec_id) {
66472 + gr_log_badprocpid("statm");
66473 + return 0;
66474 + }
66475 +#endif
66476 + mm = get_task_mm(task);
66477 if (mm) {
66478 size = task_statm(mm, &shared, &text, &data, &resident);
66479 mmput(mm);
66480 @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66481 return 0;
66482 }
66483
66484 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66485 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
66486 +{
66487 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
66488 +}
66489 +#endif
66490 +
66491 #ifdef CONFIG_CHECKPOINT_RESTORE
66492 static struct pid *
66493 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
66494 diff --git a/fs/proc/base.c b/fs/proc/base.c
66495 index 2d696b0..b9da447 100644
66496 --- a/fs/proc/base.c
66497 +++ b/fs/proc/base.c
66498 @@ -113,6 +113,14 @@ struct pid_entry {
66499 union proc_op op;
66500 };
66501
66502 +struct getdents_callback {
66503 + struct linux_dirent __user * current_dir;
66504 + struct linux_dirent __user * previous;
66505 + struct file * file;
66506 + int count;
66507 + int error;
66508 +};
66509 +
66510 #define NOD(NAME, MODE, IOP, FOP, OP) { \
66511 .name = (NAME), \
66512 .len = sizeof(NAME) - 1, \
66513 @@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
66514 return get_cmdline(task, buffer, PAGE_SIZE);
66515 }
66516
66517 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66518 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66519 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
66520 + _mm->pax_flags & MF_PAX_SEGMEXEC))
66521 +#endif
66522 +
66523 static int proc_pid_auxv(struct task_struct *task, char *buffer)
66524 {
66525 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
66526 int res = PTR_ERR(mm);
66527 if (mm && !IS_ERR(mm)) {
66528 unsigned int nwords = 0;
66529 +
66530 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66531 + /* allow if we're currently ptracing this task */
66532 + if (PAX_RAND_FLAGS(mm) &&
66533 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
66534 + mmput(mm);
66535 + return 0;
66536 + }
66537 +#endif
66538 +
66539 do {
66540 nwords += 2;
66541 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
66542 @@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
66543 }
66544
66545
66546 -#ifdef CONFIG_KALLSYMS
66547 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66548 /*
66549 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
66550 * Returns the resolved symbol. If that fails, simply return the address.
66551 @@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
66552 mutex_unlock(&task->signal->cred_guard_mutex);
66553 }
66554
66555 -#ifdef CONFIG_STACKTRACE
66556 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66557
66558 #define MAX_STACK_TRACE_DEPTH 64
66559
66560 @@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
66561 return count;
66562 }
66563
66564 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66565 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66566 static int proc_pid_syscall(struct task_struct *task, char *buffer)
66567 {
66568 long nr;
66569 @@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
66570 /************************************************************************/
66571
66572 /* permission checks */
66573 -static int proc_fd_access_allowed(struct inode *inode)
66574 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
66575 {
66576 struct task_struct *task;
66577 int allowed = 0;
66578 @@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
66579 */
66580 task = get_proc_task(inode);
66581 if (task) {
66582 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66583 + if (log)
66584 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66585 + else
66586 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66587 put_task_struct(task);
66588 }
66589 return allowed;
66590 @@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
66591 struct task_struct *task,
66592 int hide_pid_min)
66593 {
66594 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66595 + return false;
66596 +
66597 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66598 + rcu_read_lock();
66599 + {
66600 + const struct cred *tmpcred = current_cred();
66601 + const struct cred *cred = __task_cred(task);
66602 +
66603 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66604 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66605 + || in_group_p(grsec_proc_gid)
66606 +#endif
66607 + ) {
66608 + rcu_read_unlock();
66609 + return true;
66610 + }
66611 + }
66612 + rcu_read_unlock();
66613 +
66614 + if (!pid->hide_pid)
66615 + return false;
66616 +#endif
66617 +
66618 if (pid->hide_pid < hide_pid_min)
66619 return true;
66620 if (in_group_p(pid->pid_gid))
66621 return true;
66622 +
66623 return ptrace_may_access(task, PTRACE_MODE_READ);
66624 }
66625
66626 @@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66627 put_task_struct(task);
66628
66629 if (!has_perms) {
66630 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66631 + {
66632 +#else
66633 if (pid->hide_pid == 2) {
66634 +#endif
66635 /*
66636 * Let's make getdents(), stat(), and open()
66637 * consistent with each other. If a process
66638 @@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66639 if (!task)
66640 return -ESRCH;
66641
66642 + if (gr_acl_handle_procpidmem(task)) {
66643 + put_task_struct(task);
66644 + return -EPERM;
66645 + }
66646 +
66647 mm = mm_access(task, mode);
66648 put_task_struct(task);
66649
66650 @@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66651
66652 file->private_data = mm;
66653
66654 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66655 + file->f_version = current->exec_id;
66656 +#endif
66657 +
66658 return 0;
66659 }
66660
66661 @@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66662 ssize_t copied;
66663 char *page;
66664
66665 +#ifdef CONFIG_GRKERNSEC
66666 + if (write)
66667 + return -EPERM;
66668 +#endif
66669 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66670 + if (file->f_version != current->exec_id) {
66671 + gr_log_badprocpid("mem");
66672 + return 0;
66673 + }
66674 +#endif
66675 +
66676 if (!mm)
66677 return 0;
66678
66679 @@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66680 goto free;
66681
66682 while (count > 0) {
66683 - int this_len = min_t(int, count, PAGE_SIZE);
66684 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66685
66686 if (write && copy_from_user(page, buf, this_len)) {
66687 copied = -EFAULT;
66688 @@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66689 if (!mm)
66690 return 0;
66691
66692 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66693 + if (file->f_version != current->exec_id) {
66694 + gr_log_badprocpid("environ");
66695 + return 0;
66696 + }
66697 +#endif
66698 +
66699 page = (char *)__get_free_page(GFP_TEMPORARY);
66700 if (!page)
66701 return -ENOMEM;
66702 @@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66703 goto free;
66704 while (count > 0) {
66705 size_t this_len, max_len;
66706 - int retval;
66707 + ssize_t retval;
66708
66709 if (src >= (mm->env_end - mm->env_start))
66710 break;
66711 @@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
66712 int error = -EACCES;
66713
66714 /* Are we allowed to snoop on the tasks file descriptors? */
66715 - if (!proc_fd_access_allowed(inode))
66716 + if (!proc_fd_access_allowed(inode, 0))
66717 goto out;
66718
66719 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66720 @@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
66721 struct path path;
66722
66723 /* Are we allowed to snoop on the tasks file descriptors? */
66724 - if (!proc_fd_access_allowed(inode))
66725 - goto out;
66726 + /* logging this is needed for learning on chromium to work properly,
66727 + but we don't want to flood the logs from 'ps' which does a readlink
66728 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
66729 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
66730 + */
66731 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
66732 + if (!proc_fd_access_allowed(inode,0))
66733 + goto out;
66734 + } else {
66735 + if (!proc_fd_access_allowed(inode,1))
66736 + goto out;
66737 + }
66738
66739 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66740 if (error)
66741 @@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
66742 rcu_read_lock();
66743 cred = __task_cred(task);
66744 inode->i_uid = cred->euid;
66745 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66746 + inode->i_gid = grsec_proc_gid;
66747 +#else
66748 inode->i_gid = cred->egid;
66749 +#endif
66750 rcu_read_unlock();
66751 }
66752 security_task_to_inode(task, inode);
66753 @@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
66754 return -ENOENT;
66755 }
66756 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66757 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66758 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66759 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66760 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66761 +#endif
66762 task_dumpable(task)) {
66763 cred = __task_cred(task);
66764 stat->uid = cred->euid;
66765 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66766 + stat->gid = grsec_proc_gid;
66767 +#else
66768 stat->gid = cred->egid;
66769 +#endif
66770 }
66771 }
66772 rcu_read_unlock();
66773 @@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
66774
66775 if (task) {
66776 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66777 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66778 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66779 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66780 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66781 +#endif
66782 task_dumpable(task)) {
66783 rcu_read_lock();
66784 cred = __task_cred(task);
66785 inode->i_uid = cred->euid;
66786 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66787 + inode->i_gid = grsec_proc_gid;
66788 +#else
66789 inode->i_gid = cred->egid;
66790 +#endif
66791 rcu_read_unlock();
66792 } else {
66793 inode->i_uid = GLOBAL_ROOT_UID;
66794 @@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
66795 if (!task)
66796 goto out_no_task;
66797
66798 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66799 + goto out;
66800 +
66801 /*
66802 * Yes, it does not scale. And it should not. Don't add
66803 * new entries into /proc/<tgid>/ without very good reasons.
66804 @@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
66805 if (!task)
66806 return -ENOENT;
66807
66808 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66809 + goto out;
66810 +
66811 if (!dir_emit_dots(file, ctx))
66812 goto out;
66813
66814 @@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
66815 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
66816 #endif
66817 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66818 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66819 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66820 INF("syscall", S_IRUSR, proc_pid_syscall),
66821 #endif
66822 INF("cmdline", S_IRUGO, proc_pid_cmdline),
66823 @@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
66824 #ifdef CONFIG_SECURITY
66825 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66826 #endif
66827 -#ifdef CONFIG_KALLSYMS
66828 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66829 INF("wchan", S_IRUGO, proc_pid_wchan),
66830 #endif
66831 -#ifdef CONFIG_STACKTRACE
66832 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66833 ONE("stack", S_IRUSR, proc_pid_stack),
66834 #endif
66835 #ifdef CONFIG_SCHEDSTATS
66836 @@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
66837 #ifdef CONFIG_HARDWALL
66838 INF("hardwall", S_IRUGO, proc_pid_hardwall),
66839 #endif
66840 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66841 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
66842 +#endif
66843 #ifdef CONFIG_USER_NS
66844 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
66845 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
66846 @@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
66847 if (!inode)
66848 goto out;
66849
66850 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66851 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
66852 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66853 + inode->i_gid = grsec_proc_gid;
66854 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
66855 +#else
66856 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
66857 +#endif
66858 inode->i_op = &proc_tgid_base_inode_operations;
66859 inode->i_fop = &proc_tgid_base_operations;
66860 inode->i_flags|=S_IMMUTABLE;
66861 @@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
66862 if (!task)
66863 goto out;
66864
66865 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66866 + goto out_put_task;
66867 +
66868 result = proc_pid_instantiate(dir, dentry, task, NULL);
66869 +out_put_task:
66870 put_task_struct(task);
66871 out:
66872 return ERR_PTR(result);
66873 @@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
66874 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
66875 #endif
66876 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66877 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66878 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66879 INF("syscall", S_IRUSR, proc_pid_syscall),
66880 #endif
66881 INF("cmdline", S_IRUGO, proc_pid_cmdline),
66882 @@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
66883 #ifdef CONFIG_SECURITY
66884 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66885 #endif
66886 -#ifdef CONFIG_KALLSYMS
66887 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66888 INF("wchan", S_IRUGO, proc_pid_wchan),
66889 #endif
66890 -#ifdef CONFIG_STACKTRACE
66891 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66892 ONE("stack", S_IRUSR, proc_pid_stack),
66893 #endif
66894 #ifdef CONFIG_SCHEDSTATS
66895 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66896 index cbd82df..c0407d2 100644
66897 --- a/fs/proc/cmdline.c
66898 +++ b/fs/proc/cmdline.c
66899 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66900
66901 static int __init proc_cmdline_init(void)
66902 {
66903 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66904 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66905 +#else
66906 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66907 +#endif
66908 return 0;
66909 }
66910 fs_initcall(proc_cmdline_init);
66911 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66912 index 50493ed..248166b 100644
66913 --- a/fs/proc/devices.c
66914 +++ b/fs/proc/devices.c
66915 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66916
66917 static int __init proc_devices_init(void)
66918 {
66919 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66920 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66921 +#else
66922 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66923 +#endif
66924 return 0;
66925 }
66926 fs_initcall(proc_devices_init);
66927 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66928 index 0788d09..9cc1385 100644
66929 --- a/fs/proc/fd.c
66930 +++ b/fs/proc/fd.c
66931 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66932 if (!task)
66933 return -ENOENT;
66934
66935 - files = get_files_struct(task);
66936 + if (!gr_acl_handle_procpidmem(task))
66937 + files = get_files_struct(task);
66938 put_task_struct(task);
66939
66940 if (files) {
66941 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66942 */
66943 int proc_fd_permission(struct inode *inode, int mask)
66944 {
66945 + struct task_struct *task;
66946 int rv = generic_permission(inode, mask);
66947 - if (rv == 0)
66948 - return 0;
66949 +
66950 if (task_tgid(current) == proc_pid(inode))
66951 rv = 0;
66952 +
66953 + task = get_proc_task(inode);
66954 + if (task == NULL)
66955 + return rv;
66956 +
66957 + if (gr_acl_handle_procpidmem(task))
66958 + rv = -EACCES;
66959 +
66960 + put_task_struct(task);
66961 +
66962 return rv;
66963 }
66964
66965 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66966 index b7f268e..3bea6b7 100644
66967 --- a/fs/proc/generic.c
66968 +++ b/fs/proc/generic.c
66969 @@ -23,6 +23,7 @@
66970 #include <linux/bitops.h>
66971 #include <linux/spinlock.h>
66972 #include <linux/completion.h>
66973 +#include <linux/grsecurity.h>
66974 #include <asm/uaccess.h>
66975
66976 #include "internal.h"
66977 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66978 return proc_lookup_de(PDE(dir), dir, dentry);
66979 }
66980
66981 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66982 + unsigned int flags)
66983 +{
66984 + if (gr_proc_is_restricted())
66985 + return ERR_PTR(-EACCES);
66986 +
66987 + return proc_lookup_de(PDE(dir), dir, dentry);
66988 +}
66989 +
66990 /*
66991 * This returns non-zero if at EOF, so that the /proc
66992 * root directory can use this and check if it should
66993 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66994 return proc_readdir_de(PDE(inode), file, ctx);
66995 }
66996
66997 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66998 +{
66999 + struct inode *inode = file_inode(file);
67000 +
67001 + if (gr_proc_is_restricted())
67002 + return -EACCES;
67003 +
67004 + return proc_readdir_de(PDE(inode), file, ctx);
67005 +}
67006 +
67007 /*
67008 * These are the generic /proc directory operations. They
67009 * use the in-memory "struct proc_dir_entry" tree to parse
67010 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
67011 .iterate = proc_readdir,
67012 };
67013
67014 +static const struct file_operations proc_dir_restricted_operations = {
67015 + .llseek = generic_file_llseek,
67016 + .read = generic_read_dir,
67017 + .iterate = proc_readdir_restrict,
67018 +};
67019 +
67020 /*
67021 * proc directories can do almost nothing..
67022 */
67023 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
67024 .setattr = proc_notify_change,
67025 };
67026
67027 +static const struct inode_operations proc_dir_restricted_inode_operations = {
67028 + .lookup = proc_lookup_restrict,
67029 + .getattr = proc_getattr,
67030 + .setattr = proc_notify_change,
67031 +};
67032 +
67033 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
67034 {
67035 struct proc_dir_entry *tmp;
67036 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
67037 return ret;
67038
67039 if (S_ISDIR(dp->mode)) {
67040 - dp->proc_fops = &proc_dir_operations;
67041 - dp->proc_iops = &proc_dir_inode_operations;
67042 + if (dp->restricted) {
67043 + dp->proc_fops = &proc_dir_restricted_operations;
67044 + dp->proc_iops = &proc_dir_restricted_inode_operations;
67045 + } else {
67046 + dp->proc_fops = &proc_dir_operations;
67047 + dp->proc_iops = &proc_dir_inode_operations;
67048 + }
67049 dir->nlink++;
67050 } else if (S_ISLNK(dp->mode)) {
67051 dp->proc_iops = &proc_link_inode_operations;
67052 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
67053 }
67054 EXPORT_SYMBOL_GPL(proc_mkdir_data);
67055
67056 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
67057 + struct proc_dir_entry *parent, void *data)
67058 +{
67059 + struct proc_dir_entry *ent;
67060 +
67061 + if (mode == 0)
67062 + mode = S_IRUGO | S_IXUGO;
67063 +
67064 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
67065 + if (ent) {
67066 + ent->data = data;
67067 + ent->restricted = 1;
67068 + if (proc_register(parent, ent) < 0) {
67069 + kfree(ent);
67070 + ent = NULL;
67071 + }
67072 + }
67073 + return ent;
67074 +}
67075 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
67076 +
67077 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
67078 struct proc_dir_entry *parent)
67079 {
67080 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
67081 }
67082 EXPORT_SYMBOL(proc_mkdir);
67083
67084 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
67085 + struct proc_dir_entry *parent)
67086 +{
67087 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
67088 +}
67089 +EXPORT_SYMBOL(proc_mkdir_restrict);
67090 +
67091 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
67092 struct proc_dir_entry *parent,
67093 const struct file_operations *proc_fops,
67094 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
67095 index 0adbc02..bee4d0b 100644
67096 --- a/fs/proc/inode.c
67097 +++ b/fs/proc/inode.c
67098 @@ -23,11 +23,17 @@
67099 #include <linux/slab.h>
67100 #include <linux/mount.h>
67101 #include <linux/magic.h>
67102 +#include <linux/grsecurity.h>
67103
67104 #include <asm/uaccess.h>
67105
67106 #include "internal.h"
67107
67108 +#ifdef CONFIG_PROC_SYSCTL
67109 +extern const struct inode_operations proc_sys_inode_operations;
67110 +extern const struct inode_operations proc_sys_dir_operations;
67111 +#endif
67112 +
67113 static void proc_evict_inode(struct inode *inode)
67114 {
67115 struct proc_dir_entry *de;
67116 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
67117 ns = PROC_I(inode)->ns.ns;
67118 if (ns_ops && ns)
67119 ns_ops->put(ns);
67120 +
67121 +#ifdef CONFIG_PROC_SYSCTL
67122 + if (inode->i_op == &proc_sys_inode_operations ||
67123 + inode->i_op == &proc_sys_dir_operations)
67124 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
67125 +#endif
67126 +
67127 }
67128
67129 static struct kmem_cache * proc_inode_cachep;
67130 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
67131 if (de->mode) {
67132 inode->i_mode = de->mode;
67133 inode->i_uid = de->uid;
67134 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67135 + inode->i_gid = grsec_proc_gid;
67136 +#else
67137 inode->i_gid = de->gid;
67138 +#endif
67139 }
67140 if (de->size)
67141 inode->i_size = de->size;
67142 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
67143 index 3ab6d14..b26174e 100644
67144 --- a/fs/proc/internal.h
67145 +++ b/fs/proc/internal.h
67146 @@ -46,9 +46,10 @@ struct proc_dir_entry {
67147 struct completion *pde_unload_completion;
67148 struct list_head pde_openers; /* who did ->open, but not ->release */
67149 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
67150 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
67151 u8 namelen;
67152 char name[];
67153 -};
67154 +} __randomize_layout;
67155
67156 union proc_op {
67157 int (*proc_get_link)(struct dentry *, struct path *);
67158 @@ -67,7 +68,7 @@ struct proc_inode {
67159 struct ctl_table *sysctl_entry;
67160 struct proc_ns ns;
67161 struct inode vfs_inode;
67162 -};
67163 +} __randomize_layout;
67164
67165 /*
67166 * General functions
67167 @@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
67168 struct pid *, struct task_struct *);
67169 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
67170 struct pid *, struct task_struct *);
67171 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
67172 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
67173 +#endif
67174
67175 /*
67176 * base.c
67177 @@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
67178 extern spinlock_t proc_subdir_lock;
67179
67180 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
67181 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
67182 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
67183 struct dentry *);
67184 extern int proc_readdir(struct file *, struct dir_context *);
67185 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
67186 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
67187
67188 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
67189 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
67190 index a352d57..cb94a5c 100644
67191 --- a/fs/proc/interrupts.c
67192 +++ b/fs/proc/interrupts.c
67193 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
67194
67195 static int __init proc_interrupts_init(void)
67196 {
67197 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67198 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
67199 +#else
67200 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
67201 +#endif
67202 return 0;
67203 }
67204 fs_initcall(proc_interrupts_init);
67205 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
67206 index 39e6ef3..2f9cb5e 100644
67207 --- a/fs/proc/kcore.c
67208 +++ b/fs/proc/kcore.c
67209 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67210 * the addresses in the elf_phdr on our list.
67211 */
67212 start = kc_offset_to_vaddr(*fpos - elf_buflen);
67213 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
67214 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
67215 + if (tsz > buflen)
67216 tsz = buflen;
67217 -
67218 +
67219 while (buflen) {
67220 struct kcore_list *m;
67221
67222 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67223 kfree(elf_buf);
67224 } else {
67225 if (kern_addr_valid(start)) {
67226 - unsigned long n;
67227 + char *elf_buf;
67228 + mm_segment_t oldfs;
67229
67230 - n = copy_to_user(buffer, (char *)start, tsz);
67231 - /*
67232 - * We cannot distinguish between fault on source
67233 - * and fault on destination. When this happens
67234 - * we clear too and hope it will trigger the
67235 - * EFAULT again.
67236 - */
67237 - if (n) {
67238 - if (clear_user(buffer + tsz - n,
67239 - n))
67240 + elf_buf = kmalloc(tsz, GFP_KERNEL);
67241 + if (!elf_buf)
67242 + return -ENOMEM;
67243 + oldfs = get_fs();
67244 + set_fs(KERNEL_DS);
67245 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
67246 + set_fs(oldfs);
67247 + if (copy_to_user(buffer, elf_buf, tsz)) {
67248 + kfree(elf_buf);
67249 return -EFAULT;
67250 + }
67251 }
67252 + set_fs(oldfs);
67253 + kfree(elf_buf);
67254 } else {
67255 if (clear_user(buffer, tsz))
67256 return -EFAULT;
67257 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67258
67259 static int open_kcore(struct inode *inode, struct file *filp)
67260 {
67261 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67262 + return -EPERM;
67263 +#endif
67264 if (!capable(CAP_SYS_RAWIO))
67265 return -EPERM;
67266 if (kcore_need_update)
67267 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
67268 index 7445af0..7c5113c 100644
67269 --- a/fs/proc/meminfo.c
67270 +++ b/fs/proc/meminfo.c
67271 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
67272 vmi.used >> 10,
67273 vmi.largest_chunk >> 10
67274 #ifdef CONFIG_MEMORY_FAILURE
67275 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
67276 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
67277 #endif
67278 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
67279 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
67280 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
67281 index d4a3574..b421ce9 100644
67282 --- a/fs/proc/nommu.c
67283 +++ b/fs/proc/nommu.c
67284 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
67285
67286 if (file) {
67287 seq_pad(m, ' ');
67288 - seq_path(m, &file->f_path, "");
67289 + seq_path(m, &file->f_path, "\n\\");
67290 }
67291
67292 seq_putc(m, '\n');
67293 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
67294 index 4677bb7..dad3045 100644
67295 --- a/fs/proc/proc_net.c
67296 +++ b/fs/proc/proc_net.c
67297 @@ -23,9 +23,27 @@
67298 #include <linux/nsproxy.h>
67299 #include <net/net_namespace.h>
67300 #include <linux/seq_file.h>
67301 +#include <linux/grsecurity.h>
67302
67303 #include "internal.h"
67304
67305 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67306 +static struct seq_operations *ipv6_seq_ops_addr;
67307 +
67308 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
67309 +{
67310 + ipv6_seq_ops_addr = addr;
67311 +}
67312 +
67313 +void unregister_ipv6_seq_ops_addr(void)
67314 +{
67315 + ipv6_seq_ops_addr = NULL;
67316 +}
67317 +
67318 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
67319 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
67320 +#endif
67321 +
67322 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
67323 {
67324 return pde->parent->data;
67325 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
67326 return maybe_get_net(PDE_NET(PDE(inode)));
67327 }
67328
67329 +extern const struct seq_operations dev_seq_ops;
67330 +
67331 int seq_open_net(struct inode *ino, struct file *f,
67332 const struct seq_operations *ops, int size)
67333 {
67334 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
67335
67336 BUG_ON(size < sizeof(*p));
67337
67338 + /* only permit access to /proc/net/dev */
67339 + if (
67340 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67341 + ops != ipv6_seq_ops_addr &&
67342 +#endif
67343 + ops != &dev_seq_ops && gr_proc_is_restricted())
67344 + return -EACCES;
67345 +
67346 net = get_proc_net(ino);
67347 if (net == NULL)
67348 return -ENXIO;
67349 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
67350 int err;
67351 struct net *net;
67352
67353 + if (gr_proc_is_restricted())
67354 + return -EACCES;
67355 +
67356 err = -ENXIO;
67357 net = get_proc_net(inode);
67358 if (net == NULL)
67359 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
67360 index 7129046..6914844 100644
67361 --- a/fs/proc/proc_sysctl.c
67362 +++ b/fs/proc/proc_sysctl.c
67363 @@ -11,13 +11,21 @@
67364 #include <linux/namei.h>
67365 #include <linux/mm.h>
67366 #include <linux/module.h>
67367 +#include <linux/nsproxy.h>
67368 +#ifdef CONFIG_GRKERNSEC
67369 +#include <net/net_namespace.h>
67370 +#endif
67371 #include "internal.h"
67372
67373 +extern int gr_handle_chroot_sysctl(const int op);
67374 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
67375 + const int op);
67376 +
67377 static const struct dentry_operations proc_sys_dentry_operations;
67378 static const struct file_operations proc_sys_file_operations;
67379 -static const struct inode_operations proc_sys_inode_operations;
67380 +const struct inode_operations proc_sys_inode_operations;
67381 static const struct file_operations proc_sys_dir_file_operations;
67382 -static const struct inode_operations proc_sys_dir_operations;
67383 +const struct inode_operations proc_sys_dir_operations;
67384
67385 void proc_sys_poll_notify(struct ctl_table_poll *poll)
67386 {
67387 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
67388
67389 err = NULL;
67390 d_set_d_op(dentry, &proc_sys_dentry_operations);
67391 +
67392 + gr_handle_proc_create(dentry, inode);
67393 +
67394 d_add(dentry, inode);
67395
67396 out:
67397 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67398 struct inode *inode = file_inode(filp);
67399 struct ctl_table_header *head = grab_header(inode);
67400 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
67401 + int op = write ? MAY_WRITE : MAY_READ;
67402 ssize_t error;
67403 size_t res;
67404
67405 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67406 * and won't be until we finish.
67407 */
67408 error = -EPERM;
67409 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
67410 + if (sysctl_perm(head, table, op))
67411 goto out;
67412
67413 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
67414 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67415 if (!table->proc_handler)
67416 goto out;
67417
67418 +#ifdef CONFIG_GRKERNSEC
67419 + error = -EPERM;
67420 + if (gr_handle_chroot_sysctl(op))
67421 + goto out;
67422 + dget(filp->f_path.dentry);
67423 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
67424 + dput(filp->f_path.dentry);
67425 + goto out;
67426 + }
67427 + dput(filp->f_path.dentry);
67428 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
67429 + goto out;
67430 + if (write) {
67431 + if (current->nsproxy->net_ns != table->extra2) {
67432 + if (!capable(CAP_SYS_ADMIN))
67433 + goto out;
67434 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
67435 + goto out;
67436 + }
67437 +#endif
67438 +
67439 /* careful: calling conventions are nasty here */
67440 res = count;
67441 error = table->proc_handler(table, write, buf, &res, ppos);
67442 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
67443 return false;
67444 } else {
67445 d_set_d_op(child, &proc_sys_dentry_operations);
67446 +
67447 + gr_handle_proc_create(child, inode);
67448 +
67449 d_add(child, inode);
67450 }
67451 } else {
67452 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
67453 if ((*pos)++ < ctx->pos)
67454 return true;
67455
67456 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
67457 + return 0;
67458 +
67459 if (unlikely(S_ISLNK(table->mode)))
67460 res = proc_sys_link_fill_cache(file, ctx, head, table);
67461 else
67462 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
67463 if (IS_ERR(head))
67464 return PTR_ERR(head);
67465
67466 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
67467 + return -ENOENT;
67468 +
67469 generic_fillattr(inode, stat);
67470 if (table)
67471 stat->mode = (stat->mode & S_IFMT) | table->mode;
67472 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
67473 .llseek = generic_file_llseek,
67474 };
67475
67476 -static const struct inode_operations proc_sys_inode_operations = {
67477 +const struct inode_operations proc_sys_inode_operations = {
67478 .permission = proc_sys_permission,
67479 .setattr = proc_sys_setattr,
67480 .getattr = proc_sys_getattr,
67481 };
67482
67483 -static const struct inode_operations proc_sys_dir_operations = {
67484 +const struct inode_operations proc_sys_dir_operations = {
67485 .lookup = proc_sys_lookup,
67486 .permission = proc_sys_permission,
67487 .setattr = proc_sys_setattr,
67488 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
67489 static struct ctl_dir *new_dir(struct ctl_table_set *set,
67490 const char *name, int namelen)
67491 {
67492 - struct ctl_table *table;
67493 + ctl_table_no_const *table;
67494 struct ctl_dir *new;
67495 struct ctl_node *node;
67496 char *new_name;
67497 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
67498 return NULL;
67499
67500 node = (struct ctl_node *)(new + 1);
67501 - table = (struct ctl_table *)(node + 1);
67502 + table = (ctl_table_no_const *)(node + 1);
67503 new_name = (char *)(table + 2);
67504 memcpy(new_name, name, namelen);
67505 new_name[namelen] = '\0';
67506 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
67507 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
67508 struct ctl_table_root *link_root)
67509 {
67510 - struct ctl_table *link_table, *entry, *link;
67511 + ctl_table_no_const *link_table, *link;
67512 + struct ctl_table *entry;
67513 struct ctl_table_header *links;
67514 struct ctl_node *node;
67515 char *link_name;
67516 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
67517 return NULL;
67518
67519 node = (struct ctl_node *)(links + 1);
67520 - link_table = (struct ctl_table *)(node + nr_entries);
67521 + link_table = (ctl_table_no_const *)(node + nr_entries);
67522 link_name = (char *)&link_table[nr_entries + 1];
67523
67524 for (link = link_table, entry = table; entry->procname; link++, entry++) {
67525 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67526 struct ctl_table_header ***subheader, struct ctl_table_set *set,
67527 struct ctl_table *table)
67528 {
67529 - struct ctl_table *ctl_table_arg = NULL;
67530 - struct ctl_table *entry, *files;
67531 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
67532 + struct ctl_table *entry;
67533 int nr_files = 0;
67534 int nr_dirs = 0;
67535 int err = -ENOMEM;
67536 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67537 nr_files++;
67538 }
67539
67540 - files = table;
67541 /* If there are mixed files and directories we need a new table */
67542 if (nr_dirs && nr_files) {
67543 - struct ctl_table *new;
67544 + ctl_table_no_const *new;
67545 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
67546 GFP_KERNEL);
67547 if (!files)
67548 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67549 /* Register everything except a directory full of subdirectories */
67550 if (nr_files || !nr_dirs) {
67551 struct ctl_table_header *header;
67552 - header = __register_sysctl_table(set, path, files);
67553 + header = __register_sysctl_table(set, path, files ? files : table);
67554 if (!header) {
67555 kfree(ctl_table_arg);
67556 goto out;
67557 diff --git a/fs/proc/root.c b/fs/proc/root.c
67558 index 5dbadec..473af2f 100644
67559 --- a/fs/proc/root.c
67560 +++ b/fs/proc/root.c
67561 @@ -185,7 +185,15 @@ void __init proc_root_init(void)
67562 proc_mkdir("openprom", NULL);
67563 #endif
67564 proc_tty_init();
67565 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67566 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67567 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
67568 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67569 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
67570 +#endif
67571 +#else
67572 proc_mkdir("bus", NULL);
67573 +#endif
67574 proc_sys_init();
67575 }
67576
67577 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
67578 index bf2d03f..f058f9c 100644
67579 --- a/fs/proc/stat.c
67580 +++ b/fs/proc/stat.c
67581 @@ -11,6 +11,7 @@
67582 #include <linux/irqnr.h>
67583 #include <linux/cputime.h>
67584 #include <linux/tick.h>
67585 +#include <linux/grsecurity.h>
67586
67587 #ifndef arch_irq_stat_cpu
67588 #define arch_irq_stat_cpu(cpu) 0
67589 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
67590 u64 sum_softirq = 0;
67591 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
67592 struct timespec boottime;
67593 + int unrestricted = 1;
67594 +
67595 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67596 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67597 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
67598 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67599 + && !in_group_p(grsec_proc_gid)
67600 +#endif
67601 + )
67602 + unrestricted = 0;
67603 +#endif
67604 +#endif
67605
67606 user = nice = system = idle = iowait =
67607 irq = softirq = steal = 0;
67608 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67609 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67610 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67611 idle += get_idle_time(i);
67612 - iowait += get_iowait_time(i);
67613 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67614 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67615 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67616 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67617 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67618 - sum += kstat_cpu_irqs_sum(i);
67619 - sum += arch_irq_stat_cpu(i);
67620 + if (unrestricted) {
67621 + iowait += get_iowait_time(i);
67622 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67623 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67624 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67625 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67626 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67627 + sum += kstat_cpu_irqs_sum(i);
67628 + sum += arch_irq_stat_cpu(i);
67629 + for (j = 0; j < NR_SOFTIRQS; j++) {
67630 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67631
67632 - for (j = 0; j < NR_SOFTIRQS; j++) {
67633 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67634 -
67635 - per_softirq_sums[j] += softirq_stat;
67636 - sum_softirq += softirq_stat;
67637 + per_softirq_sums[j] += softirq_stat;
67638 + sum_softirq += softirq_stat;
67639 + }
67640 }
67641 }
67642 - sum += arch_irq_stat();
67643 + if (unrestricted)
67644 + sum += arch_irq_stat();
67645
67646 seq_puts(p, "cpu ");
67647 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67648 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67649 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67650 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67651 idle = get_idle_time(i);
67652 - iowait = get_iowait_time(i);
67653 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67654 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67655 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67656 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67657 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67658 + if (unrestricted) {
67659 + iowait = get_iowait_time(i);
67660 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67661 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67662 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67663 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67664 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67665 + }
67666 seq_printf(p, "cpu%d", i);
67667 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67668 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67669 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67670
67671 /* sum again ? it could be updated? */
67672 for_each_irq_nr(j)
67673 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
67674 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
67675
67676 seq_printf(p,
67677 "\nctxt %llu\n"
67678 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67679 "processes %lu\n"
67680 "procs_running %lu\n"
67681 "procs_blocked %lu\n",
67682 - nr_context_switches(),
67683 + unrestricted ? nr_context_switches() : 0ULL,
67684 (unsigned long)jif,
67685 - total_forks,
67686 - nr_running(),
67687 - nr_iowait());
67688 + unrestricted ? total_forks : 0UL,
67689 + unrestricted ? nr_running() : 0UL,
67690 + unrestricted ? nr_iowait() : 0UL);
67691
67692 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67693
67694 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67695 index cfa63ee..fce112e 100644
67696 --- a/fs/proc/task_mmu.c
67697 +++ b/fs/proc/task_mmu.c
67698 @@ -13,12 +13,19 @@
67699 #include <linux/swap.h>
67700 #include <linux/swapops.h>
67701 #include <linux/mmu_notifier.h>
67702 +#include <linux/grsecurity.h>
67703
67704 #include <asm/elf.h>
67705 #include <asm/uaccess.h>
67706 #include <asm/tlbflush.h>
67707 #include "internal.h"
67708
67709 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67710 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67711 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
67712 + _mm->pax_flags & MF_PAX_SEGMEXEC))
67713 +#endif
67714 +
67715 void task_mem(struct seq_file *m, struct mm_struct *mm)
67716 {
67717 unsigned long data, text, lib, swap;
67718 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67719 "VmExe:\t%8lu kB\n"
67720 "VmLib:\t%8lu kB\n"
67721 "VmPTE:\t%8lu kB\n"
67722 - "VmSwap:\t%8lu kB\n",
67723 - hiwater_vm << (PAGE_SHIFT-10),
67724 + "VmSwap:\t%8lu kB\n"
67725 +
67726 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67727 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
67728 +#endif
67729 +
67730 + ,hiwater_vm << (PAGE_SHIFT-10),
67731 total_vm << (PAGE_SHIFT-10),
67732 mm->locked_vm << (PAGE_SHIFT-10),
67733 mm->pinned_vm << (PAGE_SHIFT-10),
67734 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67735 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
67736 (PTRS_PER_PTE * sizeof(pte_t) *
67737 atomic_long_read(&mm->nr_ptes)) >> 10,
67738 - swap << (PAGE_SHIFT-10));
67739 + swap << (PAGE_SHIFT-10)
67740 +
67741 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67742 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67743 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
67744 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
67745 +#else
67746 + , mm->context.user_cs_base
67747 + , mm->context.user_cs_limit
67748 +#endif
67749 +#endif
67750 +
67751 + );
67752 }
67753
67754 unsigned long task_vsize(struct mm_struct *mm)
67755 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67756 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
67757 }
67758
67759 - /* We don't show the stack guard page in /proc/maps */
67760 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67761 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
67762 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
67763 +#else
67764 start = vma->vm_start;
67765 - if (stack_guard_page_start(vma, start))
67766 - start += PAGE_SIZE;
67767 end = vma->vm_end;
67768 - if (stack_guard_page_end(vma, end))
67769 - end -= PAGE_SIZE;
67770 +#endif
67771
67772 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
67773 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
67774 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67775 flags & VM_WRITE ? 'w' : '-',
67776 flags & VM_EXEC ? 'x' : '-',
67777 flags & VM_MAYSHARE ? 's' : 'p',
67778 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67779 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
67780 +#else
67781 pgoff,
67782 +#endif
67783 MAJOR(dev), MINOR(dev), ino);
67784
67785 /*
67786 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67787 */
67788 if (file) {
67789 seq_pad(m, ' ');
67790 - seq_path(m, &file->f_path, "\n");
67791 + seq_path(m, &file->f_path, "\n\\");
67792 goto done;
67793 }
67794
67795 @@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67796 * Thread stack in /proc/PID/task/TID/maps or
67797 * the main process stack.
67798 */
67799 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
67800 - vma->vm_end >= mm->start_stack)) {
67801 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
67802 + (vma->vm_start <= mm->start_stack &&
67803 + vma->vm_end >= mm->start_stack)) {
67804 name = "[stack]";
67805 } else {
67806 /* Thread stack in /proc/PID/maps */
67807 @@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
67808 struct proc_maps_private *priv = m->private;
67809 struct task_struct *task = priv->task;
67810
67811 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67812 + if (current->exec_id != m->exec_id) {
67813 + gr_log_badprocpid("maps");
67814 + return 0;
67815 + }
67816 +#endif
67817 +
67818 show_map_vma(m, vma, is_pid);
67819
67820 if (m->count < m->size) /* vma is copied successfully */
67821 @@ -593,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67822 .private = &mss,
67823 };
67824
67825 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67826 + if (current->exec_id != m->exec_id) {
67827 + gr_log_badprocpid("smaps");
67828 + return 0;
67829 + }
67830 +#endif
67831 memset(&mss, 0, sizeof mss);
67832 - mss.vma = vma;
67833 - /* mmap_sem is held in m_start */
67834 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67835 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67836 -
67837 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67838 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
67839 +#endif
67840 + mss.vma = vma;
67841 + /* mmap_sem is held in m_start */
67842 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67843 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67844 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67845 + }
67846 +#endif
67847 show_map_vma(m, vma, is_pid);
67848
67849 seq_printf(m,
67850 @@ -616,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67851 "KernelPageSize: %8lu kB\n"
67852 "MMUPageSize: %8lu kB\n"
67853 "Locked: %8lu kB\n",
67854 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67855 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
67856 +#else
67857 (vma->vm_end - vma->vm_start) >> 10,
67858 +#endif
67859 mss.resident >> 10,
67860 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
67861 mss.shared_clean >> 10,
67862 @@ -1398,6 +1449,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67863 char buffer[64];
67864 int nid;
67865
67866 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67867 + if (current->exec_id != m->exec_id) {
67868 + gr_log_badprocpid("numa_maps");
67869 + return 0;
67870 + }
67871 +#endif
67872 +
67873 if (!mm)
67874 return 0;
67875
67876 @@ -1415,11 +1473,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67877 mpol_to_str(buffer, sizeof(buffer), pol);
67878 mpol_cond_put(pol);
67879
67880 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67881 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
67882 +#else
67883 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
67884 +#endif
67885
67886 if (file) {
67887 seq_puts(m, " file=");
67888 - seq_path(m, &file->f_path, "\n\t= ");
67889 + seq_path(m, &file->f_path, "\n\t\\= ");
67890 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67891 seq_puts(m, " heap");
67892 } else {
67893 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67894 index 678455d..ebd3245 100644
67895 --- a/fs/proc/task_nommu.c
67896 +++ b/fs/proc/task_nommu.c
67897 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67898 else
67899 bytes += kobjsize(mm);
67900
67901 - if (current->fs && current->fs->users > 1)
67902 + if (current->fs && atomic_read(&current->fs->users) > 1)
67903 sbytes += kobjsize(current->fs);
67904 else
67905 bytes += kobjsize(current->fs);
67906 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67907
67908 if (file) {
67909 seq_pad(m, ' ');
67910 - seq_path(m, &file->f_path, "");
67911 + seq_path(m, &file->f_path, "\n\\");
67912 } else if (mm) {
67913 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
67914
67915 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67916 index 382aa89..6b03974 100644
67917 --- a/fs/proc/vmcore.c
67918 +++ b/fs/proc/vmcore.c
67919 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67920 nr_bytes = count;
67921
67922 /* If pfn is not ram, return zeros for sparse dump files */
67923 - if (pfn_is_ram(pfn) == 0)
67924 - memset(buf, 0, nr_bytes);
67925 - else {
67926 + if (pfn_is_ram(pfn) == 0) {
67927 + if (userbuf) {
67928 + if (clear_user((char __force_user *)buf, nr_bytes))
67929 + return -EFAULT;
67930 + } else
67931 + memset(buf, 0, nr_bytes);
67932 + } else {
67933 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67934 offset, userbuf);
67935 if (tmp < 0)
67936 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67937 static int copy_to(void *target, void *src, size_t size, int userbuf)
67938 {
67939 if (userbuf) {
67940 - if (copy_to_user((char __user *) target, src, size))
67941 + if (copy_to_user((char __force_user *) target, src, size))
67942 return -EFAULT;
67943 } else {
67944 memcpy(target, src, size);
67945 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67946 if (*fpos < m->offset + m->size) {
67947 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67948 start = m->paddr + *fpos - m->offset;
67949 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67950 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67951 if (tmp < 0)
67952 return tmp;
67953 buflen -= tsz;
67954 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67955 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67956 size_t buflen, loff_t *fpos)
67957 {
67958 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67959 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67960 }
67961
67962 /*
67963 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67964 index b00fcc9..e0c6381 100644
67965 --- a/fs/qnx6/qnx6.h
67966 +++ b/fs/qnx6/qnx6.h
67967 @@ -74,7 +74,7 @@ enum {
67968 BYTESEX_BE,
67969 };
67970
67971 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67972 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67973 {
67974 if (sbi->s_bytesex == BYTESEX_LE)
67975 return le64_to_cpu((__force __le64)n);
67976 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67977 return (__force __fs64)cpu_to_be64(n);
67978 }
67979
67980 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67981 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67982 {
67983 if (sbi->s_bytesex == BYTESEX_LE)
67984 return le32_to_cpu((__force __le32)n);
67985 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67986 index 72d2917..c917c12 100644
67987 --- a/fs/quota/netlink.c
67988 +++ b/fs/quota/netlink.c
67989 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
67990 void quota_send_warning(struct kqid qid, dev_t dev,
67991 const char warntype)
67992 {
67993 - static atomic_t seq;
67994 + static atomic_unchecked_t seq;
67995 struct sk_buff *skb;
67996 void *msg_head;
67997 int ret;
67998 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67999 "VFS: Not enough memory to send quota warning.\n");
68000 return;
68001 }
68002 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
68003 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
68004 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
68005 if (!msg_head) {
68006 printk(KERN_ERR
68007 diff --git a/fs/read_write.c b/fs/read_write.c
68008 index 009d854..16ce214 100644
68009 --- a/fs/read_write.c
68010 +++ b/fs/read_write.c
68011 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
68012
68013 old_fs = get_fs();
68014 set_fs(get_ds());
68015 - p = (__force const char __user *)buf;
68016 + p = (const char __force_user *)buf;
68017 if (count > MAX_RW_COUNT)
68018 count = MAX_RW_COUNT;
68019 if (file->f_op->write)
68020 diff --git a/fs/readdir.c b/fs/readdir.c
68021 index 33fd922..e0d6094 100644
68022 --- a/fs/readdir.c
68023 +++ b/fs/readdir.c
68024 @@ -18,6 +18,7 @@
68025 #include <linux/security.h>
68026 #include <linux/syscalls.h>
68027 #include <linux/unistd.h>
68028 +#include <linux/namei.h>
68029
68030 #include <asm/uaccess.h>
68031
68032 @@ -71,6 +72,7 @@ struct old_linux_dirent {
68033 struct readdir_callback {
68034 struct dir_context ctx;
68035 struct old_linux_dirent __user * dirent;
68036 + struct file * file;
68037 int result;
68038 };
68039
68040 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
68041 buf->result = -EOVERFLOW;
68042 return -EOVERFLOW;
68043 }
68044 +
68045 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68046 + return 0;
68047 +
68048 buf->result++;
68049 dirent = buf->dirent;
68050 if (!access_ok(VERIFY_WRITE, dirent,
68051 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
68052 if (!f.file)
68053 return -EBADF;
68054
68055 + buf.file = f.file;
68056 error = iterate_dir(f.file, &buf.ctx);
68057 if (buf.result)
68058 error = buf.result;
68059 @@ -144,6 +151,7 @@ struct getdents_callback {
68060 struct dir_context ctx;
68061 struct linux_dirent __user * current_dir;
68062 struct linux_dirent __user * previous;
68063 + struct file * file;
68064 int count;
68065 int error;
68066 };
68067 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
68068 buf->error = -EOVERFLOW;
68069 return -EOVERFLOW;
68070 }
68071 +
68072 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68073 + return 0;
68074 +
68075 dirent = buf->previous;
68076 if (dirent) {
68077 if (__put_user(offset, &dirent->d_off))
68078 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
68079 if (!f.file)
68080 return -EBADF;
68081
68082 + buf.file = f.file;
68083 error = iterate_dir(f.file, &buf.ctx);
68084 if (error >= 0)
68085 error = buf.error;
68086 @@ -228,6 +241,7 @@ struct getdents_callback64 {
68087 struct dir_context ctx;
68088 struct linux_dirent64 __user * current_dir;
68089 struct linux_dirent64 __user * previous;
68090 + struct file *file;
68091 int count;
68092 int error;
68093 };
68094 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
68095 buf->error = -EINVAL; /* only used if we fail.. */
68096 if (reclen > buf->count)
68097 return -EINVAL;
68098 +
68099 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68100 + return 0;
68101 +
68102 dirent = buf->previous;
68103 if (dirent) {
68104 if (__put_user(offset, &dirent->d_off))
68105 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
68106 if (!f.file)
68107 return -EBADF;
68108
68109 + buf.file = f.file;
68110 error = iterate_dir(f.file, &buf.ctx);
68111 if (error >= 0)
68112 error = buf.error;
68113 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
68114 index 54fdf19..987862b 100644
68115 --- a/fs/reiserfs/do_balan.c
68116 +++ b/fs/reiserfs/do_balan.c
68117 @@ -1872,7 +1872,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
68118 return;
68119 }
68120
68121 - atomic_inc(&fs_generation(tb->tb_sb));
68122 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
68123 do_balance_starts(tb);
68124
68125 /*
68126 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
68127 index cfaee91..b9d0d60 100644
68128 --- a/fs/reiserfs/item_ops.c
68129 +++ b/fs/reiserfs/item_ops.c
68130 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
68131 }
68132
68133 static struct item_operations errcatch_ops = {
68134 - errcatch_bytes_number,
68135 - errcatch_decrement_key,
68136 - errcatch_is_left_mergeable,
68137 - errcatch_print_item,
68138 - errcatch_check_item,
68139 + .bytes_number = errcatch_bytes_number,
68140 + .decrement_key = errcatch_decrement_key,
68141 + .is_left_mergeable = errcatch_is_left_mergeable,
68142 + .print_item = errcatch_print_item,
68143 + .check_item = errcatch_check_item,
68144
68145 - errcatch_create_vi,
68146 - errcatch_check_left,
68147 - errcatch_check_right,
68148 - errcatch_part_size,
68149 - errcatch_unit_num,
68150 - errcatch_print_vi
68151 + .create_vi = errcatch_create_vi,
68152 + .check_left = errcatch_check_left,
68153 + .check_right = errcatch_check_right,
68154 + .part_size = errcatch_part_size,
68155 + .unit_num = errcatch_unit_num,
68156 + .print_vi = errcatch_print_vi
68157 };
68158
68159 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
68160 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
68161 index 02b0b7d..c85018b 100644
68162 --- a/fs/reiserfs/procfs.c
68163 +++ b/fs/reiserfs/procfs.c
68164 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
68165 "SMALL_TAILS " : "NO_TAILS ",
68166 replay_only(sb) ? "REPLAY_ONLY " : "",
68167 convert_reiserfs(sb) ? "CONV " : "",
68168 - atomic_read(&r->s_generation_counter),
68169 + atomic_read_unchecked(&r->s_generation_counter),
68170 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
68171 SF(s_do_balance), SF(s_unneeded_left_neighbor),
68172 SF(s_good_search_by_key_reada), SF(s_bmaps),
68173 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
68174 index bf53888..227f5ae 100644
68175 --- a/fs/reiserfs/reiserfs.h
68176 +++ b/fs/reiserfs/reiserfs.h
68177 @@ -573,7 +573,7 @@ struct reiserfs_sb_info {
68178 /* Comment? -Hans */
68179 wait_queue_head_t s_wait;
68180 /* increased by one every time the tree gets re-balanced */
68181 - atomic_t s_generation_counter;
68182 + atomic_unchecked_t s_generation_counter;
68183
68184 /* File system properties. Currently holds on-disk FS format */
68185 unsigned long s_properties;
68186 @@ -2294,7 +2294,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
68187 #define REISERFS_USER_MEM 1 /* user memory mode */
68188
68189 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
68190 -#define get_generation(s) atomic_read (&fs_generation(s))
68191 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
68192 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
68193 #define __fs_changed(gen,s) (gen != get_generation (s))
68194 #define fs_changed(gen,s) \
68195 diff --git a/fs/select.c b/fs/select.c
68196 index 467bb1c..cf9d65a 100644
68197 --- a/fs/select.c
68198 +++ b/fs/select.c
68199 @@ -20,6 +20,7 @@
68200 #include <linux/export.h>
68201 #include <linux/slab.h>
68202 #include <linux/poll.h>
68203 +#include <linux/security.h>
68204 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
68205 #include <linux/file.h>
68206 #include <linux/fdtable.h>
68207 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
68208 struct poll_list *walk = head;
68209 unsigned long todo = nfds;
68210
68211 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
68212 if (nfds > rlimit(RLIMIT_NOFILE))
68213 return -EINVAL;
68214
68215 diff --git a/fs/seq_file.c b/fs/seq_file.c
68216 index 3857b72..0b7281e 100644
68217 --- a/fs/seq_file.c
68218 +++ b/fs/seq_file.c
68219 @@ -12,6 +12,8 @@
68220 #include <linux/slab.h>
68221 #include <linux/cred.h>
68222 #include <linux/mm.h>
68223 +#include <linux/sched.h>
68224 +#include <linux/grsecurity.h>
68225
68226 #include <asm/uaccess.h>
68227 #include <asm/page.h>
68228 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
68229
68230 static void *seq_buf_alloc(unsigned long size)
68231 {
68232 - void *buf;
68233 -
68234 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
68235 - if (!buf && size > PAGE_SIZE)
68236 - buf = vmalloc(size);
68237 - return buf;
68238 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
68239 }
68240
68241 /**
68242 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
68243 #ifdef CONFIG_USER_NS
68244 p->user_ns = file->f_cred->user_ns;
68245 #endif
68246 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68247 + p->exec_id = current->exec_id;
68248 +#endif
68249
68250 /*
68251 * Wrappers around seq_open(e.g. swaps_open) need to be
68252 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
68253 }
68254 EXPORT_SYMBOL(seq_open);
68255
68256 +
68257 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
68258 +{
68259 + if (gr_proc_is_restricted())
68260 + return -EACCES;
68261 +
68262 + return seq_open(file, op);
68263 +}
68264 +EXPORT_SYMBOL(seq_open_restrict);
68265 +
68266 static int traverse(struct seq_file *m, loff_t offset)
68267 {
68268 loff_t pos = 0, index;
68269 @@ -165,7 +175,7 @@ Eoverflow:
68270 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
68271 {
68272 struct seq_file *m = file->private_data;
68273 - size_t copied = 0;
68274 + ssize_t copied = 0;
68275 loff_t pos;
68276 size_t n;
68277 void *p;
68278 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
68279 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
68280 void *data)
68281 {
68282 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
68283 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
68284 int res = -ENOMEM;
68285
68286 if (op) {
68287 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
68288 }
68289 EXPORT_SYMBOL(single_open_size);
68290
68291 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
68292 + void *data)
68293 +{
68294 + if (gr_proc_is_restricted())
68295 + return -EACCES;
68296 +
68297 + return single_open(file, show, data);
68298 +}
68299 +EXPORT_SYMBOL(single_open_restrict);
68300 +
68301 +
68302 int single_release(struct inode *inode, struct file *file)
68303 {
68304 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
68305 diff --git a/fs/splice.c b/fs/splice.c
68306 index f5cb9ba..8ddb1e9 100644
68307 --- a/fs/splice.c
68308 +++ b/fs/splice.c
68309 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68310 pipe_lock(pipe);
68311
68312 for (;;) {
68313 - if (!pipe->readers) {
68314 + if (!atomic_read(&pipe->readers)) {
68315 send_sig(SIGPIPE, current, 0);
68316 if (!ret)
68317 ret = -EPIPE;
68318 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68319 page_nr++;
68320 ret += buf->len;
68321
68322 - if (pipe->files)
68323 + if (atomic_read(&pipe->files))
68324 do_wakeup = 1;
68325
68326 if (!--spd->nr_pages)
68327 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68328 do_wakeup = 0;
68329 }
68330
68331 - pipe->waiting_writers++;
68332 + atomic_inc(&pipe->waiting_writers);
68333 pipe_wait(pipe);
68334 - pipe->waiting_writers--;
68335 + atomic_dec(&pipe->waiting_writers);
68336 }
68337
68338 pipe_unlock(pipe);
68339 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
68340 old_fs = get_fs();
68341 set_fs(get_ds());
68342 /* The cast to a user pointer is valid due to the set_fs() */
68343 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
68344 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
68345 set_fs(old_fs);
68346
68347 return res;
68348 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
68349 old_fs = get_fs();
68350 set_fs(get_ds());
68351 /* The cast to a user pointer is valid due to the set_fs() */
68352 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
68353 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
68354 set_fs(old_fs);
68355
68356 return res;
68357 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
68358 goto err;
68359
68360 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
68361 - vec[i].iov_base = (void __user *) page_address(page);
68362 + vec[i].iov_base = (void __force_user *) page_address(page);
68363 vec[i].iov_len = this_len;
68364 spd.pages[i] = page;
68365 spd.nr_pages++;
68366 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68367 ops->release(pipe, buf);
68368 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68369 pipe->nrbufs--;
68370 - if (pipe->files)
68371 + if (atomic_read(&pipe->files))
68372 sd->need_wakeup = true;
68373 }
68374
68375 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68376 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
68377 {
68378 while (!pipe->nrbufs) {
68379 - if (!pipe->writers)
68380 + if (!atomic_read(&pipe->writers))
68381 return 0;
68382
68383 - if (!pipe->waiting_writers && sd->num_spliced)
68384 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
68385 return 0;
68386
68387 if (sd->flags & SPLICE_F_NONBLOCK)
68388 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
68389 ops->release(pipe, buf);
68390 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68391 pipe->nrbufs--;
68392 - if (pipe->files)
68393 + if (atomic_read(&pipe->files))
68394 sd.need_wakeup = true;
68395 } else {
68396 buf->offset += ret;
68397 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
68398 * out of the pipe right after the splice_to_pipe(). So set
68399 * PIPE_READERS appropriately.
68400 */
68401 - pipe->readers = 1;
68402 + atomic_set(&pipe->readers, 1);
68403
68404 current->splice_pipe = pipe;
68405 }
68406 @@ -1496,6 +1496,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
68407
68408 partial[buffers].offset = off;
68409 partial[buffers].len = plen;
68410 + partial[buffers].private = 0;
68411
68412 off = 0;
68413 len -= plen;
68414 @@ -1732,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68415 ret = -ERESTARTSYS;
68416 break;
68417 }
68418 - if (!pipe->writers)
68419 + if (!atomic_read(&pipe->writers))
68420 break;
68421 - if (!pipe->waiting_writers) {
68422 + if (!atomic_read(&pipe->waiting_writers)) {
68423 if (flags & SPLICE_F_NONBLOCK) {
68424 ret = -EAGAIN;
68425 break;
68426 @@ -1766,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68427 pipe_lock(pipe);
68428
68429 while (pipe->nrbufs >= pipe->buffers) {
68430 - if (!pipe->readers) {
68431 + if (!atomic_read(&pipe->readers)) {
68432 send_sig(SIGPIPE, current, 0);
68433 ret = -EPIPE;
68434 break;
68435 @@ -1779,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68436 ret = -ERESTARTSYS;
68437 break;
68438 }
68439 - pipe->waiting_writers++;
68440 + atomic_inc(&pipe->waiting_writers);
68441 pipe_wait(pipe);
68442 - pipe->waiting_writers--;
68443 + atomic_dec(&pipe->waiting_writers);
68444 }
68445
68446 pipe_unlock(pipe);
68447 @@ -1817,14 +1818,14 @@ retry:
68448 pipe_double_lock(ipipe, opipe);
68449
68450 do {
68451 - if (!opipe->readers) {
68452 + if (!atomic_read(&opipe->readers)) {
68453 send_sig(SIGPIPE, current, 0);
68454 if (!ret)
68455 ret = -EPIPE;
68456 break;
68457 }
68458
68459 - if (!ipipe->nrbufs && !ipipe->writers)
68460 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
68461 break;
68462
68463 /*
68464 @@ -1921,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68465 pipe_double_lock(ipipe, opipe);
68466
68467 do {
68468 - if (!opipe->readers) {
68469 + if (!atomic_read(&opipe->readers)) {
68470 send_sig(SIGPIPE, current, 0);
68471 if (!ret)
68472 ret = -EPIPE;
68473 @@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68474 * return EAGAIN if we have the potential of some data in the
68475 * future, otherwise just return 0
68476 */
68477 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
68478 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
68479 ret = -EAGAIN;
68480
68481 pipe_unlock(ipipe);
68482 diff --git a/fs/stat.c b/fs/stat.c
68483 index ae0c3ce..9ee641c 100644
68484 --- a/fs/stat.c
68485 +++ b/fs/stat.c
68486 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
68487 stat->gid = inode->i_gid;
68488 stat->rdev = inode->i_rdev;
68489 stat->size = i_size_read(inode);
68490 - stat->atime = inode->i_atime;
68491 - stat->mtime = inode->i_mtime;
68492 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68493 + stat->atime = inode->i_ctime;
68494 + stat->mtime = inode->i_ctime;
68495 + } else {
68496 + stat->atime = inode->i_atime;
68497 + stat->mtime = inode->i_mtime;
68498 + }
68499 stat->ctime = inode->i_ctime;
68500 stat->blksize = (1 << inode->i_blkbits);
68501 stat->blocks = inode->i_blocks;
68502 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
68503 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
68504 {
68505 struct inode *inode = path->dentry->d_inode;
68506 + int retval;
68507
68508 - if (inode->i_op->getattr)
68509 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
68510 + if (inode->i_op->getattr) {
68511 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
68512 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68513 + stat->atime = stat->ctime;
68514 + stat->mtime = stat->ctime;
68515 + }
68516 + return retval;
68517 + }
68518
68519 generic_fillattr(inode, stat);
68520 return 0;
68521 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
68522 index 0b45ff4..847de5b 100644
68523 --- a/fs/sysfs/dir.c
68524 +++ b/fs/sysfs/dir.c
68525 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
68526 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68527 {
68528 struct kernfs_node *parent, *kn;
68529 + const char *name;
68530 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
68531 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68532 + const char *parent_name;
68533 +#endif
68534
68535 BUG_ON(!kobj);
68536
68537 + name = kobject_name(kobj);
68538 +
68539 if (kobj->parent)
68540 parent = kobj->parent->sd;
68541 else
68542 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68543 if (!parent)
68544 return -ENOENT;
68545
68546 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
68547 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
68548 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68549 + parent_name = parent->name;
68550 + mode = S_IRWXU;
68551 +
68552 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
68553 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
68554 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
68555 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
68556 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
68557 +#endif
68558 +
68559 + kn = kernfs_create_dir_ns(parent, name,
68560 + mode, kobj, ns);
68561 if (IS_ERR(kn)) {
68562 if (PTR_ERR(kn) == -EEXIST)
68563 - sysfs_warn_dup(parent, kobject_name(kobj));
68564 + sysfs_warn_dup(parent, name);
68565 return PTR_ERR(kn);
68566 }
68567
68568 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
68569 index 69d4889..a810bd4 100644
68570 --- a/fs/sysv/sysv.h
68571 +++ b/fs/sysv/sysv.h
68572 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
68573 #endif
68574 }
68575
68576 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68577 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68578 {
68579 if (sbi->s_bytesex == BYTESEX_PDP)
68580 return PDP_swab((__force __u32)n);
68581 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
68582 index 2290d58..7791371 100644
68583 --- a/fs/ubifs/io.c
68584 +++ b/fs/ubifs/io.c
68585 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
68586 return err;
68587 }
68588
68589 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68590 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68591 {
68592 int err;
68593
68594 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68595 index c175b4d..8f36a16 100644
68596 --- a/fs/udf/misc.c
68597 +++ b/fs/udf/misc.c
68598 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68599
68600 u8 udf_tag_checksum(const struct tag *t)
68601 {
68602 - u8 *data = (u8 *)t;
68603 + const u8 *data = (const u8 *)t;
68604 u8 checksum = 0;
68605 int i;
68606 for (i = 0; i < sizeof(struct tag); ++i)
68607 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68608 index 8d974c4..b82f6ec 100644
68609 --- a/fs/ufs/swab.h
68610 +++ b/fs/ufs/swab.h
68611 @@ -22,7 +22,7 @@ enum {
68612 BYTESEX_BE
68613 };
68614
68615 -static inline u64
68616 +static inline u64 __intentional_overflow(-1)
68617 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68618 {
68619 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68620 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68621 return (__force __fs64)cpu_to_be64(n);
68622 }
68623
68624 -static inline u32
68625 +static inline u32 __intentional_overflow(-1)
68626 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68627 {
68628 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68629 diff --git a/fs/utimes.c b/fs/utimes.c
68630 index aa138d6..5f3a811 100644
68631 --- a/fs/utimes.c
68632 +++ b/fs/utimes.c
68633 @@ -1,6 +1,7 @@
68634 #include <linux/compiler.h>
68635 #include <linux/file.h>
68636 #include <linux/fs.h>
68637 +#include <linux/security.h>
68638 #include <linux/linkage.h>
68639 #include <linux/mount.h>
68640 #include <linux/namei.h>
68641 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68642 }
68643 }
68644 retry_deleg:
68645 +
68646 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68647 + error = -EACCES;
68648 + goto mnt_drop_write_and_out;
68649 + }
68650 +
68651 mutex_lock(&inode->i_mutex);
68652 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68653 mutex_unlock(&inode->i_mutex);
68654 diff --git a/fs/xattr.c b/fs/xattr.c
68655 index c69e6d4..cc56af5 100644
68656 --- a/fs/xattr.c
68657 +++ b/fs/xattr.c
68658 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68659 return rc;
68660 }
68661
68662 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68663 +ssize_t
68664 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
68665 +{
68666 + struct inode *inode = dentry->d_inode;
68667 + ssize_t error;
68668 +
68669 + error = inode_permission(inode, MAY_EXEC);
68670 + if (error)
68671 + return error;
68672 +
68673 + if (inode->i_op->getxattr)
68674 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68675 + else
68676 + error = -EOPNOTSUPP;
68677 +
68678 + return error;
68679 +}
68680 +EXPORT_SYMBOL(pax_getxattr);
68681 +#endif
68682 +
68683 ssize_t
68684 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68685 {
68686 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68687 * Extended attribute SET operations
68688 */
68689 static long
68690 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
68691 +setxattr(struct path *path, const char __user *name, const void __user *value,
68692 size_t size, int flags)
68693 {
68694 int error;
68695 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68696 posix_acl_fix_xattr_from_user(kvalue, size);
68697 }
68698
68699 - error = vfs_setxattr(d, kname, kvalue, size, flags);
68700 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68701 + error = -EACCES;
68702 + goto out;
68703 + }
68704 +
68705 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68706 out:
68707 if (vvalue)
68708 vfree(vvalue);
68709 @@ -377,7 +403,7 @@ retry:
68710 return error;
68711 error = mnt_want_write(path.mnt);
68712 if (!error) {
68713 - error = setxattr(path.dentry, name, value, size, flags);
68714 + error = setxattr(&path, name, value, size, flags);
68715 mnt_drop_write(path.mnt);
68716 }
68717 path_put(&path);
68718 @@ -401,7 +427,7 @@ retry:
68719 return error;
68720 error = mnt_want_write(path.mnt);
68721 if (!error) {
68722 - error = setxattr(path.dentry, name, value, size, flags);
68723 + error = setxattr(&path, name, value, size, flags);
68724 mnt_drop_write(path.mnt);
68725 }
68726 path_put(&path);
68727 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68728 const void __user *,value, size_t, size, int, flags)
68729 {
68730 struct fd f = fdget(fd);
68731 - struct dentry *dentry;
68732 int error = -EBADF;
68733
68734 if (!f.file)
68735 return error;
68736 - dentry = f.file->f_path.dentry;
68737 - audit_inode(NULL, dentry, 0);
68738 + audit_inode(NULL, f.file->f_path.dentry, 0);
68739 error = mnt_want_write_file(f.file);
68740 if (!error) {
68741 - error = setxattr(dentry, name, value, size, flags);
68742 + error = setxattr(&f.file->f_path, name, value, size, flags);
68743 mnt_drop_write_file(f.file);
68744 }
68745 fdput(f);
68746 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68747 * Extended attribute REMOVE operations
68748 */
68749 static long
68750 -removexattr(struct dentry *d, const char __user *name)
68751 +removexattr(struct path *path, const char __user *name)
68752 {
68753 int error;
68754 char kname[XATTR_NAME_MAX + 1];
68755 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
68756 if (error < 0)
68757 return error;
68758
68759 - return vfs_removexattr(d, kname);
68760 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68761 + return -EACCES;
68762 +
68763 + return vfs_removexattr(path->dentry, kname);
68764 }
68765
68766 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
68767 @@ -652,7 +679,7 @@ retry:
68768 return error;
68769 error = mnt_want_write(path.mnt);
68770 if (!error) {
68771 - error = removexattr(path.dentry, name);
68772 + error = removexattr(&path, name);
68773 mnt_drop_write(path.mnt);
68774 }
68775 path_put(&path);
68776 @@ -675,7 +702,7 @@ retry:
68777 return error;
68778 error = mnt_want_write(path.mnt);
68779 if (!error) {
68780 - error = removexattr(path.dentry, name);
68781 + error = removexattr(&path, name);
68782 mnt_drop_write(path.mnt);
68783 }
68784 path_put(&path);
68785 @@ -689,16 +716,16 @@ retry:
68786 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68787 {
68788 struct fd f = fdget(fd);
68789 - struct dentry *dentry;
68790 + struct path *path;
68791 int error = -EBADF;
68792
68793 if (!f.file)
68794 return error;
68795 - dentry = f.file->f_path.dentry;
68796 - audit_inode(NULL, dentry, 0);
68797 + path = &f.file->f_path;
68798 + audit_inode(NULL, path->dentry, 0);
68799 error = mnt_want_write_file(f.file);
68800 if (!error) {
68801 - error = removexattr(dentry, name);
68802 + error = removexattr(path, name);
68803 mnt_drop_write_file(f.file);
68804 }
68805 fdput(f);
68806 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
68807 index 75c3fe5..b0f6bbe 100644
68808 --- a/fs/xfs/xfs_bmap.c
68809 +++ b/fs/xfs/xfs_bmap.c
68810 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68811
68812 #else
68813 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68814 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68815 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68816 #endif /* DEBUG */
68817
68818 /*
68819 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68820 index 48e99af..54ebae3 100644
68821 --- a/fs/xfs/xfs_dir2_readdir.c
68822 +++ b/fs/xfs/xfs_dir2_readdir.c
68823 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68824 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68825 filetype = dp->d_ops->sf_get_ftype(sfep);
68826 ctx->pos = off & 0x7fffffff;
68827 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68828 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68829 + char name[sfep->namelen];
68830 + memcpy(name, sfep->name, sfep->namelen);
68831 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68832 + return 0;
68833 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68834 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68835 return 0;
68836 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68837 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68838 index 8bc1bbc..0d6911b 100644
68839 --- a/fs/xfs/xfs_ioctl.c
68840 +++ b/fs/xfs/xfs_ioctl.c
68841 @@ -122,7 +122,7 @@ xfs_find_handle(
68842 }
68843
68844 error = -EFAULT;
68845 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68846 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68847 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68848 goto out_put;
68849
68850 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68851 new file mode 100644
68852 index 0000000..27cec32
68853 --- /dev/null
68854 +++ b/grsecurity/Kconfig
68855 @@ -0,0 +1,1166 @@
68856 +#
68857 +# grecurity configuration
68858 +#
68859 +menu "Memory Protections"
68860 +depends on GRKERNSEC
68861 +
68862 +config GRKERNSEC_KMEM
68863 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68864 + default y if GRKERNSEC_CONFIG_AUTO
68865 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68866 + help
68867 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68868 + be written to or read from to modify or leak the contents of the running
68869 + kernel. /dev/port will also not be allowed to be opened, writing to
68870 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68871 + If you have module support disabled, enabling this will close up several
68872 + ways that are currently used to insert malicious code into the running
68873 + kernel.
68874 +
68875 + Even with this feature enabled, we still highly recommend that
68876 + you use the RBAC system, as it is still possible for an attacker to
68877 + modify the running kernel through other more obscure methods.
68878 +
68879 + It is highly recommended that you say Y here if you meet all the
68880 + conditions above.
68881 +
68882 +config GRKERNSEC_VM86
68883 + bool "Restrict VM86 mode"
68884 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68885 + depends on X86_32
68886 +
68887 + help
68888 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68889 + make use of a special execution mode on 32bit x86 processors called
68890 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68891 + video cards and will still work with this option enabled. The purpose
68892 + of the option is to prevent exploitation of emulation errors in
68893 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
68894 + Nearly all users should be able to enable this option.
68895 +
68896 +config GRKERNSEC_IO
68897 + bool "Disable privileged I/O"
68898 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68899 + depends on X86
68900 + select RTC_CLASS
68901 + select RTC_INTF_DEV
68902 + select RTC_DRV_CMOS
68903 +
68904 + help
68905 + If you say Y here, all ioperm and iopl calls will return an error.
68906 + Ioperm and iopl can be used to modify the running kernel.
68907 + Unfortunately, some programs need this access to operate properly,
68908 + the most notable of which are XFree86 and hwclock. hwclock can be
68909 + remedied by having RTC support in the kernel, so real-time
68910 + clock support is enabled if this option is enabled, to ensure
68911 + that hwclock operates correctly. If hwclock still does not work,
68912 + either update udev or symlink /dev/rtc to /dev/rtc0.
68913 +
68914 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
68915 + you may not be able to boot into a graphical environment with this
68916 + option enabled. In this case, you should use the RBAC system instead.
68917 +
68918 +config GRKERNSEC_JIT_HARDEN
68919 + bool "Harden BPF JIT against spray attacks"
68920 + default y if GRKERNSEC_CONFIG_AUTO
68921 + depends on BPF_JIT && X86
68922 + help
68923 + If you say Y here, the native code generated by the kernel's Berkeley
68924 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
68925 + attacks that attempt to fit attacker-beneficial instructions in
68926 + 32bit immediate fields of JIT-generated native instructions. The
68927 + attacker will generally aim to cause an unintended instruction sequence
68928 + of JIT-generated native code to execute by jumping into the middle of
68929 + a generated instruction. This feature effectively randomizes the 32bit
68930 + immediate constants present in the generated code to thwart such attacks.
68931 +
68932 + If you're using KERNEXEC, it's recommended that you enable this option
68933 + to supplement the hardening of the kernel.
68934 +
68935 +config GRKERNSEC_PERF_HARDEN
68936 + bool "Disable unprivileged PERF_EVENTS usage by default"
68937 + default y if GRKERNSEC_CONFIG_AUTO
68938 + depends on PERF_EVENTS
68939 + help
68940 + If you say Y here, the range of acceptable values for the
68941 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68942 + default to a new value: 3. When the sysctl is set to this value, no
68943 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68944 +
68945 + Though PERF_EVENTS can be used legitimately for performance monitoring
68946 + and low-level application profiling, it is forced on regardless of
68947 + configuration, has been at fault for several vulnerabilities, and
68948 + creates new opportunities for side channels and other information leaks.
68949 +
68950 + This feature puts PERF_EVENTS into a secure default state and permits
68951 + the administrator to change out of it temporarily if unprivileged
68952 + application profiling is needed.
68953 +
68954 +config GRKERNSEC_RAND_THREADSTACK
68955 + bool "Insert random gaps between thread stacks"
68956 + default y if GRKERNSEC_CONFIG_AUTO
68957 + depends on PAX_RANDMMAP && !PPC
68958 + help
68959 + If you say Y here, a random-sized gap will be enforced between allocated
68960 + thread stacks. Glibc's NPTL and other threading libraries that
68961 + pass MAP_STACK to the kernel for thread stack allocation are supported.
68962 + The implementation currently provides 8 bits of entropy for the gap.
68963 +
68964 + Many distributions do not compile threaded remote services with the
68965 + -fstack-check argument to GCC, causing the variable-sized stack-based
68966 + allocator, alloca(), to not probe the stack on allocation. This
68967 + permits an unbounded alloca() to skip over any guard page and potentially
68968 + modify another thread's stack reliably. An enforced random gap
68969 + reduces the reliability of such an attack and increases the chance
68970 + that such a read/write to another thread's stack instead lands in
68971 + an unmapped area, causing a crash and triggering grsecurity's
68972 + anti-bruteforcing logic.
68973 +
68974 +config GRKERNSEC_PROC_MEMMAP
68975 + bool "Harden ASLR against information leaks and entropy reduction"
68976 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68977 + depends on PAX_NOEXEC || PAX_ASLR
68978 + help
68979 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68980 + give no information about the addresses of its mappings if
68981 + PaX features that rely on random addresses are enabled on the task.
68982 + In addition to sanitizing this information and disabling other
68983 + dangerous sources of information, this option causes reads of sensitive
68984 + /proc/<pid> entries where the file descriptor was opened in a different
68985 + task than the one performing the read. Such attempts are logged.
68986 + This option also limits argv/env strings for suid/sgid binaries
68987 + to 512KB to prevent a complete exhaustion of the stack entropy provided
68988 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68989 + binaries to prevent alternative mmap layouts from being abused.
68990 +
68991 + If you use PaX it is essential that you say Y here as it closes up
68992 + several holes that make full ASLR useless locally.
68993 +
68994 +
68995 +config GRKERNSEC_KSTACKOVERFLOW
68996 + bool "Prevent kernel stack overflows"
68997 + default y if GRKERNSEC_CONFIG_AUTO
68998 + depends on !IA64 && 64BIT
68999 + help
69000 + If you say Y here, the kernel's process stacks will be allocated
69001 + with vmalloc instead of the kernel's default allocator. This
69002 + introduces guard pages that in combination with the alloca checking
69003 + of the STACKLEAK feature prevents all forms of kernel process stack
69004 + overflow abuse. Note that this is different from kernel stack
69005 + buffer overflows.
69006 +
69007 +config GRKERNSEC_BRUTE
69008 + bool "Deter exploit bruteforcing"
69009 + default y if GRKERNSEC_CONFIG_AUTO
69010 + help
69011 + If you say Y here, attempts to bruteforce exploits against forking
69012 + daemons such as apache or sshd, as well as against suid/sgid binaries
69013 + will be deterred. When a child of a forking daemon is killed by PaX
69014 + or crashes due to an illegal instruction or other suspicious signal,
69015 + the parent process will be delayed 30 seconds upon every subsequent
69016 + fork until the administrator is able to assess the situation and
69017 + restart the daemon.
69018 + In the suid/sgid case, the attempt is logged, the user has all their
69019 + existing instances of the suid/sgid binary terminated and will
69020 + be unable to execute any suid/sgid binaries for 15 minutes.
69021 +
69022 + It is recommended that you also enable signal logging in the auditing
69023 + section so that logs are generated when a process triggers a suspicious
69024 + signal.
69025 + If the sysctl option is enabled, a sysctl option with name
69026 + "deter_bruteforce" is created.
69027 +
69028 +config GRKERNSEC_MODHARDEN
69029 + bool "Harden module auto-loading"
69030 + default y if GRKERNSEC_CONFIG_AUTO
69031 + depends on MODULES
69032 + help
69033 + If you say Y here, module auto-loading in response to use of some
69034 + feature implemented by an unloaded module will be restricted to
69035 + root users. Enabling this option helps defend against attacks
69036 + by unprivileged users who abuse the auto-loading behavior to
69037 + cause a vulnerable module to load that is then exploited.
69038 +
69039 + If this option prevents a legitimate use of auto-loading for a
69040 + non-root user, the administrator can execute modprobe manually
69041 + with the exact name of the module mentioned in the alert log.
69042 + Alternatively, the administrator can add the module to the list
69043 + of modules loaded at boot by modifying init scripts.
69044 +
69045 + Modification of init scripts will most likely be needed on
69046 + Ubuntu servers with encrypted home directory support enabled,
69047 + as the first non-root user logging in will cause the ecb(aes),
69048 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
69049 +
69050 +config GRKERNSEC_HIDESYM
69051 + bool "Hide kernel symbols"
69052 + default y if GRKERNSEC_CONFIG_AUTO
69053 + select PAX_USERCOPY_SLABS
69054 + help
69055 + If you say Y here, getting information on loaded modules, and
69056 + displaying all kernel symbols through a syscall will be restricted
69057 + to users with CAP_SYS_MODULE. For software compatibility reasons,
69058 + /proc/kallsyms will be restricted to the root user. The RBAC
69059 + system can hide that entry even from root.
69060 +
69061 + This option also prevents leaking of kernel addresses through
69062 + several /proc entries.
69063 +
69064 + Note that this option is only effective provided the following
69065 + conditions are met:
69066 + 1) The kernel using grsecurity is not precompiled by some distribution
69067 + 2) You have also enabled GRKERNSEC_DMESG
69068 + 3) You are using the RBAC system and hiding other files such as your
69069 + kernel image and System.map. Alternatively, enabling this option
69070 + causes the permissions on /boot, /lib/modules, and the kernel
69071 + source directory to change at compile time to prevent
69072 + reading by non-root users.
69073 + If the above conditions are met, this option will aid in providing a
69074 + useful protection against local kernel exploitation of overflows
69075 + and arbitrary read/write vulnerabilities.
69076 +
69077 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
69078 + in addition to this feature.
69079 +
69080 +config GRKERNSEC_RANDSTRUCT
69081 + bool "Randomize layout of sensitive kernel structures"
69082 + default y if GRKERNSEC_CONFIG_AUTO
69083 + select GRKERNSEC_HIDESYM
69084 + select MODVERSIONS if MODULES
69085 + help
69086 + If you say Y here, the layouts of a number of sensitive kernel
69087 + structures (task, fs, cred, etc) and all structures composed entirely
69088 + of function pointers (aka "ops" structs) will be randomized at compile-time.
69089 + This can introduce the requirement of an additional infoleak
69090 + vulnerability for exploits targeting these structure types.
69091 +
69092 + Enabling this feature will introduce some performance impact, slightly
69093 + increase memory usage, and prevent the use of forensic tools like
69094 + Volatility against the system (unless the kernel source tree isn't
69095 + cleaned after kernel installation).
69096 +
69097 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
69098 + It remains after a make clean to allow for external modules to be compiled
69099 + with the existing seed and will be removed by a make mrproper or
69100 + make distclean.
69101 +
69102 + Note that the implementation requires gcc 4.6.4. or newer. You may need
69103 + to install the supporting headers explicitly in addition to the normal
69104 + gcc package.
69105 +
69106 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
69107 + bool "Use cacheline-aware structure randomization"
69108 + depends on GRKERNSEC_RANDSTRUCT
69109 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
69110 + help
69111 + If you say Y here, the RANDSTRUCT randomization will make a best effort
69112 + at restricting randomization to cacheline-sized groups of elements. It
69113 + will further not randomize bitfields in structures. This reduces the
69114 + performance hit of RANDSTRUCT at the cost of weakened randomization.
69115 +
69116 +config GRKERNSEC_KERN_LOCKOUT
69117 + bool "Active kernel exploit response"
69118 + default y if GRKERNSEC_CONFIG_AUTO
69119 + depends on X86 || ARM || PPC || SPARC
69120 + help
69121 + If you say Y here, when a PaX alert is triggered due to suspicious
69122 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
69123 + or an OOPS occurs due to bad memory accesses, instead of just
69124 + terminating the offending process (and potentially allowing
69125 + a subsequent exploit from the same user), we will take one of two
69126 + actions:
69127 + If the user was root, we will panic the system
69128 + If the user was non-root, we will log the attempt, terminate
69129 + all processes owned by the user, then prevent them from creating
69130 + any new processes until the system is restarted
69131 + This deters repeated kernel exploitation/bruteforcing attempts
69132 + and is useful for later forensics.
69133 +
69134 +config GRKERNSEC_OLD_ARM_USERLAND
69135 + bool "Old ARM userland compatibility"
69136 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
69137 + help
69138 + If you say Y here, stubs of executable code to perform such operations
69139 + as "compare-exchange" will be placed at fixed locations in the ARM vector
69140 + table. This is unfortunately needed for old ARM userland meant to run
69141 + across a wide range of processors. Without this option enabled,
69142 + the get_tls and data memory barrier stubs will be emulated by the kernel,
69143 + which is enough for Linaro userlands or other userlands designed for v6
69144 + and newer ARM CPUs. It's recommended that you try without this option enabled
69145 + first, and only enable it if your userland does not boot (it will likely fail
69146 + at init time).
69147 +
69148 +endmenu
69149 +menu "Role Based Access Control Options"
69150 +depends on GRKERNSEC
69151 +
69152 +config GRKERNSEC_RBAC_DEBUG
69153 + bool
69154 +
69155 +config GRKERNSEC_NO_RBAC
69156 + bool "Disable RBAC system"
69157 + help
69158 + If you say Y here, the /dev/grsec device will be removed from the kernel,
69159 + preventing the RBAC system from being enabled. You should only say Y
69160 + here if you have no intention of using the RBAC system, so as to prevent
69161 + an attacker with root access from misusing the RBAC system to hide files
69162 + and processes when loadable module support and /dev/[k]mem have been
69163 + locked down.
69164 +
69165 +config GRKERNSEC_ACL_HIDEKERN
69166 + bool "Hide kernel processes"
69167 + help
69168 + If you say Y here, all kernel threads will be hidden to all
69169 + processes but those whose subject has the "view hidden processes"
69170 + flag.
69171 +
69172 +config GRKERNSEC_ACL_MAXTRIES
69173 + int "Maximum tries before password lockout"
69174 + default 3
69175 + help
69176 + This option enforces the maximum number of times a user can attempt
69177 + to authorize themselves with the grsecurity RBAC system before being
69178 + denied the ability to attempt authorization again for a specified time.
69179 + The lower the number, the harder it will be to brute-force a password.
69180 +
69181 +config GRKERNSEC_ACL_TIMEOUT
69182 + int "Time to wait after max password tries, in seconds"
69183 + default 30
69184 + help
69185 + This option specifies the time the user must wait after attempting to
69186 + authorize to the RBAC system with the maximum number of invalid
69187 + passwords. The higher the number, the harder it will be to brute-force
69188 + a password.
69189 +
69190 +endmenu
69191 +menu "Filesystem Protections"
69192 +depends on GRKERNSEC
69193 +
69194 +config GRKERNSEC_PROC
69195 + bool "Proc restrictions"
69196 + default y if GRKERNSEC_CONFIG_AUTO
69197 + help
69198 + If you say Y here, the permissions of the /proc filesystem
69199 + will be altered to enhance system security and privacy. You MUST
69200 + choose either a user only restriction or a user and group restriction.
69201 + Depending upon the option you choose, you can either restrict users to
69202 + see only the processes they themselves run, or choose a group that can
69203 + view all processes and files normally restricted to root if you choose
69204 + the "restrict to user only" option. NOTE: If you're running identd or
69205 + ntpd as a non-root user, you will have to run it as the group you
69206 + specify here.
69207 +
69208 +config GRKERNSEC_PROC_USER
69209 + bool "Restrict /proc to user only"
69210 + depends on GRKERNSEC_PROC
69211 + help
69212 + If you say Y here, non-root users will only be able to view their own
69213 + processes, and restricts them from viewing network-related information,
69214 + and viewing kernel symbol and module information.
69215 +
69216 +config GRKERNSEC_PROC_USERGROUP
69217 + bool "Allow special group"
69218 + default y if GRKERNSEC_CONFIG_AUTO
69219 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
69220 + help
69221 + If you say Y here, you will be able to select a group that will be
69222 + able to view all processes and network-related information. If you've
69223 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
69224 + remain hidden. This option is useful if you want to run identd as
69225 + a non-root user. The group you select may also be chosen at boot time
69226 + via "grsec_proc_gid=" on the kernel commandline.
69227 +
69228 +config GRKERNSEC_PROC_GID
69229 + int "GID for special group"
69230 + depends on GRKERNSEC_PROC_USERGROUP
69231 + default 1001
69232 +
69233 +config GRKERNSEC_PROC_ADD
69234 + bool "Additional restrictions"
69235 + default y if GRKERNSEC_CONFIG_AUTO
69236 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
69237 + help
69238 + If you say Y here, additional restrictions will be placed on
69239 + /proc that keep normal users from viewing device information and
69240 + slabinfo information that could be useful for exploits.
69241 +
69242 +config GRKERNSEC_LINK
69243 + bool "Linking restrictions"
69244 + default y if GRKERNSEC_CONFIG_AUTO
69245 + help
69246 + If you say Y here, /tmp race exploits will be prevented, since users
69247 + will no longer be able to follow symlinks owned by other users in
69248 + world-writable +t directories (e.g. /tmp), unless the owner of the
69249 + symlink is the owner of the directory. users will also not be
69250 + able to hardlink to files they do not own. If the sysctl option is
69251 + enabled, a sysctl option with name "linking_restrictions" is created.
69252 +
69253 +config GRKERNSEC_SYMLINKOWN
69254 + bool "Kernel-enforced SymlinksIfOwnerMatch"
69255 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69256 + help
69257 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
69258 + that prevents it from being used as a security feature. As Apache
69259 + verifies the symlink by performing a stat() against the target of
69260 + the symlink before it is followed, an attacker can setup a symlink
69261 + to point to a same-owned file, then replace the symlink with one
69262 + that targets another user's file just after Apache "validates" the
69263 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
69264 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
69265 + will be in place for the group you specify. If the sysctl option
69266 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
69267 + created.
69268 +
69269 +config GRKERNSEC_SYMLINKOWN_GID
69270 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
69271 + depends on GRKERNSEC_SYMLINKOWN
69272 + default 1006
69273 + help
69274 + Setting this GID determines what group kernel-enforced
69275 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
69276 + is enabled, a sysctl option with name "symlinkown_gid" is created.
69277 +
69278 +config GRKERNSEC_FIFO
69279 + bool "FIFO restrictions"
69280 + default y if GRKERNSEC_CONFIG_AUTO
69281 + help
69282 + If you say Y here, users will not be able to write to FIFOs they don't
69283 + own in world-writable +t directories (e.g. /tmp), unless the owner of
69284 + the FIFO is the same owner of the directory it's held in. If the sysctl
69285 + option is enabled, a sysctl option with name "fifo_restrictions" is
69286 + created.
69287 +
69288 +config GRKERNSEC_SYSFS_RESTRICT
69289 + bool "Sysfs/debugfs restriction"
69290 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69291 + depends on SYSFS
69292 + help
69293 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
69294 + any filesystem normally mounted under it (e.g. debugfs) will be
69295 + mostly accessible only by root. These filesystems generally provide access
69296 + to hardware and debug information that isn't appropriate for unprivileged
69297 + users of the system. Sysfs and debugfs have also become a large source
69298 + of new vulnerabilities, ranging from infoleaks to local compromise.
69299 + There has been very little oversight with an eye toward security involved
69300 + in adding new exporters of information to these filesystems, so their
69301 + use is discouraged.
69302 + For reasons of compatibility, a few directories have been whitelisted
69303 + for access by non-root users:
69304 + /sys/fs/selinux
69305 + /sys/fs/fuse
69306 + /sys/devices/system/cpu
69307 +
69308 +config GRKERNSEC_ROFS
69309 + bool "Runtime read-only mount protection"
69310 + depends on SYSCTL
69311 + help
69312 + If you say Y here, a sysctl option with name "romount_protect" will
69313 + be created. By setting this option to 1 at runtime, filesystems
69314 + will be protected in the following ways:
69315 + * No new writable mounts will be allowed
69316 + * Existing read-only mounts won't be able to be remounted read/write
69317 + * Write operations will be denied on all block devices
69318 + This option acts independently of grsec_lock: once it is set to 1,
69319 + it cannot be turned off. Therefore, please be mindful of the resulting
69320 + behavior if this option is enabled in an init script on a read-only
69321 + filesystem.
69322 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
69323 + and GRKERNSEC_IO should be enabled and module loading disabled via
69324 + config or at runtime.
69325 + This feature is mainly intended for secure embedded systems.
69326 +
69327 +
69328 +config GRKERNSEC_DEVICE_SIDECHANNEL
69329 + bool "Eliminate stat/notify-based device sidechannels"
69330 + default y if GRKERNSEC_CONFIG_AUTO
69331 + help
69332 + If you say Y here, timing analyses on block or character
69333 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
69334 + will be thwarted for unprivileged users. If a process without
69335 + CAP_MKNOD stats such a device, the last access and last modify times
69336 + will match the device's create time. No access or modify events
69337 + will be triggered through inotify/dnotify/fanotify for such devices.
69338 + This feature will prevent attacks that may at a minimum
69339 + allow an attacker to determine the administrator's password length.
69340 +
69341 +config GRKERNSEC_CHROOT
69342 + bool "Chroot jail restrictions"
69343 + default y if GRKERNSEC_CONFIG_AUTO
69344 + help
69345 + If you say Y here, you will be able to choose several options that will
69346 + make breaking out of a chrooted jail much more difficult. If you
69347 + encounter no software incompatibilities with the following options, it
69348 + is recommended that you enable each one.
69349 +
69350 + Note that the chroot restrictions are not intended to apply to "chroots"
69351 + to directories that are simple bind mounts of the global root filesystem.
69352 + For several other reasons, a user shouldn't expect any significant
69353 + security by performing such a chroot.
69354 +
69355 +config GRKERNSEC_CHROOT_MOUNT
69356 + bool "Deny mounts"
69357 + default y if GRKERNSEC_CONFIG_AUTO
69358 + depends on GRKERNSEC_CHROOT
69359 + help
69360 + If you say Y here, processes inside a chroot will not be able to
69361 + mount or remount filesystems. If the sysctl option is enabled, a
69362 + sysctl option with name "chroot_deny_mount" is created.
69363 +
69364 +config GRKERNSEC_CHROOT_DOUBLE
69365 + bool "Deny double-chroots"
69366 + default y if GRKERNSEC_CONFIG_AUTO
69367 + depends on GRKERNSEC_CHROOT
69368 + help
69369 + If you say Y here, processes inside a chroot will not be able to chroot
69370 + again outside the chroot. This is a widely used method of breaking
69371 + out of a chroot jail and should not be allowed. If the sysctl
69372 + option is enabled, a sysctl option with name
69373 + "chroot_deny_chroot" is created.
69374 +
69375 +config GRKERNSEC_CHROOT_PIVOT
69376 + bool "Deny pivot_root in chroot"
69377 + default y if GRKERNSEC_CONFIG_AUTO
69378 + depends on GRKERNSEC_CHROOT
69379 + help
69380 + If you say Y here, processes inside a chroot will not be able to use
69381 + a function called pivot_root() that was introduced in Linux 2.3.41. It
69382 + works similar to chroot in that it changes the root filesystem. This
69383 + function could be misused in a chrooted process to attempt to break out
69384 + of the chroot, and therefore should not be allowed. If the sysctl
69385 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
69386 + created.
69387 +
69388 +config GRKERNSEC_CHROOT_CHDIR
69389 + bool "Enforce chdir(\"/\") on all chroots"
69390 + default y if GRKERNSEC_CONFIG_AUTO
69391 + depends on GRKERNSEC_CHROOT
69392 + help
69393 + If you say Y here, the current working directory of all newly-chrooted
69394 + applications will be set to the the root directory of the chroot.
69395 + The man page on chroot(2) states:
69396 + Note that this call does not change the current working
69397 + directory, so that `.' can be outside the tree rooted at
69398 + `/'. In particular, the super-user can escape from a
69399 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
69400 +
69401 + It is recommended that you say Y here, since it's not known to break
69402 + any software. If the sysctl option is enabled, a sysctl option with
69403 + name "chroot_enforce_chdir" is created.
69404 +
69405 +config GRKERNSEC_CHROOT_CHMOD
69406 + bool "Deny (f)chmod +s"
69407 + default y if GRKERNSEC_CONFIG_AUTO
69408 + depends on GRKERNSEC_CHROOT
69409 + help
69410 + If you say Y here, processes inside a chroot will not be able to chmod
69411 + or fchmod files to make them have suid or sgid bits. This protects
69412 + against another published method of breaking a chroot. If the sysctl
69413 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
69414 + created.
69415 +
69416 +config GRKERNSEC_CHROOT_FCHDIR
69417 + bool "Deny fchdir and fhandle out of chroot"
69418 + default y if GRKERNSEC_CONFIG_AUTO
69419 + depends on GRKERNSEC_CHROOT
69420 + help
69421 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
69422 + to a file descriptor of the chrooting process that points to a directory
69423 + outside the filesystem will be stopped. Additionally, this option prevents
69424 + use of the recently-created syscall for opening files by a guessable "file
69425 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
69426 + with name "chroot_deny_fchdir" is created.
69427 +
69428 +config GRKERNSEC_CHROOT_MKNOD
69429 + bool "Deny mknod"
69430 + default y if GRKERNSEC_CONFIG_AUTO
69431 + depends on GRKERNSEC_CHROOT
69432 + help
69433 + If you say Y here, processes inside a chroot will not be allowed to
69434 + mknod. The problem with using mknod inside a chroot is that it
69435 + would allow an attacker to create a device entry that is the same
69436 + as one on the physical root of your system, which could range from
69437 + anything from the console device to a device for your harddrive (which
69438 + they could then use to wipe the drive or steal data). It is recommended
69439 + that you say Y here, unless you run into software incompatibilities.
69440 + If the sysctl option is enabled, a sysctl option with name
69441 + "chroot_deny_mknod" is created.
69442 +
69443 +config GRKERNSEC_CHROOT_SHMAT
69444 + bool "Deny shmat() out of chroot"
69445 + default y if GRKERNSEC_CONFIG_AUTO
69446 + depends on GRKERNSEC_CHROOT
69447 + help
69448 + If you say Y here, processes inside a chroot will not be able to attach
69449 + to shared memory segments that were created outside of the chroot jail.
69450 + It is recommended that you say Y here. If the sysctl option is enabled,
69451 + a sysctl option with name "chroot_deny_shmat" is created.
69452 +
69453 +config GRKERNSEC_CHROOT_UNIX
69454 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
69455 + default y if GRKERNSEC_CONFIG_AUTO
69456 + depends on GRKERNSEC_CHROOT
69457 + help
69458 + If you say Y here, processes inside a chroot will not be able to
69459 + connect to abstract (meaning not belonging to a filesystem) Unix
69460 + domain sockets that were bound outside of a chroot. It is recommended
69461 + that you say Y here. If the sysctl option is enabled, a sysctl option
69462 + with name "chroot_deny_unix" is created.
69463 +
69464 +config GRKERNSEC_CHROOT_FINDTASK
69465 + bool "Protect outside processes"
69466 + default y if GRKERNSEC_CONFIG_AUTO
69467 + depends on GRKERNSEC_CHROOT
69468 + help
69469 + If you say Y here, processes inside a chroot will not be able to
69470 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
69471 + getsid, or view any process outside of the chroot. If the sysctl
69472 + option is enabled, a sysctl option with name "chroot_findtask" is
69473 + created.
69474 +
69475 +config GRKERNSEC_CHROOT_NICE
69476 + bool "Restrict priority changes"
69477 + default y if GRKERNSEC_CONFIG_AUTO
69478 + depends on GRKERNSEC_CHROOT
69479 + help
69480 + If you say Y here, processes inside a chroot will not be able to raise
69481 + the priority of processes in the chroot, or alter the priority of
69482 + processes outside the chroot. This provides more security than simply
69483 + removing CAP_SYS_NICE from the process' capability set. If the
69484 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
69485 + is created.
69486 +
69487 +config GRKERNSEC_CHROOT_SYSCTL
69488 + bool "Deny sysctl writes"
69489 + default y if GRKERNSEC_CONFIG_AUTO
69490 + depends on GRKERNSEC_CHROOT
69491 + help
69492 + If you say Y here, an attacker in a chroot will not be able to
69493 + write to sysctl entries, either by sysctl(2) or through a /proc
69494 + interface. It is strongly recommended that you say Y here. If the
69495 + sysctl option is enabled, a sysctl option with name
69496 + "chroot_deny_sysctl" is created.
69497 +
69498 +config GRKERNSEC_CHROOT_CAPS
69499 + bool "Capability restrictions"
69500 + default y if GRKERNSEC_CONFIG_AUTO
69501 + depends on GRKERNSEC_CHROOT
69502 + help
69503 + If you say Y here, the capabilities on all processes within a
69504 + chroot jail will be lowered to stop module insertion, raw i/o,
69505 + system and net admin tasks, rebooting the system, modifying immutable
69506 + files, modifying IPC owned by another, and changing the system time.
69507 + This is left an option because it can break some apps. Disable this
69508 + if your chrooted apps are having problems performing those kinds of
69509 + tasks. If the sysctl option is enabled, a sysctl option with
69510 + name "chroot_caps" is created.
69511 +
69512 +config GRKERNSEC_CHROOT_INITRD
69513 + bool "Exempt initrd tasks from restrictions"
69514 + default y if GRKERNSEC_CONFIG_AUTO
69515 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
69516 + help
69517 + If you say Y here, tasks started prior to init will be exempted from
69518 + grsecurity's chroot restrictions. This option is mainly meant to
69519 + resolve Plymouth's performing privileged operations unnecessarily
69520 + in a chroot.
69521 +
69522 +endmenu
69523 +menu "Kernel Auditing"
69524 +depends on GRKERNSEC
69525 +
69526 +config GRKERNSEC_AUDIT_GROUP
69527 + bool "Single group for auditing"
69528 + help
69529 + If you say Y here, the exec and chdir logging features will only operate
69530 + on a group you specify. This option is recommended if you only want to
69531 + watch certain users instead of having a large amount of logs from the
69532 + entire system. If the sysctl option is enabled, a sysctl option with
69533 + name "audit_group" is created.
69534 +
69535 +config GRKERNSEC_AUDIT_GID
69536 + int "GID for auditing"
69537 + depends on GRKERNSEC_AUDIT_GROUP
69538 + default 1007
69539 +
69540 +config GRKERNSEC_EXECLOG
69541 + bool "Exec logging"
69542 + help
69543 + If you say Y here, all execve() calls will be logged (since the
69544 + other exec*() calls are frontends to execve(), all execution
69545 + will be logged). Useful for shell-servers that like to keep track
69546 + of their users. If the sysctl option is enabled, a sysctl option with
69547 + name "exec_logging" is created.
69548 + WARNING: This option when enabled will produce a LOT of logs, especially
69549 + on an active system.
69550 +
69551 +config GRKERNSEC_RESLOG
69552 + bool "Resource logging"
69553 + default y if GRKERNSEC_CONFIG_AUTO
69554 + help
69555 + If you say Y here, all attempts to overstep resource limits will
69556 + be logged with the resource name, the requested size, and the current
69557 + limit. It is highly recommended that you say Y here. If the sysctl
69558 + option is enabled, a sysctl option with name "resource_logging" is
69559 + created. If the RBAC system is enabled, the sysctl value is ignored.
69560 +
69561 +config GRKERNSEC_CHROOT_EXECLOG
69562 + bool "Log execs within chroot"
69563 + help
69564 + If you say Y here, all executions inside a chroot jail will be logged
69565 + to syslog. This can cause a large amount of logs if certain
69566 + applications (eg. djb's daemontools) are installed on the system, and
69567 + is therefore left as an option. If the sysctl option is enabled, a
69568 + sysctl option with name "chroot_execlog" is created.
69569 +
69570 +config GRKERNSEC_AUDIT_PTRACE
69571 + bool "Ptrace logging"
69572 + help
69573 + If you say Y here, all attempts to attach to a process via ptrace
69574 + will be logged. If the sysctl option is enabled, a sysctl option
69575 + with name "audit_ptrace" is created.
69576 +
69577 +config GRKERNSEC_AUDIT_CHDIR
69578 + bool "Chdir logging"
69579 + help
69580 + If you say Y here, all chdir() calls will be logged. If the sysctl
69581 + option is enabled, a sysctl option with name "audit_chdir" is created.
69582 +
69583 +config GRKERNSEC_AUDIT_MOUNT
69584 + bool "(Un)Mount logging"
69585 + help
69586 + If you say Y here, all mounts and unmounts will be logged. If the
69587 + sysctl option is enabled, a sysctl option with name "audit_mount" is
69588 + created.
69589 +
69590 +config GRKERNSEC_SIGNAL
69591 + bool "Signal logging"
69592 + default y if GRKERNSEC_CONFIG_AUTO
69593 + help
69594 + If you say Y here, certain important signals will be logged, such as
69595 + SIGSEGV, which will as a result inform you of when a error in a program
69596 + occurred, which in some cases could mean a possible exploit attempt.
69597 + If the sysctl option is enabled, a sysctl option with name
69598 + "signal_logging" is created.
69599 +
69600 +config GRKERNSEC_FORKFAIL
69601 + bool "Fork failure logging"
69602 + help
69603 + If you say Y here, all failed fork() attempts will be logged.
69604 + This could suggest a fork bomb, or someone attempting to overstep
69605 + their process limit. If the sysctl option is enabled, a sysctl option
69606 + with name "forkfail_logging" is created.
69607 +
69608 +config GRKERNSEC_TIME
69609 + bool "Time change logging"
69610 + default y if GRKERNSEC_CONFIG_AUTO
69611 + help
69612 + If you say Y here, any changes of the system clock will be logged.
69613 + If the sysctl option is enabled, a sysctl option with name
69614 + "timechange_logging" is created.
69615 +
69616 +config GRKERNSEC_PROC_IPADDR
69617 + bool "/proc/<pid>/ipaddr support"
69618 + default y if GRKERNSEC_CONFIG_AUTO
69619 + help
69620 + If you say Y here, a new entry will be added to each /proc/<pid>
69621 + directory that contains the IP address of the person using the task.
69622 + The IP is carried across local TCP and AF_UNIX stream sockets.
69623 + This information can be useful for IDS/IPSes to perform remote response
69624 + to a local attack. The entry is readable by only the owner of the
69625 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69626 + the RBAC system), and thus does not create privacy concerns.
69627 +
69628 +config GRKERNSEC_RWXMAP_LOG
69629 + bool 'Denied RWX mmap/mprotect logging'
69630 + default y if GRKERNSEC_CONFIG_AUTO
69631 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69632 + help
69633 + If you say Y here, calls to mmap() and mprotect() with explicit
69634 + usage of PROT_WRITE and PROT_EXEC together will be logged when
69635 + denied by the PAX_MPROTECT feature. This feature will also
69636 + log other problematic scenarios that can occur when PAX_MPROTECT
69637 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
69638 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69639 + is created.
69640 +
69641 +endmenu
69642 +
69643 +menu "Executable Protections"
69644 +depends on GRKERNSEC
69645 +
69646 +config GRKERNSEC_DMESG
69647 + bool "Dmesg(8) restriction"
69648 + default y if GRKERNSEC_CONFIG_AUTO
69649 + help
69650 + If you say Y here, non-root users will not be able to use dmesg(8)
69651 + to view the contents of the kernel's circular log buffer.
69652 + The kernel's log buffer often contains kernel addresses and other
69653 + identifying information useful to an attacker in fingerprinting a
69654 + system for a targeted exploit.
69655 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
69656 + created.
69657 +
69658 +config GRKERNSEC_HARDEN_PTRACE
69659 + bool "Deter ptrace-based process snooping"
69660 + default y if GRKERNSEC_CONFIG_AUTO
69661 + help
69662 + If you say Y here, TTY sniffers and other malicious monitoring
69663 + programs implemented through ptrace will be defeated. If you
69664 + have been using the RBAC system, this option has already been
69665 + enabled for several years for all users, with the ability to make
69666 + fine-grained exceptions.
69667 +
69668 + This option only affects the ability of non-root users to ptrace
69669 + processes that are not a descendent of the ptracing process.
69670 + This means that strace ./binary and gdb ./binary will still work,
69671 + but attaching to arbitrary processes will not. If the sysctl
69672 + option is enabled, a sysctl option with name "harden_ptrace" is
69673 + created.
69674 +
69675 +config GRKERNSEC_PTRACE_READEXEC
69676 + bool "Require read access to ptrace sensitive binaries"
69677 + default y if GRKERNSEC_CONFIG_AUTO
69678 + help
69679 + If you say Y here, unprivileged users will not be able to ptrace unreadable
69680 + binaries. This option is useful in environments that
69681 + remove the read bits (e.g. file mode 4711) from suid binaries to
69682 + prevent infoleaking of their contents. This option adds
69683 + consistency to the use of that file mode, as the binary could normally
69684 + be read out when run without privileges while ptracing.
69685 +
69686 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69687 + is created.
69688 +
69689 +config GRKERNSEC_SETXID
69690 + bool "Enforce consistent multithreaded privileges"
69691 + default y if GRKERNSEC_CONFIG_AUTO
69692 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69693 + help
69694 + If you say Y here, a change from a root uid to a non-root uid
69695 + in a multithreaded application will cause the resulting uids,
69696 + gids, supplementary groups, and capabilities in that thread
69697 + to be propagated to the other threads of the process. In most
69698 + cases this is unnecessary, as glibc will emulate this behavior
69699 + on behalf of the application. Other libcs do not act in the
69700 + same way, allowing the other threads of the process to continue
69701 + running with root privileges. If the sysctl option is enabled,
69702 + a sysctl option with name "consistent_setxid" is created.
69703 +
69704 +config GRKERNSEC_HARDEN_IPC
69705 + bool "Disallow access to overly-permissive IPC objects"
69706 + default y if GRKERNSEC_CONFIG_AUTO
69707 + depends on SYSVIPC
69708 + help
69709 + If you say Y here, access to overly-permissive IPC objects (shared
69710 + memory, message queues, and semaphores) will be denied for processes
69711 + given the following criteria beyond normal permission checks:
69712 + 1) If the IPC object is world-accessible and the euid doesn't match
69713 + that of the creator or current uid for the IPC object
69714 + 2) If the IPC object is group-accessible and the egid doesn't
69715 + match that of the creator or current gid for the IPC object
69716 + It's a common error to grant too much permission to these objects,
69717 + with impact ranging from denial of service and information leaking to
69718 + privilege escalation. This feature was developed in response to
69719 + research by Tim Brown:
69720 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69721 + who found hundreds of such insecure usages. Processes with
69722 + CAP_IPC_OWNER are still permitted to access these IPC objects.
69723 + If the sysctl option is enabled, a sysctl option with name
69724 + "harden_ipc" is created.
69725 +
69726 +config GRKERNSEC_TPE
69727 + bool "Trusted Path Execution (TPE)"
69728 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69729 + help
69730 + If you say Y here, you will be able to choose a gid to add to the
69731 + supplementary groups of users you want to mark as "untrusted."
69732 + These users will not be able to execute any files that are not in
69733 + root-owned directories writable only by root. If the sysctl option
69734 + is enabled, a sysctl option with name "tpe" is created.
69735 +
69736 +config GRKERNSEC_TPE_ALL
69737 + bool "Partially restrict all non-root users"
69738 + depends on GRKERNSEC_TPE
69739 + help
69740 + If you say Y here, all non-root users will be covered under
69741 + a weaker TPE restriction. This is separate from, and in addition to,
69742 + the main TPE options that you have selected elsewhere. Thus, if a
69743 + "trusted" GID is chosen, this restriction applies to even that GID.
69744 + Under this restriction, all non-root users will only be allowed to
69745 + execute files in directories they own that are not group or
69746 + world-writable, or in directories owned by root and writable only by
69747 + root. If the sysctl option is enabled, a sysctl option with name
69748 + "tpe_restrict_all" is created.
69749 +
69750 +config GRKERNSEC_TPE_INVERT
69751 + bool "Invert GID option"
69752 + depends on GRKERNSEC_TPE
69753 + help
69754 + If you say Y here, the group you specify in the TPE configuration will
69755 + decide what group TPE restrictions will be *disabled* for. This
69756 + option is useful if you want TPE restrictions to be applied to most
69757 + users on the system. If the sysctl option is enabled, a sysctl option
69758 + with name "tpe_invert" is created. Unlike other sysctl options, this
69759 + entry will default to on for backward-compatibility.
69760 +
69761 +config GRKERNSEC_TPE_GID
69762 + int
69763 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69764 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69765 +
69766 +config GRKERNSEC_TPE_UNTRUSTED_GID
69767 + int "GID for TPE-untrusted users"
69768 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69769 + default 1005
69770 + help
69771 + Setting this GID determines what group TPE restrictions will be
69772 + *enabled* for. If the sysctl option is enabled, a sysctl option
69773 + with name "tpe_gid" is created.
69774 +
69775 +config GRKERNSEC_TPE_TRUSTED_GID
69776 + int "GID for TPE-trusted users"
69777 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69778 + default 1005
69779 + help
69780 + Setting this GID determines what group TPE restrictions will be
69781 + *disabled* for. If the sysctl option is enabled, a sysctl option
69782 + with name "tpe_gid" is created.
69783 +
69784 +endmenu
69785 +menu "Network Protections"
69786 +depends on GRKERNSEC
69787 +
69788 +config GRKERNSEC_BLACKHOLE
69789 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69790 + default y if GRKERNSEC_CONFIG_AUTO
69791 + depends on NET
69792 + help
69793 + If you say Y here, neither TCP resets nor ICMP
69794 + destination-unreachable packets will be sent in response to packets
69795 + sent to ports for which no associated listening process exists.
69796 + This feature supports both IPV4 and IPV6 and exempts the
69797 + loopback interface from blackholing. Enabling this feature
69798 + makes a host more resilient to DoS attacks and reduces network
69799 + visibility against scanners.
69800 +
69801 + The blackhole feature as-implemented is equivalent to the FreeBSD
69802 + blackhole feature, as it prevents RST responses to all packets, not
69803 + just SYNs. Under most application behavior this causes no
69804 + problems, but applications (like haproxy) may not close certain
69805 + connections in a way that cleanly terminates them on the remote
69806 + end, leaving the remote host in LAST_ACK state. Because of this
69807 + side-effect and to prevent intentional LAST_ACK DoSes, this
69808 + feature also adds automatic mitigation against such attacks.
69809 + The mitigation drastically reduces the amount of time a socket
69810 + can spend in LAST_ACK state. If you're using haproxy and not
69811 + all servers it connects to have this option enabled, consider
69812 + disabling this feature on the haproxy host.
69813 +
69814 + If the sysctl option is enabled, two sysctl options with names
69815 + "ip_blackhole" and "lastack_retries" will be created.
69816 + While "ip_blackhole" takes the standard zero/non-zero on/off
69817 + toggle, "lastack_retries" uses the same kinds of values as
69818 + "tcp_retries1" and "tcp_retries2". The default value of 4
69819 + prevents a socket from lasting more than 45 seconds in LAST_ACK
69820 + state.
69821 +
69822 +config GRKERNSEC_NO_SIMULT_CONNECT
69823 + bool "Disable TCP Simultaneous Connect"
69824 + default y if GRKERNSEC_CONFIG_AUTO
69825 + depends on NET
69826 + help
69827 + If you say Y here, a feature by Willy Tarreau will be enabled that
69828 + removes a weakness in Linux's strict implementation of TCP that
69829 + allows two clients to connect to each other without either entering
69830 + a listening state. The weakness allows an attacker to easily prevent
69831 + a client from connecting to a known server provided the source port
69832 + for the connection is guessed correctly.
69833 +
69834 + As the weakness could be used to prevent an antivirus or IPS from
69835 + fetching updates, or prevent an SSL gateway from fetching a CRL,
69836 + it should be eliminated by enabling this option. Though Linux is
69837 + one of few operating systems supporting simultaneous connect, it
69838 + has no legitimate use in practice and is rarely supported by firewalls.
69839 +
69840 +config GRKERNSEC_SOCKET
69841 + bool "Socket restrictions"
69842 + depends on NET
69843 + help
69844 + If you say Y here, you will be able to choose from several options.
69845 + If you assign a GID on your system and add it to the supplementary
69846 + groups of users you want to restrict socket access to, this patch
69847 + will perform up to three things, based on the option(s) you choose.
69848 +
69849 +config GRKERNSEC_SOCKET_ALL
69850 + bool "Deny any sockets to group"
69851 + depends on GRKERNSEC_SOCKET
69852 + help
69853 + If you say Y here, you will be able to choose a GID of whose users will
69854 + be unable to connect to other hosts from your machine or run server
69855 + applications from your machine. If the sysctl option is enabled, a
69856 + sysctl option with name "socket_all" is created.
69857 +
69858 +config GRKERNSEC_SOCKET_ALL_GID
69859 + int "GID to deny all sockets for"
69860 + depends on GRKERNSEC_SOCKET_ALL
69861 + default 1004
69862 + help
69863 + Here you can choose the GID to disable socket access for. Remember to
69864 + add the users you want socket access disabled for to the GID
69865 + specified here. If the sysctl option is enabled, a sysctl option
69866 + with name "socket_all_gid" is created.
69867 +
69868 +config GRKERNSEC_SOCKET_CLIENT
69869 + bool "Deny client sockets to group"
69870 + depends on GRKERNSEC_SOCKET
69871 + help
69872 + If you say Y here, you will be able to choose a GID of whose users will
69873 + be unable to connect to other hosts from your machine, but will be
69874 + able to run servers. If this option is enabled, all users in the group
69875 + you specify will have to use passive mode when initiating ftp transfers
69876 + from the shell on your machine. If the sysctl option is enabled, a
69877 + sysctl option with name "socket_client" is created.
69878 +
69879 +config GRKERNSEC_SOCKET_CLIENT_GID
69880 + int "GID to deny client sockets for"
69881 + depends on GRKERNSEC_SOCKET_CLIENT
69882 + default 1003
69883 + help
69884 + Here you can choose the GID to disable client socket access for.
69885 + Remember to add the users you want client socket access disabled for to
69886 + the GID specified here. If the sysctl option is enabled, a sysctl
69887 + option with name "socket_client_gid" is created.
69888 +
69889 +config GRKERNSEC_SOCKET_SERVER
69890 + bool "Deny server sockets to group"
69891 + depends on GRKERNSEC_SOCKET
69892 + help
69893 + If you say Y here, you will be able to choose a GID of whose users will
69894 + be unable to run server applications from your machine. If the sysctl
69895 + option is enabled, a sysctl option with name "socket_server" is created.
69896 +
69897 +config GRKERNSEC_SOCKET_SERVER_GID
69898 + int "GID to deny server sockets for"
69899 + depends on GRKERNSEC_SOCKET_SERVER
69900 + default 1002
69901 + help
69902 + Here you can choose the GID to disable server socket access for.
69903 + Remember to add the users you want server socket access disabled for to
69904 + the GID specified here. If the sysctl option is enabled, a sysctl
69905 + option with name "socket_server_gid" is created.
69906 +
69907 +endmenu
69908 +
69909 +menu "Physical Protections"
69910 +depends on GRKERNSEC
69911 +
69912 +config GRKERNSEC_DENYUSB
69913 + bool "Deny new USB connections after toggle"
69914 + default y if GRKERNSEC_CONFIG_AUTO
69915 + depends on SYSCTL && USB_SUPPORT
69916 + help
69917 + If you say Y here, a new sysctl option with name "deny_new_usb"
69918 + will be created. Setting its value to 1 will prevent any new
69919 + USB devices from being recognized by the OS. Any attempted USB
69920 + device insertion will be logged. This option is intended to be
69921 + used against custom USB devices designed to exploit vulnerabilities
69922 + in various USB device drivers.
69923 +
69924 + For greatest effectiveness, this sysctl should be set after any
69925 + relevant init scripts. This option is safe to enable in distros
69926 + as each user can choose whether or not to toggle the sysctl.
69927 +
69928 +config GRKERNSEC_DENYUSB_FORCE
69929 + bool "Reject all USB devices not connected at boot"
69930 + select USB
69931 + depends on GRKERNSEC_DENYUSB
69932 + help
69933 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69934 + that doesn't involve a sysctl entry. This option should only be
69935 + enabled if you're sure you want to deny all new USB connections
69936 + at runtime and don't want to modify init scripts. This should not
69937 + be enabled by distros. It forces the core USB code to be built
69938 + into the kernel image so that all devices connected at boot time
69939 + can be recognized and new USB device connections can be prevented
69940 + prior to init running.
69941 +
69942 +endmenu
69943 +
69944 +menu "Sysctl Support"
69945 +depends on GRKERNSEC && SYSCTL
69946 +
69947 +config GRKERNSEC_SYSCTL
69948 + bool "Sysctl support"
69949 + default y if GRKERNSEC_CONFIG_AUTO
69950 + help
69951 + If you say Y here, you will be able to change the options that
69952 + grsecurity runs with at bootup, without having to recompile your
69953 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69954 + to enable (1) or disable (0) various features. All the sysctl entries
69955 + are mutable until the "grsec_lock" entry is set to a non-zero value.
69956 + All features enabled in the kernel configuration are disabled at boot
69957 + if you do not say Y to the "Turn on features by default" option.
69958 + All options should be set at startup, and the grsec_lock entry should
69959 + be set to a non-zero value after all the options are set.
69960 + *THIS IS EXTREMELY IMPORTANT*
69961 +
69962 +config GRKERNSEC_SYSCTL_DISTRO
69963 + bool "Extra sysctl support for distro makers (READ HELP)"
69964 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69965 + help
69966 + If you say Y here, additional sysctl options will be created
69967 + for features that affect processes running as root. Therefore,
69968 + it is critical when using this option that the grsec_lock entry be
69969 + enabled after boot. Only distros with prebuilt kernel packages
69970 + with this option enabled that can ensure grsec_lock is enabled
69971 + after boot should use this option.
69972 + *Failure to set grsec_lock after boot makes all grsec features
69973 + this option covers useless*
69974 +
69975 + Currently this option creates the following sysctl entries:
69976 + "Disable Privileged I/O": "disable_priv_io"
69977 +
69978 +config GRKERNSEC_SYSCTL_ON
69979 + bool "Turn on features by default"
69980 + default y if GRKERNSEC_CONFIG_AUTO
69981 + depends on GRKERNSEC_SYSCTL
69982 + help
69983 + If you say Y here, instead of having all features enabled in the
69984 + kernel configuration disabled at boot time, the features will be
69985 + enabled at boot time. It is recommended you say Y here unless
69986 + there is some reason you would want all sysctl-tunable features to
69987 + be disabled by default. As mentioned elsewhere, it is important
69988 + to enable the grsec_lock entry once you have finished modifying
69989 + the sysctl entries.
69990 +
69991 +endmenu
69992 +menu "Logging Options"
69993 +depends on GRKERNSEC
69994 +
69995 +config GRKERNSEC_FLOODTIME
69996 + int "Seconds in between log messages (minimum)"
69997 + default 10
69998 + help
69999 + This option allows you to enforce the number of seconds between
70000 + grsecurity log messages. The default should be suitable for most
70001 + people, however, if you choose to change it, choose a value small enough
70002 + to allow informative logs to be produced, but large enough to
70003 + prevent flooding.
70004 +
70005 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
70006 + any rate limiting on grsecurity log messages.
70007 +
70008 +config GRKERNSEC_FLOODBURST
70009 + int "Number of messages in a burst (maximum)"
70010 + default 6
70011 + help
70012 + This option allows you to choose the maximum number of messages allowed
70013 + within the flood time interval you chose in a separate option. The
70014 + default should be suitable for most people, however if you find that
70015 + many of your logs are being interpreted as flooding, you may want to
70016 + raise this value.
70017 +
70018 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
70019 + any rate limiting on grsecurity log messages.
70020 +
70021 +endmenu
70022 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
70023 new file mode 100644
70024 index 0000000..30ababb
70025 --- /dev/null
70026 +++ b/grsecurity/Makefile
70027 @@ -0,0 +1,54 @@
70028 +# grsecurity – access control and security hardening for Linux
70029 +# All code in this directory and various hooks located throughout the Linux kernel are
70030 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
70031 +# http://www.grsecurity.net spender@grsecurity.net
70032 +#
70033 +# This program is free software; you can redistribute it and/or
70034 +# modify it under the terms of the GNU General Public License version 2
70035 +# as published by the Free Software Foundation.
70036 +#
70037 +# This program is distributed in the hope that it will be useful,
70038 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
70039 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70040 +# GNU General Public License for more details.
70041 +#
70042 +# You should have received a copy of the GNU General Public License
70043 +# along with this program; if not, write to the Free Software
70044 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
70045 +
70046 +KBUILD_CFLAGS += -Werror
70047 +
70048 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
70049 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
70050 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
70051 + grsec_usb.o grsec_ipc.o grsec_proc.o
70052 +
70053 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
70054 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
70055 + gracl_learn.o grsec_log.o gracl_policy.o
70056 +ifdef CONFIG_COMPAT
70057 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
70058 +endif
70059 +
70060 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
70061 +
70062 +ifdef CONFIG_NET
70063 +obj-y += grsec_sock.o
70064 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
70065 +endif
70066 +
70067 +ifndef CONFIG_GRKERNSEC
70068 +obj-y += grsec_disabled.o
70069 +endif
70070 +
70071 +ifdef CONFIG_GRKERNSEC_HIDESYM
70072 +extra-y := grsec_hidesym.o
70073 +$(obj)/grsec_hidesym.o:
70074 + @-chmod -f 500 /boot
70075 + @-chmod -f 500 /lib/modules
70076 + @-chmod -f 500 /lib64/modules
70077 + @-chmod -f 500 /lib32/modules
70078 + @-chmod -f 700 .
70079 + @-chmod -f 700 $(objtree)
70080 + @echo ' grsec: protected kernel image paths'
70081 +endif
70082 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
70083 new file mode 100644
70084 index 0000000..58223f6
70085 --- /dev/null
70086 +++ b/grsecurity/gracl.c
70087 @@ -0,0 +1,2702 @@
70088 +#include <linux/kernel.h>
70089 +#include <linux/module.h>
70090 +#include <linux/sched.h>
70091 +#include <linux/mm.h>
70092 +#include <linux/file.h>
70093 +#include <linux/fs.h>
70094 +#include <linux/namei.h>
70095 +#include <linux/mount.h>
70096 +#include <linux/tty.h>
70097 +#include <linux/proc_fs.h>
70098 +#include <linux/lglock.h>
70099 +#include <linux/slab.h>
70100 +#include <linux/vmalloc.h>
70101 +#include <linux/types.h>
70102 +#include <linux/sysctl.h>
70103 +#include <linux/netdevice.h>
70104 +#include <linux/ptrace.h>
70105 +#include <linux/gracl.h>
70106 +#include <linux/gralloc.h>
70107 +#include <linux/security.h>
70108 +#include <linux/grinternal.h>
70109 +#include <linux/pid_namespace.h>
70110 +#include <linux/stop_machine.h>
70111 +#include <linux/fdtable.h>
70112 +#include <linux/percpu.h>
70113 +#include <linux/lglock.h>
70114 +#include <linux/hugetlb.h>
70115 +#include <linux/posix-timers.h>
70116 +#include <linux/prefetch.h>
70117 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
70118 +#include <linux/magic.h>
70119 +#include <linux/pagemap.h>
70120 +#include "../fs/btrfs/async-thread.h"
70121 +#include "../fs/btrfs/ctree.h"
70122 +#include "../fs/btrfs/btrfs_inode.h"
70123 +#endif
70124 +#include "../fs/mount.h"
70125 +
70126 +#include <asm/uaccess.h>
70127 +#include <asm/errno.h>
70128 +#include <asm/mman.h>
70129 +
70130 +#define FOR_EACH_ROLE_START(role) \
70131 + role = running_polstate.role_list; \
70132 + while (role) {
70133 +
70134 +#define FOR_EACH_ROLE_END(role) \
70135 + role = role->prev; \
70136 + }
70137 +
70138 +extern struct path gr_real_root;
70139 +
70140 +static struct gr_policy_state running_polstate;
70141 +struct gr_policy_state *polstate = &running_polstate;
70142 +extern struct gr_alloc_state *current_alloc_state;
70143 +
70144 +extern char *gr_shared_page[4];
70145 +DEFINE_RWLOCK(gr_inode_lock);
70146 +
70147 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
70148 +
70149 +#ifdef CONFIG_NET
70150 +extern struct vfsmount *sock_mnt;
70151 +#endif
70152 +
70153 +extern struct vfsmount *pipe_mnt;
70154 +extern struct vfsmount *shm_mnt;
70155 +
70156 +#ifdef CONFIG_HUGETLBFS
70157 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
70158 +#endif
70159 +
70160 +extern u16 acl_sp_role_value;
70161 +extern struct acl_object_label *fakefs_obj_rw;
70162 +extern struct acl_object_label *fakefs_obj_rwx;
70163 +
70164 +int gr_acl_is_enabled(void)
70165 +{
70166 + return (gr_status & GR_READY);
70167 +}
70168 +
70169 +void gr_enable_rbac_system(void)
70170 +{
70171 + pax_open_kernel();
70172 + gr_status |= GR_READY;
70173 + pax_close_kernel();
70174 +}
70175 +
70176 +int gr_rbac_disable(void *unused)
70177 +{
70178 + pax_open_kernel();
70179 + gr_status &= ~GR_READY;
70180 + pax_close_kernel();
70181 +
70182 + return 0;
70183 +}
70184 +
70185 +static inline dev_t __get_dev(const struct dentry *dentry)
70186 +{
70187 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
70188 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
70189 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
70190 + else
70191 +#endif
70192 + return dentry->d_sb->s_dev;
70193 +}
70194 +
70195 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
70196 +{
70197 + return __get_dev(dentry);
70198 +}
70199 +
70200 +static char gr_task_roletype_to_char(struct task_struct *task)
70201 +{
70202 + switch (task->role->roletype &
70203 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
70204 + GR_ROLE_SPECIAL)) {
70205 + case GR_ROLE_DEFAULT:
70206 + return 'D';
70207 + case GR_ROLE_USER:
70208 + return 'U';
70209 + case GR_ROLE_GROUP:
70210 + return 'G';
70211 + case GR_ROLE_SPECIAL:
70212 + return 'S';
70213 + }
70214 +
70215 + return 'X';
70216 +}
70217 +
70218 +char gr_roletype_to_char(void)
70219 +{
70220 + return gr_task_roletype_to_char(current);
70221 +}
70222 +
70223 +__inline__ int
70224 +gr_acl_tpe_check(void)
70225 +{
70226 + if (unlikely(!(gr_status & GR_READY)))
70227 + return 0;
70228 + if (current->role->roletype & GR_ROLE_TPE)
70229 + return 1;
70230 + else
70231 + return 0;
70232 +}
70233 +
70234 +int
70235 +gr_handle_rawio(const struct inode *inode)
70236 +{
70237 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70238 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
70239 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
70240 + !capable(CAP_SYS_RAWIO))
70241 + return 1;
70242 +#endif
70243 + return 0;
70244 +}
70245 +
70246 +int
70247 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
70248 +{
70249 + if (likely(lena != lenb))
70250 + return 0;
70251 +
70252 + return !memcmp(a, b, lena);
70253 +}
70254 +
70255 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
70256 +{
70257 + *buflen -= namelen;
70258 + if (*buflen < 0)
70259 + return -ENAMETOOLONG;
70260 + *buffer -= namelen;
70261 + memcpy(*buffer, str, namelen);
70262 + return 0;
70263 +}
70264 +
70265 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
70266 +{
70267 + return prepend(buffer, buflen, name->name, name->len);
70268 +}
70269 +
70270 +static int prepend_path(const struct path *path, struct path *root,
70271 + char **buffer, int *buflen)
70272 +{
70273 + struct dentry *dentry = path->dentry;
70274 + struct vfsmount *vfsmnt = path->mnt;
70275 + struct mount *mnt = real_mount(vfsmnt);
70276 + bool slash = false;
70277 + int error = 0;
70278 +
70279 + while (dentry != root->dentry || vfsmnt != root->mnt) {
70280 + struct dentry * parent;
70281 +
70282 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
70283 + /* Global root? */
70284 + if (!mnt_has_parent(mnt)) {
70285 + goto out;
70286 + }
70287 + dentry = mnt->mnt_mountpoint;
70288 + mnt = mnt->mnt_parent;
70289 + vfsmnt = &mnt->mnt;
70290 + continue;
70291 + }
70292 + parent = dentry->d_parent;
70293 + prefetch(parent);
70294 + spin_lock(&dentry->d_lock);
70295 + error = prepend_name(buffer, buflen, &dentry->d_name);
70296 + spin_unlock(&dentry->d_lock);
70297 + if (!error)
70298 + error = prepend(buffer, buflen, "/", 1);
70299 + if (error)
70300 + break;
70301 +
70302 + slash = true;
70303 + dentry = parent;
70304 + }
70305 +
70306 +out:
70307 + if (!error && !slash)
70308 + error = prepend(buffer, buflen, "/", 1);
70309 +
70310 + return error;
70311 +}
70312 +
70313 +/* this must be called with mount_lock and rename_lock held */
70314 +
70315 +static char *__our_d_path(const struct path *path, struct path *root,
70316 + char *buf, int buflen)
70317 +{
70318 + char *res = buf + buflen;
70319 + int error;
70320 +
70321 + prepend(&res, &buflen, "\0", 1);
70322 + error = prepend_path(path, root, &res, &buflen);
70323 + if (error)
70324 + return ERR_PTR(error);
70325 +
70326 + return res;
70327 +}
70328 +
70329 +static char *
70330 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
70331 +{
70332 + char *retval;
70333 +
70334 + retval = __our_d_path(path, root, buf, buflen);
70335 + if (unlikely(IS_ERR(retval)))
70336 + retval = strcpy(buf, "<path too long>");
70337 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
70338 + retval[1] = '\0';
70339 +
70340 + return retval;
70341 +}
70342 +
70343 +static char *
70344 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70345 + char *buf, int buflen)
70346 +{
70347 + struct path path;
70348 + char *res;
70349 +
70350 + path.dentry = (struct dentry *)dentry;
70351 + path.mnt = (struct vfsmount *)vfsmnt;
70352 +
70353 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
70354 + by the RBAC system */
70355 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
70356 +
70357 + return res;
70358 +}
70359 +
70360 +static char *
70361 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70362 + char *buf, int buflen)
70363 +{
70364 + char *res;
70365 + struct path path;
70366 + struct path root;
70367 + struct task_struct *reaper = init_pid_ns.child_reaper;
70368 +
70369 + path.dentry = (struct dentry *)dentry;
70370 + path.mnt = (struct vfsmount *)vfsmnt;
70371 +
70372 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
70373 + get_fs_root(reaper->fs, &root);
70374 +
70375 + read_seqlock_excl(&mount_lock);
70376 + write_seqlock(&rename_lock);
70377 + res = gen_full_path(&path, &root, buf, buflen);
70378 + write_sequnlock(&rename_lock);
70379 + read_sequnlock_excl(&mount_lock);
70380 +
70381 + path_put(&root);
70382 + return res;
70383 +}
70384 +
70385 +char *
70386 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70387 +{
70388 + char *ret;
70389 + read_seqlock_excl(&mount_lock);
70390 + write_seqlock(&rename_lock);
70391 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70392 + PAGE_SIZE);
70393 + write_sequnlock(&rename_lock);
70394 + read_sequnlock_excl(&mount_lock);
70395 + return ret;
70396 +}
70397 +
70398 +static char *
70399 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70400 +{
70401 + char *ret;
70402 + char *buf;
70403 + int buflen;
70404 +
70405 + read_seqlock_excl(&mount_lock);
70406 + write_seqlock(&rename_lock);
70407 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
70408 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
70409 + buflen = (int)(ret - buf);
70410 + if (buflen >= 5)
70411 + prepend(&ret, &buflen, "/proc", 5);
70412 + else
70413 + ret = strcpy(buf, "<path too long>");
70414 + write_sequnlock(&rename_lock);
70415 + read_sequnlock_excl(&mount_lock);
70416 + return ret;
70417 +}
70418 +
70419 +char *
70420 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
70421 +{
70422 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70423 + PAGE_SIZE);
70424 +}
70425 +
70426 +char *
70427 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
70428 +{
70429 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
70430 + PAGE_SIZE);
70431 +}
70432 +
70433 +char *
70434 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
70435 +{
70436 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
70437 + PAGE_SIZE);
70438 +}
70439 +
70440 +char *
70441 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
70442 +{
70443 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
70444 + PAGE_SIZE);
70445 +}
70446 +
70447 +char *
70448 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
70449 +{
70450 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
70451 + PAGE_SIZE);
70452 +}
70453 +
70454 +__inline__ __u32
70455 +to_gr_audit(const __u32 reqmode)
70456 +{
70457 + /* masks off auditable permission flags, then shifts them to create
70458 + auditing flags, and adds the special case of append auditing if
70459 + we're requesting write */
70460 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
70461 +}
70462 +
70463 +struct acl_role_label *
70464 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
70465 + const gid_t gid)
70466 +{
70467 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
70468 + struct acl_role_label *match;
70469 + struct role_allowed_ip *ipp;
70470 + unsigned int x;
70471 + u32 curr_ip = task->signal->saved_ip;
70472 +
70473 + match = state->acl_role_set.r_hash[index];
70474 +
70475 + while (match) {
70476 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
70477 + for (x = 0; x < match->domain_child_num; x++) {
70478 + if (match->domain_children[x] == uid)
70479 + goto found;
70480 + }
70481 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
70482 + break;
70483 + match = match->next;
70484 + }
70485 +found:
70486 + if (match == NULL) {
70487 + try_group:
70488 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
70489 + match = state->acl_role_set.r_hash[index];
70490 +
70491 + while (match) {
70492 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
70493 + for (x = 0; x < match->domain_child_num; x++) {
70494 + if (match->domain_children[x] == gid)
70495 + goto found2;
70496 + }
70497 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
70498 + break;
70499 + match = match->next;
70500 + }
70501 +found2:
70502 + if (match == NULL)
70503 + match = state->default_role;
70504 + if (match->allowed_ips == NULL)
70505 + return match;
70506 + else {
70507 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70508 + if (likely
70509 + ((ntohl(curr_ip) & ipp->netmask) ==
70510 + (ntohl(ipp->addr) & ipp->netmask)))
70511 + return match;
70512 + }
70513 + match = state->default_role;
70514 + }
70515 + } else if (match->allowed_ips == NULL) {
70516 + return match;
70517 + } else {
70518 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70519 + if (likely
70520 + ((ntohl(curr_ip) & ipp->netmask) ==
70521 + (ntohl(ipp->addr) & ipp->netmask)))
70522 + return match;
70523 + }
70524 + goto try_group;
70525 + }
70526 +
70527 + return match;
70528 +}
70529 +
70530 +static struct acl_role_label *
70531 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
70532 + const gid_t gid)
70533 +{
70534 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
70535 +}
70536 +
70537 +struct acl_subject_label *
70538 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
70539 + const struct acl_role_label *role)
70540 +{
70541 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70542 + struct acl_subject_label *match;
70543 +
70544 + match = role->subj_hash[index];
70545 +
70546 + while (match && (match->inode != ino || match->device != dev ||
70547 + (match->mode & GR_DELETED))) {
70548 + match = match->next;
70549 + }
70550 +
70551 + if (match && !(match->mode & GR_DELETED))
70552 + return match;
70553 + else
70554 + return NULL;
70555 +}
70556 +
70557 +struct acl_subject_label *
70558 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
70559 + const struct acl_role_label *role)
70560 +{
70561 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70562 + struct acl_subject_label *match;
70563 +
70564 + match = role->subj_hash[index];
70565 +
70566 + while (match && (match->inode != ino || match->device != dev ||
70567 + !(match->mode & GR_DELETED))) {
70568 + match = match->next;
70569 + }
70570 +
70571 + if (match && (match->mode & GR_DELETED))
70572 + return match;
70573 + else
70574 + return NULL;
70575 +}
70576 +
70577 +static struct acl_object_label *
70578 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
70579 + const struct acl_subject_label *subj)
70580 +{
70581 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70582 + struct acl_object_label *match;
70583 +
70584 + match = subj->obj_hash[index];
70585 +
70586 + while (match && (match->inode != ino || match->device != dev ||
70587 + (match->mode & GR_DELETED))) {
70588 + match = match->next;
70589 + }
70590 +
70591 + if (match && !(match->mode & GR_DELETED))
70592 + return match;
70593 + else
70594 + return NULL;
70595 +}
70596 +
70597 +static struct acl_object_label *
70598 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
70599 + const struct acl_subject_label *subj)
70600 +{
70601 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70602 + struct acl_object_label *match;
70603 +
70604 + match = subj->obj_hash[index];
70605 +
70606 + while (match && (match->inode != ino || match->device != dev ||
70607 + !(match->mode & GR_DELETED))) {
70608 + match = match->next;
70609 + }
70610 +
70611 + if (match && (match->mode & GR_DELETED))
70612 + return match;
70613 +
70614 + match = subj->obj_hash[index];
70615 +
70616 + while (match && (match->inode != ino || match->device != dev ||
70617 + (match->mode & GR_DELETED))) {
70618 + match = match->next;
70619 + }
70620 +
70621 + if (match && !(match->mode & GR_DELETED))
70622 + return match;
70623 + else
70624 + return NULL;
70625 +}
70626 +
70627 +struct name_entry *
70628 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70629 +{
70630 + unsigned int len = strlen(name);
70631 + unsigned int key = full_name_hash(name, len);
70632 + unsigned int index = key % state->name_set.n_size;
70633 + struct name_entry *match;
70634 +
70635 + match = state->name_set.n_hash[index];
70636 +
70637 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70638 + match = match->next;
70639 +
70640 + return match;
70641 +}
70642 +
70643 +static struct name_entry *
70644 +lookup_name_entry(const char *name)
70645 +{
70646 + return __lookup_name_entry(&running_polstate, name);
70647 +}
70648 +
70649 +static struct name_entry *
70650 +lookup_name_entry_create(const char *name)
70651 +{
70652 + unsigned int len = strlen(name);
70653 + unsigned int key = full_name_hash(name, len);
70654 + unsigned int index = key % running_polstate.name_set.n_size;
70655 + struct name_entry *match;
70656 +
70657 + match = running_polstate.name_set.n_hash[index];
70658 +
70659 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70660 + !match->deleted))
70661 + match = match->next;
70662 +
70663 + if (match && match->deleted)
70664 + return match;
70665 +
70666 + match = running_polstate.name_set.n_hash[index];
70667 +
70668 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70669 + match->deleted))
70670 + match = match->next;
70671 +
70672 + if (match && !match->deleted)
70673 + return match;
70674 + else
70675 + return NULL;
70676 +}
70677 +
70678 +static struct inodev_entry *
70679 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
70680 +{
70681 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70682 + struct inodev_entry *match;
70683 +
70684 + match = running_polstate.inodev_set.i_hash[index];
70685 +
70686 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70687 + match = match->next;
70688 +
70689 + return match;
70690 +}
70691 +
70692 +void
70693 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70694 +{
70695 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70696 + state->inodev_set.i_size);
70697 + struct inodev_entry **curr;
70698 +
70699 + entry->prev = NULL;
70700 +
70701 + curr = &state->inodev_set.i_hash[index];
70702 + if (*curr != NULL)
70703 + (*curr)->prev = entry;
70704 +
70705 + entry->next = *curr;
70706 + *curr = entry;
70707 +
70708 + return;
70709 +}
70710 +
70711 +static void
70712 +insert_inodev_entry(struct inodev_entry *entry)
70713 +{
70714 + __insert_inodev_entry(&running_polstate, entry);
70715 +}
70716 +
70717 +void
70718 +insert_acl_obj_label(struct acl_object_label *obj,
70719 + struct acl_subject_label *subj)
70720 +{
70721 + unsigned int index =
70722 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70723 + struct acl_object_label **curr;
70724 +
70725 + obj->prev = NULL;
70726 +
70727 + curr = &subj->obj_hash[index];
70728 + if (*curr != NULL)
70729 + (*curr)->prev = obj;
70730 +
70731 + obj->next = *curr;
70732 + *curr = obj;
70733 +
70734 + return;
70735 +}
70736 +
70737 +void
70738 +insert_acl_subj_label(struct acl_subject_label *obj,
70739 + struct acl_role_label *role)
70740 +{
70741 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70742 + struct acl_subject_label **curr;
70743 +
70744 + obj->prev = NULL;
70745 +
70746 + curr = &role->subj_hash[index];
70747 + if (*curr != NULL)
70748 + (*curr)->prev = obj;
70749 +
70750 + obj->next = *curr;
70751 + *curr = obj;
70752 +
70753 + return;
70754 +}
70755 +
70756 +/* derived from glibc fnmatch() 0: match, 1: no match*/
70757 +
70758 +static int
70759 +glob_match(const char *p, const char *n)
70760 +{
70761 + char c;
70762 +
70763 + while ((c = *p++) != '\0') {
70764 + switch (c) {
70765 + case '?':
70766 + if (*n == '\0')
70767 + return 1;
70768 + else if (*n == '/')
70769 + return 1;
70770 + break;
70771 + case '\\':
70772 + if (*n != c)
70773 + return 1;
70774 + break;
70775 + case '*':
70776 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
70777 + if (*n == '/')
70778 + return 1;
70779 + else if (c == '?') {
70780 + if (*n == '\0')
70781 + return 1;
70782 + else
70783 + ++n;
70784 + }
70785 + }
70786 + if (c == '\0') {
70787 + return 0;
70788 + } else {
70789 + const char *endp;
70790 +
70791 + if ((endp = strchr(n, '/')) == NULL)
70792 + endp = n + strlen(n);
70793 +
70794 + if (c == '[') {
70795 + for (--p; n < endp; ++n)
70796 + if (!glob_match(p, n))
70797 + return 0;
70798 + } else if (c == '/') {
70799 + while (*n != '\0' && *n != '/')
70800 + ++n;
70801 + if (*n == '/' && !glob_match(p, n + 1))
70802 + return 0;
70803 + } else {
70804 + for (--p; n < endp; ++n)
70805 + if (*n == c && !glob_match(p, n))
70806 + return 0;
70807 + }
70808 +
70809 + return 1;
70810 + }
70811 + case '[':
70812 + {
70813 + int not;
70814 + char cold;
70815 +
70816 + if (*n == '\0' || *n == '/')
70817 + return 1;
70818 +
70819 + not = (*p == '!' || *p == '^');
70820 + if (not)
70821 + ++p;
70822 +
70823 + c = *p++;
70824 + for (;;) {
70825 + unsigned char fn = (unsigned char)*n;
70826 +
70827 + if (c == '\0')
70828 + return 1;
70829 + else {
70830 + if (c == fn)
70831 + goto matched;
70832 + cold = c;
70833 + c = *p++;
70834 +
70835 + if (c == '-' && *p != ']') {
70836 + unsigned char cend = *p++;
70837 +
70838 + if (cend == '\0')
70839 + return 1;
70840 +
70841 + if (cold <= fn && fn <= cend)
70842 + goto matched;
70843 +
70844 + c = *p++;
70845 + }
70846 + }
70847 +
70848 + if (c == ']')
70849 + break;
70850 + }
70851 + if (!not)
70852 + return 1;
70853 + break;
70854 + matched:
70855 + while (c != ']') {
70856 + if (c == '\0')
70857 + return 1;
70858 +
70859 + c = *p++;
70860 + }
70861 + if (not)
70862 + return 1;
70863 + }
70864 + break;
70865 + default:
70866 + if (c != *n)
70867 + return 1;
70868 + }
70869 +
70870 + ++n;
70871 + }
70872 +
70873 + if (*n == '\0')
70874 + return 0;
70875 +
70876 + if (*n == '/')
70877 + return 0;
70878 +
70879 + return 1;
70880 +}
70881 +
70882 +static struct acl_object_label *
70883 +chk_glob_label(struct acl_object_label *globbed,
70884 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70885 +{
70886 + struct acl_object_label *tmp;
70887 +
70888 + if (*path == NULL)
70889 + *path = gr_to_filename_nolock(dentry, mnt);
70890 +
70891 + tmp = globbed;
70892 +
70893 + while (tmp) {
70894 + if (!glob_match(tmp->filename, *path))
70895 + return tmp;
70896 + tmp = tmp->next;
70897 + }
70898 +
70899 + return NULL;
70900 +}
70901 +
70902 +static struct acl_object_label *
70903 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70904 + const ino_t curr_ino, const dev_t curr_dev,
70905 + const struct acl_subject_label *subj, char **path, const int checkglob)
70906 +{
70907 + struct acl_subject_label *tmpsubj;
70908 + struct acl_object_label *retval;
70909 + struct acl_object_label *retval2;
70910 +
70911 + tmpsubj = (struct acl_subject_label *) subj;
70912 + read_lock(&gr_inode_lock);
70913 + do {
70914 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70915 + if (retval) {
70916 + if (checkglob && retval->globbed) {
70917 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70918 + if (retval2)
70919 + retval = retval2;
70920 + }
70921 + break;
70922 + }
70923 + } while ((tmpsubj = tmpsubj->parent_subject));
70924 + read_unlock(&gr_inode_lock);
70925 +
70926 + return retval;
70927 +}
70928 +
70929 +static __inline__ struct acl_object_label *
70930 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70931 + struct dentry *curr_dentry,
70932 + const struct acl_subject_label *subj, char **path, const int checkglob)
70933 +{
70934 + int newglob = checkglob;
70935 + ino_t inode;
70936 + dev_t device;
70937 +
70938 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70939 + as we don't want a / * rule to match instead of the / object
70940 + don't do this for create lookups that call this function though, since they're looking up
70941 + on the parent and thus need globbing checks on all paths
70942 + */
70943 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70944 + newglob = GR_NO_GLOB;
70945 +
70946 + spin_lock(&curr_dentry->d_lock);
70947 + inode = curr_dentry->d_inode->i_ino;
70948 + device = __get_dev(curr_dentry);
70949 + spin_unlock(&curr_dentry->d_lock);
70950 +
70951 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70952 +}
70953 +
70954 +#ifdef CONFIG_HUGETLBFS
70955 +static inline bool
70956 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
70957 +{
70958 + int i;
70959 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70960 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70961 + return true;
70962 + }
70963 +
70964 + return false;
70965 +}
70966 +#endif
70967 +
70968 +static struct acl_object_label *
70969 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70970 + const struct acl_subject_label *subj, char *path, const int checkglob)
70971 +{
70972 + struct dentry *dentry = (struct dentry *) l_dentry;
70973 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70974 + struct mount *real_mnt = real_mount(mnt);
70975 + struct acl_object_label *retval;
70976 + struct dentry *parent;
70977 +
70978 + read_seqlock_excl(&mount_lock);
70979 + write_seqlock(&rename_lock);
70980 +
70981 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70982 +#ifdef CONFIG_NET
70983 + mnt == sock_mnt ||
70984 +#endif
70985 +#ifdef CONFIG_HUGETLBFS
70986 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70987 +#endif
70988 + /* ignore Eric Biederman */
70989 + IS_PRIVATE(l_dentry->d_inode))) {
70990 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70991 + goto out;
70992 + }
70993 +
70994 + for (;;) {
70995 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70996 + break;
70997 +
70998 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70999 + if (!mnt_has_parent(real_mnt))
71000 + break;
71001 +
71002 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
71003 + if (retval != NULL)
71004 + goto out;
71005 +
71006 + dentry = real_mnt->mnt_mountpoint;
71007 + real_mnt = real_mnt->mnt_parent;
71008 + mnt = &real_mnt->mnt;
71009 + continue;
71010 + }
71011 +
71012 + parent = dentry->d_parent;
71013 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
71014 + if (retval != NULL)
71015 + goto out;
71016 +
71017 + dentry = parent;
71018 + }
71019 +
71020 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
71021 +
71022 + /* gr_real_root is pinned so we don't have to hold a reference */
71023 + if (retval == NULL)
71024 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
71025 +out:
71026 + write_sequnlock(&rename_lock);
71027 + read_sequnlock_excl(&mount_lock);
71028 +
71029 + BUG_ON(retval == NULL);
71030 +
71031 + return retval;
71032 +}
71033 +
71034 +static __inline__ struct acl_object_label *
71035 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71036 + const struct acl_subject_label *subj)
71037 +{
71038 + char *path = NULL;
71039 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
71040 +}
71041 +
71042 +static __inline__ struct acl_object_label *
71043 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71044 + const struct acl_subject_label *subj)
71045 +{
71046 + char *path = NULL;
71047 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
71048 +}
71049 +
71050 +static __inline__ struct acl_object_label *
71051 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71052 + const struct acl_subject_label *subj, char *path)
71053 +{
71054 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
71055 +}
71056 +
71057 +struct acl_subject_label *
71058 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71059 + const struct acl_role_label *role)
71060 +{
71061 + struct dentry *dentry = (struct dentry *) l_dentry;
71062 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
71063 + struct mount *real_mnt = real_mount(mnt);
71064 + struct acl_subject_label *retval;
71065 + struct dentry *parent;
71066 +
71067 + read_seqlock_excl(&mount_lock);
71068 + write_seqlock(&rename_lock);
71069 +
71070 + for (;;) {
71071 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
71072 + break;
71073 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
71074 + if (!mnt_has_parent(real_mnt))
71075 + break;
71076 +
71077 + spin_lock(&dentry->d_lock);
71078 + read_lock(&gr_inode_lock);
71079 + retval =
71080 + lookup_acl_subj_label(dentry->d_inode->i_ino,
71081 + __get_dev(dentry), role);
71082 + read_unlock(&gr_inode_lock);
71083 + spin_unlock(&dentry->d_lock);
71084 + if (retval != NULL)
71085 + goto out;
71086 +
71087 + dentry = real_mnt->mnt_mountpoint;
71088 + real_mnt = real_mnt->mnt_parent;
71089 + mnt = &real_mnt->mnt;
71090 + continue;
71091 + }
71092 +
71093 + spin_lock(&dentry->d_lock);
71094 + read_lock(&gr_inode_lock);
71095 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
71096 + __get_dev(dentry), role);
71097 + read_unlock(&gr_inode_lock);
71098 + parent = dentry->d_parent;
71099 + spin_unlock(&dentry->d_lock);
71100 +
71101 + if (retval != NULL)
71102 + goto out;
71103 +
71104 + dentry = parent;
71105 + }
71106 +
71107 + spin_lock(&dentry->d_lock);
71108 + read_lock(&gr_inode_lock);
71109 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
71110 + __get_dev(dentry), role);
71111 + read_unlock(&gr_inode_lock);
71112 + spin_unlock(&dentry->d_lock);
71113 +
71114 + if (unlikely(retval == NULL)) {
71115 + /* gr_real_root is pinned, we don't need to hold a reference */
71116 + read_lock(&gr_inode_lock);
71117 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
71118 + __get_dev(gr_real_root.dentry), role);
71119 + read_unlock(&gr_inode_lock);
71120 + }
71121 +out:
71122 + write_sequnlock(&rename_lock);
71123 + read_sequnlock_excl(&mount_lock);
71124 +
71125 + BUG_ON(retval == NULL);
71126 +
71127 + return retval;
71128 +}
71129 +
71130 +void
71131 +assign_special_role(const char *rolename)
71132 +{
71133 + struct acl_object_label *obj;
71134 + struct acl_role_label *r;
71135 + struct acl_role_label *assigned = NULL;
71136 + struct task_struct *tsk;
71137 + struct file *filp;
71138 +
71139 + FOR_EACH_ROLE_START(r)
71140 + if (!strcmp(rolename, r->rolename) &&
71141 + (r->roletype & GR_ROLE_SPECIAL)) {
71142 + assigned = r;
71143 + break;
71144 + }
71145 + FOR_EACH_ROLE_END(r)
71146 +
71147 + if (!assigned)
71148 + return;
71149 +
71150 + read_lock(&tasklist_lock);
71151 + read_lock(&grsec_exec_file_lock);
71152 +
71153 + tsk = current->real_parent;
71154 + if (tsk == NULL)
71155 + goto out_unlock;
71156 +
71157 + filp = tsk->exec_file;
71158 + if (filp == NULL)
71159 + goto out_unlock;
71160 +
71161 + tsk->is_writable = 0;
71162 + tsk->inherited = 0;
71163 +
71164 + tsk->acl_sp_role = 1;
71165 + tsk->acl_role_id = ++acl_sp_role_value;
71166 + tsk->role = assigned;
71167 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
71168 +
71169 + /* ignore additional mmap checks for processes that are writable
71170 + by the default ACL */
71171 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71172 + if (unlikely(obj->mode & GR_WRITE))
71173 + tsk->is_writable = 1;
71174 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
71175 + if (unlikely(obj->mode & GR_WRITE))
71176 + tsk->is_writable = 1;
71177 +
71178 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71179 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
71180 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
71181 +#endif
71182 +
71183 +out_unlock:
71184 + read_unlock(&grsec_exec_file_lock);
71185 + read_unlock(&tasklist_lock);
71186 + return;
71187 +}
71188 +
71189 +
71190 +static void
71191 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
71192 +{
71193 + struct task_struct *task = current;
71194 + const struct cred *cred = current_cred();
71195 +
71196 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
71197 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71198 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71199 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
71200 +
71201 + return;
71202 +}
71203 +
71204 +static void
71205 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
71206 +{
71207 + struct task_struct *task = current;
71208 + const struct cred *cred = current_cred();
71209 +
71210 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
71211 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71212 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71213 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
71214 +
71215 + return;
71216 +}
71217 +
71218 +static void
71219 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
71220 +{
71221 + struct task_struct *task = current;
71222 + const struct cred *cred = current_cred();
71223 +
71224 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
71225 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71226 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71227 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
71228 +
71229 + return;
71230 +}
71231 +
71232 +static void
71233 +gr_set_proc_res(struct task_struct *task)
71234 +{
71235 + struct acl_subject_label *proc;
71236 + unsigned short i;
71237 +
71238 + proc = task->acl;
71239 +
71240 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
71241 + return;
71242 +
71243 + for (i = 0; i < RLIM_NLIMITS; i++) {
71244 + if (!(proc->resmask & (1U << i)))
71245 + continue;
71246 +
71247 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
71248 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
71249 +
71250 + if (i == RLIMIT_CPU)
71251 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
71252 + }
71253 +
71254 + return;
71255 +}
71256 +
71257 +/* both of the below must be called with
71258 + rcu_read_lock();
71259 + read_lock(&tasklist_lock);
71260 + read_lock(&grsec_exec_file_lock);
71261 +*/
71262 +
71263 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
71264 +{
71265 + char *tmpname;
71266 + struct acl_subject_label *tmpsubj;
71267 + struct file *filp;
71268 + struct name_entry *nmatch;
71269 +
71270 + filp = task->exec_file;
71271 + if (filp == NULL)
71272 + return NULL;
71273 +
71274 + /* the following is to apply the correct subject
71275 + on binaries running when the RBAC system
71276 + is enabled, when the binaries have been
71277 + replaced or deleted since their execution
71278 + -----
71279 + when the RBAC system starts, the inode/dev
71280 + from exec_file will be one the RBAC system
71281 + is unaware of. It only knows the inode/dev
71282 + of the present file on disk, or the absence
71283 + of it.
71284 + */
71285 +
71286 + if (filename)
71287 + nmatch = __lookup_name_entry(state, filename);
71288 + else {
71289 + preempt_disable();
71290 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
71291 +
71292 + nmatch = __lookup_name_entry(state, tmpname);
71293 + preempt_enable();
71294 + }
71295 + tmpsubj = NULL;
71296 + if (nmatch) {
71297 + if (nmatch->deleted)
71298 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
71299 + else
71300 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
71301 + }
71302 + /* this also works for the reload case -- if we don't match a potentially inherited subject
71303 + then we fall back to a normal lookup based on the binary's ino/dev
71304 + */
71305 + if (tmpsubj == NULL)
71306 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
71307 +
71308 + return tmpsubj;
71309 +}
71310 +
71311 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
71312 +{
71313 + return __gr_get_subject_for_task(&running_polstate, task, filename);
71314 +}
71315 +
71316 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
71317 +{
71318 + struct acl_object_label *obj;
71319 + struct file *filp;
71320 +
71321 + filp = task->exec_file;
71322 +
71323 + task->acl = subj;
71324 + task->is_writable = 0;
71325 + /* ignore additional mmap checks for processes that are writable
71326 + by the default ACL */
71327 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
71328 + if (unlikely(obj->mode & GR_WRITE))
71329 + task->is_writable = 1;
71330 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71331 + if (unlikely(obj->mode & GR_WRITE))
71332 + task->is_writable = 1;
71333 +
71334 + gr_set_proc_res(task);
71335 +
71336 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71337 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
71338 +#endif
71339 +}
71340 +
71341 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
71342 +{
71343 + __gr_apply_subject_to_task(&running_polstate, task, subj);
71344 +}
71345 +
71346 +__u32
71347 +gr_search_file(const struct dentry * dentry, const __u32 mode,
71348 + const struct vfsmount * mnt)
71349 +{
71350 + __u32 retval = mode;
71351 + struct acl_subject_label *curracl;
71352 + struct acl_object_label *currobj;
71353 +
71354 + if (unlikely(!(gr_status & GR_READY)))
71355 + return (mode & ~GR_AUDITS);
71356 +
71357 + curracl = current->acl;
71358 +
71359 + currobj = chk_obj_label(dentry, mnt, curracl);
71360 + retval = currobj->mode & mode;
71361 +
71362 + /* if we're opening a specified transfer file for writing
71363 + (e.g. /dev/initctl), then transfer our role to init
71364 + */
71365 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
71366 + current->role->roletype & GR_ROLE_PERSIST)) {
71367 + struct task_struct *task = init_pid_ns.child_reaper;
71368 +
71369 + if (task->role != current->role) {
71370 + struct acl_subject_label *subj;
71371 +
71372 + task->acl_sp_role = 0;
71373 + task->acl_role_id = current->acl_role_id;
71374 + task->role = current->role;
71375 + rcu_read_lock();
71376 + read_lock(&grsec_exec_file_lock);
71377 + subj = gr_get_subject_for_task(task, NULL);
71378 + gr_apply_subject_to_task(task, subj);
71379 + read_unlock(&grsec_exec_file_lock);
71380 + rcu_read_unlock();
71381 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
71382 + }
71383 + }
71384 +
71385 + if (unlikely
71386 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
71387 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
71388 + __u32 new_mode = mode;
71389 +
71390 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71391 +
71392 + retval = new_mode;
71393 +
71394 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
71395 + new_mode |= GR_INHERIT;
71396 +
71397 + if (!(mode & GR_NOLEARN))
71398 + gr_log_learn(dentry, mnt, new_mode);
71399 + }
71400 +
71401 + return retval;
71402 +}
71403 +
71404 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
71405 + const struct dentry *parent,
71406 + const struct vfsmount *mnt)
71407 +{
71408 + struct name_entry *match;
71409 + struct acl_object_label *matchpo;
71410 + struct acl_subject_label *curracl;
71411 + char *path;
71412 +
71413 + if (unlikely(!(gr_status & GR_READY)))
71414 + return NULL;
71415 +
71416 + preempt_disable();
71417 + path = gr_to_filename_rbac(new_dentry, mnt);
71418 + match = lookup_name_entry_create(path);
71419 +
71420 + curracl = current->acl;
71421 +
71422 + if (match) {
71423 + read_lock(&gr_inode_lock);
71424 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
71425 + read_unlock(&gr_inode_lock);
71426 +
71427 + if (matchpo) {
71428 + preempt_enable();
71429 + return matchpo;
71430 + }
71431 + }
71432 +
71433 + // lookup parent
71434 +
71435 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
71436 +
71437 + preempt_enable();
71438 + return matchpo;
71439 +}
71440 +
71441 +__u32
71442 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
71443 + const struct vfsmount * mnt, const __u32 mode)
71444 +{
71445 + struct acl_object_label *matchpo;
71446 + __u32 retval;
71447 +
71448 + if (unlikely(!(gr_status & GR_READY)))
71449 + return (mode & ~GR_AUDITS);
71450 +
71451 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
71452 +
71453 + retval = matchpo->mode & mode;
71454 +
71455 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
71456 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71457 + __u32 new_mode = mode;
71458 +
71459 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71460 +
71461 + gr_log_learn(new_dentry, mnt, new_mode);
71462 + return new_mode;
71463 + }
71464 +
71465 + return retval;
71466 +}
71467 +
71468 +__u32
71469 +gr_check_link(const struct dentry * new_dentry,
71470 + const struct dentry * parent_dentry,
71471 + const struct vfsmount * parent_mnt,
71472 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
71473 +{
71474 + struct acl_object_label *obj;
71475 + __u32 oldmode, newmode;
71476 + __u32 needmode;
71477 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
71478 + GR_DELETE | GR_INHERIT;
71479 +
71480 + if (unlikely(!(gr_status & GR_READY)))
71481 + return (GR_CREATE | GR_LINK);
71482 +
71483 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
71484 + oldmode = obj->mode;
71485 +
71486 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
71487 + newmode = obj->mode;
71488 +
71489 + needmode = newmode & checkmodes;
71490 +
71491 + // old name for hardlink must have at least the permissions of the new name
71492 + if ((oldmode & needmode) != needmode)
71493 + goto bad;
71494 +
71495 + // if old name had restrictions/auditing, make sure the new name does as well
71496 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
71497 +
71498 + // don't allow hardlinking of suid/sgid/fcapped files without permission
71499 + if (is_privileged_binary(old_dentry))
71500 + needmode |= GR_SETID;
71501 +
71502 + if ((newmode & needmode) != needmode)
71503 + goto bad;
71504 +
71505 + // enforce minimum permissions
71506 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
71507 + return newmode;
71508 +bad:
71509 + needmode = oldmode;
71510 + if (is_privileged_binary(old_dentry))
71511 + needmode |= GR_SETID;
71512 +
71513 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
71514 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
71515 + return (GR_CREATE | GR_LINK);
71516 + } else if (newmode & GR_SUPPRESS)
71517 + return GR_SUPPRESS;
71518 + else
71519 + return 0;
71520 +}
71521 +
71522 +int
71523 +gr_check_hidden_task(const struct task_struct *task)
71524 +{
71525 + if (unlikely(!(gr_status & GR_READY)))
71526 + return 0;
71527 +
71528 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
71529 + return 1;
71530 +
71531 + return 0;
71532 +}
71533 +
71534 +int
71535 +gr_check_protected_task(const struct task_struct *task)
71536 +{
71537 + if (unlikely(!(gr_status & GR_READY) || !task))
71538 + return 0;
71539 +
71540 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71541 + task->acl != current->acl)
71542 + return 1;
71543 +
71544 + return 0;
71545 +}
71546 +
71547 +int
71548 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
71549 +{
71550 + struct task_struct *p;
71551 + int ret = 0;
71552 +
71553 + if (unlikely(!(gr_status & GR_READY) || !pid))
71554 + return ret;
71555 +
71556 + read_lock(&tasklist_lock);
71557 + do_each_pid_task(pid, type, p) {
71558 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71559 + p->acl != current->acl) {
71560 + ret = 1;
71561 + goto out;
71562 + }
71563 + } while_each_pid_task(pid, type, p);
71564 +out:
71565 + read_unlock(&tasklist_lock);
71566 +
71567 + return ret;
71568 +}
71569 +
71570 +void
71571 +gr_copy_label(struct task_struct *tsk)
71572 +{
71573 + struct task_struct *p = current;
71574 +
71575 + tsk->inherited = p->inherited;
71576 + tsk->acl_sp_role = 0;
71577 + tsk->acl_role_id = p->acl_role_id;
71578 + tsk->acl = p->acl;
71579 + tsk->role = p->role;
71580 + tsk->signal->used_accept = 0;
71581 + tsk->signal->curr_ip = p->signal->curr_ip;
71582 + tsk->signal->saved_ip = p->signal->saved_ip;
71583 + if (p->exec_file)
71584 + get_file(p->exec_file);
71585 + tsk->exec_file = p->exec_file;
71586 + tsk->is_writable = p->is_writable;
71587 + if (unlikely(p->signal->used_accept)) {
71588 + p->signal->curr_ip = 0;
71589 + p->signal->saved_ip = 0;
71590 + }
71591 +
71592 + return;
71593 +}
71594 +
71595 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71596 +
71597 +int
71598 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71599 +{
71600 + unsigned int i;
71601 + __u16 num;
71602 + uid_t *uidlist;
71603 + uid_t curuid;
71604 + int realok = 0;
71605 + int effectiveok = 0;
71606 + int fsok = 0;
71607 + uid_t globalreal, globaleffective, globalfs;
71608 +
71609 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71610 + struct user_struct *user;
71611 +
71612 + if (!uid_valid(real))
71613 + goto skipit;
71614 +
71615 + /* find user based on global namespace */
71616 +
71617 + globalreal = GR_GLOBAL_UID(real);
71618 +
71619 + user = find_user(make_kuid(&init_user_ns, globalreal));
71620 + if (user == NULL)
71621 + goto skipit;
71622 +
71623 + if (gr_process_kernel_setuid_ban(user)) {
71624 + /* for find_user */
71625 + free_uid(user);
71626 + return 1;
71627 + }
71628 +
71629 + /* for find_user */
71630 + free_uid(user);
71631 +
71632 +skipit:
71633 +#endif
71634 +
71635 + if (unlikely(!(gr_status & GR_READY)))
71636 + return 0;
71637 +
71638 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71639 + gr_log_learn_uid_change(real, effective, fs);
71640 +
71641 + num = current->acl->user_trans_num;
71642 + uidlist = current->acl->user_transitions;
71643 +
71644 + if (uidlist == NULL)
71645 + return 0;
71646 +
71647 + if (!uid_valid(real)) {
71648 + realok = 1;
71649 + globalreal = (uid_t)-1;
71650 + } else {
71651 + globalreal = GR_GLOBAL_UID(real);
71652 + }
71653 + if (!uid_valid(effective)) {
71654 + effectiveok = 1;
71655 + globaleffective = (uid_t)-1;
71656 + } else {
71657 + globaleffective = GR_GLOBAL_UID(effective);
71658 + }
71659 + if (!uid_valid(fs)) {
71660 + fsok = 1;
71661 + globalfs = (uid_t)-1;
71662 + } else {
71663 + globalfs = GR_GLOBAL_UID(fs);
71664 + }
71665 +
71666 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
71667 + for (i = 0; i < num; i++) {
71668 + curuid = uidlist[i];
71669 + if (globalreal == curuid)
71670 + realok = 1;
71671 + if (globaleffective == curuid)
71672 + effectiveok = 1;
71673 + if (globalfs == curuid)
71674 + fsok = 1;
71675 + }
71676 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
71677 + for (i = 0; i < num; i++) {
71678 + curuid = uidlist[i];
71679 + if (globalreal == curuid)
71680 + break;
71681 + if (globaleffective == curuid)
71682 + break;
71683 + if (globalfs == curuid)
71684 + break;
71685 + }
71686 + /* not in deny list */
71687 + if (i == num) {
71688 + realok = 1;
71689 + effectiveok = 1;
71690 + fsok = 1;
71691 + }
71692 + }
71693 +
71694 + if (realok && effectiveok && fsok)
71695 + return 0;
71696 + else {
71697 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71698 + return 1;
71699 + }
71700 +}
71701 +
71702 +int
71703 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71704 +{
71705 + unsigned int i;
71706 + __u16 num;
71707 + gid_t *gidlist;
71708 + gid_t curgid;
71709 + int realok = 0;
71710 + int effectiveok = 0;
71711 + int fsok = 0;
71712 + gid_t globalreal, globaleffective, globalfs;
71713 +
71714 + if (unlikely(!(gr_status & GR_READY)))
71715 + return 0;
71716 +
71717 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71718 + gr_log_learn_gid_change(real, effective, fs);
71719 +
71720 + num = current->acl->group_trans_num;
71721 + gidlist = current->acl->group_transitions;
71722 +
71723 + if (gidlist == NULL)
71724 + return 0;
71725 +
71726 + if (!gid_valid(real)) {
71727 + realok = 1;
71728 + globalreal = (gid_t)-1;
71729 + } else {
71730 + globalreal = GR_GLOBAL_GID(real);
71731 + }
71732 + if (!gid_valid(effective)) {
71733 + effectiveok = 1;
71734 + globaleffective = (gid_t)-1;
71735 + } else {
71736 + globaleffective = GR_GLOBAL_GID(effective);
71737 + }
71738 + if (!gid_valid(fs)) {
71739 + fsok = 1;
71740 + globalfs = (gid_t)-1;
71741 + } else {
71742 + globalfs = GR_GLOBAL_GID(fs);
71743 + }
71744 +
71745 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
71746 + for (i = 0; i < num; i++) {
71747 + curgid = gidlist[i];
71748 + if (globalreal == curgid)
71749 + realok = 1;
71750 + if (globaleffective == curgid)
71751 + effectiveok = 1;
71752 + if (globalfs == curgid)
71753 + fsok = 1;
71754 + }
71755 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
71756 + for (i = 0; i < num; i++) {
71757 + curgid = gidlist[i];
71758 + if (globalreal == curgid)
71759 + break;
71760 + if (globaleffective == curgid)
71761 + break;
71762 + if (globalfs == curgid)
71763 + break;
71764 + }
71765 + /* not in deny list */
71766 + if (i == num) {
71767 + realok = 1;
71768 + effectiveok = 1;
71769 + fsok = 1;
71770 + }
71771 + }
71772 +
71773 + if (realok && effectiveok && fsok)
71774 + return 0;
71775 + else {
71776 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71777 + return 1;
71778 + }
71779 +}
71780 +
71781 +extern int gr_acl_is_capable(const int cap);
71782 +
71783 +void
71784 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71785 +{
71786 + struct acl_role_label *role = task->role;
71787 + struct acl_subject_label *subj = NULL;
71788 + struct acl_object_label *obj;
71789 + struct file *filp;
71790 + uid_t uid;
71791 + gid_t gid;
71792 +
71793 + if (unlikely(!(gr_status & GR_READY)))
71794 + return;
71795 +
71796 + uid = GR_GLOBAL_UID(kuid);
71797 + gid = GR_GLOBAL_GID(kgid);
71798 +
71799 + filp = task->exec_file;
71800 +
71801 + /* kernel process, we'll give them the kernel role */
71802 + if (unlikely(!filp)) {
71803 + task->role = running_polstate.kernel_role;
71804 + task->acl = running_polstate.kernel_role->root_label;
71805 + return;
71806 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71807 + /* save the current ip at time of role lookup so that the proper
71808 + IP will be learned for role_allowed_ip */
71809 + task->signal->saved_ip = task->signal->curr_ip;
71810 + role = lookup_acl_role_label(task, uid, gid);
71811 + }
71812 +
71813 + /* don't change the role if we're not a privileged process */
71814 + if (role && task->role != role &&
71815 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71816 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71817 + return;
71818 +
71819 + /* perform subject lookup in possibly new role
71820 + we can use this result below in the case where role == task->role
71821 + */
71822 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71823 +
71824 + /* if we changed uid/gid, but result in the same role
71825 + and are using inheritance, don't lose the inherited subject
71826 + if current subject is other than what normal lookup
71827 + would result in, we arrived via inheritance, don't
71828 + lose subject
71829 + */
71830 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
71831 + (subj == task->acl)))
71832 + task->acl = subj;
71833 +
71834 + /* leave task->inherited unaffected */
71835 +
71836 + task->role = role;
71837 +
71838 + task->is_writable = 0;
71839 +
71840 + /* ignore additional mmap checks for processes that are writable
71841 + by the default ACL */
71842 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71843 + if (unlikely(obj->mode & GR_WRITE))
71844 + task->is_writable = 1;
71845 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71846 + if (unlikely(obj->mode & GR_WRITE))
71847 + task->is_writable = 1;
71848 +
71849 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71850 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
71851 +#endif
71852 +
71853 + gr_set_proc_res(task);
71854 +
71855 + return;
71856 +}
71857 +
71858 +int
71859 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71860 + const int unsafe_flags)
71861 +{
71862 + struct task_struct *task = current;
71863 + struct acl_subject_label *newacl;
71864 + struct acl_object_label *obj;
71865 + __u32 retmode;
71866 +
71867 + if (unlikely(!(gr_status & GR_READY)))
71868 + return 0;
71869 +
71870 + newacl = chk_subj_label(dentry, mnt, task->role);
71871 +
71872 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71873 + did an exec
71874 + */
71875 + rcu_read_lock();
71876 + read_lock(&tasklist_lock);
71877 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71878 + (task->parent->acl->mode & GR_POVERRIDE))) {
71879 + read_unlock(&tasklist_lock);
71880 + rcu_read_unlock();
71881 + goto skip_check;
71882 + }
71883 + read_unlock(&tasklist_lock);
71884 + rcu_read_unlock();
71885 +
71886 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71887 + !(task->role->roletype & GR_ROLE_GOD) &&
71888 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71889 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71890 + if (unsafe_flags & LSM_UNSAFE_SHARE)
71891 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71892 + else
71893 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71894 + return -EACCES;
71895 + }
71896 +
71897 +skip_check:
71898 +
71899 + obj = chk_obj_label(dentry, mnt, task->acl);
71900 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71901 +
71902 + if (!(task->acl->mode & GR_INHERITLEARN) &&
71903 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71904 + if (obj->nested)
71905 + task->acl = obj->nested;
71906 + else
71907 + task->acl = newacl;
71908 + task->inherited = 0;
71909 + } else {
71910 + task->inherited = 1;
71911 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71912 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71913 + }
71914 +
71915 + task->is_writable = 0;
71916 +
71917 + /* ignore additional mmap checks for processes that are writable
71918 + by the default ACL */
71919 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71920 + if (unlikely(obj->mode & GR_WRITE))
71921 + task->is_writable = 1;
71922 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
71923 + if (unlikely(obj->mode & GR_WRITE))
71924 + task->is_writable = 1;
71925 +
71926 + gr_set_proc_res(task);
71927 +
71928 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71929 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
71930 +#endif
71931 + return 0;
71932 +}
71933 +
71934 +/* always called with valid inodev ptr */
71935 +static void
71936 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71937 +{
71938 + struct acl_object_label *matchpo;
71939 + struct acl_subject_label *matchps;
71940 + struct acl_subject_label *subj;
71941 + struct acl_role_label *role;
71942 + unsigned int x;
71943 +
71944 + FOR_EACH_ROLE_START(role)
71945 + FOR_EACH_SUBJECT_START(role, subj, x)
71946 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71947 + matchpo->mode |= GR_DELETED;
71948 + FOR_EACH_SUBJECT_END(subj,x)
71949 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71950 + /* nested subjects aren't in the role's subj_hash table */
71951 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71952 + matchpo->mode |= GR_DELETED;
71953 + FOR_EACH_NESTED_SUBJECT_END(subj)
71954 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71955 + matchps->mode |= GR_DELETED;
71956 + FOR_EACH_ROLE_END(role)
71957 +
71958 + inodev->nentry->deleted = 1;
71959 +
71960 + return;
71961 +}
71962 +
71963 +void
71964 +gr_handle_delete(const ino_t ino, const dev_t dev)
71965 +{
71966 + struct inodev_entry *inodev;
71967 +
71968 + if (unlikely(!(gr_status & GR_READY)))
71969 + return;
71970 +
71971 + write_lock(&gr_inode_lock);
71972 + inodev = lookup_inodev_entry(ino, dev);
71973 + if (inodev != NULL)
71974 + do_handle_delete(inodev, ino, dev);
71975 + write_unlock(&gr_inode_lock);
71976 +
71977 + return;
71978 +}
71979 +
71980 +static void
71981 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71982 + const ino_t newinode, const dev_t newdevice,
71983 + struct acl_subject_label *subj)
71984 +{
71985 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71986 + struct acl_object_label *match;
71987 +
71988 + match = subj->obj_hash[index];
71989 +
71990 + while (match && (match->inode != oldinode ||
71991 + match->device != olddevice ||
71992 + !(match->mode & GR_DELETED)))
71993 + match = match->next;
71994 +
71995 + if (match && (match->inode == oldinode)
71996 + && (match->device == olddevice)
71997 + && (match->mode & GR_DELETED)) {
71998 + if (match->prev == NULL) {
71999 + subj->obj_hash[index] = match->next;
72000 + if (match->next != NULL)
72001 + match->next->prev = NULL;
72002 + } else {
72003 + match->prev->next = match->next;
72004 + if (match->next != NULL)
72005 + match->next->prev = match->prev;
72006 + }
72007 + match->prev = NULL;
72008 + match->next = NULL;
72009 + match->inode = newinode;
72010 + match->device = newdevice;
72011 + match->mode &= ~GR_DELETED;
72012 +
72013 + insert_acl_obj_label(match, subj);
72014 + }
72015 +
72016 + return;
72017 +}
72018 +
72019 +static void
72020 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
72021 + const ino_t newinode, const dev_t newdevice,
72022 + struct acl_role_label *role)
72023 +{
72024 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
72025 + struct acl_subject_label *match;
72026 +
72027 + match = role->subj_hash[index];
72028 +
72029 + while (match && (match->inode != oldinode ||
72030 + match->device != olddevice ||
72031 + !(match->mode & GR_DELETED)))
72032 + match = match->next;
72033 +
72034 + if (match && (match->inode == oldinode)
72035 + && (match->device == olddevice)
72036 + && (match->mode & GR_DELETED)) {
72037 + if (match->prev == NULL) {
72038 + role->subj_hash[index] = match->next;
72039 + if (match->next != NULL)
72040 + match->next->prev = NULL;
72041 + } else {
72042 + match->prev->next = match->next;
72043 + if (match->next != NULL)
72044 + match->next->prev = match->prev;
72045 + }
72046 + match->prev = NULL;
72047 + match->next = NULL;
72048 + match->inode = newinode;
72049 + match->device = newdevice;
72050 + match->mode &= ~GR_DELETED;
72051 +
72052 + insert_acl_subj_label(match, role);
72053 + }
72054 +
72055 + return;
72056 +}
72057 +
72058 +static void
72059 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
72060 + const ino_t newinode, const dev_t newdevice)
72061 +{
72062 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
72063 + struct inodev_entry *match;
72064 +
72065 + match = running_polstate.inodev_set.i_hash[index];
72066 +
72067 + while (match && (match->nentry->inode != oldinode ||
72068 + match->nentry->device != olddevice || !match->nentry->deleted))
72069 + match = match->next;
72070 +
72071 + if (match && (match->nentry->inode == oldinode)
72072 + && (match->nentry->device == olddevice) &&
72073 + match->nentry->deleted) {
72074 + if (match->prev == NULL) {
72075 + running_polstate.inodev_set.i_hash[index] = match->next;
72076 + if (match->next != NULL)
72077 + match->next->prev = NULL;
72078 + } else {
72079 + match->prev->next = match->next;
72080 + if (match->next != NULL)
72081 + match->next->prev = match->prev;
72082 + }
72083 + match->prev = NULL;
72084 + match->next = NULL;
72085 + match->nentry->inode = newinode;
72086 + match->nentry->device = newdevice;
72087 + match->nentry->deleted = 0;
72088 +
72089 + insert_inodev_entry(match);
72090 + }
72091 +
72092 + return;
72093 +}
72094 +
72095 +static void
72096 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
72097 +{
72098 + struct acl_subject_label *subj;
72099 + struct acl_role_label *role;
72100 + unsigned int x;
72101 +
72102 + FOR_EACH_ROLE_START(role)
72103 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
72104 +
72105 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
72106 + if ((subj->inode == ino) && (subj->device == dev)) {
72107 + subj->inode = ino;
72108 + subj->device = dev;
72109 + }
72110 + /* nested subjects aren't in the role's subj_hash table */
72111 + update_acl_obj_label(matchn->inode, matchn->device,
72112 + ino, dev, subj);
72113 + FOR_EACH_NESTED_SUBJECT_END(subj)
72114 + FOR_EACH_SUBJECT_START(role, subj, x)
72115 + update_acl_obj_label(matchn->inode, matchn->device,
72116 + ino, dev, subj);
72117 + FOR_EACH_SUBJECT_END(subj,x)
72118 + FOR_EACH_ROLE_END(role)
72119 +
72120 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
72121 +
72122 + return;
72123 +}
72124 +
72125 +static void
72126 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
72127 + const struct vfsmount *mnt)
72128 +{
72129 + ino_t ino = dentry->d_inode->i_ino;
72130 + dev_t dev = __get_dev(dentry);
72131 +
72132 + __do_handle_create(matchn, ino, dev);
72133 +
72134 + return;
72135 +}
72136 +
72137 +void
72138 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
72139 +{
72140 + struct name_entry *matchn;
72141 +
72142 + if (unlikely(!(gr_status & GR_READY)))
72143 + return;
72144 +
72145 + preempt_disable();
72146 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
72147 +
72148 + if (unlikely((unsigned long)matchn)) {
72149 + write_lock(&gr_inode_lock);
72150 + do_handle_create(matchn, dentry, mnt);
72151 + write_unlock(&gr_inode_lock);
72152 + }
72153 + preempt_enable();
72154 +
72155 + return;
72156 +}
72157 +
72158 +void
72159 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
72160 +{
72161 + struct name_entry *matchn;
72162 +
72163 + if (unlikely(!(gr_status & GR_READY)))
72164 + return;
72165 +
72166 + preempt_disable();
72167 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
72168 +
72169 + if (unlikely((unsigned long)matchn)) {
72170 + write_lock(&gr_inode_lock);
72171 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
72172 + write_unlock(&gr_inode_lock);
72173 + }
72174 + preempt_enable();
72175 +
72176 + return;
72177 +}
72178 +
72179 +void
72180 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
72181 + struct dentry *old_dentry,
72182 + struct dentry *new_dentry,
72183 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
72184 +{
72185 + struct name_entry *matchn;
72186 + struct name_entry *matchn2 = NULL;
72187 + struct inodev_entry *inodev;
72188 + struct inode *inode = new_dentry->d_inode;
72189 + ino_t old_ino = old_dentry->d_inode->i_ino;
72190 + dev_t old_dev = __get_dev(old_dentry);
72191 + unsigned int exchange = flags & RENAME_EXCHANGE;
72192 +
72193 + /* vfs_rename swaps the name and parent link for old_dentry and
72194 + new_dentry
72195 + at this point, old_dentry has the new name, parent link, and inode
72196 + for the renamed file
72197 + if a file is being replaced by a rename, new_dentry has the inode
72198 + and name for the replaced file
72199 + */
72200 +
72201 + if (unlikely(!(gr_status & GR_READY)))
72202 + return;
72203 +
72204 + preempt_disable();
72205 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
72206 +
72207 + /* exchange cases:
72208 + a filename exists for the source, but not dest
72209 + do a recreate on source
72210 + a filename exists for the dest, but not source
72211 + do a recreate on dest
72212 + a filename exists for both source and dest
72213 + delete source and dest, then create source and dest
72214 + a filename exists for neither source nor dest
72215 + no updates needed
72216 +
72217 + the name entry lookups get us the old inode/dev associated with
72218 + each name, so do the deletes first (if possible) so that when
72219 + we do the create, we pick up on the right entries
72220 + */
72221 +
72222 + if (exchange)
72223 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
72224 +
72225 + /* we wouldn't have to check d_inode if it weren't for
72226 + NFS silly-renaming
72227 + */
72228 +
72229 + write_lock(&gr_inode_lock);
72230 + if (unlikely((replace || exchange) && inode)) {
72231 + ino_t new_ino = inode->i_ino;
72232 + dev_t new_dev = __get_dev(new_dentry);
72233 +
72234 + inodev = lookup_inodev_entry(new_ino, new_dev);
72235 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
72236 + do_handle_delete(inodev, new_ino, new_dev);
72237 + }
72238 +
72239 + inodev = lookup_inodev_entry(old_ino, old_dev);
72240 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
72241 + do_handle_delete(inodev, old_ino, old_dev);
72242 +
72243 + if (unlikely(matchn != NULL))
72244 + do_handle_create(matchn, old_dentry, mnt);
72245 +
72246 + if (unlikely(matchn2 != NULL))
72247 + do_handle_create(matchn2, new_dentry, mnt);
72248 +
72249 + write_unlock(&gr_inode_lock);
72250 + preempt_enable();
72251 +
72252 + return;
72253 +}
72254 +
72255 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
72256 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
72257 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
72258 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
72259 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
72260 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
72261 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
72262 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
72263 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
72264 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
72265 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
72266 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
72267 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
72268 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
72269 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
72270 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
72271 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
72272 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
72273 +};
72274 +
72275 +void
72276 +gr_learn_resource(const struct task_struct *task,
72277 + const int res, const unsigned long wanted, const int gt)
72278 +{
72279 + struct acl_subject_label *acl;
72280 + const struct cred *cred;
72281 +
72282 + if (unlikely((gr_status & GR_READY) &&
72283 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
72284 + goto skip_reslog;
72285 +
72286 + gr_log_resource(task, res, wanted, gt);
72287 +skip_reslog:
72288 +
72289 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
72290 + return;
72291 +
72292 + acl = task->acl;
72293 +
72294 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
72295 + !(acl->resmask & (1U << (unsigned short) res))))
72296 + return;
72297 +
72298 + if (wanted >= acl->res[res].rlim_cur) {
72299 + unsigned long res_add;
72300 +
72301 + res_add = wanted + res_learn_bumps[res];
72302 +
72303 + acl->res[res].rlim_cur = res_add;
72304 +
72305 + if (wanted > acl->res[res].rlim_max)
72306 + acl->res[res].rlim_max = res_add;
72307 +
72308 + /* only log the subject filename, since resource logging is supported for
72309 + single-subject learning only */
72310 + rcu_read_lock();
72311 + cred = __task_cred(task);
72312 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72313 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
72314 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
72315 + "", (unsigned long) res, &task->signal->saved_ip);
72316 + rcu_read_unlock();
72317 + }
72318 +
72319 + return;
72320 +}
72321 +EXPORT_SYMBOL_GPL(gr_learn_resource);
72322 +#endif
72323 +
72324 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
72325 +void
72326 +pax_set_initial_flags(struct linux_binprm *bprm)
72327 +{
72328 + struct task_struct *task = current;
72329 + struct acl_subject_label *proc;
72330 + unsigned long flags;
72331 +
72332 + if (unlikely(!(gr_status & GR_READY)))
72333 + return;
72334 +
72335 + flags = pax_get_flags(task);
72336 +
72337 + proc = task->acl;
72338 +
72339 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
72340 + flags &= ~MF_PAX_PAGEEXEC;
72341 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
72342 + flags &= ~MF_PAX_SEGMEXEC;
72343 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
72344 + flags &= ~MF_PAX_RANDMMAP;
72345 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
72346 + flags &= ~MF_PAX_EMUTRAMP;
72347 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
72348 + flags &= ~MF_PAX_MPROTECT;
72349 +
72350 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
72351 + flags |= MF_PAX_PAGEEXEC;
72352 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
72353 + flags |= MF_PAX_SEGMEXEC;
72354 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
72355 + flags |= MF_PAX_RANDMMAP;
72356 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
72357 + flags |= MF_PAX_EMUTRAMP;
72358 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
72359 + flags |= MF_PAX_MPROTECT;
72360 +
72361 + pax_set_flags(task, flags);
72362 +
72363 + return;
72364 +}
72365 +#endif
72366 +
72367 +int
72368 +gr_handle_proc_ptrace(struct task_struct *task)
72369 +{
72370 + struct file *filp;
72371 + struct task_struct *tmp = task;
72372 + struct task_struct *curtemp = current;
72373 + __u32 retmode;
72374 +
72375 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72376 + if (unlikely(!(gr_status & GR_READY)))
72377 + return 0;
72378 +#endif
72379 +
72380 + read_lock(&tasklist_lock);
72381 + read_lock(&grsec_exec_file_lock);
72382 + filp = task->exec_file;
72383 +
72384 + while (task_pid_nr(tmp) > 0) {
72385 + if (tmp == curtemp)
72386 + break;
72387 + tmp = tmp->real_parent;
72388 + }
72389 +
72390 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72391 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
72392 + read_unlock(&grsec_exec_file_lock);
72393 + read_unlock(&tasklist_lock);
72394 + return 1;
72395 + }
72396 +
72397 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72398 + if (!(gr_status & GR_READY)) {
72399 + read_unlock(&grsec_exec_file_lock);
72400 + read_unlock(&tasklist_lock);
72401 + return 0;
72402 + }
72403 +#endif
72404 +
72405 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
72406 + read_unlock(&grsec_exec_file_lock);
72407 + read_unlock(&tasklist_lock);
72408 +
72409 + if (retmode & GR_NOPTRACE)
72410 + return 1;
72411 +
72412 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
72413 + && (current->acl != task->acl || (current->acl != current->role->root_label
72414 + && task_pid_nr(current) != task_pid_nr(task))))
72415 + return 1;
72416 +
72417 + return 0;
72418 +}
72419 +
72420 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
72421 +{
72422 + if (unlikely(!(gr_status & GR_READY)))
72423 + return;
72424 +
72425 + if (!(current->role->roletype & GR_ROLE_GOD))
72426 + return;
72427 +
72428 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
72429 + p->role->rolename, gr_task_roletype_to_char(p),
72430 + p->acl->filename);
72431 +}
72432 +
72433 +int
72434 +gr_handle_ptrace(struct task_struct *task, const long request)
72435 +{
72436 + struct task_struct *tmp = task;
72437 + struct task_struct *curtemp = current;
72438 + __u32 retmode;
72439 +
72440 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72441 + if (unlikely(!(gr_status & GR_READY)))
72442 + return 0;
72443 +#endif
72444 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72445 + read_lock(&tasklist_lock);
72446 + while (task_pid_nr(tmp) > 0) {
72447 + if (tmp == curtemp)
72448 + break;
72449 + tmp = tmp->real_parent;
72450 + }
72451 +
72452 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72453 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
72454 + read_unlock(&tasklist_lock);
72455 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72456 + return 1;
72457 + }
72458 + read_unlock(&tasklist_lock);
72459 + }
72460 +
72461 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72462 + if (!(gr_status & GR_READY))
72463 + return 0;
72464 +#endif
72465 +
72466 + read_lock(&grsec_exec_file_lock);
72467 + if (unlikely(!task->exec_file)) {
72468 + read_unlock(&grsec_exec_file_lock);
72469 + return 0;
72470 + }
72471 +
72472 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
72473 + read_unlock(&grsec_exec_file_lock);
72474 +
72475 + if (retmode & GR_NOPTRACE) {
72476 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72477 + return 1;
72478 + }
72479 +
72480 + if (retmode & GR_PTRACERD) {
72481 + switch (request) {
72482 + case PTRACE_SEIZE:
72483 + case PTRACE_POKETEXT:
72484 + case PTRACE_POKEDATA:
72485 + case PTRACE_POKEUSR:
72486 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
72487 + case PTRACE_SETREGS:
72488 + case PTRACE_SETFPREGS:
72489 +#endif
72490 +#ifdef CONFIG_X86
72491 + case PTRACE_SETFPXREGS:
72492 +#endif
72493 +#ifdef CONFIG_ALTIVEC
72494 + case PTRACE_SETVRREGS:
72495 +#endif
72496 + return 1;
72497 + default:
72498 + return 0;
72499 + }
72500 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
72501 + !(current->role->roletype & GR_ROLE_GOD) &&
72502 + (current->acl != task->acl)) {
72503 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72504 + return 1;
72505 + }
72506 +
72507 + return 0;
72508 +}
72509 +
72510 +static int is_writable_mmap(const struct file *filp)
72511 +{
72512 + struct task_struct *task = current;
72513 + struct acl_object_label *obj, *obj2;
72514 +
72515 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
72516 + !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode) && (filp->f_path.mnt != shm_mnt || (filp->f_path.dentry->d_inode->i_nlink > 0))) {
72517 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72518 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
72519 + task->role->root_label);
72520 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
72521 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
72522 + return 1;
72523 + }
72524 + }
72525 + return 0;
72526 +}
72527 +
72528 +int
72529 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
72530 +{
72531 + __u32 mode;
72532 +
72533 + if (unlikely(!file || !(prot & PROT_EXEC)))
72534 + return 1;
72535 +
72536 + if (is_writable_mmap(file))
72537 + return 0;
72538 +
72539 + mode =
72540 + gr_search_file(file->f_path.dentry,
72541 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72542 + file->f_path.mnt);
72543 +
72544 + if (!gr_tpe_allow(file))
72545 + return 0;
72546 +
72547 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72548 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72549 + return 0;
72550 + } else if (unlikely(!(mode & GR_EXEC))) {
72551 + return 0;
72552 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72553 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72554 + return 1;
72555 + }
72556 +
72557 + return 1;
72558 +}
72559 +
72560 +int
72561 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72562 +{
72563 + __u32 mode;
72564 +
72565 + if (unlikely(!file || !(prot & PROT_EXEC)))
72566 + return 1;
72567 +
72568 + if (is_writable_mmap(file))
72569 + return 0;
72570 +
72571 + mode =
72572 + gr_search_file(file->f_path.dentry,
72573 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72574 + file->f_path.mnt);
72575 +
72576 + if (!gr_tpe_allow(file))
72577 + return 0;
72578 +
72579 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72580 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72581 + return 0;
72582 + } else if (unlikely(!(mode & GR_EXEC))) {
72583 + return 0;
72584 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72585 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72586 + return 1;
72587 + }
72588 +
72589 + return 1;
72590 +}
72591 +
72592 +void
72593 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72594 +{
72595 + unsigned long runtime, cputime;
72596 + cputime_t utime, stime;
72597 + unsigned int wday, cday;
72598 + __u8 whr, chr;
72599 + __u8 wmin, cmin;
72600 + __u8 wsec, csec;
72601 + struct timespec timeval;
72602 +
72603 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72604 + !(task->acl->mode & GR_PROCACCT)))
72605 + return;
72606 +
72607 + do_posix_clock_monotonic_gettime(&timeval);
72608 + runtime = timeval.tv_sec - task->start_time.tv_sec;
72609 + wday = runtime / (60 * 60 * 24);
72610 + runtime -= wday * (60 * 60 * 24);
72611 + whr = runtime / (60 * 60);
72612 + runtime -= whr * (60 * 60);
72613 + wmin = runtime / 60;
72614 + runtime -= wmin * 60;
72615 + wsec = runtime;
72616 +
72617 + task_cputime(task, &utime, &stime);
72618 + cputime = cputime_to_secs(utime + stime);
72619 + cday = cputime / (60 * 60 * 24);
72620 + cputime -= cday * (60 * 60 * 24);
72621 + chr = cputime / (60 * 60);
72622 + cputime -= chr * (60 * 60);
72623 + cmin = cputime / 60;
72624 + cputime -= cmin * 60;
72625 + csec = cputime;
72626 +
72627 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72628 +
72629 + return;
72630 +}
72631 +
72632 +#ifdef CONFIG_TASKSTATS
72633 +int gr_is_taskstats_denied(int pid)
72634 +{
72635 + struct task_struct *task;
72636 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72637 + const struct cred *cred;
72638 +#endif
72639 + int ret = 0;
72640 +
72641 + /* restrict taskstats viewing to un-chrooted root users
72642 + who have the 'view' subject flag if the RBAC system is enabled
72643 + */
72644 +
72645 + rcu_read_lock();
72646 + read_lock(&tasklist_lock);
72647 + task = find_task_by_vpid(pid);
72648 + if (task) {
72649 +#ifdef CONFIG_GRKERNSEC_CHROOT
72650 + if (proc_is_chrooted(task))
72651 + ret = -EACCES;
72652 +#endif
72653 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72654 + cred = __task_cred(task);
72655 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72656 + if (gr_is_global_nonroot(cred->uid))
72657 + ret = -EACCES;
72658 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72659 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72660 + ret = -EACCES;
72661 +#endif
72662 +#endif
72663 + if (gr_status & GR_READY) {
72664 + if (!(task->acl->mode & GR_VIEW))
72665 + ret = -EACCES;
72666 + }
72667 + } else
72668 + ret = -ENOENT;
72669 +
72670 + read_unlock(&tasklist_lock);
72671 + rcu_read_unlock();
72672 +
72673 + return ret;
72674 +}
72675 +#endif
72676 +
72677 +/* AUXV entries are filled via a descendant of search_binary_handler
72678 + after we've already applied the subject for the target
72679 +*/
72680 +int gr_acl_enable_at_secure(void)
72681 +{
72682 + if (unlikely(!(gr_status & GR_READY)))
72683 + return 0;
72684 +
72685 + if (current->acl->mode & GR_ATSECURE)
72686 + return 1;
72687 +
72688 + return 0;
72689 +}
72690 +
72691 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72692 +{
72693 + struct task_struct *task = current;
72694 + struct dentry *dentry = file->f_path.dentry;
72695 + struct vfsmount *mnt = file->f_path.mnt;
72696 + struct acl_object_label *obj, *tmp;
72697 + struct acl_subject_label *subj;
72698 + unsigned int bufsize;
72699 + int is_not_root;
72700 + char *path;
72701 + dev_t dev = __get_dev(dentry);
72702 +
72703 + if (unlikely(!(gr_status & GR_READY)))
72704 + return 1;
72705 +
72706 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72707 + return 1;
72708 +
72709 + /* ignore Eric Biederman */
72710 + if (IS_PRIVATE(dentry->d_inode))
72711 + return 1;
72712 +
72713 + subj = task->acl;
72714 + read_lock(&gr_inode_lock);
72715 + do {
72716 + obj = lookup_acl_obj_label(ino, dev, subj);
72717 + if (obj != NULL) {
72718 + read_unlock(&gr_inode_lock);
72719 + return (obj->mode & GR_FIND) ? 1 : 0;
72720 + }
72721 + } while ((subj = subj->parent_subject));
72722 + read_unlock(&gr_inode_lock);
72723 +
72724 + /* this is purely an optimization since we're looking for an object
72725 + for the directory we're doing a readdir on
72726 + if it's possible for any globbed object to match the entry we're
72727 + filling into the directory, then the object we find here will be
72728 + an anchor point with attached globbed objects
72729 + */
72730 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72731 + if (obj->globbed == NULL)
72732 + return (obj->mode & GR_FIND) ? 1 : 0;
72733 +
72734 + is_not_root = ((obj->filename[0] == '/') &&
72735 + (obj->filename[1] == '\0')) ? 0 : 1;
72736 + bufsize = PAGE_SIZE - namelen - is_not_root;
72737 +
72738 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
72739 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72740 + return 1;
72741 +
72742 + preempt_disable();
72743 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72744 + bufsize);
72745 +
72746 + bufsize = strlen(path);
72747 +
72748 + /* if base is "/", don't append an additional slash */
72749 + if (is_not_root)
72750 + *(path + bufsize) = '/';
72751 + memcpy(path + bufsize + is_not_root, name, namelen);
72752 + *(path + bufsize + namelen + is_not_root) = '\0';
72753 +
72754 + tmp = obj->globbed;
72755 + while (tmp) {
72756 + if (!glob_match(tmp->filename, path)) {
72757 + preempt_enable();
72758 + return (tmp->mode & GR_FIND) ? 1 : 0;
72759 + }
72760 + tmp = tmp->next;
72761 + }
72762 + preempt_enable();
72763 + return (obj->mode & GR_FIND) ? 1 : 0;
72764 +}
72765 +
72766 +void gr_put_exec_file(struct task_struct *task)
72767 +{
72768 + struct file *filp;
72769 +
72770 + write_lock(&grsec_exec_file_lock);
72771 + filp = task->exec_file;
72772 + task->exec_file = NULL;
72773 + write_unlock(&grsec_exec_file_lock);
72774 +
72775 + if (filp)
72776 + fput(filp);
72777 +
72778 + return;
72779 +}
72780 +
72781 +
72782 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72783 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72784 +#endif
72785 +#ifdef CONFIG_SECURITY
72786 +EXPORT_SYMBOL_GPL(gr_check_user_change);
72787 +EXPORT_SYMBOL_GPL(gr_check_group_change);
72788 +#endif
72789 +
72790 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72791 new file mode 100644
72792 index 0000000..18ffbbd
72793 --- /dev/null
72794 +++ b/grsecurity/gracl_alloc.c
72795 @@ -0,0 +1,105 @@
72796 +#include <linux/kernel.h>
72797 +#include <linux/mm.h>
72798 +#include <linux/slab.h>
72799 +#include <linux/vmalloc.h>
72800 +#include <linux/gracl.h>
72801 +#include <linux/grsecurity.h>
72802 +
72803 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72804 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72805 +
72806 +static __inline__ int
72807 +alloc_pop(void)
72808 +{
72809 + if (current_alloc_state->alloc_stack_next == 1)
72810 + return 0;
72811 +
72812 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72813 +
72814 + current_alloc_state->alloc_stack_next--;
72815 +
72816 + return 1;
72817 +}
72818 +
72819 +static __inline__ int
72820 +alloc_push(void *buf)
72821 +{
72822 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72823 + return 1;
72824 +
72825 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72826 +
72827 + current_alloc_state->alloc_stack_next++;
72828 +
72829 + return 0;
72830 +}
72831 +
72832 +void *
72833 +acl_alloc(unsigned long len)
72834 +{
72835 + void *ret = NULL;
72836 +
72837 + if (!len || len > PAGE_SIZE)
72838 + goto out;
72839 +
72840 + ret = kmalloc(len, GFP_KERNEL);
72841 +
72842 + if (ret) {
72843 + if (alloc_push(ret)) {
72844 + kfree(ret);
72845 + ret = NULL;
72846 + }
72847 + }
72848 +
72849 +out:
72850 + return ret;
72851 +}
72852 +
72853 +void *
72854 +acl_alloc_num(unsigned long num, unsigned long len)
72855 +{
72856 + if (!len || (num > (PAGE_SIZE / len)))
72857 + return NULL;
72858 +
72859 + return acl_alloc(num * len);
72860 +}
72861 +
72862 +void
72863 +acl_free_all(void)
72864 +{
72865 + if (!current_alloc_state->alloc_stack)
72866 + return;
72867 +
72868 + while (alloc_pop()) ;
72869 +
72870 + if (current_alloc_state->alloc_stack) {
72871 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72872 + kfree(current_alloc_state->alloc_stack);
72873 + else
72874 + vfree(current_alloc_state->alloc_stack);
72875 + }
72876 +
72877 + current_alloc_state->alloc_stack = NULL;
72878 + current_alloc_state->alloc_stack_size = 1;
72879 + current_alloc_state->alloc_stack_next = 1;
72880 +
72881 + return;
72882 +}
72883 +
72884 +int
72885 +acl_alloc_stack_init(unsigned long size)
72886 +{
72887 + if ((size * sizeof (void *)) <= PAGE_SIZE)
72888 + current_alloc_state->alloc_stack =
72889 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72890 + else
72891 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72892 +
72893 + current_alloc_state->alloc_stack_size = size;
72894 + current_alloc_state->alloc_stack_next = 1;
72895 +
72896 + if (!current_alloc_state->alloc_stack)
72897 + return 0;
72898 + else
72899 + return 1;
72900 +}
72901 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72902 new file mode 100644
72903 index 0000000..1a94c11
72904 --- /dev/null
72905 +++ b/grsecurity/gracl_cap.c
72906 @@ -0,0 +1,127 @@
72907 +#include <linux/kernel.h>
72908 +#include <linux/module.h>
72909 +#include <linux/sched.h>
72910 +#include <linux/gracl.h>
72911 +#include <linux/grsecurity.h>
72912 +#include <linux/grinternal.h>
72913 +
72914 +extern const char *captab_log[];
72915 +extern int captab_log_entries;
72916 +
72917 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72918 +{
72919 + struct acl_subject_label *curracl;
72920 +
72921 + if (!gr_acl_is_enabled())
72922 + return 1;
72923 +
72924 + curracl = task->acl;
72925 +
72926 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72927 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72928 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
72929 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
72930 + gr_to_filename(task->exec_file->f_path.dentry,
72931 + task->exec_file->f_path.mnt) : curracl->filename,
72932 + curracl->filename, 0UL,
72933 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72934 + return 1;
72935 + }
72936 +
72937 + return 0;
72938 +}
72939 +
72940 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72941 +{
72942 + struct acl_subject_label *curracl;
72943 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72944 + kernel_cap_t cap_audit = __cap_empty_set;
72945 +
72946 + if (!gr_acl_is_enabled())
72947 + return 1;
72948 +
72949 + curracl = task->acl;
72950 +
72951 + cap_drop = curracl->cap_lower;
72952 + cap_mask = curracl->cap_mask;
72953 + cap_audit = curracl->cap_invert_audit;
72954 +
72955 + while ((curracl = curracl->parent_subject)) {
72956 + /* if the cap isn't specified in the current computed mask but is specified in the
72957 + current level subject, and is lowered in the current level subject, then add
72958 + it to the set of dropped capabilities
72959 + otherwise, add the current level subject's mask to the current computed mask
72960 + */
72961 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72962 + cap_raise(cap_mask, cap);
72963 + if (cap_raised(curracl->cap_lower, cap))
72964 + cap_raise(cap_drop, cap);
72965 + if (cap_raised(curracl->cap_invert_audit, cap))
72966 + cap_raise(cap_audit, cap);
72967 + }
72968 + }
72969 +
72970 + if (!cap_raised(cap_drop, cap)) {
72971 + if (cap_raised(cap_audit, cap))
72972 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72973 + return 1;
72974 + }
72975 +
72976 + /* only learn the capability use if the process has the capability in the
72977 + general case, the two uses in sys.c of gr_learn_cap are an exception
72978 + to this rule to ensure any role transition involves what the full-learned
72979 + policy believes in a privileged process
72980 + */
72981 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72982 + return 1;
72983 +
72984 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72985 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72986 +
72987 + return 0;
72988 +}
72989 +
72990 +int
72991 +gr_acl_is_capable(const int cap)
72992 +{
72993 + return gr_task_acl_is_capable(current, current_cred(), cap);
72994 +}
72995 +
72996 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72997 +{
72998 + struct acl_subject_label *curracl;
72999 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
73000 +
73001 + if (!gr_acl_is_enabled())
73002 + return 1;
73003 +
73004 + curracl = task->acl;
73005 +
73006 + cap_drop = curracl->cap_lower;
73007 + cap_mask = curracl->cap_mask;
73008 +
73009 + while ((curracl = curracl->parent_subject)) {
73010 + /* if the cap isn't specified in the current computed mask but is specified in the
73011 + current level subject, and is lowered in the current level subject, then add
73012 + it to the set of dropped capabilities
73013 + otherwise, add the current level subject's mask to the current computed mask
73014 + */
73015 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
73016 + cap_raise(cap_mask, cap);
73017 + if (cap_raised(curracl->cap_lower, cap))
73018 + cap_raise(cap_drop, cap);
73019 + }
73020 + }
73021 +
73022 + if (!cap_raised(cap_drop, cap))
73023 + return 1;
73024 +
73025 + return 0;
73026 +}
73027 +
73028 +int
73029 +gr_acl_is_capable_nolog(const int cap)
73030 +{
73031 + return gr_task_acl_is_capable_nolog(current, cap);
73032 +}
73033 +
73034 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
73035 new file mode 100644
73036 index 0000000..ca25605
73037 --- /dev/null
73038 +++ b/grsecurity/gracl_compat.c
73039 @@ -0,0 +1,270 @@
73040 +#include <linux/kernel.h>
73041 +#include <linux/gracl.h>
73042 +#include <linux/compat.h>
73043 +#include <linux/gracl_compat.h>
73044 +
73045 +#include <asm/uaccess.h>
73046 +
73047 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
73048 +{
73049 + struct gr_arg_wrapper_compat uwrapcompat;
73050 +
73051 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
73052 + return -EFAULT;
73053 +
73054 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
73055 + (uwrapcompat.version != 0x2901)) ||
73056 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
73057 + return -EINVAL;
73058 +
73059 + uwrap->arg = compat_ptr(uwrapcompat.arg);
73060 + uwrap->version = uwrapcompat.version;
73061 + uwrap->size = sizeof(struct gr_arg);
73062 +
73063 + return 0;
73064 +}
73065 +
73066 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
73067 +{
73068 + struct gr_arg_compat argcompat;
73069 +
73070 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
73071 + return -EFAULT;
73072 +
73073 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
73074 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
73075 + arg->role_db.num_roles = argcompat.role_db.num_roles;
73076 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
73077 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
73078 + arg->role_db.num_objects = argcompat.role_db.num_objects;
73079 +
73080 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
73081 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
73082 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
73083 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
73084 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
73085 + arg->segv_device = argcompat.segv_device;
73086 + arg->segv_inode = argcompat.segv_inode;
73087 + arg->segv_uid = argcompat.segv_uid;
73088 + arg->num_sprole_pws = argcompat.num_sprole_pws;
73089 + arg->mode = argcompat.mode;
73090 +
73091 + return 0;
73092 +}
73093 +
73094 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
73095 +{
73096 + struct acl_object_label_compat objcompat;
73097 +
73098 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
73099 + return -EFAULT;
73100 +
73101 + obj->filename = compat_ptr(objcompat.filename);
73102 + obj->inode = objcompat.inode;
73103 + obj->device = objcompat.device;
73104 + obj->mode = objcompat.mode;
73105 +
73106 + obj->nested = compat_ptr(objcompat.nested);
73107 + obj->globbed = compat_ptr(objcompat.globbed);
73108 +
73109 + obj->prev = compat_ptr(objcompat.prev);
73110 + obj->next = compat_ptr(objcompat.next);
73111 +
73112 + return 0;
73113 +}
73114 +
73115 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73116 +{
73117 + unsigned int i;
73118 + struct acl_subject_label_compat subjcompat;
73119 +
73120 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
73121 + return -EFAULT;
73122 +
73123 + subj->filename = compat_ptr(subjcompat.filename);
73124 + subj->inode = subjcompat.inode;
73125 + subj->device = subjcompat.device;
73126 + subj->mode = subjcompat.mode;
73127 + subj->cap_mask = subjcompat.cap_mask;
73128 + subj->cap_lower = subjcompat.cap_lower;
73129 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
73130 +
73131 + for (i = 0; i < GR_NLIMITS; i++) {
73132 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
73133 + subj->res[i].rlim_cur = RLIM_INFINITY;
73134 + else
73135 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
73136 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
73137 + subj->res[i].rlim_max = RLIM_INFINITY;
73138 + else
73139 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
73140 + }
73141 + subj->resmask = subjcompat.resmask;
73142 +
73143 + subj->user_trans_type = subjcompat.user_trans_type;
73144 + subj->group_trans_type = subjcompat.group_trans_type;
73145 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
73146 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
73147 + subj->user_trans_num = subjcompat.user_trans_num;
73148 + subj->group_trans_num = subjcompat.group_trans_num;
73149 +
73150 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
73151 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
73152 + subj->ip_type = subjcompat.ip_type;
73153 + subj->ips = compat_ptr(subjcompat.ips);
73154 + subj->ip_num = subjcompat.ip_num;
73155 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
73156 +
73157 + subj->crashes = subjcompat.crashes;
73158 + subj->expires = subjcompat.expires;
73159 +
73160 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
73161 + subj->hash = compat_ptr(subjcompat.hash);
73162 + subj->prev = compat_ptr(subjcompat.prev);
73163 + subj->next = compat_ptr(subjcompat.next);
73164 +
73165 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
73166 + subj->obj_hash_size = subjcompat.obj_hash_size;
73167 + subj->pax_flags = subjcompat.pax_flags;
73168 +
73169 + return 0;
73170 +}
73171 +
73172 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
73173 +{
73174 + struct acl_role_label_compat rolecompat;
73175 +
73176 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
73177 + return -EFAULT;
73178 +
73179 + role->rolename = compat_ptr(rolecompat.rolename);
73180 + role->uidgid = rolecompat.uidgid;
73181 + role->roletype = rolecompat.roletype;
73182 +
73183 + role->auth_attempts = rolecompat.auth_attempts;
73184 + role->expires = rolecompat.expires;
73185 +
73186 + role->root_label = compat_ptr(rolecompat.root_label);
73187 + role->hash = compat_ptr(rolecompat.hash);
73188 +
73189 + role->prev = compat_ptr(rolecompat.prev);
73190 + role->next = compat_ptr(rolecompat.next);
73191 +
73192 + role->transitions = compat_ptr(rolecompat.transitions);
73193 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
73194 + role->domain_children = compat_ptr(rolecompat.domain_children);
73195 + role->domain_child_num = rolecompat.domain_child_num;
73196 +
73197 + role->umask = rolecompat.umask;
73198 +
73199 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
73200 + role->subj_hash_size = rolecompat.subj_hash_size;
73201 +
73202 + return 0;
73203 +}
73204 +
73205 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73206 +{
73207 + struct role_allowed_ip_compat roleip_compat;
73208 +
73209 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
73210 + return -EFAULT;
73211 +
73212 + roleip->addr = roleip_compat.addr;
73213 + roleip->netmask = roleip_compat.netmask;
73214 +
73215 + roleip->prev = compat_ptr(roleip_compat.prev);
73216 + roleip->next = compat_ptr(roleip_compat.next);
73217 +
73218 + return 0;
73219 +}
73220 +
73221 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
73222 +{
73223 + struct role_transition_compat trans_compat;
73224 +
73225 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
73226 + return -EFAULT;
73227 +
73228 + trans->rolename = compat_ptr(trans_compat.rolename);
73229 +
73230 + trans->prev = compat_ptr(trans_compat.prev);
73231 + trans->next = compat_ptr(trans_compat.next);
73232 +
73233 + return 0;
73234 +
73235 +}
73236 +
73237 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73238 +{
73239 + struct gr_hash_struct_compat hash_compat;
73240 +
73241 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
73242 + return -EFAULT;
73243 +
73244 + hash->table = compat_ptr(hash_compat.table);
73245 + hash->nametable = compat_ptr(hash_compat.nametable);
73246 + hash->first = compat_ptr(hash_compat.first);
73247 +
73248 + hash->table_size = hash_compat.table_size;
73249 + hash->used_size = hash_compat.used_size;
73250 +
73251 + hash->type = hash_compat.type;
73252 +
73253 + return 0;
73254 +}
73255 +
73256 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
73257 +{
73258 + compat_uptr_t ptrcompat;
73259 +
73260 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
73261 + return -EFAULT;
73262 +
73263 + *(void **)ptr = compat_ptr(ptrcompat);
73264 +
73265 + return 0;
73266 +}
73267 +
73268 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73269 +{
73270 + struct acl_ip_label_compat ip_compat;
73271 +
73272 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
73273 + return -EFAULT;
73274 +
73275 + ip->iface = compat_ptr(ip_compat.iface);
73276 + ip->addr = ip_compat.addr;
73277 + ip->netmask = ip_compat.netmask;
73278 + ip->low = ip_compat.low;
73279 + ip->high = ip_compat.high;
73280 + ip->mode = ip_compat.mode;
73281 + ip->type = ip_compat.type;
73282 +
73283 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
73284 +
73285 + ip->prev = compat_ptr(ip_compat.prev);
73286 + ip->next = compat_ptr(ip_compat.next);
73287 +
73288 + return 0;
73289 +}
73290 +
73291 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73292 +{
73293 + struct sprole_pw_compat pw_compat;
73294 +
73295 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
73296 + return -EFAULT;
73297 +
73298 + pw->rolename = compat_ptr(pw_compat.rolename);
73299 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
73300 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
73301 +
73302 + return 0;
73303 +}
73304 +
73305 +size_t get_gr_arg_wrapper_size_compat(void)
73306 +{
73307 + return sizeof(struct gr_arg_wrapper_compat);
73308 +}
73309 +
73310 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
73311 new file mode 100644
73312 index 0000000..4008fdc
73313 --- /dev/null
73314 +++ b/grsecurity/gracl_fs.c
73315 @@ -0,0 +1,445 @@
73316 +#include <linux/kernel.h>
73317 +#include <linux/sched.h>
73318 +#include <linux/types.h>
73319 +#include <linux/fs.h>
73320 +#include <linux/file.h>
73321 +#include <linux/stat.h>
73322 +#include <linux/grsecurity.h>
73323 +#include <linux/grinternal.h>
73324 +#include <linux/gracl.h>
73325 +
73326 +umode_t
73327 +gr_acl_umask(void)
73328 +{
73329 + if (unlikely(!gr_acl_is_enabled()))
73330 + return 0;
73331 +
73332 + return current->role->umask;
73333 +}
73334 +
73335 +__u32
73336 +gr_acl_handle_hidden_file(const struct dentry * dentry,
73337 + const struct vfsmount * mnt)
73338 +{
73339 + __u32 mode;
73340 +
73341 + if (unlikely(d_is_negative(dentry)))
73342 + return GR_FIND;
73343 +
73344 + mode =
73345 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
73346 +
73347 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
73348 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73349 + return mode;
73350 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
73351 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73352 + return 0;
73353 + } else if (unlikely(!(mode & GR_FIND)))
73354 + return 0;
73355 +
73356 + return GR_FIND;
73357 +}
73358 +
73359 +__u32
73360 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73361 + int acc_mode)
73362 +{
73363 + __u32 reqmode = GR_FIND;
73364 + __u32 mode;
73365 +
73366 + if (unlikely(d_is_negative(dentry)))
73367 + return reqmode;
73368 +
73369 + if (acc_mode & MAY_APPEND)
73370 + reqmode |= GR_APPEND;
73371 + else if (acc_mode & MAY_WRITE)
73372 + reqmode |= GR_WRITE;
73373 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
73374 + reqmode |= GR_READ;
73375 +
73376 + mode =
73377 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73378 + mnt);
73379 +
73380 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73381 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73382 + reqmode & GR_READ ? " reading" : "",
73383 + reqmode & GR_WRITE ? " writing" : reqmode &
73384 + GR_APPEND ? " appending" : "");
73385 + return reqmode;
73386 + } else
73387 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73388 + {
73389 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73390 + reqmode & GR_READ ? " reading" : "",
73391 + reqmode & GR_WRITE ? " writing" : reqmode &
73392 + GR_APPEND ? " appending" : "");
73393 + return 0;
73394 + } else if (unlikely((mode & reqmode) != reqmode))
73395 + return 0;
73396 +
73397 + return reqmode;
73398 +}
73399 +
73400 +__u32
73401 +gr_acl_handle_creat(const struct dentry * dentry,
73402 + const struct dentry * p_dentry,
73403 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73404 + const int imode)
73405 +{
73406 + __u32 reqmode = GR_WRITE | GR_CREATE;
73407 + __u32 mode;
73408 +
73409 + if (acc_mode & MAY_APPEND)
73410 + reqmode |= GR_APPEND;
73411 + // if a directory was required or the directory already exists, then
73412 + // don't count this open as a read
73413 + if ((acc_mode & MAY_READ) &&
73414 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
73415 + reqmode |= GR_READ;
73416 + if ((open_flags & O_CREAT) &&
73417 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73418 + reqmode |= GR_SETID;
73419 +
73420 + mode =
73421 + gr_check_create(dentry, p_dentry, p_mnt,
73422 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73423 +
73424 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73425 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73426 + reqmode & GR_READ ? " reading" : "",
73427 + reqmode & GR_WRITE ? " writing" : reqmode &
73428 + GR_APPEND ? " appending" : "");
73429 + return reqmode;
73430 + } else
73431 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73432 + {
73433 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73434 + reqmode & GR_READ ? " reading" : "",
73435 + reqmode & GR_WRITE ? " writing" : reqmode &
73436 + GR_APPEND ? " appending" : "");
73437 + return 0;
73438 + } else if (unlikely((mode & reqmode) != reqmode))
73439 + return 0;
73440 +
73441 + return reqmode;
73442 +}
73443 +
73444 +__u32
73445 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
73446 + const int fmode)
73447 +{
73448 + __u32 mode, reqmode = GR_FIND;
73449 +
73450 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
73451 + reqmode |= GR_EXEC;
73452 + if (fmode & S_IWOTH)
73453 + reqmode |= GR_WRITE;
73454 + if (fmode & S_IROTH)
73455 + reqmode |= GR_READ;
73456 +
73457 + mode =
73458 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73459 + mnt);
73460 +
73461 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73462 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73463 + reqmode & GR_READ ? " reading" : "",
73464 + reqmode & GR_WRITE ? " writing" : "",
73465 + reqmode & GR_EXEC ? " executing" : "");
73466 + return reqmode;
73467 + } else
73468 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73469 + {
73470 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73471 + reqmode & GR_READ ? " reading" : "",
73472 + reqmode & GR_WRITE ? " writing" : "",
73473 + reqmode & GR_EXEC ? " executing" : "");
73474 + return 0;
73475 + } else if (unlikely((mode & reqmode) != reqmode))
73476 + return 0;
73477 +
73478 + return reqmode;
73479 +}
73480 +
73481 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
73482 +{
73483 + __u32 mode;
73484 +
73485 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
73486 +
73487 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73488 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
73489 + return mode;
73490 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73491 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
73492 + return 0;
73493 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73494 + return 0;
73495 +
73496 + return (reqmode);
73497 +}
73498 +
73499 +__u32
73500 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73501 +{
73502 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
73503 +}
73504 +
73505 +__u32
73506 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
73507 +{
73508 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
73509 +}
73510 +
73511 +__u32
73512 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
73513 +{
73514 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
73515 +}
73516 +
73517 +__u32
73518 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
73519 +{
73520 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
73521 +}
73522 +
73523 +__u32
73524 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
73525 + umode_t *modeptr)
73526 +{
73527 + umode_t mode;
73528 +
73529 + *modeptr &= ~gr_acl_umask();
73530 + mode = *modeptr;
73531 +
73532 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
73533 + return 1;
73534 +
73535 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
73536 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
73537 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
73538 + GR_CHMOD_ACL_MSG);
73539 + } else {
73540 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
73541 + }
73542 +}
73543 +
73544 +__u32
73545 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
73546 +{
73547 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
73548 +}
73549 +
73550 +__u32
73551 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
73552 +{
73553 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
73554 +}
73555 +
73556 +__u32
73557 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
73558 +{
73559 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
73560 +}
73561 +
73562 +__u32
73563 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
73564 +{
73565 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73566 +}
73567 +
73568 +__u32
73569 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73570 +{
73571 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73572 + GR_UNIXCONNECT_ACL_MSG);
73573 +}
73574 +
73575 +/* hardlinks require at minimum create and link permission,
73576 + any additional privilege required is based on the
73577 + privilege of the file being linked to
73578 +*/
73579 +__u32
73580 +gr_acl_handle_link(const struct dentry * new_dentry,
73581 + const struct dentry * parent_dentry,
73582 + const struct vfsmount * parent_mnt,
73583 + const struct dentry * old_dentry,
73584 + const struct vfsmount * old_mnt, const struct filename *to)
73585 +{
73586 + __u32 mode;
73587 + __u32 needmode = GR_CREATE | GR_LINK;
73588 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73589 +
73590 + mode =
73591 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73592 + old_mnt);
73593 +
73594 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73595 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73596 + return mode;
73597 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73598 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73599 + return 0;
73600 + } else if (unlikely((mode & needmode) != needmode))
73601 + return 0;
73602 +
73603 + return 1;
73604 +}
73605 +
73606 +__u32
73607 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73608 + const struct dentry * parent_dentry,
73609 + const struct vfsmount * parent_mnt, const struct filename *from)
73610 +{
73611 + __u32 needmode = GR_WRITE | GR_CREATE;
73612 + __u32 mode;
73613 +
73614 + mode =
73615 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
73616 + GR_CREATE | GR_AUDIT_CREATE |
73617 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73618 +
73619 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73620 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73621 + return mode;
73622 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73623 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73624 + return 0;
73625 + } else if (unlikely((mode & needmode) != needmode))
73626 + return 0;
73627 +
73628 + return (GR_WRITE | GR_CREATE);
73629 +}
73630 +
73631 +static __u32 generic_fs_create_handler(const struct dentry *new_dentry, const struct dentry *parent_dentry, const struct vfsmount *parent_mnt, __u32 reqmode, const char *fmt)
73632 +{
73633 + __u32 mode;
73634 +
73635 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73636 +
73637 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73638 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73639 + return mode;
73640 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73641 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73642 + return 0;
73643 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73644 + return 0;
73645 +
73646 + return (reqmode);
73647 +}
73648 +
73649 +__u32
73650 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73651 + const struct dentry * parent_dentry,
73652 + const struct vfsmount * parent_mnt,
73653 + const int mode)
73654 +{
73655 + __u32 reqmode = GR_WRITE | GR_CREATE;
73656 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73657 + reqmode |= GR_SETID;
73658 +
73659 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73660 + reqmode, GR_MKNOD_ACL_MSG);
73661 +}
73662 +
73663 +__u32
73664 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
73665 + const struct dentry *parent_dentry,
73666 + const struct vfsmount *parent_mnt)
73667 +{
73668 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73669 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73670 +}
73671 +
73672 +#define RENAME_CHECK_SUCCESS(old, new) \
73673 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73674 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73675 +
73676 +int
73677 +gr_acl_handle_rename(struct dentry *new_dentry,
73678 + struct dentry *parent_dentry,
73679 + const struct vfsmount *parent_mnt,
73680 + struct dentry *old_dentry,
73681 + struct inode *old_parent_inode,
73682 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73683 +{
73684 + __u32 comp1, comp2;
73685 + int error = 0;
73686 +
73687 + if (unlikely(!gr_acl_is_enabled()))
73688 + return 0;
73689 +
73690 + if (flags & RENAME_EXCHANGE) {
73691 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73692 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73693 + GR_SUPPRESS, parent_mnt);
73694 + comp2 =
73695 + gr_search_file(old_dentry,
73696 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73697 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73698 + } else if (d_is_negative(new_dentry)) {
73699 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73700 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73701 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73702 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73703 + GR_DELETE | GR_AUDIT_DELETE |
73704 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73705 + GR_SUPPRESS, old_mnt);
73706 + } else {
73707 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73708 + GR_CREATE | GR_DELETE |
73709 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73710 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73711 + GR_SUPPRESS, parent_mnt);
73712 + comp2 =
73713 + gr_search_file(old_dentry,
73714 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73715 + GR_DELETE | GR_AUDIT_DELETE |
73716 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73717 + }
73718 +
73719 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73720 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73721 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73722 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73723 + && !(comp2 & GR_SUPPRESS)) {
73724 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73725 + error = -EACCES;
73726 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73727 + error = -EACCES;
73728 +
73729 + return error;
73730 +}
73731 +
73732 +void
73733 +gr_acl_handle_exit(void)
73734 +{
73735 + u16 id;
73736 + char *rolename;
73737 +
73738 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73739 + !(current->role->roletype & GR_ROLE_PERSIST))) {
73740 + id = current->acl_role_id;
73741 + rolename = current->role->rolename;
73742 + gr_set_acls(1);
73743 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73744 + }
73745 +
73746 + gr_put_exec_file(current);
73747 + return;
73748 +}
73749 +
73750 +int
73751 +gr_acl_handle_procpidmem(const struct task_struct *task)
73752 +{
73753 + if (unlikely(!gr_acl_is_enabled()))
73754 + return 0;
73755 +
73756 + if (task != current && task->acl->mode & GR_PROTPROCFD)
73757 + return -EACCES;
73758 +
73759 + return 0;
73760 +}
73761 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73762 new file mode 100644
73763 index 0000000..f056b81
73764 --- /dev/null
73765 +++ b/grsecurity/gracl_ip.c
73766 @@ -0,0 +1,386 @@
73767 +#include <linux/kernel.h>
73768 +#include <asm/uaccess.h>
73769 +#include <asm/errno.h>
73770 +#include <net/sock.h>
73771 +#include <linux/file.h>
73772 +#include <linux/fs.h>
73773 +#include <linux/net.h>
73774 +#include <linux/in.h>
73775 +#include <linux/skbuff.h>
73776 +#include <linux/ip.h>
73777 +#include <linux/udp.h>
73778 +#include <linux/types.h>
73779 +#include <linux/sched.h>
73780 +#include <linux/netdevice.h>
73781 +#include <linux/inetdevice.h>
73782 +#include <linux/gracl.h>
73783 +#include <linux/grsecurity.h>
73784 +#include <linux/grinternal.h>
73785 +
73786 +#define GR_BIND 0x01
73787 +#define GR_CONNECT 0x02
73788 +#define GR_INVERT 0x04
73789 +#define GR_BINDOVERRIDE 0x08
73790 +#define GR_CONNECTOVERRIDE 0x10
73791 +#define GR_SOCK_FAMILY 0x20
73792 +
73793 +static const char * gr_protocols[IPPROTO_MAX] = {
73794 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73795 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73796 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73797 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73798 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73799 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73800 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73801 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73802 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73803 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73804 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73805 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73806 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73807 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73808 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73809 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73810 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73811 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73812 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73813 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73814 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73815 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73816 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73817 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73818 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73819 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73820 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73821 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73822 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73823 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73824 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73825 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73826 + };
73827 +
73828 +static const char * gr_socktypes[SOCK_MAX] = {
73829 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73830 + "unknown:7", "unknown:8", "unknown:9", "packet"
73831 + };
73832 +
73833 +static const char * gr_sockfamilies[AF_MAX+1] = {
73834 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73835 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73836 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73837 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73838 + };
73839 +
73840 +const char *
73841 +gr_proto_to_name(unsigned char proto)
73842 +{
73843 + return gr_protocols[proto];
73844 +}
73845 +
73846 +const char *
73847 +gr_socktype_to_name(unsigned char type)
73848 +{
73849 + return gr_socktypes[type];
73850 +}
73851 +
73852 +const char *
73853 +gr_sockfamily_to_name(unsigned char family)
73854 +{
73855 + return gr_sockfamilies[family];
73856 +}
73857 +
73858 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73859 +
73860 +int
73861 +gr_search_socket(const int domain, const int type, const int protocol)
73862 +{
73863 + struct acl_subject_label *curr;
73864 + const struct cred *cred = current_cred();
73865 +
73866 + if (unlikely(!gr_acl_is_enabled()))
73867 + goto exit;
73868 +
73869 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
73870 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73871 + goto exit; // let the kernel handle it
73872 +
73873 + curr = current->acl;
73874 +
73875 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73876 + /* the family is allowed, if this is PF_INET allow it only if
73877 + the extra sock type/protocol checks pass */
73878 + if (domain == PF_INET)
73879 + goto inet_check;
73880 + goto exit;
73881 + } else {
73882 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73883 + __u32 fakeip = 0;
73884 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73885 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73886 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73887 + gr_to_filename(current->exec_file->f_path.dentry,
73888 + current->exec_file->f_path.mnt) :
73889 + curr->filename, curr->filename,
73890 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73891 + &current->signal->saved_ip);
73892 + goto exit;
73893 + }
73894 + goto exit_fail;
73895 + }
73896 +
73897 +inet_check:
73898 + /* the rest of this checking is for IPv4 only */
73899 + if (!curr->ips)
73900 + goto exit;
73901 +
73902 + if ((curr->ip_type & (1U << type)) &&
73903 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73904 + goto exit;
73905 +
73906 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73907 + /* we don't place acls on raw sockets , and sometimes
73908 + dgram/ip sockets are opened for ioctl and not
73909 + bind/connect, so we'll fake a bind learn log */
73910 + if (type == SOCK_RAW || type == SOCK_PACKET) {
73911 + __u32 fakeip = 0;
73912 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73913 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73914 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73915 + gr_to_filename(current->exec_file->f_path.dentry,
73916 + current->exec_file->f_path.mnt) :
73917 + curr->filename, curr->filename,
73918 + &fakeip, 0, type,
73919 + protocol, GR_CONNECT, &current->signal->saved_ip);
73920 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73921 + __u32 fakeip = 0;
73922 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73923 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73924 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73925 + gr_to_filename(current->exec_file->f_path.dentry,
73926 + current->exec_file->f_path.mnt) :
73927 + curr->filename, curr->filename,
73928 + &fakeip, 0, type,
73929 + protocol, GR_BIND, &current->signal->saved_ip);
73930 + }
73931 + /* we'll log when they use connect or bind */
73932 + goto exit;
73933 + }
73934 +
73935 +exit_fail:
73936 + if (domain == PF_INET)
73937 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73938 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
73939 + else if (rcu_access_pointer(net_families[domain]) != NULL)
73940 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73941 + gr_socktype_to_name(type), protocol);
73942 +
73943 + return 0;
73944 +exit:
73945 + return 1;
73946 +}
73947 +
73948 +int check_ip_policy(struct acl_ip_label *ip, __u32 ip_addr, __u16 ip_port, __u8 protocol, const int mode, const int type, __u32 our_addr, __u32 our_netmask)
73949 +{
73950 + if ((ip->mode & mode) &&
73951 + (ip_port >= ip->low) &&
73952 + (ip_port <= ip->high) &&
73953 + ((ntohl(ip_addr) & our_netmask) ==
73954 + (ntohl(our_addr) & our_netmask))
73955 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73956 + && (ip->type & (1U << type))) {
73957 + if (ip->mode & GR_INVERT)
73958 + return 2; // specifically denied
73959 + else
73960 + return 1; // allowed
73961 + }
73962 +
73963 + return 0; // not specifically allowed, may continue parsing
73964 +}
73965 +
73966 +static int
73967 +gr_search_connectbind(const int full_mode, struct sock *sk,
73968 + struct sockaddr_in *addr, const int type)
73969 +{
73970 + char iface[IFNAMSIZ] = {0};
73971 + struct acl_subject_label *curr;
73972 + struct acl_ip_label *ip;
73973 + struct inet_sock *isk;
73974 + struct net_device *dev;
73975 + struct in_device *idev;
73976 + unsigned long i;
73977 + int ret;
73978 + int mode = full_mode & (GR_BIND | GR_CONNECT);
73979 + __u32 ip_addr = 0;
73980 + __u32 our_addr;
73981 + __u32 our_netmask;
73982 + char *p;
73983 + __u16 ip_port = 0;
73984 + const struct cred *cred = current_cred();
73985 +
73986 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73987 + return 0;
73988 +
73989 + curr = current->acl;
73990 + isk = inet_sk(sk);
73991 +
73992 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73993 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73994 + addr->sin_addr.s_addr = curr->inaddr_any_override;
73995 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73996 + struct sockaddr_in saddr;
73997 + int err;
73998 +
73999 + saddr.sin_family = AF_INET;
74000 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
74001 + saddr.sin_port = isk->inet_sport;
74002 +
74003 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
74004 + if (err)
74005 + return err;
74006 +
74007 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
74008 + if (err)
74009 + return err;
74010 + }
74011 +
74012 + if (!curr->ips)
74013 + return 0;
74014 +
74015 + ip_addr = addr->sin_addr.s_addr;
74016 + ip_port = ntohs(addr->sin_port);
74017 +
74018 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
74019 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74020 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
74021 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
74022 + gr_to_filename(current->exec_file->f_path.dentry,
74023 + current->exec_file->f_path.mnt) :
74024 + curr->filename, curr->filename,
74025 + &ip_addr, ip_port, type,
74026 + sk->sk_protocol, mode, &current->signal->saved_ip);
74027 + return 0;
74028 + }
74029 +
74030 + for (i = 0; i < curr->ip_num; i++) {
74031 + ip = *(curr->ips + i);
74032 + if (ip->iface != NULL) {
74033 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
74034 + p = strchr(iface, ':');
74035 + if (p != NULL)
74036 + *p = '\0';
74037 + dev = dev_get_by_name(sock_net(sk), iface);
74038 + if (dev == NULL)
74039 + continue;
74040 + idev = in_dev_get(dev);
74041 + if (idev == NULL) {
74042 + dev_put(dev);
74043 + continue;
74044 + }
74045 + rcu_read_lock();
74046 + for_ifa(idev) {
74047 + if (!strcmp(ip->iface, ifa->ifa_label)) {
74048 + our_addr = ifa->ifa_address;
74049 + our_netmask = 0xffffffff;
74050 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
74051 + if (ret == 1) {
74052 + rcu_read_unlock();
74053 + in_dev_put(idev);
74054 + dev_put(dev);
74055 + return 0;
74056 + } else if (ret == 2) {
74057 + rcu_read_unlock();
74058 + in_dev_put(idev);
74059 + dev_put(dev);
74060 + goto denied;
74061 + }
74062 + }
74063 + } endfor_ifa(idev);
74064 + rcu_read_unlock();
74065 + in_dev_put(idev);
74066 + dev_put(dev);
74067 + } else {
74068 + our_addr = ip->addr;
74069 + our_netmask = ip->netmask;
74070 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
74071 + if (ret == 1)
74072 + return 0;
74073 + else if (ret == 2)
74074 + goto denied;
74075 + }
74076 + }
74077 +
74078 +denied:
74079 + if (mode == GR_BIND)
74080 + gr_log_int5_str2(GR_DONT_AUDIT, GR_BIND_ACL_MSG, &ip_addr, ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
74081 + else if (mode == GR_CONNECT)
74082 + gr_log_int5_str2(GR_DONT_AUDIT, GR_CONNECT_ACL_MSG, &ip_addr, ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
74083 +
74084 + return -EACCES;
74085 +}
74086 +
74087 +int
74088 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
74089 +{
74090 + /* always allow disconnection of dgram sockets with connect */
74091 + if (addr->sin_family == AF_UNSPEC)
74092 + return 0;
74093 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
74094 +}
74095 +
74096 +int
74097 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
74098 +{
74099 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
74100 +}
74101 +
74102 +int gr_search_listen(struct socket *sock)
74103 +{
74104 + struct sock *sk = sock->sk;
74105 + struct sockaddr_in addr;
74106 +
74107 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
74108 + addr.sin_port = inet_sk(sk)->inet_sport;
74109 +
74110 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
74111 +}
74112 +
74113 +int gr_search_accept(struct socket *sock)
74114 +{
74115 + struct sock *sk = sock->sk;
74116 + struct sockaddr_in addr;
74117 +
74118 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
74119 + addr.sin_port = inet_sk(sk)->inet_sport;
74120 +
74121 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
74122 +}
74123 +
74124 +int
74125 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
74126 +{
74127 + if (addr)
74128 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
74129 + else {
74130 + struct sockaddr_in sin;
74131 + const struct inet_sock *inet = inet_sk(sk);
74132 +
74133 + sin.sin_addr.s_addr = inet->inet_daddr;
74134 + sin.sin_port = inet->inet_dport;
74135 +
74136 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
74137 + }
74138 +}
74139 +
74140 +int
74141 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
74142 +{
74143 + struct sockaddr_in sin;
74144 +
74145 + if (unlikely(skb->len < sizeof (struct udphdr)))
74146 + return 0; // skip this packet
74147 +
74148 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
74149 + sin.sin_port = udp_hdr(skb)->source;
74150 +
74151 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
74152 +}
74153 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
74154 new file mode 100644
74155 index 0000000..25f54ef
74156 --- /dev/null
74157 +++ b/grsecurity/gracl_learn.c
74158 @@ -0,0 +1,207 @@
74159 +#include <linux/kernel.h>
74160 +#include <linux/mm.h>
74161 +#include <linux/sched.h>
74162 +#include <linux/poll.h>
74163 +#include <linux/string.h>
74164 +#include <linux/file.h>
74165 +#include <linux/types.h>
74166 +#include <linux/vmalloc.h>
74167 +#include <linux/grinternal.h>
74168 +
74169 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
74170 + size_t count, loff_t *ppos);
74171 +extern int gr_acl_is_enabled(void);
74172 +
74173 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
74174 +static int gr_learn_attached;
74175 +
74176 +/* use a 512k buffer */
74177 +#define LEARN_BUFFER_SIZE (512 * 1024)
74178 +
74179 +static DEFINE_SPINLOCK(gr_learn_lock);
74180 +static DEFINE_MUTEX(gr_learn_user_mutex);
74181 +
74182 +/* we need to maintain two buffers, so that the kernel context of grlearn
74183 + uses a semaphore around the userspace copying, and the other kernel contexts
74184 + use a spinlock when copying into the buffer, since they cannot sleep
74185 +*/
74186 +static char *learn_buffer;
74187 +static char *learn_buffer_user;
74188 +static int learn_buffer_len;
74189 +static int learn_buffer_user_len;
74190 +
74191 +static ssize_t
74192 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
74193 +{
74194 + DECLARE_WAITQUEUE(wait, current);
74195 + ssize_t retval = 0;
74196 +
74197 + add_wait_queue(&learn_wait, &wait);
74198 + set_current_state(TASK_INTERRUPTIBLE);
74199 + do {
74200 + mutex_lock(&gr_learn_user_mutex);
74201 + spin_lock(&gr_learn_lock);
74202 + if (learn_buffer_len)
74203 + break;
74204 + spin_unlock(&gr_learn_lock);
74205 + mutex_unlock(&gr_learn_user_mutex);
74206 + if (file->f_flags & O_NONBLOCK) {
74207 + retval = -EAGAIN;
74208 + goto out;
74209 + }
74210 + if (signal_pending(current)) {
74211 + retval = -ERESTARTSYS;
74212 + goto out;
74213 + }
74214 +
74215 + schedule();
74216 + } while (1);
74217 +
74218 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
74219 + learn_buffer_user_len = learn_buffer_len;
74220 + retval = learn_buffer_len;
74221 + learn_buffer_len = 0;
74222 +
74223 + spin_unlock(&gr_learn_lock);
74224 +
74225 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
74226 + retval = -EFAULT;
74227 +
74228 + mutex_unlock(&gr_learn_user_mutex);
74229 +out:
74230 + set_current_state(TASK_RUNNING);
74231 + remove_wait_queue(&learn_wait, &wait);
74232 + return retval;
74233 +}
74234 +
74235 +static unsigned int
74236 +poll_learn(struct file * file, poll_table * wait)
74237 +{
74238 + poll_wait(file, &learn_wait, wait);
74239 +
74240 + if (learn_buffer_len)
74241 + return (POLLIN | POLLRDNORM);
74242 +
74243 + return 0;
74244 +}
74245 +
74246 +void
74247 +gr_clear_learn_entries(void)
74248 +{
74249 + char *tmp;
74250 +
74251 + mutex_lock(&gr_learn_user_mutex);
74252 + spin_lock(&gr_learn_lock);
74253 + tmp = learn_buffer;
74254 + learn_buffer = NULL;
74255 + spin_unlock(&gr_learn_lock);
74256 + if (tmp)
74257 + vfree(tmp);
74258 + if (learn_buffer_user != NULL) {
74259 + vfree(learn_buffer_user);
74260 + learn_buffer_user = NULL;
74261 + }
74262 + learn_buffer_len = 0;
74263 + mutex_unlock(&gr_learn_user_mutex);
74264 +
74265 + return;
74266 +}
74267 +
74268 +void
74269 +gr_add_learn_entry(const char *fmt, ...)
74270 +{
74271 + va_list args;
74272 + unsigned int len;
74273 +
74274 + if (!gr_learn_attached)
74275 + return;
74276 +
74277 + spin_lock(&gr_learn_lock);
74278 +
74279 + /* leave a gap at the end so we know when it's "full" but don't have to
74280 + compute the exact length of the string we're trying to append
74281 + */
74282 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
74283 + spin_unlock(&gr_learn_lock);
74284 + wake_up_interruptible(&learn_wait);
74285 + return;
74286 + }
74287 + if (learn_buffer == NULL) {
74288 + spin_unlock(&gr_learn_lock);
74289 + return;
74290 + }
74291 +
74292 + va_start(args, fmt);
74293 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
74294 + va_end(args);
74295 +
74296 + learn_buffer_len += len + 1;
74297 +
74298 + spin_unlock(&gr_learn_lock);
74299 + wake_up_interruptible(&learn_wait);
74300 +
74301 + return;
74302 +}
74303 +
74304 +static int
74305 +open_learn(struct inode *inode, struct file *file)
74306 +{
74307 + if (file->f_mode & FMODE_READ && gr_learn_attached)
74308 + return -EBUSY;
74309 + if (file->f_mode & FMODE_READ) {
74310 + int retval = 0;
74311 + mutex_lock(&gr_learn_user_mutex);
74312 + if (learn_buffer == NULL)
74313 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
74314 + if (learn_buffer_user == NULL)
74315 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
74316 + if (learn_buffer == NULL) {
74317 + retval = -ENOMEM;
74318 + goto out_error;
74319 + }
74320 + if (learn_buffer_user == NULL) {
74321 + retval = -ENOMEM;
74322 + goto out_error;
74323 + }
74324 + learn_buffer_len = 0;
74325 + learn_buffer_user_len = 0;
74326 + gr_learn_attached = 1;
74327 +out_error:
74328 + mutex_unlock(&gr_learn_user_mutex);
74329 + return retval;
74330 + }
74331 + return 0;
74332 +}
74333 +
74334 +static int
74335 +close_learn(struct inode *inode, struct file *file)
74336 +{
74337 + if (file->f_mode & FMODE_READ) {
74338 + char *tmp = NULL;
74339 + mutex_lock(&gr_learn_user_mutex);
74340 + spin_lock(&gr_learn_lock);
74341 + tmp = learn_buffer;
74342 + learn_buffer = NULL;
74343 + spin_unlock(&gr_learn_lock);
74344 + if (tmp)
74345 + vfree(tmp);
74346 + if (learn_buffer_user != NULL) {
74347 + vfree(learn_buffer_user);
74348 + learn_buffer_user = NULL;
74349 + }
74350 + learn_buffer_len = 0;
74351 + learn_buffer_user_len = 0;
74352 + gr_learn_attached = 0;
74353 + mutex_unlock(&gr_learn_user_mutex);
74354 + }
74355 +
74356 + return 0;
74357 +}
74358 +
74359 +const struct file_operations grsec_fops = {
74360 + .read = read_learn,
74361 + .write = write_grsec_handler,
74362 + .open = open_learn,
74363 + .release = close_learn,
74364 + .poll = poll_learn,
74365 +};
74366 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
74367 new file mode 100644
74368 index 0000000..3f8ade0
74369 --- /dev/null
74370 +++ b/grsecurity/gracl_policy.c
74371 @@ -0,0 +1,1782 @@
74372 +#include <linux/kernel.h>
74373 +#include <linux/module.h>
74374 +#include <linux/sched.h>
74375 +#include <linux/mm.h>
74376 +#include <linux/file.h>
74377 +#include <linux/fs.h>
74378 +#include <linux/namei.h>
74379 +#include <linux/mount.h>
74380 +#include <linux/tty.h>
74381 +#include <linux/proc_fs.h>
74382 +#include <linux/lglock.h>
74383 +#include <linux/slab.h>
74384 +#include <linux/vmalloc.h>
74385 +#include <linux/types.h>
74386 +#include <linux/sysctl.h>
74387 +#include <linux/netdevice.h>
74388 +#include <linux/ptrace.h>
74389 +#include <linux/gracl.h>
74390 +#include <linux/gralloc.h>
74391 +#include <linux/security.h>
74392 +#include <linux/grinternal.h>
74393 +#include <linux/pid_namespace.h>
74394 +#include <linux/stop_machine.h>
74395 +#include <linux/fdtable.h>
74396 +#include <linux/percpu.h>
74397 +#include <linux/lglock.h>
74398 +#include <linux/hugetlb.h>
74399 +#include <linux/posix-timers.h>
74400 +#include "../fs/mount.h"
74401 +
74402 +#include <asm/uaccess.h>
74403 +#include <asm/errno.h>
74404 +#include <asm/mman.h>
74405 +
74406 +extern struct gr_policy_state *polstate;
74407 +
74408 +#define FOR_EACH_ROLE_START(role) \
74409 + role = polstate->role_list; \
74410 + while (role) {
74411 +
74412 +#define FOR_EACH_ROLE_END(role) \
74413 + role = role->prev; \
74414 + }
74415 +
74416 +struct path gr_real_root;
74417 +
74418 +extern struct gr_alloc_state *current_alloc_state;
74419 +
74420 +u16 acl_sp_role_value;
74421 +
74422 +static DEFINE_MUTEX(gr_dev_mutex);
74423 +
74424 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
74425 +extern void gr_clear_learn_entries(void);
74426 +
74427 +struct gr_arg *gr_usermode __read_only;
74428 +unsigned char *gr_system_salt __read_only;
74429 +unsigned char *gr_system_sum __read_only;
74430 +
74431 +static unsigned int gr_auth_attempts = 0;
74432 +static unsigned long gr_auth_expires = 0UL;
74433 +
74434 +struct acl_object_label *fakefs_obj_rw;
74435 +struct acl_object_label *fakefs_obj_rwx;
74436 +
74437 +extern int gr_init_uidset(void);
74438 +extern void gr_free_uidset(void);
74439 +extern void gr_remove_uid(uid_t uid);
74440 +extern int gr_find_uid(uid_t uid);
74441 +
74442 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
74443 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
74444 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
74445 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
74446 +extern struct acl_role_label *__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid, const gid_t gid);
74447 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
74448 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
74449 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
74450 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
74451 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74452 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74453 +extern void assign_special_role(const char *rolename);
74454 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
74455 +extern int gr_rbac_disable(void *unused);
74456 +extern void gr_enable_rbac_system(void);
74457 +
74458 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
74459 +{
74460 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
74461 + return -EFAULT;
74462 +
74463 + return 0;
74464 +}
74465 +
74466 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
74467 +{
74468 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
74469 + return -EFAULT;
74470 +
74471 + return 0;
74472 +}
74473 +
74474 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
74475 +{
74476 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
74477 + return -EFAULT;
74478 +
74479 + return 0;
74480 +}
74481 +
74482 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
74483 +{
74484 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
74485 + return -EFAULT;
74486 +
74487 + return 0;
74488 +}
74489 +
74490 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
74491 +{
74492 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
74493 + return -EFAULT;
74494 +
74495 + return 0;
74496 +}
74497 +
74498 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
74499 +{
74500 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
74501 + return -EFAULT;
74502 +
74503 + return 0;
74504 +}
74505 +
74506 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
74507 +{
74508 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
74509 + return -EFAULT;
74510 +
74511 + return 0;
74512 +}
74513 +
74514 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
74515 +{
74516 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
74517 + return -EFAULT;
74518 +
74519 + return 0;
74520 +}
74521 +
74522 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
74523 +{
74524 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
74525 + return -EFAULT;
74526 +
74527 + return 0;
74528 +}
74529 +
74530 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
74531 +{
74532 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
74533 + return -EFAULT;
74534 +
74535 + if (((uwrap->version != GRSECURITY_VERSION) &&
74536 + (uwrap->version != 0x2901)) ||
74537 + (uwrap->size != sizeof(struct gr_arg)))
74538 + return -EINVAL;
74539 +
74540 + return 0;
74541 +}
74542 +
74543 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
74544 +{
74545 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
74546 + return -EFAULT;
74547 +
74548 + return 0;
74549 +}
74550 +
74551 +static size_t get_gr_arg_wrapper_size_normal(void)
74552 +{
74553 + return sizeof(struct gr_arg_wrapper);
74554 +}
74555 +
74556 +#ifdef CONFIG_COMPAT
74557 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
74558 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
74559 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
74560 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
74561 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
74562 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
74563 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
74564 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74565 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74566 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74567 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74568 +extern size_t get_gr_arg_wrapper_size_compat(void);
74569 +
74570 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74571 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74572 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74573 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74574 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74575 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74576 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74577 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74578 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74579 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74580 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74581 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74582 +
74583 +#else
74584 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74585 +#define copy_gr_arg copy_gr_arg_normal
74586 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
74587 +#define copy_acl_object_label copy_acl_object_label_normal
74588 +#define copy_acl_subject_label copy_acl_subject_label_normal
74589 +#define copy_acl_role_label copy_acl_role_label_normal
74590 +#define copy_acl_ip_label copy_acl_ip_label_normal
74591 +#define copy_pointer_from_array copy_pointer_from_array_normal
74592 +#define copy_sprole_pw copy_sprole_pw_normal
74593 +#define copy_role_transition copy_role_transition_normal
74594 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
74595 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74596 +#endif
74597 +
74598 +static struct acl_subject_label *
74599 +lookup_subject_map(const struct acl_subject_label *userp)
74600 +{
74601 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74602 + struct subject_map *match;
74603 +
74604 + match = polstate->subj_map_set.s_hash[index];
74605 +
74606 + while (match && match->user != userp)
74607 + match = match->next;
74608 +
74609 + if (match != NULL)
74610 + return match->kernel;
74611 + else
74612 + return NULL;
74613 +}
74614 +
74615 +static void
74616 +insert_subj_map_entry(struct subject_map *subjmap)
74617 +{
74618 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74619 + struct subject_map **curr;
74620 +
74621 + subjmap->prev = NULL;
74622 +
74623 + curr = &polstate->subj_map_set.s_hash[index];
74624 + if (*curr != NULL)
74625 + (*curr)->prev = subjmap;
74626 +
74627 + subjmap->next = *curr;
74628 + *curr = subjmap;
74629 +
74630 + return;
74631 +}
74632 +
74633 +static void
74634 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74635 +{
74636 + unsigned int index =
74637 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74638 + struct acl_role_label **curr;
74639 + struct acl_role_label *tmp, *tmp2;
74640 +
74641 + curr = &polstate->acl_role_set.r_hash[index];
74642 +
74643 + /* simple case, slot is empty, just set it to our role */
74644 + if (*curr == NULL) {
74645 + *curr = role;
74646 + } else {
74647 + /* example:
74648 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
74649 + 2 -> 3
74650 + */
74651 + /* first check to see if we can already be reached via this slot */
74652 + tmp = *curr;
74653 + while (tmp && tmp != role)
74654 + tmp = tmp->next;
74655 + if (tmp == role) {
74656 + /* we don't need to add ourselves to this slot's chain */
74657 + return;
74658 + }
74659 + /* we need to add ourselves to this chain, two cases */
74660 + if (role->next == NULL) {
74661 + /* simple case, append the current chain to our role */
74662 + role->next = *curr;
74663 + *curr = role;
74664 + } else {
74665 + /* 1 -> 2 -> 3 -> 4
74666 + 2 -> 3 -> 4
74667 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74668 + */
74669 + /* trickier case: walk our role's chain until we find
74670 + the role for the start of the current slot's chain */
74671 + tmp = role;
74672 + tmp2 = *curr;
74673 + while (tmp->next && tmp->next != tmp2)
74674 + tmp = tmp->next;
74675 + if (tmp->next == tmp2) {
74676 + /* from example above, we found 3, so just
74677 + replace this slot's chain with ours */
74678 + *curr = role;
74679 + } else {
74680 + /* we didn't find a subset of our role's chain
74681 + in the current slot's chain, so append their
74682 + chain to ours, and set us as the first role in
74683 + the slot's chain
74684 +
74685 + we could fold this case with the case above,
74686 + but making it explicit for clarity
74687 + */
74688 + tmp->next = tmp2;
74689 + *curr = role;
74690 + }
74691 + }
74692 + }
74693 +
74694 + return;
74695 +}
74696 +
74697 +static void
74698 +insert_acl_role_label(struct acl_role_label *role)
74699 +{
74700 + int i;
74701 +
74702 + if (polstate->role_list == NULL) {
74703 + polstate->role_list = role;
74704 + role->prev = NULL;
74705 + } else {
74706 + role->prev = polstate->role_list;
74707 + polstate->role_list = role;
74708 + }
74709 +
74710 + /* used for hash chains */
74711 + role->next = NULL;
74712 +
74713 + if (role->roletype & GR_ROLE_DOMAIN) {
74714 + for (i = 0; i < role->domain_child_num; i++)
74715 + __insert_acl_role_label(role, role->domain_children[i]);
74716 + } else
74717 + __insert_acl_role_label(role, role->uidgid);
74718 +}
74719 +
74720 +static int
74721 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
74722 +{
74723 + struct name_entry **curr, *nentry;
74724 + struct inodev_entry *ientry;
74725 + unsigned int len = strlen(name);
74726 + unsigned int key = full_name_hash(name, len);
74727 + unsigned int index = key % polstate->name_set.n_size;
74728 +
74729 + curr = &polstate->name_set.n_hash[index];
74730 +
74731 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74732 + curr = &((*curr)->next);
74733 +
74734 + if (*curr != NULL)
74735 + return 1;
74736 +
74737 + nentry = acl_alloc(sizeof (struct name_entry));
74738 + if (nentry == NULL)
74739 + return 0;
74740 + ientry = acl_alloc(sizeof (struct inodev_entry));
74741 + if (ientry == NULL)
74742 + return 0;
74743 + ientry->nentry = nentry;
74744 +
74745 + nentry->key = key;
74746 + nentry->name = name;
74747 + nentry->inode = inode;
74748 + nentry->device = device;
74749 + nentry->len = len;
74750 + nentry->deleted = deleted;
74751 +
74752 + nentry->prev = NULL;
74753 + curr = &polstate->name_set.n_hash[index];
74754 + if (*curr != NULL)
74755 + (*curr)->prev = nentry;
74756 + nentry->next = *curr;
74757 + *curr = nentry;
74758 +
74759 + /* insert us into the table searchable by inode/dev */
74760 + __insert_inodev_entry(polstate, ientry);
74761 +
74762 + return 1;
74763 +}
74764 +
74765 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74766 +
74767 +static void *
74768 +create_table(__u32 * len, int elementsize)
74769 +{
74770 + unsigned int table_sizes[] = {
74771 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74772 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74773 + 4194301, 8388593, 16777213, 33554393, 67108859
74774 + };
74775 + void *newtable = NULL;
74776 + unsigned int pwr = 0;
74777 +
74778 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74779 + table_sizes[pwr] <= *len)
74780 + pwr++;
74781 +
74782 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74783 + return newtable;
74784 +
74785 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74786 + newtable =
74787 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74788 + else
74789 + newtable = vmalloc(table_sizes[pwr] * elementsize);
74790 +
74791 + *len = table_sizes[pwr];
74792 +
74793 + return newtable;
74794 +}
74795 +
74796 +static int
74797 +init_variables(const struct gr_arg *arg, bool reload)
74798 +{
74799 + struct task_struct *reaper = init_pid_ns.child_reaper;
74800 + unsigned int stacksize;
74801 +
74802 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74803 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74804 + polstate->name_set.n_size = arg->role_db.num_objects;
74805 + polstate->inodev_set.i_size = arg->role_db.num_objects;
74806 +
74807 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74808 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74809 + return 1;
74810 +
74811 + if (!reload) {
74812 + if (!gr_init_uidset())
74813 + return 1;
74814 + }
74815 +
74816 + /* set up the stack that holds allocation info */
74817 +
74818 + stacksize = arg->role_db.num_pointers + 5;
74819 +
74820 + if (!acl_alloc_stack_init(stacksize))
74821 + return 1;
74822 +
74823 + if (!reload) {
74824 + /* grab reference for the real root dentry and vfsmount */
74825 + get_fs_root(reaper->fs, &gr_real_root);
74826 +
74827 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74828 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(gr_real_root.dentry), gr_real_root.dentry->d_inode->i_ino);
74829 +#endif
74830 +
74831 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74832 + if (fakefs_obj_rw == NULL)
74833 + return 1;
74834 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74835 +
74836 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74837 + if (fakefs_obj_rwx == NULL)
74838 + return 1;
74839 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74840 + }
74841 +
74842 + polstate->subj_map_set.s_hash =
74843 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74844 + polstate->acl_role_set.r_hash =
74845 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74846 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74847 + polstate->inodev_set.i_hash =
74848 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74849 +
74850 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74851 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74852 + return 1;
74853 +
74854 + memset(polstate->subj_map_set.s_hash, 0,
74855 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74856 + memset(polstate->acl_role_set.r_hash, 0,
74857 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74858 + memset(polstate->name_set.n_hash, 0,
74859 + sizeof (struct name_entry *) * polstate->name_set.n_size);
74860 + memset(polstate->inodev_set.i_hash, 0,
74861 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74862 +
74863 + return 0;
74864 +}
74865 +
74866 +/* free information not needed after startup
74867 + currently contains user->kernel pointer mappings for subjects
74868 +*/
74869 +
74870 +static void
74871 +free_init_variables(void)
74872 +{
74873 + __u32 i;
74874 +
74875 + if (polstate->subj_map_set.s_hash) {
74876 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74877 + if (polstate->subj_map_set.s_hash[i]) {
74878 + kfree(polstate->subj_map_set.s_hash[i]);
74879 + polstate->subj_map_set.s_hash[i] = NULL;
74880 + }
74881 + }
74882 +
74883 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74884 + PAGE_SIZE)
74885 + kfree(polstate->subj_map_set.s_hash);
74886 + else
74887 + vfree(polstate->subj_map_set.s_hash);
74888 + }
74889 +
74890 + return;
74891 +}
74892 +
74893 +static void
74894 +free_variables(bool reload)
74895 +{
74896 + struct acl_subject_label *s;
74897 + struct acl_role_label *r;
74898 + struct task_struct *task, *task2;
74899 + unsigned int x;
74900 +
74901 + if (!reload) {
74902 + gr_clear_learn_entries();
74903 +
74904 + read_lock(&tasklist_lock);
74905 + do_each_thread(task2, task) {
74906 + task->acl_sp_role = 0;
74907 + task->acl_role_id = 0;
74908 + task->inherited = 0;
74909 + task->acl = NULL;
74910 + task->role = NULL;
74911 + } while_each_thread(task2, task);
74912 + read_unlock(&tasklist_lock);
74913 +
74914 + kfree(fakefs_obj_rw);
74915 + fakefs_obj_rw = NULL;
74916 + kfree(fakefs_obj_rwx);
74917 + fakefs_obj_rwx = NULL;
74918 +
74919 + /* release the reference to the real root dentry and vfsmount */
74920 + path_put(&gr_real_root);
74921 + memset(&gr_real_root, 0, sizeof(gr_real_root));
74922 + }
74923 +
74924 + /* free all object hash tables */
74925 +
74926 + FOR_EACH_ROLE_START(r)
74927 + if (r->subj_hash == NULL)
74928 + goto next_role;
74929 + FOR_EACH_SUBJECT_START(r, s, x)
74930 + if (s->obj_hash == NULL)
74931 + break;
74932 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74933 + kfree(s->obj_hash);
74934 + else
74935 + vfree(s->obj_hash);
74936 + FOR_EACH_SUBJECT_END(s, x)
74937 + FOR_EACH_NESTED_SUBJECT_START(r, s)
74938 + if (s->obj_hash == NULL)
74939 + break;
74940 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74941 + kfree(s->obj_hash);
74942 + else
74943 + vfree(s->obj_hash);
74944 + FOR_EACH_NESTED_SUBJECT_END(s)
74945 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74946 + kfree(r->subj_hash);
74947 + else
74948 + vfree(r->subj_hash);
74949 + r->subj_hash = NULL;
74950 +next_role:
74951 + FOR_EACH_ROLE_END(r)
74952 +
74953 + acl_free_all();
74954 +
74955 + if (polstate->acl_role_set.r_hash) {
74956 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74957 + PAGE_SIZE)
74958 + kfree(polstate->acl_role_set.r_hash);
74959 + else
74960 + vfree(polstate->acl_role_set.r_hash);
74961 + }
74962 + if (polstate->name_set.n_hash) {
74963 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74964 + PAGE_SIZE)
74965 + kfree(polstate->name_set.n_hash);
74966 + else
74967 + vfree(polstate->name_set.n_hash);
74968 + }
74969 +
74970 + if (polstate->inodev_set.i_hash) {
74971 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74972 + PAGE_SIZE)
74973 + kfree(polstate->inodev_set.i_hash);
74974 + else
74975 + vfree(polstate->inodev_set.i_hash);
74976 + }
74977 +
74978 + if (!reload)
74979 + gr_free_uidset();
74980 +
74981 + memset(&polstate->name_set, 0, sizeof (struct name_db));
74982 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74983 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74984 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74985 +
74986 + polstate->default_role = NULL;
74987 + polstate->kernel_role = NULL;
74988 + polstate->role_list = NULL;
74989 +
74990 + return;
74991 +}
74992 +
74993 +static struct acl_subject_label *
74994 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74995 +
74996 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
74997 +{
74998 + unsigned int len = strnlen_user(*name, maxlen);
74999 + char *tmp;
75000 +
75001 + if (!len || len >= maxlen)
75002 + return -EINVAL;
75003 +
75004 + if ((tmp = (char *) acl_alloc(len)) == NULL)
75005 + return -ENOMEM;
75006 +
75007 + if (copy_from_user(tmp, *name, len))
75008 + return -EFAULT;
75009 +
75010 + tmp[len-1] = '\0';
75011 + *name = tmp;
75012 +
75013 + return 0;
75014 +}
75015 +
75016 +static int
75017 +copy_user_glob(struct acl_object_label *obj)
75018 +{
75019 + struct acl_object_label *g_tmp, **guser;
75020 + int error;
75021 +
75022 + if (obj->globbed == NULL)
75023 + return 0;
75024 +
75025 + guser = &obj->globbed;
75026 + while (*guser) {
75027 + g_tmp = (struct acl_object_label *)
75028 + acl_alloc(sizeof (struct acl_object_label));
75029 + if (g_tmp == NULL)
75030 + return -ENOMEM;
75031 +
75032 + if (copy_acl_object_label(g_tmp, *guser))
75033 + return -EFAULT;
75034 +
75035 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
75036 + if (error)
75037 + return error;
75038 +
75039 + *guser = g_tmp;
75040 + guser = &(g_tmp->next);
75041 + }
75042 +
75043 + return 0;
75044 +}
75045 +
75046 +static int
75047 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
75048 + struct acl_role_label *role)
75049 +{
75050 + struct acl_object_label *o_tmp;
75051 + int ret;
75052 +
75053 + while (userp) {
75054 + if ((o_tmp = (struct acl_object_label *)
75055 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
75056 + return -ENOMEM;
75057 +
75058 + if (copy_acl_object_label(o_tmp, userp))
75059 + return -EFAULT;
75060 +
75061 + userp = o_tmp->prev;
75062 +
75063 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
75064 + if (ret)
75065 + return ret;
75066 +
75067 + insert_acl_obj_label(o_tmp, subj);
75068 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
75069 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
75070 + return -ENOMEM;
75071 +
75072 + ret = copy_user_glob(o_tmp);
75073 + if (ret)
75074 + return ret;
75075 +
75076 + if (o_tmp->nested) {
75077 + int already_copied;
75078 +
75079 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
75080 + if (IS_ERR(o_tmp->nested))
75081 + return PTR_ERR(o_tmp->nested);
75082 +
75083 + /* insert into nested subject list if we haven't copied this one yet
75084 + to prevent duplicate entries */
75085 + if (!already_copied) {
75086 + o_tmp->nested->next = role->hash->first;
75087 + role->hash->first = o_tmp->nested;
75088 + }
75089 + }
75090 + }
75091 +
75092 + return 0;
75093 +}
75094 +
75095 +static __u32
75096 +count_user_subjs(struct acl_subject_label *userp)
75097 +{
75098 + struct acl_subject_label s_tmp;
75099 + __u32 num = 0;
75100 +
75101 + while (userp) {
75102 + if (copy_acl_subject_label(&s_tmp, userp))
75103 + break;
75104 +
75105 + userp = s_tmp.prev;
75106 + }
75107 +
75108 + return num;
75109 +}
75110 +
75111 +static int
75112 +copy_user_allowedips(struct acl_role_label *rolep)
75113 +{
75114 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
75115 +
75116 + ruserip = rolep->allowed_ips;
75117 +
75118 + while (ruserip) {
75119 + rlast = rtmp;
75120 +
75121 + if ((rtmp = (struct role_allowed_ip *)
75122 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
75123 + return -ENOMEM;
75124 +
75125 + if (copy_role_allowed_ip(rtmp, ruserip))
75126 + return -EFAULT;
75127 +
75128 + ruserip = rtmp->prev;
75129 +
75130 + if (!rlast) {
75131 + rtmp->prev = NULL;
75132 + rolep->allowed_ips = rtmp;
75133 + } else {
75134 + rlast->next = rtmp;
75135 + rtmp->prev = rlast;
75136 + }
75137 +
75138 + if (!ruserip)
75139 + rtmp->next = NULL;
75140 + }
75141 +
75142 + return 0;
75143 +}
75144 +
75145 +static int
75146 +copy_user_transitions(struct acl_role_label *rolep)
75147 +{
75148 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
75149 + int error;
75150 +
75151 + rusertp = rolep->transitions;
75152 +
75153 + while (rusertp) {
75154 + rlast = rtmp;
75155 +
75156 + if ((rtmp = (struct role_transition *)
75157 + acl_alloc(sizeof (struct role_transition))) == NULL)
75158 + return -ENOMEM;
75159 +
75160 + if (copy_role_transition(rtmp, rusertp))
75161 + return -EFAULT;
75162 +
75163 + rusertp = rtmp->prev;
75164 +
75165 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
75166 + if (error)
75167 + return error;
75168 +
75169 + if (!rlast) {
75170 + rtmp->prev = NULL;
75171 + rolep->transitions = rtmp;
75172 + } else {
75173 + rlast->next = rtmp;
75174 + rtmp->prev = rlast;
75175 + }
75176 +
75177 + if (!rusertp)
75178 + rtmp->next = NULL;
75179 + }
75180 +
75181 + return 0;
75182 +}
75183 +
75184 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
75185 +{
75186 + struct acl_object_label o_tmp;
75187 + __u32 num = 0;
75188 +
75189 + while (userp) {
75190 + if (copy_acl_object_label(&o_tmp, userp))
75191 + break;
75192 +
75193 + userp = o_tmp.prev;
75194 + num++;
75195 + }
75196 +
75197 + return num;
75198 +}
75199 +
75200 +static struct acl_subject_label *
75201 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
75202 +{
75203 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
75204 + __u32 num_objs;
75205 + struct acl_ip_label **i_tmp, *i_utmp2;
75206 + struct gr_hash_struct ghash;
75207 + struct subject_map *subjmap;
75208 + unsigned int i_num;
75209 + int err;
75210 +
75211 + if (already_copied != NULL)
75212 + *already_copied = 0;
75213 +
75214 + s_tmp = lookup_subject_map(userp);
75215 +
75216 + /* we've already copied this subject into the kernel, just return
75217 + the reference to it, and don't copy it over again
75218 + */
75219 + if (s_tmp) {
75220 + if (already_copied != NULL)
75221 + *already_copied = 1;
75222 + return(s_tmp);
75223 + }
75224 +
75225 + if ((s_tmp = (struct acl_subject_label *)
75226 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
75227 + return ERR_PTR(-ENOMEM);
75228 +
75229 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
75230 + if (subjmap == NULL)
75231 + return ERR_PTR(-ENOMEM);
75232 +
75233 + subjmap->user = userp;
75234 + subjmap->kernel = s_tmp;
75235 + insert_subj_map_entry(subjmap);
75236 +
75237 + if (copy_acl_subject_label(s_tmp, userp))
75238 + return ERR_PTR(-EFAULT);
75239 +
75240 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
75241 + if (err)
75242 + return ERR_PTR(err);
75243 +
75244 + if (!strcmp(s_tmp->filename, "/"))
75245 + role->root_label = s_tmp;
75246 +
75247 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
75248 + return ERR_PTR(-EFAULT);
75249 +
75250 + /* copy user and group transition tables */
75251 +
75252 + if (s_tmp->user_trans_num) {
75253 + uid_t *uidlist;
75254 +
75255 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
75256 + if (uidlist == NULL)
75257 + return ERR_PTR(-ENOMEM);
75258 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
75259 + return ERR_PTR(-EFAULT);
75260 +
75261 + s_tmp->user_transitions = uidlist;
75262 + }
75263 +
75264 + if (s_tmp->group_trans_num) {
75265 + gid_t *gidlist;
75266 +
75267 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
75268 + if (gidlist == NULL)
75269 + return ERR_PTR(-ENOMEM);
75270 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
75271 + return ERR_PTR(-EFAULT);
75272 +
75273 + s_tmp->group_transitions = gidlist;
75274 + }
75275 +
75276 + /* set up object hash table */
75277 + num_objs = count_user_objs(ghash.first);
75278 +
75279 + s_tmp->obj_hash_size = num_objs;
75280 + s_tmp->obj_hash =
75281 + (struct acl_object_label **)
75282 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
75283 +
75284 + if (!s_tmp->obj_hash)
75285 + return ERR_PTR(-ENOMEM);
75286 +
75287 + memset(s_tmp->obj_hash, 0,
75288 + s_tmp->obj_hash_size *
75289 + sizeof (struct acl_object_label *));
75290 +
75291 + /* add in objects */
75292 + err = copy_user_objs(ghash.first, s_tmp, role);
75293 +
75294 + if (err)
75295 + return ERR_PTR(err);
75296 +
75297 + /* set pointer for parent subject */
75298 + if (s_tmp->parent_subject) {
75299 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
75300 +
75301 + if (IS_ERR(s_tmp2))
75302 + return s_tmp2;
75303 +
75304 + s_tmp->parent_subject = s_tmp2;
75305 + }
75306 +
75307 + /* add in ip acls */
75308 +
75309 + if (!s_tmp->ip_num) {
75310 + s_tmp->ips = NULL;
75311 + goto insert;
75312 + }
75313 +
75314 + i_tmp =
75315 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
75316 + sizeof (struct acl_ip_label *));
75317 +
75318 + if (!i_tmp)
75319 + return ERR_PTR(-ENOMEM);
75320 +
75321 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
75322 + *(i_tmp + i_num) =
75323 + (struct acl_ip_label *)
75324 + acl_alloc(sizeof (struct acl_ip_label));
75325 + if (!*(i_tmp + i_num))
75326 + return ERR_PTR(-ENOMEM);
75327 +
75328 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
75329 + return ERR_PTR(-EFAULT);
75330 +
75331 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
75332 + return ERR_PTR(-EFAULT);
75333 +
75334 + if ((*(i_tmp + i_num))->iface == NULL)
75335 + continue;
75336 +
75337 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
75338 + if (err)
75339 + return ERR_PTR(err);
75340 + }
75341 +
75342 + s_tmp->ips = i_tmp;
75343 +
75344 +insert:
75345 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
75346 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
75347 + return ERR_PTR(-ENOMEM);
75348 +
75349 + return s_tmp;
75350 +}
75351 +
75352 +static int
75353 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
75354 +{
75355 + struct acl_subject_label s_pre;
75356 + struct acl_subject_label * ret;
75357 + int err;
75358 +
75359 + while (userp) {
75360 + if (copy_acl_subject_label(&s_pre, userp))
75361 + return -EFAULT;
75362 +
75363 + ret = do_copy_user_subj(userp, role, NULL);
75364 +
75365 + err = PTR_ERR(ret);
75366 + if (IS_ERR(ret))
75367 + return err;
75368 +
75369 + insert_acl_subj_label(ret, role);
75370 +
75371 + userp = s_pre.prev;
75372 + }
75373 +
75374 + return 0;
75375 +}
75376 +
75377 +static int
75378 +copy_user_acl(struct gr_arg *arg)
75379 +{
75380 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
75381 + struct acl_subject_label *subj_list;
75382 + struct sprole_pw *sptmp;
75383 + struct gr_hash_struct *ghash;
75384 + uid_t *domainlist;
75385 + unsigned int r_num;
75386 + int err = 0;
75387 + __u16 i;
75388 + __u32 num_subjs;
75389 +
75390 + /* we need a default and kernel role */
75391 + if (arg->role_db.num_roles < 2)
75392 + return -EINVAL;
75393 +
75394 + /* copy special role authentication info from userspace */
75395 +
75396 + polstate->num_sprole_pws = arg->num_sprole_pws;
75397 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
75398 +
75399 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
75400 + return -ENOMEM;
75401 +
75402 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75403 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
75404 + if (!sptmp)
75405 + return -ENOMEM;
75406 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
75407 + return -EFAULT;
75408 +
75409 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
75410 + if (err)
75411 + return err;
75412 +
75413 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
75414 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
75415 +#endif
75416 +
75417 + polstate->acl_special_roles[i] = sptmp;
75418 + }
75419 +
75420 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
75421 +
75422 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
75423 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
75424 +
75425 + if (!r_tmp)
75426 + return -ENOMEM;
75427 +
75428 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
75429 + return -EFAULT;
75430 +
75431 + if (copy_acl_role_label(r_tmp, r_utmp2))
75432 + return -EFAULT;
75433 +
75434 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
75435 + if (err)
75436 + return err;
75437 +
75438 + if (!strcmp(r_tmp->rolename, "default")
75439 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
75440 + polstate->default_role = r_tmp;
75441 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
75442 + polstate->kernel_role = r_tmp;
75443 + }
75444 +
75445 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
75446 + return -ENOMEM;
75447 +
75448 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
75449 + return -EFAULT;
75450 +
75451 + r_tmp->hash = ghash;
75452 +
75453 + num_subjs = count_user_subjs(r_tmp->hash->first);
75454 +
75455 + r_tmp->subj_hash_size = num_subjs;
75456 + r_tmp->subj_hash =
75457 + (struct acl_subject_label **)
75458 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
75459 +
75460 + if (!r_tmp->subj_hash)
75461 + return -ENOMEM;
75462 +
75463 + err = copy_user_allowedips(r_tmp);
75464 + if (err)
75465 + return err;
75466 +
75467 + /* copy domain info */
75468 + if (r_tmp->domain_children != NULL) {
75469 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
75470 + if (domainlist == NULL)
75471 + return -ENOMEM;
75472 +
75473 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
75474 + return -EFAULT;
75475 +
75476 + r_tmp->domain_children = domainlist;
75477 + }
75478 +
75479 + err = copy_user_transitions(r_tmp);
75480 + if (err)
75481 + return err;
75482 +
75483 + memset(r_tmp->subj_hash, 0,
75484 + r_tmp->subj_hash_size *
75485 + sizeof (struct acl_subject_label *));
75486 +
75487 + /* acquire the list of subjects, then NULL out
75488 + the list prior to parsing the subjects for this role,
75489 + as during this parsing the list is replaced with a list
75490 + of *nested* subjects for the role
75491 + */
75492 + subj_list = r_tmp->hash->first;
75493 +
75494 + /* set nested subject list to null */
75495 + r_tmp->hash->first = NULL;
75496 +
75497 + err = copy_user_subjs(subj_list, r_tmp);
75498 +
75499 + if (err)
75500 + return err;
75501 +
75502 + insert_acl_role_label(r_tmp);
75503 + }
75504 +
75505 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
75506 + return -EINVAL;
75507 +
75508 + return err;
75509 +}
75510 +
75511 +static int gracl_reload_apply_policies(void *reload)
75512 +{
75513 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
75514 + struct task_struct *task, *task2;
75515 + struct acl_role_label *role, *rtmp;
75516 + struct acl_subject_label *subj;
75517 + const struct cred *cred;
75518 + int role_applied;
75519 + int ret = 0;
75520 +
75521 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
75522 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
75523 +
75524 + /* first make sure we'll be able to apply the new policy cleanly */
75525 + do_each_thread(task2, task) {
75526 + if (task->exec_file == NULL)
75527 + continue;
75528 + role_applied = 0;
75529 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75530 + /* preserve special roles */
75531 + FOR_EACH_ROLE_START(role)
75532 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75533 + rtmp = task->role;
75534 + task->role = role;
75535 + role_applied = 1;
75536 + break;
75537 + }
75538 + FOR_EACH_ROLE_END(role)
75539 + }
75540 + if (!role_applied) {
75541 + cred = __task_cred(task);
75542 + rtmp = task->role;
75543 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75544 + }
75545 + /* this handles non-nested inherited subjects, nested subjects will still
75546 + be dropped currently */
75547 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75548 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
75549 + /* change the role back so that we've made no modifications to the policy */
75550 + task->role = rtmp;
75551 +
75552 + if (subj == NULL || task->tmpacl == NULL) {
75553 + ret = -EINVAL;
75554 + goto out;
75555 + }
75556 + } while_each_thread(task2, task);
75557 +
75558 + /* now actually apply the policy */
75559 +
75560 + do_each_thread(task2, task) {
75561 + if (task->exec_file) {
75562 + role_applied = 0;
75563 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75564 + /* preserve special roles */
75565 + FOR_EACH_ROLE_START(role)
75566 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75567 + task->role = role;
75568 + role_applied = 1;
75569 + break;
75570 + }
75571 + FOR_EACH_ROLE_END(role)
75572 + }
75573 + if (!role_applied) {
75574 + cred = __task_cred(task);
75575 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75576 + }
75577 + /* this handles non-nested inherited subjects, nested subjects will still
75578 + be dropped currently */
75579 + if (!reload_state->oldmode && task->inherited)
75580 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75581 + else {
75582 + /* looked up and tagged to the task previously */
75583 + subj = task->tmpacl;
75584 + }
75585 + /* subj will be non-null */
75586 + __gr_apply_subject_to_task(polstate, task, subj);
75587 + if (reload_state->oldmode) {
75588 + task->acl_role_id = 0;
75589 + task->acl_sp_role = 0;
75590 + task->inherited = 0;
75591 + }
75592 + } else {
75593 + // it's a kernel process
75594 + task->role = polstate->kernel_role;
75595 + task->acl = polstate->kernel_role->root_label;
75596 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75597 + task->acl->mode &= ~GR_PROCFIND;
75598 +#endif
75599 + }
75600 + } while_each_thread(task2, task);
75601 +
75602 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75603 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75604 +
75605 +out:
75606 +
75607 + return ret;
75608 +}
75609 +
75610 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75611 +{
75612 + struct gr_reload_state new_reload_state = { };
75613 + int err;
75614 +
75615 + new_reload_state.oldpolicy_ptr = polstate;
75616 + new_reload_state.oldalloc_ptr = current_alloc_state;
75617 + new_reload_state.oldmode = oldmode;
75618 +
75619 + current_alloc_state = &new_reload_state.newalloc;
75620 + polstate = &new_reload_state.newpolicy;
75621 +
75622 + /* everything relevant is now saved off, copy in the new policy */
75623 + if (init_variables(args, true)) {
75624 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75625 + err = -ENOMEM;
75626 + goto error;
75627 + }
75628 +
75629 + err = copy_user_acl(args);
75630 + free_init_variables();
75631 + if (err)
75632 + goto error;
75633 + /* the new policy is copied in, with the old policy available via saved_state
75634 + first go through applying roles, making sure to preserve special roles
75635 + then apply new subjects, making sure to preserve inherited and nested subjects,
75636 + though currently only inherited subjects will be preserved
75637 + */
75638 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75639 + if (err)
75640 + goto error;
75641 +
75642 + /* we've now applied the new policy, so restore the old policy state to free it */
75643 + polstate = &new_reload_state.oldpolicy;
75644 + current_alloc_state = &new_reload_state.oldalloc;
75645 + free_variables(true);
75646 +
75647 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75648 + to running_polstate/current_alloc_state inside stop_machine
75649 + */
75650 + err = 0;
75651 + goto out;
75652 +error:
75653 + /* on error of loading the new policy, we'll just keep the previous
75654 + policy set around
75655 + */
75656 + free_variables(true);
75657 +
75658 + /* doesn't affect runtime, but maintains consistent state */
75659 +out:
75660 + polstate = new_reload_state.oldpolicy_ptr;
75661 + current_alloc_state = new_reload_state.oldalloc_ptr;
75662 +
75663 + return err;
75664 +}
75665 +
75666 +static int
75667 +gracl_init(struct gr_arg *args)
75668 +{
75669 + int error = 0;
75670 +
75671 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75672 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75673 +
75674 + if (init_variables(args, false)) {
75675 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75676 + error = -ENOMEM;
75677 + goto out;
75678 + }
75679 +
75680 + error = copy_user_acl(args);
75681 + free_init_variables();
75682 + if (error)
75683 + goto out;
75684 +
75685 + error = gr_set_acls(0);
75686 + if (error)
75687 + goto out;
75688 +
75689 + gr_enable_rbac_system();
75690 +
75691 + return 0;
75692 +
75693 +out:
75694 + free_variables(false);
75695 + return error;
75696 +}
75697 +
75698 +static int
75699 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75700 + unsigned char **sum)
75701 +{
75702 + struct acl_role_label *r;
75703 + struct role_allowed_ip *ipp;
75704 + struct role_transition *trans;
75705 + unsigned int i;
75706 + int found = 0;
75707 + u32 curr_ip = current->signal->curr_ip;
75708 +
75709 + current->signal->saved_ip = curr_ip;
75710 +
75711 + /* check transition table */
75712 +
75713 + for (trans = current->role->transitions; trans; trans = trans->next) {
75714 + if (!strcmp(rolename, trans->rolename)) {
75715 + found = 1;
75716 + break;
75717 + }
75718 + }
75719 +
75720 + if (!found)
75721 + return 0;
75722 +
75723 + /* handle special roles that do not require authentication
75724 + and check ip */
75725 +
75726 + FOR_EACH_ROLE_START(r)
75727 + if (!strcmp(rolename, r->rolename) &&
75728 + (r->roletype & GR_ROLE_SPECIAL)) {
75729 + found = 0;
75730 + if (r->allowed_ips != NULL) {
75731 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75732 + if ((ntohl(curr_ip) & ipp->netmask) ==
75733 + (ntohl(ipp->addr) & ipp->netmask))
75734 + found = 1;
75735 + }
75736 + } else
75737 + found = 2;
75738 + if (!found)
75739 + return 0;
75740 +
75741 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75742 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75743 + *salt = NULL;
75744 + *sum = NULL;
75745 + return 1;
75746 + }
75747 + }
75748 + FOR_EACH_ROLE_END(r)
75749 +
75750 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75751 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75752 + *salt = polstate->acl_special_roles[i]->salt;
75753 + *sum = polstate->acl_special_roles[i]->sum;
75754 + return 1;
75755 + }
75756 + }
75757 +
75758 + return 0;
75759 +}
75760 +
75761 +int gr_check_secure_terminal(struct task_struct *task)
75762 +{
75763 + struct task_struct *p, *p2, *p3;
75764 + struct files_struct *files;
75765 + struct fdtable *fdt;
75766 + struct file *our_file = NULL, *file;
75767 + int i;
75768 +
75769 + if (task->signal->tty == NULL)
75770 + return 1;
75771 +
75772 + files = get_files_struct(task);
75773 + if (files != NULL) {
75774 + rcu_read_lock();
75775 + fdt = files_fdtable(files);
75776 + for (i=0; i < fdt->max_fds; i++) {
75777 + file = fcheck_files(files, i);
75778 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75779 + get_file(file);
75780 + our_file = file;
75781 + }
75782 + }
75783 + rcu_read_unlock();
75784 + put_files_struct(files);
75785 + }
75786 +
75787 + if (our_file == NULL)
75788 + return 1;
75789 +
75790 + read_lock(&tasklist_lock);
75791 + do_each_thread(p2, p) {
75792 + files = get_files_struct(p);
75793 + if (files == NULL ||
75794 + (p->signal && p->signal->tty == task->signal->tty)) {
75795 + if (files != NULL)
75796 + put_files_struct(files);
75797 + continue;
75798 + }
75799 + rcu_read_lock();
75800 + fdt = files_fdtable(files);
75801 + for (i=0; i < fdt->max_fds; i++) {
75802 + file = fcheck_files(files, i);
75803 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75804 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75805 + p3 = task;
75806 + while (task_pid_nr(p3) > 0) {
75807 + if (p3 == p)
75808 + break;
75809 + p3 = p3->real_parent;
75810 + }
75811 + if (p3 == p)
75812 + break;
75813 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75814 + gr_handle_alertkill(p);
75815 + rcu_read_unlock();
75816 + put_files_struct(files);
75817 + read_unlock(&tasklist_lock);
75818 + fput(our_file);
75819 + return 0;
75820 + }
75821 + }
75822 + rcu_read_unlock();
75823 + put_files_struct(files);
75824 + } while_each_thread(p2, p);
75825 + read_unlock(&tasklist_lock);
75826 +
75827 + fput(our_file);
75828 + return 1;
75829 +}
75830 +
75831 +ssize_t
75832 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75833 +{
75834 + struct gr_arg_wrapper uwrap;
75835 + unsigned char *sprole_salt = NULL;
75836 + unsigned char *sprole_sum = NULL;
75837 + int error = 0;
75838 + int error2 = 0;
75839 + size_t req_count = 0;
75840 + unsigned char oldmode = 0;
75841 +
75842 + mutex_lock(&gr_dev_mutex);
75843 +
75844 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75845 + error = -EPERM;
75846 + goto out;
75847 + }
75848 +
75849 +#ifdef CONFIG_COMPAT
75850 + pax_open_kernel();
75851 + if (is_compat_task()) {
75852 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75853 + copy_gr_arg = &copy_gr_arg_compat;
75854 + copy_acl_object_label = &copy_acl_object_label_compat;
75855 + copy_acl_subject_label = &copy_acl_subject_label_compat;
75856 + copy_acl_role_label = &copy_acl_role_label_compat;
75857 + copy_acl_ip_label = &copy_acl_ip_label_compat;
75858 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75859 + copy_role_transition = &copy_role_transition_compat;
75860 + copy_sprole_pw = &copy_sprole_pw_compat;
75861 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75862 + copy_pointer_from_array = &copy_pointer_from_array_compat;
75863 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75864 + } else {
75865 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75866 + copy_gr_arg = &copy_gr_arg_normal;
75867 + copy_acl_object_label = &copy_acl_object_label_normal;
75868 + copy_acl_subject_label = &copy_acl_subject_label_normal;
75869 + copy_acl_role_label = &copy_acl_role_label_normal;
75870 + copy_acl_ip_label = &copy_acl_ip_label_normal;
75871 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75872 + copy_role_transition = &copy_role_transition_normal;
75873 + copy_sprole_pw = &copy_sprole_pw_normal;
75874 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75875 + copy_pointer_from_array = &copy_pointer_from_array_normal;
75876 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75877 + }
75878 + pax_close_kernel();
75879 +#endif
75880 +
75881 + req_count = get_gr_arg_wrapper_size();
75882 +
75883 + if (count != req_count) {
75884 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75885 + error = -EINVAL;
75886 + goto out;
75887 + }
75888 +
75889 +
75890 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75891 + gr_auth_expires = 0;
75892 + gr_auth_attempts = 0;
75893 + }
75894 +
75895 + error = copy_gr_arg_wrapper(buf, &uwrap);
75896 + if (error)
75897 + goto out;
75898 +
75899 + error = copy_gr_arg(uwrap.arg, gr_usermode);
75900 + if (error)
75901 + goto out;
75902 +
75903 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75904 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75905 + time_after(gr_auth_expires, get_seconds())) {
75906 + error = -EBUSY;
75907 + goto out;
75908 + }
75909 +
75910 + /* if non-root trying to do anything other than use a special role,
75911 + do not attempt authentication, do not count towards authentication
75912 + locking
75913 + */
75914 +
75915 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75916 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75917 + gr_is_global_nonroot(current_uid())) {
75918 + error = -EPERM;
75919 + goto out;
75920 + }
75921 +
75922 + /* ensure pw and special role name are null terminated */
75923 +
75924 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75925 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75926 +
75927 + /* Okay.
75928 + * We have our enough of the argument structure..(we have yet
75929 + * to copy_from_user the tables themselves) . Copy the tables
75930 + * only if we need them, i.e. for loading operations. */
75931 +
75932 + switch (gr_usermode->mode) {
75933 + case GR_STATUS:
75934 + if (gr_acl_is_enabled()) {
75935 + error = 1;
75936 + if (!gr_check_secure_terminal(current))
75937 + error = 3;
75938 + } else
75939 + error = 2;
75940 + goto out;
75941 + case GR_SHUTDOWN:
75942 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75943 + stop_machine(gr_rbac_disable, NULL, NULL);
75944 + free_variables(false);
75945 + memset(gr_usermode, 0, sizeof(struct gr_arg));
75946 + memset(gr_system_salt, 0, GR_SALT_LEN);
75947 + memset(gr_system_sum, 0, GR_SHA_LEN);
75948 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75949 + } else if (gr_acl_is_enabled()) {
75950 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75951 + error = -EPERM;
75952 + } else {
75953 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75954 + error = -EAGAIN;
75955 + }
75956 + break;
75957 + case GR_ENABLE:
75958 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75959 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75960 + else {
75961 + if (gr_acl_is_enabled())
75962 + error = -EAGAIN;
75963 + else
75964 + error = error2;
75965 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75966 + }
75967 + break;
75968 + case GR_OLDRELOAD:
75969 + oldmode = 1;
75970 + case GR_RELOAD:
75971 + if (!gr_acl_is_enabled()) {
75972 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75973 + error = -EAGAIN;
75974 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75975 + error2 = gracl_reload(gr_usermode, oldmode);
75976 + if (!error2)
75977 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75978 + else {
75979 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75980 + error = error2;
75981 + }
75982 + } else {
75983 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75984 + error = -EPERM;
75985 + }
75986 + break;
75987 + case GR_SEGVMOD:
75988 + if (unlikely(!gr_acl_is_enabled())) {
75989 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75990 + error = -EAGAIN;
75991 + break;
75992 + }
75993 +
75994 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75995 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75996 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75997 + struct acl_subject_label *segvacl;
75998 + segvacl =
75999 + lookup_acl_subj_label(gr_usermode->segv_inode,
76000 + gr_usermode->segv_device,
76001 + current->role);
76002 + if (segvacl) {
76003 + segvacl->crashes = 0;
76004 + segvacl->expires = 0;
76005 + }
76006 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
76007 + gr_remove_uid(gr_usermode->segv_uid);
76008 + }
76009 + } else {
76010 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
76011 + error = -EPERM;
76012 + }
76013 + break;
76014 + case GR_SPROLE:
76015 + case GR_SPROLEPAM:
76016 + if (unlikely(!gr_acl_is_enabled())) {
76017 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
76018 + error = -EAGAIN;
76019 + break;
76020 + }
76021 +
76022 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
76023 + current->role->expires = 0;
76024 + current->role->auth_attempts = 0;
76025 + }
76026 +
76027 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
76028 + time_after(current->role->expires, get_seconds())) {
76029 + error = -EBUSY;
76030 + goto out;
76031 + }
76032 +
76033 + if (lookup_special_role_auth
76034 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
76035 + && ((!sprole_salt && !sprole_sum)
76036 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
76037 + char *p = "";
76038 + assign_special_role(gr_usermode->sp_role);
76039 + read_lock(&tasklist_lock);
76040 + if (current->real_parent)
76041 + p = current->real_parent->role->rolename;
76042 + read_unlock(&tasklist_lock);
76043 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
76044 + p, acl_sp_role_value);
76045 + } else {
76046 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
76047 + error = -EPERM;
76048 + if(!(current->role->auth_attempts++))
76049 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
76050 +
76051 + goto out;
76052 + }
76053 + break;
76054 + case GR_UNSPROLE:
76055 + if (unlikely(!gr_acl_is_enabled())) {
76056 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
76057 + error = -EAGAIN;
76058 + break;
76059 + }
76060 +
76061 + if (current->role->roletype & GR_ROLE_SPECIAL) {
76062 + char *p = "";
76063 + int i = 0;
76064 +
76065 + read_lock(&tasklist_lock);
76066 + if (current->real_parent) {
76067 + p = current->real_parent->role->rolename;
76068 + i = current->real_parent->acl_role_id;
76069 + }
76070 + read_unlock(&tasklist_lock);
76071 +
76072 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
76073 + gr_set_acls(1);
76074 + } else {
76075 + error = -EPERM;
76076 + goto out;
76077 + }
76078 + break;
76079 + default:
76080 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
76081 + error = -EINVAL;
76082 + break;
76083 + }
76084 +
76085 + if (error != -EPERM)
76086 + goto out;
76087 +
76088 + if(!(gr_auth_attempts++))
76089 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
76090 +
76091 + out:
76092 + mutex_unlock(&gr_dev_mutex);
76093 +
76094 + if (!error)
76095 + error = req_count;
76096 +
76097 + return error;
76098 +}
76099 +
76100 +int
76101 +gr_set_acls(const int type)
76102 +{
76103 + struct task_struct *task, *task2;
76104 + struct acl_role_label *role = current->role;
76105 + struct acl_subject_label *subj;
76106 + __u16 acl_role_id = current->acl_role_id;
76107 + const struct cred *cred;
76108 + int ret;
76109 +
76110 + rcu_read_lock();
76111 + read_lock(&tasklist_lock);
76112 + read_lock(&grsec_exec_file_lock);
76113 + do_each_thread(task2, task) {
76114 + /* check to see if we're called from the exit handler,
76115 + if so, only replace ACLs that have inherited the admin
76116 + ACL */
76117 +
76118 + if (type && (task->role != role ||
76119 + task->acl_role_id != acl_role_id))
76120 + continue;
76121 +
76122 + task->acl_role_id = 0;
76123 + task->acl_sp_role = 0;
76124 + task->inherited = 0;
76125 +
76126 + if (task->exec_file) {
76127 + cred = __task_cred(task);
76128 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
76129 + subj = __gr_get_subject_for_task(polstate, task, NULL);
76130 + if (subj == NULL) {
76131 + ret = -EINVAL;
76132 + read_unlock(&grsec_exec_file_lock);
76133 + read_unlock(&tasklist_lock);
76134 + rcu_read_unlock();
76135 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
76136 + return ret;
76137 + }
76138 + __gr_apply_subject_to_task(polstate, task, subj);
76139 + } else {
76140 + // it's a kernel process
76141 + task->role = polstate->kernel_role;
76142 + task->acl = polstate->kernel_role->root_label;
76143 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
76144 + task->acl->mode &= ~GR_PROCFIND;
76145 +#endif
76146 + }
76147 + } while_each_thread(task2, task);
76148 + read_unlock(&grsec_exec_file_lock);
76149 + read_unlock(&tasklist_lock);
76150 + rcu_read_unlock();
76151 +
76152 + return 0;
76153 +}
76154 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
76155 new file mode 100644
76156 index 0000000..39645c9
76157 --- /dev/null
76158 +++ b/grsecurity/gracl_res.c
76159 @@ -0,0 +1,68 @@
76160 +#include <linux/kernel.h>
76161 +#include <linux/sched.h>
76162 +#include <linux/gracl.h>
76163 +#include <linux/grinternal.h>
76164 +
76165 +static const char *restab_log[] = {
76166 + [RLIMIT_CPU] = "RLIMIT_CPU",
76167 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
76168 + [RLIMIT_DATA] = "RLIMIT_DATA",
76169 + [RLIMIT_STACK] = "RLIMIT_STACK",
76170 + [RLIMIT_CORE] = "RLIMIT_CORE",
76171 + [RLIMIT_RSS] = "RLIMIT_RSS",
76172 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
76173 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
76174 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
76175 + [RLIMIT_AS] = "RLIMIT_AS",
76176 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
76177 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
76178 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
76179 + [RLIMIT_NICE] = "RLIMIT_NICE",
76180 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
76181 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
76182 + [GR_CRASH_RES] = "RLIMIT_CRASH"
76183 +};
76184 +
76185 +void
76186 +gr_log_resource(const struct task_struct *task,
76187 + const int res, const unsigned long wanted, const int gt)
76188 +{
76189 + const struct cred *cred;
76190 + unsigned long rlim;
76191 +
76192 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
76193 + return;
76194 +
76195 + // not yet supported resource
76196 + if (unlikely(!restab_log[res]))
76197 + return;
76198 +
76199 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
76200 + rlim = task_rlimit_max(task, res);
76201 + else
76202 + rlim = task_rlimit(task, res);
76203 +
76204 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
76205 + return;
76206 +
76207 + rcu_read_lock();
76208 + cred = __task_cred(task);
76209 +
76210 + if (res == RLIMIT_NPROC &&
76211 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
76212 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
76213 + goto out_rcu_unlock;
76214 + else if (res == RLIMIT_MEMLOCK &&
76215 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
76216 + goto out_rcu_unlock;
76217 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
76218 + goto out_rcu_unlock;
76219 + rcu_read_unlock();
76220 +
76221 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
76222 +
76223 + return;
76224 +out_rcu_unlock:
76225 + rcu_read_unlock();
76226 + return;
76227 +}
76228 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
76229 new file mode 100644
76230 index 0000000..2040e61
76231 --- /dev/null
76232 +++ b/grsecurity/gracl_segv.c
76233 @@ -0,0 +1,313 @@
76234 +#include <linux/kernel.h>
76235 +#include <linux/mm.h>
76236 +#include <asm/uaccess.h>
76237 +#include <asm/errno.h>
76238 +#include <asm/mman.h>
76239 +#include <net/sock.h>
76240 +#include <linux/file.h>
76241 +#include <linux/fs.h>
76242 +#include <linux/net.h>
76243 +#include <linux/in.h>
76244 +#include <linux/slab.h>
76245 +#include <linux/types.h>
76246 +#include <linux/sched.h>
76247 +#include <linux/timer.h>
76248 +#include <linux/gracl.h>
76249 +#include <linux/grsecurity.h>
76250 +#include <linux/grinternal.h>
76251 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
76252 +#include <linux/magic.h>
76253 +#include <linux/pagemap.h>
76254 +#include "../fs/btrfs/async-thread.h"
76255 +#include "../fs/btrfs/ctree.h"
76256 +#include "../fs/btrfs/btrfs_inode.h"
76257 +#endif
76258 +
76259 +static struct crash_uid *uid_set;
76260 +static unsigned short uid_used;
76261 +static DEFINE_SPINLOCK(gr_uid_lock);
76262 +extern rwlock_t gr_inode_lock;
76263 +extern struct acl_subject_label *
76264 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
76265 + struct acl_role_label *role);
76266 +
76267 +static inline dev_t __get_dev(const struct dentry *dentry)
76268 +{
76269 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
76270 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
76271 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
76272 + else
76273 +#endif
76274 + return dentry->d_sb->s_dev;
76275 +}
76276 +
76277 +int
76278 +gr_init_uidset(void)
76279 +{
76280 + uid_set =
76281 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
76282 + uid_used = 0;
76283 +
76284 + return uid_set ? 1 : 0;
76285 +}
76286 +
76287 +void
76288 +gr_free_uidset(void)
76289 +{
76290 + if (uid_set) {
76291 + struct crash_uid *tmpset;
76292 + spin_lock(&gr_uid_lock);
76293 + tmpset = uid_set;
76294 + uid_set = NULL;
76295 + uid_used = 0;
76296 + spin_unlock(&gr_uid_lock);
76297 + if (tmpset)
76298 + kfree(tmpset);
76299 + }
76300 +
76301 + return;
76302 +}
76303 +
76304 +int
76305 +gr_find_uid(const uid_t uid)
76306 +{
76307 + struct crash_uid *tmp = uid_set;
76308 + uid_t buid;
76309 + int low = 0, high = uid_used - 1, mid;
76310 +
76311 + while (high >= low) {
76312 + mid = (low + high) >> 1;
76313 + buid = tmp[mid].uid;
76314 + if (buid == uid)
76315 + return mid;
76316 + if (buid > uid)
76317 + high = mid - 1;
76318 + if (buid < uid)
76319 + low = mid + 1;
76320 + }
76321 +
76322 + return -1;
76323 +}
76324 +
76325 +static __inline__ void
76326 +gr_insertsort(void)
76327 +{
76328 + unsigned short i, j;
76329 + struct crash_uid index;
76330 +
76331 + for (i = 1; i < uid_used; i++) {
76332 + index = uid_set[i];
76333 + j = i;
76334 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
76335 + uid_set[j] = uid_set[j - 1];
76336 + j--;
76337 + }
76338 + uid_set[j] = index;
76339 + }
76340 +
76341 + return;
76342 +}
76343 +
76344 +static __inline__ void
76345 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
76346 +{
76347 + int loc;
76348 + uid_t uid = GR_GLOBAL_UID(kuid);
76349 +
76350 + if (uid_used == GR_UIDTABLE_MAX)
76351 + return;
76352 +
76353 + loc = gr_find_uid(uid);
76354 +
76355 + if (loc >= 0) {
76356 + uid_set[loc].expires = expires;
76357 + return;
76358 + }
76359 +
76360 + uid_set[uid_used].uid = uid;
76361 + uid_set[uid_used].expires = expires;
76362 + uid_used++;
76363 +
76364 + gr_insertsort();
76365 +
76366 + return;
76367 +}
76368 +
76369 +void
76370 +gr_remove_uid(const unsigned short loc)
76371 +{
76372 + unsigned short i;
76373 +
76374 + for (i = loc + 1; i < uid_used; i++)
76375 + uid_set[i - 1] = uid_set[i];
76376 +
76377 + uid_used--;
76378 +
76379 + return;
76380 +}
76381 +
76382 +int
76383 +gr_check_crash_uid(const kuid_t kuid)
76384 +{
76385 + int loc;
76386 + int ret = 0;
76387 + uid_t uid;
76388 +
76389 + if (unlikely(!gr_acl_is_enabled()))
76390 + return 0;
76391 +
76392 + uid = GR_GLOBAL_UID(kuid);
76393 +
76394 + spin_lock(&gr_uid_lock);
76395 + loc = gr_find_uid(uid);
76396 +
76397 + if (loc < 0)
76398 + goto out_unlock;
76399 +
76400 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
76401 + gr_remove_uid(loc);
76402 + else
76403 + ret = 1;
76404 +
76405 +out_unlock:
76406 + spin_unlock(&gr_uid_lock);
76407 + return ret;
76408 +}
76409 +
76410 +static __inline__ int
76411 +proc_is_setxid(const struct cred *cred)
76412 +{
76413 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
76414 + !uid_eq(cred->uid, cred->fsuid))
76415 + return 1;
76416 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
76417 + !gid_eq(cred->gid, cred->fsgid))
76418 + return 1;
76419 +
76420 + return 0;
76421 +}
76422 +
76423 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
76424 +
76425 +void
76426 +gr_handle_crash(struct task_struct *task, const int sig)
76427 +{
76428 + struct acl_subject_label *curr;
76429 + struct task_struct *tsk, *tsk2;
76430 + const struct cred *cred;
76431 + const struct cred *cred2;
76432 +
76433 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
76434 + return;
76435 +
76436 + if (unlikely(!gr_acl_is_enabled()))
76437 + return;
76438 +
76439 + curr = task->acl;
76440 +
76441 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
76442 + return;
76443 +
76444 + if (time_before_eq(curr->expires, get_seconds())) {
76445 + curr->expires = 0;
76446 + curr->crashes = 0;
76447 + }
76448 +
76449 + curr->crashes++;
76450 +
76451 + if (!curr->expires)
76452 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
76453 +
76454 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76455 + time_after(curr->expires, get_seconds())) {
76456 + rcu_read_lock();
76457 + cred = __task_cred(task);
76458 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
76459 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76460 + spin_lock(&gr_uid_lock);
76461 + gr_insert_uid(cred->uid, curr->expires);
76462 + spin_unlock(&gr_uid_lock);
76463 + curr->expires = 0;
76464 + curr->crashes = 0;
76465 + read_lock(&tasklist_lock);
76466 + do_each_thread(tsk2, tsk) {
76467 + cred2 = __task_cred(tsk);
76468 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
76469 + gr_fake_force_sig(SIGKILL, tsk);
76470 + } while_each_thread(tsk2, tsk);
76471 + read_unlock(&tasklist_lock);
76472 + } else {
76473 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76474 + read_lock(&tasklist_lock);
76475 + read_lock(&grsec_exec_file_lock);
76476 + do_each_thread(tsk2, tsk) {
76477 + if (likely(tsk != task)) {
76478 + // if this thread has the same subject as the one that triggered
76479 + // RES_CRASH and it's the same binary, kill it
76480 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
76481 + gr_fake_force_sig(SIGKILL, tsk);
76482 + }
76483 + } while_each_thread(tsk2, tsk);
76484 + read_unlock(&grsec_exec_file_lock);
76485 + read_unlock(&tasklist_lock);
76486 + }
76487 + rcu_read_unlock();
76488 + }
76489 +
76490 + return;
76491 +}
76492 +
76493 +int
76494 +gr_check_crash_exec(const struct file *filp)
76495 +{
76496 + struct acl_subject_label *curr;
76497 +
76498 + if (unlikely(!gr_acl_is_enabled()))
76499 + return 0;
76500 +
76501 + read_lock(&gr_inode_lock);
76502 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
76503 + __get_dev(filp->f_path.dentry),
76504 + current->role);
76505 + read_unlock(&gr_inode_lock);
76506 +
76507 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
76508 + (!curr->crashes && !curr->expires))
76509 + return 0;
76510 +
76511 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76512 + time_after(curr->expires, get_seconds()))
76513 + return 1;
76514 + else if (time_before_eq(curr->expires, get_seconds())) {
76515 + curr->crashes = 0;
76516 + curr->expires = 0;
76517 + }
76518 +
76519 + return 0;
76520 +}
76521 +
76522 +void
76523 +gr_handle_alertkill(struct task_struct *task)
76524 +{
76525 + struct acl_subject_label *curracl;
76526 + __u32 curr_ip;
76527 + struct task_struct *p, *p2;
76528 +
76529 + if (unlikely(!gr_acl_is_enabled()))
76530 + return;
76531 +
76532 + curracl = task->acl;
76533 + curr_ip = task->signal->curr_ip;
76534 +
76535 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
76536 + read_lock(&tasklist_lock);
76537 + do_each_thread(p2, p) {
76538 + if (p->signal->curr_ip == curr_ip)
76539 + gr_fake_force_sig(SIGKILL, p);
76540 + } while_each_thread(p2, p);
76541 + read_unlock(&tasklist_lock);
76542 + } else if (curracl->mode & GR_KILLPROC)
76543 + gr_fake_force_sig(SIGKILL, task);
76544 +
76545 + return;
76546 +}
76547 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
76548 new file mode 100644
76549 index 0000000..98011b0
76550 --- /dev/null
76551 +++ b/grsecurity/gracl_shm.c
76552 @@ -0,0 +1,40 @@
76553 +#include <linux/kernel.h>
76554 +#include <linux/mm.h>
76555 +#include <linux/sched.h>
76556 +#include <linux/file.h>
76557 +#include <linux/ipc.h>
76558 +#include <linux/gracl.h>
76559 +#include <linux/grsecurity.h>
76560 +#include <linux/grinternal.h>
76561 +
76562 +int
76563 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76564 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
76565 +{
76566 + struct task_struct *task;
76567 +
76568 + if (!gr_acl_is_enabled())
76569 + return 1;
76570 +
76571 + rcu_read_lock();
76572 + read_lock(&tasklist_lock);
76573 +
76574 + task = find_task_by_vpid(shm_cprid);
76575 +
76576 + if (unlikely(!task))
76577 + task = find_task_by_vpid(shm_lapid);
76578 +
76579 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
76580 + (task_pid_nr(task) == shm_lapid)) &&
76581 + (task->acl->mode & GR_PROTSHM) &&
76582 + (task->acl != current->acl))) {
76583 + read_unlock(&tasklist_lock);
76584 + rcu_read_unlock();
76585 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76586 + return 0;
76587 + }
76588 + read_unlock(&tasklist_lock);
76589 + rcu_read_unlock();
76590 +
76591 + return 1;
76592 +}
76593 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76594 new file mode 100644
76595 index 0000000..bc0be01
76596 --- /dev/null
76597 +++ b/grsecurity/grsec_chdir.c
76598 @@ -0,0 +1,19 @@
76599 +#include <linux/kernel.h>
76600 +#include <linux/sched.h>
76601 +#include <linux/fs.h>
76602 +#include <linux/file.h>
76603 +#include <linux/grsecurity.h>
76604 +#include <linux/grinternal.h>
76605 +
76606 +void
76607 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76608 +{
76609 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76610 + if ((grsec_enable_chdir && grsec_enable_group &&
76611 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76612 + !grsec_enable_group)) {
76613 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76614 + }
76615 +#endif
76616 + return;
76617 +}
76618 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76619 new file mode 100644
76620 index 0000000..baa635c
76621 --- /dev/null
76622 +++ b/grsecurity/grsec_chroot.c
76623 @@ -0,0 +1,387 @@
76624 +#include <linux/kernel.h>
76625 +#include <linux/module.h>
76626 +#include <linux/sched.h>
76627 +#include <linux/file.h>
76628 +#include <linux/fs.h>
76629 +#include <linux/mount.h>
76630 +#include <linux/types.h>
76631 +#include "../fs/mount.h"
76632 +#include <linux/grsecurity.h>
76633 +#include <linux/grinternal.h>
76634 +
76635 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76636 +int gr_init_ran;
76637 +#endif
76638 +
76639 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76640 +{
76641 +#ifdef CONFIG_GRKERNSEC
76642 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76643 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76644 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76645 + && gr_init_ran
76646 +#endif
76647 + )
76648 + task->gr_is_chrooted = 1;
76649 + else {
76650 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76651 + if (task_pid_nr(task) == 1 && !gr_init_ran)
76652 + gr_init_ran = 1;
76653 +#endif
76654 + task->gr_is_chrooted = 0;
76655 + }
76656 +
76657 + task->gr_chroot_dentry = path->dentry;
76658 +#endif
76659 + return;
76660 +}
76661 +
76662 +void gr_clear_chroot_entries(struct task_struct *task)
76663 +{
76664 +#ifdef CONFIG_GRKERNSEC
76665 + task->gr_is_chrooted = 0;
76666 + task->gr_chroot_dentry = NULL;
76667 +#endif
76668 + return;
76669 +}
76670 +
76671 +int
76672 +gr_handle_chroot_unix(const pid_t pid)
76673 +{
76674 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76675 + struct task_struct *p;
76676 +
76677 + if (unlikely(!grsec_enable_chroot_unix))
76678 + return 1;
76679 +
76680 + if (likely(!proc_is_chrooted(current)))
76681 + return 1;
76682 +
76683 + rcu_read_lock();
76684 + read_lock(&tasklist_lock);
76685 + p = find_task_by_vpid_unrestricted(pid);
76686 + if (unlikely(p && !have_same_root(current, p))) {
76687 + read_unlock(&tasklist_lock);
76688 + rcu_read_unlock();
76689 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76690 + return 0;
76691 + }
76692 + read_unlock(&tasklist_lock);
76693 + rcu_read_unlock();
76694 +#endif
76695 + return 1;
76696 +}
76697 +
76698 +int
76699 +gr_handle_chroot_nice(void)
76700 +{
76701 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76702 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76703 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76704 + return -EPERM;
76705 + }
76706 +#endif
76707 + return 0;
76708 +}
76709 +
76710 +int
76711 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76712 +{
76713 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76714 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76715 + && proc_is_chrooted(current)) {
76716 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76717 + return -EACCES;
76718 + }
76719 +#endif
76720 + return 0;
76721 +}
76722 +
76723 +int
76724 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76725 +{
76726 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76727 + struct task_struct *p;
76728 + int ret = 0;
76729 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76730 + return ret;
76731 +
76732 + read_lock(&tasklist_lock);
76733 + do_each_pid_task(pid, type, p) {
76734 + if (!have_same_root(current, p)) {
76735 + ret = 1;
76736 + goto out;
76737 + }
76738 + } while_each_pid_task(pid, type, p);
76739 +out:
76740 + read_unlock(&tasklist_lock);
76741 + return ret;
76742 +#endif
76743 + return 0;
76744 +}
76745 +
76746 +int
76747 +gr_pid_is_chrooted(struct task_struct *p)
76748 +{
76749 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76750 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76751 + return 0;
76752 +
76753 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76754 + !have_same_root(current, p)) {
76755 + return 1;
76756 + }
76757 +#endif
76758 + return 0;
76759 +}
76760 +
76761 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76762 +
76763 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76764 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76765 +{
76766 + struct path path, currentroot;
76767 + int ret = 0;
76768 +
76769 + path.dentry = (struct dentry *)u_dentry;
76770 + path.mnt = (struct vfsmount *)u_mnt;
76771 + get_fs_root(current->fs, &currentroot);
76772 + if (path_is_under(&path, &currentroot))
76773 + ret = 1;
76774 + path_put(&currentroot);
76775 +
76776 + return ret;
76777 +}
76778 +#endif
76779 +
76780 +int
76781 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76782 +{
76783 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76784 + if (!grsec_enable_chroot_fchdir)
76785 + return 1;
76786 +
76787 + if (!proc_is_chrooted(current))
76788 + return 1;
76789 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76790 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76791 + return 0;
76792 + }
76793 +#endif
76794 + return 1;
76795 +}
76796 +
76797 +int
76798 +gr_chroot_fhandle(void)
76799 +{
76800 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76801 + if (!grsec_enable_chroot_fchdir)
76802 + return 1;
76803 +
76804 + if (!proc_is_chrooted(current))
76805 + return 1;
76806 + else {
76807 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76808 + return 0;
76809 + }
76810 +#endif
76811 + return 1;
76812 +}
76813 +
76814 +int
76815 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76816 + const time_t shm_createtime)
76817 +{
76818 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76819 + struct task_struct *p;
76820 + time_t starttime;
76821 +
76822 + if (unlikely(!grsec_enable_chroot_shmat))
76823 + return 1;
76824 +
76825 + if (likely(!proc_is_chrooted(current)))
76826 + return 1;
76827 +
76828 + rcu_read_lock();
76829 + read_lock(&tasklist_lock);
76830 +
76831 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76832 + starttime = p->start_time.tv_sec;
76833 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
76834 + if (have_same_root(current, p)) {
76835 + goto allow;
76836 + } else {
76837 + read_unlock(&tasklist_lock);
76838 + rcu_read_unlock();
76839 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76840 + return 0;
76841 + }
76842 + }
76843 + /* creator exited, pid reuse, fall through to next check */
76844 + }
76845 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76846 + if (unlikely(!have_same_root(current, p))) {
76847 + read_unlock(&tasklist_lock);
76848 + rcu_read_unlock();
76849 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76850 + return 0;
76851 + }
76852 + }
76853 +
76854 +allow:
76855 + read_unlock(&tasklist_lock);
76856 + rcu_read_unlock();
76857 +#endif
76858 + return 1;
76859 +}
76860 +
76861 +void
76862 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76863 +{
76864 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76865 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76866 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76867 +#endif
76868 + return;
76869 +}
76870 +
76871 +int
76872 +gr_handle_chroot_mknod(const struct dentry *dentry,
76873 + const struct vfsmount *mnt, const int mode)
76874 +{
76875 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76876 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76877 + proc_is_chrooted(current)) {
76878 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76879 + return -EPERM;
76880 + }
76881 +#endif
76882 + return 0;
76883 +}
76884 +
76885 +int
76886 +gr_handle_chroot_mount(const struct dentry *dentry,
76887 + const struct vfsmount *mnt, const char *dev_name)
76888 +{
76889 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76890 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76891 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76892 + return -EPERM;
76893 + }
76894 +#endif
76895 + return 0;
76896 +}
76897 +
76898 +int
76899 +gr_handle_chroot_pivot(void)
76900 +{
76901 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76902 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76903 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76904 + return -EPERM;
76905 + }
76906 +#endif
76907 + return 0;
76908 +}
76909 +
76910 +int
76911 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76912 +{
76913 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76914 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76915 + !gr_is_outside_chroot(dentry, mnt)) {
76916 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76917 + return -EPERM;
76918 + }
76919 +#endif
76920 + return 0;
76921 +}
76922 +
76923 +extern const char *captab_log[];
76924 +extern int captab_log_entries;
76925 +
76926 +int
76927 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76928 +{
76929 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76930 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76931 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76932 + if (cap_raised(chroot_caps, cap)) {
76933 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76934 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76935 + }
76936 + return 0;
76937 + }
76938 + }
76939 +#endif
76940 + return 1;
76941 +}
76942 +
76943 +int
76944 +gr_chroot_is_capable(const int cap)
76945 +{
76946 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76947 + return gr_task_chroot_is_capable(current, current_cred(), cap);
76948 +#endif
76949 + return 1;
76950 +}
76951 +
76952 +int
76953 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76954 +{
76955 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76956 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76957 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76958 + if (cap_raised(chroot_caps, cap)) {
76959 + return 0;
76960 + }
76961 + }
76962 +#endif
76963 + return 1;
76964 +}
76965 +
76966 +int
76967 +gr_chroot_is_capable_nolog(const int cap)
76968 +{
76969 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76970 + return gr_task_chroot_is_capable_nolog(current, cap);
76971 +#endif
76972 + return 1;
76973 +}
76974 +
76975 +int
76976 +gr_handle_chroot_sysctl(const int op)
76977 +{
76978 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76979 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76980 + proc_is_chrooted(current))
76981 + return -EACCES;
76982 +#endif
76983 + return 0;
76984 +}
76985 +
76986 +void
76987 +gr_handle_chroot_chdir(const struct path *path)
76988 +{
76989 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76990 + if (grsec_enable_chroot_chdir)
76991 + set_fs_pwd(current->fs, path);
76992 +#endif
76993 + return;
76994 +}
76995 +
76996 +int
76997 +gr_handle_chroot_chmod(const struct dentry *dentry,
76998 + const struct vfsmount *mnt, const int mode)
76999 +{
77000 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77001 + /* allow chmod +s on directories, but not files */
77002 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
77003 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
77004 + proc_is_chrooted(current)) {
77005 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
77006 + return -EPERM;
77007 + }
77008 +#endif
77009 + return 0;
77010 +}
77011 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
77012 new file mode 100644
77013 index 0000000..2d3bcb7
77014 --- /dev/null
77015 +++ b/grsecurity/grsec_disabled.c
77016 @@ -0,0 +1,440 @@
77017 +#include <linux/kernel.h>
77018 +#include <linux/module.h>
77019 +#include <linux/sched.h>
77020 +#include <linux/file.h>
77021 +#include <linux/fs.h>
77022 +#include <linux/kdev_t.h>
77023 +#include <linux/net.h>
77024 +#include <linux/in.h>
77025 +#include <linux/ip.h>
77026 +#include <linux/skbuff.h>
77027 +#include <linux/sysctl.h>
77028 +
77029 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
77030 +void
77031 +pax_set_initial_flags(struct linux_binprm *bprm)
77032 +{
77033 + return;
77034 +}
77035 +#endif
77036 +
77037 +#ifdef CONFIG_SYSCTL
77038 +__u32
77039 +gr_handle_sysctl(const struct ctl_table * table, const int op)
77040 +{
77041 + return 0;
77042 +}
77043 +#endif
77044 +
77045 +#ifdef CONFIG_TASKSTATS
77046 +int gr_is_taskstats_denied(int pid)
77047 +{
77048 + return 0;
77049 +}
77050 +#endif
77051 +
77052 +int
77053 +gr_acl_is_enabled(void)
77054 +{
77055 + return 0;
77056 +}
77057 +
77058 +int
77059 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
77060 +{
77061 + return 0;
77062 +}
77063 +
77064 +void
77065 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
77066 +{
77067 + return;
77068 +}
77069 +
77070 +int
77071 +gr_handle_rawio(const struct inode *inode)
77072 +{
77073 + return 0;
77074 +}
77075 +
77076 +void
77077 +gr_acl_handle_psacct(struct task_struct *task, const long code)
77078 +{
77079 + return;
77080 +}
77081 +
77082 +int
77083 +gr_handle_ptrace(struct task_struct *task, const long request)
77084 +{
77085 + return 0;
77086 +}
77087 +
77088 +int
77089 +gr_handle_proc_ptrace(struct task_struct *task)
77090 +{
77091 + return 0;
77092 +}
77093 +
77094 +int
77095 +gr_set_acls(const int type)
77096 +{
77097 + return 0;
77098 +}
77099 +
77100 +int
77101 +gr_check_hidden_task(const struct task_struct *tsk)
77102 +{
77103 + return 0;
77104 +}
77105 +
77106 +int
77107 +gr_check_protected_task(const struct task_struct *task)
77108 +{
77109 + return 0;
77110 +}
77111 +
77112 +int
77113 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
77114 +{
77115 + return 0;
77116 +}
77117 +
77118 +void
77119 +gr_copy_label(struct task_struct *tsk)
77120 +{
77121 + return;
77122 +}
77123 +
77124 +void
77125 +gr_set_pax_flags(struct task_struct *task)
77126 +{
77127 + return;
77128 +}
77129 +
77130 +int
77131 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
77132 + const int unsafe_share)
77133 +{
77134 + return 0;
77135 +}
77136 +
77137 +void
77138 +gr_handle_delete(const ino_t ino, const dev_t dev)
77139 +{
77140 + return;
77141 +}
77142 +
77143 +void
77144 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
77145 +{
77146 + return;
77147 +}
77148 +
77149 +void
77150 +gr_handle_crash(struct task_struct *task, const int sig)
77151 +{
77152 + return;
77153 +}
77154 +
77155 +int
77156 +gr_check_crash_exec(const struct file *filp)
77157 +{
77158 + return 0;
77159 +}
77160 +
77161 +int
77162 +gr_check_crash_uid(const kuid_t uid)
77163 +{
77164 + return 0;
77165 +}
77166 +
77167 +void
77168 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
77169 + struct dentry *old_dentry,
77170 + struct dentry *new_dentry,
77171 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
77172 +{
77173 + return;
77174 +}
77175 +
77176 +int
77177 +gr_search_socket(const int family, const int type, const int protocol)
77178 +{
77179 + return 1;
77180 +}
77181 +
77182 +int
77183 +gr_search_connectbind(const int mode, const struct socket *sock,
77184 + const struct sockaddr_in *addr)
77185 +{
77186 + return 0;
77187 +}
77188 +
77189 +void
77190 +gr_handle_alertkill(struct task_struct *task)
77191 +{
77192 + return;
77193 +}
77194 +
77195 +__u32
77196 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
77197 +{
77198 + return 1;
77199 +}
77200 +
77201 +__u32
77202 +gr_acl_handle_hidden_file(const struct dentry * dentry,
77203 + const struct vfsmount * mnt)
77204 +{
77205 + return 1;
77206 +}
77207 +
77208 +__u32
77209 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
77210 + int acc_mode)
77211 +{
77212 + return 1;
77213 +}
77214 +
77215 +__u32
77216 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
77217 +{
77218 + return 1;
77219 +}
77220 +
77221 +__u32
77222 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
77223 +{
77224 + return 1;
77225 +}
77226 +
77227 +int
77228 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
77229 + unsigned int *vm_flags)
77230 +{
77231 + return 1;
77232 +}
77233 +
77234 +__u32
77235 +gr_acl_handle_truncate(const struct dentry * dentry,
77236 + const struct vfsmount * mnt)
77237 +{
77238 + return 1;
77239 +}
77240 +
77241 +__u32
77242 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
77243 +{
77244 + return 1;
77245 +}
77246 +
77247 +__u32
77248 +gr_acl_handle_access(const struct dentry * dentry,
77249 + const struct vfsmount * mnt, const int fmode)
77250 +{
77251 + return 1;
77252 +}
77253 +
77254 +__u32
77255 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
77256 + umode_t *mode)
77257 +{
77258 + return 1;
77259 +}
77260 +
77261 +__u32
77262 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
77263 +{
77264 + return 1;
77265 +}
77266 +
77267 +__u32
77268 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
77269 +{
77270 + return 1;
77271 +}
77272 +
77273 +__u32
77274 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
77275 +{
77276 + return 1;
77277 +}
77278 +
77279 +void
77280 +grsecurity_init(void)
77281 +{
77282 + return;
77283 +}
77284 +
77285 +umode_t gr_acl_umask(void)
77286 +{
77287 + return 0;
77288 +}
77289 +
77290 +__u32
77291 +gr_acl_handle_mknod(const struct dentry * new_dentry,
77292 + const struct dentry * parent_dentry,
77293 + const struct vfsmount * parent_mnt,
77294 + const int mode)
77295 +{
77296 + return 1;
77297 +}
77298 +
77299 +__u32
77300 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
77301 + const struct dentry * parent_dentry,
77302 + const struct vfsmount * parent_mnt)
77303 +{
77304 + return 1;
77305 +}
77306 +
77307 +__u32
77308 +gr_acl_handle_symlink(const struct dentry * new_dentry,
77309 + const struct dentry * parent_dentry,
77310 + const struct vfsmount * parent_mnt, const struct filename *from)
77311 +{
77312 + return 1;
77313 +}
77314 +
77315 +__u32
77316 +gr_acl_handle_link(const struct dentry * new_dentry,
77317 + const struct dentry * parent_dentry,
77318 + const struct vfsmount * parent_mnt,
77319 + const struct dentry * old_dentry,
77320 + const struct vfsmount * old_mnt, const struct filename *to)
77321 +{
77322 + return 1;
77323 +}
77324 +
77325 +int
77326 +gr_acl_handle_rename(const struct dentry *new_dentry,
77327 + const struct dentry *parent_dentry,
77328 + const struct vfsmount *parent_mnt,
77329 + const struct dentry *old_dentry,
77330 + const struct inode *old_parent_inode,
77331 + const struct vfsmount *old_mnt, const struct filename *newname,
77332 + unsigned int flags)
77333 +{
77334 + return 0;
77335 +}
77336 +
77337 +int
77338 +gr_acl_handle_filldir(const struct file *file, const char *name,
77339 + const int namelen, const ino_t ino)
77340 +{
77341 + return 1;
77342 +}
77343 +
77344 +int
77345 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77346 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
77347 +{
77348 + return 1;
77349 +}
77350 +
77351 +int
77352 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
77353 +{
77354 + return 0;
77355 +}
77356 +
77357 +int
77358 +gr_search_accept(const struct socket *sock)
77359 +{
77360 + return 0;
77361 +}
77362 +
77363 +int
77364 +gr_search_listen(const struct socket *sock)
77365 +{
77366 + return 0;
77367 +}
77368 +
77369 +int
77370 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
77371 +{
77372 + return 0;
77373 +}
77374 +
77375 +__u32
77376 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
77377 +{
77378 + return 1;
77379 +}
77380 +
77381 +__u32
77382 +gr_acl_handle_creat(const struct dentry * dentry,
77383 + const struct dentry * p_dentry,
77384 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
77385 + const int imode)
77386 +{
77387 + return 1;
77388 +}
77389 +
77390 +void
77391 +gr_acl_handle_exit(void)
77392 +{
77393 + return;
77394 +}
77395 +
77396 +int
77397 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
77398 +{
77399 + return 1;
77400 +}
77401 +
77402 +void
77403 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
77404 +{
77405 + return;
77406 +}
77407 +
77408 +int
77409 +gr_acl_handle_procpidmem(const struct task_struct *task)
77410 +{
77411 + return 0;
77412 +}
77413 +
77414 +int
77415 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
77416 +{
77417 + return 0;
77418 +}
77419 +
77420 +int
77421 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
77422 +{
77423 + return 0;
77424 +}
77425 +
77426 +int
77427 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
77428 +{
77429 + return 0;
77430 +}
77431 +
77432 +int
77433 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
77434 +{
77435 + return 0;
77436 +}
77437 +
77438 +int gr_acl_enable_at_secure(void)
77439 +{
77440 + return 0;
77441 +}
77442 +
77443 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
77444 +{
77445 + return dentry->d_sb->s_dev;
77446 +}
77447 +
77448 +void gr_put_exec_file(struct task_struct *task)
77449 +{
77450 + return;
77451 +}
77452 +
77453 +#ifdef CONFIG_SECURITY
77454 +EXPORT_SYMBOL_GPL(gr_check_user_change);
77455 +EXPORT_SYMBOL_GPL(gr_check_group_change);
77456 +#endif
77457 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
77458 new file mode 100644
77459 index 0000000..14638ff
77460 --- /dev/null
77461 +++ b/grsecurity/grsec_exec.c
77462 @@ -0,0 +1,188 @@
77463 +#include <linux/kernel.h>
77464 +#include <linux/sched.h>
77465 +#include <linux/file.h>
77466 +#include <linux/binfmts.h>
77467 +#include <linux/fs.h>
77468 +#include <linux/types.h>
77469 +#include <linux/grdefs.h>
77470 +#include <linux/grsecurity.h>
77471 +#include <linux/grinternal.h>
77472 +#include <linux/capability.h>
77473 +#include <linux/module.h>
77474 +#include <linux/compat.h>
77475 +
77476 +#include <asm/uaccess.h>
77477 +
77478 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77479 +static char gr_exec_arg_buf[132];
77480 +static DEFINE_MUTEX(gr_exec_arg_mutex);
77481 +#endif
77482 +
77483 +struct user_arg_ptr {
77484 +#ifdef CONFIG_COMPAT
77485 + bool is_compat;
77486 +#endif
77487 + union {
77488 + const char __user *const __user *native;
77489 +#ifdef CONFIG_COMPAT
77490 + const compat_uptr_t __user *compat;
77491 +#endif
77492 + } ptr;
77493 +};
77494 +
77495 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
77496 +
77497 +void
77498 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
77499 +{
77500 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77501 + char *grarg = gr_exec_arg_buf;
77502 + unsigned int i, x, execlen = 0;
77503 + char c;
77504 +
77505 + if (!((grsec_enable_execlog && grsec_enable_group &&
77506 + in_group_p(grsec_audit_gid))
77507 + || (grsec_enable_execlog && !grsec_enable_group)))
77508 + return;
77509 +
77510 + mutex_lock(&gr_exec_arg_mutex);
77511 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
77512 +
77513 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
77514 + const char __user *p;
77515 + unsigned int len;
77516 +
77517 + p = get_user_arg_ptr(argv, i);
77518 + if (IS_ERR(p))
77519 + goto log;
77520 +
77521 + len = strnlen_user(p, 128 - execlen);
77522 + if (len > 128 - execlen)
77523 + len = 128 - execlen;
77524 + else if (len > 0)
77525 + len--;
77526 + if (copy_from_user(grarg + execlen, p, len))
77527 + goto log;
77528 +
77529 + /* rewrite unprintable characters */
77530 + for (x = 0; x < len; x++) {
77531 + c = *(grarg + execlen + x);
77532 + if (c < 32 || c > 126)
77533 + *(grarg + execlen + x) = ' ';
77534 + }
77535 +
77536 + execlen += len;
77537 + *(grarg + execlen) = ' ';
77538 + *(grarg + execlen + 1) = '\0';
77539 + execlen++;
77540 + }
77541 +
77542 + log:
77543 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
77544 + bprm->file->f_path.mnt, grarg);
77545 + mutex_unlock(&gr_exec_arg_mutex);
77546 +#endif
77547 + return;
77548 +}
77549 +
77550 +#ifdef CONFIG_GRKERNSEC
77551 +extern int gr_acl_is_capable(const int cap);
77552 +extern int gr_acl_is_capable_nolog(const int cap);
77553 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77554 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77555 +extern int gr_chroot_is_capable(const int cap);
77556 +extern int gr_chroot_is_capable_nolog(const int cap);
77557 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77558 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77559 +#endif
77560 +
77561 +const char *captab_log[] = {
77562 + "CAP_CHOWN",
77563 + "CAP_DAC_OVERRIDE",
77564 + "CAP_DAC_READ_SEARCH",
77565 + "CAP_FOWNER",
77566 + "CAP_FSETID",
77567 + "CAP_KILL",
77568 + "CAP_SETGID",
77569 + "CAP_SETUID",
77570 + "CAP_SETPCAP",
77571 + "CAP_LINUX_IMMUTABLE",
77572 + "CAP_NET_BIND_SERVICE",
77573 + "CAP_NET_BROADCAST",
77574 + "CAP_NET_ADMIN",
77575 + "CAP_NET_RAW",
77576 + "CAP_IPC_LOCK",
77577 + "CAP_IPC_OWNER",
77578 + "CAP_SYS_MODULE",
77579 + "CAP_SYS_RAWIO",
77580 + "CAP_SYS_CHROOT",
77581 + "CAP_SYS_PTRACE",
77582 + "CAP_SYS_PACCT",
77583 + "CAP_SYS_ADMIN",
77584 + "CAP_SYS_BOOT",
77585 + "CAP_SYS_NICE",
77586 + "CAP_SYS_RESOURCE",
77587 + "CAP_SYS_TIME",
77588 + "CAP_SYS_TTY_CONFIG",
77589 + "CAP_MKNOD",
77590 + "CAP_LEASE",
77591 + "CAP_AUDIT_WRITE",
77592 + "CAP_AUDIT_CONTROL",
77593 + "CAP_SETFCAP",
77594 + "CAP_MAC_OVERRIDE",
77595 + "CAP_MAC_ADMIN",
77596 + "CAP_SYSLOG",
77597 + "CAP_WAKE_ALARM",
77598 + "CAP_BLOCK_SUSPEND"
77599 +};
77600 +
77601 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77602 +
77603 +int gr_is_capable(const int cap)
77604 +{
77605 +#ifdef CONFIG_GRKERNSEC
77606 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77607 + return 1;
77608 + return 0;
77609 +#else
77610 + return 1;
77611 +#endif
77612 +}
77613 +
77614 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77615 +{
77616 +#ifdef CONFIG_GRKERNSEC
77617 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77618 + return 1;
77619 + return 0;
77620 +#else
77621 + return 1;
77622 +#endif
77623 +}
77624 +
77625 +int gr_is_capable_nolog(const int cap)
77626 +{
77627 +#ifdef CONFIG_GRKERNSEC
77628 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77629 + return 1;
77630 + return 0;
77631 +#else
77632 + return 1;
77633 +#endif
77634 +}
77635 +
77636 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77637 +{
77638 +#ifdef CONFIG_GRKERNSEC
77639 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77640 + return 1;
77641 + return 0;
77642 +#else
77643 + return 1;
77644 +#endif
77645 +}
77646 +
77647 +EXPORT_SYMBOL_GPL(gr_is_capable);
77648 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77649 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
77650 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77651 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77652 new file mode 100644
77653 index 0000000..06cc6ea
77654 --- /dev/null
77655 +++ b/grsecurity/grsec_fifo.c
77656 @@ -0,0 +1,24 @@
77657 +#include <linux/kernel.h>
77658 +#include <linux/sched.h>
77659 +#include <linux/fs.h>
77660 +#include <linux/file.h>
77661 +#include <linux/grinternal.h>
77662 +
77663 +int
77664 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77665 + const struct dentry *dir, const int flag, const int acc_mode)
77666 +{
77667 +#ifdef CONFIG_GRKERNSEC_FIFO
77668 + const struct cred *cred = current_cred();
77669 +
77670 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77671 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77672 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77673 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77674 + if (!inode_permission(dentry->d_inode, acc_mode))
77675 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, GR_GLOBAL_UID(dentry->d_inode->i_uid), GR_GLOBAL_GID(dentry->d_inode->i_gid));
77676 + return -EACCES;
77677 + }
77678 +#endif
77679 + return 0;
77680 +}
77681 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77682 new file mode 100644
77683 index 0000000..8ca18bf
77684 --- /dev/null
77685 +++ b/grsecurity/grsec_fork.c
77686 @@ -0,0 +1,23 @@
77687 +#include <linux/kernel.h>
77688 +#include <linux/sched.h>
77689 +#include <linux/grsecurity.h>
77690 +#include <linux/grinternal.h>
77691 +#include <linux/errno.h>
77692 +
77693 +void
77694 +gr_log_forkfail(const int retval)
77695 +{
77696 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77697 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77698 + switch (retval) {
77699 + case -EAGAIN:
77700 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77701 + break;
77702 + case -ENOMEM:
77703 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77704 + break;
77705 + }
77706 + }
77707 +#endif
77708 + return;
77709 +}
77710 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77711 new file mode 100644
77712 index 0000000..b7cb191
77713 --- /dev/null
77714 +++ b/grsecurity/grsec_init.c
77715 @@ -0,0 +1,286 @@
77716 +#include <linux/kernel.h>
77717 +#include <linux/sched.h>
77718 +#include <linux/mm.h>
77719 +#include <linux/gracl.h>
77720 +#include <linux/slab.h>
77721 +#include <linux/vmalloc.h>
77722 +#include <linux/percpu.h>
77723 +#include <linux/module.h>
77724 +
77725 +int grsec_enable_ptrace_readexec;
77726 +int grsec_enable_setxid;
77727 +int grsec_enable_symlinkown;
77728 +kgid_t grsec_symlinkown_gid;
77729 +int grsec_enable_brute;
77730 +int grsec_enable_link;
77731 +int grsec_enable_dmesg;
77732 +int grsec_enable_harden_ptrace;
77733 +int grsec_enable_harden_ipc;
77734 +int grsec_enable_fifo;
77735 +int grsec_enable_execlog;
77736 +int grsec_enable_signal;
77737 +int grsec_enable_forkfail;
77738 +int grsec_enable_audit_ptrace;
77739 +int grsec_enable_time;
77740 +int grsec_enable_group;
77741 +kgid_t grsec_audit_gid;
77742 +int grsec_enable_chdir;
77743 +int grsec_enable_mount;
77744 +int grsec_enable_rofs;
77745 +int grsec_deny_new_usb;
77746 +int grsec_enable_chroot_findtask;
77747 +int grsec_enable_chroot_mount;
77748 +int grsec_enable_chroot_shmat;
77749 +int grsec_enable_chroot_fchdir;
77750 +int grsec_enable_chroot_double;
77751 +int grsec_enable_chroot_pivot;
77752 +int grsec_enable_chroot_chdir;
77753 +int grsec_enable_chroot_chmod;
77754 +int grsec_enable_chroot_mknod;
77755 +int grsec_enable_chroot_nice;
77756 +int grsec_enable_chroot_execlog;
77757 +int grsec_enable_chroot_caps;
77758 +int grsec_enable_chroot_sysctl;
77759 +int grsec_enable_chroot_unix;
77760 +int grsec_enable_tpe;
77761 +kgid_t grsec_tpe_gid;
77762 +int grsec_enable_blackhole;
77763 +#ifdef CONFIG_IPV6_MODULE
77764 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77765 +#endif
77766 +int grsec_lastack_retries;
77767 +int grsec_enable_tpe_all;
77768 +int grsec_enable_tpe_invert;
77769 +int grsec_enable_socket_all;
77770 +kgid_t grsec_socket_all_gid;
77771 +int grsec_enable_socket_client;
77772 +kgid_t grsec_socket_client_gid;
77773 +int grsec_enable_socket_server;
77774 +kgid_t grsec_socket_server_gid;
77775 +int grsec_resource_logging;
77776 +int grsec_disable_privio;
77777 +int grsec_enable_log_rwxmaps;
77778 +int grsec_lock;
77779 +
77780 +DEFINE_SPINLOCK(grsec_alert_lock);
77781 +unsigned long grsec_alert_wtime = 0;
77782 +unsigned long grsec_alert_fyet = 0;
77783 +
77784 +DEFINE_SPINLOCK(grsec_audit_lock);
77785 +
77786 +DEFINE_RWLOCK(grsec_exec_file_lock);
77787 +
77788 +char *gr_shared_page[4];
77789 +
77790 +char *gr_alert_log_fmt;
77791 +char *gr_audit_log_fmt;
77792 +char *gr_alert_log_buf;
77793 +char *gr_audit_log_buf;
77794 +
77795 +extern struct gr_arg *gr_usermode;
77796 +extern unsigned char *gr_system_salt;
77797 +extern unsigned char *gr_system_sum;
77798 +
77799 +void __init
77800 +grsecurity_init(void)
77801 +{
77802 + int j;
77803 + /* create the per-cpu shared pages */
77804 +
77805 +#ifdef CONFIG_X86
77806 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77807 +#endif
77808 +
77809 + for (j = 0; j < 4; j++) {
77810 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77811 + if (gr_shared_page[j] == NULL) {
77812 + panic("Unable to allocate grsecurity shared page");
77813 + return;
77814 + }
77815 + }
77816 +
77817 + /* allocate log buffers */
77818 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77819 + if (!gr_alert_log_fmt) {
77820 + panic("Unable to allocate grsecurity alert log format buffer");
77821 + return;
77822 + }
77823 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77824 + if (!gr_audit_log_fmt) {
77825 + panic("Unable to allocate grsecurity audit log format buffer");
77826 + return;
77827 + }
77828 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77829 + if (!gr_alert_log_buf) {
77830 + panic("Unable to allocate grsecurity alert log buffer");
77831 + return;
77832 + }
77833 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77834 + if (!gr_audit_log_buf) {
77835 + panic("Unable to allocate grsecurity audit log buffer");
77836 + return;
77837 + }
77838 +
77839 + /* allocate memory for authentication structure */
77840 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77841 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77842 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77843 +
77844 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77845 + panic("Unable to allocate grsecurity authentication structure");
77846 + return;
77847 + }
77848 +
77849 +#ifdef CONFIG_GRKERNSEC_IO
77850 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77851 + grsec_disable_privio = 1;
77852 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77853 + grsec_disable_privio = 1;
77854 +#else
77855 + grsec_disable_privio = 0;
77856 +#endif
77857 +#endif
77858 +
77859 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77860 + /* for backward compatibility, tpe_invert always defaults to on if
77861 + enabled in the kernel
77862 + */
77863 + grsec_enable_tpe_invert = 1;
77864 +#endif
77865 +
77866 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77867 +#ifndef CONFIG_GRKERNSEC_SYSCTL
77868 + grsec_lock = 1;
77869 +#endif
77870 +
77871 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77872 + grsec_enable_log_rwxmaps = 1;
77873 +#endif
77874 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77875 + grsec_enable_group = 1;
77876 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77877 +#endif
77878 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77879 + grsec_enable_ptrace_readexec = 1;
77880 +#endif
77881 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77882 + grsec_enable_chdir = 1;
77883 +#endif
77884 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77885 + grsec_enable_harden_ptrace = 1;
77886 +#endif
77887 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77888 + grsec_enable_harden_ipc = 1;
77889 +#endif
77890 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77891 + grsec_enable_mount = 1;
77892 +#endif
77893 +#ifdef CONFIG_GRKERNSEC_LINK
77894 + grsec_enable_link = 1;
77895 +#endif
77896 +#ifdef CONFIG_GRKERNSEC_BRUTE
77897 + grsec_enable_brute = 1;
77898 +#endif
77899 +#ifdef CONFIG_GRKERNSEC_DMESG
77900 + grsec_enable_dmesg = 1;
77901 +#endif
77902 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77903 + grsec_enable_blackhole = 1;
77904 + grsec_lastack_retries = 4;
77905 +#endif
77906 +#ifdef CONFIG_GRKERNSEC_FIFO
77907 + grsec_enable_fifo = 1;
77908 +#endif
77909 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77910 + grsec_enable_execlog = 1;
77911 +#endif
77912 +#ifdef CONFIG_GRKERNSEC_SETXID
77913 + grsec_enable_setxid = 1;
77914 +#endif
77915 +#ifdef CONFIG_GRKERNSEC_SIGNAL
77916 + grsec_enable_signal = 1;
77917 +#endif
77918 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77919 + grsec_enable_forkfail = 1;
77920 +#endif
77921 +#ifdef CONFIG_GRKERNSEC_TIME
77922 + grsec_enable_time = 1;
77923 +#endif
77924 +#ifdef CONFIG_GRKERNSEC_RESLOG
77925 + grsec_resource_logging = 1;
77926 +#endif
77927 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77928 + grsec_enable_chroot_findtask = 1;
77929 +#endif
77930 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77931 + grsec_enable_chroot_unix = 1;
77932 +#endif
77933 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77934 + grsec_enable_chroot_mount = 1;
77935 +#endif
77936 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77937 + grsec_enable_chroot_fchdir = 1;
77938 +#endif
77939 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77940 + grsec_enable_chroot_shmat = 1;
77941 +#endif
77942 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77943 + grsec_enable_audit_ptrace = 1;
77944 +#endif
77945 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77946 + grsec_enable_chroot_double = 1;
77947 +#endif
77948 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77949 + grsec_enable_chroot_pivot = 1;
77950 +#endif
77951 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77952 + grsec_enable_chroot_chdir = 1;
77953 +#endif
77954 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77955 + grsec_enable_chroot_chmod = 1;
77956 +#endif
77957 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77958 + grsec_enable_chroot_mknod = 1;
77959 +#endif
77960 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77961 + grsec_enable_chroot_nice = 1;
77962 +#endif
77963 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77964 + grsec_enable_chroot_execlog = 1;
77965 +#endif
77966 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77967 + grsec_enable_chroot_caps = 1;
77968 +#endif
77969 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77970 + grsec_enable_chroot_sysctl = 1;
77971 +#endif
77972 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77973 + grsec_enable_symlinkown = 1;
77974 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77975 +#endif
77976 +#ifdef CONFIG_GRKERNSEC_TPE
77977 + grsec_enable_tpe = 1;
77978 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77979 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
77980 + grsec_enable_tpe_all = 1;
77981 +#endif
77982 +#endif
77983 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77984 + grsec_enable_socket_all = 1;
77985 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77986 +#endif
77987 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77988 + grsec_enable_socket_client = 1;
77989 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77990 +#endif
77991 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77992 + grsec_enable_socket_server = 1;
77993 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77994 +#endif
77995 +#endif
77996 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77997 + grsec_deny_new_usb = 1;
77998 +#endif
77999 +
78000 + return;
78001 +}
78002 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
78003 new file mode 100644
78004 index 0000000..1773300
78005 --- /dev/null
78006 +++ b/grsecurity/grsec_ipc.c
78007 @@ -0,0 +1,48 @@
78008 +#include <linux/kernel.h>
78009 +#include <linux/mm.h>
78010 +#include <linux/sched.h>
78011 +#include <linux/file.h>
78012 +#include <linux/ipc.h>
78013 +#include <linux/ipc_namespace.h>
78014 +#include <linux/grsecurity.h>
78015 +#include <linux/grinternal.h>
78016 +
78017 +int
78018 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
78019 +{
78020 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
78021 + int write;
78022 + int orig_granted_mode;
78023 + kuid_t euid;
78024 + kgid_t egid;
78025 +
78026 + if (!grsec_enable_harden_ipc)
78027 + return 1;
78028 +
78029 + euid = current_euid();
78030 + egid = current_egid();
78031 +
78032 + write = requested_mode & 00002;
78033 + orig_granted_mode = ipcp->mode;
78034 +
78035 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
78036 + orig_granted_mode >>= 6;
78037 + else {
78038 + /* if likely wrong permissions, lock to user */
78039 + if (orig_granted_mode & 0007)
78040 + orig_granted_mode = 0;
78041 + /* otherwise do a egid-only check */
78042 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
78043 + orig_granted_mode >>= 3;
78044 + /* otherwise, no access */
78045 + else
78046 + orig_granted_mode = 0;
78047 + }
78048 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
78049 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
78050 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
78051 + return 0;
78052 + }
78053 +#endif
78054 + return 1;
78055 +}
78056 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
78057 new file mode 100644
78058 index 0000000..5e05e20
78059 --- /dev/null
78060 +++ b/grsecurity/grsec_link.c
78061 @@ -0,0 +1,58 @@
78062 +#include <linux/kernel.h>
78063 +#include <linux/sched.h>
78064 +#include <linux/fs.h>
78065 +#include <linux/file.h>
78066 +#include <linux/grinternal.h>
78067 +
78068 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
78069 +{
78070 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78071 + const struct inode *link_inode = link->dentry->d_inode;
78072 +
78073 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
78074 + /* ignore root-owned links, e.g. /proc/self */
78075 + gr_is_global_nonroot(link_inode->i_uid) && target &&
78076 + !uid_eq(link_inode->i_uid, target->i_uid)) {
78077 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
78078 + return 1;
78079 + }
78080 +#endif
78081 + return 0;
78082 +}
78083 +
78084 +int
78085 +gr_handle_follow_link(const struct inode *parent,
78086 + const struct inode *inode,
78087 + const struct dentry *dentry, const struct vfsmount *mnt)
78088 +{
78089 +#ifdef CONFIG_GRKERNSEC_LINK
78090 + const struct cred *cred = current_cred();
78091 +
78092 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
78093 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
78094 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
78095 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
78096 + return -EACCES;
78097 + }
78098 +#endif
78099 + return 0;
78100 +}
78101 +
78102 +int
78103 +gr_handle_hardlink(const struct dentry *dentry,
78104 + const struct vfsmount *mnt,
78105 + struct inode *inode, const int mode, const struct filename *to)
78106 +{
78107 +#ifdef CONFIG_GRKERNSEC_LINK
78108 + const struct cred *cred = current_cred();
78109 +
78110 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
78111 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
78112 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
78113 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
78114 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
78115 + return -EPERM;
78116 + }
78117 +#endif
78118 + return 0;
78119 +}
78120 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
78121 new file mode 100644
78122 index 0000000..dbe0a6b
78123 --- /dev/null
78124 +++ b/grsecurity/grsec_log.c
78125 @@ -0,0 +1,341 @@
78126 +#include <linux/kernel.h>
78127 +#include <linux/sched.h>
78128 +#include <linux/file.h>
78129 +#include <linux/tty.h>
78130 +#include <linux/fs.h>
78131 +#include <linux/mm.h>
78132 +#include <linux/grinternal.h>
78133 +
78134 +#ifdef CONFIG_TREE_PREEMPT_RCU
78135 +#define DISABLE_PREEMPT() preempt_disable()
78136 +#define ENABLE_PREEMPT() preempt_enable()
78137 +#else
78138 +#define DISABLE_PREEMPT()
78139 +#define ENABLE_PREEMPT()
78140 +#endif
78141 +
78142 +#define BEGIN_LOCKS(x) \
78143 + DISABLE_PREEMPT(); \
78144 + rcu_read_lock(); \
78145 + read_lock(&tasklist_lock); \
78146 + read_lock(&grsec_exec_file_lock); \
78147 + if (x != GR_DO_AUDIT) \
78148 + spin_lock(&grsec_alert_lock); \
78149 + else \
78150 + spin_lock(&grsec_audit_lock)
78151 +
78152 +#define END_LOCKS(x) \
78153 + if (x != GR_DO_AUDIT) \
78154 + spin_unlock(&grsec_alert_lock); \
78155 + else \
78156 + spin_unlock(&grsec_audit_lock); \
78157 + read_unlock(&grsec_exec_file_lock); \
78158 + read_unlock(&tasklist_lock); \
78159 + rcu_read_unlock(); \
78160 + ENABLE_PREEMPT(); \
78161 + if (x == GR_DONT_AUDIT) \
78162 + gr_handle_alertkill(current)
78163 +
78164 +enum {
78165 + FLOODING,
78166 + NO_FLOODING
78167 +};
78168 +
78169 +extern char *gr_alert_log_fmt;
78170 +extern char *gr_audit_log_fmt;
78171 +extern char *gr_alert_log_buf;
78172 +extern char *gr_audit_log_buf;
78173 +
78174 +static int gr_log_start(int audit)
78175 +{
78176 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
78177 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
78178 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78179 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
78180 + unsigned long curr_secs = get_seconds();
78181 +
78182 + if (audit == GR_DO_AUDIT)
78183 + goto set_fmt;
78184 +
78185 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
78186 + grsec_alert_wtime = curr_secs;
78187 + grsec_alert_fyet = 0;
78188 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
78189 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
78190 + grsec_alert_fyet++;
78191 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
78192 + grsec_alert_wtime = curr_secs;
78193 + grsec_alert_fyet++;
78194 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
78195 + return FLOODING;
78196 + }
78197 + else return FLOODING;
78198 +
78199 +set_fmt:
78200 +#endif
78201 + memset(buf, 0, PAGE_SIZE);
78202 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
78203 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
78204 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
78205 + } else if (current->signal->curr_ip) {
78206 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
78207 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
78208 + } else if (gr_acl_is_enabled()) {
78209 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
78210 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
78211 + } else {
78212 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
78213 + strcpy(buf, fmt);
78214 + }
78215 +
78216 + return NO_FLOODING;
78217 +}
78218 +
78219 +static void gr_log_middle(int audit, const char *msg, va_list ap)
78220 + __attribute__ ((format (printf, 2, 0)));
78221 +
78222 +static void gr_log_middle(int audit, const char *msg, va_list ap)
78223 +{
78224 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78225 + unsigned int len = strlen(buf);
78226 +
78227 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
78228 +
78229 + return;
78230 +}
78231 +
78232 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
78233 + __attribute__ ((format (printf, 2, 3)));
78234 +
78235 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
78236 +{
78237 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78238 + unsigned int len = strlen(buf);
78239 + va_list ap;
78240 +
78241 + va_start(ap, msg);
78242 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
78243 + va_end(ap);
78244 +
78245 + return;
78246 +}
78247 +
78248 +static void gr_log_end(int audit, int append_default)
78249 +{
78250 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78251 + if (append_default) {
78252 + struct task_struct *task = current;
78253 + struct task_struct *parent = task->real_parent;
78254 + const struct cred *cred = __task_cred(task);
78255 + const struct cred *pcred = __task_cred(parent);
78256 + unsigned int len = strlen(buf);
78257 +
78258 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
78259 + }
78260 +
78261 + printk("%s\n", buf);
78262 +
78263 + return;
78264 +}
78265 +
78266 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
78267 +{
78268 + int logtype;
78269 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
78270 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
78271 + void *voidptr = NULL;
78272 + int num1 = 0, num2 = 0;
78273 + unsigned long ulong1 = 0, ulong2 = 0;
78274 + struct dentry *dentry = NULL;
78275 + struct vfsmount *mnt = NULL;
78276 + struct file *file = NULL;
78277 + struct task_struct *task = NULL;
78278 + struct vm_area_struct *vma = NULL;
78279 + const struct cred *cred, *pcred;
78280 + va_list ap;
78281 +
78282 + BEGIN_LOCKS(audit);
78283 + logtype = gr_log_start(audit);
78284 + if (logtype == FLOODING) {
78285 + END_LOCKS(audit);
78286 + return;
78287 + }
78288 + va_start(ap, argtypes);
78289 + switch (argtypes) {
78290 + case GR_TTYSNIFF:
78291 + task = va_arg(ap, struct task_struct *);
78292 + gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task_pid_nr(task), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent));
78293 + break;
78294 + case GR_SYSCTL_HIDDEN:
78295 + str1 = va_arg(ap, char *);
78296 + gr_log_middle_varargs(audit, msg, result, str1);
78297 + break;
78298 + case GR_RBAC:
78299 + dentry = va_arg(ap, struct dentry *);
78300 + mnt = va_arg(ap, struct vfsmount *);
78301 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
78302 + break;
78303 + case GR_RBAC_STR:
78304 + dentry = va_arg(ap, struct dentry *);
78305 + mnt = va_arg(ap, struct vfsmount *);
78306 + str1 = va_arg(ap, char *);
78307 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
78308 + break;
78309 + case GR_STR_RBAC:
78310 + str1 = va_arg(ap, char *);
78311 + dentry = va_arg(ap, struct dentry *);
78312 + mnt = va_arg(ap, struct vfsmount *);
78313 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
78314 + break;
78315 + case GR_RBAC_MODE2:
78316 + dentry = va_arg(ap, struct dentry *);
78317 + mnt = va_arg(ap, struct vfsmount *);
78318 + str1 = va_arg(ap, char *);
78319 + str2 = va_arg(ap, char *);
78320 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
78321 + break;
78322 + case GR_RBAC_MODE3:
78323 + dentry = va_arg(ap, struct dentry *);
78324 + mnt = va_arg(ap, struct vfsmount *);
78325 + str1 = va_arg(ap, char *);
78326 + str2 = va_arg(ap, char *);
78327 + str3 = va_arg(ap, char *);
78328 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
78329 + break;
78330 + case GR_FILENAME:
78331 + dentry = va_arg(ap, struct dentry *);
78332 + mnt = va_arg(ap, struct vfsmount *);
78333 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
78334 + break;
78335 + case GR_STR_FILENAME:
78336 + str1 = va_arg(ap, char *);
78337 + dentry = va_arg(ap, struct dentry *);
78338 + mnt = va_arg(ap, struct vfsmount *);
78339 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
78340 + break;
78341 + case GR_FILENAME_STR:
78342 + dentry = va_arg(ap, struct dentry *);
78343 + mnt = va_arg(ap, struct vfsmount *);
78344 + str1 = va_arg(ap, char *);
78345 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
78346 + break;
78347 + case GR_FILENAME_TWO_INT:
78348 + dentry = va_arg(ap, struct dentry *);
78349 + mnt = va_arg(ap, struct vfsmount *);
78350 + num1 = va_arg(ap, int);
78351 + num2 = va_arg(ap, int);
78352 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
78353 + break;
78354 + case GR_FILENAME_TWO_INT_STR:
78355 + dentry = va_arg(ap, struct dentry *);
78356 + mnt = va_arg(ap, struct vfsmount *);
78357 + num1 = va_arg(ap, int);
78358 + num2 = va_arg(ap, int);
78359 + str1 = va_arg(ap, char *);
78360 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
78361 + break;
78362 + case GR_TEXTREL:
78363 + file = va_arg(ap, struct file *);
78364 + ulong1 = va_arg(ap, unsigned long);
78365 + ulong2 = va_arg(ap, unsigned long);
78366 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
78367 + break;
78368 + case GR_PTRACE:
78369 + task = va_arg(ap, struct task_struct *);
78370 + gr_log_middle_varargs(audit, msg, task->exec_file ? gr_to_filename(task->exec_file->f_path.dentry, task->exec_file->f_path.mnt) : "(none)", task->comm, task_pid_nr(task));
78371 + break;
78372 + case GR_RESOURCE:
78373 + task = va_arg(ap, struct task_struct *);
78374 + cred = __task_cred(task);
78375 + pcred = __task_cred(task->real_parent);
78376 + ulong1 = va_arg(ap, unsigned long);
78377 + str1 = va_arg(ap, char *);
78378 + ulong2 = va_arg(ap, unsigned long);
78379 + gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
78380 + break;
78381 + case GR_CAP:
78382 + task = va_arg(ap, struct task_struct *);
78383 + cred = __task_cred(task);
78384 + pcred = __task_cred(task->real_parent);
78385 + str1 = va_arg(ap, char *);
78386 + gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
78387 + break;
78388 + case GR_SIG:
78389 + str1 = va_arg(ap, char *);
78390 + voidptr = va_arg(ap, void *);
78391 + gr_log_middle_varargs(audit, msg, str1, voidptr);
78392 + break;
78393 + case GR_SIG2:
78394 + task = va_arg(ap, struct task_struct *);
78395 + cred = __task_cred(task);
78396 + pcred = __task_cred(task->real_parent);
78397 + num1 = va_arg(ap, int);
78398 + gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
78399 + break;
78400 + case GR_CRASH1:
78401 + task = va_arg(ap, struct task_struct *);
78402 + cred = __task_cred(task);
78403 + pcred = __task_cred(task->real_parent);
78404 + ulong1 = va_arg(ap, unsigned long);
78405 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), GR_GLOBAL_UID(cred->uid), ulong1);
78406 + break;
78407 + case GR_CRASH2:
78408 + task = va_arg(ap, struct task_struct *);
78409 + cred = __task_cred(task);
78410 + pcred = __task_cred(task->real_parent);
78411 + ulong1 = va_arg(ap, unsigned long);
78412 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), ulong1);
78413 + break;
78414 + case GR_RWXMAP:
78415 + file = va_arg(ap, struct file *);
78416 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
78417 + break;
78418 + case GR_RWXMAPVMA:
78419 + vma = va_arg(ap, struct vm_area_struct *);
78420 + if (vma->vm_file)
78421 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
78422 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
78423 + str1 = "<stack>";
78424 + else if (vma->vm_start <= current->mm->brk &&
78425 + vma->vm_end >= current->mm->start_brk)
78426 + str1 = "<heap>";
78427 + else
78428 + str1 = "<anonymous mapping>";
78429 + gr_log_middle_varargs(audit, msg, str1);
78430 + break;
78431 + case GR_PSACCT:
78432 + {
78433 + unsigned int wday, cday;
78434 + __u8 whr, chr;
78435 + __u8 wmin, cmin;
78436 + __u8 wsec, csec;
78437 + char cur_tty[64] = { 0 };
78438 + char parent_tty[64] = { 0 };
78439 +
78440 + task = va_arg(ap, struct task_struct *);
78441 + wday = va_arg(ap, unsigned int);
78442 + cday = va_arg(ap, unsigned int);
78443 + whr = va_arg(ap, int);
78444 + chr = va_arg(ap, int);
78445 + wmin = va_arg(ap, int);
78446 + cmin = va_arg(ap, int);
78447 + wsec = va_arg(ap, int);
78448 + csec = va_arg(ap, int);
78449 + ulong1 = va_arg(ap, unsigned long);
78450 + cred = __task_cred(task);
78451 + pcred = __task_cred(task->real_parent);
78452 +
78453 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
78454 + }
78455 + break;
78456 + default:
78457 + gr_log_middle(audit, msg, ap);
78458 + }
78459 + va_end(ap);
78460 + // these don't need DEFAULTSECARGS printed on the end
78461 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
78462 + gr_log_end(audit, 0);
78463 + else
78464 + gr_log_end(audit, 1);
78465 + END_LOCKS(audit);
78466 +}
78467 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
78468 new file mode 100644
78469 index 0000000..0e39d8c
78470 --- /dev/null
78471 +++ b/grsecurity/grsec_mem.c
78472 @@ -0,0 +1,48 @@
78473 +#include <linux/kernel.h>
78474 +#include <linux/sched.h>
78475 +#include <linux/mm.h>
78476 +#include <linux/mman.h>
78477 +#include <linux/module.h>
78478 +#include <linux/grinternal.h>
78479 +
78480 +void gr_handle_msr_write(void)
78481 +{
78482 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
78483 + return;
78484 +}
78485 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
78486 +
78487 +void
78488 +gr_handle_ioperm(void)
78489 +{
78490 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
78491 + return;
78492 +}
78493 +
78494 +void
78495 +gr_handle_iopl(void)
78496 +{
78497 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
78498 + return;
78499 +}
78500 +
78501 +void
78502 +gr_handle_mem_readwrite(u64 from, u64 to)
78503 +{
78504 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
78505 + return;
78506 +}
78507 +
78508 +void
78509 +gr_handle_vm86(void)
78510 +{
78511 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
78512 + return;
78513 +}
78514 +
78515 +void
78516 +gr_log_badprocpid(const char *entry)
78517 +{
78518 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
78519 + return;
78520 +}
78521 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
78522 new file mode 100644
78523 index 0000000..cd9e124
78524 --- /dev/null
78525 +++ b/grsecurity/grsec_mount.c
78526 @@ -0,0 +1,65 @@
78527 +#include <linux/kernel.h>
78528 +#include <linux/sched.h>
78529 +#include <linux/mount.h>
78530 +#include <linux/major.h>
78531 +#include <linux/grsecurity.h>
78532 +#include <linux/grinternal.h>
78533 +
78534 +void
78535 +gr_log_remount(const char *devname, const int retval)
78536 +{
78537 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78538 + if (grsec_enable_mount && (retval >= 0))
78539 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
78540 +#endif
78541 + return;
78542 +}
78543 +
78544 +void
78545 +gr_log_unmount(const char *devname, const int retval)
78546 +{
78547 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78548 + if (grsec_enable_mount && (retval >= 0))
78549 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78550 +#endif
78551 + return;
78552 +}
78553 +
78554 +void
78555 +gr_log_mount(const char *from, const char *to, const int retval)
78556 +{
78557 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78558 + if (grsec_enable_mount && (retval >= 0))
78559 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
78560 +#endif
78561 + return;
78562 +}
78563 +
78564 +int
78565 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78566 +{
78567 +#ifdef CONFIG_GRKERNSEC_ROFS
78568 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78569 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78570 + return -EPERM;
78571 + } else
78572 + return 0;
78573 +#endif
78574 + return 0;
78575 +}
78576 +
78577 +int
78578 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78579 +{
78580 +#ifdef CONFIG_GRKERNSEC_ROFS
78581 + struct inode *inode = dentry->d_inode;
78582 +
78583 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78584 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78585 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78586 + return -EPERM;
78587 + } else
78588 + return 0;
78589 +#endif
78590 + return 0;
78591 +}
78592 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78593 new file mode 100644
78594 index 0000000..6ee9d50
78595 --- /dev/null
78596 +++ b/grsecurity/grsec_pax.c
78597 @@ -0,0 +1,45 @@
78598 +#include <linux/kernel.h>
78599 +#include <linux/sched.h>
78600 +#include <linux/mm.h>
78601 +#include <linux/file.h>
78602 +#include <linux/grinternal.h>
78603 +#include <linux/grsecurity.h>
78604 +
78605 +void
78606 +gr_log_textrel(struct vm_area_struct * vma)
78607 +{
78608 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78609 + if (grsec_enable_log_rwxmaps)
78610 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78611 +#endif
78612 + return;
78613 +}
78614 +
78615 +void gr_log_ptgnustack(struct file *file)
78616 +{
78617 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78618 + if (grsec_enable_log_rwxmaps)
78619 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78620 +#endif
78621 + return;
78622 +}
78623 +
78624 +void
78625 +gr_log_rwxmmap(struct file *file)
78626 +{
78627 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78628 + if (grsec_enable_log_rwxmaps)
78629 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78630 +#endif
78631 + return;
78632 +}
78633 +
78634 +void
78635 +gr_log_rwxmprotect(struct vm_area_struct *vma)
78636 +{
78637 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78638 + if (grsec_enable_log_rwxmaps)
78639 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78640 +#endif
78641 + return;
78642 +}
78643 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78644 new file mode 100644
78645 index 0000000..2005a3a
78646 --- /dev/null
78647 +++ b/grsecurity/grsec_proc.c
78648 @@ -0,0 +1,20 @@
78649 +#include <linux/kernel.h>
78650 +#include <linux/sched.h>
78651 +#include <linux/grsecurity.h>
78652 +#include <linux/grinternal.h>
78653 +
78654 +int gr_proc_is_restricted(void)
78655 +{
78656 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78657 + const struct cred *cred = current_cred();
78658 +#endif
78659 +
78660 +#ifdef CONFIG_GRKERNSEC_PROC_USER
78661 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78662 + return -EACCES;
78663 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78664 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78665 + return -EACCES;
78666 +#endif
78667 + return 0;
78668 +}
78669 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78670 new file mode 100644
78671 index 0000000..f7f29aa
78672 --- /dev/null
78673 +++ b/grsecurity/grsec_ptrace.c
78674 @@ -0,0 +1,30 @@
78675 +#include <linux/kernel.h>
78676 +#include <linux/sched.h>
78677 +#include <linux/grinternal.h>
78678 +#include <linux/security.h>
78679 +
78680 +void
78681 +gr_audit_ptrace(struct task_struct *task)
78682 +{
78683 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78684 + if (grsec_enable_audit_ptrace)
78685 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78686 +#endif
78687 + return;
78688 +}
78689 +
78690 +int
78691 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
78692 +{
78693 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78694 + const struct dentry *dentry = file->f_path.dentry;
78695 + const struct vfsmount *mnt = file->f_path.mnt;
78696 +
78697 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78698 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78699 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78700 + return -EACCES;
78701 + }
78702 +#endif
78703 + return 0;
78704 +}
78705 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78706 new file mode 100644
78707 index 0000000..3860c7e
78708 --- /dev/null
78709 +++ b/grsecurity/grsec_sig.c
78710 @@ -0,0 +1,236 @@
78711 +#include <linux/kernel.h>
78712 +#include <linux/sched.h>
78713 +#include <linux/fs.h>
78714 +#include <linux/delay.h>
78715 +#include <linux/grsecurity.h>
78716 +#include <linux/grinternal.h>
78717 +#include <linux/hardirq.h>
78718 +
78719 +char *signames[] = {
78720 + [SIGSEGV] = "Segmentation fault",
78721 + [SIGILL] = "Illegal instruction",
78722 + [SIGABRT] = "Abort",
78723 + [SIGBUS] = "Invalid alignment/Bus error"
78724 +};
78725 +
78726 +void
78727 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78728 +{
78729 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78730 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78731 + (sig == SIGABRT) || (sig == SIGBUS))) {
78732 + if (task_pid_nr(t) == task_pid_nr(current)) {
78733 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78734 + } else {
78735 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78736 + }
78737 + }
78738 +#endif
78739 + return;
78740 +}
78741 +
78742 +int
78743 +gr_handle_signal(const struct task_struct *p, const int sig)
78744 +{
78745 +#ifdef CONFIG_GRKERNSEC
78746 + /* ignore the 0 signal for protected task checks */
78747 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78748 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78749 + return -EPERM;
78750 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78751 + return -EPERM;
78752 + }
78753 +#endif
78754 + return 0;
78755 +}
78756 +
78757 +#ifdef CONFIG_GRKERNSEC
78758 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78759 +
78760 +int gr_fake_force_sig(int sig, struct task_struct *t)
78761 +{
78762 + unsigned long int flags;
78763 + int ret, blocked, ignored;
78764 + struct k_sigaction *action;
78765 +
78766 + spin_lock_irqsave(&t->sighand->siglock, flags);
78767 + action = &t->sighand->action[sig-1];
78768 + ignored = action->sa.sa_handler == SIG_IGN;
78769 + blocked = sigismember(&t->blocked, sig);
78770 + if (blocked || ignored) {
78771 + action->sa.sa_handler = SIG_DFL;
78772 + if (blocked) {
78773 + sigdelset(&t->blocked, sig);
78774 + recalc_sigpending_and_wake(t);
78775 + }
78776 + }
78777 + if (action->sa.sa_handler == SIG_DFL)
78778 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
78779 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78780 +
78781 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
78782 +
78783 + return ret;
78784 +}
78785 +#endif
78786 +
78787 +#define GR_USER_BAN_TIME (15 * 60)
78788 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
78789 +
78790 +void gr_handle_brute_attach(int dumpable)
78791 +{
78792 +#ifdef CONFIG_GRKERNSEC_BRUTE
78793 + struct task_struct *p = current;
78794 + kuid_t uid = GLOBAL_ROOT_UID;
78795 + int daemon = 0;
78796 +
78797 + if (!grsec_enable_brute)
78798 + return;
78799 +
78800 + rcu_read_lock();
78801 + read_lock(&tasklist_lock);
78802 + read_lock(&grsec_exec_file_lock);
78803 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78804 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78805 + p->real_parent->brute = 1;
78806 + daemon = 1;
78807 + } else {
78808 + const struct cred *cred = __task_cred(p), *cred2;
78809 + struct task_struct *tsk, *tsk2;
78810 +
78811 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78812 + struct user_struct *user;
78813 +
78814 + uid = cred->uid;
78815 +
78816 + /* this is put upon execution past expiration */
78817 + user = find_user(uid);
78818 + if (user == NULL)
78819 + goto unlock;
78820 + user->suid_banned = 1;
78821 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78822 + if (user->suid_ban_expires == ~0UL)
78823 + user->suid_ban_expires--;
78824 +
78825 + /* only kill other threads of the same binary, from the same user */
78826 + do_each_thread(tsk2, tsk) {
78827 + cred2 = __task_cred(tsk);
78828 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78829 + gr_fake_force_sig(SIGKILL, tsk);
78830 + } while_each_thread(tsk2, tsk);
78831 + }
78832 + }
78833 +unlock:
78834 + read_unlock(&grsec_exec_file_lock);
78835 + read_unlock(&tasklist_lock);
78836 + rcu_read_unlock();
78837 +
78838 + if (gr_is_global_nonroot(uid))
78839 + gr_log_fs_int2(GR_DONT_AUDIT, GR_BRUTE_SUID_MSG, p->exec_file->f_path.dentry, p->exec_file->f_path.mnt, GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
78840 + else if (daemon)
78841 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78842 +
78843 +#endif
78844 + return;
78845 +}
78846 +
78847 +void gr_handle_brute_check(void)
78848 +{
78849 +#ifdef CONFIG_GRKERNSEC_BRUTE
78850 + struct task_struct *p = current;
78851 +
78852 + if (unlikely(p->brute)) {
78853 + if (!grsec_enable_brute)
78854 + p->brute = 0;
78855 + else if (time_before(get_seconds(), p->brute_expires))
78856 + msleep(30 * 1000);
78857 + }
78858 +#endif
78859 + return;
78860 +}
78861 +
78862 +void gr_handle_kernel_exploit(void)
78863 +{
78864 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78865 + const struct cred *cred;
78866 + struct task_struct *tsk, *tsk2;
78867 + struct user_struct *user;
78868 + kuid_t uid;
78869 +
78870 + if (in_irq() || in_serving_softirq() || in_nmi())
78871 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78872 +
78873 + uid = current_uid();
78874 +
78875 + if (gr_is_global_root(uid))
78876 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
78877 + else {
78878 + /* kill all the processes of this user, hold a reference
78879 + to their creds struct, and prevent them from creating
78880 + another process until system reset
78881 + */
78882 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78883 + GR_GLOBAL_UID(uid));
78884 + /* we intentionally leak this ref */
78885 + user = get_uid(current->cred->user);
78886 + if (user)
78887 + user->kernel_banned = 1;
78888 +
78889 + /* kill all processes of this user */
78890 + read_lock(&tasklist_lock);
78891 + do_each_thread(tsk2, tsk) {
78892 + cred = __task_cred(tsk);
78893 + if (uid_eq(cred->uid, uid))
78894 + gr_fake_force_sig(SIGKILL, tsk);
78895 + } while_each_thread(tsk2, tsk);
78896 + read_unlock(&tasklist_lock);
78897 + }
78898 +#endif
78899 +}
78900 +
78901 +#ifdef CONFIG_GRKERNSEC_BRUTE
78902 +static bool suid_ban_expired(struct user_struct *user)
78903 +{
78904 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78905 + user->suid_banned = 0;
78906 + user->suid_ban_expires = 0;
78907 + free_uid(user);
78908 + return true;
78909 + }
78910 +
78911 + return false;
78912 +}
78913 +#endif
78914 +
78915 +int gr_process_kernel_exec_ban(void)
78916 +{
78917 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78918 + if (unlikely(current->cred->user->kernel_banned))
78919 + return -EPERM;
78920 +#endif
78921 + return 0;
78922 +}
78923 +
78924 +int gr_process_kernel_setuid_ban(struct user_struct *user)
78925 +{
78926 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78927 + if (unlikely(user->kernel_banned))
78928 + gr_fake_force_sig(SIGKILL, current);
78929 +#endif
78930 + return 0;
78931 +}
78932 +
78933 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78934 +{
78935 +#ifdef CONFIG_GRKERNSEC_BRUTE
78936 + struct user_struct *user = current->cred->user;
78937 + if (unlikely(user->suid_banned)) {
78938 + if (suid_ban_expired(user))
78939 + return 0;
78940 + /* disallow execution of suid binaries only */
78941 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78942 + return -EPERM;
78943 + }
78944 +#endif
78945 + return 0;
78946 +}
78947 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78948 new file mode 100644
78949 index 0000000..c0aef3a
78950 --- /dev/null
78951 +++ b/grsecurity/grsec_sock.c
78952 @@ -0,0 +1,244 @@
78953 +#include <linux/kernel.h>
78954 +#include <linux/module.h>
78955 +#include <linux/sched.h>
78956 +#include <linux/file.h>
78957 +#include <linux/net.h>
78958 +#include <linux/in.h>
78959 +#include <linux/ip.h>
78960 +#include <net/sock.h>
78961 +#include <net/inet_sock.h>
78962 +#include <linux/grsecurity.h>
78963 +#include <linux/grinternal.h>
78964 +#include <linux/gracl.h>
78965 +
78966 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78967 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78968 +
78969 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78970 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78971 +
78972 +#ifdef CONFIG_UNIX_MODULE
78973 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78974 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78975 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78976 +EXPORT_SYMBOL_GPL(gr_handle_create);
78977 +#endif
78978 +
78979 +#ifdef CONFIG_GRKERNSEC
78980 +#define gr_conn_table_size 32749
78981 +struct conn_table_entry {
78982 + struct conn_table_entry *next;
78983 + struct signal_struct *sig;
78984 +};
78985 +
78986 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78987 +DEFINE_SPINLOCK(gr_conn_table_lock);
78988 +
78989 +extern const char * gr_socktype_to_name(unsigned char type);
78990 +extern const char * gr_proto_to_name(unsigned char proto);
78991 +extern const char * gr_sockfamily_to_name(unsigned char family);
78992 +
78993 +static __inline__ int
78994 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78995 +{
78996 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78997 +}
78998 +
78999 +static __inline__ int
79000 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
79001 + __u16 sport, __u16 dport)
79002 +{
79003 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
79004 + sig->gr_sport == sport && sig->gr_dport == dport))
79005 + return 1;
79006 + else
79007 + return 0;
79008 +}
79009 +
79010 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
79011 +{
79012 + struct conn_table_entry **match;
79013 + unsigned int index;
79014 +
79015 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
79016 + sig->gr_sport, sig->gr_dport,
79017 + gr_conn_table_size);
79018 +
79019 + newent->sig = sig;
79020 +
79021 + match = &gr_conn_table[index];
79022 + newent->next = *match;
79023 + *match = newent;
79024 +
79025 + return;
79026 +}
79027 +
79028 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
79029 +{
79030 + struct conn_table_entry *match, *last = NULL;
79031 + unsigned int index;
79032 +
79033 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
79034 + sig->gr_sport, sig->gr_dport,
79035 + gr_conn_table_size);
79036 +
79037 + match = gr_conn_table[index];
79038 + while (match && !conn_match(match->sig,
79039 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
79040 + sig->gr_dport)) {
79041 + last = match;
79042 + match = match->next;
79043 + }
79044 +
79045 + if (match) {
79046 + if (last)
79047 + last->next = match->next;
79048 + else
79049 + gr_conn_table[index] = NULL;
79050 + kfree(match);
79051 + }
79052 +
79053 + return;
79054 +}
79055 +
79056 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
79057 + __u16 sport, __u16 dport)
79058 +{
79059 + struct conn_table_entry *match;
79060 + unsigned int index;
79061 +
79062 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
79063 +
79064 + match = gr_conn_table[index];
79065 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
79066 + match = match->next;
79067 +
79068 + if (match)
79069 + return match->sig;
79070 + else
79071 + return NULL;
79072 +}
79073 +
79074 +#endif
79075 +
79076 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
79077 +{
79078 +#ifdef CONFIG_GRKERNSEC
79079 + struct signal_struct *sig = task->signal;
79080 + struct conn_table_entry *newent;
79081 +
79082 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
79083 + if (newent == NULL)
79084 + return;
79085 + /* no bh lock needed since we are called with bh disabled */
79086 + spin_lock(&gr_conn_table_lock);
79087 + gr_del_task_from_ip_table_nolock(sig);
79088 + sig->gr_saddr = inet->inet_rcv_saddr;
79089 + sig->gr_daddr = inet->inet_daddr;
79090 + sig->gr_sport = inet->inet_sport;
79091 + sig->gr_dport = inet->inet_dport;
79092 + gr_add_to_task_ip_table_nolock(sig, newent);
79093 + spin_unlock(&gr_conn_table_lock);
79094 +#endif
79095 + return;
79096 +}
79097 +
79098 +void gr_del_task_from_ip_table(struct task_struct *task)
79099 +{
79100 +#ifdef CONFIG_GRKERNSEC
79101 + spin_lock_bh(&gr_conn_table_lock);
79102 + gr_del_task_from_ip_table_nolock(task->signal);
79103 + spin_unlock_bh(&gr_conn_table_lock);
79104 +#endif
79105 + return;
79106 +}
79107 +
79108 +void
79109 +gr_attach_curr_ip(const struct sock *sk)
79110 +{
79111 +#ifdef CONFIG_GRKERNSEC
79112 + struct signal_struct *p, *set;
79113 + const struct inet_sock *inet = inet_sk(sk);
79114 +
79115 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
79116 + return;
79117 +
79118 + set = current->signal;
79119 +
79120 + spin_lock_bh(&gr_conn_table_lock);
79121 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
79122 + inet->inet_dport, inet->inet_sport);
79123 + if (unlikely(p != NULL)) {
79124 + set->curr_ip = p->curr_ip;
79125 + set->used_accept = 1;
79126 + gr_del_task_from_ip_table_nolock(p);
79127 + spin_unlock_bh(&gr_conn_table_lock);
79128 + return;
79129 + }
79130 + spin_unlock_bh(&gr_conn_table_lock);
79131 +
79132 + set->curr_ip = inet->inet_daddr;
79133 + set->used_accept = 1;
79134 +#endif
79135 + return;
79136 +}
79137 +
79138 +int
79139 +gr_handle_sock_all(const int family, const int type, const int protocol)
79140 +{
79141 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79142 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
79143 + (family != AF_UNIX)) {
79144 + if (family == AF_INET)
79145 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
79146 + else
79147 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
79148 + return -EACCES;
79149 + }
79150 +#endif
79151 + return 0;
79152 +}
79153 +
79154 +int
79155 +gr_handle_sock_server(const struct sockaddr *sck)
79156 +{
79157 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79158 + if (grsec_enable_socket_server &&
79159 + in_group_p(grsec_socket_server_gid) &&
79160 + sck && (sck->sa_family != AF_UNIX) &&
79161 + (sck->sa_family != AF_LOCAL)) {
79162 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
79163 + return -EACCES;
79164 + }
79165 +#endif
79166 + return 0;
79167 +}
79168 +
79169 +int
79170 +gr_handle_sock_server_other(const struct sock *sck)
79171 +{
79172 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79173 + if (grsec_enable_socket_server &&
79174 + in_group_p(grsec_socket_server_gid) &&
79175 + sck && (sck->sk_family != AF_UNIX) &&
79176 + (sck->sk_family != AF_LOCAL)) {
79177 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
79178 + return -EACCES;
79179 + }
79180 +#endif
79181 + return 0;
79182 +}
79183 +
79184 +int
79185 +gr_handle_sock_client(const struct sockaddr *sck)
79186 +{
79187 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79188 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
79189 + sck && (sck->sa_family != AF_UNIX) &&
79190 + (sck->sa_family != AF_LOCAL)) {
79191 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
79192 + return -EACCES;
79193 + }
79194 +#endif
79195 + return 0;
79196 +}
79197 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
79198 new file mode 100644
79199 index 0000000..8159888
79200 --- /dev/null
79201 +++ b/grsecurity/grsec_sysctl.c
79202 @@ -0,0 +1,479 @@
79203 +#include <linux/kernel.h>
79204 +#include <linux/sched.h>
79205 +#include <linux/sysctl.h>
79206 +#include <linux/grsecurity.h>
79207 +#include <linux/grinternal.h>
79208 +
79209 +int
79210 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
79211 +{
79212 +#ifdef CONFIG_GRKERNSEC_SYSCTL
79213 + if (dirname == NULL || name == NULL)
79214 + return 0;
79215 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
79216 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
79217 + return -EACCES;
79218 + }
79219 +#endif
79220 + return 0;
79221 +}
79222 +
79223 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
79224 +static int __maybe_unused __read_only one = 1;
79225 +#endif
79226 +
79227 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
79228 + defined(CONFIG_GRKERNSEC_DENYUSB)
79229 +struct ctl_table grsecurity_table[] = {
79230 +#ifdef CONFIG_GRKERNSEC_SYSCTL
79231 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
79232 +#ifdef CONFIG_GRKERNSEC_IO
79233 + {
79234 + .procname = "disable_priv_io",
79235 + .data = &grsec_disable_privio,
79236 + .maxlen = sizeof(int),
79237 + .mode = 0600,
79238 + .proc_handler = &proc_dointvec,
79239 + },
79240 +#endif
79241 +#endif
79242 +#ifdef CONFIG_GRKERNSEC_LINK
79243 + {
79244 + .procname = "linking_restrictions",
79245 + .data = &grsec_enable_link,
79246 + .maxlen = sizeof(int),
79247 + .mode = 0600,
79248 + .proc_handler = &proc_dointvec,
79249 + },
79250 +#endif
79251 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
79252 + {
79253 + .procname = "enforce_symlinksifowner",
79254 + .data = &grsec_enable_symlinkown,
79255 + .maxlen = sizeof(int),
79256 + .mode = 0600,
79257 + .proc_handler = &proc_dointvec,
79258 + },
79259 + {
79260 + .procname = "symlinkown_gid",
79261 + .data = &grsec_symlinkown_gid,
79262 + .maxlen = sizeof(int),
79263 + .mode = 0600,
79264 + .proc_handler = &proc_dointvec,
79265 + },
79266 +#endif
79267 +#ifdef CONFIG_GRKERNSEC_BRUTE
79268 + {
79269 + .procname = "deter_bruteforce",
79270 + .data = &grsec_enable_brute,
79271 + .maxlen = sizeof(int),
79272 + .mode = 0600,
79273 + .proc_handler = &proc_dointvec,
79274 + },
79275 +#endif
79276 +#ifdef CONFIG_GRKERNSEC_FIFO
79277 + {
79278 + .procname = "fifo_restrictions",
79279 + .data = &grsec_enable_fifo,
79280 + .maxlen = sizeof(int),
79281 + .mode = 0600,
79282 + .proc_handler = &proc_dointvec,
79283 + },
79284 +#endif
79285 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
79286 + {
79287 + .procname = "ptrace_readexec",
79288 + .data = &grsec_enable_ptrace_readexec,
79289 + .maxlen = sizeof(int),
79290 + .mode = 0600,
79291 + .proc_handler = &proc_dointvec,
79292 + },
79293 +#endif
79294 +#ifdef CONFIG_GRKERNSEC_SETXID
79295 + {
79296 + .procname = "consistent_setxid",
79297 + .data = &grsec_enable_setxid,
79298 + .maxlen = sizeof(int),
79299 + .mode = 0600,
79300 + .proc_handler = &proc_dointvec,
79301 + },
79302 +#endif
79303 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79304 + {
79305 + .procname = "ip_blackhole",
79306 + .data = &grsec_enable_blackhole,
79307 + .maxlen = sizeof(int),
79308 + .mode = 0600,
79309 + .proc_handler = &proc_dointvec,
79310 + },
79311 + {
79312 + .procname = "lastack_retries",
79313 + .data = &grsec_lastack_retries,
79314 + .maxlen = sizeof(int),
79315 + .mode = 0600,
79316 + .proc_handler = &proc_dointvec,
79317 + },
79318 +#endif
79319 +#ifdef CONFIG_GRKERNSEC_EXECLOG
79320 + {
79321 + .procname = "exec_logging",
79322 + .data = &grsec_enable_execlog,
79323 + .maxlen = sizeof(int),
79324 + .mode = 0600,
79325 + .proc_handler = &proc_dointvec,
79326 + },
79327 +#endif
79328 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
79329 + {
79330 + .procname = "rwxmap_logging",
79331 + .data = &grsec_enable_log_rwxmaps,
79332 + .maxlen = sizeof(int),
79333 + .mode = 0600,
79334 + .proc_handler = &proc_dointvec,
79335 + },
79336 +#endif
79337 +#ifdef CONFIG_GRKERNSEC_SIGNAL
79338 + {
79339 + .procname = "signal_logging",
79340 + .data = &grsec_enable_signal,
79341 + .maxlen = sizeof(int),
79342 + .mode = 0600,
79343 + .proc_handler = &proc_dointvec,
79344 + },
79345 +#endif
79346 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
79347 + {
79348 + .procname = "forkfail_logging",
79349 + .data = &grsec_enable_forkfail,
79350 + .maxlen = sizeof(int),
79351 + .mode = 0600,
79352 + .proc_handler = &proc_dointvec,
79353 + },
79354 +#endif
79355 +#ifdef CONFIG_GRKERNSEC_TIME
79356 + {
79357 + .procname = "timechange_logging",
79358 + .data = &grsec_enable_time,
79359 + .maxlen = sizeof(int),
79360 + .mode = 0600,
79361 + .proc_handler = &proc_dointvec,
79362 + },
79363 +#endif
79364 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
79365 + {
79366 + .procname = "chroot_deny_shmat",
79367 + .data = &grsec_enable_chroot_shmat,
79368 + .maxlen = sizeof(int),
79369 + .mode = 0600,
79370 + .proc_handler = &proc_dointvec,
79371 + },
79372 +#endif
79373 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
79374 + {
79375 + .procname = "chroot_deny_unix",
79376 + .data = &grsec_enable_chroot_unix,
79377 + .maxlen = sizeof(int),
79378 + .mode = 0600,
79379 + .proc_handler = &proc_dointvec,
79380 + },
79381 +#endif
79382 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
79383 + {
79384 + .procname = "chroot_deny_mount",
79385 + .data = &grsec_enable_chroot_mount,
79386 + .maxlen = sizeof(int),
79387 + .mode = 0600,
79388 + .proc_handler = &proc_dointvec,
79389 + },
79390 +#endif
79391 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
79392 + {
79393 + .procname = "chroot_deny_fchdir",
79394 + .data = &grsec_enable_chroot_fchdir,
79395 + .maxlen = sizeof(int),
79396 + .mode = 0600,
79397 + .proc_handler = &proc_dointvec,
79398 + },
79399 +#endif
79400 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
79401 + {
79402 + .procname = "chroot_deny_chroot",
79403 + .data = &grsec_enable_chroot_double,
79404 + .maxlen = sizeof(int),
79405 + .mode = 0600,
79406 + .proc_handler = &proc_dointvec,
79407 + },
79408 +#endif
79409 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
79410 + {
79411 + .procname = "chroot_deny_pivot",
79412 + .data = &grsec_enable_chroot_pivot,
79413 + .maxlen = sizeof(int),
79414 + .mode = 0600,
79415 + .proc_handler = &proc_dointvec,
79416 + },
79417 +#endif
79418 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
79419 + {
79420 + .procname = "chroot_enforce_chdir",
79421 + .data = &grsec_enable_chroot_chdir,
79422 + .maxlen = sizeof(int),
79423 + .mode = 0600,
79424 + .proc_handler = &proc_dointvec,
79425 + },
79426 +#endif
79427 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
79428 + {
79429 + .procname = "chroot_deny_chmod",
79430 + .data = &grsec_enable_chroot_chmod,
79431 + .maxlen = sizeof(int),
79432 + .mode = 0600,
79433 + .proc_handler = &proc_dointvec,
79434 + },
79435 +#endif
79436 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
79437 + {
79438 + .procname = "chroot_deny_mknod",
79439 + .data = &grsec_enable_chroot_mknod,
79440 + .maxlen = sizeof(int),
79441 + .mode = 0600,
79442 + .proc_handler = &proc_dointvec,
79443 + },
79444 +#endif
79445 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
79446 + {
79447 + .procname = "chroot_restrict_nice",
79448 + .data = &grsec_enable_chroot_nice,
79449 + .maxlen = sizeof(int),
79450 + .mode = 0600,
79451 + .proc_handler = &proc_dointvec,
79452 + },
79453 +#endif
79454 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
79455 + {
79456 + .procname = "chroot_execlog",
79457 + .data = &grsec_enable_chroot_execlog,
79458 + .maxlen = sizeof(int),
79459 + .mode = 0600,
79460 + .proc_handler = &proc_dointvec,
79461 + },
79462 +#endif
79463 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
79464 + {
79465 + .procname = "chroot_caps",
79466 + .data = &grsec_enable_chroot_caps,
79467 + .maxlen = sizeof(int),
79468 + .mode = 0600,
79469 + .proc_handler = &proc_dointvec,
79470 + },
79471 +#endif
79472 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
79473 + {
79474 + .procname = "chroot_deny_sysctl",
79475 + .data = &grsec_enable_chroot_sysctl,
79476 + .maxlen = sizeof(int),
79477 + .mode = 0600,
79478 + .proc_handler = &proc_dointvec,
79479 + },
79480 +#endif
79481 +#ifdef CONFIG_GRKERNSEC_TPE
79482 + {
79483 + .procname = "tpe",
79484 + .data = &grsec_enable_tpe,
79485 + .maxlen = sizeof(int),
79486 + .mode = 0600,
79487 + .proc_handler = &proc_dointvec,
79488 + },
79489 + {
79490 + .procname = "tpe_gid",
79491 + .data = &grsec_tpe_gid,
79492 + .maxlen = sizeof(int),
79493 + .mode = 0600,
79494 + .proc_handler = &proc_dointvec,
79495 + },
79496 +#endif
79497 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79498 + {
79499 + .procname = "tpe_invert",
79500 + .data = &grsec_enable_tpe_invert,
79501 + .maxlen = sizeof(int),
79502 + .mode = 0600,
79503 + .proc_handler = &proc_dointvec,
79504 + },
79505 +#endif
79506 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79507 + {
79508 + .procname = "tpe_restrict_all",
79509 + .data = &grsec_enable_tpe_all,
79510 + .maxlen = sizeof(int),
79511 + .mode = 0600,
79512 + .proc_handler = &proc_dointvec,
79513 + },
79514 +#endif
79515 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79516 + {
79517 + .procname = "socket_all",
79518 + .data = &grsec_enable_socket_all,
79519 + .maxlen = sizeof(int),
79520 + .mode = 0600,
79521 + .proc_handler = &proc_dointvec,
79522 + },
79523 + {
79524 + .procname = "socket_all_gid",
79525 + .data = &grsec_socket_all_gid,
79526 + .maxlen = sizeof(int),
79527 + .mode = 0600,
79528 + .proc_handler = &proc_dointvec,
79529 + },
79530 +#endif
79531 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79532 + {
79533 + .procname = "socket_client",
79534 + .data = &grsec_enable_socket_client,
79535 + .maxlen = sizeof(int),
79536 + .mode = 0600,
79537 + .proc_handler = &proc_dointvec,
79538 + },
79539 + {
79540 + .procname = "socket_client_gid",
79541 + .data = &grsec_socket_client_gid,
79542 + .maxlen = sizeof(int),
79543 + .mode = 0600,
79544 + .proc_handler = &proc_dointvec,
79545 + },
79546 +#endif
79547 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79548 + {
79549 + .procname = "socket_server",
79550 + .data = &grsec_enable_socket_server,
79551 + .maxlen = sizeof(int),
79552 + .mode = 0600,
79553 + .proc_handler = &proc_dointvec,
79554 + },
79555 + {
79556 + .procname = "socket_server_gid",
79557 + .data = &grsec_socket_server_gid,
79558 + .maxlen = sizeof(int),
79559 + .mode = 0600,
79560 + .proc_handler = &proc_dointvec,
79561 + },
79562 +#endif
79563 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79564 + {
79565 + .procname = "audit_group",
79566 + .data = &grsec_enable_group,
79567 + .maxlen = sizeof(int),
79568 + .mode = 0600,
79569 + .proc_handler = &proc_dointvec,
79570 + },
79571 + {
79572 + .procname = "audit_gid",
79573 + .data = &grsec_audit_gid,
79574 + .maxlen = sizeof(int),
79575 + .mode = 0600,
79576 + .proc_handler = &proc_dointvec,
79577 + },
79578 +#endif
79579 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79580 + {
79581 + .procname = "audit_chdir",
79582 + .data = &grsec_enable_chdir,
79583 + .maxlen = sizeof(int),
79584 + .mode = 0600,
79585 + .proc_handler = &proc_dointvec,
79586 + },
79587 +#endif
79588 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79589 + {
79590 + .procname = "audit_mount",
79591 + .data = &grsec_enable_mount,
79592 + .maxlen = sizeof(int),
79593 + .mode = 0600,
79594 + .proc_handler = &proc_dointvec,
79595 + },
79596 +#endif
79597 +#ifdef CONFIG_GRKERNSEC_DMESG
79598 + {
79599 + .procname = "dmesg",
79600 + .data = &grsec_enable_dmesg,
79601 + .maxlen = sizeof(int),
79602 + .mode = 0600,
79603 + .proc_handler = &proc_dointvec,
79604 + },
79605 +#endif
79606 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79607 + {
79608 + .procname = "chroot_findtask",
79609 + .data = &grsec_enable_chroot_findtask,
79610 + .maxlen = sizeof(int),
79611 + .mode = 0600,
79612 + .proc_handler = &proc_dointvec,
79613 + },
79614 +#endif
79615 +#ifdef CONFIG_GRKERNSEC_RESLOG
79616 + {
79617 + .procname = "resource_logging",
79618 + .data = &grsec_resource_logging,
79619 + .maxlen = sizeof(int),
79620 + .mode = 0600,
79621 + .proc_handler = &proc_dointvec,
79622 + },
79623 +#endif
79624 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79625 + {
79626 + .procname = "audit_ptrace",
79627 + .data = &grsec_enable_audit_ptrace,
79628 + .maxlen = sizeof(int),
79629 + .mode = 0600,
79630 + .proc_handler = &proc_dointvec,
79631 + },
79632 +#endif
79633 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79634 + {
79635 + .procname = "harden_ptrace",
79636 + .data = &grsec_enable_harden_ptrace,
79637 + .maxlen = sizeof(int),
79638 + .mode = 0600,
79639 + .proc_handler = &proc_dointvec,
79640 + },
79641 +#endif
79642 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79643 + {
79644 + .procname = "harden_ipc",
79645 + .data = &grsec_enable_harden_ipc,
79646 + .maxlen = sizeof(int),
79647 + .mode = 0600,
79648 + .proc_handler = &proc_dointvec,
79649 + },
79650 +#endif
79651 + {
79652 + .procname = "grsec_lock",
79653 + .data = &grsec_lock,
79654 + .maxlen = sizeof(int),
79655 + .mode = 0600,
79656 + .proc_handler = &proc_dointvec,
79657 + },
79658 +#endif
79659 +#ifdef CONFIG_GRKERNSEC_ROFS
79660 + {
79661 + .procname = "romount_protect",
79662 + .data = &grsec_enable_rofs,
79663 + .maxlen = sizeof(int),
79664 + .mode = 0600,
79665 + .proc_handler = &proc_dointvec_minmax,
79666 + .extra1 = &one,
79667 + .extra2 = &one,
79668 + },
79669 +#endif
79670 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79671 + {
79672 + .procname = "deny_new_usb",
79673 + .data = &grsec_deny_new_usb,
79674 + .maxlen = sizeof(int),
79675 + .mode = 0600,
79676 + .proc_handler = &proc_dointvec,
79677 + },
79678 +#endif
79679 + { }
79680 +};
79681 +#endif
79682 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79683 new file mode 100644
79684 index 0000000..61b514e
79685 --- /dev/null
79686 +++ b/grsecurity/grsec_time.c
79687 @@ -0,0 +1,16 @@
79688 +#include <linux/kernel.h>
79689 +#include <linux/sched.h>
79690 +#include <linux/grinternal.h>
79691 +#include <linux/module.h>
79692 +
79693 +void
79694 +gr_log_timechange(void)
79695 +{
79696 +#ifdef CONFIG_GRKERNSEC_TIME
79697 + if (grsec_enable_time)
79698 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79699 +#endif
79700 + return;
79701 +}
79702 +
79703 +EXPORT_SYMBOL_GPL(gr_log_timechange);
79704 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79705 new file mode 100644
79706 index 0000000..d1953de
79707 --- /dev/null
79708 +++ b/grsecurity/grsec_tpe.c
79709 @@ -0,0 +1,78 @@
79710 +#include <linux/kernel.h>
79711 +#include <linux/sched.h>
79712 +#include <linux/file.h>
79713 +#include <linux/fs.h>
79714 +#include <linux/grinternal.h>
79715 +
79716 +extern int gr_acl_tpe_check(void);
79717 +
79718 +int
79719 +gr_tpe_allow(const struct file *file)
79720 +{
79721 +#ifdef CONFIG_GRKERNSEC
79722 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79723 + struct inode *file_inode = file->f_path.dentry->d_inode;
79724 + const struct cred *cred = current_cred();
79725 + char *msg = NULL;
79726 + char *msg2 = NULL;
79727 +
79728 + // never restrict root
79729 + if (gr_is_global_root(cred->uid))
79730 + return 1;
79731 +
79732 + if (grsec_enable_tpe) {
79733 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79734 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79735 + msg = "not being in trusted group";
79736 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79737 + msg = "being in untrusted group";
79738 +#else
79739 + if (in_group_p(grsec_tpe_gid))
79740 + msg = "being in untrusted group";
79741 +#endif
79742 + }
79743 + if (!msg && gr_acl_tpe_check())
79744 + msg = "being in untrusted role";
79745 +
79746 + // not in any affected group/role
79747 + if (!msg)
79748 + goto next_check;
79749 +
79750 + if (gr_is_global_nonroot(inode->i_uid))
79751 + msg2 = "file in non-root-owned directory";
79752 + else if (inode->i_mode & S_IWOTH)
79753 + msg2 = "file in world-writable directory";
79754 + else if (inode->i_mode & S_IWGRP)
79755 + msg2 = "file in group-writable directory";
79756 + else if (file_inode->i_mode & S_IWOTH)
79757 + msg2 = "file is world-writable";
79758 +
79759 + if (msg && msg2) {
79760 + char fullmsg[70] = {0};
79761 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79762 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79763 + return 0;
79764 + }
79765 + msg = NULL;
79766 +next_check:
79767 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79768 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79769 + return 1;
79770 +
79771 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79772 + msg = "directory not owned by user";
79773 + else if (inode->i_mode & S_IWOTH)
79774 + msg = "file in world-writable directory";
79775 + else if (inode->i_mode & S_IWGRP)
79776 + msg = "file in group-writable directory";
79777 + else if (file_inode->i_mode & S_IWOTH)
79778 + msg = "file is world-writable";
79779 +
79780 + if (msg) {
79781 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79782 + return 0;
79783 + }
79784 +#endif
79785 +#endif
79786 + return 1;
79787 +}
79788 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79789 new file mode 100644
79790 index 0000000..ae02d8e
79791 --- /dev/null
79792 +++ b/grsecurity/grsec_usb.c
79793 @@ -0,0 +1,15 @@
79794 +#include <linux/kernel.h>
79795 +#include <linux/grinternal.h>
79796 +#include <linux/module.h>
79797 +
79798 +int gr_handle_new_usb(void)
79799 +{
79800 +#ifdef CONFIG_GRKERNSEC_DENYUSB
79801 + if (grsec_deny_new_usb) {
79802 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79803 + return 1;
79804 + }
79805 +#endif
79806 + return 0;
79807 +}
79808 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79809 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79810 new file mode 100644
79811 index 0000000..158b330
79812 --- /dev/null
79813 +++ b/grsecurity/grsum.c
79814 @@ -0,0 +1,64 @@
79815 +#include <linux/err.h>
79816 +#include <linux/kernel.h>
79817 +#include <linux/sched.h>
79818 +#include <linux/mm.h>
79819 +#include <linux/scatterlist.h>
79820 +#include <linux/crypto.h>
79821 +#include <linux/gracl.h>
79822 +
79823 +
79824 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79825 +#error "crypto and sha256 must be built into the kernel"
79826 +#endif
79827 +
79828 +int
79829 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79830 +{
79831 + struct crypto_hash *tfm;
79832 + struct hash_desc desc;
79833 + struct scatterlist sg[2];
79834 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79835 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79836 + unsigned long *sumptr = (unsigned long *)sum;
79837 + int cryptres;
79838 + int retval = 1;
79839 + volatile int mismatched = 0;
79840 + volatile int dummy = 0;
79841 + unsigned int i;
79842 +
79843 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79844 + if (IS_ERR(tfm)) {
79845 + /* should never happen, since sha256 should be built in */
79846 + memset(entry->pw, 0, GR_PW_LEN);
79847 + return 1;
79848 + }
79849 +
79850 + sg_init_table(sg, 2);
79851 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79852 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79853 +
79854 + desc.tfm = tfm;
79855 + desc.flags = 0;
79856 +
79857 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79858 + temp_sum);
79859 +
79860 + memset(entry->pw, 0, GR_PW_LEN);
79861 +
79862 + if (cryptres)
79863 + goto out;
79864 +
79865 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79866 + if (sumptr[i] != tmpsumptr[i])
79867 + mismatched = 1;
79868 + else
79869 + dummy = 1; // waste a cycle
79870 +
79871 + if (!mismatched)
79872 + retval = dummy - 1;
79873 +
79874 +out:
79875 + crypto_free_hash(tfm);
79876 +
79877 + return retval;
79878 +}
79879 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79880 index 77ff547..181834f 100644
79881 --- a/include/asm-generic/4level-fixup.h
79882 +++ b/include/asm-generic/4level-fixup.h
79883 @@ -13,8 +13,10 @@
79884 #define pmd_alloc(mm, pud, address) \
79885 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79886 NULL: pmd_offset(pud, address))
79887 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79888
79889 #define pud_alloc(mm, pgd, address) (pgd)
79890 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79891 #define pud_offset(pgd, start) (pgd)
79892 #define pud_none(pud) 0
79893 #define pud_bad(pud) 0
79894 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79895 index b7babf0..97f4c4f 100644
79896 --- a/include/asm-generic/atomic-long.h
79897 +++ b/include/asm-generic/atomic-long.h
79898 @@ -22,6 +22,12 @@
79899
79900 typedef atomic64_t atomic_long_t;
79901
79902 +#ifdef CONFIG_PAX_REFCOUNT
79903 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
79904 +#else
79905 +typedef atomic64_t atomic_long_unchecked_t;
79906 +#endif
79907 +
79908 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79909
79910 static inline long atomic_long_read(atomic_long_t *l)
79911 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79912 return (long)atomic64_read(v);
79913 }
79914
79915 +#ifdef CONFIG_PAX_REFCOUNT
79916 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79917 +{
79918 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79919 +
79920 + return (long)atomic64_read_unchecked(v);
79921 +}
79922 +#endif
79923 +
79924 static inline void atomic_long_set(atomic_long_t *l, long i)
79925 {
79926 atomic64_t *v = (atomic64_t *)l;
79927 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79928 atomic64_set(v, i);
79929 }
79930
79931 +#ifdef CONFIG_PAX_REFCOUNT
79932 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79933 +{
79934 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79935 +
79936 + atomic64_set_unchecked(v, i);
79937 +}
79938 +#endif
79939 +
79940 static inline void atomic_long_inc(atomic_long_t *l)
79941 {
79942 atomic64_t *v = (atomic64_t *)l;
79943 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79944 atomic64_inc(v);
79945 }
79946
79947 +#ifdef CONFIG_PAX_REFCOUNT
79948 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79949 +{
79950 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79951 +
79952 + atomic64_inc_unchecked(v);
79953 +}
79954 +#endif
79955 +
79956 static inline void atomic_long_dec(atomic_long_t *l)
79957 {
79958 atomic64_t *v = (atomic64_t *)l;
79959 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79960 atomic64_dec(v);
79961 }
79962
79963 +#ifdef CONFIG_PAX_REFCOUNT
79964 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79965 +{
79966 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79967 +
79968 + atomic64_dec_unchecked(v);
79969 +}
79970 +#endif
79971 +
79972 static inline void atomic_long_add(long i, atomic_long_t *l)
79973 {
79974 atomic64_t *v = (atomic64_t *)l;
79975 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79976 atomic64_add(i, v);
79977 }
79978
79979 +#ifdef CONFIG_PAX_REFCOUNT
79980 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79981 +{
79982 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79983 +
79984 + atomic64_add_unchecked(i, v);
79985 +}
79986 +#endif
79987 +
79988 static inline void atomic_long_sub(long i, atomic_long_t *l)
79989 {
79990 atomic64_t *v = (atomic64_t *)l;
79991 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79992 atomic64_sub(i, v);
79993 }
79994
79995 +#ifdef CONFIG_PAX_REFCOUNT
79996 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79997 +{
79998 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79999 +
80000 + atomic64_sub_unchecked(i, v);
80001 +}
80002 +#endif
80003 +
80004 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
80005 {
80006 atomic64_t *v = (atomic64_t *)l;
80007 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
80008 return atomic64_add_negative(i, v);
80009 }
80010
80011 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
80012 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
80013 {
80014 atomic64_t *v = (atomic64_t *)l;
80015
80016 return (long)atomic64_add_return(i, v);
80017 }
80018
80019 +#ifdef CONFIG_PAX_REFCOUNT
80020 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
80021 +{
80022 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80023 +
80024 + return (long)atomic64_add_return_unchecked(i, v);
80025 +}
80026 +#endif
80027 +
80028 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
80029 {
80030 atomic64_t *v = (atomic64_t *)l;
80031 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
80032 return (long)atomic64_inc_return(v);
80033 }
80034
80035 +#ifdef CONFIG_PAX_REFCOUNT
80036 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
80037 +{
80038 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80039 +
80040 + return (long)atomic64_inc_return_unchecked(v);
80041 +}
80042 +#endif
80043 +
80044 static inline long atomic_long_dec_return(atomic_long_t *l)
80045 {
80046 atomic64_t *v = (atomic64_t *)l;
80047 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
80048
80049 typedef atomic_t atomic_long_t;
80050
80051 +#ifdef CONFIG_PAX_REFCOUNT
80052 +typedef atomic_unchecked_t atomic_long_unchecked_t;
80053 +#else
80054 +typedef atomic_t atomic_long_unchecked_t;
80055 +#endif
80056 +
80057 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
80058 static inline long atomic_long_read(atomic_long_t *l)
80059 {
80060 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
80061 return (long)atomic_read(v);
80062 }
80063
80064 +#ifdef CONFIG_PAX_REFCOUNT
80065 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
80066 +{
80067 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80068 +
80069 + return (long)atomic_read_unchecked(v);
80070 +}
80071 +#endif
80072 +
80073 static inline void atomic_long_set(atomic_long_t *l, long i)
80074 {
80075 atomic_t *v = (atomic_t *)l;
80076 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
80077 atomic_set(v, i);
80078 }
80079
80080 +#ifdef CONFIG_PAX_REFCOUNT
80081 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
80082 +{
80083 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80084 +
80085 + atomic_set_unchecked(v, i);
80086 +}
80087 +#endif
80088 +
80089 static inline void atomic_long_inc(atomic_long_t *l)
80090 {
80091 atomic_t *v = (atomic_t *)l;
80092 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
80093 atomic_inc(v);
80094 }
80095
80096 +#ifdef CONFIG_PAX_REFCOUNT
80097 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
80098 +{
80099 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80100 +
80101 + atomic_inc_unchecked(v);
80102 +}
80103 +#endif
80104 +
80105 static inline void atomic_long_dec(atomic_long_t *l)
80106 {
80107 atomic_t *v = (atomic_t *)l;
80108 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
80109 atomic_dec(v);
80110 }
80111
80112 +#ifdef CONFIG_PAX_REFCOUNT
80113 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
80114 +{
80115 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80116 +
80117 + atomic_dec_unchecked(v);
80118 +}
80119 +#endif
80120 +
80121 static inline void atomic_long_add(long i, atomic_long_t *l)
80122 {
80123 atomic_t *v = (atomic_t *)l;
80124 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
80125 atomic_add(i, v);
80126 }
80127
80128 +#ifdef CONFIG_PAX_REFCOUNT
80129 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
80130 +{
80131 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80132 +
80133 + atomic_add_unchecked(i, v);
80134 +}
80135 +#endif
80136 +
80137 static inline void atomic_long_sub(long i, atomic_long_t *l)
80138 {
80139 atomic_t *v = (atomic_t *)l;
80140 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
80141 atomic_sub(i, v);
80142 }
80143
80144 +#ifdef CONFIG_PAX_REFCOUNT
80145 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
80146 +{
80147 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80148 +
80149 + atomic_sub_unchecked(i, v);
80150 +}
80151 +#endif
80152 +
80153 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
80154 {
80155 atomic_t *v = (atomic_t *)l;
80156 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
80157 return (long)atomic_add_return(i, v);
80158 }
80159
80160 +#ifdef CONFIG_PAX_REFCOUNT
80161 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
80162 +{
80163 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80164 +
80165 + return (long)atomic_add_return_unchecked(i, v);
80166 +}
80167 +
80168 +#endif
80169 +
80170 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
80171 {
80172 atomic_t *v = (atomic_t *)l;
80173 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
80174 return (long)atomic_inc_return(v);
80175 }
80176
80177 +#ifdef CONFIG_PAX_REFCOUNT
80178 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
80179 +{
80180 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80181 +
80182 + return (long)atomic_inc_return_unchecked(v);
80183 +}
80184 +#endif
80185 +
80186 static inline long atomic_long_dec_return(atomic_long_t *l)
80187 {
80188 atomic_t *v = (atomic_t *)l;
80189 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
80190
80191 #endif /* BITS_PER_LONG == 64 */
80192
80193 +#ifdef CONFIG_PAX_REFCOUNT
80194 +static inline void pax_refcount_needs_these_functions(void)
80195 +{
80196 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
80197 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
80198 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
80199 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
80200 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
80201 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
80202 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
80203 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
80204 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
80205 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
80206 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
80207 +#ifdef CONFIG_X86
80208 + atomic_clear_mask_unchecked(0, NULL);
80209 + atomic_set_mask_unchecked(0, NULL);
80210 +#endif
80211 +
80212 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
80213 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
80214 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
80215 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
80216 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
80217 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
80218 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
80219 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
80220 +}
80221 +#else
80222 +#define atomic_read_unchecked(v) atomic_read(v)
80223 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
80224 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
80225 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
80226 +#define atomic_inc_unchecked(v) atomic_inc(v)
80227 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
80228 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
80229 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
80230 +#define atomic_dec_unchecked(v) atomic_dec(v)
80231 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
80232 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
80233 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
80234 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
80235 +
80236 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
80237 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
80238 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
80239 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
80240 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
80241 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
80242 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
80243 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
80244 +#endif
80245 +
80246 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
80247 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
80248 index 9c79e76..9f7827d 100644
80249 --- a/include/asm-generic/atomic.h
80250 +++ b/include/asm-generic/atomic.h
80251 @@ -154,7 +154,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
80252 * Atomically clears the bits set in @mask from @v
80253 */
80254 #ifndef atomic_clear_mask
80255 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
80256 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
80257 {
80258 unsigned long flags;
80259
80260 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
80261 index b18ce4f..2ee2843 100644
80262 --- a/include/asm-generic/atomic64.h
80263 +++ b/include/asm-generic/atomic64.h
80264 @@ -16,6 +16,8 @@ typedef struct {
80265 long long counter;
80266 } atomic64_t;
80267
80268 +typedef atomic64_t atomic64_unchecked_t;
80269 +
80270 #define ATOMIC64_INIT(i) { (i) }
80271
80272 extern long long atomic64_read(const atomic64_t *v);
80273 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
80274 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
80275 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
80276
80277 +#define atomic64_read_unchecked(v) atomic64_read(v)
80278 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
80279 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
80280 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
80281 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
80282 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
80283 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
80284 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
80285 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
80286 +
80287 #endif /* _ASM_GENERIC_ATOMIC64_H */
80288 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
80289 index 1402fa8..025a736 100644
80290 --- a/include/asm-generic/barrier.h
80291 +++ b/include/asm-generic/barrier.h
80292 @@ -74,7 +74,7 @@
80293 do { \
80294 compiletime_assert_atomic_type(*p); \
80295 smp_mb(); \
80296 - ACCESS_ONCE(*p) = (v); \
80297 + ACCESS_ONCE_RW(*p) = (v); \
80298 } while (0)
80299
80300 #define smp_load_acquire(p) \
80301 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
80302 index a60a7cc..0fe12f2 100644
80303 --- a/include/asm-generic/bitops/__fls.h
80304 +++ b/include/asm-generic/bitops/__fls.h
80305 @@ -9,7 +9,7 @@
80306 *
80307 * Undefined if no set bit exists, so code should check against 0 first.
80308 */
80309 -static __always_inline unsigned long __fls(unsigned long word)
80310 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
80311 {
80312 int num = BITS_PER_LONG - 1;
80313
80314 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
80315 index 0576d1f..dad6c71 100644
80316 --- a/include/asm-generic/bitops/fls.h
80317 +++ b/include/asm-generic/bitops/fls.h
80318 @@ -9,7 +9,7 @@
80319 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
80320 */
80321
80322 -static __always_inline int fls(int x)
80323 +static __always_inline int __intentional_overflow(-1) fls(int x)
80324 {
80325 int r = 32;
80326
80327 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
80328 index b097cf8..3d40e14 100644
80329 --- a/include/asm-generic/bitops/fls64.h
80330 +++ b/include/asm-generic/bitops/fls64.h
80331 @@ -15,7 +15,7 @@
80332 * at position 64.
80333 */
80334 #if BITS_PER_LONG == 32
80335 -static __always_inline int fls64(__u64 x)
80336 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80337 {
80338 __u32 h = x >> 32;
80339 if (h)
80340 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
80341 return fls(x);
80342 }
80343 #elif BITS_PER_LONG == 64
80344 -static __always_inline int fls64(__u64 x)
80345 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80346 {
80347 if (x == 0)
80348 return 0;
80349 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
80350 index 1bfcfe5..e04c5c9 100644
80351 --- a/include/asm-generic/cache.h
80352 +++ b/include/asm-generic/cache.h
80353 @@ -6,7 +6,7 @@
80354 * cache lines need to provide their own cache.h.
80355 */
80356
80357 -#define L1_CACHE_SHIFT 5
80358 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
80359 +#define L1_CACHE_SHIFT 5UL
80360 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
80361
80362 #endif /* __ASM_GENERIC_CACHE_H */
80363 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
80364 index 0d68a1e..b74a761 100644
80365 --- a/include/asm-generic/emergency-restart.h
80366 +++ b/include/asm-generic/emergency-restart.h
80367 @@ -1,7 +1,7 @@
80368 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
80369 #define _ASM_GENERIC_EMERGENCY_RESTART_H
80370
80371 -static inline void machine_emergency_restart(void)
80372 +static inline __noreturn void machine_emergency_restart(void)
80373 {
80374 machine_restart(NULL);
80375 }
80376 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
80377 index 975e1cc..0b8a083 100644
80378 --- a/include/asm-generic/io.h
80379 +++ b/include/asm-generic/io.h
80380 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
80381 * These are pretty trivial
80382 */
80383 #ifndef virt_to_phys
80384 -static inline unsigned long virt_to_phys(volatile void *address)
80385 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
80386 {
80387 return __pa((unsigned long)address);
80388 }
80389 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
80390 index 90f99c7..00ce236 100644
80391 --- a/include/asm-generic/kmap_types.h
80392 +++ b/include/asm-generic/kmap_types.h
80393 @@ -2,9 +2,9 @@
80394 #define _ASM_GENERIC_KMAP_TYPES_H
80395
80396 #ifdef __WITH_KM_FENCE
80397 -# define KM_TYPE_NR 41
80398 +# define KM_TYPE_NR 42
80399 #else
80400 -# define KM_TYPE_NR 20
80401 +# define KM_TYPE_NR 21
80402 #endif
80403
80404 #endif
80405 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
80406 index 9ceb03b..62b0b8f 100644
80407 --- a/include/asm-generic/local.h
80408 +++ b/include/asm-generic/local.h
80409 @@ -23,24 +23,37 @@ typedef struct
80410 atomic_long_t a;
80411 } local_t;
80412
80413 +typedef struct {
80414 + atomic_long_unchecked_t a;
80415 +} local_unchecked_t;
80416 +
80417 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
80418
80419 #define local_read(l) atomic_long_read(&(l)->a)
80420 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
80421 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
80422 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
80423 #define local_inc(l) atomic_long_inc(&(l)->a)
80424 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
80425 #define local_dec(l) atomic_long_dec(&(l)->a)
80426 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
80427 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
80428 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
80429 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
80430 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
80431
80432 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
80433 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
80434 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
80435 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
80436 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
80437 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
80438 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
80439 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
80440 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
80441
80442 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80443 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80444 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
80445 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
80446 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
80447 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
80448 index 725612b..9cc513a 100644
80449 --- a/include/asm-generic/pgtable-nopmd.h
80450 +++ b/include/asm-generic/pgtable-nopmd.h
80451 @@ -1,14 +1,19 @@
80452 #ifndef _PGTABLE_NOPMD_H
80453 #define _PGTABLE_NOPMD_H
80454
80455 -#ifndef __ASSEMBLY__
80456 -
80457 #include <asm-generic/pgtable-nopud.h>
80458
80459 -struct mm_struct;
80460 -
80461 #define __PAGETABLE_PMD_FOLDED
80462
80463 +#define PMD_SHIFT PUD_SHIFT
80464 +#define PTRS_PER_PMD 1
80465 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
80466 +#define PMD_MASK (~(PMD_SIZE-1))
80467 +
80468 +#ifndef __ASSEMBLY__
80469 +
80470 +struct mm_struct;
80471 +
80472 /*
80473 * Having the pmd type consist of a pud gets the size right, and allows
80474 * us to conceptually access the pud entry that this pmd is folded into
80475 @@ -16,11 +21,6 @@ struct mm_struct;
80476 */
80477 typedef struct { pud_t pud; } pmd_t;
80478
80479 -#define PMD_SHIFT PUD_SHIFT
80480 -#define PTRS_PER_PMD 1
80481 -#define PMD_SIZE (1UL << PMD_SHIFT)
80482 -#define PMD_MASK (~(PMD_SIZE-1))
80483 -
80484 /*
80485 * The "pud_xxx()" functions here are trivial for a folded two-level
80486 * setup: the pmd is never bad, and a pmd always exists (as it's folded
80487 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
80488 index 810431d..0ec4804f 100644
80489 --- a/include/asm-generic/pgtable-nopud.h
80490 +++ b/include/asm-generic/pgtable-nopud.h
80491 @@ -1,10 +1,15 @@
80492 #ifndef _PGTABLE_NOPUD_H
80493 #define _PGTABLE_NOPUD_H
80494
80495 -#ifndef __ASSEMBLY__
80496 -
80497 #define __PAGETABLE_PUD_FOLDED
80498
80499 +#define PUD_SHIFT PGDIR_SHIFT
80500 +#define PTRS_PER_PUD 1
80501 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
80502 +#define PUD_MASK (~(PUD_SIZE-1))
80503 +
80504 +#ifndef __ASSEMBLY__
80505 +
80506 /*
80507 * Having the pud type consist of a pgd gets the size right, and allows
80508 * us to conceptually access the pgd entry that this pud is folded into
80509 @@ -12,11 +17,6 @@
80510 */
80511 typedef struct { pgd_t pgd; } pud_t;
80512
80513 -#define PUD_SHIFT PGDIR_SHIFT
80514 -#define PTRS_PER_PUD 1
80515 -#define PUD_SIZE (1UL << PUD_SHIFT)
80516 -#define PUD_MASK (~(PUD_SIZE-1))
80517 -
80518 /*
80519 * The "pgd_xxx()" functions here are trivial for a folded two-level
80520 * setup: the pud is never bad, and a pud always exists (as it's folded
80521 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
80522 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
80523
80524 #define pgd_populate(mm, pgd, pud) do { } while (0)
80525 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
80526 /*
80527 * (puds are folded into pgds so this doesn't get actually called,
80528 * but the define is needed for a generic inline function.)
80529 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
80530 index 53b2acc..f4568e7 100644
80531 --- a/include/asm-generic/pgtable.h
80532 +++ b/include/asm-generic/pgtable.h
80533 @@ -819,6 +819,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
80534 }
80535 #endif /* CONFIG_NUMA_BALANCING */
80536
80537 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
80538 +#ifdef CONFIG_PAX_KERNEXEC
80539 +#error KERNEXEC requires pax_open_kernel
80540 +#else
80541 +static inline unsigned long pax_open_kernel(void) { return 0; }
80542 +#endif
80543 +#endif
80544 +
80545 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
80546 +#ifdef CONFIG_PAX_KERNEXEC
80547 +#error KERNEXEC requires pax_close_kernel
80548 +#else
80549 +static inline unsigned long pax_close_kernel(void) { return 0; }
80550 +#endif
80551 +#endif
80552 +
80553 #endif /* CONFIG_MMU */
80554
80555 #endif /* !__ASSEMBLY__ */
80556 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80557 index 72d8803..cb9749c 100644
80558 --- a/include/asm-generic/uaccess.h
80559 +++ b/include/asm-generic/uaccess.h
80560 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80561 return __clear_user(to, n);
80562 }
80563
80564 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80566 +#error UDEREF requires pax_open_userland
80567 +#else
80568 +static inline unsigned long pax_open_userland(void) { return 0; }
80569 +#endif
80570 +#endif
80571 +
80572 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80573 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80574 +#error UDEREF requires pax_close_userland
80575 +#else
80576 +static inline unsigned long pax_close_userland(void) { return 0; }
80577 +#endif
80578 +#endif
80579 +
80580 #endif /* __ASM_GENERIC_UACCESS_H */
80581 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80582 index c1c0b0c..05c9588 100644
80583 --- a/include/asm-generic/vmlinux.lds.h
80584 +++ b/include/asm-generic/vmlinux.lds.h
80585 @@ -231,6 +231,7 @@
80586 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80587 VMLINUX_SYMBOL(__start_rodata) = .; \
80588 *(.rodata) *(.rodata.*) \
80589 + *(.data..read_only) \
80590 *(__vermagic) /* Kernel version magic */ \
80591 . = ALIGN(8); \
80592 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80593 @@ -719,17 +720,18 @@
80594 * section in the linker script will go there too. @phdr should have
80595 * a leading colon.
80596 *
80597 - * Note that this macros defines __per_cpu_load as an absolute symbol.
80598 + * Note that this macros defines per_cpu_load as an absolute symbol.
80599 * If there is no need to put the percpu section at a predetermined
80600 * address, use PERCPU_SECTION.
80601 */
80602 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80603 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
80604 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80605 + per_cpu_load = .; \
80606 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80607 - LOAD_OFFSET) { \
80608 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80609 PERCPU_INPUT(cacheline) \
80610 } phdr \
80611 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80612 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80613
80614 /**
80615 * PERCPU_SECTION - define output section for percpu area, simple version
80616 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80617 index 016c2f1..c4baa98 100644
80618 --- a/include/crypto/algapi.h
80619 +++ b/include/crypto/algapi.h
80620 @@ -34,7 +34,7 @@ struct crypto_type {
80621 unsigned int maskclear;
80622 unsigned int maskset;
80623 unsigned int tfmsize;
80624 -};
80625 +} __do_const;
80626
80627 struct crypto_instance {
80628 struct crypto_alg alg;
80629 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80630 index 8af71a8..7fe6c19 100644
80631 --- a/include/drm/drmP.h
80632 +++ b/include/drm/drmP.h
80633 @@ -68,6 +68,7 @@
80634 #include <linux/workqueue.h>
80635 #include <linux/poll.h>
80636 #include <asm/pgalloc.h>
80637 +#include <asm/local.h>
80638 #include <drm/drm.h>
80639 #include <drm/drm_sarea.h>
80640 #include <drm/drm_vma_manager.h>
80641 @@ -261,10 +262,12 @@ do { \
80642 * \param cmd command.
80643 * \param arg argument.
80644 */
80645 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80646 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80647 + struct drm_file *file_priv);
80648 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80649 struct drm_file *file_priv);
80650
80651 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80652 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80653 unsigned long arg);
80654
80655 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80656 @@ -280,10 +283,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80657 struct drm_ioctl_desc {
80658 unsigned int cmd;
80659 int flags;
80660 - drm_ioctl_t *func;
80661 + drm_ioctl_t func;
80662 unsigned int cmd_drv;
80663 const char *name;
80664 -};
80665 +} __do_const;
80666
80667 /**
80668 * Creates a driver or general drm_ioctl_desc array entry for the given
80669 @@ -983,7 +986,8 @@ struct drm_info_list {
80670 int (*show)(struct seq_file*, void*); /** show callback */
80671 u32 driver_features; /**< Required driver features for this entry */
80672 void *data;
80673 -};
80674 +} __do_const;
80675 +typedef struct drm_info_list __no_const drm_info_list_no_const;
80676
80677 /**
80678 * debugfs node structure. This structure represents a debugfs file.
80679 @@ -1067,7 +1071,7 @@ struct drm_device {
80680
80681 /** \name Usage Counters */
80682 /*@{ */
80683 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80684 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80685 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80686 int buf_use; /**< Buffers in use -- cannot alloc */
80687 atomic_t buf_alloc; /**< Buffer allocation in progress */
80688 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80689 index a3d75fe..6802f9c 100644
80690 --- a/include/drm/drm_crtc_helper.h
80691 +++ b/include/drm/drm_crtc_helper.h
80692 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80693 struct drm_connector *connector);
80694 /* disable encoder when not in use - more explicit than dpms off */
80695 void (*disable)(struct drm_encoder *encoder);
80696 -};
80697 +} __no_const;
80698
80699 /**
80700 * drm_connector_helper_funcs - helper operations for connectors
80701 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80702 index a70d456..6ea07cd 100644
80703 --- a/include/drm/i915_pciids.h
80704 +++ b/include/drm/i915_pciids.h
80705 @@ -37,7 +37,7 @@
80706 */
80707 #define INTEL_VGA_DEVICE(id, info) { \
80708 0x8086, id, \
80709 - ~0, ~0, \
80710 + PCI_ANY_ID, PCI_ANY_ID, \
80711 0x030000, 0xff0000, \
80712 (unsigned long) info }
80713
80714 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80715 index 72dcbe8..8db58d7 100644
80716 --- a/include/drm/ttm/ttm_memory.h
80717 +++ b/include/drm/ttm/ttm_memory.h
80718 @@ -48,7 +48,7 @@
80719
80720 struct ttm_mem_shrink {
80721 int (*do_shrink) (struct ttm_mem_shrink *);
80722 -};
80723 +} __no_const;
80724
80725 /**
80726 * struct ttm_mem_global - Global memory accounting structure.
80727 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80728 index 49a8284..9643967 100644
80729 --- a/include/drm/ttm/ttm_page_alloc.h
80730 +++ b/include/drm/ttm/ttm_page_alloc.h
80731 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80732 */
80733 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80734
80735 +struct device;
80736 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80737 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80738
80739 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80740 index 4b840e8..155d235 100644
80741 --- a/include/keys/asymmetric-subtype.h
80742 +++ b/include/keys/asymmetric-subtype.h
80743 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80744 /* Verify the signature on a key of this subtype (optional) */
80745 int (*verify_signature)(const struct key *key,
80746 const struct public_key_signature *sig);
80747 -};
80748 +} __do_const;
80749
80750 /**
80751 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80752 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80753 index c1da539..1dcec55 100644
80754 --- a/include/linux/atmdev.h
80755 +++ b/include/linux/atmdev.h
80756 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80757 #endif
80758
80759 struct k_atm_aal_stats {
80760 -#define __HANDLE_ITEM(i) atomic_t i
80761 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80762 __AAL_STAT_ITEMS
80763 #undef __HANDLE_ITEM
80764 };
80765 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80766 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80767 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80768 struct module *owner;
80769 -};
80770 +} __do_const ;
80771
80772 struct atmphy_ops {
80773 int (*start)(struct atm_dev *dev);
80774 diff --git a/include/linux/audit.h b/include/linux/audit.h
80775 index 22cfddb..ab759e8 100644
80776 --- a/include/linux/audit.h
80777 +++ b/include/linux/audit.h
80778 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
80779 extern unsigned int audit_serial(void);
80780 extern int auditsc_get_stamp(struct audit_context *ctx,
80781 struct timespec *t, unsigned int *serial);
80782 -extern int audit_set_loginuid(kuid_t loginuid);
80783 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80784
80785 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80786 {
80787 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80788 index 61f29e5..e67c658 100644
80789 --- a/include/linux/binfmts.h
80790 +++ b/include/linux/binfmts.h
80791 @@ -44,7 +44,7 @@ struct linux_binprm {
80792 unsigned interp_flags;
80793 unsigned interp_data;
80794 unsigned long loader, exec;
80795 -};
80796 +} __randomize_layout;
80797
80798 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80799 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80800 @@ -73,8 +73,10 @@ struct linux_binfmt {
80801 int (*load_binary)(struct linux_binprm *);
80802 int (*load_shlib)(struct file *);
80803 int (*core_dump)(struct coredump_params *cprm);
80804 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80805 + void (*handle_mmap)(struct file *);
80806 unsigned long min_coredump; /* minimal dump size */
80807 -};
80808 +} __do_const __randomize_layout;
80809
80810 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80811
80812 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80813 index cbc5833..8123ebc 100644
80814 --- a/include/linux/bitops.h
80815 +++ b/include/linux/bitops.h
80816 @@ -122,7 +122,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80817 * @word: value to rotate
80818 * @shift: bits to roll
80819 */
80820 -static inline __u32 rol32(__u32 word, unsigned int shift)
80821 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80822 {
80823 return (word << shift) | (word >> (32 - shift));
80824 }
80825 @@ -132,7 +132,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80826 * @word: value to rotate
80827 * @shift: bits to roll
80828 */
80829 -static inline __u32 ror32(__u32 word, unsigned int shift)
80830 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80831 {
80832 return (word >> shift) | (word << (32 - shift));
80833 }
80834 @@ -188,7 +188,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80835 return (__s32)(value << shift) >> shift;
80836 }
80837
80838 -static inline unsigned fls_long(unsigned long l)
80839 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80840 {
80841 if (sizeof(l) == 4)
80842 return fls(l);
80843 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80844 index 8699bcf..279485d 100644
80845 --- a/include/linux/blkdev.h
80846 +++ b/include/linux/blkdev.h
80847 @@ -1625,7 +1625,7 @@ struct block_device_operations {
80848 /* this callback is with swap_lock and sometimes page table lock held */
80849 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80850 struct module *owner;
80851 -};
80852 +} __do_const;
80853
80854 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80855 unsigned long);
80856 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80857 index afc1343..9735539 100644
80858 --- a/include/linux/blktrace_api.h
80859 +++ b/include/linux/blktrace_api.h
80860 @@ -25,7 +25,7 @@ struct blk_trace {
80861 struct dentry *dropped_file;
80862 struct dentry *msg_file;
80863 struct list_head running_list;
80864 - atomic_t dropped;
80865 + atomic_unchecked_t dropped;
80866 };
80867
80868 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80869 diff --git a/include/linux/cache.h b/include/linux/cache.h
80870 index 17e7e82..1d7da26 100644
80871 --- a/include/linux/cache.h
80872 +++ b/include/linux/cache.h
80873 @@ -16,6 +16,14 @@
80874 #define __read_mostly
80875 #endif
80876
80877 +#ifndef __read_only
80878 +#ifdef CONFIG_PAX_KERNEXEC
80879 +#error KERNEXEC requires __read_only
80880 +#else
80881 +#define __read_only __read_mostly
80882 +#endif
80883 +#endif
80884 +
80885 #ifndef ____cacheline_aligned
80886 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80887 #endif
80888 diff --git a/include/linux/capability.h b/include/linux/capability.h
80889 index 84b13ad..172cdee 100644
80890 --- a/include/linux/capability.h
80891 +++ b/include/linux/capability.h
80892 @@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80893 extern bool capable(int cap);
80894 extern bool ns_capable(struct user_namespace *ns, int cap);
80895 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80896 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80897 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80898 +extern bool capable_nolog(int cap);
80899 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80900
80901 /* audit system wants to get cap info from files as well */
80902 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80903
80904 +extern int is_privileged_binary(const struct dentry *dentry);
80905 +
80906 #endif /* !_LINUX_CAPABILITY_H */
80907 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80908 index 8609d57..86e4d79 100644
80909 --- a/include/linux/cdrom.h
80910 +++ b/include/linux/cdrom.h
80911 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
80912
80913 /* driver specifications */
80914 const int capability; /* capability flags */
80915 - int n_minors; /* number of active minor devices */
80916 /* handle uniform packets for scsi type devices (scsi,atapi) */
80917 int (*generic_packet) (struct cdrom_device_info *,
80918 struct packet_command *);
80919 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80920 index 4ce9056..86caac6 100644
80921 --- a/include/linux/cleancache.h
80922 +++ b/include/linux/cleancache.h
80923 @@ -31,7 +31,7 @@ struct cleancache_ops {
80924 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80925 void (*invalidate_inode)(int, struct cleancache_filekey);
80926 void (*invalidate_fs)(int);
80927 -};
80928 +} __no_const;
80929
80930 extern struct cleancache_ops *
80931 cleancache_register_ops(struct cleancache_ops *ops);
80932 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80933 index 0c287db..5efa775 100644
80934 --- a/include/linux/clk-provider.h
80935 +++ b/include/linux/clk-provider.h
80936 @@ -180,6 +180,7 @@ struct clk_ops {
80937 void (*init)(struct clk_hw *hw);
80938 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80939 };
80940 +typedef struct clk_ops __no_const clk_ops_no_const;
80941
80942 /**
80943 * struct clk_init_data - holds init data that's common to all clocks and is
80944 diff --git a/include/linux/compat.h b/include/linux/compat.h
80945 index e649426..a74047b 100644
80946 --- a/include/linux/compat.h
80947 +++ b/include/linux/compat.h
80948 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80949 compat_size_t __user *len_ptr);
80950
80951 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80952 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80953 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80954 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80955 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80956 compat_ssize_t msgsz, int msgflg);
80957 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80958 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80959 compat_ulong_t addr, compat_ulong_t data);
80960 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80961 - compat_long_t addr, compat_long_t data);
80962 + compat_ulong_t addr, compat_ulong_t data);
80963
80964 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80965 /*
80966 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80967 index 2507fd2..55203f8 100644
80968 --- a/include/linux/compiler-gcc4.h
80969 +++ b/include/linux/compiler-gcc4.h
80970 @@ -39,9 +39,34 @@
80971 # define __compiletime_warning(message) __attribute__((warning(message)))
80972 # define __compiletime_error(message) __attribute__((error(message)))
80973 #endif /* __CHECKER__ */
80974 +
80975 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80976 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80977 +#define __bos0(ptr) __bos((ptr), 0)
80978 +#define __bos1(ptr) __bos((ptr), 1)
80979 #endif /* GCC_VERSION >= 40300 */
80980
80981 #if GCC_VERSION >= 40500
80982 +
80983 +#ifdef RANDSTRUCT_PLUGIN
80984 +#define __randomize_layout __attribute__((randomize_layout))
80985 +#define __no_randomize_layout __attribute__((no_randomize_layout))
80986 +#endif
80987 +
80988 +#ifdef CONSTIFY_PLUGIN
80989 +#define __no_const __attribute__((no_const))
80990 +#define __do_const __attribute__((do_const))
80991 +#endif
80992 +
80993 +#ifdef SIZE_OVERFLOW_PLUGIN
80994 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80995 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80996 +#endif
80997 +
80998 +#ifdef LATENT_ENTROPY_PLUGIN
80999 +#define __latent_entropy __attribute__((latent_entropy))
81000 +#endif
81001 +
81002 /*
81003 * Mark a position in code as unreachable. This can be used to
81004 * suppress control flow warnings after asm blocks that transfer
81005 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
81006 index d5ad7b1..3b74638 100644
81007 --- a/include/linux/compiler.h
81008 +++ b/include/linux/compiler.h
81009 @@ -5,11 +5,14 @@
81010
81011 #ifdef __CHECKER__
81012 # define __user __attribute__((noderef, address_space(1)))
81013 +# define __force_user __force __user
81014 # define __kernel __attribute__((address_space(0)))
81015 +# define __force_kernel __force __kernel
81016 # define __safe __attribute__((safe))
81017 # define __force __attribute__((force))
81018 # define __nocast __attribute__((nocast))
81019 # define __iomem __attribute__((noderef, address_space(2)))
81020 +# define __force_iomem __force __iomem
81021 # define __must_hold(x) __attribute__((context(x,1,1)))
81022 # define __acquires(x) __attribute__((context(x,0,1)))
81023 # define __releases(x) __attribute__((context(x,1,0)))
81024 @@ -17,20 +20,37 @@
81025 # define __release(x) __context__(x,-1)
81026 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
81027 # define __percpu __attribute__((noderef, address_space(3)))
81028 +# define __force_percpu __force __percpu
81029 #ifdef CONFIG_SPARSE_RCU_POINTER
81030 # define __rcu __attribute__((noderef, address_space(4)))
81031 +# define __force_rcu __force __rcu
81032 #else
81033 # define __rcu
81034 +# define __force_rcu
81035 #endif
81036 extern void __chk_user_ptr(const volatile void __user *);
81037 extern void __chk_io_ptr(const volatile void __iomem *);
81038 #else
81039 -# define __user
81040 -# define __kernel
81041 +# ifdef CHECKER_PLUGIN
81042 +//# define __user
81043 +//# define __force_user
81044 +//# define __kernel
81045 +//# define __force_kernel
81046 +# else
81047 +# ifdef STRUCTLEAK_PLUGIN
81048 +# define __user __attribute__((user))
81049 +# else
81050 +# define __user
81051 +# endif
81052 +# define __force_user
81053 +# define __kernel
81054 +# define __force_kernel
81055 +# endif
81056 # define __safe
81057 # define __force
81058 # define __nocast
81059 # define __iomem
81060 +# define __force_iomem
81061 # define __chk_user_ptr(x) (void)0
81062 # define __chk_io_ptr(x) (void)0
81063 # define __builtin_warning(x, y...) (1)
81064 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
81065 # define __release(x) (void)0
81066 # define __cond_lock(x,c) (c)
81067 # define __percpu
81068 +# define __force_percpu
81069 # define __rcu
81070 +# define __force_rcu
81071 #endif
81072
81073 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
81074 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
81075 # define __attribute_const__ /* unimplemented */
81076 #endif
81077
81078 +#ifndef __randomize_layout
81079 +# define __randomize_layout
81080 +#endif
81081 +
81082 +#ifndef __no_randomize_layout
81083 +# define __no_randomize_layout
81084 +#endif
81085 +
81086 +#ifndef __no_const
81087 +# define __no_const
81088 +#endif
81089 +
81090 +#ifndef __do_const
81091 +# define __do_const
81092 +#endif
81093 +
81094 +#ifndef __size_overflow
81095 +# define __size_overflow(...)
81096 +#endif
81097 +
81098 +#ifndef __intentional_overflow
81099 +# define __intentional_overflow(...)
81100 +#endif
81101 +
81102 +#ifndef __latent_entropy
81103 +# define __latent_entropy
81104 +#endif
81105 +
81106 /*
81107 * Tell gcc if a function is cold. The compiler will assume any path
81108 * directly leading to the call is unlikely.
81109 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
81110 #define __cold
81111 #endif
81112
81113 +#ifndef __alloc_size
81114 +#define __alloc_size(...)
81115 +#endif
81116 +
81117 +#ifndef __bos
81118 +#define __bos(ptr, arg)
81119 +#endif
81120 +
81121 +#ifndef __bos0
81122 +#define __bos0(ptr)
81123 +#endif
81124 +
81125 +#ifndef __bos1
81126 +#define __bos1(ptr)
81127 +#endif
81128 +
81129 /* Simple shorthand for a section definition */
81130 #ifndef __section
81131 # define __section(S) __attribute__ ((__section__(#S)))
81132 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
81133 * use is to mediate communication between process-level code and irq/NMI
81134 * handlers, all running on the same CPU.
81135 */
81136 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
81137 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
81138 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
81139
81140 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
81141 #ifdef CONFIG_KPROBES
81142 diff --git a/include/linux/completion.h b/include/linux/completion.h
81143 index 5d5aaae..0ea9b84 100644
81144 --- a/include/linux/completion.h
81145 +++ b/include/linux/completion.h
81146 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
81147
81148 extern void wait_for_completion(struct completion *);
81149 extern void wait_for_completion_io(struct completion *);
81150 -extern int wait_for_completion_interruptible(struct completion *x);
81151 -extern int wait_for_completion_killable(struct completion *x);
81152 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
81153 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
81154 extern unsigned long wait_for_completion_timeout(struct completion *x,
81155 - unsigned long timeout);
81156 + unsigned long timeout) __intentional_overflow(-1);
81157 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
81158 - unsigned long timeout);
81159 + unsigned long timeout) __intentional_overflow(-1);
81160 extern long wait_for_completion_interruptible_timeout(
81161 - struct completion *x, unsigned long timeout);
81162 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
81163 extern long wait_for_completion_killable_timeout(
81164 - struct completion *x, unsigned long timeout);
81165 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
81166 extern bool try_wait_for_completion(struct completion *x);
81167 extern bool completion_done(struct completion *x);
81168
81169 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
81170 index 34025df..d94bbbc 100644
81171 --- a/include/linux/configfs.h
81172 +++ b/include/linux/configfs.h
81173 @@ -125,7 +125,7 @@ struct configfs_attribute {
81174 const char *ca_name;
81175 struct module *ca_owner;
81176 umode_t ca_mode;
81177 -};
81178 +} __do_const;
81179
81180 /*
81181 * Users often need to create attribute structures for their configurable
81182 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
81183 index 8f8ae95..b9b0e6d 100644
81184 --- a/include/linux/cpufreq.h
81185 +++ b/include/linux/cpufreq.h
81186 @@ -202,6 +202,7 @@ struct global_attr {
81187 ssize_t (*store)(struct kobject *a, struct attribute *b,
81188 const char *c, size_t count);
81189 };
81190 +typedef struct global_attr __no_const global_attr_no_const;
81191
81192 #define define_one_global_ro(_name) \
81193 static struct global_attr _name = \
81194 @@ -268,7 +269,7 @@ struct cpufreq_driver {
81195 bool boost_supported;
81196 bool boost_enabled;
81197 int (*set_boost) (int state);
81198 -};
81199 +} __do_const;
81200
81201 /* flags */
81202 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
81203 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
81204 index 25e0df6..952dffd 100644
81205 --- a/include/linux/cpuidle.h
81206 +++ b/include/linux/cpuidle.h
81207 @@ -50,7 +50,8 @@ struct cpuidle_state {
81208 int index);
81209
81210 int (*enter_dead) (struct cpuidle_device *dev, int index);
81211 -};
81212 +} __do_const;
81213 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
81214
81215 /* Idle State Flags */
81216 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
81217 @@ -209,7 +210,7 @@ struct cpuidle_governor {
81218 void (*reflect) (struct cpuidle_device *dev, int index);
81219
81220 struct module *owner;
81221 -};
81222 +} __do_const;
81223
81224 #ifdef CONFIG_CPU_IDLE
81225 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
81226 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
81227 index 2997af6..424ddc1 100644
81228 --- a/include/linux/cpumask.h
81229 +++ b/include/linux/cpumask.h
81230 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
81231 }
81232
81233 /* Valid inputs for n are -1 and 0. */
81234 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81235 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
81236 {
81237 return n+1;
81238 }
81239
81240 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81241 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
81242 {
81243 return n+1;
81244 }
81245
81246 -static inline unsigned int cpumask_next_and(int n,
81247 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
81248 const struct cpumask *srcp,
81249 const struct cpumask *andp)
81250 {
81251 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
81252 *
81253 * Returns >= nr_cpu_ids if no further cpus set.
81254 */
81255 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81256 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
81257 {
81258 /* -1 is a legal arg here. */
81259 if (n != -1)
81260 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81261 *
81262 * Returns >= nr_cpu_ids if no further cpus unset.
81263 */
81264 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81265 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
81266 {
81267 /* -1 is a legal arg here. */
81268 if (n != -1)
81269 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81270 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
81271 }
81272
81273 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
81274 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
81275 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
81276 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
81277
81278 diff --git a/include/linux/cred.h b/include/linux/cred.h
81279 index f61d6c8..d372d95 100644
81280 --- a/include/linux/cred.h
81281 +++ b/include/linux/cred.h
81282 @@ -35,7 +35,7 @@ struct group_info {
81283 int nblocks;
81284 kgid_t small_block[NGROUPS_SMALL];
81285 kgid_t *blocks[0];
81286 -};
81287 +} __randomize_layout;
81288
81289 /**
81290 * get_group_info - Get a reference to a group info structure
81291 @@ -136,7 +136,7 @@ struct cred {
81292 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
81293 struct group_info *group_info; /* supplementary groups for euid/fsgid */
81294 struct rcu_head rcu; /* RCU deletion hook */
81295 -};
81296 +} __randomize_layout;
81297
81298 extern void __put_cred(struct cred *);
81299 extern void exit_creds(struct task_struct *);
81300 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
81301 static inline void validate_process_creds(void)
81302 {
81303 }
81304 +static inline void validate_task_creds(struct task_struct *task)
81305 +{
81306 +}
81307 #endif
81308
81309 /**
81310 @@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
81311
81312 #define task_uid(task) (task_cred_xxx((task), uid))
81313 #define task_euid(task) (task_cred_xxx((task), euid))
81314 +#define task_securebits(task) (task_cred_xxx((task), securebits))
81315
81316 #define current_cred_xxx(xxx) \
81317 ({ \
81318 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
81319 index b92eadf..b4ecdc1 100644
81320 --- a/include/linux/crypto.h
81321 +++ b/include/linux/crypto.h
81322 @@ -373,7 +373,7 @@ struct cipher_tfm {
81323 const u8 *key, unsigned int keylen);
81324 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81325 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81326 -};
81327 +} __no_const;
81328
81329 struct hash_tfm {
81330 int (*init)(struct hash_desc *desc);
81331 @@ -394,13 +394,13 @@ struct compress_tfm {
81332 int (*cot_decompress)(struct crypto_tfm *tfm,
81333 const u8 *src, unsigned int slen,
81334 u8 *dst, unsigned int *dlen);
81335 -};
81336 +} __no_const;
81337
81338 struct rng_tfm {
81339 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
81340 unsigned int dlen);
81341 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
81342 -};
81343 +} __no_const;
81344
81345 #define crt_ablkcipher crt_u.ablkcipher
81346 #define crt_aead crt_u.aead
81347 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
81348 index 653589e..4ef254a 100644
81349 --- a/include/linux/ctype.h
81350 +++ b/include/linux/ctype.h
81351 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
81352 * Fast implementation of tolower() for internal usage. Do not use in your
81353 * code.
81354 */
81355 -static inline char _tolower(const char c)
81356 +static inline unsigned char _tolower(const unsigned char c)
81357 {
81358 return c | 0x20;
81359 }
81360 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
81361 index 3c7ec32..4ca97cc 100644
81362 --- a/include/linux/dcache.h
81363 +++ b/include/linux/dcache.h
81364 @@ -133,7 +133,7 @@ struct dentry {
81365 } d_u;
81366 struct list_head d_subdirs; /* our children */
81367 struct hlist_node d_alias; /* inode alias list */
81368 -};
81369 +} __randomize_layout;
81370
81371 /*
81372 * dentry->d_lock spinlock nesting subclasses:
81373 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
81374 index 7925bf0..d5143d2 100644
81375 --- a/include/linux/decompress/mm.h
81376 +++ b/include/linux/decompress/mm.h
81377 @@ -77,7 +77,7 @@ static void free(void *where)
81378 * warnings when not needed (indeed large_malloc / large_free are not
81379 * needed by inflate */
81380
81381 -#define malloc(a) kmalloc(a, GFP_KERNEL)
81382 +#define malloc(a) kmalloc((a), GFP_KERNEL)
81383 #define free(a) kfree(a)
81384
81385 #define large_malloc(a) vmalloc(a)
81386 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
81387 index f1863dc..5c26074 100644
81388 --- a/include/linux/devfreq.h
81389 +++ b/include/linux/devfreq.h
81390 @@ -114,7 +114,7 @@ struct devfreq_governor {
81391 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
81392 int (*event_handler)(struct devfreq *devfreq,
81393 unsigned int event, void *data);
81394 -};
81395 +} __do_const;
81396
81397 /**
81398 * struct devfreq - Device devfreq structure
81399 diff --git a/include/linux/device.h b/include/linux/device.h
81400 index af424ac..fd46ddf 100644
81401 --- a/include/linux/device.h
81402 +++ b/include/linux/device.h
81403 @@ -310,7 +310,7 @@ struct subsys_interface {
81404 struct list_head node;
81405 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
81406 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
81407 -};
81408 +} __do_const;
81409
81410 int subsys_interface_register(struct subsys_interface *sif);
81411 void subsys_interface_unregister(struct subsys_interface *sif);
81412 @@ -506,7 +506,7 @@ struct device_type {
81413 void (*release)(struct device *dev);
81414
81415 const struct dev_pm_ops *pm;
81416 -};
81417 +} __do_const;
81418
81419 /* interface for exporting device attributes */
81420 struct device_attribute {
81421 @@ -516,11 +516,12 @@ struct device_attribute {
81422 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
81423 const char *buf, size_t count);
81424 };
81425 +typedef struct device_attribute __no_const device_attribute_no_const;
81426
81427 struct dev_ext_attribute {
81428 struct device_attribute attr;
81429 void *var;
81430 -};
81431 +} __do_const;
81432
81433 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
81434 char *buf);
81435 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
81436 index 931b709..89b2d89 100644
81437 --- a/include/linux/dma-mapping.h
81438 +++ b/include/linux/dma-mapping.h
81439 @@ -60,7 +60,7 @@ struct dma_map_ops {
81440 u64 (*get_required_mask)(struct device *dev);
81441 #endif
81442 int is_phys;
81443 -};
81444 +} __do_const;
81445
81446 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
81447
81448 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
81449 index d2c5cc7..d193394 100644
81450 --- a/include/linux/dmaengine.h
81451 +++ b/include/linux/dmaengine.h
81452 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
81453 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
81454 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
81455
81456 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81457 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81458 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
81459 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81460 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81461 struct dma_pinned_list *pinned_list, struct page *page,
81462 unsigned int offset, size_t len);
81463
81464 diff --git a/include/linux/efi.h b/include/linux/efi.h
81465 index 41bbf8b..bd3a718 100644
81466 --- a/include/linux/efi.h
81467 +++ b/include/linux/efi.h
81468 @@ -1027,6 +1027,7 @@ struct efivar_operations {
81469 efi_set_variable_t *set_variable;
81470 efi_query_variable_store_t *query_variable_store;
81471 };
81472 +typedef struct efivar_operations __no_const efivar_operations_no_const;
81473
81474 struct efivars {
81475 /*
81476 diff --git a/include/linux/elf.h b/include/linux/elf.h
81477 index 67a5fa7..b817372 100644
81478 --- a/include/linux/elf.h
81479 +++ b/include/linux/elf.h
81480 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
81481 #define elf_note elf32_note
81482 #define elf_addr_t Elf32_Off
81483 #define Elf_Half Elf32_Half
81484 +#define elf_dyn Elf32_Dyn
81485
81486 #else
81487
81488 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
81489 #define elf_note elf64_note
81490 #define elf_addr_t Elf64_Off
81491 #define Elf_Half Elf64_Half
81492 +#define elf_dyn Elf64_Dyn
81493
81494 #endif
81495
81496 diff --git a/include/linux/err.h b/include/linux/err.h
81497 index a729120..6ede2c9 100644
81498 --- a/include/linux/err.h
81499 +++ b/include/linux/err.h
81500 @@ -20,12 +20,12 @@
81501
81502 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
81503
81504 -static inline void * __must_check ERR_PTR(long error)
81505 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
81506 {
81507 return (void *) error;
81508 }
81509
81510 -static inline long __must_check PTR_ERR(__force const void *ptr)
81511 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
81512 {
81513 return (long) ptr;
81514 }
81515 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
81516 index 36f49c4..a2a1f4c 100644
81517 --- a/include/linux/extcon.h
81518 +++ b/include/linux/extcon.h
81519 @@ -135,7 +135,7 @@ struct extcon_dev {
81520 /* /sys/class/extcon/.../mutually_exclusive/... */
81521 struct attribute_group attr_g_muex;
81522 struct attribute **attrs_muex;
81523 - struct device_attribute *d_attrs_muex;
81524 + device_attribute_no_const *d_attrs_muex;
81525 };
81526
81527 /**
81528 diff --git a/include/linux/fb.h b/include/linux/fb.h
81529 index b6bfda9..1f13487 100644
81530 --- a/include/linux/fb.h
81531 +++ b/include/linux/fb.h
81532 @@ -305,7 +305,7 @@ struct fb_ops {
81533 /* called at KDB enter and leave time to prepare the console */
81534 int (*fb_debug_enter)(struct fb_info *info);
81535 int (*fb_debug_leave)(struct fb_info *info);
81536 -};
81537 +} __do_const;
81538
81539 #ifdef CONFIG_FB_TILEBLITTING
81540 #define FB_TILE_CURSOR_NONE 0
81541 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81542 index 230f87b..1fd0485 100644
81543 --- a/include/linux/fdtable.h
81544 +++ b/include/linux/fdtable.h
81545 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81546 void put_files_struct(struct files_struct *fs);
81547 void reset_files_struct(struct files_struct *);
81548 int unshare_files(struct files_struct **);
81549 -struct files_struct *dup_fd(struct files_struct *, int *);
81550 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81551 void do_close_on_exec(struct files_struct *);
81552 int iterate_fd(struct files_struct *, unsigned,
81553 int (*)(const void *, struct file *, unsigned),
81554 diff --git a/include/linux/filter.h b/include/linux/filter.h
81555 index a7e3c48..e568c8e 100644
81556 --- a/include/linux/filter.h
81557 +++ b/include/linux/filter.h
81558 @@ -9,330 +9,28 @@
81559 #include <linux/workqueue.h>
81560 #include <uapi/linux/filter.h>
81561
81562 -/* Internally used and optimized filter representation with extended
81563 - * instruction set based on top of classic BPF.
81564 - */
81565 -
81566 -/* instruction classes */
81567 -#define BPF_ALU64 0x07 /* alu mode in double word width */
81568 -
81569 -/* ld/ldx fields */
81570 -#define BPF_DW 0x18 /* double word */
81571 -#define BPF_XADD 0xc0 /* exclusive add */
81572 -
81573 -/* alu/jmp fields */
81574 -#define BPF_MOV 0xb0 /* mov reg to reg */
81575 -#define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */
81576 -
81577 -/* change endianness of a register */
81578 -#define BPF_END 0xd0 /* flags for endianness conversion: */
81579 -#define BPF_TO_LE 0x00 /* convert to little-endian */
81580 -#define BPF_TO_BE 0x08 /* convert to big-endian */
81581 -#define BPF_FROM_LE BPF_TO_LE
81582 -#define BPF_FROM_BE BPF_TO_BE
81583 -
81584 -#define BPF_JNE 0x50 /* jump != */
81585 -#define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */
81586 -#define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */
81587 -#define BPF_CALL 0x80 /* function call */
81588 -#define BPF_EXIT 0x90 /* function return */
81589 -
81590 -/* Register numbers */
81591 -enum {
81592 - BPF_REG_0 = 0,
81593 - BPF_REG_1,
81594 - BPF_REG_2,
81595 - BPF_REG_3,
81596 - BPF_REG_4,
81597 - BPF_REG_5,
81598 - BPF_REG_6,
81599 - BPF_REG_7,
81600 - BPF_REG_8,
81601 - BPF_REG_9,
81602 - BPF_REG_10,
81603 - __MAX_BPF_REG,
81604 -};
81605 -
81606 -/* BPF has 10 general purpose 64-bit registers and stack frame. */
81607 -#define MAX_BPF_REG __MAX_BPF_REG
81608 -
81609 -/* ArgX, context and stack frame pointer register positions. Note,
81610 - * Arg1, Arg2, Arg3, etc are used as argument mappings of function
81611 - * calls in BPF_CALL instruction.
81612 - */
81613 -#define BPF_REG_ARG1 BPF_REG_1
81614 -#define BPF_REG_ARG2 BPF_REG_2
81615 -#define BPF_REG_ARG3 BPF_REG_3
81616 -#define BPF_REG_ARG4 BPF_REG_4
81617 -#define BPF_REG_ARG5 BPF_REG_5
81618 -#define BPF_REG_CTX BPF_REG_6
81619 -#define BPF_REG_FP BPF_REG_10
81620 -
81621 -/* Additional register mappings for converted user programs. */
81622 -#define BPF_REG_A BPF_REG_0
81623 -#define BPF_REG_X BPF_REG_7
81624 -#define BPF_REG_TMP BPF_REG_8
81625 -
81626 -/* BPF program can access up to 512 bytes of stack space. */
81627 -#define MAX_BPF_STACK 512
81628 -
81629 -/* Helper macros for filter block array initializers. */
81630 -
81631 -/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
81632 -
81633 -#define BPF_ALU64_REG(OP, DST, SRC) \
81634 - ((struct sock_filter_int) { \
81635 - .code = BPF_ALU64 | BPF_OP(OP) | BPF_X, \
81636 - .dst_reg = DST, \
81637 - .src_reg = SRC, \
81638 - .off = 0, \
81639 - .imm = 0 })
81640 -
81641 -#define BPF_ALU32_REG(OP, DST, SRC) \
81642 - ((struct sock_filter_int) { \
81643 - .code = BPF_ALU | BPF_OP(OP) | BPF_X, \
81644 - .dst_reg = DST, \
81645 - .src_reg = SRC, \
81646 - .off = 0, \
81647 - .imm = 0 })
81648 -
81649 -/* ALU ops on immediates, bpf_add|sub|...: dst_reg += imm32 */
81650 -
81651 -#define BPF_ALU64_IMM(OP, DST, IMM) \
81652 - ((struct sock_filter_int) { \
81653 - .code = BPF_ALU64 | BPF_OP(OP) | BPF_K, \
81654 - .dst_reg = DST, \
81655 - .src_reg = 0, \
81656 - .off = 0, \
81657 - .imm = IMM })
81658 -
81659 -#define BPF_ALU32_IMM(OP, DST, IMM) \
81660 - ((struct sock_filter_int) { \
81661 - .code = BPF_ALU | BPF_OP(OP) | BPF_K, \
81662 - .dst_reg = DST, \
81663 - .src_reg = 0, \
81664 - .off = 0, \
81665 - .imm = IMM })
81666 -
81667 -/* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */
81668 -
81669 -#define BPF_ENDIAN(TYPE, DST, LEN) \
81670 - ((struct sock_filter_int) { \
81671 - .code = BPF_ALU | BPF_END | BPF_SRC(TYPE), \
81672 - .dst_reg = DST, \
81673 - .src_reg = 0, \
81674 - .off = 0, \
81675 - .imm = LEN })
81676 -
81677 -/* Short form of mov, dst_reg = src_reg */
81678 -
81679 -#define BPF_MOV64_REG(DST, SRC) \
81680 - ((struct sock_filter_int) { \
81681 - .code = BPF_ALU64 | BPF_MOV | BPF_X, \
81682 - .dst_reg = DST, \
81683 - .src_reg = SRC, \
81684 - .off = 0, \
81685 - .imm = 0 })
81686 -
81687 -#define BPF_MOV32_REG(DST, SRC) \
81688 - ((struct sock_filter_int) { \
81689 - .code = BPF_ALU | BPF_MOV | BPF_X, \
81690 - .dst_reg = DST, \
81691 - .src_reg = SRC, \
81692 - .off = 0, \
81693 - .imm = 0 })
81694 -
81695 -/* Short form of mov, dst_reg = imm32 */
81696 -
81697 -#define BPF_MOV64_IMM(DST, IMM) \
81698 - ((struct sock_filter_int) { \
81699 - .code = BPF_ALU64 | BPF_MOV | BPF_K, \
81700 - .dst_reg = DST, \
81701 - .src_reg = 0, \
81702 - .off = 0, \
81703 - .imm = IMM })
81704 -
81705 -#define BPF_MOV32_IMM(DST, IMM) \
81706 - ((struct sock_filter_int) { \
81707 - .code = BPF_ALU | BPF_MOV | BPF_K, \
81708 - .dst_reg = DST, \
81709 - .src_reg = 0, \
81710 - .off = 0, \
81711 - .imm = IMM })
81712 -
81713 -/* Short form of mov based on type, BPF_X: dst_reg = src_reg, BPF_K: dst_reg = imm32 */
81714 -
81715 -#define BPF_MOV64_RAW(TYPE, DST, SRC, IMM) \
81716 - ((struct sock_filter_int) { \
81717 - .code = BPF_ALU64 | BPF_MOV | BPF_SRC(TYPE), \
81718 - .dst_reg = DST, \
81719 - .src_reg = SRC, \
81720 - .off = 0, \
81721 - .imm = IMM })
81722 -
81723 -#define BPF_MOV32_RAW(TYPE, DST, SRC, IMM) \
81724 - ((struct sock_filter_int) { \
81725 - .code = BPF_ALU | BPF_MOV | BPF_SRC(TYPE), \
81726 - .dst_reg = DST, \
81727 - .src_reg = SRC, \
81728 - .off = 0, \
81729 - .imm = IMM })
81730 -
81731 -/* Direct packet access, R0 = *(uint *) (skb->data + imm32) */
81732 -
81733 -#define BPF_LD_ABS(SIZE, IMM) \
81734 - ((struct sock_filter_int) { \
81735 - .code = BPF_LD | BPF_SIZE(SIZE) | BPF_ABS, \
81736 - .dst_reg = 0, \
81737 - .src_reg = 0, \
81738 - .off = 0, \
81739 - .imm = IMM })
81740 -
81741 -/* Indirect packet access, R0 = *(uint *) (skb->data + src_reg + imm32) */
81742 -
81743 -#define BPF_LD_IND(SIZE, SRC, IMM) \
81744 - ((struct sock_filter_int) { \
81745 - .code = BPF_LD | BPF_SIZE(SIZE) | BPF_IND, \
81746 - .dst_reg = 0, \
81747 - .src_reg = SRC, \
81748 - .off = 0, \
81749 - .imm = IMM })
81750 -
81751 -/* Memory load, dst_reg = *(uint *) (src_reg + off16) */
81752 -
81753 -#define BPF_LDX_MEM(SIZE, DST, SRC, OFF) \
81754 - ((struct sock_filter_int) { \
81755 - .code = BPF_LDX | BPF_SIZE(SIZE) | BPF_MEM, \
81756 - .dst_reg = DST, \
81757 - .src_reg = SRC, \
81758 - .off = OFF, \
81759 - .imm = 0 })
81760 -
81761 -/* Memory store, *(uint *) (dst_reg + off16) = src_reg */
81762 -
81763 -#define BPF_STX_MEM(SIZE, DST, SRC, OFF) \
81764 - ((struct sock_filter_int) { \
81765 - .code = BPF_STX | BPF_SIZE(SIZE) | BPF_MEM, \
81766 - .dst_reg = DST, \
81767 - .src_reg = SRC, \
81768 - .off = OFF, \
81769 - .imm = 0 })
81770 -
81771 -/* Memory store, *(uint *) (dst_reg + off16) = imm32 */
81772 -
81773 -#define BPF_ST_MEM(SIZE, DST, OFF, IMM) \
81774 - ((struct sock_filter_int) { \
81775 - .code = BPF_ST | BPF_SIZE(SIZE) | BPF_MEM, \
81776 - .dst_reg = DST, \
81777 - .src_reg = 0, \
81778 - .off = OFF, \
81779 - .imm = IMM })
81780 -
81781 -/* Conditional jumps against registers, if (dst_reg 'op' src_reg) goto pc + off16 */
81782 -
81783 -#define BPF_JMP_REG(OP, DST, SRC, OFF) \
81784 - ((struct sock_filter_int) { \
81785 - .code = BPF_JMP | BPF_OP(OP) | BPF_X, \
81786 - .dst_reg = DST, \
81787 - .src_reg = SRC, \
81788 - .off = OFF, \
81789 - .imm = 0 })
81790 -
81791 -/* Conditional jumps against immediates, if (dst_reg 'op' imm32) goto pc + off16 */
81792 -
81793 -#define BPF_JMP_IMM(OP, DST, IMM, OFF) \
81794 - ((struct sock_filter_int) { \
81795 - .code = BPF_JMP | BPF_OP(OP) | BPF_K, \
81796 - .dst_reg = DST, \
81797 - .src_reg = 0, \
81798 - .off = OFF, \
81799 - .imm = IMM })
81800 -
81801 -/* Function call */
81802 -
81803 -#define BPF_EMIT_CALL(FUNC) \
81804 - ((struct sock_filter_int) { \
81805 - .code = BPF_JMP | BPF_CALL, \
81806 - .dst_reg = 0, \
81807 - .src_reg = 0, \
81808 - .off = 0, \
81809 - .imm = ((FUNC) - __bpf_call_base) })
81810 -
81811 -/* Raw code statement block */
81812 -
81813 -#define BPF_RAW_INSN(CODE, DST, SRC, OFF, IMM) \
81814 - ((struct sock_filter_int) { \
81815 - .code = CODE, \
81816 - .dst_reg = DST, \
81817 - .src_reg = SRC, \
81818 - .off = OFF, \
81819 - .imm = IMM })
81820 -
81821 -/* Program exit */
81822 -
81823 -#define BPF_EXIT_INSN() \
81824 - ((struct sock_filter_int) { \
81825 - .code = BPF_JMP | BPF_EXIT, \
81826 - .dst_reg = 0, \
81827 - .src_reg = 0, \
81828 - .off = 0, \
81829 - .imm = 0 })
81830 -
81831 -#define bytes_to_bpf_size(bytes) \
81832 -({ \
81833 - int bpf_size = -EINVAL; \
81834 - \
81835 - if (bytes == sizeof(u8)) \
81836 - bpf_size = BPF_B; \
81837 - else if (bytes == sizeof(u16)) \
81838 - bpf_size = BPF_H; \
81839 - else if (bytes == sizeof(u32)) \
81840 - bpf_size = BPF_W; \
81841 - else if (bytes == sizeof(u64)) \
81842 - bpf_size = BPF_DW; \
81843 - \
81844 - bpf_size; \
81845 -})
81846 -
81847 -/* Macro to invoke filter function. */
81848 -#define SK_RUN_FILTER(filter, ctx) (*filter->bpf_func)(ctx, filter->insnsi)
81849 -
81850 -struct sock_filter_int {
81851 - __u8 code; /* opcode */
81852 - __u8 dst_reg:4; /* dest register */
81853 - __u8 src_reg:4; /* source register */
81854 - __s16 off; /* signed offset */
81855 - __s32 imm; /* signed immediate constant */
81856 -};
81857 -
81858 #ifdef CONFIG_COMPAT
81859 -/* A struct sock_filter is architecture independent. */
81860 +/*
81861 + * A struct sock_filter is architecture independent.
81862 + */
81863 struct compat_sock_fprog {
81864 u16 len;
81865 - compat_uptr_t filter; /* struct sock_filter * */
81866 + compat_uptr_t filter; /* struct sock_filter * */
81867 };
81868 #endif
81869
81870 -struct sock_fprog_kern {
81871 - u16 len;
81872 - struct sock_filter *filter;
81873 -};
81874 -
81875 struct sk_buff;
81876 struct sock;
81877 -struct seccomp_data;
81878
81879 -struct sk_filter {
81880 +struct sk_filter
81881 +{
81882 atomic_t refcnt;
81883 - u32 jited:1, /* Is our filter JIT'ed? */
81884 - len:31; /* Number of filter blocks */
81885 - struct sock_fprog_kern *orig_prog; /* Original BPF program */
81886 + unsigned int len; /* Number of filter blocks */
81887 struct rcu_head rcu;
81888 unsigned int (*bpf_func)(const struct sk_buff *skb,
81889 - const struct sock_filter_int *filter);
81890 + const struct sock_filter *filter);
81891 union {
81892 - struct sock_filter insns[0];
81893 - struct sock_filter_int insnsi[0];
81894 + struct sock_filter insns[0];
81895 struct work_struct work;
81896 };
81897 };
81898 @@ -343,76 +41,25 @@ static inline unsigned int sk_filter_size(unsigned int proglen)
81899 offsetof(struct sk_filter, insns[proglen]));
81900 }
81901
81902 -#define sk_filter_proglen(fprog) \
81903 - (fprog->len * sizeof(fprog->filter[0]))
81904 -
81905 -int sk_filter(struct sock *sk, struct sk_buff *skb);
81906 -
81907 -void sk_filter_select_runtime(struct sk_filter *fp);
81908 -void sk_filter_free(struct sk_filter *fp);
81909 -
81910 -int sk_convert_filter(struct sock_filter *prog, int len,
81911 - struct sock_filter_int *new_prog, int *new_len);
81912 -
81913 -int sk_unattached_filter_create(struct sk_filter **pfp,
81914 - struct sock_fprog_kern *fprog);
81915 -void sk_unattached_filter_destroy(struct sk_filter *fp);
81916 -
81917 -int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
81918 -int sk_detach_filter(struct sock *sk);
81919 -
81920 -int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
81921 -int sk_get_filter(struct sock *sk, struct sock_filter __user *filter,
81922 - unsigned int len);
81923 -
81924 -void sk_filter_charge(struct sock *sk, struct sk_filter *fp);
81925 -void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp);
81926 -
81927 -u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
81928 -void bpf_int_jit_compile(struct sk_filter *fp);
81929 -
81930 -#define BPF_ANC BIT(15)
81931 -
81932 -static inline u16 bpf_anc_helper(const struct sock_filter *ftest)
81933 -{
81934 - BUG_ON(ftest->code & BPF_ANC);
81935 -
81936 - switch (ftest->code) {
81937 - case BPF_LD | BPF_W | BPF_ABS:
81938 - case BPF_LD | BPF_H | BPF_ABS:
81939 - case BPF_LD | BPF_B | BPF_ABS:
81940 -#define BPF_ANCILLARY(CODE) case SKF_AD_OFF + SKF_AD_##CODE: \
81941 - return BPF_ANC | SKF_AD_##CODE
81942 - switch (ftest->k) {
81943 - BPF_ANCILLARY(PROTOCOL);
81944 - BPF_ANCILLARY(PKTTYPE);
81945 - BPF_ANCILLARY(IFINDEX);
81946 - BPF_ANCILLARY(NLATTR);
81947 - BPF_ANCILLARY(NLATTR_NEST);
81948 - BPF_ANCILLARY(MARK);
81949 - BPF_ANCILLARY(QUEUE);
81950 - BPF_ANCILLARY(HATYPE);
81951 - BPF_ANCILLARY(RXHASH);
81952 - BPF_ANCILLARY(CPU);
81953 - BPF_ANCILLARY(ALU_XOR_X);
81954 - BPF_ANCILLARY(VLAN_TAG);
81955 - BPF_ANCILLARY(VLAN_TAG_PRESENT);
81956 - BPF_ANCILLARY(PAY_OFFSET);
81957 - BPF_ANCILLARY(RANDOM);
81958 - }
81959 - /* Fallthrough. */
81960 - default:
81961 - return ftest->code;
81962 - }
81963 -}
81964 +extern int sk_filter(struct sock *sk, struct sk_buff *skb);
81965 +extern unsigned int sk_run_filter(const struct sk_buff *skb,
81966 + const struct sock_filter *filter);
81967 +extern int sk_unattached_filter_create(struct sk_filter **pfp,
81968 + struct sock_fprog *fprog);
81969 +extern void sk_unattached_filter_destroy(struct sk_filter *fp);
81970 +extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
81971 +extern int sk_detach_filter(struct sock *sk);
81972 +extern int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
81973 +extern int sk_get_filter(struct sock *sk, struct sock_filter __user *filter, unsigned len);
81974 +extern void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to);
81975
81976 #ifdef CONFIG_BPF_JIT
81977 #include <stdarg.h>
81978 #include <linux/linkage.h>
81979 #include <linux/printk.h>
81980
81981 -void bpf_jit_compile(struct sk_filter *fp);
81982 -void bpf_jit_free(struct sk_filter *fp);
81983 +extern void bpf_jit_compile(struct sk_filter *fp);
81984 +extern void bpf_jit_free(struct sk_filter *fp);
81985
81986 static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
81987 u32 pass, void *image)
81988 @@ -423,22 +70,90 @@ static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
81989 print_hex_dump(KERN_ERR, "JIT code: ", DUMP_PREFIX_OFFSET,
81990 16, 1, image, proglen, false);
81991 }
81992 +#define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns)
81993 #else
81994 #include <linux/slab.h>
81995 -
81996 static inline void bpf_jit_compile(struct sk_filter *fp)
81997 {
81998 }
81999 -
82000 static inline void bpf_jit_free(struct sk_filter *fp)
82001 {
82002 kfree(fp);
82003 }
82004 -#endif /* CONFIG_BPF_JIT */
82005 +#define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns)
82006 +#endif
82007
82008 static inline int bpf_tell_extensions(void)
82009 {
82010 return SKF_AD_MAX;
82011 }
82012
82013 +enum {
82014 + BPF_S_RET_K = 1,
82015 + BPF_S_RET_A,
82016 + BPF_S_ALU_ADD_K,
82017 + BPF_S_ALU_ADD_X,
82018 + BPF_S_ALU_SUB_K,
82019 + BPF_S_ALU_SUB_X,
82020 + BPF_S_ALU_MUL_K,
82021 + BPF_S_ALU_MUL_X,
82022 + BPF_S_ALU_DIV_X,
82023 + BPF_S_ALU_MOD_K,
82024 + BPF_S_ALU_MOD_X,
82025 + BPF_S_ALU_AND_K,
82026 + BPF_S_ALU_AND_X,
82027 + BPF_S_ALU_OR_K,
82028 + BPF_S_ALU_OR_X,
82029 + BPF_S_ALU_XOR_K,
82030 + BPF_S_ALU_XOR_X,
82031 + BPF_S_ALU_LSH_K,
82032 + BPF_S_ALU_LSH_X,
82033 + BPF_S_ALU_RSH_K,
82034 + BPF_S_ALU_RSH_X,
82035 + BPF_S_ALU_NEG,
82036 + BPF_S_LD_W_ABS,
82037 + BPF_S_LD_H_ABS,
82038 + BPF_S_LD_B_ABS,
82039 + BPF_S_LD_W_LEN,
82040 + BPF_S_LD_W_IND,
82041 + BPF_S_LD_H_IND,
82042 + BPF_S_LD_B_IND,
82043 + BPF_S_LD_IMM,
82044 + BPF_S_LDX_W_LEN,
82045 + BPF_S_LDX_B_MSH,
82046 + BPF_S_LDX_IMM,
82047 + BPF_S_MISC_TAX,
82048 + BPF_S_MISC_TXA,
82049 + BPF_S_ALU_DIV_K,
82050 + BPF_S_LD_MEM,
82051 + BPF_S_LDX_MEM,
82052 + BPF_S_ST,
82053 + BPF_S_STX,
82054 + BPF_S_JMP_JA,
82055 + BPF_S_JMP_JEQ_K,
82056 + BPF_S_JMP_JEQ_X,
82057 + BPF_S_JMP_JGE_K,
82058 + BPF_S_JMP_JGE_X,
82059 + BPF_S_JMP_JGT_K,
82060 + BPF_S_JMP_JGT_X,
82061 + BPF_S_JMP_JSET_K,
82062 + BPF_S_JMP_JSET_X,
82063 + /* Ancillary data */
82064 + BPF_S_ANC_PROTOCOL,
82065 + BPF_S_ANC_PKTTYPE,
82066 + BPF_S_ANC_IFINDEX,
82067 + BPF_S_ANC_NLATTR,
82068 + BPF_S_ANC_NLATTR_NEST,
82069 + BPF_S_ANC_MARK,
82070 + BPF_S_ANC_QUEUE,
82071 + BPF_S_ANC_HATYPE,
82072 + BPF_S_ANC_RXHASH,
82073 + BPF_S_ANC_CPU,
82074 + BPF_S_ANC_ALU_XOR_X,
82075 + BPF_S_ANC_SECCOMP_LD_W,
82076 + BPF_S_ANC_VLAN_TAG,
82077 + BPF_S_ANC_VLAN_TAG_PRESENT,
82078 + BPF_S_ANC_PAY_OFFSET,
82079 +};
82080 +
82081 #endif /* __LINUX_FILTER_H__ */
82082 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
82083 index 8293262..2b3b8bd 100644
82084 --- a/include/linux/frontswap.h
82085 +++ b/include/linux/frontswap.h
82086 @@ -11,7 +11,7 @@ struct frontswap_ops {
82087 int (*load)(unsigned, pgoff_t, struct page *);
82088 void (*invalidate_page)(unsigned, pgoff_t);
82089 void (*invalidate_area)(unsigned);
82090 -};
82091 +} __no_const;
82092
82093 extern bool frontswap_enabled;
82094 extern struct frontswap_ops *
82095 diff --git a/include/linux/fs.h b/include/linux/fs.h
82096 index e11d60c..901317a 100644
82097 --- a/include/linux/fs.h
82098 +++ b/include/linux/fs.h
82099 @@ -401,7 +401,7 @@ struct address_space {
82100 spinlock_t private_lock; /* for use by the address_space */
82101 struct list_head private_list; /* ditto */
82102 void *private_data; /* ditto */
82103 -} __attribute__((aligned(sizeof(long))));
82104 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
82105 /*
82106 * On most architectures that alignment is already the case; but
82107 * must be enforced here for CRIS, to let the least significant bit
82108 @@ -444,7 +444,7 @@ struct block_device {
82109 int bd_fsfreeze_count;
82110 /* Mutex for freeze */
82111 struct mutex bd_fsfreeze_mutex;
82112 -};
82113 +} __randomize_layout;
82114
82115 /*
82116 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
82117 @@ -588,7 +588,7 @@ struct inode {
82118 #endif
82119
82120 void *i_private; /* fs or device private pointer */
82121 -};
82122 +} __randomize_layout;
82123
82124 static inline int inode_unhashed(struct inode *inode)
82125 {
82126 @@ -781,7 +781,7 @@ struct file {
82127 struct list_head f_tfile_llink;
82128 #endif /* #ifdef CONFIG_EPOLL */
82129 struct address_space *f_mapping;
82130 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
82131 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
82132
82133 struct file_handle {
82134 __u32 handle_bytes;
82135 @@ -909,7 +909,7 @@ struct file_lock {
82136 int state; /* state of grant or error if -ve */
82137 } afs;
82138 } fl_u;
82139 -};
82140 +} __randomize_layout;
82141
82142 /* The following constant reflects the upper bound of the file/locking space */
82143 #ifndef OFFSET_MAX
82144 @@ -1258,7 +1258,7 @@ struct super_block {
82145 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
82146 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
82147 struct rcu_head rcu;
82148 -};
82149 +} __randomize_layout;
82150
82151 extern struct timespec current_fs_time(struct super_block *sb);
82152
82153 @@ -1484,7 +1484,8 @@ struct file_operations {
82154 long (*fallocate)(struct file *file, int mode, loff_t offset,
82155 loff_t len);
82156 int (*show_fdinfo)(struct seq_file *m, struct file *f);
82157 -};
82158 +} __do_const __randomize_layout;
82159 +typedef struct file_operations __no_const file_operations_no_const;
82160
82161 struct inode_operations {
82162 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
82163 @@ -2769,4 +2770,14 @@ static inline bool dir_relax(struct inode *inode)
82164 return !IS_DEADDIR(inode);
82165 }
82166
82167 +static inline bool is_sidechannel_device(const struct inode *inode)
82168 +{
82169 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
82170 + umode_t mode = inode->i_mode;
82171 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
82172 +#else
82173 + return false;
82174 +#endif
82175 +}
82176 +
82177 #endif /* _LINUX_FS_H */
82178 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
82179 index 0efc3e6..fd23610 100644
82180 --- a/include/linux/fs_struct.h
82181 +++ b/include/linux/fs_struct.h
82182 @@ -6,13 +6,13 @@
82183 #include <linux/seqlock.h>
82184
82185 struct fs_struct {
82186 - int users;
82187 + atomic_t users;
82188 spinlock_t lock;
82189 seqcount_t seq;
82190 int umask;
82191 int in_exec;
82192 struct path root, pwd;
82193 -};
82194 +} __randomize_layout;
82195
82196 extern struct kmem_cache *fs_cachep;
82197
82198 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
82199 index 7714849..a4a5c7a 100644
82200 --- a/include/linux/fscache-cache.h
82201 +++ b/include/linux/fscache-cache.h
82202 @@ -113,7 +113,7 @@ struct fscache_operation {
82203 fscache_operation_release_t release;
82204 };
82205
82206 -extern atomic_t fscache_op_debug_id;
82207 +extern atomic_unchecked_t fscache_op_debug_id;
82208 extern void fscache_op_work_func(struct work_struct *work);
82209
82210 extern void fscache_enqueue_operation(struct fscache_operation *);
82211 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
82212 INIT_WORK(&op->work, fscache_op_work_func);
82213 atomic_set(&op->usage, 1);
82214 op->state = FSCACHE_OP_ST_INITIALISED;
82215 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
82216 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
82217 op->processor = processor;
82218 op->release = release;
82219 INIT_LIST_HEAD(&op->pend_link);
82220 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
82221 index 115bb81..e7b812b 100644
82222 --- a/include/linux/fscache.h
82223 +++ b/include/linux/fscache.h
82224 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
82225 * - this is mandatory for any object that may have data
82226 */
82227 void (*now_uncached)(void *cookie_netfs_data);
82228 -};
82229 +} __do_const;
82230
82231 /*
82232 * fscache cached network filesystem type
82233 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
82234 index 1c804b0..1432c2b 100644
82235 --- a/include/linux/fsnotify.h
82236 +++ b/include/linux/fsnotify.h
82237 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
82238 struct inode *inode = file_inode(file);
82239 __u32 mask = FS_ACCESS;
82240
82241 + if (is_sidechannel_device(inode))
82242 + return;
82243 +
82244 if (S_ISDIR(inode->i_mode))
82245 mask |= FS_ISDIR;
82246
82247 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
82248 struct inode *inode = file_inode(file);
82249 __u32 mask = FS_MODIFY;
82250
82251 + if (is_sidechannel_device(inode))
82252 + return;
82253 +
82254 if (S_ISDIR(inode->i_mode))
82255 mask |= FS_ISDIR;
82256
82257 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
82258 */
82259 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
82260 {
82261 - return kstrdup(name, GFP_KERNEL);
82262 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
82263 }
82264
82265 /*
82266 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
82267 index ec274e0..e678159 100644
82268 --- a/include/linux/genhd.h
82269 +++ b/include/linux/genhd.h
82270 @@ -194,7 +194,7 @@ struct gendisk {
82271 struct kobject *slave_dir;
82272
82273 struct timer_rand_state *random;
82274 - atomic_t sync_io; /* RAID */
82275 + atomic_unchecked_t sync_io; /* RAID */
82276 struct disk_events *ev;
82277 #ifdef CONFIG_BLK_DEV_INTEGRITY
82278 struct blk_integrity *integrity;
82279 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
82280 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
82281
82282 /* drivers/char/random.c */
82283 -extern void add_disk_randomness(struct gendisk *disk);
82284 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
82285 extern void rand_initialize_disk(struct gendisk *disk);
82286
82287 static inline sector_t get_start_sect(struct block_device *bdev)
82288 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
82289 index c0894dd..2fbf10c 100644
82290 --- a/include/linux/genl_magic_func.h
82291 +++ b/include/linux/genl_magic_func.h
82292 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
82293 },
82294
82295 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
82296 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
82297 +static struct genl_ops ZZZ_genl_ops[] = {
82298 #include GENL_MAGIC_INCLUDE_FILE
82299 };
82300
82301 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
82302 index 6eb1fb3..30fe7e4 100644
82303 --- a/include/linux/gfp.h
82304 +++ b/include/linux/gfp.h
82305 @@ -34,6 +34,13 @@ struct vm_area_struct;
82306 #define ___GFP_NO_KSWAPD 0x400000u
82307 #define ___GFP_OTHER_NODE 0x800000u
82308 #define ___GFP_WRITE 0x1000000u
82309 +
82310 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82311 +#define ___GFP_USERCOPY 0x2000000u
82312 +#else
82313 +#define ___GFP_USERCOPY 0
82314 +#endif
82315 +
82316 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
82317
82318 /*
82319 @@ -90,6 +97,7 @@ struct vm_area_struct;
82320 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
82321 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
82322 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
82323 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
82324
82325 /*
82326 * This may seem redundant, but it's a way of annotating false positives vs.
82327 @@ -97,7 +105,7 @@ struct vm_area_struct;
82328 */
82329 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
82330
82331 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
82332 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
82333 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
82334
82335 /* This equals 0, but use constants in case they ever change */
82336 @@ -155,6 +163,8 @@ struct vm_area_struct;
82337 /* 4GB DMA on some platforms */
82338 #define GFP_DMA32 __GFP_DMA32
82339
82340 +#define GFP_USERCOPY __GFP_USERCOPY
82341 +
82342 /* Convert GFP flags to their corresponding migrate type */
82343 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
82344 {
82345 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
82346 new file mode 100644
82347 index 0000000..edb2cb6
82348 --- /dev/null
82349 +++ b/include/linux/gracl.h
82350 @@ -0,0 +1,340 @@
82351 +#ifndef GR_ACL_H
82352 +#define GR_ACL_H
82353 +
82354 +#include <linux/grdefs.h>
82355 +#include <linux/resource.h>
82356 +#include <linux/capability.h>
82357 +#include <linux/dcache.h>
82358 +#include <asm/resource.h>
82359 +
82360 +/* Major status information */
82361 +
82362 +#define GR_VERSION "grsecurity 3.0"
82363 +#define GRSECURITY_VERSION 0x3000
82364 +
82365 +enum {
82366 + GR_SHUTDOWN = 0,
82367 + GR_ENABLE = 1,
82368 + GR_SPROLE = 2,
82369 + GR_OLDRELOAD = 3,
82370 + GR_SEGVMOD = 4,
82371 + GR_STATUS = 5,
82372 + GR_UNSPROLE = 6,
82373 + GR_PASSSET = 7,
82374 + GR_SPROLEPAM = 8,
82375 + GR_RELOAD = 9,
82376 +};
82377 +
82378 +/* Password setup definitions
82379 + * kernel/grhash.c */
82380 +enum {
82381 + GR_PW_LEN = 128,
82382 + GR_SALT_LEN = 16,
82383 + GR_SHA_LEN = 32,
82384 +};
82385 +
82386 +enum {
82387 + GR_SPROLE_LEN = 64,
82388 +};
82389 +
82390 +enum {
82391 + GR_NO_GLOB = 0,
82392 + GR_REG_GLOB,
82393 + GR_CREATE_GLOB
82394 +};
82395 +
82396 +#define GR_NLIMITS 32
82397 +
82398 +/* Begin Data Structures */
82399 +
82400 +struct sprole_pw {
82401 + unsigned char *rolename;
82402 + unsigned char salt[GR_SALT_LEN];
82403 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
82404 +};
82405 +
82406 +struct name_entry {
82407 + __u32 key;
82408 + ino_t inode;
82409 + dev_t device;
82410 + char *name;
82411 + __u16 len;
82412 + __u8 deleted;
82413 + struct name_entry *prev;
82414 + struct name_entry *next;
82415 +};
82416 +
82417 +struct inodev_entry {
82418 + struct name_entry *nentry;
82419 + struct inodev_entry *prev;
82420 + struct inodev_entry *next;
82421 +};
82422 +
82423 +struct acl_role_db {
82424 + struct acl_role_label **r_hash;
82425 + __u32 r_size;
82426 +};
82427 +
82428 +struct inodev_db {
82429 + struct inodev_entry **i_hash;
82430 + __u32 i_size;
82431 +};
82432 +
82433 +struct name_db {
82434 + struct name_entry **n_hash;
82435 + __u32 n_size;
82436 +};
82437 +
82438 +struct crash_uid {
82439 + uid_t uid;
82440 + unsigned long expires;
82441 +};
82442 +
82443 +struct gr_hash_struct {
82444 + void **table;
82445 + void **nametable;
82446 + void *first;
82447 + __u32 table_size;
82448 + __u32 used_size;
82449 + int type;
82450 +};
82451 +
82452 +/* Userspace Grsecurity ACL data structures */
82453 +
82454 +struct acl_subject_label {
82455 + char *filename;
82456 + ino_t inode;
82457 + dev_t device;
82458 + __u32 mode;
82459 + kernel_cap_t cap_mask;
82460 + kernel_cap_t cap_lower;
82461 + kernel_cap_t cap_invert_audit;
82462 +
82463 + struct rlimit res[GR_NLIMITS];
82464 + __u32 resmask;
82465 +
82466 + __u8 user_trans_type;
82467 + __u8 group_trans_type;
82468 + uid_t *user_transitions;
82469 + gid_t *group_transitions;
82470 + __u16 user_trans_num;
82471 + __u16 group_trans_num;
82472 +
82473 + __u32 sock_families[2];
82474 + __u32 ip_proto[8];
82475 + __u32 ip_type;
82476 + struct acl_ip_label **ips;
82477 + __u32 ip_num;
82478 + __u32 inaddr_any_override;
82479 +
82480 + __u32 crashes;
82481 + unsigned long expires;
82482 +
82483 + struct acl_subject_label *parent_subject;
82484 + struct gr_hash_struct *hash;
82485 + struct acl_subject_label *prev;
82486 + struct acl_subject_label *next;
82487 +
82488 + struct acl_object_label **obj_hash;
82489 + __u32 obj_hash_size;
82490 + __u16 pax_flags;
82491 +};
82492 +
82493 +struct role_allowed_ip {
82494 + __u32 addr;
82495 + __u32 netmask;
82496 +
82497 + struct role_allowed_ip *prev;
82498 + struct role_allowed_ip *next;
82499 +};
82500 +
82501 +struct role_transition {
82502 + char *rolename;
82503 +
82504 + struct role_transition *prev;
82505 + struct role_transition *next;
82506 +};
82507 +
82508 +struct acl_role_label {
82509 + char *rolename;
82510 + uid_t uidgid;
82511 + __u16 roletype;
82512 +
82513 + __u16 auth_attempts;
82514 + unsigned long expires;
82515 +
82516 + struct acl_subject_label *root_label;
82517 + struct gr_hash_struct *hash;
82518 +
82519 + struct acl_role_label *prev;
82520 + struct acl_role_label *next;
82521 +
82522 + struct role_transition *transitions;
82523 + struct role_allowed_ip *allowed_ips;
82524 + uid_t *domain_children;
82525 + __u16 domain_child_num;
82526 +
82527 + umode_t umask;
82528 +
82529 + struct acl_subject_label **subj_hash;
82530 + __u32 subj_hash_size;
82531 +};
82532 +
82533 +struct user_acl_role_db {
82534 + struct acl_role_label **r_table;
82535 + __u32 num_pointers; /* Number of allocations to track */
82536 + __u32 num_roles; /* Number of roles */
82537 + __u32 num_domain_children; /* Number of domain children */
82538 + __u32 num_subjects; /* Number of subjects */
82539 + __u32 num_objects; /* Number of objects */
82540 +};
82541 +
82542 +struct acl_object_label {
82543 + char *filename;
82544 + ino_t inode;
82545 + dev_t device;
82546 + __u32 mode;
82547 +
82548 + struct acl_subject_label *nested;
82549 + struct acl_object_label *globbed;
82550 +
82551 + /* next two structures not used */
82552 +
82553 + struct acl_object_label *prev;
82554 + struct acl_object_label *next;
82555 +};
82556 +
82557 +struct acl_ip_label {
82558 + char *iface;
82559 + __u32 addr;
82560 + __u32 netmask;
82561 + __u16 low, high;
82562 + __u8 mode;
82563 + __u32 type;
82564 + __u32 proto[8];
82565 +
82566 + /* next two structures not used */
82567 +
82568 + struct acl_ip_label *prev;
82569 + struct acl_ip_label *next;
82570 +};
82571 +
82572 +struct gr_arg {
82573 + struct user_acl_role_db role_db;
82574 + unsigned char pw[GR_PW_LEN];
82575 + unsigned char salt[GR_SALT_LEN];
82576 + unsigned char sum[GR_SHA_LEN];
82577 + unsigned char sp_role[GR_SPROLE_LEN];
82578 + struct sprole_pw *sprole_pws;
82579 + dev_t segv_device;
82580 + ino_t segv_inode;
82581 + uid_t segv_uid;
82582 + __u16 num_sprole_pws;
82583 + __u16 mode;
82584 +};
82585 +
82586 +struct gr_arg_wrapper {
82587 + struct gr_arg *arg;
82588 + __u32 version;
82589 + __u32 size;
82590 +};
82591 +
82592 +struct subject_map {
82593 + struct acl_subject_label *user;
82594 + struct acl_subject_label *kernel;
82595 + struct subject_map *prev;
82596 + struct subject_map *next;
82597 +};
82598 +
82599 +struct acl_subj_map_db {
82600 + struct subject_map **s_hash;
82601 + __u32 s_size;
82602 +};
82603 +
82604 +struct gr_policy_state {
82605 + struct sprole_pw **acl_special_roles;
82606 + __u16 num_sprole_pws;
82607 + struct acl_role_label *kernel_role;
82608 + struct acl_role_label *role_list;
82609 + struct acl_role_label *default_role;
82610 + struct acl_role_db acl_role_set;
82611 + struct acl_subj_map_db subj_map_set;
82612 + struct name_db name_set;
82613 + struct inodev_db inodev_set;
82614 +};
82615 +
82616 +struct gr_alloc_state {
82617 + unsigned long alloc_stack_next;
82618 + unsigned long alloc_stack_size;
82619 + void **alloc_stack;
82620 +};
82621 +
82622 +struct gr_reload_state {
82623 + struct gr_policy_state oldpolicy;
82624 + struct gr_alloc_state oldalloc;
82625 + struct gr_policy_state newpolicy;
82626 + struct gr_alloc_state newalloc;
82627 + struct gr_policy_state *oldpolicy_ptr;
82628 + struct gr_alloc_state *oldalloc_ptr;
82629 + unsigned char oldmode;
82630 +};
82631 +
82632 +/* End Data Structures Section */
82633 +
82634 +/* Hash functions generated by empirical testing by Brad Spengler
82635 + Makes good use of the low bits of the inode. Generally 0-1 times
82636 + in loop for successful match. 0-3 for unsuccessful match.
82637 + Shift/add algorithm with modulus of table size and an XOR*/
82638 +
82639 +static __inline__ unsigned int
82640 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
82641 +{
82642 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
82643 +}
82644 +
82645 + static __inline__ unsigned int
82646 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
82647 +{
82648 + return ((const unsigned long)userp % sz);
82649 +}
82650 +
82651 +static __inline__ unsigned int
82652 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
82653 +{
82654 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
82655 +}
82656 +
82657 +static __inline__ unsigned int
82658 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
82659 +{
82660 + return full_name_hash((const unsigned char *)name, len) % sz;
82661 +}
82662 +
82663 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
82664 + subj = NULL; \
82665 + iter = 0; \
82666 + while (iter < role->subj_hash_size) { \
82667 + if (subj == NULL) \
82668 + subj = role->subj_hash[iter]; \
82669 + if (subj == NULL) { \
82670 + iter++; \
82671 + continue; \
82672 + }
82673 +
82674 +#define FOR_EACH_SUBJECT_END(subj,iter) \
82675 + subj = subj->next; \
82676 + if (subj == NULL) \
82677 + iter++; \
82678 + }
82679 +
82680 +
82681 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
82682 + subj = role->hash->first; \
82683 + while (subj != NULL) {
82684 +
82685 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
82686 + subj = subj->next; \
82687 + }
82688 +
82689 +#endif
82690 +
82691 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
82692 new file mode 100644
82693 index 0000000..33ebd1f
82694 --- /dev/null
82695 +++ b/include/linux/gracl_compat.h
82696 @@ -0,0 +1,156 @@
82697 +#ifndef GR_ACL_COMPAT_H
82698 +#define GR_ACL_COMPAT_H
82699 +
82700 +#include <linux/resource.h>
82701 +#include <asm/resource.h>
82702 +
82703 +struct sprole_pw_compat {
82704 + compat_uptr_t rolename;
82705 + unsigned char salt[GR_SALT_LEN];
82706 + unsigned char sum[GR_SHA_LEN];
82707 +};
82708 +
82709 +struct gr_hash_struct_compat {
82710 + compat_uptr_t table;
82711 + compat_uptr_t nametable;
82712 + compat_uptr_t first;
82713 + __u32 table_size;
82714 + __u32 used_size;
82715 + int type;
82716 +};
82717 +
82718 +struct acl_subject_label_compat {
82719 + compat_uptr_t filename;
82720 + compat_ino_t inode;
82721 + __u32 device;
82722 + __u32 mode;
82723 + kernel_cap_t cap_mask;
82724 + kernel_cap_t cap_lower;
82725 + kernel_cap_t cap_invert_audit;
82726 +
82727 + struct compat_rlimit res[GR_NLIMITS];
82728 + __u32 resmask;
82729 +
82730 + __u8 user_trans_type;
82731 + __u8 group_trans_type;
82732 + compat_uptr_t user_transitions;
82733 + compat_uptr_t group_transitions;
82734 + __u16 user_trans_num;
82735 + __u16 group_trans_num;
82736 +
82737 + __u32 sock_families[2];
82738 + __u32 ip_proto[8];
82739 + __u32 ip_type;
82740 + compat_uptr_t ips;
82741 + __u32 ip_num;
82742 + __u32 inaddr_any_override;
82743 +
82744 + __u32 crashes;
82745 + compat_ulong_t expires;
82746 +
82747 + compat_uptr_t parent_subject;
82748 + compat_uptr_t hash;
82749 + compat_uptr_t prev;
82750 + compat_uptr_t next;
82751 +
82752 + compat_uptr_t obj_hash;
82753 + __u32 obj_hash_size;
82754 + __u16 pax_flags;
82755 +};
82756 +
82757 +struct role_allowed_ip_compat {
82758 + __u32 addr;
82759 + __u32 netmask;
82760 +
82761 + compat_uptr_t prev;
82762 + compat_uptr_t next;
82763 +};
82764 +
82765 +struct role_transition_compat {
82766 + compat_uptr_t rolename;
82767 +
82768 + compat_uptr_t prev;
82769 + compat_uptr_t next;
82770 +};
82771 +
82772 +struct acl_role_label_compat {
82773 + compat_uptr_t rolename;
82774 + uid_t uidgid;
82775 + __u16 roletype;
82776 +
82777 + __u16 auth_attempts;
82778 + compat_ulong_t expires;
82779 +
82780 + compat_uptr_t root_label;
82781 + compat_uptr_t hash;
82782 +
82783 + compat_uptr_t prev;
82784 + compat_uptr_t next;
82785 +
82786 + compat_uptr_t transitions;
82787 + compat_uptr_t allowed_ips;
82788 + compat_uptr_t domain_children;
82789 + __u16 domain_child_num;
82790 +
82791 + umode_t umask;
82792 +
82793 + compat_uptr_t subj_hash;
82794 + __u32 subj_hash_size;
82795 +};
82796 +
82797 +struct user_acl_role_db_compat {
82798 + compat_uptr_t r_table;
82799 + __u32 num_pointers;
82800 + __u32 num_roles;
82801 + __u32 num_domain_children;
82802 + __u32 num_subjects;
82803 + __u32 num_objects;
82804 +};
82805 +
82806 +struct acl_object_label_compat {
82807 + compat_uptr_t filename;
82808 + compat_ino_t inode;
82809 + __u32 device;
82810 + __u32 mode;
82811 +
82812 + compat_uptr_t nested;
82813 + compat_uptr_t globbed;
82814 +
82815 + compat_uptr_t prev;
82816 + compat_uptr_t next;
82817 +};
82818 +
82819 +struct acl_ip_label_compat {
82820 + compat_uptr_t iface;
82821 + __u32 addr;
82822 + __u32 netmask;
82823 + __u16 low, high;
82824 + __u8 mode;
82825 + __u32 type;
82826 + __u32 proto[8];
82827 +
82828 + compat_uptr_t prev;
82829 + compat_uptr_t next;
82830 +};
82831 +
82832 +struct gr_arg_compat {
82833 + struct user_acl_role_db_compat role_db;
82834 + unsigned char pw[GR_PW_LEN];
82835 + unsigned char salt[GR_SALT_LEN];
82836 + unsigned char sum[GR_SHA_LEN];
82837 + unsigned char sp_role[GR_SPROLE_LEN];
82838 + compat_uptr_t sprole_pws;
82839 + __u32 segv_device;
82840 + compat_ino_t segv_inode;
82841 + uid_t segv_uid;
82842 + __u16 num_sprole_pws;
82843 + __u16 mode;
82844 +};
82845 +
82846 +struct gr_arg_wrapper_compat {
82847 + compat_uptr_t arg;
82848 + __u32 version;
82849 + __u32 size;
82850 +};
82851 +
82852 +#endif
82853 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
82854 new file mode 100644
82855 index 0000000..323ecf2
82856 --- /dev/null
82857 +++ b/include/linux/gralloc.h
82858 @@ -0,0 +1,9 @@
82859 +#ifndef __GRALLOC_H
82860 +#define __GRALLOC_H
82861 +
82862 +void acl_free_all(void);
82863 +int acl_alloc_stack_init(unsigned long size);
82864 +void *acl_alloc(unsigned long len);
82865 +void *acl_alloc_num(unsigned long num, unsigned long len);
82866 +
82867 +#endif
82868 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
82869 new file mode 100644
82870 index 0000000..be66033
82871 --- /dev/null
82872 +++ b/include/linux/grdefs.h
82873 @@ -0,0 +1,140 @@
82874 +#ifndef GRDEFS_H
82875 +#define GRDEFS_H
82876 +
82877 +/* Begin grsecurity status declarations */
82878 +
82879 +enum {
82880 + GR_READY = 0x01,
82881 + GR_STATUS_INIT = 0x00 // disabled state
82882 +};
82883 +
82884 +/* Begin ACL declarations */
82885 +
82886 +/* Role flags */
82887 +
82888 +enum {
82889 + GR_ROLE_USER = 0x0001,
82890 + GR_ROLE_GROUP = 0x0002,
82891 + GR_ROLE_DEFAULT = 0x0004,
82892 + GR_ROLE_SPECIAL = 0x0008,
82893 + GR_ROLE_AUTH = 0x0010,
82894 + GR_ROLE_NOPW = 0x0020,
82895 + GR_ROLE_GOD = 0x0040,
82896 + GR_ROLE_LEARN = 0x0080,
82897 + GR_ROLE_TPE = 0x0100,
82898 + GR_ROLE_DOMAIN = 0x0200,
82899 + GR_ROLE_PAM = 0x0400,
82900 + GR_ROLE_PERSIST = 0x0800
82901 +};
82902 +
82903 +/* ACL Subject and Object mode flags */
82904 +enum {
82905 + GR_DELETED = 0x80000000
82906 +};
82907 +
82908 +/* ACL Object-only mode flags */
82909 +enum {
82910 + GR_READ = 0x00000001,
82911 + GR_APPEND = 0x00000002,
82912 + GR_WRITE = 0x00000004,
82913 + GR_EXEC = 0x00000008,
82914 + GR_FIND = 0x00000010,
82915 + GR_INHERIT = 0x00000020,
82916 + GR_SETID = 0x00000040,
82917 + GR_CREATE = 0x00000080,
82918 + GR_DELETE = 0x00000100,
82919 + GR_LINK = 0x00000200,
82920 + GR_AUDIT_READ = 0x00000400,
82921 + GR_AUDIT_APPEND = 0x00000800,
82922 + GR_AUDIT_WRITE = 0x00001000,
82923 + GR_AUDIT_EXEC = 0x00002000,
82924 + GR_AUDIT_FIND = 0x00004000,
82925 + GR_AUDIT_INHERIT= 0x00008000,
82926 + GR_AUDIT_SETID = 0x00010000,
82927 + GR_AUDIT_CREATE = 0x00020000,
82928 + GR_AUDIT_DELETE = 0x00040000,
82929 + GR_AUDIT_LINK = 0x00080000,
82930 + GR_PTRACERD = 0x00100000,
82931 + GR_NOPTRACE = 0x00200000,
82932 + GR_SUPPRESS = 0x00400000,
82933 + GR_NOLEARN = 0x00800000,
82934 + GR_INIT_TRANSFER= 0x01000000
82935 +};
82936 +
82937 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
82938 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
82939 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
82940 +
82941 +/* ACL subject-only mode flags */
82942 +enum {
82943 + GR_KILL = 0x00000001,
82944 + GR_VIEW = 0x00000002,
82945 + GR_PROTECTED = 0x00000004,
82946 + GR_LEARN = 0x00000008,
82947 + GR_OVERRIDE = 0x00000010,
82948 + /* just a placeholder, this mode is only used in userspace */
82949 + GR_DUMMY = 0x00000020,
82950 + GR_PROTSHM = 0x00000040,
82951 + GR_KILLPROC = 0x00000080,
82952 + GR_KILLIPPROC = 0x00000100,
82953 + /* just a placeholder, this mode is only used in userspace */
82954 + GR_NOTROJAN = 0x00000200,
82955 + GR_PROTPROCFD = 0x00000400,
82956 + GR_PROCACCT = 0x00000800,
82957 + GR_RELAXPTRACE = 0x00001000,
82958 + //GR_NESTED = 0x00002000,
82959 + GR_INHERITLEARN = 0x00004000,
82960 + GR_PROCFIND = 0x00008000,
82961 + GR_POVERRIDE = 0x00010000,
82962 + GR_KERNELAUTH = 0x00020000,
82963 + GR_ATSECURE = 0x00040000,
82964 + GR_SHMEXEC = 0x00080000
82965 +};
82966 +
82967 +enum {
82968 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
82969 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
82970 + GR_PAX_ENABLE_MPROTECT = 0x0004,
82971 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
82972 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
82973 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
82974 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
82975 + GR_PAX_DISABLE_MPROTECT = 0x0400,
82976 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
82977 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
82978 +};
82979 +
82980 +enum {
82981 + GR_ID_USER = 0x01,
82982 + GR_ID_GROUP = 0x02,
82983 +};
82984 +
82985 +enum {
82986 + GR_ID_ALLOW = 0x01,
82987 + GR_ID_DENY = 0x02,
82988 +};
82989 +
82990 +#define GR_CRASH_RES 31
82991 +#define GR_UIDTABLE_MAX 500
82992 +
82993 +/* begin resource learning section */
82994 +enum {
82995 + GR_RLIM_CPU_BUMP = 60,
82996 + GR_RLIM_FSIZE_BUMP = 50000,
82997 + GR_RLIM_DATA_BUMP = 10000,
82998 + GR_RLIM_STACK_BUMP = 1000,
82999 + GR_RLIM_CORE_BUMP = 10000,
83000 + GR_RLIM_RSS_BUMP = 500000,
83001 + GR_RLIM_NPROC_BUMP = 1,
83002 + GR_RLIM_NOFILE_BUMP = 5,
83003 + GR_RLIM_MEMLOCK_BUMP = 50000,
83004 + GR_RLIM_AS_BUMP = 500000,
83005 + GR_RLIM_LOCKS_BUMP = 2,
83006 + GR_RLIM_SIGPENDING_BUMP = 5,
83007 + GR_RLIM_MSGQUEUE_BUMP = 10000,
83008 + GR_RLIM_NICE_BUMP = 1,
83009 + GR_RLIM_RTPRIO_BUMP = 1,
83010 + GR_RLIM_RTTIME_BUMP = 1000000
83011 +};
83012 +
83013 +#endif
83014 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
83015 new file mode 100644
83016 index 0000000..d25522e
83017 --- /dev/null
83018 +++ b/include/linux/grinternal.h
83019 @@ -0,0 +1,229 @@
83020 +#ifndef __GRINTERNAL_H
83021 +#define __GRINTERNAL_H
83022 +
83023 +#ifdef CONFIG_GRKERNSEC
83024 +
83025 +#include <linux/fs.h>
83026 +#include <linux/mnt_namespace.h>
83027 +#include <linux/nsproxy.h>
83028 +#include <linux/gracl.h>
83029 +#include <linux/grdefs.h>
83030 +#include <linux/grmsg.h>
83031 +
83032 +void gr_add_learn_entry(const char *fmt, ...)
83033 + __attribute__ ((format (printf, 1, 2)));
83034 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
83035 + const struct vfsmount *mnt);
83036 +__u32 gr_check_create(const struct dentry *new_dentry,
83037 + const struct dentry *parent,
83038 + const struct vfsmount *mnt, const __u32 mode);
83039 +int gr_check_protected_task(const struct task_struct *task);
83040 +__u32 to_gr_audit(const __u32 reqmode);
83041 +int gr_set_acls(const int type);
83042 +int gr_acl_is_enabled(void);
83043 +char gr_roletype_to_char(void);
83044 +
83045 +void gr_handle_alertkill(struct task_struct *task);
83046 +char *gr_to_filename(const struct dentry *dentry,
83047 + const struct vfsmount *mnt);
83048 +char *gr_to_filename1(const struct dentry *dentry,
83049 + const struct vfsmount *mnt);
83050 +char *gr_to_filename2(const struct dentry *dentry,
83051 + const struct vfsmount *mnt);
83052 +char *gr_to_filename3(const struct dentry *dentry,
83053 + const struct vfsmount *mnt);
83054 +
83055 +extern int grsec_enable_ptrace_readexec;
83056 +extern int grsec_enable_harden_ptrace;
83057 +extern int grsec_enable_link;
83058 +extern int grsec_enable_fifo;
83059 +extern int grsec_enable_execve;
83060 +extern int grsec_enable_shm;
83061 +extern int grsec_enable_execlog;
83062 +extern int grsec_enable_signal;
83063 +extern int grsec_enable_audit_ptrace;
83064 +extern int grsec_enable_forkfail;
83065 +extern int grsec_enable_time;
83066 +extern int grsec_enable_rofs;
83067 +extern int grsec_deny_new_usb;
83068 +extern int grsec_enable_chroot_shmat;
83069 +extern int grsec_enable_chroot_mount;
83070 +extern int grsec_enable_chroot_double;
83071 +extern int grsec_enable_chroot_pivot;
83072 +extern int grsec_enable_chroot_chdir;
83073 +extern int grsec_enable_chroot_chmod;
83074 +extern int grsec_enable_chroot_mknod;
83075 +extern int grsec_enable_chroot_fchdir;
83076 +extern int grsec_enable_chroot_nice;
83077 +extern int grsec_enable_chroot_execlog;
83078 +extern int grsec_enable_chroot_caps;
83079 +extern int grsec_enable_chroot_sysctl;
83080 +extern int grsec_enable_chroot_unix;
83081 +extern int grsec_enable_symlinkown;
83082 +extern kgid_t grsec_symlinkown_gid;
83083 +extern int grsec_enable_tpe;
83084 +extern kgid_t grsec_tpe_gid;
83085 +extern int grsec_enable_tpe_all;
83086 +extern int grsec_enable_tpe_invert;
83087 +extern int grsec_enable_socket_all;
83088 +extern kgid_t grsec_socket_all_gid;
83089 +extern int grsec_enable_socket_client;
83090 +extern kgid_t grsec_socket_client_gid;
83091 +extern int grsec_enable_socket_server;
83092 +extern kgid_t grsec_socket_server_gid;
83093 +extern kgid_t grsec_audit_gid;
83094 +extern int grsec_enable_group;
83095 +extern int grsec_enable_log_rwxmaps;
83096 +extern int grsec_enable_mount;
83097 +extern int grsec_enable_chdir;
83098 +extern int grsec_resource_logging;
83099 +extern int grsec_enable_blackhole;
83100 +extern int grsec_lastack_retries;
83101 +extern int grsec_enable_brute;
83102 +extern int grsec_enable_harden_ipc;
83103 +extern int grsec_lock;
83104 +
83105 +extern spinlock_t grsec_alert_lock;
83106 +extern unsigned long grsec_alert_wtime;
83107 +extern unsigned long grsec_alert_fyet;
83108 +
83109 +extern spinlock_t grsec_audit_lock;
83110 +
83111 +extern rwlock_t grsec_exec_file_lock;
83112 +
83113 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
83114 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
83115 + (tsk)->exec_file->f_path.mnt) : "/")
83116 +
83117 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
83118 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
83119 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
83120 +
83121 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
83122 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
83123 + (tsk)->exec_file->f_path.mnt) : "/")
83124 +
83125 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
83126 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
83127 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
83128 +
83129 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
83130 +
83131 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
83132 +
83133 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
83134 +{
83135 + if (file1 && file2) {
83136 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
83137 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
83138 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
83139 + return true;
83140 + }
83141 +
83142 + return false;
83143 +}
83144 +
83145 +#define GR_CHROOT_CAPS {{ \
83146 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
83147 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
83148 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
83149 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
83150 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
83151 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
83152 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
83153 +
83154 +#define security_learn(normal_msg,args...) \
83155 +({ \
83156 + read_lock(&grsec_exec_file_lock); \
83157 + gr_add_learn_entry(normal_msg "\n", ## args); \
83158 + read_unlock(&grsec_exec_file_lock); \
83159 +})
83160 +
83161 +enum {
83162 + GR_DO_AUDIT,
83163 + GR_DONT_AUDIT,
83164 + /* used for non-audit messages that we shouldn't kill the task on */
83165 + GR_DONT_AUDIT_GOOD
83166 +};
83167 +
83168 +enum {
83169 + GR_TTYSNIFF,
83170 + GR_RBAC,
83171 + GR_RBAC_STR,
83172 + GR_STR_RBAC,
83173 + GR_RBAC_MODE2,
83174 + GR_RBAC_MODE3,
83175 + GR_FILENAME,
83176 + GR_SYSCTL_HIDDEN,
83177 + GR_NOARGS,
83178 + GR_ONE_INT,
83179 + GR_ONE_INT_TWO_STR,
83180 + GR_ONE_STR,
83181 + GR_STR_INT,
83182 + GR_TWO_STR_INT,
83183 + GR_TWO_INT,
83184 + GR_TWO_U64,
83185 + GR_THREE_INT,
83186 + GR_FIVE_INT_TWO_STR,
83187 + GR_TWO_STR,
83188 + GR_THREE_STR,
83189 + GR_FOUR_STR,
83190 + GR_STR_FILENAME,
83191 + GR_FILENAME_STR,
83192 + GR_FILENAME_TWO_INT,
83193 + GR_FILENAME_TWO_INT_STR,
83194 + GR_TEXTREL,
83195 + GR_PTRACE,
83196 + GR_RESOURCE,
83197 + GR_CAP,
83198 + GR_SIG,
83199 + GR_SIG2,
83200 + GR_CRASH1,
83201 + GR_CRASH2,
83202 + GR_PSACCT,
83203 + GR_RWXMAP,
83204 + GR_RWXMAPVMA
83205 +};
83206 +
83207 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
83208 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
83209 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
83210 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
83211 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
83212 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
83213 +#define gr_log_fs_rbac_mode3(audit, msg, dentry, mnt, str1, str2, str3) gr_log_varargs(audit, msg, GR_RBAC_MODE3, dentry, mnt, str1, str2, str3)
83214 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
83215 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
83216 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
83217 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
83218 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
83219 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
83220 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
83221 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
83222 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
83223 +#define gr_log_int5_str2(audit, msg, num1, num2, str1, str2) gr_log_varargs(audit, msg, GR_FIVE_INT_TWO_STR, num1, num2, str1, str2)
83224 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
83225 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
83226 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
83227 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
83228 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
83229 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
83230 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
83231 +#define gr_log_fs_int2_str(audit, msg, dentry, mnt, num1, num2, str) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT_STR, dentry, mnt, num1, num2, str)
83232 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
83233 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
83234 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
83235 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
83236 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
83237 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
83238 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
83239 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
83240 +#define gr_log_procacct(audit, msg, task, num1, num2, num3, num4, num5, num6, num7, num8, num9) gr_log_varargs(audit, msg, GR_PSACCT, task, num1, num2, num3, num4, num5, num6, num7, num8, num9)
83241 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
83242 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
83243 +
83244 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
83245 +
83246 +#endif
83247 +
83248 +#endif
83249 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
83250 new file mode 100644
83251 index 0000000..b02ba9d
83252 --- /dev/null
83253 +++ b/include/linux/grmsg.h
83254 @@ -0,0 +1,117 @@
83255 +#define DEFAULTSECMSG "%.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u, parent %.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u"
83256 +#define GR_ACL_PROCACCT_MSG "%.256s[%.16s:%d] IP:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u run time:[%ud %uh %um %us] cpu time:[%ud %uh %um %us] %s with exit code %ld, parent %.256s[%.16s:%d] IP:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u"
83257 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
83258 +#define GR_STOPMOD_MSG "denied modification of module state by "
83259 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
83260 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
83261 +#define GR_IOPERM_MSG "denied use of ioperm() by "
83262 +#define GR_IOPL_MSG "denied use of iopl() by "
83263 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
83264 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
83265 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
83266 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
83267 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
83268 +#define GR_LEARN_AUDIT_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%lu\t%lu\t%.4095s\t%lu\t%pI4"
83269 +#define GR_ID_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%c\t%d\t%d\t%d\t%pI4"
83270 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
83271 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
83272 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
83273 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
83274 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
83275 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
83276 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
83277 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
83278 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
83279 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
83280 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
83281 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
83282 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
83283 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
83284 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
83285 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
83286 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
83287 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
83288 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
83289 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
83290 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
83291 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
83292 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
83293 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
83294 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
83295 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
83296 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
83297 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
83298 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
83299 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
83300 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
83301 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
83302 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
83303 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
83304 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
83305 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
83306 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
83307 +#define GR_DISABLED_ACL_MSG "Error loading %s, trying to run kernel with acls disabled. To disable acls at startup use <kernel image name> gracl=off from your boot loader"
83308 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
83309 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
83310 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
83311 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
83312 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
83313 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
83314 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
83315 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
83316 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
83317 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
83318 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
83319 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
83320 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
83321 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
83322 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
83323 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
83324 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
83325 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
83326 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
83327 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
83328 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
83329 +#define GR_NICE_CHROOT_MSG "denied priority change by "
83330 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
83331 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
83332 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
83333 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
83334 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
83335 +#define GR_TIME_MSG "time set by "
83336 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
83337 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
83338 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
83339 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
83340 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
83341 +#define GR_BIND_MSG "denied bind() by "
83342 +#define GR_CONNECT_MSG "denied connect() by "
83343 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
83344 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
83345 +#define GR_IP_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%pI4\t%u\t%u\t%u\t%u\t%pI4"
83346 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
83347 +#define GR_CAP_ACL_MSG "use of %s denied for "
83348 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
83349 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
83350 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
83351 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
83352 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
83353 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
83354 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
83355 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
83356 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
83357 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
83358 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
83359 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
83360 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
83361 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
83362 +#define GR_VM86_MSG "denied use of vm86 by "
83363 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
83364 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
83365 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
83366 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
83367 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
83368 +#define GR_BRUTE_DAEMON_MSG "bruteforce prevention initiated for the next 30 minutes or until service restarted, stalling each fork 30 seconds. Please investigate the crash report for "
83369 +#define GR_BRUTE_SUID_MSG "bruteforce prevention initiated due to crash of %.950s against uid %u, banning suid/sgid execs for %u minutes. Please investigate the crash report for "
83370 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
83371 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
83372 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
83373 new file mode 100644
83374 index 0000000..10b9635
83375 --- /dev/null
83376 +++ b/include/linux/grsecurity.h
83377 @@ -0,0 +1,254 @@
83378 +#ifndef GR_SECURITY_H
83379 +#define GR_SECURITY_H
83380 +#include <linux/fs.h>
83381 +#include <linux/fs_struct.h>
83382 +#include <linux/binfmts.h>
83383 +#include <linux/gracl.h>
83384 +
83385 +/* notify of brain-dead configs */
83386 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83387 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
83388 +#endif
83389 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83390 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
83391 +#endif
83392 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
83393 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
83394 +#endif
83395 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
83396 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
83397 +#endif
83398 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
83399 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
83400 +#endif
83401 +
83402 +int gr_handle_new_usb(void);
83403 +
83404 +void gr_handle_brute_attach(int dumpable);
83405 +void gr_handle_brute_check(void);
83406 +void gr_handle_kernel_exploit(void);
83407 +
83408 +char gr_roletype_to_char(void);
83409 +
83410 +int gr_proc_is_restricted(void);
83411 +
83412 +int gr_acl_enable_at_secure(void);
83413 +
83414 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
83415 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
83416 +
83417 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
83418 +
83419 +void gr_del_task_from_ip_table(struct task_struct *p);
83420 +
83421 +int gr_pid_is_chrooted(struct task_struct *p);
83422 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
83423 +int gr_handle_chroot_nice(void);
83424 +int gr_handle_chroot_sysctl(const int op);
83425 +int gr_handle_chroot_setpriority(struct task_struct *p,
83426 + const int niceval);
83427 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
83428 +int gr_chroot_fhandle(void);
83429 +int gr_handle_chroot_chroot(const struct dentry *dentry,
83430 + const struct vfsmount *mnt);
83431 +void gr_handle_chroot_chdir(const struct path *path);
83432 +int gr_handle_chroot_chmod(const struct dentry *dentry,
83433 + const struct vfsmount *mnt, const int mode);
83434 +int gr_handle_chroot_mknod(const struct dentry *dentry,
83435 + const struct vfsmount *mnt, const int mode);
83436 +int gr_handle_chroot_mount(const struct dentry *dentry,
83437 + const struct vfsmount *mnt,
83438 + const char *dev_name);
83439 +int gr_handle_chroot_pivot(void);
83440 +int gr_handle_chroot_unix(const pid_t pid);
83441 +
83442 +int gr_handle_rawio(const struct inode *inode);
83443 +
83444 +void gr_handle_ioperm(void);
83445 +void gr_handle_iopl(void);
83446 +void gr_handle_msr_write(void);
83447 +
83448 +umode_t gr_acl_umask(void);
83449 +
83450 +int gr_tpe_allow(const struct file *file);
83451 +
83452 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
83453 +void gr_clear_chroot_entries(struct task_struct *task);
83454 +
83455 +void gr_log_forkfail(const int retval);
83456 +void gr_log_timechange(void);
83457 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
83458 +void gr_log_chdir(const struct dentry *dentry,
83459 + const struct vfsmount *mnt);
83460 +void gr_log_chroot_exec(const struct dentry *dentry,
83461 + const struct vfsmount *mnt);
83462 +void gr_log_remount(const char *devname, const int retval);
83463 +void gr_log_unmount(const char *devname, const int retval);
83464 +void gr_log_mount(const char *from, const char *to, const int retval);
83465 +void gr_log_textrel(struct vm_area_struct *vma);
83466 +void gr_log_ptgnustack(struct file *file);
83467 +void gr_log_rwxmmap(struct file *file);
83468 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
83469 +
83470 +int gr_handle_follow_link(const struct inode *parent,
83471 + const struct inode *inode,
83472 + const struct dentry *dentry,
83473 + const struct vfsmount *mnt);
83474 +int gr_handle_fifo(const struct dentry *dentry,
83475 + const struct vfsmount *mnt,
83476 + const struct dentry *dir, const int flag,
83477 + const int acc_mode);
83478 +int gr_handle_hardlink(const struct dentry *dentry,
83479 + const struct vfsmount *mnt,
83480 + struct inode *inode,
83481 + const int mode, const struct filename *to);
83482 +
83483 +int gr_is_capable(const int cap);
83484 +int gr_is_capable_nolog(const int cap);
83485 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
83486 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
83487 +
83488 +void gr_copy_label(struct task_struct *tsk);
83489 +void gr_handle_crash(struct task_struct *task, const int sig);
83490 +int gr_handle_signal(const struct task_struct *p, const int sig);
83491 +int gr_check_crash_uid(const kuid_t uid);
83492 +int gr_check_protected_task(const struct task_struct *task);
83493 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
83494 +int gr_acl_handle_mmap(const struct file *file,
83495 + const unsigned long prot);
83496 +int gr_acl_handle_mprotect(const struct file *file,
83497 + const unsigned long prot);
83498 +int gr_check_hidden_task(const struct task_struct *tsk);
83499 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
83500 + const struct vfsmount *mnt);
83501 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
83502 + const struct vfsmount *mnt);
83503 +__u32 gr_acl_handle_access(const struct dentry *dentry,
83504 + const struct vfsmount *mnt, const int fmode);
83505 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
83506 + const struct vfsmount *mnt, umode_t *mode);
83507 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
83508 + const struct vfsmount *mnt);
83509 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
83510 + const struct vfsmount *mnt);
83511 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
83512 + const struct vfsmount *mnt);
83513 +int gr_handle_ptrace(struct task_struct *task, const long request);
83514 +int gr_handle_proc_ptrace(struct task_struct *task);
83515 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
83516 + const struct vfsmount *mnt);
83517 +int gr_check_crash_exec(const struct file *filp);
83518 +int gr_acl_is_enabled(void);
83519 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
83520 + const kgid_t gid);
83521 +int gr_set_proc_label(const struct dentry *dentry,
83522 + const struct vfsmount *mnt,
83523 + const int unsafe_flags);
83524 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
83525 + const struct vfsmount *mnt);
83526 +__u32 gr_acl_handle_open(const struct dentry *dentry,
83527 + const struct vfsmount *mnt, int acc_mode);
83528 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
83529 + const struct dentry *p_dentry,
83530 + const struct vfsmount *p_mnt,
83531 + int open_flags, int acc_mode, const int imode);
83532 +void gr_handle_create(const struct dentry *dentry,
83533 + const struct vfsmount *mnt);
83534 +void gr_handle_proc_create(const struct dentry *dentry,
83535 + const struct inode *inode);
83536 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
83537 + const struct dentry *parent_dentry,
83538 + const struct vfsmount *parent_mnt,
83539 + const int mode);
83540 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
83541 + const struct dentry *parent_dentry,
83542 + const struct vfsmount *parent_mnt);
83543 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
83544 + const struct vfsmount *mnt);
83545 +void gr_handle_delete(const ino_t ino, const dev_t dev);
83546 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
83547 + const struct vfsmount *mnt);
83548 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
83549 + const struct dentry *parent_dentry,
83550 + const struct vfsmount *parent_mnt,
83551 + const struct filename *from);
83552 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
83553 + const struct dentry *parent_dentry,
83554 + const struct vfsmount *parent_mnt,
83555 + const struct dentry *old_dentry,
83556 + const struct vfsmount *old_mnt, const struct filename *to);
83557 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
83558 +int gr_acl_handle_rename(struct dentry *new_dentry,
83559 + struct dentry *parent_dentry,
83560 + const struct vfsmount *parent_mnt,
83561 + struct dentry *old_dentry,
83562 + struct inode *old_parent_inode,
83563 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
83564 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
83565 + struct dentry *old_dentry,
83566 + struct dentry *new_dentry,
83567 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
83568 +__u32 gr_check_link(const struct dentry *new_dentry,
83569 + const struct dentry *parent_dentry,
83570 + const struct vfsmount *parent_mnt,
83571 + const struct dentry *old_dentry,
83572 + const struct vfsmount *old_mnt);
83573 +int gr_acl_handle_filldir(const struct file *file, const char *name,
83574 + const unsigned int namelen, const ino_t ino);
83575 +
83576 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
83577 + const struct vfsmount *mnt);
83578 +void gr_acl_handle_exit(void);
83579 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
83580 +int gr_acl_handle_procpidmem(const struct task_struct *task);
83581 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
83582 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
83583 +void gr_audit_ptrace(struct task_struct *task);
83584 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
83585 +void gr_put_exec_file(struct task_struct *task);
83586 +
83587 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
83588 +
83589 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
83590 +extern void gr_learn_resource(const struct task_struct *task, const int res,
83591 + const unsigned long wanted, const int gt);
83592 +#else
83593 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
83594 + const unsigned long wanted, const int gt)
83595 +{
83596 +}
83597 +#endif
83598 +
83599 +#ifdef CONFIG_GRKERNSEC_RESLOG
83600 +extern void gr_log_resource(const struct task_struct *task, const int res,
83601 + const unsigned long wanted, const int gt);
83602 +#else
83603 +static inline void gr_log_resource(const struct task_struct *task, const int res,
83604 + const unsigned long wanted, const int gt)
83605 +{
83606 +}
83607 +#endif
83608 +
83609 +#ifdef CONFIG_GRKERNSEC
83610 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
83611 +void gr_handle_vm86(void);
83612 +void gr_handle_mem_readwrite(u64 from, u64 to);
83613 +
83614 +void gr_log_badprocpid(const char *entry);
83615 +
83616 +extern int grsec_enable_dmesg;
83617 +extern int grsec_disable_privio;
83618 +
83619 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83620 +extern kgid_t grsec_proc_gid;
83621 +#endif
83622 +
83623 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83624 +extern int grsec_enable_chroot_findtask;
83625 +#endif
83626 +#ifdef CONFIG_GRKERNSEC_SETXID
83627 +extern int grsec_enable_setxid;
83628 +#endif
83629 +#endif
83630 +
83631 +#endif
83632 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
83633 new file mode 100644
83634 index 0000000..e7ffaaf
83635 --- /dev/null
83636 +++ b/include/linux/grsock.h
83637 @@ -0,0 +1,19 @@
83638 +#ifndef __GRSOCK_H
83639 +#define __GRSOCK_H
83640 +
83641 +extern void gr_attach_curr_ip(const struct sock *sk);
83642 +extern int gr_handle_sock_all(const int family, const int type,
83643 + const int protocol);
83644 +extern int gr_handle_sock_server(const struct sockaddr *sck);
83645 +extern int gr_handle_sock_server_other(const struct sock *sck);
83646 +extern int gr_handle_sock_client(const struct sockaddr *sck);
83647 +extern int gr_search_connect(struct socket * sock,
83648 + struct sockaddr_in * addr);
83649 +extern int gr_search_bind(struct socket * sock,
83650 + struct sockaddr_in * addr);
83651 +extern int gr_search_listen(struct socket * sock);
83652 +extern int gr_search_accept(struct socket * sock);
83653 +extern int gr_search_socket(const int domain, const int type,
83654 + const int protocol);
83655 +
83656 +#endif
83657 diff --git a/include/linux/hash.h b/include/linux/hash.h
83658 index bd1754c..8240892 100644
83659 --- a/include/linux/hash.h
83660 +++ b/include/linux/hash.h
83661 @@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
83662 struct fast_hash_ops {
83663 u32 (*hash)(const void *data, u32 len, u32 seed);
83664 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
83665 -};
83666 +} __no_const;
83667
83668 /**
83669 * arch_fast_hash - Caclulates a hash over a given buffer that can have
83670 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
83671 index 7fb31da..08b5114 100644
83672 --- a/include/linux/highmem.h
83673 +++ b/include/linux/highmem.h
83674 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
83675 kunmap_atomic(kaddr);
83676 }
83677
83678 +static inline void sanitize_highpage(struct page *page)
83679 +{
83680 + void *kaddr;
83681 + unsigned long flags;
83682 +
83683 + local_irq_save(flags);
83684 + kaddr = kmap_atomic(page);
83685 + clear_page(kaddr);
83686 + kunmap_atomic(kaddr);
83687 + local_irq_restore(flags);
83688 +}
83689 +
83690 static inline void zero_user_segments(struct page *page,
83691 unsigned start1, unsigned end1,
83692 unsigned start2, unsigned end2)
83693 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
83694 index 1c7b89a..7dda400 100644
83695 --- a/include/linux/hwmon-sysfs.h
83696 +++ b/include/linux/hwmon-sysfs.h
83697 @@ -25,7 +25,8 @@
83698 struct sensor_device_attribute{
83699 struct device_attribute dev_attr;
83700 int index;
83701 -};
83702 +} __do_const;
83703 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
83704 #define to_sensor_dev_attr(_dev_attr) \
83705 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
83706
83707 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
83708 struct device_attribute dev_attr;
83709 u8 index;
83710 u8 nr;
83711 -};
83712 +} __do_const;
83713 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
83714 #define to_sensor_dev_attr_2(_dev_attr) \
83715 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
83716
83717 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
83718 index b556e0a..c10a515 100644
83719 --- a/include/linux/i2c.h
83720 +++ b/include/linux/i2c.h
83721 @@ -378,6 +378,7 @@ struct i2c_algorithm {
83722 /* To determine what the adapter supports */
83723 u32 (*functionality) (struct i2c_adapter *);
83724 };
83725 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
83726
83727 /**
83728 * struct i2c_bus_recovery_info - I2C bus recovery information
83729 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
83730 index d23c3c2..eb63c81 100644
83731 --- a/include/linux/i2o.h
83732 +++ b/include/linux/i2o.h
83733 @@ -565,7 +565,7 @@ struct i2o_controller {
83734 struct i2o_device *exec; /* Executive */
83735 #if BITS_PER_LONG == 64
83736 spinlock_t context_list_lock; /* lock for context_list */
83737 - atomic_t context_list_counter; /* needed for unique contexts */
83738 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
83739 struct list_head context_list; /* list of context id's
83740 and pointers */
83741 #endif
83742 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
83743 index aff7ad8..3942bbd 100644
83744 --- a/include/linux/if_pppox.h
83745 +++ b/include/linux/if_pppox.h
83746 @@ -76,7 +76,7 @@ struct pppox_proto {
83747 int (*ioctl)(struct socket *sock, unsigned int cmd,
83748 unsigned long arg);
83749 struct module *owner;
83750 -};
83751 +} __do_const;
83752
83753 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
83754 extern void unregister_pppox_proto(int proto_num);
83755 diff --git a/include/linux/init.h b/include/linux/init.h
83756 index 2df8e8d..3e1280d 100644
83757 --- a/include/linux/init.h
83758 +++ b/include/linux/init.h
83759 @@ -37,9 +37,17 @@
83760 * section.
83761 */
83762
83763 +#define add_init_latent_entropy __latent_entropy
83764 +
83765 +#ifdef CONFIG_MEMORY_HOTPLUG
83766 +#define add_meminit_latent_entropy
83767 +#else
83768 +#define add_meminit_latent_entropy __latent_entropy
83769 +#endif
83770 +
83771 /* These are for everybody (although not all archs will actually
83772 discard it in modules) */
83773 -#define __init __section(.init.text) __cold notrace
83774 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
83775 #define __initdata __section(.init.data)
83776 #define __initconst __constsection(.init.rodata)
83777 #define __exitdata __section(.exit.data)
83778 @@ -100,7 +108,7 @@
83779 #define __cpuexitconst
83780
83781 /* Used for MEMORY_HOTPLUG */
83782 -#define __meminit __section(.meminit.text) __cold notrace
83783 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
83784 #define __meminitdata __section(.meminit.data)
83785 #define __meminitconst __constsection(.meminit.rodata)
83786 #define __memexit __section(.memexit.text) __exitused __cold notrace
83787 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
83788 index 6df7f9f..d0bf699 100644
83789 --- a/include/linux/init_task.h
83790 +++ b/include/linux/init_task.h
83791 @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
83792
83793 #define INIT_TASK_COMM "swapper"
83794
83795 +#ifdef CONFIG_X86
83796 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
83797 +#else
83798 +#define INIT_TASK_THREAD_INFO
83799 +#endif
83800 +
83801 #ifdef CONFIG_RT_MUTEXES
83802 # define INIT_RT_MUTEXES(tsk) \
83803 .pi_waiters = RB_ROOT, \
83804 @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
83805 RCU_POINTER_INITIALIZER(cred, &init_cred), \
83806 .comm = INIT_TASK_COMM, \
83807 .thread = INIT_THREAD, \
83808 + INIT_TASK_THREAD_INFO \
83809 .fs = &init_fs, \
83810 .files = &init_files, \
83811 .signal = &init_signals, \
83812 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
83813 index 698ad05..8601bb7 100644
83814 --- a/include/linux/interrupt.h
83815 +++ b/include/linux/interrupt.h
83816 @@ -418,8 +418,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
83817
83818 struct softirq_action
83819 {
83820 - void (*action)(struct softirq_action *);
83821 -};
83822 + void (*action)(void);
83823 +} __no_const;
83824
83825 asmlinkage void do_softirq(void);
83826 asmlinkage void __do_softirq(void);
83827 @@ -433,7 +433,7 @@ static inline void do_softirq_own_stack(void)
83828 }
83829 #endif
83830
83831 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
83832 +extern void open_softirq(int nr, void (*action)(void));
83833 extern void softirq_init(void);
83834 extern void __raise_softirq_irqoff(unsigned int nr);
83835
83836 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
83837 index b96a5b2..2732d1c 100644
83838 --- a/include/linux/iommu.h
83839 +++ b/include/linux/iommu.h
83840 @@ -131,7 +131,7 @@ struct iommu_ops {
83841 u32 (*domain_get_windows)(struct iommu_domain *domain);
83842
83843 unsigned long pgsize_bitmap;
83844 -};
83845 +} __do_const;
83846
83847 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
83848 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
83849 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
83850 index 5e3a906..3131d0f 100644
83851 --- a/include/linux/ioport.h
83852 +++ b/include/linux/ioport.h
83853 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
83854 int adjust_resource(struct resource *res, resource_size_t start,
83855 resource_size_t size);
83856 resource_size_t resource_alignment(struct resource *res);
83857 -static inline resource_size_t resource_size(const struct resource *res)
83858 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
83859 {
83860 return res->end - res->start + 1;
83861 }
83862 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
83863 index 35e7eca..6afb7ad 100644
83864 --- a/include/linux/ipc_namespace.h
83865 +++ b/include/linux/ipc_namespace.h
83866 @@ -69,7 +69,7 @@ struct ipc_namespace {
83867 struct user_namespace *user_ns;
83868
83869 unsigned int proc_inum;
83870 -};
83871 +} __randomize_layout;
83872
83873 extern struct ipc_namespace init_ipc_ns;
83874 extern atomic_t nr_ipc_ns;
83875 diff --git a/include/linux/irq.h b/include/linux/irq.h
83876 index 0d998d8..3a1c782 100644
83877 --- a/include/linux/irq.h
83878 +++ b/include/linux/irq.h
83879 @@ -344,7 +344,8 @@ struct irq_chip {
83880 void (*irq_release_resources)(struct irq_data *data);
83881
83882 unsigned long flags;
83883 -};
83884 +} __do_const;
83885 +typedef struct irq_chip __no_const irq_chip_no_const;
83886
83887 /*
83888 * irq_chip specific flags
83889 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
83890 index 45e2d8c..26d85da 100644
83891 --- a/include/linux/irqchip/arm-gic.h
83892 +++ b/include/linux/irqchip/arm-gic.h
83893 @@ -75,9 +75,11 @@
83894
83895 #ifndef __ASSEMBLY__
83896
83897 +#include <linux/irq.h>
83898 +
83899 struct device_node;
83900
83901 -extern struct irq_chip gic_arch_extn;
83902 +extern irq_chip_no_const gic_arch_extn;
83903
83904 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
83905 u32 offset, struct device_node *);
83906 diff --git a/include/linux/isdn_ppp.h b/include/linux/isdn_ppp.h
83907 index 8e10f57..d5f62bc 100644
83908 --- a/include/linux/isdn_ppp.h
83909 +++ b/include/linux/isdn_ppp.h
83910 @@ -180,8 +180,9 @@ struct ippp_struct {
83911 struct slcompress *slcomp;
83912 #endif
83913 #ifdef CONFIG_IPPP_FILTER
83914 - struct sk_filter *pass_filter; /* filter for packets to pass */
83915 - struct sk_filter *active_filter; /* filter for pkts to reset idle */
83916 + struct sock_filter *pass_filter; /* filter for packets to pass */
83917 + struct sock_filter *active_filter; /* filter for pkts to reset idle */
83918 + unsigned pass_len, active_len;
83919 #endif
83920 unsigned long debug;
83921 struct isdn_ppp_compressor *compressor,*decompressor;
83922 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
83923 index 1f44466..b481806 100644
83924 --- a/include/linux/jiffies.h
83925 +++ b/include/linux/jiffies.h
83926 @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
83927 /*
83928 * Convert various time units to each other:
83929 */
83930 -extern unsigned int jiffies_to_msecs(const unsigned long j);
83931 -extern unsigned int jiffies_to_usecs(const unsigned long j);
83932 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
83933 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
83934
83935 -static inline u64 jiffies_to_nsecs(const unsigned long j)
83936 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
83937 {
83938 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
83939 }
83940
83941 -extern unsigned long msecs_to_jiffies(const unsigned int m);
83942 -extern unsigned long usecs_to_jiffies(const unsigned int u);
83943 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
83944 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
83945 extern unsigned long timespec_to_jiffies(const struct timespec *value);
83946 extern void jiffies_to_timespec(const unsigned long jiffies,
83947 - struct timespec *value);
83948 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
83949 + struct timespec *value) __intentional_overflow(-1);
83950 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
83951 extern void jiffies_to_timeval(const unsigned long jiffies,
83952 struct timeval *value);
83953
83954 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
83955 index 6883e19..e854fcb 100644
83956 --- a/include/linux/kallsyms.h
83957 +++ b/include/linux/kallsyms.h
83958 @@ -15,7 +15,8 @@
83959
83960 struct module;
83961
83962 -#ifdef CONFIG_KALLSYMS
83963 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
83964 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
83965 /* Lookup the address for a symbol. Returns 0 if not found. */
83966 unsigned long kallsyms_lookup_name(const char *name);
83967
83968 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
83969 /* Stupid that this does nothing, but I didn't create this mess. */
83970 #define __print_symbol(fmt, addr)
83971 #endif /*CONFIG_KALLSYMS*/
83972 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
83973 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
83974 +extern unsigned long kallsyms_lookup_name(const char *name);
83975 +extern void __print_symbol(const char *fmt, unsigned long address);
83976 +extern int sprint_backtrace(char *buffer, unsigned long address);
83977 +extern int sprint_symbol(char *buffer, unsigned long address);
83978 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
83979 +const char *kallsyms_lookup(unsigned long addr,
83980 + unsigned long *symbolsize,
83981 + unsigned long *offset,
83982 + char **modname, char *namebuf);
83983 +extern int kallsyms_lookup_size_offset(unsigned long addr,
83984 + unsigned long *symbolsize,
83985 + unsigned long *offset);
83986 +#endif
83987
83988 /* This macro allows us to keep printk typechecking */
83989 static __printf(1, 2)
83990 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
83991 index a74c3a8..28d3f21 100644
83992 --- a/include/linux/key-type.h
83993 +++ b/include/linux/key-type.h
83994 @@ -131,7 +131,7 @@ struct key_type {
83995 /* internal fields */
83996 struct list_head link; /* link in types list */
83997 struct lock_class_key lock_class; /* key->sem lock class */
83998 -};
83999 +} __do_const;
84000
84001 extern struct key_type key_type_keyring;
84002
84003 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
84004 index 6b06d37..c134867 100644
84005 --- a/include/linux/kgdb.h
84006 +++ b/include/linux/kgdb.h
84007 @@ -52,7 +52,7 @@ extern int kgdb_connected;
84008 extern int kgdb_io_module_registered;
84009
84010 extern atomic_t kgdb_setting_breakpoint;
84011 -extern atomic_t kgdb_cpu_doing_single_step;
84012 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
84013
84014 extern struct task_struct *kgdb_usethread;
84015 extern struct task_struct *kgdb_contthread;
84016 @@ -254,7 +254,7 @@ struct kgdb_arch {
84017 void (*correct_hw_break)(void);
84018
84019 void (*enable_nmi)(bool on);
84020 -};
84021 +} __do_const;
84022
84023 /**
84024 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
84025 @@ -279,7 +279,7 @@ struct kgdb_io {
84026 void (*pre_exception) (void);
84027 void (*post_exception) (void);
84028 int is_console;
84029 -};
84030 +} __do_const;
84031
84032 extern struct kgdb_arch arch_kgdb_ops;
84033
84034 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
84035 index 0555cc6..40116ce 100644
84036 --- a/include/linux/kmod.h
84037 +++ b/include/linux/kmod.h
84038 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
84039 * usually useless though. */
84040 extern __printf(2, 3)
84041 int __request_module(bool wait, const char *name, ...);
84042 +extern __printf(3, 4)
84043 +int ___request_module(bool wait, char *param_name, const char *name, ...);
84044 #define request_module(mod...) __request_module(true, mod)
84045 #define request_module_nowait(mod...) __request_module(false, mod)
84046 #define try_then_request_module(x, mod...) \
84047 @@ -57,6 +59,9 @@ struct subprocess_info {
84048 struct work_struct work;
84049 struct completion *complete;
84050 char *path;
84051 +#ifdef CONFIG_GRKERNSEC
84052 + char *origpath;
84053 +#endif
84054 char **argv;
84055 char **envp;
84056 int wait;
84057 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
84058 index 2d61b90..a1d0a13 100644
84059 --- a/include/linux/kobject.h
84060 +++ b/include/linux/kobject.h
84061 @@ -118,7 +118,7 @@ struct kobj_type {
84062 struct attribute **default_attrs;
84063 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
84064 const void *(*namespace)(struct kobject *kobj);
84065 -};
84066 +} __do_const;
84067
84068 struct kobj_uevent_env {
84069 char *argv[3];
84070 @@ -142,6 +142,7 @@ struct kobj_attribute {
84071 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
84072 const char *buf, size_t count);
84073 };
84074 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
84075
84076 extern const struct sysfs_ops kobj_sysfs_ops;
84077
84078 @@ -169,7 +170,7 @@ struct kset {
84079 spinlock_t list_lock;
84080 struct kobject kobj;
84081 const struct kset_uevent_ops *uevent_ops;
84082 -};
84083 +} __randomize_layout;
84084
84085 extern void kset_init(struct kset *kset);
84086 extern int __must_check kset_register(struct kset *kset);
84087 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
84088 index df32d25..fb52e27 100644
84089 --- a/include/linux/kobject_ns.h
84090 +++ b/include/linux/kobject_ns.h
84091 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
84092 const void *(*netlink_ns)(struct sock *sk);
84093 const void *(*initial_ns)(void);
84094 void (*drop_ns)(void *);
84095 -};
84096 +} __do_const;
84097
84098 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
84099 int kobj_ns_type_registered(enum kobj_ns_type type);
84100 diff --git a/include/linux/kref.h b/include/linux/kref.h
84101 index 484604d..0f6c5b6 100644
84102 --- a/include/linux/kref.h
84103 +++ b/include/linux/kref.h
84104 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
84105 static inline int kref_sub(struct kref *kref, unsigned int count,
84106 void (*release)(struct kref *kref))
84107 {
84108 - WARN_ON(release == NULL);
84109 + BUG_ON(release == NULL);
84110
84111 if (atomic_sub_and_test((int) count, &kref->refcount)) {
84112 release(kref);
84113 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
84114 index ec4e3bd..14db03a 100644
84115 --- a/include/linux/kvm_host.h
84116 +++ b/include/linux/kvm_host.h
84117 @@ -468,7 +468,7 @@ static inline void kvm_irqfd_exit(void)
84118 {
84119 }
84120 #endif
84121 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84122 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84123 struct module *module);
84124 void kvm_exit(void);
84125
84126 @@ -634,7 +634,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
84127 struct kvm_guest_debug *dbg);
84128 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
84129
84130 -int kvm_arch_init(void *opaque);
84131 +int kvm_arch_init(const void *opaque);
84132 void kvm_arch_exit(void);
84133
84134 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
84135 diff --git a/include/linux/libata.h b/include/linux/libata.h
84136 index 92abb49..e7fff2a 100644
84137 --- a/include/linux/libata.h
84138 +++ b/include/linux/libata.h
84139 @@ -976,7 +976,7 @@ struct ata_port_operations {
84140 * fields must be pointers.
84141 */
84142 const struct ata_port_operations *inherits;
84143 -};
84144 +} __do_const;
84145
84146 struct ata_port_info {
84147 unsigned long flags;
84148 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
84149 index a6a42dd..6c5ebce 100644
84150 --- a/include/linux/linkage.h
84151 +++ b/include/linux/linkage.h
84152 @@ -36,6 +36,7 @@
84153 #endif
84154
84155 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
84156 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
84157 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
84158
84159 /*
84160 diff --git a/include/linux/list.h b/include/linux/list.h
84161 index ef95941..82db65a 100644
84162 --- a/include/linux/list.h
84163 +++ b/include/linux/list.h
84164 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
84165 extern void list_del(struct list_head *entry);
84166 #endif
84167
84168 +extern void __pax_list_add(struct list_head *new,
84169 + struct list_head *prev,
84170 + struct list_head *next);
84171 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
84172 +{
84173 + __pax_list_add(new, head, head->next);
84174 +}
84175 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
84176 +{
84177 + __pax_list_add(new, head->prev, head);
84178 +}
84179 +extern void pax_list_del(struct list_head *entry);
84180 +
84181 /**
84182 * list_replace - replace old entry by new one
84183 * @old : the element to be replaced
84184 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
84185 INIT_LIST_HEAD(entry);
84186 }
84187
84188 +extern void pax_list_del_init(struct list_head *entry);
84189 +
84190 /**
84191 * list_move - delete from one list and add as another's head
84192 * @list: the entry to move
84193 diff --git a/include/linux/math64.h b/include/linux/math64.h
84194 index c45c089..298841c 100644
84195 --- a/include/linux/math64.h
84196 +++ b/include/linux/math64.h
84197 @@ -15,7 +15,7 @@
84198 * This is commonly provided by 32bit archs to provide an optimized 64bit
84199 * divide.
84200 */
84201 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84202 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84203 {
84204 *remainder = dividend % divisor;
84205 return dividend / divisor;
84206 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
84207 /**
84208 * div64_u64 - unsigned 64bit divide with 64bit divisor
84209 */
84210 -static inline u64 div64_u64(u64 dividend, u64 divisor)
84211 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
84212 {
84213 return dividend / divisor;
84214 }
84215 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
84216 #define div64_ul(x, y) div_u64((x), (y))
84217
84218 #ifndef div_u64_rem
84219 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84220 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84221 {
84222 *remainder = do_div(dividend, divisor);
84223 return dividend;
84224 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
84225 #endif
84226
84227 #ifndef div64_u64
84228 -extern u64 div64_u64(u64 dividend, u64 divisor);
84229 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
84230 #endif
84231
84232 #ifndef div64_s64
84233 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
84234 * divide.
84235 */
84236 #ifndef div_u64
84237 -static inline u64 div_u64(u64 dividend, u32 divisor)
84238 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
84239 {
84240 u32 remainder;
84241 return div_u64_rem(dividend, divisor, &remainder);
84242 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
84243 index f230a97..714c006 100644
84244 --- a/include/linux/mempolicy.h
84245 +++ b/include/linux/mempolicy.h
84246 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
84247 }
84248
84249 #define vma_policy(vma) ((vma)->vm_policy)
84250 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
84251 +{
84252 + vma->vm_policy = pol;
84253 +}
84254
84255 static inline void mpol_get(struct mempolicy *pol)
84256 {
84257 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
84258 }
84259
84260 #define vma_policy(vma) NULL
84261 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
84262 +{
84263 +}
84264
84265 static inline int
84266 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
84267 diff --git a/include/linux/mm.h b/include/linux/mm.h
84268 index e03dd29..eaf923c 100644
84269 --- a/include/linux/mm.h
84270 +++ b/include/linux/mm.h
84271 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
84272 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
84273 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
84274 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
84275 +
84276 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
84277 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
84278 +#endif
84279 +
84280 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
84281
84282 #ifdef CONFIG_MEM_SOFT_DIRTY
84283 @@ -237,8 +242,8 @@ struct vm_operations_struct {
84284 /* called by access_process_vm when get_user_pages() fails, typically
84285 * for use by special VMAs that can switch between memory and hardware
84286 */
84287 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
84288 - void *buf, int len, int write);
84289 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
84290 + void *buf, size_t len, int write);
84291
84292 /* Called by the /proc/PID/maps code to ask the vma whether it
84293 * has a special name. Returning non-NULL will also cause this
84294 @@ -274,6 +279,7 @@ struct vm_operations_struct {
84295 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
84296 unsigned long size, pgoff_t pgoff);
84297 };
84298 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
84299
84300 struct mmu_gather;
84301 struct inode;
84302 @@ -1144,8 +1150,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
84303 unsigned long *pfn);
84304 int follow_phys(struct vm_area_struct *vma, unsigned long address,
84305 unsigned int flags, unsigned long *prot, resource_size_t *phys);
84306 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
84307 - void *buf, int len, int write);
84308 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
84309 + void *buf, size_t len, int write);
84310
84311 static inline void unmap_shared_mapping_range(struct address_space *mapping,
84312 loff_t const holebegin, loff_t const holelen)
84313 @@ -1184,9 +1190,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
84314 }
84315 #endif
84316
84317 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
84318 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84319 - void *buf, int len, int write);
84320 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
84321 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
84322 + void *buf, size_t len, int write);
84323
84324 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
84325 unsigned long start, unsigned long nr_pages,
84326 @@ -1219,34 +1225,6 @@ int set_page_dirty_lock(struct page *page);
84327 int clear_page_dirty_for_io(struct page *page);
84328 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
84329
84330 -/* Is the vma a continuation of the stack vma above it? */
84331 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
84332 -{
84333 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
84334 -}
84335 -
84336 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
84337 - unsigned long addr)
84338 -{
84339 - return (vma->vm_flags & VM_GROWSDOWN) &&
84340 - (vma->vm_start == addr) &&
84341 - !vma_growsdown(vma->vm_prev, addr);
84342 -}
84343 -
84344 -/* Is the vma a continuation of the stack vma below it? */
84345 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
84346 -{
84347 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
84348 -}
84349 -
84350 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
84351 - unsigned long addr)
84352 -{
84353 - return (vma->vm_flags & VM_GROWSUP) &&
84354 - (vma->vm_end == addr) &&
84355 - !vma_growsup(vma->vm_next, addr);
84356 -}
84357 -
84358 extern pid_t
84359 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
84360
84361 @@ -1346,6 +1324,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
84362 }
84363 #endif
84364
84365 +#ifdef CONFIG_MMU
84366 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
84367 +#else
84368 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
84369 +{
84370 + return __pgprot(0);
84371 +}
84372 +#endif
84373 +
84374 int vma_wants_writenotify(struct vm_area_struct *vma);
84375
84376 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
84377 @@ -1364,8 +1351,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
84378 {
84379 return 0;
84380 }
84381 +
84382 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
84383 + unsigned long address)
84384 +{
84385 + return 0;
84386 +}
84387 #else
84388 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
84389 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
84390 #endif
84391
84392 #ifdef __PAGETABLE_PMD_FOLDED
84393 @@ -1374,8 +1368,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
84394 {
84395 return 0;
84396 }
84397 +
84398 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
84399 + unsigned long address)
84400 +{
84401 + return 0;
84402 +}
84403 #else
84404 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
84405 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
84406 #endif
84407
84408 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
84409 @@ -1393,11 +1394,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
84410 NULL: pud_offset(pgd, address);
84411 }
84412
84413 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
84414 +{
84415 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
84416 + NULL: pud_offset(pgd, address);
84417 +}
84418 +
84419 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
84420 {
84421 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
84422 NULL: pmd_offset(pud, address);
84423 }
84424 +
84425 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
84426 +{
84427 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
84428 + NULL: pmd_offset(pud, address);
84429 +}
84430 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
84431
84432 #if USE_SPLIT_PTE_PTLOCKS
84433 @@ -1796,7 +1809,7 @@ extern int install_special_mapping(struct mm_struct *mm,
84434 unsigned long addr, unsigned long len,
84435 unsigned long flags, struct page **pages);
84436
84437 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
84438 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
84439
84440 extern unsigned long mmap_region(struct file *file, unsigned long addr,
84441 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
84442 @@ -1804,6 +1817,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
84443 unsigned long len, unsigned long prot, unsigned long flags,
84444 unsigned long pgoff, unsigned long *populate);
84445 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
84446 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
84447
84448 #ifdef CONFIG_MMU
84449 extern int __mm_populate(unsigned long addr, unsigned long len,
84450 @@ -1832,10 +1846,11 @@ struct vm_unmapped_area_info {
84451 unsigned long high_limit;
84452 unsigned long align_mask;
84453 unsigned long align_offset;
84454 + unsigned long threadstack_offset;
84455 };
84456
84457 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
84458 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
84459 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
84460 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
84461
84462 /*
84463 * Search for an unmapped address range.
84464 @@ -1847,7 +1862,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
84465 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
84466 */
84467 static inline unsigned long
84468 -vm_unmapped_area(struct vm_unmapped_area_info *info)
84469 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
84470 {
84471 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
84472 return unmapped_area(info);
84473 @@ -1909,6 +1924,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
84474 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
84475 struct vm_area_struct **pprev);
84476
84477 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
84478 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
84479 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
84480 +
84481 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
84482 NULL if none. Assume start_addr < end_addr. */
84483 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
84484 @@ -1937,15 +1956,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
84485 return vma;
84486 }
84487
84488 -#ifdef CONFIG_MMU
84489 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
84490 -#else
84491 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
84492 -{
84493 - return __pgprot(0);
84494 -}
84495 -#endif
84496 -
84497 #ifdef CONFIG_NUMA_BALANCING
84498 unsigned long change_prot_numa(struct vm_area_struct *vma,
84499 unsigned long start, unsigned long end);
84500 @@ -1997,6 +2007,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
84501 static inline void vm_stat_account(struct mm_struct *mm,
84502 unsigned long flags, struct file *file, long pages)
84503 {
84504 +
84505 +#ifdef CONFIG_PAX_RANDMMAP
84506 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
84507 +#endif
84508 +
84509 mm->total_vm += pages;
84510 }
84511 #endif /* CONFIG_PROC_FS */
84512 @@ -2078,7 +2093,7 @@ extern int unpoison_memory(unsigned long pfn);
84513 extern int sysctl_memory_failure_early_kill;
84514 extern int sysctl_memory_failure_recovery;
84515 extern void shake_page(struct page *p, int access);
84516 -extern atomic_long_t num_poisoned_pages;
84517 +extern atomic_long_unchecked_t num_poisoned_pages;
84518 extern int soft_offline_page(struct page *page, int flags);
84519
84520 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
84521 @@ -2113,5 +2128,11 @@ void __init setup_nr_node_ids(void);
84522 static inline void setup_nr_node_ids(void) {}
84523 #endif
84524
84525 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
84526 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
84527 +#else
84528 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
84529 +#endif
84530 +
84531 #endif /* __KERNEL__ */
84532 #endif /* _LINUX_MM_H */
84533 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
84534 index 96c5750..15668ba 100644
84535 --- a/include/linux/mm_types.h
84536 +++ b/include/linux/mm_types.h
84537 @@ -308,7 +308,9 @@ struct vm_area_struct {
84538 #ifdef CONFIG_NUMA
84539 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
84540 #endif
84541 -};
84542 +
84543 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
84544 +} __randomize_layout;
84545
84546 struct core_thread {
84547 struct task_struct *task;
84548 @@ -454,7 +456,25 @@ struct mm_struct {
84549 bool tlb_flush_pending;
84550 #endif
84551 struct uprobes_state uprobes_state;
84552 -};
84553 +
84554 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
84555 + unsigned long pax_flags;
84556 +#endif
84557 +
84558 +#ifdef CONFIG_PAX_DLRESOLVE
84559 + unsigned long call_dl_resolve;
84560 +#endif
84561 +
84562 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
84563 + unsigned long call_syscall;
84564 +#endif
84565 +
84566 +#ifdef CONFIG_PAX_ASLR
84567 + unsigned long delta_mmap; /* randomized offset */
84568 + unsigned long delta_stack; /* randomized offset */
84569 +#endif
84570 +
84571 +} __randomize_layout;
84572
84573 static inline void mm_init_cpumask(struct mm_struct *mm)
84574 {
84575 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
84576 index c5d5278..f0b68c8 100644
84577 --- a/include/linux/mmiotrace.h
84578 +++ b/include/linux/mmiotrace.h
84579 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
84580 /* Called from ioremap.c */
84581 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
84582 void __iomem *addr);
84583 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
84584 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
84585
84586 /* For anyone to insert markers. Remember trailing newline. */
84587 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
84588 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
84589 {
84590 }
84591
84592 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
84593 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
84594 {
84595 }
84596
84597 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
84598 index 6cbd1b6..b1d2f99 100644
84599 --- a/include/linux/mmzone.h
84600 +++ b/include/linux/mmzone.h
84601 @@ -412,7 +412,7 @@ struct zone {
84602 unsigned long flags; /* zone flags, see below */
84603
84604 /* Zone statistics */
84605 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
84606 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
84607
84608 /*
84609 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
84610 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
84611 index 44eeef0..a92d3f9 100644
84612 --- a/include/linux/mod_devicetable.h
84613 +++ b/include/linux/mod_devicetable.h
84614 @@ -139,7 +139,7 @@ struct usb_device_id {
84615 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
84616 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
84617
84618 -#define HID_ANY_ID (~0)
84619 +#define HID_ANY_ID (~0U)
84620 #define HID_BUS_ANY 0xffff
84621 #define HID_GROUP_ANY 0x0000
84622
84623 @@ -475,7 +475,7 @@ struct dmi_system_id {
84624 const char *ident;
84625 struct dmi_strmatch matches[4];
84626 void *driver_data;
84627 -};
84628 +} __do_const;
84629 /*
84630 * struct dmi_device_id appears during expansion of
84631 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
84632 diff --git a/include/linux/module.h b/include/linux/module.h
84633 index f520a76..5f898ef 100644
84634 --- a/include/linux/module.h
84635 +++ b/include/linux/module.h
84636 @@ -17,9 +17,11 @@
84637 #include <linux/moduleparam.h>
84638 #include <linux/jump_label.h>
84639 #include <linux/export.h>
84640 +#include <linux/fs.h>
84641
84642 #include <linux/percpu.h>
84643 #include <asm/module.h>
84644 +#include <asm/pgtable.h>
84645
84646 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
84647 #define MODULE_SIG_STRING "~Module signature appended~\n"
84648 @@ -42,7 +44,7 @@ struct module_kobject {
84649 struct kobject *drivers_dir;
84650 struct module_param_attrs *mp;
84651 struct completion *kobj_completion;
84652 -};
84653 +} __randomize_layout;
84654
84655 struct module_attribute {
84656 struct attribute attr;
84657 @@ -54,12 +56,13 @@ struct module_attribute {
84658 int (*test)(struct module *);
84659 void (*free)(struct module *);
84660 };
84661 +typedef struct module_attribute __no_const module_attribute_no_const;
84662
84663 struct module_version_attribute {
84664 struct module_attribute mattr;
84665 const char *module_name;
84666 const char *version;
84667 -} __attribute__ ((__aligned__(sizeof(void *))));
84668 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
84669
84670 extern ssize_t __modver_version_show(struct module_attribute *,
84671 struct module_kobject *, char *);
84672 @@ -235,7 +238,7 @@ struct module {
84673
84674 /* Sysfs stuff. */
84675 struct module_kobject mkobj;
84676 - struct module_attribute *modinfo_attrs;
84677 + module_attribute_no_const *modinfo_attrs;
84678 const char *version;
84679 const char *srcversion;
84680 struct kobject *holders_dir;
84681 @@ -284,19 +287,16 @@ struct module {
84682 int (*init)(void);
84683
84684 /* If this is non-NULL, vfree after init() returns */
84685 - void *module_init;
84686 + void *module_init_rx, *module_init_rw;
84687
84688 /* Here is the actual code + data, vfree'd on unload. */
84689 - void *module_core;
84690 + void *module_core_rx, *module_core_rw;
84691
84692 /* Here are the sizes of the init and core sections */
84693 - unsigned int init_size, core_size;
84694 + unsigned int init_size_rw, core_size_rw;
84695
84696 /* The size of the executable code in each section. */
84697 - unsigned int init_text_size, core_text_size;
84698 -
84699 - /* Size of RO sections of the module (text+rodata) */
84700 - unsigned int init_ro_size, core_ro_size;
84701 + unsigned int init_size_rx, core_size_rx;
84702
84703 /* Arch-specific module values */
84704 struct mod_arch_specific arch;
84705 @@ -352,6 +352,10 @@ struct module {
84706 #ifdef CONFIG_EVENT_TRACING
84707 struct ftrace_event_call **trace_events;
84708 unsigned int num_trace_events;
84709 + struct file_operations trace_id;
84710 + struct file_operations trace_enable;
84711 + struct file_operations trace_format;
84712 + struct file_operations trace_filter;
84713 #endif
84714 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
84715 unsigned int num_ftrace_callsites;
84716 @@ -375,7 +379,7 @@ struct module {
84717 ctor_fn_t *ctors;
84718 unsigned int num_ctors;
84719 #endif
84720 -};
84721 +} __randomize_layout;
84722 #ifndef MODULE_ARCH_INIT
84723 #define MODULE_ARCH_INIT {}
84724 #endif
84725 @@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
84726 bool is_module_percpu_address(unsigned long addr);
84727 bool is_module_text_address(unsigned long addr);
84728
84729 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
84730 +{
84731 +
84732 +#ifdef CONFIG_PAX_KERNEXEC
84733 + if (ktla_ktva(addr) >= (unsigned long)start &&
84734 + ktla_ktva(addr) < (unsigned long)start + size)
84735 + return 1;
84736 +#endif
84737 +
84738 + return ((void *)addr >= start && (void *)addr < start + size);
84739 +}
84740 +
84741 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
84742 +{
84743 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
84744 +}
84745 +
84746 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
84747 +{
84748 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
84749 +}
84750 +
84751 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
84752 +{
84753 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
84754 +}
84755 +
84756 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
84757 +{
84758 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
84759 +}
84760 +
84761 static inline int within_module_core(unsigned long addr, const struct module *mod)
84762 {
84763 - return (unsigned long)mod->module_core <= addr &&
84764 - addr < (unsigned long)mod->module_core + mod->core_size;
84765 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
84766 }
84767
84768 static inline int within_module_init(unsigned long addr, const struct module *mod)
84769 {
84770 - return (unsigned long)mod->module_init <= addr &&
84771 - addr < (unsigned long)mod->module_init + mod->init_size;
84772 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
84773 }
84774
84775 /* Search for module by name: must hold module_mutex. */
84776 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
84777 index 560ca53..ef621ef 100644
84778 --- a/include/linux/moduleloader.h
84779 +++ b/include/linux/moduleloader.h
84780 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
84781 sections. Returns NULL on failure. */
84782 void *module_alloc(unsigned long size);
84783
84784 +#ifdef CONFIG_PAX_KERNEXEC
84785 +void *module_alloc_exec(unsigned long size);
84786 +#else
84787 +#define module_alloc_exec(x) module_alloc(x)
84788 +#endif
84789 +
84790 /* Free memory returned from module_alloc. */
84791 void module_free(struct module *mod, void *module_region);
84792
84793 +#ifdef CONFIG_PAX_KERNEXEC
84794 +void module_free_exec(struct module *mod, void *module_region);
84795 +#else
84796 +#define module_free_exec(x, y) module_free((x), (y))
84797 +#endif
84798 +
84799 /*
84800 * Apply the given relocation to the (simplified) ELF. Return -error
84801 * or 0.
84802 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
84803 unsigned int relsec,
84804 struct module *me)
84805 {
84806 +#ifdef CONFIG_MODULES
84807 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
84808 +#endif
84809 return -ENOEXEC;
84810 }
84811 #endif
84812 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
84813 unsigned int relsec,
84814 struct module *me)
84815 {
84816 +#ifdef CONFIG_MODULES
84817 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
84818 +#endif
84819 return -ENOEXEC;
84820 }
84821 #endif
84822 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
84823 index b1990c5..2a6e611 100644
84824 --- a/include/linux/moduleparam.h
84825 +++ b/include/linux/moduleparam.h
84826 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
84827 * @len is usually just sizeof(string).
84828 */
84829 #define module_param_string(name, string, len, perm) \
84830 - static const struct kparam_string __param_string_##name \
84831 + static const struct kparam_string __param_string_##name __used \
84832 = { len, string }; \
84833 __module_param_call(MODULE_PARAM_PREFIX, name, \
84834 &param_ops_string, \
84835 @@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
84836 */
84837 #define module_param_array_named(name, array, type, nump, perm) \
84838 param_check_##type(name, &(array)[0]); \
84839 - static const struct kparam_array __param_arr_##name \
84840 + static const struct kparam_array __param_arr_##name __used \
84841 = { .max = ARRAY_SIZE(array), .num = nump, \
84842 .ops = &param_ops_##type, \
84843 .elemsize = sizeof(array[0]), .elem = array }; \
84844 diff --git a/include/linux/mount.h b/include/linux/mount.h
84845 index 839bac2..a96b37c 100644
84846 --- a/include/linux/mount.h
84847 +++ b/include/linux/mount.h
84848 @@ -59,7 +59,7 @@ struct vfsmount {
84849 struct dentry *mnt_root; /* root of the mounted tree */
84850 struct super_block *mnt_sb; /* pointer to superblock */
84851 int mnt_flags;
84852 -};
84853 +} __randomize_layout;
84854
84855 struct file; /* forward dec */
84856
84857 diff --git a/include/linux/namei.h b/include/linux/namei.h
84858 index 492de72..1bddcd4 100644
84859 --- a/include/linux/namei.h
84860 +++ b/include/linux/namei.h
84861 @@ -19,7 +19,7 @@ struct nameidata {
84862 unsigned seq, m_seq;
84863 int last_type;
84864 unsigned depth;
84865 - char *saved_names[MAX_NESTED_LINKS + 1];
84866 + const char *saved_names[MAX_NESTED_LINKS + 1];
84867 };
84868
84869 /*
84870 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
84871
84872 extern void nd_jump_link(struct nameidata *nd, struct path *path);
84873
84874 -static inline void nd_set_link(struct nameidata *nd, char *path)
84875 +static inline void nd_set_link(struct nameidata *nd, const char *path)
84876 {
84877 nd->saved_names[nd->depth] = path;
84878 }
84879
84880 -static inline char *nd_get_link(struct nameidata *nd)
84881 +static inline const char *nd_get_link(const struct nameidata *nd)
84882 {
84883 return nd->saved_names[nd->depth];
84884 }
84885 diff --git a/include/linux/net.h b/include/linux/net.h
84886 index 17d8339..81656c0 100644
84887 --- a/include/linux/net.h
84888 +++ b/include/linux/net.h
84889 @@ -192,7 +192,7 @@ struct net_proto_family {
84890 int (*create)(struct net *net, struct socket *sock,
84891 int protocol, int kern);
84892 struct module *owner;
84893 -};
84894 +} __do_const;
84895
84896 struct iovec;
84897 struct kvec;
84898 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
84899 index 66f9a04..056078d 100644
84900 --- a/include/linux/netdevice.h
84901 +++ b/include/linux/netdevice.h
84902 @@ -1145,6 +1145,7 @@ struct net_device_ops {
84903 void *priv);
84904 int (*ndo_get_lock_subclass)(struct net_device *dev);
84905 };
84906 +typedef struct net_device_ops __no_const net_device_ops_no_const;
84907
84908 /**
84909 * enum net_device_priv_flags - &struct net_device priv_flags
84910 @@ -1312,11 +1313,11 @@ struct net_device {
84911 struct net_device_stats stats;
84912
84913 /* dropped packets by core network, Do not use this in drivers */
84914 - atomic_long_t rx_dropped;
84915 - atomic_long_t tx_dropped;
84916 + atomic_long_unchecked_t rx_dropped;
84917 + atomic_long_unchecked_t tx_dropped;
84918
84919 /* Stats to monitor carrier on<->off transitions */
84920 - atomic_t carrier_changes;
84921 + atomic_unchecked_t carrier_changes;
84922
84923 #ifdef CONFIG_WIRELESS_EXT
84924 /* List of functions to handle Wireless Extensions (instead of ioctl).
84925 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
84926 index 2077489..a15e561 100644
84927 --- a/include/linux/netfilter.h
84928 +++ b/include/linux/netfilter.h
84929 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
84930 #endif
84931 /* Use the module struct to lock set/get code in place */
84932 struct module *owner;
84933 -};
84934 +} __do_const;
84935
84936 /* Function to register/unregister hook points. */
84937 int nf_register_hook(struct nf_hook_ops *reg);
84938 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
84939 index e955d47..04a5338 100644
84940 --- a/include/linux/netfilter/nfnetlink.h
84941 +++ b/include/linux/netfilter/nfnetlink.h
84942 @@ -19,7 +19,7 @@ struct nfnl_callback {
84943 const struct nlattr * const cda[]);
84944 const struct nla_policy *policy; /* netlink attribute policy */
84945 const u_int16_t attr_count; /* number of nlattr's */
84946 -};
84947 +} __do_const;
84948
84949 struct nfnetlink_subsystem {
84950 const char *name;
84951 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
84952 new file mode 100644
84953 index 0000000..33f4af8
84954 --- /dev/null
84955 +++ b/include/linux/netfilter/xt_gradm.h
84956 @@ -0,0 +1,9 @@
84957 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
84958 +#define _LINUX_NETFILTER_XT_GRADM_H 1
84959 +
84960 +struct xt_gradm_mtinfo {
84961 + __u16 flags;
84962 + __u16 invflags;
84963 +};
84964 +
84965 +#endif
84966 diff --git a/include/linux/nls.h b/include/linux/nls.h
84967 index 520681b..2b7fabb 100644
84968 --- a/include/linux/nls.h
84969 +++ b/include/linux/nls.h
84970 @@ -31,7 +31,7 @@ struct nls_table {
84971 const unsigned char *charset2upper;
84972 struct module *owner;
84973 struct nls_table *next;
84974 -};
84975 +} __do_const;
84976
84977 /* this value hold the maximum octet of charset */
84978 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
84979 @@ -46,7 +46,7 @@ enum utf16_endian {
84980 /* nls_base.c */
84981 extern int __register_nls(struct nls_table *, struct module *);
84982 extern int unregister_nls(struct nls_table *);
84983 -extern struct nls_table *load_nls(char *);
84984 +extern struct nls_table *load_nls(const char *);
84985 extern void unload_nls(struct nls_table *);
84986 extern struct nls_table *load_nls_default(void);
84987 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
84988 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
84989 index d14a4c3..a078786 100644
84990 --- a/include/linux/notifier.h
84991 +++ b/include/linux/notifier.h
84992 @@ -54,7 +54,8 @@ struct notifier_block {
84993 notifier_fn_t notifier_call;
84994 struct notifier_block __rcu *next;
84995 int priority;
84996 -};
84997 +} __do_const;
84998 +typedef struct notifier_block __no_const notifier_block_no_const;
84999
85000 struct atomic_notifier_head {
85001 spinlock_t lock;
85002 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
85003 index b2a0f15..4d7da32 100644
85004 --- a/include/linux/oprofile.h
85005 +++ b/include/linux/oprofile.h
85006 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
85007 int oprofilefs_create_ro_ulong(struct dentry * root,
85008 char const * name, ulong * val);
85009
85010 -/** Create a file for read-only access to an atomic_t. */
85011 +/** Create a file for read-only access to an atomic_unchecked_t. */
85012 int oprofilefs_create_ro_atomic(struct dentry * root,
85013 - char const * name, atomic_t * val);
85014 + char const * name, atomic_unchecked_t * val);
85015
85016 /** create a directory */
85017 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
85018 diff --git a/include/linux/padata.h b/include/linux/padata.h
85019 index 4386946..f50c615 100644
85020 --- a/include/linux/padata.h
85021 +++ b/include/linux/padata.h
85022 @@ -129,7 +129,7 @@ struct parallel_data {
85023 struct padata_serial_queue __percpu *squeue;
85024 atomic_t reorder_objects;
85025 atomic_t refcnt;
85026 - atomic_t seq_nr;
85027 + atomic_unchecked_t seq_nr;
85028 struct padata_cpumask cpumask;
85029 spinlock_t lock ____cacheline_aligned;
85030 unsigned int processed;
85031 diff --git a/include/linux/path.h b/include/linux/path.h
85032 index d137218..be0c176 100644
85033 --- a/include/linux/path.h
85034 +++ b/include/linux/path.h
85035 @@ -1,13 +1,15 @@
85036 #ifndef _LINUX_PATH_H
85037 #define _LINUX_PATH_H
85038
85039 +#include <linux/compiler.h>
85040 +
85041 struct dentry;
85042 struct vfsmount;
85043
85044 struct path {
85045 struct vfsmount *mnt;
85046 struct dentry *dentry;
85047 -};
85048 +} __randomize_layout;
85049
85050 extern void path_get(const struct path *);
85051 extern void path_put(const struct path *);
85052 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
85053 index 5f2e559..7d59314 100644
85054 --- a/include/linux/pci_hotplug.h
85055 +++ b/include/linux/pci_hotplug.h
85056 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
85057 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
85058 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
85059 int (*reset_slot) (struct hotplug_slot *slot, int probe);
85060 -};
85061 +} __do_const;
85062 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
85063
85064 /**
85065 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
85066 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
85067 index 707617a..28a2e7e 100644
85068 --- a/include/linux/perf_event.h
85069 +++ b/include/linux/perf_event.h
85070 @@ -339,8 +339,8 @@ struct perf_event {
85071
85072 enum perf_event_active_state state;
85073 unsigned int attach_state;
85074 - local64_t count;
85075 - atomic64_t child_count;
85076 + local64_t count; /* PaX: fix it one day */
85077 + atomic64_unchecked_t child_count;
85078
85079 /*
85080 * These are the total time in nanoseconds that the event
85081 @@ -391,8 +391,8 @@ struct perf_event {
85082 * These accumulate total time (in nanoseconds) that children
85083 * events have been enabled and running, respectively.
85084 */
85085 - atomic64_t child_total_time_enabled;
85086 - atomic64_t child_total_time_running;
85087 + atomic64_unchecked_t child_total_time_enabled;
85088 + atomic64_unchecked_t child_total_time_running;
85089
85090 /*
85091 * Protect attach/detach and child_list:
85092 @@ -722,7 +722,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
85093 entry->ip[entry->nr++] = ip;
85094 }
85095
85096 -extern int sysctl_perf_event_paranoid;
85097 +extern int sysctl_perf_event_legitimately_concerned;
85098 extern int sysctl_perf_event_mlock;
85099 extern int sysctl_perf_event_sample_rate;
85100 extern int sysctl_perf_cpu_time_max_percent;
85101 @@ -737,19 +737,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
85102 loff_t *ppos);
85103
85104
85105 +static inline bool perf_paranoid_any(void)
85106 +{
85107 + return sysctl_perf_event_legitimately_concerned > 2;
85108 +}
85109 +
85110 static inline bool perf_paranoid_tracepoint_raw(void)
85111 {
85112 - return sysctl_perf_event_paranoid > -1;
85113 + return sysctl_perf_event_legitimately_concerned > -1;
85114 }
85115
85116 static inline bool perf_paranoid_cpu(void)
85117 {
85118 - return sysctl_perf_event_paranoid > 0;
85119 + return sysctl_perf_event_legitimately_concerned > 0;
85120 }
85121
85122 static inline bool perf_paranoid_kernel(void)
85123 {
85124 - return sysctl_perf_event_paranoid > 1;
85125 + return sysctl_perf_event_legitimately_concerned > 1;
85126 }
85127
85128 extern void perf_event_init(void);
85129 @@ -880,7 +885,7 @@ struct perf_pmu_events_attr {
85130 struct device_attribute attr;
85131 u64 id;
85132 const char *event_str;
85133 -};
85134 +} __do_const;
85135
85136 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
85137 static struct perf_pmu_events_attr _var = { \
85138 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
85139 index 7246ef3..1539ea4 100644
85140 --- a/include/linux/pid_namespace.h
85141 +++ b/include/linux/pid_namespace.h
85142 @@ -43,7 +43,7 @@ struct pid_namespace {
85143 int hide_pid;
85144 int reboot; /* group exit code if this pidns was rebooted */
85145 unsigned int proc_inum;
85146 -};
85147 +} __randomize_layout;
85148
85149 extern struct pid_namespace init_pid_ns;
85150
85151 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
85152 index eb8b8ac..62649e1 100644
85153 --- a/include/linux/pipe_fs_i.h
85154 +++ b/include/linux/pipe_fs_i.h
85155 @@ -47,10 +47,10 @@ struct pipe_inode_info {
85156 struct mutex mutex;
85157 wait_queue_head_t wait;
85158 unsigned int nrbufs, curbuf, buffers;
85159 - unsigned int readers;
85160 - unsigned int writers;
85161 - unsigned int files;
85162 - unsigned int waiting_writers;
85163 + atomic_t readers;
85164 + atomic_t writers;
85165 + atomic_t files;
85166 + atomic_t waiting_writers;
85167 unsigned int r_counter;
85168 unsigned int w_counter;
85169 struct page *tmp_page;
85170 diff --git a/include/linux/pm.h b/include/linux/pm.h
85171 index 72c0fe0..26918ed 100644
85172 --- a/include/linux/pm.h
85173 +++ b/include/linux/pm.h
85174 @@ -620,6 +620,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
85175 struct dev_pm_domain {
85176 struct dev_pm_ops ops;
85177 };
85178 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
85179
85180 /*
85181 * The PM_EVENT_ messages are also used by drivers implementing the legacy
85182 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
85183 index 7c1d252..0e7061d 100644
85184 --- a/include/linux/pm_domain.h
85185 +++ b/include/linux/pm_domain.h
85186 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
85187 int (*thaw_early)(struct device *dev);
85188 int (*thaw)(struct device *dev);
85189 bool (*active_wakeup)(struct device *dev);
85190 -};
85191 +} __no_const;
85192
85193 struct gpd_cpu_data {
85194 unsigned int saved_exit_latency;
85195 - struct cpuidle_state *idle_state;
85196 + cpuidle_state_no_const *idle_state;
85197 };
85198
85199 struct generic_pm_domain {
85200 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
85201 index 43fd671..08c96ee 100644
85202 --- a/include/linux/pm_runtime.h
85203 +++ b/include/linux/pm_runtime.h
85204 @@ -118,7 +118,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
85205
85206 static inline void pm_runtime_mark_last_busy(struct device *dev)
85207 {
85208 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
85209 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
85210 }
85211
85212 #else /* !CONFIG_PM_RUNTIME */
85213 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
85214 index 195aafc..49a7bc2 100644
85215 --- a/include/linux/pnp.h
85216 +++ b/include/linux/pnp.h
85217 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
85218 struct pnp_fixup {
85219 char id[7];
85220 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
85221 -};
85222 +} __do_const;
85223
85224 /* config parameters */
85225 #define PNP_CONFIG_NORMAL 0x0001
85226 diff --git a/include/linux/poison.h b/include/linux/poison.h
85227 index 2110a81..13a11bb 100644
85228 --- a/include/linux/poison.h
85229 +++ b/include/linux/poison.h
85230 @@ -19,8 +19,8 @@
85231 * under normal circumstances, used to verify that nobody uses
85232 * non-initialized list entries.
85233 */
85234 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
85235 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
85236 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
85237 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
85238
85239 /********** include/linux/timer.h **********/
85240 /*
85241 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
85242 index d8b187c3..9a9257a 100644
85243 --- a/include/linux/power/smartreflex.h
85244 +++ b/include/linux/power/smartreflex.h
85245 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
85246 int (*notify)(struct omap_sr *sr, u32 status);
85247 u8 notify_flags;
85248 u8 class_type;
85249 -};
85250 +} __do_const;
85251
85252 /**
85253 * struct omap_sr_nvalue_table - Smartreflex n-target value info
85254 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
85255 index 4ea1d37..80f4b33 100644
85256 --- a/include/linux/ppp-comp.h
85257 +++ b/include/linux/ppp-comp.h
85258 @@ -84,7 +84,7 @@ struct compressor {
85259 struct module *owner;
85260 /* Extra skb space needed by the compressor algorithm */
85261 unsigned int comp_extra;
85262 -};
85263 +} __do_const;
85264
85265 /*
85266 * The return value from decompress routine is the length of the
85267 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
85268 index de83b4e..c4b997d 100644
85269 --- a/include/linux/preempt.h
85270 +++ b/include/linux/preempt.h
85271 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
85272 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
85273 #endif
85274
85275 +#define raw_preempt_count_add(val) __preempt_count_add(val)
85276 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
85277 +
85278 #define __preempt_count_inc() __preempt_count_add(1)
85279 #define __preempt_count_dec() __preempt_count_sub(1)
85280
85281 #define preempt_count_inc() preempt_count_add(1)
85282 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
85283 #define preempt_count_dec() preempt_count_sub(1)
85284 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
85285
85286 #ifdef CONFIG_PREEMPT_COUNT
85287
85288 @@ -41,6 +46,12 @@ do { \
85289 barrier(); \
85290 } while (0)
85291
85292 +#define raw_preempt_disable() \
85293 +do { \
85294 + raw_preempt_count_inc(); \
85295 + barrier(); \
85296 +} while (0)
85297 +
85298 #define sched_preempt_enable_no_resched() \
85299 do { \
85300 barrier(); \
85301 @@ -49,6 +60,12 @@ do { \
85302
85303 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
85304
85305 +#define raw_preempt_enable_no_resched() \
85306 +do { \
85307 + barrier(); \
85308 + raw_preempt_count_dec(); \
85309 +} while (0)
85310 +
85311 #ifdef CONFIG_PREEMPT
85312 #define preempt_enable() \
85313 do { \
85314 @@ -113,8 +130,10 @@ do { \
85315 * region.
85316 */
85317 #define preempt_disable() barrier()
85318 +#define raw_preempt_disable() barrier()
85319 #define sched_preempt_enable_no_resched() barrier()
85320 #define preempt_enable_no_resched() barrier()
85321 +#define raw_preempt_enable_no_resched() barrier()
85322 #define preempt_enable() barrier()
85323 #define preempt_check_resched() do { } while (0)
85324
85325 @@ -128,11 +147,13 @@ do { \
85326 /*
85327 * Modules have no business playing preemption tricks.
85328 */
85329 +#ifndef CONFIG_PAX_KERNEXEC
85330 #undef sched_preempt_enable_no_resched
85331 #undef preempt_enable_no_resched
85332 #undef preempt_enable_no_resched_notrace
85333 #undef preempt_check_resched
85334 #endif
85335 +#endif
85336
85337 #define preempt_set_need_resched() \
85338 do { \
85339 diff --git a/include/linux/printk.h b/include/linux/printk.h
85340 index 319ff7e..608849a 100644
85341 --- a/include/linux/printk.h
85342 +++ b/include/linux/printk.h
85343 @@ -121,6 +121,8 @@ static inline __printf(1, 2) __cold
85344 void early_printk(const char *s, ...) { }
85345 #endif
85346
85347 +extern int kptr_restrict;
85348 +
85349 #ifdef CONFIG_PRINTK
85350 asmlinkage __printf(5, 0)
85351 int vprintk_emit(int facility, int level,
85352 @@ -155,7 +157,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
85353
85354 extern int printk_delay_msec;
85355 extern int dmesg_restrict;
85356 -extern int kptr_restrict;
85357
85358 extern void wake_up_klogd(void);
85359
85360 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
85361 index 9d117f6..d832b31 100644
85362 --- a/include/linux/proc_fs.h
85363 +++ b/include/linux/proc_fs.h
85364 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
85365 extern struct proc_dir_entry *proc_symlink(const char *,
85366 struct proc_dir_entry *, const char *);
85367 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
85368 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
85369 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
85370 struct proc_dir_entry *, void *);
85371 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
85372 + struct proc_dir_entry *, void *);
85373 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
85374 struct proc_dir_entry *);
85375
85376 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
85377 return proc_create_data(name, mode, parent, proc_fops, NULL);
85378 }
85379
85380 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
85381 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
85382 +{
85383 +#ifdef CONFIG_GRKERNSEC_PROC_USER
85384 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
85385 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85386 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
85387 +#else
85388 + return proc_create_data(name, mode, parent, proc_fops, NULL);
85389 +#endif
85390 +}
85391 +
85392 +
85393 extern void proc_set_size(struct proc_dir_entry *, loff_t);
85394 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
85395 extern void *PDE_DATA(const struct inode *);
85396 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
85397 struct proc_dir_entry *parent,const char *dest) { return NULL;}
85398 static inline struct proc_dir_entry *proc_mkdir(const char *name,
85399 struct proc_dir_entry *parent) {return NULL;}
85400 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
85401 + struct proc_dir_entry *parent) { return NULL; }
85402 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
85403 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
85404 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
85405 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
85406 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
85407 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
85408 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
85409 @@ -77,7 +97,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
85410 static inline struct proc_dir_entry *proc_net_mkdir(
85411 struct net *net, const char *name, struct proc_dir_entry *parent)
85412 {
85413 - return proc_mkdir_data(name, 0, parent, net);
85414 + return proc_mkdir_data_restrict(name, 0, parent, net);
85415 }
85416
85417 #endif /* _LINUX_PROC_FS_H */
85418 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
85419 index 34a1e10..70f6bde 100644
85420 --- a/include/linux/proc_ns.h
85421 +++ b/include/linux/proc_ns.h
85422 @@ -14,7 +14,7 @@ struct proc_ns_operations {
85423 void (*put)(void *ns);
85424 int (*install)(struct nsproxy *nsproxy, void *ns);
85425 unsigned int (*inum)(void *ns);
85426 -};
85427 +} __do_const __randomize_layout;
85428
85429 struct proc_ns {
85430 void *ns;
85431 diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h
85432 index 7dfed71..1dc420b 100644
85433 --- a/include/linux/ptp_classify.h
85434 +++ b/include/linux/ptp_classify.h
85435 @@ -23,8 +23,15 @@
85436 #ifndef _PTP_CLASSIFY_H_
85437 #define _PTP_CLASSIFY_H_
85438
85439 +#include <linux/if_ether.h>
85440 +#include <linux/if_vlan.h>
85441 #include <linux/ip.h>
85442 -#include <linux/skbuff.h>
85443 +#include <linux/filter.h>
85444 +#ifdef __KERNEL__
85445 +#include <linux/in.h>
85446 +#else
85447 +#include <netinet/in.h>
85448 +#endif
85449
85450 #define PTP_CLASS_NONE 0x00 /* not a PTP event message */
85451 #define PTP_CLASS_V1 0x01 /* protocol version 1 */
85452 @@ -37,7 +44,7 @@
85453 #define PTP_CLASS_PMASK 0xf0 /* mask for the packet type field */
85454
85455 #define PTP_CLASS_V1_IPV4 (PTP_CLASS_V1 | PTP_CLASS_IPV4)
85456 -#define PTP_CLASS_V1_IPV6 (PTP_CLASS_V1 | PTP_CLASS_IPV6) /* probably DNE */
85457 +#define PTP_CLASS_V1_IPV6 (PTP_CLASS_V1 | PTP_CLASS_IPV6) /*probably DNE*/
85458 #define PTP_CLASS_V2_IPV4 (PTP_CLASS_V2 | PTP_CLASS_IPV4)
85459 #define PTP_CLASS_V2_IPV6 (PTP_CLASS_V2 | PTP_CLASS_IPV6)
85460 #define PTP_CLASS_V2_L2 (PTP_CLASS_V2 | PTP_CLASS_L2)
85461 @@ -46,34 +53,88 @@
85462 #define PTP_EV_PORT 319
85463 #define PTP_GEN_BIT 0x08 /* indicates general message, if set in message type */
85464
85465 +#define OFF_ETYPE 12
85466 +#define OFF_IHL 14
85467 +#define OFF_FRAG 20
85468 +#define OFF_PROTO4 23
85469 +#define OFF_NEXT 6
85470 +#define OFF_UDP_DST 2
85471 +
85472 #define OFF_PTP_SOURCE_UUID 22 /* PTPv1 only */
85473 #define OFF_PTP_SEQUENCE_ID 30
85474 #define OFF_PTP_CONTROL 32 /* PTPv1 only */
85475
85476 -/* Below defines should actually be removed at some point in time. */
85477 +#define IPV4_HLEN(data) (((struct iphdr *)(data + OFF_IHL))->ihl << 2)
85478 +
85479 #define IP6_HLEN 40
85480 #define UDP_HLEN 8
85481 -#define OFF_IHL 14
85482 +
85483 +#define RELOFF_DST4 (ETH_HLEN + OFF_UDP_DST)
85484 +#define OFF_DST6 (ETH_HLEN + IP6_HLEN + OFF_UDP_DST)
85485 #define OFF_PTP6 (ETH_HLEN + IP6_HLEN + UDP_HLEN)
85486 -#define IPV4_HLEN(data) (((struct iphdr *)(data + OFF_IHL))->ihl << 2)
85487
85488 -#if defined(CONFIG_NET_PTP_CLASSIFY)
85489 -/**
85490 - * ptp_classify_raw - classify a PTP packet
85491 - * @skb: buffer
85492 - *
85493 - * Runs a minimal BPF dissector to classify a network packet to
85494 - * determine the PTP class. In case the skb does not contain any
85495 - * PTP protocol data, PTP_CLASS_NONE will be returned, otherwise
85496 - * PTP_CLASS_V1_IPV{4,6}, PTP_CLASS_V2_IPV{4,6} or
85497 - * PTP_CLASS_V2_{L2,VLAN}, depending on the packet content.
85498 - */
85499 -unsigned int ptp_classify_raw(const struct sk_buff *skb);
85500 +#define OP_AND (BPF_ALU | BPF_AND | BPF_K)
85501 +#define OP_JEQ (BPF_JMP | BPF_JEQ | BPF_K)
85502 +#define OP_JSET (BPF_JMP | BPF_JSET | BPF_K)
85503 +#define OP_LDB (BPF_LD | BPF_B | BPF_ABS)
85504 +#define OP_LDH (BPF_LD | BPF_H | BPF_ABS)
85505 +#define OP_LDHI (BPF_LD | BPF_H | BPF_IND)
85506 +#define OP_LDX (BPF_LDX | BPF_B | BPF_MSH)
85507 +#define OP_OR (BPF_ALU | BPF_OR | BPF_K)
85508 +#define OP_RETA (BPF_RET | BPF_A)
85509 +#define OP_RETK (BPF_RET | BPF_K)
85510
85511 -void __init ptp_classifier_init(void);
85512 -#else
85513 -static inline void ptp_classifier_init(void)
85514 +static inline int ptp_filter_init(struct sock_filter *f, int len)
85515 {
85516 + if (OP_LDH == f[0].code)
85517 + return sk_chk_filter(f, len);
85518 + else
85519 + return 0;
85520 }
85521 +
85522 +#define PTP_FILTER \
85523 + {OP_LDH, 0, 0, OFF_ETYPE }, /* */ \
85524 + {OP_JEQ, 0, 12, ETH_P_IP }, /* f goto L20 */ \
85525 + {OP_LDB, 0, 0, OFF_PROTO4 }, /* */ \
85526 + {OP_JEQ, 0, 9, IPPROTO_UDP }, /* f goto L10 */ \
85527 + {OP_LDH, 0, 0, OFF_FRAG }, /* */ \
85528 + {OP_JSET, 7, 0, 0x1fff }, /* t goto L11 */ \
85529 + {OP_LDX, 0, 0, OFF_IHL }, /* */ \
85530 + {OP_LDHI, 0, 0, RELOFF_DST4 }, /* */ \
85531 + {OP_JEQ, 0, 4, PTP_EV_PORT }, /* f goto L12 */ \
85532 + {OP_LDHI, 0, 0, ETH_HLEN + UDP_HLEN }, /* */ \
85533 + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
85534 + {OP_OR, 0, 0, PTP_CLASS_IPV4 }, /* */ \
85535 + {OP_RETA, 0, 0, 0 }, /* */ \
85536 +/*L1x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, /* */ \
85537 +/*L20*/ {OP_JEQ, 0, 9, ETH_P_IPV6 }, /* f goto L40 */ \
85538 + {OP_LDB, 0, 0, ETH_HLEN + OFF_NEXT }, /* */ \
85539 + {OP_JEQ, 0, 6, IPPROTO_UDP }, /* f goto L30 */ \
85540 + {OP_LDH, 0, 0, OFF_DST6 }, /* */ \
85541 + {OP_JEQ, 0, 4, PTP_EV_PORT }, /* f goto L31 */ \
85542 + {OP_LDH, 0, 0, OFF_PTP6 }, /* */ \
85543 + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
85544 + {OP_OR, 0, 0, PTP_CLASS_IPV6 }, /* */ \
85545 + {OP_RETA, 0, 0, 0 }, /* */ \
85546 +/*L3x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, /* */ \
85547 +/*L40*/ {OP_JEQ, 0, 9, ETH_P_8021Q }, /* f goto L50 */ \
85548 + {OP_LDH, 0, 0, OFF_ETYPE + 4 }, /* */ \
85549 + {OP_JEQ, 0, 15, ETH_P_1588 }, /* f goto L60 */ \
85550 + {OP_LDB, 0, 0, ETH_HLEN + VLAN_HLEN }, /* */ \
85551 + {OP_AND, 0, 0, PTP_GEN_BIT }, /* */ \
85552 + {OP_JEQ, 0, 12, 0 }, /* f goto L6x */ \
85553 + {OP_LDH, 0, 0, ETH_HLEN + VLAN_HLEN }, /* */ \
85554 + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
85555 + {OP_OR, 0, 0, PTP_CLASS_VLAN }, /* */ \
85556 + {OP_RETA, 0, 0, 0 }, /* */ \
85557 +/*L50*/ {OP_JEQ, 0, 7, ETH_P_1588 }, /* f goto L61 */ \
85558 + {OP_LDB, 0, 0, ETH_HLEN }, /* */ \
85559 + {OP_AND, 0, 0, PTP_GEN_BIT }, /* */ \
85560 + {OP_JEQ, 0, 4, 0 }, /* f goto L6x */ \
85561 + {OP_LDH, 0, 0, ETH_HLEN }, /* */ \
85562 + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
85563 + {OP_OR, 0, 0, PTP_CLASS_L2 }, /* */ \
85564 + {OP_RETA, 0, 0, 0 }, /* */ \
85565 +/*L6x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE },
85566 +
85567 #endif
85568 -#endif /* _PTP_CLASSIFY_H_ */
85569 diff --git a/include/linux/quota.h b/include/linux/quota.h
85570 index 0f3c5d3..bc559e3 100644
85571 --- a/include/linux/quota.h
85572 +++ b/include/linux/quota.h
85573 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
85574
85575 extern bool qid_eq(struct kqid left, struct kqid right);
85576 extern bool qid_lt(struct kqid left, struct kqid right);
85577 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
85578 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
85579 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
85580 extern bool qid_valid(struct kqid qid);
85581
85582 diff --git a/include/linux/random.h b/include/linux/random.h
85583 index 57fbbff..2170304 100644
85584 --- a/include/linux/random.h
85585 +++ b/include/linux/random.h
85586 @@ -9,9 +9,19 @@
85587 #include <uapi/linux/random.h>
85588
85589 extern void add_device_randomness(const void *, unsigned int);
85590 +
85591 +static inline void add_latent_entropy(void)
85592 +{
85593 +
85594 +#ifdef LATENT_ENTROPY_PLUGIN
85595 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
85596 +#endif
85597 +
85598 +}
85599 +
85600 extern void add_input_randomness(unsigned int type, unsigned int code,
85601 - unsigned int value);
85602 -extern void add_interrupt_randomness(int irq, int irq_flags);
85603 + unsigned int value) __latent_entropy;
85604 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
85605
85606 extern void get_random_bytes(void *buf, int nbytes);
85607 extern void get_random_bytes_arch(void *buf, int nbytes);
85608 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
85609 extern const struct file_operations random_fops, urandom_fops;
85610 #endif
85611
85612 -unsigned int get_random_int(void);
85613 +unsigned int __intentional_overflow(-1) get_random_int(void);
85614 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
85615
85616 -u32 prandom_u32(void);
85617 +u32 prandom_u32(void) __intentional_overflow(-1);
85618 void prandom_bytes(void *buf, int nbytes);
85619 void prandom_seed(u32 seed);
85620 void prandom_reseed_late(void);
85621 @@ -37,6 +47,11 @@ struct rnd_state {
85622 u32 prandom_u32_state(struct rnd_state *state);
85623 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
85624
85625 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
85626 +{
85627 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
85628 +}
85629 +
85630 /**
85631 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
85632 * @ep_ro: right open interval endpoint
85633 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
85634 *
85635 * Returns: pseudo-random number in interval [0, ep_ro)
85636 */
85637 -static inline u32 prandom_u32_max(u32 ep_ro)
85638 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
85639 {
85640 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
85641 }
85642 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
85643 index fea49b5..2ac22bb 100644
85644 --- a/include/linux/rbtree_augmented.h
85645 +++ b/include/linux/rbtree_augmented.h
85646 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
85647 old->rbaugmented = rbcompute(old); \
85648 } \
85649 rbstatic const struct rb_augment_callbacks rbname = { \
85650 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
85651 + .propagate = rbname ## _propagate, \
85652 + .copy = rbname ## _copy, \
85653 + .rotate = rbname ## _rotate \
85654 };
85655
85656
85657 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
85658 index 8183b46..a388711 100644
85659 --- a/include/linux/rculist.h
85660 +++ b/include/linux/rculist.h
85661 @@ -29,8 +29,8 @@
85662 */
85663 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
85664 {
85665 - ACCESS_ONCE(list->next) = list;
85666 - ACCESS_ONCE(list->prev) = list;
85667 + ACCESS_ONCE_RW(list->next) = list;
85668 + ACCESS_ONCE_RW(list->prev) = list;
85669 }
85670
85671 /*
85672 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
85673 struct list_head *prev, struct list_head *next);
85674 #endif
85675
85676 +void __pax_list_add_rcu(struct list_head *new,
85677 + struct list_head *prev, struct list_head *next);
85678 +
85679 /**
85680 * list_add_rcu - add a new entry to rcu-protected list
85681 * @new: new entry to be added
85682 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
85683 __list_add_rcu(new, head, head->next);
85684 }
85685
85686 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
85687 +{
85688 + __pax_list_add_rcu(new, head, head->next);
85689 +}
85690 +
85691 /**
85692 * list_add_tail_rcu - add a new entry to rcu-protected list
85693 * @new: new entry to be added
85694 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
85695 __list_add_rcu(new, head->prev, head);
85696 }
85697
85698 +static inline void pax_list_add_tail_rcu(struct list_head *new,
85699 + struct list_head *head)
85700 +{
85701 + __pax_list_add_rcu(new, head->prev, head);
85702 +}
85703 +
85704 /**
85705 * list_del_rcu - deletes entry from list without re-initialization
85706 * @entry: the element to delete from the list.
85707 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
85708 entry->prev = LIST_POISON2;
85709 }
85710
85711 +extern void pax_list_del_rcu(struct list_head *entry);
85712 +
85713 /**
85714 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
85715 * @n: the element to delete from the hash list.
85716 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
85717 index 48bf152..d38b785 100644
85718 --- a/include/linux/reboot.h
85719 +++ b/include/linux/reboot.h
85720 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
85721 */
85722
85723 extern void migrate_to_reboot_cpu(void);
85724 -extern void machine_restart(char *cmd);
85725 -extern void machine_halt(void);
85726 -extern void machine_power_off(void);
85727 +extern void machine_restart(char *cmd) __noreturn;
85728 +extern void machine_halt(void) __noreturn;
85729 +extern void machine_power_off(void) __noreturn;
85730
85731 extern void machine_shutdown(void);
85732 struct pt_regs;
85733 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
85734 */
85735
85736 extern void kernel_restart_prepare(char *cmd);
85737 -extern void kernel_restart(char *cmd);
85738 -extern void kernel_halt(void);
85739 -extern void kernel_power_off(void);
85740 +extern void kernel_restart(char *cmd) __noreturn;
85741 +extern void kernel_halt(void) __noreturn;
85742 +extern void kernel_power_off(void) __noreturn;
85743
85744 extern int C_A_D; /* for sysctl */
85745 void ctrl_alt_del(void);
85746 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
85747 * Emergency restart, callable from an interrupt handler.
85748 */
85749
85750 -extern void emergency_restart(void);
85751 +extern void emergency_restart(void) __noreturn;
85752 #include <asm/emergency-restart.h>
85753
85754 #endif /* _LINUX_REBOOT_H */
85755 diff --git a/include/linux/regset.h b/include/linux/regset.h
85756 index 8e0c9fe..ac4d221 100644
85757 --- a/include/linux/regset.h
85758 +++ b/include/linux/regset.h
85759 @@ -161,7 +161,8 @@ struct user_regset {
85760 unsigned int align;
85761 unsigned int bias;
85762 unsigned int core_note_type;
85763 -};
85764 +} __do_const;
85765 +typedef struct user_regset __no_const user_regset_no_const;
85766
85767 /**
85768 * struct user_regset_view - available regsets
85769 diff --git a/include/linux/relay.h b/include/linux/relay.h
85770 index d7c8359..818daf5 100644
85771 --- a/include/linux/relay.h
85772 +++ b/include/linux/relay.h
85773 @@ -157,7 +157,7 @@ struct rchan_callbacks
85774 * The callback should return 0 if successful, negative if not.
85775 */
85776 int (*remove_buf_file)(struct dentry *dentry);
85777 -};
85778 +} __no_const;
85779
85780 /*
85781 * CONFIG_RELAY kernel API, kernel/relay.c
85782 diff --git a/include/linux/rio.h b/include/linux/rio.h
85783 index 6bda06f..bf39a9b 100644
85784 --- a/include/linux/rio.h
85785 +++ b/include/linux/rio.h
85786 @@ -358,7 +358,7 @@ struct rio_ops {
85787 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
85788 u64 rstart, u32 size, u32 flags);
85789 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
85790 -};
85791 +} __no_const;
85792
85793 #define RIO_RESOURCE_MEM 0x00000100
85794 #define RIO_RESOURCE_DOORBELL 0x00000200
85795 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
85796 index be57450..31cf65e 100644
85797 --- a/include/linux/rmap.h
85798 +++ b/include/linux/rmap.h
85799 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
85800 void anon_vma_init(void); /* create anon_vma_cachep */
85801 int anon_vma_prepare(struct vm_area_struct *);
85802 void unlink_anon_vmas(struct vm_area_struct *);
85803 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
85804 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
85805 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
85806 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
85807
85808 static inline void anon_vma_merge(struct vm_area_struct *vma,
85809 struct vm_area_struct *next)
85810 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
85811 index a964f72..b475afb 100644
85812 --- a/include/linux/scatterlist.h
85813 +++ b/include/linux/scatterlist.h
85814 @@ -1,6 +1,7 @@
85815 #ifndef _LINUX_SCATTERLIST_H
85816 #define _LINUX_SCATTERLIST_H
85817
85818 +#include <linux/sched.h>
85819 #include <linux/string.h>
85820 #include <linux/bug.h>
85821 #include <linux/mm.h>
85822 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
85823 #ifdef CONFIG_DEBUG_SG
85824 BUG_ON(!virt_addr_valid(buf));
85825 #endif
85826 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85827 + if (object_starts_on_stack(buf)) {
85828 + void *adjbuf = buf - current->stack + current->lowmem_stack;
85829 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
85830 + } else
85831 +#endif
85832 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
85833 }
85834
85835 diff --git a/include/linux/sched.h b/include/linux/sched.h
85836 index 0376b05..82054c2 100644
85837 --- a/include/linux/sched.h
85838 +++ b/include/linux/sched.h
85839 @@ -131,6 +131,7 @@ struct fs_struct;
85840 struct perf_event_context;
85841 struct blk_plug;
85842 struct filename;
85843 +struct linux_binprm;
85844
85845 #define VMACACHE_BITS 2
85846 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
85847 @@ -374,7 +375,7 @@ extern char __sched_text_start[], __sched_text_end[];
85848 extern int in_sched_functions(unsigned long addr);
85849
85850 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
85851 -extern signed long schedule_timeout(signed long timeout);
85852 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
85853 extern signed long schedule_timeout_interruptible(signed long timeout);
85854 extern signed long schedule_timeout_killable(signed long timeout);
85855 extern signed long schedule_timeout_uninterruptible(signed long timeout);
85856 @@ -385,6 +386,19 @@ struct nsproxy;
85857 struct user_namespace;
85858
85859 #ifdef CONFIG_MMU
85860 +
85861 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
85862 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
85863 +#else
85864 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
85865 +{
85866 + return 0;
85867 +}
85868 +#endif
85869 +
85870 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
85871 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
85872 +
85873 extern void arch_pick_mmap_layout(struct mm_struct *mm);
85874 extern unsigned long
85875 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
85876 @@ -682,6 +696,17 @@ struct signal_struct {
85877 #ifdef CONFIG_TASKSTATS
85878 struct taskstats *stats;
85879 #endif
85880 +
85881 +#ifdef CONFIG_GRKERNSEC
85882 + u32 curr_ip;
85883 + u32 saved_ip;
85884 + u32 gr_saddr;
85885 + u32 gr_daddr;
85886 + u16 gr_sport;
85887 + u16 gr_dport;
85888 + u8 used_accept:1;
85889 +#endif
85890 +
85891 #ifdef CONFIG_AUDIT
85892 unsigned audit_tty;
85893 unsigned audit_tty_log_passwd;
85894 @@ -708,7 +733,7 @@ struct signal_struct {
85895 struct mutex cred_guard_mutex; /* guard against foreign influences on
85896 * credential calculations
85897 * (notably. ptrace) */
85898 -};
85899 +} __randomize_layout;
85900
85901 /*
85902 * Bits in flags field of signal_struct.
85903 @@ -761,6 +786,14 @@ struct user_struct {
85904 struct key *session_keyring; /* UID's default session keyring */
85905 #endif
85906
85907 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
85908 + unsigned char kernel_banned;
85909 +#endif
85910 +#ifdef CONFIG_GRKERNSEC_BRUTE
85911 + unsigned char suid_banned;
85912 + unsigned long suid_ban_expires;
85913 +#endif
85914 +
85915 /* Hash table maintenance information */
85916 struct hlist_node uidhash_node;
85917 kuid_t uid;
85918 @@ -768,7 +801,7 @@ struct user_struct {
85919 #ifdef CONFIG_PERF_EVENTS
85920 atomic_long_t locked_vm;
85921 #endif
85922 -};
85923 +} __randomize_layout;
85924
85925 extern int uids_sysfs_init(void);
85926
85927 @@ -1224,6 +1257,9 @@ enum perf_event_task_context {
85928 struct task_struct {
85929 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
85930 void *stack;
85931 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85932 + void *lowmem_stack;
85933 +#endif
85934 atomic_t usage;
85935 unsigned int flags; /* per process flags, defined below */
85936 unsigned int ptrace;
85937 @@ -1349,8 +1385,8 @@ struct task_struct {
85938 struct list_head thread_node;
85939
85940 struct completion *vfork_done; /* for vfork() */
85941 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
85942 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85943 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
85944 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85945
85946 cputime_t utime, stime, utimescaled, stimescaled;
85947 cputime_t gtime;
85948 @@ -1375,11 +1411,6 @@ struct task_struct {
85949 struct task_cputime cputime_expires;
85950 struct list_head cpu_timers[3];
85951
85952 -/* process credentials */
85953 - const struct cred __rcu *real_cred; /* objective and real subjective task
85954 - * credentials (COW) */
85955 - const struct cred __rcu *cred; /* effective (overridable) subjective task
85956 - * credentials (COW) */
85957 char comm[TASK_COMM_LEN]; /* executable name excluding path
85958 - access with [gs]et_task_comm (which lock
85959 it with task_lock())
85960 @@ -1396,6 +1427,10 @@ struct task_struct {
85961 #endif
85962 /* CPU-specific state of this task */
85963 struct thread_struct thread;
85964 +/* thread_info moved to task_struct */
85965 +#ifdef CONFIG_X86
85966 + struct thread_info tinfo;
85967 +#endif
85968 /* filesystem information */
85969 struct fs_struct *fs;
85970 /* open file information */
85971 @@ -1472,6 +1507,10 @@ struct task_struct {
85972 gfp_t lockdep_reclaim_gfp;
85973 #endif
85974
85975 +/* process credentials */
85976 + const struct cred __rcu *real_cred; /* objective and real subjective task
85977 + * credentials (COW) */
85978 +
85979 /* journalling filesystem info */
85980 void *journal_info;
85981
85982 @@ -1510,6 +1549,10 @@ struct task_struct {
85983 /* cg_list protected by css_set_lock and tsk->alloc_lock */
85984 struct list_head cg_list;
85985 #endif
85986 +
85987 + const struct cred __rcu *cred; /* effective (overridable) subjective task
85988 + * credentials (COW) */
85989 +
85990 #ifdef CONFIG_FUTEX
85991 struct robust_list_head __user *robust_list;
85992 #ifdef CONFIG_COMPAT
85993 @@ -1655,7 +1698,78 @@ struct task_struct {
85994 unsigned int sequential_io;
85995 unsigned int sequential_io_avg;
85996 #endif
85997 -};
85998 +
85999 +#ifdef CONFIG_GRKERNSEC
86000 + /* grsecurity */
86001 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
86002 + u64 exec_id;
86003 +#endif
86004 +#ifdef CONFIG_GRKERNSEC_SETXID
86005 + const struct cred *delayed_cred;
86006 +#endif
86007 + struct dentry *gr_chroot_dentry;
86008 + struct acl_subject_label *acl;
86009 + struct acl_subject_label *tmpacl;
86010 + struct acl_role_label *role;
86011 + struct file *exec_file;
86012 + unsigned long brute_expires;
86013 + u16 acl_role_id;
86014 + u8 inherited;
86015 + /* is this the task that authenticated to the special role */
86016 + u8 acl_sp_role;
86017 + u8 is_writable;
86018 + u8 brute;
86019 + u8 gr_is_chrooted;
86020 +#endif
86021 +
86022 +} __randomize_layout;
86023 +
86024 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
86025 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
86026 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
86027 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
86028 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
86029 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
86030 +
86031 +#ifdef CONFIG_PAX_SOFTMODE
86032 +extern int pax_softmode;
86033 +#endif
86034 +
86035 +extern int pax_check_flags(unsigned long *);
86036 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
86037 +
86038 +/* if tsk != current then task_lock must be held on it */
86039 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
86040 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
86041 +{
86042 + if (likely(tsk->mm))
86043 + return tsk->mm->pax_flags;
86044 + else
86045 + return 0UL;
86046 +}
86047 +
86048 +/* if tsk != current then task_lock must be held on it */
86049 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
86050 +{
86051 + if (likely(tsk->mm)) {
86052 + tsk->mm->pax_flags = flags;
86053 + return 0;
86054 + }
86055 + return -EINVAL;
86056 +}
86057 +#endif
86058 +
86059 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
86060 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
86061 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
86062 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
86063 +#endif
86064 +
86065 +struct path;
86066 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
86067 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
86068 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
86069 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
86070
86071 /* Future-safe accessor for struct task_struct's cpus_allowed. */
86072 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
86073 @@ -1737,7 +1851,7 @@ struct pid_namespace;
86074 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
86075 struct pid_namespace *ns);
86076
86077 -static inline pid_t task_pid_nr(struct task_struct *tsk)
86078 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
86079 {
86080 return tsk->pid;
86081 }
86082 @@ -2084,6 +2198,25 @@ extern u64 sched_clock_cpu(int cpu);
86083
86084 extern void sched_clock_init(void);
86085
86086 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86087 +static inline void populate_stack(void)
86088 +{
86089 + struct task_struct *curtask = current;
86090 + int c;
86091 + int *ptr = curtask->stack;
86092 + int *end = curtask->stack + THREAD_SIZE;
86093 +
86094 + while (ptr < end) {
86095 + c = *(volatile int *)ptr;
86096 + ptr += PAGE_SIZE/sizeof(int);
86097 + }
86098 +}
86099 +#else
86100 +static inline void populate_stack(void)
86101 +{
86102 +}
86103 +#endif
86104 +
86105 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
86106 static inline void sched_clock_tick(void)
86107 {
86108 @@ -2217,7 +2350,9 @@ void yield(void);
86109 extern struct exec_domain default_exec_domain;
86110
86111 union thread_union {
86112 +#ifndef CONFIG_X86
86113 struct thread_info thread_info;
86114 +#endif
86115 unsigned long stack[THREAD_SIZE/sizeof(long)];
86116 };
86117
86118 @@ -2250,6 +2385,7 @@ extern struct pid_namespace init_pid_ns;
86119 */
86120
86121 extern struct task_struct *find_task_by_vpid(pid_t nr);
86122 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
86123 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
86124 struct pid_namespace *ns);
86125
86126 @@ -2412,7 +2548,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
86127 extern void exit_itimers(struct signal_struct *);
86128 extern void flush_itimer_signals(void);
86129
86130 -extern void do_group_exit(int);
86131 +extern __noreturn void do_group_exit(int);
86132
86133 extern int do_execve(struct filename *,
86134 const char __user * const __user *,
86135 @@ -2614,9 +2750,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
86136
86137 #endif
86138
86139 -static inline int object_is_on_stack(void *obj)
86140 +static inline int object_starts_on_stack(const void *obj)
86141 {
86142 - void *stack = task_stack_page(current);
86143 + const void *stack = task_stack_page(current);
86144
86145 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
86146 }
86147 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
86148 index 596a0e0..bea77ec 100644
86149 --- a/include/linux/sched/sysctl.h
86150 +++ b/include/linux/sched/sysctl.h
86151 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
86152 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
86153
86154 extern int sysctl_max_map_count;
86155 +extern unsigned long sysctl_heap_stack_gap;
86156
86157 extern unsigned int sysctl_sched_latency;
86158 extern unsigned int sysctl_sched_min_granularity;
86159 diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h
86160 index 4054b09..6f19cfd 100644
86161 --- a/include/linux/seccomp.h
86162 +++ b/include/linux/seccomp.h
86163 @@ -76,6 +76,7 @@ static inline int seccomp_mode(struct seccomp *s)
86164 #ifdef CONFIG_SECCOMP_FILTER
86165 extern void put_seccomp_filter(struct task_struct *tsk);
86166 extern void get_seccomp_filter(struct task_struct *tsk);
86167 +extern u32 seccomp_bpf_load(int off);
86168 #else /* CONFIG_SECCOMP_FILTER */
86169 static inline void put_seccomp_filter(struct task_struct *tsk)
86170 {
86171 diff --git a/include/linux/security.h b/include/linux/security.h
86172 index 9c6b972..7e7c704 100644
86173 --- a/include/linux/security.h
86174 +++ b/include/linux/security.h
86175 @@ -27,6 +27,7 @@
86176 #include <linux/slab.h>
86177 #include <linux/err.h>
86178 #include <linux/string.h>
86179 +#include <linux/grsecurity.h>
86180
86181 struct linux_binprm;
86182 struct cred;
86183 @@ -116,8 +117,6 @@ struct seq_file;
86184
86185 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
86186
86187 -void reset_security_ops(void);
86188 -
86189 #ifdef CONFIG_MMU
86190 extern unsigned long mmap_min_addr;
86191 extern unsigned long dac_mmap_min_addr;
86192 @@ -1719,7 +1718,7 @@ struct security_operations {
86193 struct audit_context *actx);
86194 void (*audit_rule_free) (void *lsmrule);
86195 #endif /* CONFIG_AUDIT */
86196 -};
86197 +} __randomize_layout;
86198
86199 /* prototypes */
86200 extern int security_init(void);
86201 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
86202 index dc368b8..e895209 100644
86203 --- a/include/linux/semaphore.h
86204 +++ b/include/linux/semaphore.h
86205 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
86206 }
86207
86208 extern void down(struct semaphore *sem);
86209 -extern int __must_check down_interruptible(struct semaphore *sem);
86210 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
86211 extern int __must_check down_killable(struct semaphore *sem);
86212 extern int __must_check down_trylock(struct semaphore *sem);
86213 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
86214 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
86215 index 52e0097..383f21d 100644
86216 --- a/include/linux/seq_file.h
86217 +++ b/include/linux/seq_file.h
86218 @@ -27,6 +27,9 @@ struct seq_file {
86219 struct mutex lock;
86220 const struct seq_operations *op;
86221 int poll_event;
86222 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
86223 + u64 exec_id;
86224 +#endif
86225 #ifdef CONFIG_USER_NS
86226 struct user_namespace *user_ns;
86227 #endif
86228 @@ -39,6 +42,7 @@ struct seq_operations {
86229 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
86230 int (*show) (struct seq_file *m, void *v);
86231 };
86232 +typedef struct seq_operations __no_const seq_operations_no_const;
86233
86234 #define SEQ_SKIP 1
86235
86236 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
86237
86238 char *mangle_path(char *s, const char *p, const char *esc);
86239 int seq_open(struct file *, const struct seq_operations *);
86240 +int seq_open_restrict(struct file *, const struct seq_operations *);
86241 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
86242 loff_t seq_lseek(struct file *, loff_t, int);
86243 int seq_release(struct inode *, struct file *);
86244 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
86245 }
86246
86247 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
86248 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
86249 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
86250 int single_release(struct inode *, struct file *);
86251 void *__seq_open_private(struct file *, const struct seq_operations *, int);
86252 diff --git a/include/linux/shm.h b/include/linux/shm.h
86253 index 57d7770..0936af6 100644
86254 --- a/include/linux/shm.h
86255 +++ b/include/linux/shm.h
86256 @@ -20,6 +20,10 @@ struct shmid_kernel /* private to the kernel */
86257
86258 /* The task created the shm object. NULL if the task is dead. */
86259 struct task_struct *shm_creator;
86260 +#ifdef CONFIG_GRKERNSEC
86261 + time_t shm_createtime;
86262 + pid_t shm_lapid;
86263 +#endif
86264 };
86265
86266 /* shm_mode upper byte flags */
86267 diff --git a/include/linux/signal.h b/include/linux/signal.h
86268 index c9e6536..923b302 100644
86269 --- a/include/linux/signal.h
86270 +++ b/include/linux/signal.h
86271 @@ -293,7 +293,7 @@ static inline void allow_signal(int sig)
86272 * know it'll be handled, so that they don't get converted to
86273 * SIGKILL or just silently dropped.
86274 */
86275 - kernel_sigaction(sig, (__force __sighandler_t)2);
86276 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
86277 }
86278
86279 static inline void disallow_signal(int sig)
86280 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
86281 index ec89301..4fd29a6 100644
86282 --- a/include/linux/skbuff.h
86283 +++ b/include/linux/skbuff.h
86284 @@ -725,7 +725,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
86285 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
86286 int node);
86287 struct sk_buff *build_skb(void *data, unsigned int frag_size);
86288 -static inline struct sk_buff *alloc_skb(unsigned int size,
86289 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
86290 gfp_t priority)
86291 {
86292 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
86293 @@ -1839,7 +1839,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
86294 return skb->inner_transport_header - skb->inner_network_header;
86295 }
86296
86297 -static inline int skb_network_offset(const struct sk_buff *skb)
86298 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
86299 {
86300 return skb_network_header(skb) - skb->data;
86301 }
86302 @@ -1911,7 +1911,7 @@ static inline void skb_pop_rcv_encapsulation(struct sk_buff *skb)
86303 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
86304 */
86305 #ifndef NET_SKB_PAD
86306 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
86307 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
86308 #endif
86309
86310 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
86311 @@ -2518,7 +2518,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
86312 int *err);
86313 unsigned int datagram_poll(struct file *file, struct socket *sock,
86314 struct poll_table_struct *wait);
86315 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
86316 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
86317 struct iovec *to, int size);
86318 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
86319 struct iovec *iov);
86320 @@ -2664,6 +2664,8 @@ static inline ktime_t net_invalid_timestamp(void)
86321 return ktime_set(0, 0);
86322 }
86323
86324 +void skb_timestamping_init(void);
86325 +
86326 #ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
86327
86328 void skb_clone_tx_timestamp(struct sk_buff *skb);
86329 @@ -2907,6 +2909,9 @@ static inline void nf_reset(struct sk_buff *skb)
86330 nf_bridge_put(skb->nf_bridge);
86331 skb->nf_bridge = NULL;
86332 #endif
86333 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
86334 + skb->nf_trace = 0;
86335 +#endif
86336 }
86337
86338 static inline void nf_reset_trace(struct sk_buff *skb)
86339 diff --git a/include/linux/slab.h b/include/linux/slab.h
86340 index 1d9abb7..b1e8b10 100644
86341 --- a/include/linux/slab.h
86342 +++ b/include/linux/slab.h
86343 @@ -14,15 +14,29 @@
86344 #include <linux/gfp.h>
86345 #include <linux/types.h>
86346 #include <linux/workqueue.h>
86347 -
86348 +#include <linux/err.h>
86349
86350 /*
86351 * Flags to pass to kmem_cache_create().
86352 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
86353 */
86354 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
86355 +
86356 +#ifdef CONFIG_PAX_USERCOPY_SLABS
86357 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
86358 +#else
86359 +#define SLAB_USERCOPY 0x00000000UL
86360 +#endif
86361 +
86362 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
86363 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
86364 +
86365 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
86366 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
86367 +#else
86368 +#define SLAB_NO_SANITIZE 0x00000000UL
86369 +#endif
86370 +
86371 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
86372 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
86373 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
86374 @@ -98,10 +112,13 @@
86375 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
86376 * Both make kfree a no-op.
86377 */
86378 -#define ZERO_SIZE_PTR ((void *)16)
86379 +#define ZERO_SIZE_PTR \
86380 +({ \
86381 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
86382 + (void *)(-MAX_ERRNO-1L); \
86383 +})
86384
86385 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
86386 - (unsigned long)ZERO_SIZE_PTR)
86387 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
86388
86389 #include <linux/kmemleak.h>
86390
86391 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
86392 void kfree(const void *);
86393 void kzfree(const void *);
86394 size_t ksize(const void *);
86395 +const char *check_heap_object(const void *ptr, unsigned long n);
86396 +bool is_usercopy_object(const void *ptr);
86397
86398 /*
86399 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
86400 @@ -176,7 +195,7 @@ struct kmem_cache {
86401 unsigned int align; /* Alignment as calculated */
86402 unsigned long flags; /* Active flags on the slab */
86403 const char *name; /* Slab name for sysfs */
86404 - int refcount; /* Use counter */
86405 + atomic_t refcount; /* Use counter */
86406 void (*ctor)(void *); /* Called on object slot creation */
86407 struct list_head list; /* List of all slab caches on the system */
86408 };
86409 @@ -261,6 +280,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
86410 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
86411 #endif
86412
86413 +#ifdef CONFIG_PAX_USERCOPY_SLABS
86414 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
86415 +#endif
86416 +
86417 /*
86418 * Figure out which kmalloc slab an allocation of a certain size
86419 * belongs to.
86420 @@ -269,7 +292,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
86421 * 2 = 120 .. 192 bytes
86422 * n = 2^(n-1) .. 2^n -1
86423 */
86424 -static __always_inline int kmalloc_index(size_t size)
86425 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
86426 {
86427 if (!size)
86428 return 0;
86429 @@ -312,11 +335,11 @@ static __always_inline int kmalloc_index(size_t size)
86430 }
86431 #endif /* !CONFIG_SLOB */
86432
86433 -void *__kmalloc(size_t size, gfp_t flags);
86434 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
86435 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
86436
86437 #ifdef CONFIG_NUMA
86438 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
86439 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
86440 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
86441 #else
86442 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
86443 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
86444 index 8235dfb..47ce586 100644
86445 --- a/include/linux/slab_def.h
86446 +++ b/include/linux/slab_def.h
86447 @@ -38,7 +38,7 @@ struct kmem_cache {
86448 /* 4) cache creation/removal */
86449 const char *name;
86450 struct list_head list;
86451 - int refcount;
86452 + atomic_t refcount;
86453 int object_size;
86454 int align;
86455
86456 @@ -54,10 +54,14 @@ struct kmem_cache {
86457 unsigned long node_allocs;
86458 unsigned long node_frees;
86459 unsigned long node_overflow;
86460 - atomic_t allochit;
86461 - atomic_t allocmiss;
86462 - atomic_t freehit;
86463 - atomic_t freemiss;
86464 + atomic_unchecked_t allochit;
86465 + atomic_unchecked_t allocmiss;
86466 + atomic_unchecked_t freehit;
86467 + atomic_unchecked_t freemiss;
86468 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
86469 + atomic_unchecked_t sanitized;
86470 + atomic_unchecked_t not_sanitized;
86471 +#endif
86472
86473 /*
86474 * If debugging is enabled, then the allocator can add additional
86475 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
86476 index d82abd4..408c3a0 100644
86477 --- a/include/linux/slub_def.h
86478 +++ b/include/linux/slub_def.h
86479 @@ -74,7 +74,7 @@ struct kmem_cache {
86480 struct kmem_cache_order_objects max;
86481 struct kmem_cache_order_objects min;
86482 gfp_t allocflags; /* gfp flags to use on each alloc */
86483 - int refcount; /* Refcount for slab cache destroy */
86484 + atomic_t refcount; /* Refcount for slab cache destroy */
86485 void (*ctor)(void *);
86486 int inuse; /* Offset to metadata */
86487 int align; /* Alignment */
86488 diff --git a/include/linux/smp.h b/include/linux/smp.h
86489 index 34347f2..8739978 100644
86490 --- a/include/linux/smp.h
86491 +++ b/include/linux/smp.h
86492 @@ -174,7 +174,9 @@ static inline void kick_all_cpus_sync(void) { }
86493 #endif
86494
86495 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
86496 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
86497 #define put_cpu() preempt_enable()
86498 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
86499
86500 /*
86501 * Callback to arch code if there's nosmp or maxcpus=0 on the
86502 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
86503 index 46cca4c..3323536 100644
86504 --- a/include/linux/sock_diag.h
86505 +++ b/include/linux/sock_diag.h
86506 @@ -11,7 +11,7 @@ struct sock;
86507 struct sock_diag_handler {
86508 __u8 family;
86509 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
86510 -};
86511 +} __do_const;
86512
86513 int sock_diag_register(const struct sock_diag_handler *h);
86514 void sock_diag_unregister(const struct sock_diag_handler *h);
86515 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
86516 index 680f9a3..f13aeb0 100644
86517 --- a/include/linux/sonet.h
86518 +++ b/include/linux/sonet.h
86519 @@ -7,7 +7,7 @@
86520 #include <uapi/linux/sonet.h>
86521
86522 struct k_sonet_stats {
86523 -#define __HANDLE_ITEM(i) atomic_t i
86524 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
86525 __SONET_ITEMS
86526 #undef __HANDLE_ITEM
86527 };
86528 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
86529 index 07d8e53..dc934c9 100644
86530 --- a/include/linux/sunrpc/addr.h
86531 +++ b/include/linux/sunrpc/addr.h
86532 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
86533 {
86534 switch (sap->sa_family) {
86535 case AF_INET:
86536 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
86537 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
86538 case AF_INET6:
86539 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
86540 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
86541 }
86542 return 0;
86543 }
86544 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
86545 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
86546 const struct sockaddr *src)
86547 {
86548 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
86549 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
86550 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
86551
86552 dsin->sin_family = ssin->sin_family;
86553 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
86554 if (sa->sa_family != AF_INET6)
86555 return 0;
86556
86557 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
86558 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
86559 }
86560
86561 #endif /* _LINUX_SUNRPC_ADDR_H */
86562 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
86563 index 70736b9..37f33db 100644
86564 --- a/include/linux/sunrpc/clnt.h
86565 +++ b/include/linux/sunrpc/clnt.h
86566 @@ -97,7 +97,7 @@ struct rpc_procinfo {
86567 unsigned int p_timer; /* Which RTT timer to use */
86568 u32 p_statidx; /* Which procedure to account */
86569 const char * p_name; /* name of procedure */
86570 -};
86571 +} __do_const;
86572
86573 #ifdef __KERNEL__
86574
86575 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
86576 index 1bc7cd0..7912dc2 100644
86577 --- a/include/linux/sunrpc/svc.h
86578 +++ b/include/linux/sunrpc/svc.h
86579 @@ -417,7 +417,7 @@ struct svc_procedure {
86580 unsigned int pc_count; /* call count */
86581 unsigned int pc_cachetype; /* cache info (NFS) */
86582 unsigned int pc_xdrressize; /* maximum size of XDR reply */
86583 -};
86584 +} __do_const;
86585
86586 /*
86587 * Function prototypes.
86588 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
86589 index 5cf99a0..c0a1b98 100644
86590 --- a/include/linux/sunrpc/svc_rdma.h
86591 +++ b/include/linux/sunrpc/svc_rdma.h
86592 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
86593 extern unsigned int svcrdma_max_requests;
86594 extern unsigned int svcrdma_max_req_size;
86595
86596 -extern atomic_t rdma_stat_recv;
86597 -extern atomic_t rdma_stat_read;
86598 -extern atomic_t rdma_stat_write;
86599 -extern atomic_t rdma_stat_sq_starve;
86600 -extern atomic_t rdma_stat_rq_starve;
86601 -extern atomic_t rdma_stat_rq_poll;
86602 -extern atomic_t rdma_stat_rq_prod;
86603 -extern atomic_t rdma_stat_sq_poll;
86604 -extern atomic_t rdma_stat_sq_prod;
86605 +extern atomic_unchecked_t rdma_stat_recv;
86606 +extern atomic_unchecked_t rdma_stat_read;
86607 +extern atomic_unchecked_t rdma_stat_write;
86608 +extern atomic_unchecked_t rdma_stat_sq_starve;
86609 +extern atomic_unchecked_t rdma_stat_rq_starve;
86610 +extern atomic_unchecked_t rdma_stat_rq_poll;
86611 +extern atomic_unchecked_t rdma_stat_rq_prod;
86612 +extern atomic_unchecked_t rdma_stat_sq_poll;
86613 +extern atomic_unchecked_t rdma_stat_sq_prod;
86614
86615 #define RPCRDMA_VERSION 1
86616
86617 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
86618 index 8d71d65..f79586e 100644
86619 --- a/include/linux/sunrpc/svcauth.h
86620 +++ b/include/linux/sunrpc/svcauth.h
86621 @@ -120,7 +120,7 @@ struct auth_ops {
86622 int (*release)(struct svc_rqst *rq);
86623 void (*domain_release)(struct auth_domain *);
86624 int (*set_client)(struct svc_rqst *rq);
86625 -};
86626 +} __do_const;
86627
86628 #define SVC_GARBAGE 1
86629 #define SVC_SYSERR 2
86630 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
86631 index e7a018e..49f8b17 100644
86632 --- a/include/linux/swiotlb.h
86633 +++ b/include/linux/swiotlb.h
86634 @@ -60,7 +60,8 @@ extern void
86635
86636 extern void
86637 swiotlb_free_coherent(struct device *hwdev, size_t size,
86638 - void *vaddr, dma_addr_t dma_handle);
86639 + void *vaddr, dma_addr_t dma_handle,
86640 + struct dma_attrs *attrs);
86641
86642 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
86643 unsigned long offset, size_t size,
86644 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
86645 index b0881a0..559a440 100644
86646 --- a/include/linux/syscalls.h
86647 +++ b/include/linux/syscalls.h
86648 @@ -98,10 +98,16 @@ struct sigaltstack;
86649 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
86650
86651 #define __SC_DECL(t, a) t a
86652 +#define __TYPE_IS_U(t) (__same_type((t)0, 0UL) || __same_type((t)0, 0U) || __same_type((t)0, (unsigned short)0) || __same_type((t)0, (unsigned char)0))
86653 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
86654 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
86655 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
86656 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
86657 +#define __SC_LONG(t, a) __typeof( \
86658 + __builtin_choose_expr( \
86659 + sizeof(t) > sizeof(int), \
86660 + (t) 0, \
86661 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
86662 + )) a
86663 #define __SC_CAST(t, a) (t) a
86664 #define __SC_ARGS(t, a) a
86665 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
86666 @@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
86667 asmlinkage long sys_fsync(unsigned int fd);
86668 asmlinkage long sys_fdatasync(unsigned int fd);
86669 asmlinkage long sys_bdflush(int func, long data);
86670 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
86671 - char __user *type, unsigned long flags,
86672 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
86673 + const char __user *type, unsigned long flags,
86674 void __user *data);
86675 -asmlinkage long sys_umount(char __user *name, int flags);
86676 -asmlinkage long sys_oldumount(char __user *name);
86677 +asmlinkage long sys_umount(const char __user *name, int flags);
86678 +asmlinkage long sys_oldumount(const char __user *name);
86679 asmlinkage long sys_truncate(const char __user *path, long length);
86680 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
86681 asmlinkage long sys_stat(const char __user *filename,
86682 @@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
86683 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
86684 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
86685 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
86686 - struct sockaddr __user *, int);
86687 + struct sockaddr __user *, int) __intentional_overflow(0);
86688 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
86689 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
86690 unsigned int vlen, unsigned flags);
86691 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
86692 index 27b3b0b..e093dd9 100644
86693 --- a/include/linux/syscore_ops.h
86694 +++ b/include/linux/syscore_ops.h
86695 @@ -16,7 +16,7 @@ struct syscore_ops {
86696 int (*suspend)(void);
86697 void (*resume)(void);
86698 void (*shutdown)(void);
86699 -};
86700 +} __do_const;
86701
86702 extern void register_syscore_ops(struct syscore_ops *ops);
86703 extern void unregister_syscore_ops(struct syscore_ops *ops);
86704 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
86705 index 14a8ff2..fa95f3a 100644
86706 --- a/include/linux/sysctl.h
86707 +++ b/include/linux/sysctl.h
86708 @@ -34,13 +34,13 @@ struct ctl_table_root;
86709 struct ctl_table_header;
86710 struct ctl_dir;
86711
86712 -typedef struct ctl_table ctl_table;
86713 -
86714 typedef int proc_handler (struct ctl_table *ctl, int write,
86715 void __user *buffer, size_t *lenp, loff_t *ppos);
86716
86717 extern int proc_dostring(struct ctl_table *, int,
86718 void __user *, size_t *, loff_t *);
86719 +extern int proc_dostring_modpriv(struct ctl_table *, int,
86720 + void __user *, size_t *, loff_t *);
86721 extern int proc_dointvec(struct ctl_table *, int,
86722 void __user *, size_t *, loff_t *);
86723 extern int proc_dointvec_minmax(struct ctl_table *, int,
86724 @@ -115,7 +115,9 @@ struct ctl_table
86725 struct ctl_table_poll *poll;
86726 void *extra1;
86727 void *extra2;
86728 -};
86729 +} __do_const __randomize_layout;
86730 +typedef struct ctl_table __no_const ctl_table_no_const;
86731 +typedef struct ctl_table ctl_table;
86732
86733 struct ctl_node {
86734 struct rb_node node;
86735 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
86736 index f97d0db..c1187dc 100644
86737 --- a/include/linux/sysfs.h
86738 +++ b/include/linux/sysfs.h
86739 @@ -34,7 +34,8 @@ struct attribute {
86740 struct lock_class_key *key;
86741 struct lock_class_key skey;
86742 #endif
86743 -};
86744 +} __do_const;
86745 +typedef struct attribute __no_const attribute_no_const;
86746
86747 /**
86748 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
86749 @@ -63,7 +64,8 @@ struct attribute_group {
86750 struct attribute *, int);
86751 struct attribute **attrs;
86752 struct bin_attribute **bin_attrs;
86753 -};
86754 +} __do_const;
86755 +typedef struct attribute_group __no_const attribute_group_no_const;
86756
86757 /**
86758 * Use these macros to make defining attributes easier. See include/linux/device.h
86759 @@ -128,7 +130,8 @@ struct bin_attribute {
86760 char *, loff_t, size_t);
86761 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
86762 struct vm_area_struct *vma);
86763 -};
86764 +} __do_const;
86765 +typedef struct bin_attribute __no_const bin_attribute_no_const;
86766
86767 /**
86768 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
86769 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
86770 index 387fa7d..3fcde6b 100644
86771 --- a/include/linux/sysrq.h
86772 +++ b/include/linux/sysrq.h
86773 @@ -16,6 +16,7 @@
86774
86775 #include <linux/errno.h>
86776 #include <linux/types.h>
86777 +#include <linux/compiler.h>
86778
86779 /* Possible values of bitmask for enabling sysrq functions */
86780 /* 0x0001 is reserved for enable everything */
86781 @@ -33,7 +34,7 @@ struct sysrq_key_op {
86782 char *help_msg;
86783 char *action_msg;
86784 int enable_mask;
86785 -};
86786 +} __do_const;
86787
86788 #ifdef CONFIG_MAGIC_SYSRQ
86789
86790 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
86791 index ff307b5..f1a4468 100644
86792 --- a/include/linux/thread_info.h
86793 +++ b/include/linux/thread_info.h
86794 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
86795 #error "no set_restore_sigmask() provided and default one won't work"
86796 #endif
86797
86798 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
86799 +
86800 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
86801 +{
86802 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
86803 +}
86804 +
86805 #endif /* __KERNEL__ */
86806
86807 #endif /* _LINUX_THREAD_INFO_H */
86808 diff --git a/include/linux/tty.h b/include/linux/tty.h
86809 index 1c3316a..ae83b9f 100644
86810 --- a/include/linux/tty.h
86811 +++ b/include/linux/tty.h
86812 @@ -202,7 +202,7 @@ struct tty_port {
86813 const struct tty_port_operations *ops; /* Port operations */
86814 spinlock_t lock; /* Lock protecting tty field */
86815 int blocked_open; /* Waiting to open */
86816 - int count; /* Usage count */
86817 + atomic_t count; /* Usage count */
86818 wait_queue_head_t open_wait; /* Open waiters */
86819 wait_queue_head_t close_wait; /* Close waiters */
86820 wait_queue_head_t delta_msr_wait; /* Modem status change */
86821 @@ -284,7 +284,7 @@ struct tty_struct {
86822 /* If the tty has a pending do_SAK, queue it here - akpm */
86823 struct work_struct SAK_work;
86824 struct tty_port *port;
86825 -};
86826 +} __randomize_layout;
86827
86828 /* Each of a tty's open files has private_data pointing to tty_file_private */
86829 struct tty_file_private {
86830 @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
86831 struct tty_struct *tty, struct file *filp);
86832 static inline int tty_port_users(struct tty_port *port)
86833 {
86834 - return port->count + port->blocked_open;
86835 + return atomic_read(&port->count) + port->blocked_open;
86836 }
86837
86838 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
86839 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
86840 index 756a609..89db85e 100644
86841 --- a/include/linux/tty_driver.h
86842 +++ b/include/linux/tty_driver.h
86843 @@ -285,7 +285,7 @@ struct tty_operations {
86844 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
86845 #endif
86846 const struct file_operations *proc_fops;
86847 -};
86848 +} __do_const __randomize_layout;
86849
86850 struct tty_driver {
86851 int magic; /* magic number for this structure */
86852 @@ -319,7 +319,7 @@ struct tty_driver {
86853
86854 const struct tty_operations *ops;
86855 struct list_head tty_drivers;
86856 -};
86857 +} __randomize_layout;
86858
86859 extern struct list_head tty_drivers;
86860
86861 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
86862 index 00c9d68..bc0188b 100644
86863 --- a/include/linux/tty_ldisc.h
86864 +++ b/include/linux/tty_ldisc.h
86865 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
86866
86867 struct module *owner;
86868
86869 - int refcount;
86870 + atomic_t refcount;
86871 };
86872
86873 struct tty_ldisc {
86874 diff --git a/include/linux/types.h b/include/linux/types.h
86875 index a0bb704..f511c77 100644
86876 --- a/include/linux/types.h
86877 +++ b/include/linux/types.h
86878 @@ -177,10 +177,26 @@ typedef struct {
86879 int counter;
86880 } atomic_t;
86881
86882 +#ifdef CONFIG_PAX_REFCOUNT
86883 +typedef struct {
86884 + int counter;
86885 +} atomic_unchecked_t;
86886 +#else
86887 +typedef atomic_t atomic_unchecked_t;
86888 +#endif
86889 +
86890 #ifdef CONFIG_64BIT
86891 typedef struct {
86892 long counter;
86893 } atomic64_t;
86894 +
86895 +#ifdef CONFIG_PAX_REFCOUNT
86896 +typedef struct {
86897 + long counter;
86898 +} atomic64_unchecked_t;
86899 +#else
86900 +typedef atomic64_t atomic64_unchecked_t;
86901 +#endif
86902 #endif
86903
86904 struct list_head {
86905 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
86906 index ecd3319..8a36ded 100644
86907 --- a/include/linux/uaccess.h
86908 +++ b/include/linux/uaccess.h
86909 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
86910 long ret; \
86911 mm_segment_t old_fs = get_fs(); \
86912 \
86913 - set_fs(KERNEL_DS); \
86914 pagefault_disable(); \
86915 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
86916 - pagefault_enable(); \
86917 + set_fs(KERNEL_DS); \
86918 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
86919 set_fs(old_fs); \
86920 + pagefault_enable(); \
86921 ret; \
86922 })
86923
86924 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
86925 index 2d1f9b6..d7a9fce 100644
86926 --- a/include/linux/uidgid.h
86927 +++ b/include/linux/uidgid.h
86928 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
86929
86930 #endif /* CONFIG_USER_NS */
86931
86932 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
86933 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
86934 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
86935 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
86936 +
86937 #endif /* _LINUX_UIDGID_H */
86938 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
86939 index 99c1b4d..562e6f3 100644
86940 --- a/include/linux/unaligned/access_ok.h
86941 +++ b/include/linux/unaligned/access_ok.h
86942 @@ -4,34 +4,34 @@
86943 #include <linux/kernel.h>
86944 #include <asm/byteorder.h>
86945
86946 -static inline u16 get_unaligned_le16(const void *p)
86947 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
86948 {
86949 - return le16_to_cpup((__le16 *)p);
86950 + return le16_to_cpup((const __le16 *)p);
86951 }
86952
86953 -static inline u32 get_unaligned_le32(const void *p)
86954 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
86955 {
86956 - return le32_to_cpup((__le32 *)p);
86957 + return le32_to_cpup((const __le32 *)p);
86958 }
86959
86960 -static inline u64 get_unaligned_le64(const void *p)
86961 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
86962 {
86963 - return le64_to_cpup((__le64 *)p);
86964 + return le64_to_cpup((const __le64 *)p);
86965 }
86966
86967 -static inline u16 get_unaligned_be16(const void *p)
86968 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
86969 {
86970 - return be16_to_cpup((__be16 *)p);
86971 + return be16_to_cpup((const __be16 *)p);
86972 }
86973
86974 -static inline u32 get_unaligned_be32(const void *p)
86975 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
86976 {
86977 - return be32_to_cpup((__be32 *)p);
86978 + return be32_to_cpup((const __be32 *)p);
86979 }
86980
86981 -static inline u64 get_unaligned_be64(const void *p)
86982 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
86983 {
86984 - return be64_to_cpup((__be64 *)p);
86985 + return be64_to_cpup((const __be64 *)p);
86986 }
86987
86988 static inline void put_unaligned_le16(u16 val, void *p)
86989 diff --git a/include/linux/usb.h b/include/linux/usb.h
86990 index d2465bc..5256de4 100644
86991 --- a/include/linux/usb.h
86992 +++ b/include/linux/usb.h
86993 @@ -571,7 +571,7 @@ struct usb_device {
86994 int maxchild;
86995
86996 u32 quirks;
86997 - atomic_t urbnum;
86998 + atomic_unchecked_t urbnum;
86999
87000 unsigned long active_duration;
87001
87002 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
87003
87004 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
87005 __u8 request, __u8 requesttype, __u16 value, __u16 index,
87006 - void *data, __u16 size, int timeout);
87007 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
87008 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
87009 void *data, int len, int *actual_length, int timeout);
87010 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
87011 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
87012 index e452ba6..78f8e80 100644
87013 --- a/include/linux/usb/renesas_usbhs.h
87014 +++ b/include/linux/usb/renesas_usbhs.h
87015 @@ -39,7 +39,7 @@ enum {
87016 */
87017 struct renesas_usbhs_driver_callback {
87018 int (*notify_hotplug)(struct platform_device *pdev);
87019 -};
87020 +} __no_const;
87021
87022 /*
87023 * callback functions for platform
87024 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
87025 index 4836ba3..603f6ee 100644
87026 --- a/include/linux/user_namespace.h
87027 +++ b/include/linux/user_namespace.h
87028 @@ -33,7 +33,7 @@ struct user_namespace {
87029 struct key *persistent_keyring_register;
87030 struct rw_semaphore persistent_keyring_register_sem;
87031 #endif
87032 -};
87033 +} __randomize_layout;
87034
87035 extern struct user_namespace init_user_ns;
87036
87037 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
87038 index 239e277..22a5cf5 100644
87039 --- a/include/linux/utsname.h
87040 +++ b/include/linux/utsname.h
87041 @@ -24,7 +24,7 @@ struct uts_namespace {
87042 struct new_utsname name;
87043 struct user_namespace *user_ns;
87044 unsigned int proc_inum;
87045 -};
87046 +} __randomize_layout;
87047 extern struct uts_namespace init_uts_ns;
87048
87049 #ifdef CONFIG_UTS_NS
87050 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
87051 index 6f8fbcf..4efc177 100644
87052 --- a/include/linux/vermagic.h
87053 +++ b/include/linux/vermagic.h
87054 @@ -25,9 +25,42 @@
87055 #define MODULE_ARCH_VERMAGIC ""
87056 #endif
87057
87058 +#ifdef CONFIG_PAX_REFCOUNT
87059 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
87060 +#else
87061 +#define MODULE_PAX_REFCOUNT ""
87062 +#endif
87063 +
87064 +#ifdef CONSTIFY_PLUGIN
87065 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
87066 +#else
87067 +#define MODULE_CONSTIFY_PLUGIN ""
87068 +#endif
87069 +
87070 +#ifdef STACKLEAK_PLUGIN
87071 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
87072 +#else
87073 +#define MODULE_STACKLEAK_PLUGIN ""
87074 +#endif
87075 +
87076 +#ifdef RANDSTRUCT_PLUGIN
87077 +#include <generated/randomize_layout_hash.h>
87078 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
87079 +#else
87080 +#define MODULE_RANDSTRUCT_PLUGIN
87081 +#endif
87082 +
87083 +#ifdef CONFIG_GRKERNSEC
87084 +#define MODULE_GRSEC "GRSEC "
87085 +#else
87086 +#define MODULE_GRSEC ""
87087 +#endif
87088 +
87089 #define VERMAGIC_STRING \
87090 UTS_RELEASE " " \
87091 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
87092 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
87093 - MODULE_ARCH_VERMAGIC
87094 + MODULE_ARCH_VERMAGIC \
87095 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
87096 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
87097
87098 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
87099 index 502073a..a7de024 100644
87100 --- a/include/linux/vga_switcheroo.h
87101 +++ b/include/linux/vga_switcheroo.h
87102 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
87103
87104 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
87105
87106 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
87107 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
87108 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
87109 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
87110 #else
87111
87112 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
87113 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
87114
87115 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
87116
87117 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
87118 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
87119 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
87120 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
87121
87122 #endif
87123 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
87124 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
87125 index 4b8a891..e9a2863 100644
87126 --- a/include/linux/vmalloc.h
87127 +++ b/include/linux/vmalloc.h
87128 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
87129 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
87130 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
87131 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
87132 +
87133 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
87134 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
87135 +#endif
87136 +
87137 /* bits [20..32] reserved for arch specific ioremap internals */
87138
87139 /*
87140 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
87141 unsigned long flags, pgprot_t prot);
87142 extern void vunmap(const void *addr);
87143
87144 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
87145 +extern void unmap_process_stacks(struct task_struct *task);
87146 +#endif
87147 +
87148 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
87149 unsigned long uaddr, void *kaddr,
87150 unsigned long size);
87151 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
87152
87153 /* for /dev/kmem */
87154 extern long vread(char *buf, char *addr, unsigned long count);
87155 -extern long vwrite(char *buf, char *addr, unsigned long count);
87156 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
87157
87158 /*
87159 * Internals. Dont't use..
87160 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
87161 index 82e7db7..f8ce3d0 100644
87162 --- a/include/linux/vmstat.h
87163 +++ b/include/linux/vmstat.h
87164 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
87165 /*
87166 * Zone based page accounting with per cpu differentials.
87167 */
87168 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
87169 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
87170
87171 static inline void zone_page_state_add(long x, struct zone *zone,
87172 enum zone_stat_item item)
87173 {
87174 - atomic_long_add(x, &zone->vm_stat[item]);
87175 - atomic_long_add(x, &vm_stat[item]);
87176 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
87177 + atomic_long_add_unchecked(x, &vm_stat[item]);
87178 }
87179
87180 -static inline unsigned long global_page_state(enum zone_stat_item item)
87181 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
87182 {
87183 - long x = atomic_long_read(&vm_stat[item]);
87184 + long x = atomic_long_read_unchecked(&vm_stat[item]);
87185 #ifdef CONFIG_SMP
87186 if (x < 0)
87187 x = 0;
87188 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
87189 return x;
87190 }
87191
87192 -static inline unsigned long zone_page_state(struct zone *zone,
87193 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
87194 enum zone_stat_item item)
87195 {
87196 - long x = atomic_long_read(&zone->vm_stat[item]);
87197 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
87198 #ifdef CONFIG_SMP
87199 if (x < 0)
87200 x = 0;
87201 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
87202 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
87203 enum zone_stat_item item)
87204 {
87205 - long x = atomic_long_read(&zone->vm_stat[item]);
87206 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
87207
87208 #ifdef CONFIG_SMP
87209 int cpu;
87210 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
87211
87212 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
87213 {
87214 - atomic_long_inc(&zone->vm_stat[item]);
87215 - atomic_long_inc(&vm_stat[item]);
87216 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
87217 + atomic_long_inc_unchecked(&vm_stat[item]);
87218 }
87219
87220 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
87221 {
87222 - atomic_long_dec(&zone->vm_stat[item]);
87223 - atomic_long_dec(&vm_stat[item]);
87224 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
87225 + atomic_long_dec_unchecked(&vm_stat[item]);
87226 }
87227
87228 static inline void __inc_zone_page_state(struct page *page,
87229 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
87230 index 91b0a68..0e9adf6 100644
87231 --- a/include/linux/xattr.h
87232 +++ b/include/linux/xattr.h
87233 @@ -28,7 +28,7 @@ struct xattr_handler {
87234 size_t size, int handler_flags);
87235 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
87236 size_t size, int flags, int handler_flags);
87237 -};
87238 +} __do_const;
87239
87240 struct xattr {
87241 const char *name;
87242 @@ -37,6 +37,9 @@ struct xattr {
87243 };
87244
87245 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
87246 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
87247 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
87248 +#endif
87249 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
87250 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
87251 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
87252 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
87253 index 9c5a6b4..09c9438 100644
87254 --- a/include/linux/zlib.h
87255 +++ b/include/linux/zlib.h
87256 @@ -31,6 +31,7 @@
87257 #define _ZLIB_H
87258
87259 #include <linux/zconf.h>
87260 +#include <linux/compiler.h>
87261
87262 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
87263 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
87264 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
87265
87266 /* basic functions */
87267
87268 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
87269 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
87270 /*
87271 Returns the number of bytes that needs to be allocated for a per-
87272 stream workspace with the specified parameters. A pointer to this
87273 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
87274 index eec6e46..82d5641 100644
87275 --- a/include/media/v4l2-dev.h
87276 +++ b/include/media/v4l2-dev.h
87277 @@ -77,7 +77,7 @@ struct v4l2_file_operations {
87278 int (*mmap) (struct file *, struct vm_area_struct *);
87279 int (*open) (struct file *);
87280 int (*release) (struct file *);
87281 -};
87282 +} __do_const;
87283
87284 /*
87285 * Newer version of video_device, handled by videodev2.c
87286 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
87287 index ffb69da..040393e 100644
87288 --- a/include/media/v4l2-device.h
87289 +++ b/include/media/v4l2-device.h
87290 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
87291 this function returns 0. If the name ends with a digit (e.g. cx18),
87292 then the name will be set to cx18-0 since cx180 looks really odd. */
87293 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
87294 - atomic_t *instance);
87295 + atomic_unchecked_t *instance);
87296
87297 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
87298 Since the parent disappears this ensures that v4l2_dev doesn't have an
87299 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
87300 index d9fa68f..45c88d1 100644
87301 --- a/include/net/9p/transport.h
87302 +++ b/include/net/9p/transport.h
87303 @@ -63,7 +63,7 @@ struct p9_trans_module {
87304 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
87305 int (*zc_request)(struct p9_client *, struct p9_req_t *,
87306 char *, char *, int , int, int, int);
87307 -};
87308 +} __do_const;
87309
87310 void v9fs_register_trans(struct p9_trans_module *m);
87311 void v9fs_unregister_trans(struct p9_trans_module *m);
87312 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
87313 index a175ba4..196eb82 100644
87314 --- a/include/net/af_unix.h
87315 +++ b/include/net/af_unix.h
87316 @@ -36,7 +36,7 @@ struct unix_skb_parms {
87317 u32 secid; /* Security ID */
87318 #endif
87319 u32 consumed;
87320 -};
87321 +} __randomize_layout;
87322
87323 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
87324 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
87325 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
87326 index 4abdcb2..945c5cc 100644
87327 --- a/include/net/bluetooth/l2cap.h
87328 +++ b/include/net/bluetooth/l2cap.h
87329 @@ -601,7 +601,7 @@ struct l2cap_ops {
87330 long (*get_sndtimeo) (struct l2cap_chan *chan);
87331 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
87332 unsigned long len, int nb);
87333 -};
87334 +} __do_const;
87335
87336 struct l2cap_conn {
87337 struct hci_conn *hcon;
87338 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
87339 index f2ae33d..c457cf0 100644
87340 --- a/include/net/caif/cfctrl.h
87341 +++ b/include/net/caif/cfctrl.h
87342 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
87343 void (*radioset_rsp)(void);
87344 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
87345 struct cflayer *client_layer);
87346 -};
87347 +} __no_const;
87348
87349 /* Link Setup Parameters for CAIF-Links. */
87350 struct cfctrl_link_param {
87351 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
87352 struct cfctrl {
87353 struct cfsrvl serv;
87354 struct cfctrl_rsp res;
87355 - atomic_t req_seq_no;
87356 - atomic_t rsp_seq_no;
87357 + atomic_unchecked_t req_seq_no;
87358 + atomic_unchecked_t rsp_seq_no;
87359 struct list_head list;
87360 /* Protects from simultaneous access to first_req list */
87361 spinlock_t info_list_lock;
87362 diff --git a/include/net/flow.h b/include/net/flow.h
87363 index 8109a15..504466d 100644
87364 --- a/include/net/flow.h
87365 +++ b/include/net/flow.h
87366 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
87367
87368 void flow_cache_flush(struct net *net);
87369 void flow_cache_flush_deferred(struct net *net);
87370 -extern atomic_t flow_cache_genid;
87371 +extern atomic_unchecked_t flow_cache_genid;
87372
87373 #endif
87374 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
87375 index 93695f0..766d71c 100644
87376 --- a/include/net/genetlink.h
87377 +++ b/include/net/genetlink.h
87378 @@ -120,7 +120,7 @@ struct genl_ops {
87379 u8 cmd;
87380 u8 internal_flags;
87381 u8 flags;
87382 -};
87383 +} __do_const;
87384
87385 int __genl_register_family(struct genl_family *family);
87386
87387 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
87388 index 734d9b5..48a9a4b 100644
87389 --- a/include/net/gro_cells.h
87390 +++ b/include/net/gro_cells.h
87391 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
87392 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
87393
87394 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
87395 - atomic_long_inc(&dev->rx_dropped);
87396 + atomic_long_inc_unchecked(&dev->rx_dropped);
87397 kfree_skb(skb);
87398 return;
87399 }
87400 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
87401 index 7a43138..bc76865 100644
87402 --- a/include/net/inet_connection_sock.h
87403 +++ b/include/net/inet_connection_sock.h
87404 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
87405 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
87406 int (*bind_conflict)(const struct sock *sk,
87407 const struct inet_bind_bucket *tb, bool relax);
87408 -};
87409 +} __do_const;
87410
87411 /** inet_connection_sock - INET connection oriented sock
87412 *
87413 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
87414 index 01d590e..f69c61d 100644
87415 --- a/include/net/inetpeer.h
87416 +++ b/include/net/inetpeer.h
87417 @@ -47,7 +47,7 @@ struct inet_peer {
87418 */
87419 union {
87420 struct {
87421 - atomic_t rid; /* Frag reception counter */
87422 + atomic_unchecked_t rid; /* Frag reception counter */
87423 };
87424 struct rcu_head rcu;
87425 struct inet_peer *gc_next;
87426 diff --git a/include/net/ip.h b/include/net/ip.h
87427 index 7596eb2..f7f5fad 100644
87428 --- a/include/net/ip.h
87429 +++ b/include/net/ip.h
87430 @@ -309,7 +309,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
87431 }
87432 }
87433
87434 -u32 ip_idents_reserve(u32 hash, int segs);
87435 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
87436 void __ip_select_ident(struct iphdr *iph, int segs);
87437
87438 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
87439 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
87440 index 9922093..a1755d6 100644
87441 --- a/include/net/ip_fib.h
87442 +++ b/include/net/ip_fib.h
87443 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
87444
87445 #define FIB_RES_SADDR(net, res) \
87446 ((FIB_RES_NH(res).nh_saddr_genid == \
87447 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
87448 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
87449 FIB_RES_NH(res).nh_saddr : \
87450 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
87451 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
87452 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
87453 index 624a8a5..b1e2a24 100644
87454 --- a/include/net/ip_vs.h
87455 +++ b/include/net/ip_vs.h
87456 @@ -558,7 +558,7 @@ struct ip_vs_conn {
87457 struct ip_vs_conn *control; /* Master control connection */
87458 atomic_t n_control; /* Number of controlled ones */
87459 struct ip_vs_dest *dest; /* real server */
87460 - atomic_t in_pkts; /* incoming packet counter */
87461 + atomic_unchecked_t in_pkts; /* incoming packet counter */
87462
87463 /* packet transmitter for different forwarding methods. If it
87464 mangles the packet, it must return NF_DROP or better NF_STOLEN,
87465 @@ -705,7 +705,7 @@ struct ip_vs_dest {
87466 __be16 port; /* port number of the server */
87467 union nf_inet_addr addr; /* IP address of the server */
87468 volatile unsigned int flags; /* dest status flags */
87469 - atomic_t conn_flags; /* flags to copy to conn */
87470 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
87471 atomic_t weight; /* server weight */
87472
87473 atomic_t refcnt; /* reference counter */
87474 @@ -960,11 +960,11 @@ struct netns_ipvs {
87475 /* ip_vs_lblc */
87476 int sysctl_lblc_expiration;
87477 struct ctl_table_header *lblc_ctl_header;
87478 - struct ctl_table *lblc_ctl_table;
87479 + ctl_table_no_const *lblc_ctl_table;
87480 /* ip_vs_lblcr */
87481 int sysctl_lblcr_expiration;
87482 struct ctl_table_header *lblcr_ctl_header;
87483 - struct ctl_table *lblcr_ctl_table;
87484 + ctl_table_no_const *lblcr_ctl_table;
87485 /* ip_vs_est */
87486 struct list_head est_list; /* estimator list */
87487 spinlock_t est_lock;
87488 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
87489 index 8d4f588..2e37ad2 100644
87490 --- a/include/net/irda/ircomm_tty.h
87491 +++ b/include/net/irda/ircomm_tty.h
87492 @@ -33,6 +33,7 @@
87493 #include <linux/termios.h>
87494 #include <linux/timer.h>
87495 #include <linux/tty.h> /* struct tty_struct */
87496 +#include <asm/local.h>
87497
87498 #include <net/irda/irias_object.h>
87499 #include <net/irda/ircomm_core.h>
87500 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
87501 index 714cc9a..ea05f3e 100644
87502 --- a/include/net/iucv/af_iucv.h
87503 +++ b/include/net/iucv/af_iucv.h
87504 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
87505 struct iucv_sock_list {
87506 struct hlist_head head;
87507 rwlock_t lock;
87508 - atomic_t autobind_name;
87509 + atomic_unchecked_t autobind_name;
87510 };
87511
87512 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
87513 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
87514 index f3be818..bf46196 100644
87515 --- a/include/net/llc_c_ac.h
87516 +++ b/include/net/llc_c_ac.h
87517 @@ -87,7 +87,7 @@
87518 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
87519 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
87520
87521 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
87522 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
87523
87524 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
87525 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
87526 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
87527 index 3948cf1..83b28c4 100644
87528 --- a/include/net/llc_c_ev.h
87529 +++ b/include/net/llc_c_ev.h
87530 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
87531 return (struct llc_conn_state_ev *)skb->cb;
87532 }
87533
87534 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
87535 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
87536 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
87537 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
87538
87539 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
87540 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
87541 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
87542 index 0e79cfb..f46db31 100644
87543 --- a/include/net/llc_c_st.h
87544 +++ b/include/net/llc_c_st.h
87545 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
87546 u8 next_state;
87547 llc_conn_ev_qfyr_t *ev_qualifiers;
87548 llc_conn_action_t *ev_actions;
87549 -};
87550 +} __do_const;
87551
87552 struct llc_conn_state {
87553 u8 current_state;
87554 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
87555 index a61b98c..aade1eb 100644
87556 --- a/include/net/llc_s_ac.h
87557 +++ b/include/net/llc_s_ac.h
87558 @@ -23,7 +23,7 @@
87559 #define SAP_ACT_TEST_IND 9
87560
87561 /* All action functions must look like this */
87562 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
87563 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
87564
87565 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
87566 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
87567 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
87568 index 567c681..cd73ac02 100644
87569 --- a/include/net/llc_s_st.h
87570 +++ b/include/net/llc_s_st.h
87571 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
87572 llc_sap_ev_t ev;
87573 u8 next_state;
87574 llc_sap_action_t *ev_actions;
87575 -};
87576 +} __do_const;
87577
87578 struct llc_sap_state {
87579 u8 curr_state;
87580 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
87581 index 421b6ec..5a03729 100644
87582 --- a/include/net/mac80211.h
87583 +++ b/include/net/mac80211.h
87584 @@ -4588,7 +4588,7 @@ struct rate_control_ops {
87585 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
87586
87587 u32 (*get_expected_throughput)(void *priv_sta);
87588 -};
87589 +} __do_const;
87590
87591 static inline int rate_supported(struct ieee80211_sta *sta,
87592 enum ieee80211_band band,
87593 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
87594 index 47f4254..fd095bc 100644
87595 --- a/include/net/neighbour.h
87596 +++ b/include/net/neighbour.h
87597 @@ -163,7 +163,7 @@ struct neigh_ops {
87598 void (*error_report)(struct neighbour *, struct sk_buff *);
87599 int (*output)(struct neighbour *, struct sk_buff *);
87600 int (*connected_output)(struct neighbour *, struct sk_buff *);
87601 -};
87602 +} __do_const;
87603
87604 struct pneigh_entry {
87605 struct pneigh_entry *next;
87606 @@ -217,7 +217,7 @@ struct neigh_table {
87607 struct neigh_statistics __percpu *stats;
87608 struct neigh_hash_table __rcu *nht;
87609 struct pneigh_entry **phash_buckets;
87610 -};
87611 +} __randomize_layout;
87612
87613 static inline int neigh_parms_family(struct neigh_parms *p)
87614 {
87615 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
87616 index 361d260..903d15f 100644
87617 --- a/include/net/net_namespace.h
87618 +++ b/include/net/net_namespace.h
87619 @@ -129,8 +129,8 @@ struct net {
87620 struct netns_ipvs *ipvs;
87621 #endif
87622 struct sock *diag_nlsk;
87623 - atomic_t fnhe_genid;
87624 -};
87625 + atomic_unchecked_t fnhe_genid;
87626 +} __randomize_layout;
87627
87628 #include <linux/seq_file_net.h>
87629
87630 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
87631 #define __net_init __init
87632 #define __net_exit __exit_refok
87633 #define __net_initdata __initdata
87634 +#ifdef CONSTIFY_PLUGIN
87635 #define __net_initconst __initconst
87636 +#else
87637 +#define __net_initconst __initdata
87638 +#endif
87639 #endif
87640
87641 struct pernet_operations {
87642 @@ -296,7 +300,7 @@ struct pernet_operations {
87643 void (*exit_batch)(struct list_head *net_exit_list);
87644 int *id;
87645 size_t size;
87646 -};
87647 +} __do_const;
87648
87649 /*
87650 * Use these carefully. If you implement a network device and it
87651 @@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
87652
87653 static inline int rt_genid_ipv4(struct net *net)
87654 {
87655 - return atomic_read(&net->ipv4.rt_genid);
87656 + return atomic_read_unchecked(&net->ipv4.rt_genid);
87657 }
87658
87659 static inline void rt_genid_bump_ipv4(struct net *net)
87660 {
87661 - atomic_inc(&net->ipv4.rt_genid);
87662 + atomic_inc_unchecked(&net->ipv4.rt_genid);
87663 }
87664
87665 #if IS_ENABLED(CONFIG_IPV6)
87666 static inline int rt_genid_ipv6(struct net *net)
87667 {
87668 - return atomic_read(&net->ipv6.rt_genid);
87669 + return atomic_read_unchecked(&net->ipv6.rt_genid);
87670 }
87671
87672 static inline void rt_genid_bump_ipv6(struct net *net)
87673 {
87674 - atomic_inc(&net->ipv6.rt_genid);
87675 + atomic_inc_unchecked(&net->ipv6.rt_genid);
87676 }
87677 #else
87678 static inline int rt_genid_ipv6(struct net *net)
87679 @@ -390,12 +394,12 @@ static inline void rt_genid_bump_all(struct net *net)
87680
87681 static inline int fnhe_genid(struct net *net)
87682 {
87683 - return atomic_read(&net->fnhe_genid);
87684 + return atomic_read_unchecked(&net->fnhe_genid);
87685 }
87686
87687 static inline void fnhe_genid_bump(struct net *net)
87688 {
87689 - atomic_inc(&net->fnhe_genid);
87690 + atomic_inc_unchecked(&net->fnhe_genid);
87691 }
87692
87693 #endif /* __NET_NET_NAMESPACE_H */
87694 diff --git a/include/net/netdma.h b/include/net/netdma.h
87695 index 8ba8ce2..99b7fff 100644
87696 --- a/include/net/netdma.h
87697 +++ b/include/net/netdma.h
87698 @@ -24,7 +24,7 @@
87699 #include <linux/dmaengine.h>
87700 #include <linux/skbuff.h>
87701
87702 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
87703 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
87704 struct sk_buff *skb, int offset, struct iovec *to,
87705 size_t len, struct dma_pinned_list *pinned_list);
87706
87707 diff --git a/include/net/netlink.h b/include/net/netlink.h
87708 index 2b47eaa..6d5bcc2 100644
87709 --- a/include/net/netlink.h
87710 +++ b/include/net/netlink.h
87711 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
87712 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
87713 {
87714 if (mark)
87715 - skb_trim(skb, (unsigned char *) mark - skb->data);
87716 + skb_trim(skb, (const unsigned char *) mark - skb->data);
87717 }
87718
87719 /**
87720 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
87721 index 773cce3..6a11852 100644
87722 --- a/include/net/netns/conntrack.h
87723 +++ b/include/net/netns/conntrack.h
87724 @@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
87725 struct nf_proto_net {
87726 #ifdef CONFIG_SYSCTL
87727 struct ctl_table_header *ctl_table_header;
87728 - struct ctl_table *ctl_table;
87729 + ctl_table_no_const *ctl_table;
87730 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
87731 struct ctl_table_header *ctl_compat_header;
87732 - struct ctl_table *ctl_compat_table;
87733 + ctl_table_no_const *ctl_compat_table;
87734 #endif
87735 #endif
87736 unsigned int users;
87737 @@ -59,7 +59,7 @@ struct nf_ip_net {
87738 struct nf_icmp_net icmpv6;
87739 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
87740 struct ctl_table_header *ctl_table_header;
87741 - struct ctl_table *ctl_table;
87742 + ctl_table_no_const *ctl_table;
87743 #endif
87744 };
87745
87746 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
87747 index aec5e12..807233f 100644
87748 --- a/include/net/netns/ipv4.h
87749 +++ b/include/net/netns/ipv4.h
87750 @@ -82,7 +82,7 @@ struct netns_ipv4 {
87751
87752 struct ping_group_range ping_group_range;
87753
87754 - atomic_t dev_addr_genid;
87755 + atomic_unchecked_t dev_addr_genid;
87756
87757 #ifdef CONFIG_SYSCTL
87758 unsigned long *sysctl_local_reserved_ports;
87759 @@ -96,6 +96,6 @@ struct netns_ipv4 {
87760 struct fib_rules_ops *mr_rules_ops;
87761 #endif
87762 #endif
87763 - atomic_t rt_genid;
87764 + atomic_unchecked_t rt_genid;
87765 };
87766 #endif
87767 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
87768 index 19d3446..3c87195 100644
87769 --- a/include/net/netns/ipv6.h
87770 +++ b/include/net/netns/ipv6.h
87771 @@ -74,8 +74,8 @@ struct netns_ipv6 {
87772 struct fib_rules_ops *mr6_rules_ops;
87773 #endif
87774 #endif
87775 - atomic_t dev_addr_genid;
87776 - atomic_t rt_genid;
87777 + atomic_unchecked_t dev_addr_genid;
87778 + atomic_unchecked_t rt_genid;
87779 };
87780
87781 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
87782 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
87783 index 3492434..209f58c 100644
87784 --- a/include/net/netns/xfrm.h
87785 +++ b/include/net/netns/xfrm.h
87786 @@ -64,7 +64,7 @@ struct netns_xfrm {
87787
87788 /* flow cache part */
87789 struct flow_cache flow_cache_global;
87790 - atomic_t flow_cache_genid;
87791 + atomic_unchecked_t flow_cache_genid;
87792 struct list_head flow_cache_gc_list;
87793 spinlock_t flow_cache_gc_lock;
87794 struct work_struct flow_cache_gc_work;
87795 diff --git a/include/net/ping.h b/include/net/ping.h
87796 index 026479b..d9b2829 100644
87797 --- a/include/net/ping.h
87798 +++ b/include/net/ping.h
87799 @@ -54,7 +54,7 @@ struct ping_iter_state {
87800
87801 extern struct proto ping_prot;
87802 #if IS_ENABLED(CONFIG_IPV6)
87803 -extern struct pingv6_ops pingv6_ops;
87804 +extern struct pingv6_ops *pingv6_ops;
87805 #endif
87806
87807 struct pingfakehdr {
87808 diff --git a/include/net/protocol.h b/include/net/protocol.h
87809 index d6fcc1f..ca277058 100644
87810 --- a/include/net/protocol.h
87811 +++ b/include/net/protocol.h
87812 @@ -49,7 +49,7 @@ struct net_protocol {
87813 * socket lookup?
87814 */
87815 icmp_strict_tag_validation:1;
87816 -};
87817 +} __do_const;
87818
87819 #if IS_ENABLED(CONFIG_IPV6)
87820 struct inet6_protocol {
87821 @@ -62,7 +62,7 @@ struct inet6_protocol {
87822 u8 type, u8 code, int offset,
87823 __be32 info);
87824 unsigned int flags; /* INET6_PROTO_xxx */
87825 -};
87826 +} __do_const;
87827
87828 #define INET6_PROTO_NOPOLICY 0x1
87829 #define INET6_PROTO_FINAL 0x2
87830 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
87831 index 72240e5..8c14bef 100644
87832 --- a/include/net/rtnetlink.h
87833 +++ b/include/net/rtnetlink.h
87834 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
87835 int (*fill_slave_info)(struct sk_buff *skb,
87836 const struct net_device *dev,
87837 const struct net_device *slave_dev);
87838 -};
87839 +} __do_const;
87840
87841 int __rtnl_link_register(struct rtnl_link_ops *ops);
87842 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
87843 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
87844 index 4a5b9a3..ca27d73 100644
87845 --- a/include/net/sctp/checksum.h
87846 +++ b/include/net/sctp/checksum.h
87847 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
87848 unsigned int offset)
87849 {
87850 struct sctphdr *sh = sctp_hdr(skb);
87851 - __le32 ret, old = sh->checksum;
87852 - const struct skb_checksum_ops ops = {
87853 + __le32 ret, old = sh->checksum;
87854 + static const struct skb_checksum_ops ops = {
87855 .update = sctp_csum_update,
87856 .combine = sctp_csum_combine,
87857 };
87858 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
87859 index 7f4eeb3..37e8fe1 100644
87860 --- a/include/net/sctp/sm.h
87861 +++ b/include/net/sctp/sm.h
87862 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
87863 typedef struct {
87864 sctp_state_fn_t *fn;
87865 const char *name;
87866 -} sctp_sm_table_entry_t;
87867 +} __do_const sctp_sm_table_entry_t;
87868
87869 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
87870 * currently in use.
87871 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
87872 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
87873
87874 /* Extern declarations for major data structures. */
87875 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
87876 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
87877
87878
87879 /* Get the size of a DATA chunk payload. */
87880 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
87881 index f38588bf..94c1795 100644
87882 --- a/include/net/sctp/structs.h
87883 +++ b/include/net/sctp/structs.h
87884 @@ -507,7 +507,7 @@ struct sctp_pf {
87885 struct sctp_association *asoc);
87886 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
87887 struct sctp_af *af;
87888 -};
87889 +} __do_const;
87890
87891
87892 /* Structure to track chunk fragments that have been acked, but peer
87893 diff --git a/include/net/sock.h b/include/net/sock.h
87894 index 1563507..20d5d0e 100644
87895 --- a/include/net/sock.h
87896 +++ b/include/net/sock.h
87897 @@ -349,7 +349,7 @@ struct sock {
87898 unsigned int sk_napi_id;
87899 unsigned int sk_ll_usec;
87900 #endif
87901 - atomic_t sk_drops;
87902 + atomic_unchecked_t sk_drops;
87903 int sk_rcvbuf;
87904
87905 struct sk_filter __rcu *sk_filter;
87906 @@ -1038,7 +1038,7 @@ struct proto {
87907 void (*destroy_cgroup)(struct mem_cgroup *memcg);
87908 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
87909 #endif
87910 -};
87911 +} __randomize_layout;
87912
87913 /*
87914 * Bits in struct cg_proto.flags
87915 @@ -1225,7 +1225,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
87916 return ret >> PAGE_SHIFT;
87917 }
87918
87919 -static inline long
87920 +static inline long __intentional_overflow(-1)
87921 sk_memory_allocated(const struct sock *sk)
87922 {
87923 struct proto *prot = sk->sk_prot;
87924 @@ -1370,7 +1370,7 @@ struct sock_iocb {
87925 struct scm_cookie *scm;
87926 struct msghdr *msg, async_msg;
87927 struct kiocb *kiocb;
87928 -};
87929 +} __randomize_layout;
87930
87931 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
87932 {
87933 @@ -1623,6 +1623,33 @@ void sk_common_release(struct sock *sk);
87934 /* Initialise core socket variables */
87935 void sock_init_data(struct socket *sock, struct sock *sk);
87936
87937 +void sk_filter_release_rcu(struct rcu_head *rcu);
87938 +
87939 +/**
87940 + * sk_filter_release - release a socket filter
87941 + * @fp: filter to remove
87942 + *
87943 + * Remove a filter from a socket and release its resources.
87944 + */
87945 +
87946 +static inline void sk_filter_release(struct sk_filter *fp)
87947 +{
87948 + if (atomic_dec_and_test(&fp->refcnt))
87949 + call_rcu(&fp->rcu, sk_filter_release_rcu);
87950 +}
87951 +
87952 +static inline void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp)
87953 +{
87954 + atomic_sub(sk_filter_size(fp->len), &sk->sk_omem_alloc);
87955 + sk_filter_release(fp);
87956 +}
87957 +
87958 +static inline void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
87959 +{
87960 + atomic_inc(&fp->refcnt);
87961 + atomic_add(sk_filter_size(fp->len), &sk->sk_omem_alloc);
87962 +}
87963 +
87964 /*
87965 * Socket reference counting postulates.
87966 *
87967 @@ -1805,7 +1832,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
87968 }
87969
87970 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
87971 - char __user *from, char *to,
87972 + char __user *from, unsigned char *to,
87973 int copy, int offset)
87974 {
87975 if (skb->ip_summed == CHECKSUM_NONE) {
87976 @@ -2067,7 +2094,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
87977 }
87978 }
87979
87980 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87981 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87982
87983 /**
87984 * sk_page_frag - return an appropriate page_frag
87985 diff --git a/include/net/tcp.h b/include/net/tcp.h
87986 index 7286db8..f1aa7dc 100644
87987 --- a/include/net/tcp.h
87988 +++ b/include/net/tcp.h
87989 @@ -535,7 +535,7 @@ void tcp_retransmit_timer(struct sock *sk);
87990 void tcp_xmit_retransmit_queue(struct sock *);
87991 void tcp_simple_retransmit(struct sock *);
87992 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
87993 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87994 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87995
87996 void tcp_send_probe0(struct sock *);
87997 void tcp_send_partial(struct sock *);
87998 @@ -708,8 +708,8 @@ struct tcp_skb_cb {
87999 struct inet6_skb_parm h6;
88000 #endif
88001 } header; /* For incoming frames */
88002 - __u32 seq; /* Starting sequence number */
88003 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
88004 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
88005 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
88006 __u32 when; /* used to compute rtt's */
88007 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
88008
88009 @@ -723,7 +723,7 @@ struct tcp_skb_cb {
88010
88011 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
88012 /* 1 byte hole */
88013 - __u32 ack_seq; /* Sequence number ACK'd */
88014 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
88015 };
88016
88017 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
88018 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
88019 index 721e9c3b..3c81bbf 100644
88020 --- a/include/net/xfrm.h
88021 +++ b/include/net/xfrm.h
88022 @@ -285,7 +285,6 @@ struct xfrm_dst;
88023 struct xfrm_policy_afinfo {
88024 unsigned short family;
88025 struct dst_ops *dst_ops;
88026 - void (*garbage_collect)(struct net *net);
88027 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
88028 const xfrm_address_t *saddr,
88029 const xfrm_address_t *daddr);
88030 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
88031 struct net_device *dev,
88032 const struct flowi *fl);
88033 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
88034 -};
88035 +} __do_const;
88036
88037 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
88038 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
88039 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
88040 int (*transport_finish)(struct sk_buff *skb,
88041 int async);
88042 void (*local_error)(struct sk_buff *skb, u32 mtu);
88043 -};
88044 +} __do_const;
88045
88046 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
88047 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
88048 @@ -437,7 +436,7 @@ struct xfrm_mode {
88049 struct module *owner;
88050 unsigned int encap;
88051 int flags;
88052 -};
88053 +} __do_const;
88054
88055 /* Flags for xfrm_mode. */
88056 enum {
88057 @@ -534,7 +533,7 @@ struct xfrm_policy {
88058 struct timer_list timer;
88059
88060 struct flow_cache_object flo;
88061 - atomic_t genid;
88062 + atomic_unchecked_t genid;
88063 u32 priority;
88064 u32 index;
88065 struct xfrm_mark mark;
88066 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
88067 }
88068
88069 void xfrm_garbage_collect(struct net *net);
88070 +void xfrm_garbage_collect_deferred(struct net *net);
88071
88072 #else
88073
88074 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
88075 static inline void xfrm_garbage_collect(struct net *net)
88076 {
88077 }
88078 +static inline void xfrm_garbage_collect_deferred(struct net *net)
88079 +{
88080 +}
88081 #endif
88082
88083 static __inline__
88084 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
88085 index 1017e0b..227aa4d 100644
88086 --- a/include/rdma/iw_cm.h
88087 +++ b/include/rdma/iw_cm.h
88088 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
88089 int backlog);
88090
88091 int (*destroy_listen)(struct iw_cm_id *cm_id);
88092 -};
88093 +} __no_const;
88094
88095 /**
88096 * iw_create_cm_id - Create an IW CM identifier.
88097 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
88098 index 52beadf..598734c 100644
88099 --- a/include/scsi/libfc.h
88100 +++ b/include/scsi/libfc.h
88101 @@ -771,6 +771,7 @@ struct libfc_function_template {
88102 */
88103 void (*disc_stop_final) (struct fc_lport *);
88104 };
88105 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
88106
88107 /**
88108 * struct fc_disc - Discovery context
88109 @@ -875,7 +876,7 @@ struct fc_lport {
88110 struct fc_vport *vport;
88111
88112 /* Operational Information */
88113 - struct libfc_function_template tt;
88114 + libfc_function_template_no_const tt;
88115 u8 link_up;
88116 u8 qfull;
88117 enum fc_lport_state state;
88118 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
88119 index 27ab310..60dc245 100644
88120 --- a/include/scsi/scsi_device.h
88121 +++ b/include/scsi/scsi_device.h
88122 @@ -187,9 +187,9 @@ struct scsi_device {
88123 unsigned int max_device_blocked; /* what device_blocked counts down from */
88124 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
88125
88126 - atomic_t iorequest_cnt;
88127 - atomic_t iodone_cnt;
88128 - atomic_t ioerr_cnt;
88129 + atomic_unchecked_t iorequest_cnt;
88130 + atomic_unchecked_t iodone_cnt;
88131 + atomic_unchecked_t ioerr_cnt;
88132
88133 struct device sdev_gendev,
88134 sdev_dev;
88135 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
88136 index 8c79980..723f6f9 100644
88137 --- a/include/scsi/scsi_transport_fc.h
88138 +++ b/include/scsi/scsi_transport_fc.h
88139 @@ -752,7 +752,8 @@ struct fc_function_template {
88140 unsigned long show_host_system_hostname:1;
88141
88142 unsigned long disable_target_scan:1;
88143 -};
88144 +} __do_const;
88145 +typedef struct fc_function_template __no_const fc_function_template_no_const;
88146
88147
88148 /**
88149 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
88150 index ae6c3b8..fd748ac 100644
88151 --- a/include/sound/compress_driver.h
88152 +++ b/include/sound/compress_driver.h
88153 @@ -128,7 +128,7 @@ struct snd_compr_ops {
88154 struct snd_compr_caps *caps);
88155 int (*get_codec_caps) (struct snd_compr_stream *stream,
88156 struct snd_compr_codec_caps *codec);
88157 -};
88158 +} __no_const;
88159
88160 /**
88161 * struct snd_compr: Compressed device
88162 diff --git a/include/sound/soc.h b/include/sound/soc.h
88163 index ed9e2d7..aad0887 100644
88164 --- a/include/sound/soc.h
88165 +++ b/include/sound/soc.h
88166 @@ -798,7 +798,7 @@ struct snd_soc_codec_driver {
88167 /* probe ordering - for components with runtime dependencies */
88168 int probe_order;
88169 int remove_order;
88170 -};
88171 +} __do_const;
88172
88173 /* SoC platform interface */
88174 struct snd_soc_platform_driver {
88175 @@ -845,7 +845,7 @@ struct snd_soc_platform_driver {
88176 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
88177 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
88178 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
88179 -};
88180 +} __do_const;
88181
88182 struct snd_soc_platform {
88183 const char *name;
88184 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
88185 index 9ec9864..e2ee1ee 100644
88186 --- a/include/target/target_core_base.h
88187 +++ b/include/target/target_core_base.h
88188 @@ -761,7 +761,7 @@ struct se_device {
88189 atomic_long_t write_bytes;
88190 /* Active commands on this virtual SE device */
88191 atomic_t simple_cmds;
88192 - atomic_t dev_ordered_id;
88193 + atomic_unchecked_t dev_ordered_id;
88194 atomic_t dev_ordered_sync;
88195 atomic_t dev_qf_count;
88196 int export_count;
88197 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
88198 new file mode 100644
88199 index 0000000..fb634b7
88200 --- /dev/null
88201 +++ b/include/trace/events/fs.h
88202 @@ -0,0 +1,53 @@
88203 +#undef TRACE_SYSTEM
88204 +#define TRACE_SYSTEM fs
88205 +
88206 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
88207 +#define _TRACE_FS_H
88208 +
88209 +#include <linux/fs.h>
88210 +#include <linux/tracepoint.h>
88211 +
88212 +TRACE_EVENT(do_sys_open,
88213 +
88214 + TP_PROTO(const char *filename, int flags, int mode),
88215 +
88216 + TP_ARGS(filename, flags, mode),
88217 +
88218 + TP_STRUCT__entry(
88219 + __string( filename, filename )
88220 + __field( int, flags )
88221 + __field( int, mode )
88222 + ),
88223 +
88224 + TP_fast_assign(
88225 + __assign_str(filename, filename);
88226 + __entry->flags = flags;
88227 + __entry->mode = mode;
88228 + ),
88229 +
88230 + TP_printk("\"%s\" %x %o",
88231 + __get_str(filename), __entry->flags, __entry->mode)
88232 +);
88233 +
88234 +TRACE_EVENT(open_exec,
88235 +
88236 + TP_PROTO(const char *filename),
88237 +
88238 + TP_ARGS(filename),
88239 +
88240 + TP_STRUCT__entry(
88241 + __string( filename, filename )
88242 + ),
88243 +
88244 + TP_fast_assign(
88245 + __assign_str(filename, filename);
88246 + ),
88247 +
88248 + TP_printk("\"%s\"",
88249 + __get_str(filename))
88250 +);
88251 +
88252 +#endif /* _TRACE_FS_H */
88253 +
88254 +/* This part must be outside protection */
88255 +#include <trace/define_trace.h>
88256 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
88257 index 1c09820..7f5ec79 100644
88258 --- a/include/trace/events/irq.h
88259 +++ b/include/trace/events/irq.h
88260 @@ -36,7 +36,7 @@ struct softirq_action;
88261 */
88262 TRACE_EVENT(irq_handler_entry,
88263
88264 - TP_PROTO(int irq, struct irqaction *action),
88265 + TP_PROTO(int irq, const struct irqaction *action),
88266
88267 TP_ARGS(irq, action),
88268
88269 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
88270 */
88271 TRACE_EVENT(irq_handler_exit,
88272
88273 - TP_PROTO(int irq, struct irqaction *action, int ret),
88274 + TP_PROTO(int irq, const struct irqaction *action, int ret),
88275
88276 TP_ARGS(irq, action, ret),
88277
88278 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
88279 index 7caf44c..23c6f27 100644
88280 --- a/include/uapi/linux/a.out.h
88281 +++ b/include/uapi/linux/a.out.h
88282 @@ -39,6 +39,14 @@ enum machine_type {
88283 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
88284 };
88285
88286 +/* Constants for the N_FLAGS field */
88287 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
88288 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
88289 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
88290 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
88291 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
88292 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
88293 +
88294 #if !defined (N_MAGIC)
88295 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
88296 #endif
88297 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
88298 index 22b6ad3..aeba37e 100644
88299 --- a/include/uapi/linux/bcache.h
88300 +++ b/include/uapi/linux/bcache.h
88301 @@ -5,6 +5,7 @@
88302 * Bcache on disk data structures
88303 */
88304
88305 +#include <linux/compiler.h>
88306 #include <asm/types.h>
88307
88308 #define BITMASK(name, type, field, offset, size) \
88309 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
88310 /* Btree keys - all units are in sectors */
88311
88312 struct bkey {
88313 - __u64 high;
88314 - __u64 low;
88315 + __u64 high __intentional_overflow(-1);
88316 + __u64 low __intentional_overflow(-1);
88317 __u64 ptr[];
88318 };
88319
88320 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
88321 index d876736..ccce5c0 100644
88322 --- a/include/uapi/linux/byteorder/little_endian.h
88323 +++ b/include/uapi/linux/byteorder/little_endian.h
88324 @@ -42,51 +42,51 @@
88325
88326 static inline __le64 __cpu_to_le64p(const __u64 *p)
88327 {
88328 - return (__force __le64)*p;
88329 + return (__force const __le64)*p;
88330 }
88331 -static inline __u64 __le64_to_cpup(const __le64 *p)
88332 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
88333 {
88334 - return (__force __u64)*p;
88335 + return (__force const __u64)*p;
88336 }
88337 static inline __le32 __cpu_to_le32p(const __u32 *p)
88338 {
88339 - return (__force __le32)*p;
88340 + return (__force const __le32)*p;
88341 }
88342 static inline __u32 __le32_to_cpup(const __le32 *p)
88343 {
88344 - return (__force __u32)*p;
88345 + return (__force const __u32)*p;
88346 }
88347 static inline __le16 __cpu_to_le16p(const __u16 *p)
88348 {
88349 - return (__force __le16)*p;
88350 + return (__force const __le16)*p;
88351 }
88352 static inline __u16 __le16_to_cpup(const __le16 *p)
88353 {
88354 - return (__force __u16)*p;
88355 + return (__force const __u16)*p;
88356 }
88357 static inline __be64 __cpu_to_be64p(const __u64 *p)
88358 {
88359 - return (__force __be64)__swab64p(p);
88360 + return (__force const __be64)__swab64p(p);
88361 }
88362 static inline __u64 __be64_to_cpup(const __be64 *p)
88363 {
88364 - return __swab64p((__u64 *)p);
88365 + return __swab64p((const __u64 *)p);
88366 }
88367 static inline __be32 __cpu_to_be32p(const __u32 *p)
88368 {
88369 - return (__force __be32)__swab32p(p);
88370 + return (__force const __be32)__swab32p(p);
88371 }
88372 -static inline __u32 __be32_to_cpup(const __be32 *p)
88373 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
88374 {
88375 - return __swab32p((__u32 *)p);
88376 + return __swab32p((const __u32 *)p);
88377 }
88378 static inline __be16 __cpu_to_be16p(const __u16 *p)
88379 {
88380 - return (__force __be16)__swab16p(p);
88381 + return (__force const __be16)__swab16p(p);
88382 }
88383 static inline __u16 __be16_to_cpup(const __be16 *p)
88384 {
88385 - return __swab16p((__u16 *)p);
88386 + return __swab16p((const __u16 *)p);
88387 }
88388 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
88389 #define __le64_to_cpus(x) do { (void)(x); } while (0)
88390 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
88391 index ef6103b..d4e65dd 100644
88392 --- a/include/uapi/linux/elf.h
88393 +++ b/include/uapi/linux/elf.h
88394 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
88395 #define PT_GNU_EH_FRAME 0x6474e550
88396
88397 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
88398 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
88399 +
88400 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
88401 +
88402 +/* Constants for the e_flags field */
88403 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
88404 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
88405 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
88406 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
88407 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
88408 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
88409
88410 /*
88411 * Extended Numbering
88412 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
88413 #define DT_DEBUG 21
88414 #define DT_TEXTREL 22
88415 #define DT_JMPREL 23
88416 +#define DT_FLAGS 30
88417 + #define DF_TEXTREL 0x00000004
88418 #define DT_ENCODING 32
88419 #define OLD_DT_LOOS 0x60000000
88420 #define DT_LOOS 0x6000000d
88421 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
88422 #define PF_W 0x2
88423 #define PF_X 0x1
88424
88425 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
88426 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
88427 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
88428 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
88429 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
88430 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
88431 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
88432 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
88433 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
88434 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
88435 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
88436 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
88437 +
88438 typedef struct elf32_phdr{
88439 Elf32_Word p_type;
88440 Elf32_Off p_offset;
88441 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
88442 #define EI_OSABI 7
88443 #define EI_PAD 8
88444
88445 +#define EI_PAX 14
88446 +
88447 #define ELFMAG0 0x7f /* EI_MAG */
88448 #define ELFMAG1 'E'
88449 #define ELFMAG2 'L'
88450 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
88451 index aa169c4..6a2771d 100644
88452 --- a/include/uapi/linux/personality.h
88453 +++ b/include/uapi/linux/personality.h
88454 @@ -30,6 +30,7 @@ enum {
88455 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
88456 ADDR_NO_RANDOMIZE | \
88457 ADDR_COMPAT_LAYOUT | \
88458 + ADDR_LIMIT_3GB | \
88459 MMAP_PAGE_ZERO)
88460
88461 /*
88462 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
88463 index 7530e74..e714828 100644
88464 --- a/include/uapi/linux/screen_info.h
88465 +++ b/include/uapi/linux/screen_info.h
88466 @@ -43,7 +43,8 @@ struct screen_info {
88467 __u16 pages; /* 0x32 */
88468 __u16 vesa_attributes; /* 0x34 */
88469 __u32 capabilities; /* 0x36 */
88470 - __u8 _reserved[6]; /* 0x3a */
88471 + __u16 vesapm_size; /* 0x3a */
88472 + __u8 _reserved[4]; /* 0x3c */
88473 } __attribute__((packed));
88474
88475 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
88476 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
88477 index 0e011eb..82681b1 100644
88478 --- a/include/uapi/linux/swab.h
88479 +++ b/include/uapi/linux/swab.h
88480 @@ -43,7 +43,7 @@
88481 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
88482 */
88483
88484 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
88485 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
88486 {
88487 #ifdef __HAVE_BUILTIN_BSWAP16__
88488 return __builtin_bswap16(val);
88489 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
88490 #endif
88491 }
88492
88493 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
88494 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
88495 {
88496 #ifdef __HAVE_BUILTIN_BSWAP32__
88497 return __builtin_bswap32(val);
88498 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
88499 #endif
88500 }
88501
88502 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
88503 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
88504 {
88505 #ifdef __HAVE_BUILTIN_BSWAP64__
88506 return __builtin_bswap64(val);
88507 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
88508 index 6d67213..552fdd9 100644
88509 --- a/include/uapi/linux/sysctl.h
88510 +++ b/include/uapi/linux/sysctl.h
88511 @@ -155,8 +155,6 @@ enum
88512 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
88513 };
88514
88515 -
88516 -
88517 /* CTL_VM names: */
88518 enum
88519 {
88520 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
88521 index 168ff50..a921df2 100644
88522 --- a/include/uapi/linux/videodev2.h
88523 +++ b/include/uapi/linux/videodev2.h
88524 @@ -1253,7 +1253,7 @@ struct v4l2_ext_control {
88525 union {
88526 __s32 value;
88527 __s64 value64;
88528 - char *string;
88529 + char __user *string;
88530 };
88531 } __attribute__ ((packed));
88532
88533 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
88534 index c38355c..17a57bc 100644
88535 --- a/include/uapi/linux/xattr.h
88536 +++ b/include/uapi/linux/xattr.h
88537 @@ -73,5 +73,9 @@
88538 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
88539 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
88540
88541 +/* User namespace */
88542 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
88543 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
88544 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
88545
88546 #endif /* _UAPI_LINUX_XATTR_H */
88547 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
88548 index f9466fa..f4e2b81 100644
88549 --- a/include/video/udlfb.h
88550 +++ b/include/video/udlfb.h
88551 @@ -53,10 +53,10 @@ struct dlfb_data {
88552 u32 pseudo_palette[256];
88553 int blank_mode; /*one of FB_BLANK_ */
88554 /* blit-only rendering path metrics, exposed through sysfs */
88555 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
88556 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
88557 - atomic_t bytes_sent; /* to usb, after compression including overhead */
88558 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
88559 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
88560 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
88561 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
88562 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
88563 };
88564
88565 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
88566 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
88567 index 30f5362..8ed8ac9 100644
88568 --- a/include/video/uvesafb.h
88569 +++ b/include/video/uvesafb.h
88570 @@ -122,6 +122,7 @@ struct uvesafb_par {
88571 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
88572 u8 pmi_setpal; /* PMI for palette changes */
88573 u16 *pmi_base; /* protected mode interface location */
88574 + u8 *pmi_code; /* protected mode code location */
88575 void *pmi_start;
88576 void *pmi_pal;
88577 u8 *vbe_state_orig; /*
88578 diff --git a/init/Kconfig b/init/Kconfig
88579 index 9d76b99..d378b1e 100644
88580 --- a/init/Kconfig
88581 +++ b/init/Kconfig
88582 @@ -1105,6 +1105,7 @@ endif # CGROUPS
88583
88584 config CHECKPOINT_RESTORE
88585 bool "Checkpoint/restore support" if EXPERT
88586 + depends on !GRKERNSEC
88587 default n
88588 help
88589 Enables additional kernel features in a sake of checkpoint/restore.
88590 @@ -1589,7 +1590,7 @@ config SLUB_DEBUG
88591
88592 config COMPAT_BRK
88593 bool "Disable heap randomization"
88594 - default y
88595 + default n
88596 help
88597 Randomizing heap placement makes heap exploits harder, but it
88598 also breaks ancient binaries (including anything libc5 based).
88599 @@ -1877,7 +1878,7 @@ config INIT_ALL_POSSIBLE
88600 config STOP_MACHINE
88601 bool
88602 default y
88603 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
88604 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
88605 help
88606 Need stop_machine() primitive.
88607
88608 diff --git a/init/Makefile b/init/Makefile
88609 index 7bc47ee..6da2dc7 100644
88610 --- a/init/Makefile
88611 +++ b/init/Makefile
88612 @@ -2,6 +2,9 @@
88613 # Makefile for the linux kernel.
88614 #
88615
88616 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
88617 +asflags-y := $(GCC_PLUGINS_AFLAGS)
88618 +
88619 obj-y := main.o version.o mounts.o
88620 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
88621 obj-y += noinitramfs.o
88622 diff --git a/init/do_mounts.c b/init/do_mounts.c
88623 index 82f2288..ea1430a 100644
88624 --- a/init/do_mounts.c
88625 +++ b/init/do_mounts.c
88626 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
88627 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
88628 {
88629 struct super_block *s;
88630 - int err = sys_mount(name, "/root", fs, flags, data);
88631 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
88632 if (err)
88633 return err;
88634
88635 - sys_chdir("/root");
88636 + sys_chdir((const char __force_user *)"/root");
88637 s = current->fs->pwd.dentry->d_sb;
88638 ROOT_DEV = s->s_dev;
88639 printk(KERN_INFO
88640 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
88641 va_start(args, fmt);
88642 vsprintf(buf, fmt, args);
88643 va_end(args);
88644 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
88645 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
88646 if (fd >= 0) {
88647 sys_ioctl(fd, FDEJECT, 0);
88648 sys_close(fd);
88649 }
88650 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
88651 - fd = sys_open("/dev/console", O_RDWR, 0);
88652 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
88653 if (fd >= 0) {
88654 sys_ioctl(fd, TCGETS, (long)&termios);
88655 termios.c_lflag &= ~ICANON;
88656 sys_ioctl(fd, TCSETSF, (long)&termios);
88657 - sys_read(fd, &c, 1);
88658 + sys_read(fd, (char __user *)&c, 1);
88659 termios.c_lflag |= ICANON;
88660 sys_ioctl(fd, TCSETSF, (long)&termios);
88661 sys_close(fd);
88662 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
88663 mount_root();
88664 out:
88665 devtmpfs_mount("dev");
88666 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
88667 - sys_chroot(".");
88668 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
88669 + sys_chroot((const char __force_user *)".");
88670 }
88671
88672 static bool is_tmpfs;
88673 diff --git a/init/do_mounts.h b/init/do_mounts.h
88674 index f5b978a..69dbfe8 100644
88675 --- a/init/do_mounts.h
88676 +++ b/init/do_mounts.h
88677 @@ -15,15 +15,15 @@ extern int root_mountflags;
88678
88679 static inline int create_dev(char *name, dev_t dev)
88680 {
88681 - sys_unlink(name);
88682 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
88683 + sys_unlink((char __force_user *)name);
88684 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
88685 }
88686
88687 #if BITS_PER_LONG == 32
88688 static inline u32 bstat(char *name)
88689 {
88690 struct stat64 stat;
88691 - if (sys_stat64(name, &stat) != 0)
88692 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
88693 return 0;
88694 if (!S_ISBLK(stat.st_mode))
88695 return 0;
88696 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
88697 static inline u32 bstat(char *name)
88698 {
88699 struct stat stat;
88700 - if (sys_newstat(name, &stat) != 0)
88701 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
88702 return 0;
88703 if (!S_ISBLK(stat.st_mode))
88704 return 0;
88705 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
88706 index 3e0878e..8a9d7a0 100644
88707 --- a/init/do_mounts_initrd.c
88708 +++ b/init/do_mounts_initrd.c
88709 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
88710 {
88711 sys_unshare(CLONE_FS | CLONE_FILES);
88712 /* stdin/stdout/stderr for /linuxrc */
88713 - sys_open("/dev/console", O_RDWR, 0);
88714 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
88715 sys_dup(0);
88716 sys_dup(0);
88717 /* move initrd over / and chdir/chroot in initrd root */
88718 - sys_chdir("/root");
88719 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
88720 - sys_chroot(".");
88721 + sys_chdir((const char __force_user *)"/root");
88722 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
88723 + sys_chroot((const char __force_user *)".");
88724 sys_setsid();
88725 return 0;
88726 }
88727 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
88728 create_dev("/dev/root.old", Root_RAM0);
88729 /* mount initrd on rootfs' /root */
88730 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
88731 - sys_mkdir("/old", 0700);
88732 - sys_chdir("/old");
88733 + sys_mkdir((const char __force_user *)"/old", 0700);
88734 + sys_chdir((const char __force_user *)"/old");
88735
88736 /* try loading default modules from initrd */
88737 load_default_modules();
88738 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
88739 current->flags &= ~PF_FREEZER_SKIP;
88740
88741 /* move initrd to rootfs' /old */
88742 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
88743 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
88744 /* switch root and cwd back to / of rootfs */
88745 - sys_chroot("..");
88746 + sys_chroot((const char __force_user *)"..");
88747
88748 if (new_decode_dev(real_root_dev) == Root_RAM0) {
88749 - sys_chdir("/old");
88750 + sys_chdir((const char __force_user *)"/old");
88751 return;
88752 }
88753
88754 - sys_chdir("/");
88755 + sys_chdir((const char __force_user *)"/");
88756 ROOT_DEV = new_decode_dev(real_root_dev);
88757 mount_root();
88758
88759 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
88760 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
88761 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
88762 if (!error)
88763 printk("okay\n");
88764 else {
88765 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
88766 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
88767 if (error == -ENOENT)
88768 printk("/initrd does not exist. Ignored.\n");
88769 else
88770 printk("failed\n");
88771 printk(KERN_NOTICE "Unmounting old root\n");
88772 - sys_umount("/old", MNT_DETACH);
88773 + sys_umount((char __force_user *)"/old", MNT_DETACH);
88774 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
88775 if (fd < 0) {
88776 error = fd;
88777 @@ -127,11 +127,11 @@ int __init initrd_load(void)
88778 * mounted in the normal path.
88779 */
88780 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
88781 - sys_unlink("/initrd.image");
88782 + sys_unlink((const char __force_user *)"/initrd.image");
88783 handle_initrd();
88784 return 1;
88785 }
88786 }
88787 - sys_unlink("/initrd.image");
88788 + sys_unlink((const char __force_user *)"/initrd.image");
88789 return 0;
88790 }
88791 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
88792 index 8cb6db5..d729f50 100644
88793 --- a/init/do_mounts_md.c
88794 +++ b/init/do_mounts_md.c
88795 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
88796 partitioned ? "_d" : "", minor,
88797 md_setup_args[ent].device_names);
88798
88799 - fd = sys_open(name, 0, 0);
88800 + fd = sys_open((char __force_user *)name, 0, 0);
88801 if (fd < 0) {
88802 printk(KERN_ERR "md: open failed - cannot start "
88803 "array %s\n", name);
88804 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
88805 * array without it
88806 */
88807 sys_close(fd);
88808 - fd = sys_open(name, 0, 0);
88809 + fd = sys_open((char __force_user *)name, 0, 0);
88810 sys_ioctl(fd, BLKRRPART, 0);
88811 }
88812 sys_close(fd);
88813 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
88814
88815 wait_for_device_probe();
88816
88817 - fd = sys_open("/dev/md0", 0, 0);
88818 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
88819 if (fd >= 0) {
88820 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
88821 sys_close(fd);
88822 diff --git a/init/init_task.c b/init/init_task.c
88823 index ba0a7f36..2bcf1d5 100644
88824 --- a/init/init_task.c
88825 +++ b/init/init_task.c
88826 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
88827 * Initial thread structure. Alignment of this is handled by a special
88828 * linker map entry.
88829 */
88830 +#ifdef CONFIG_X86
88831 +union thread_union init_thread_union __init_task_data;
88832 +#else
88833 union thread_union init_thread_union __init_task_data =
88834 { INIT_THREAD_INFO(init_task) };
88835 +#endif
88836 diff --git a/init/initramfs.c b/init/initramfs.c
88837 index a8497fa..35b3c90 100644
88838 --- a/init/initramfs.c
88839 +++ b/init/initramfs.c
88840 @@ -84,7 +84,7 @@ static void __init free_hash(void)
88841 }
88842 }
88843
88844 -static long __init do_utime(char *filename, time_t mtime)
88845 +static long __init do_utime(char __force_user *filename, time_t mtime)
88846 {
88847 struct timespec t[2];
88848
88849 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
88850 struct dir_entry *de, *tmp;
88851 list_for_each_entry_safe(de, tmp, &dir_list, list) {
88852 list_del(&de->list);
88853 - do_utime(de->name, de->mtime);
88854 + do_utime((char __force_user *)de->name, de->mtime);
88855 kfree(de->name);
88856 kfree(de);
88857 }
88858 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
88859 if (nlink >= 2) {
88860 char *old = find_link(major, minor, ino, mode, collected);
88861 if (old)
88862 - return (sys_link(old, collected) < 0) ? -1 : 1;
88863 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
88864 }
88865 return 0;
88866 }
88867 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
88868 {
88869 struct stat st;
88870
88871 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
88872 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
88873 if (S_ISDIR(st.st_mode))
88874 - sys_rmdir(path);
88875 + sys_rmdir((char __force_user *)path);
88876 else
88877 - sys_unlink(path);
88878 + sys_unlink((char __force_user *)path);
88879 }
88880 }
88881
88882 @@ -315,7 +315,7 @@ static int __init do_name(void)
88883 int openflags = O_WRONLY|O_CREAT;
88884 if (ml != 1)
88885 openflags |= O_TRUNC;
88886 - wfd = sys_open(collected, openflags, mode);
88887 + wfd = sys_open((char __force_user *)collected, openflags, mode);
88888
88889 if (wfd >= 0) {
88890 sys_fchown(wfd, uid, gid);
88891 @@ -327,17 +327,17 @@ static int __init do_name(void)
88892 }
88893 }
88894 } else if (S_ISDIR(mode)) {
88895 - sys_mkdir(collected, mode);
88896 - sys_chown(collected, uid, gid);
88897 - sys_chmod(collected, mode);
88898 + sys_mkdir((char __force_user *)collected, mode);
88899 + sys_chown((char __force_user *)collected, uid, gid);
88900 + sys_chmod((char __force_user *)collected, mode);
88901 dir_add(collected, mtime);
88902 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
88903 S_ISFIFO(mode) || S_ISSOCK(mode)) {
88904 if (maybe_link() == 0) {
88905 - sys_mknod(collected, mode, rdev);
88906 - sys_chown(collected, uid, gid);
88907 - sys_chmod(collected, mode);
88908 - do_utime(collected, mtime);
88909 + sys_mknod((char __force_user *)collected, mode, rdev);
88910 + sys_chown((char __force_user *)collected, uid, gid);
88911 + sys_chmod((char __force_user *)collected, mode);
88912 + do_utime((char __force_user *)collected, mtime);
88913 }
88914 }
88915 return 0;
88916 @@ -346,15 +346,15 @@ static int __init do_name(void)
88917 static int __init do_copy(void)
88918 {
88919 if (count >= body_len) {
88920 - sys_write(wfd, victim, body_len);
88921 + sys_write(wfd, (char __force_user *)victim, body_len);
88922 sys_close(wfd);
88923 - do_utime(vcollected, mtime);
88924 + do_utime((char __force_user *)vcollected, mtime);
88925 kfree(vcollected);
88926 eat(body_len);
88927 state = SkipIt;
88928 return 0;
88929 } else {
88930 - sys_write(wfd, victim, count);
88931 + sys_write(wfd, (char __force_user *)victim, count);
88932 body_len -= count;
88933 eat(count);
88934 return 1;
88935 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
88936 {
88937 collected[N_ALIGN(name_len) + body_len] = '\0';
88938 clean_path(collected, 0);
88939 - sys_symlink(collected + N_ALIGN(name_len), collected);
88940 - sys_lchown(collected, uid, gid);
88941 - do_utime(collected, mtime);
88942 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
88943 + sys_lchown((char __force_user *)collected, uid, gid);
88944 + do_utime((char __force_user *)collected, mtime);
88945 state = SkipIt;
88946 next_state = Reset;
88947 return 0;
88948 diff --git a/init/main.c b/init/main.c
88949 index e8ae1fe..f60f98c 100644
88950 --- a/init/main.c
88951 +++ b/init/main.c
88952 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
88953 static inline void mark_rodata_ro(void) { }
88954 #endif
88955
88956 +extern void grsecurity_init(void);
88957 +
88958 /*
88959 * Debug helper: via this flag we know that we are in 'early bootup code'
88960 * where only the boot processor is running with IRQ disabled. This means
88961 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
88962
88963 __setup("reset_devices", set_reset_devices);
88964
88965 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
88966 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
88967 +static int __init setup_grsec_proc_gid(char *str)
88968 +{
88969 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
88970 + return 1;
88971 +}
88972 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
88973 +#endif
88974 +
88975 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
88976 +unsigned long pax_user_shadow_base __read_only;
88977 +EXPORT_SYMBOL(pax_user_shadow_base);
88978 +extern char pax_enter_kernel_user[];
88979 +extern char pax_exit_kernel_user[];
88980 +#endif
88981 +
88982 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
88983 +static int __init setup_pax_nouderef(char *str)
88984 +{
88985 +#ifdef CONFIG_X86_32
88986 + unsigned int cpu;
88987 + struct desc_struct *gdt;
88988 +
88989 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
88990 + gdt = get_cpu_gdt_table(cpu);
88991 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
88992 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
88993 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
88994 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
88995 + }
88996 + loadsegment(ds, __KERNEL_DS);
88997 + loadsegment(es, __KERNEL_DS);
88998 + loadsegment(ss, __KERNEL_DS);
88999 +#else
89000 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
89001 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
89002 + clone_pgd_mask = ~(pgdval_t)0UL;
89003 + pax_user_shadow_base = 0UL;
89004 + setup_clear_cpu_cap(X86_FEATURE_PCID);
89005 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
89006 +#endif
89007 +
89008 + return 0;
89009 +}
89010 +early_param("pax_nouderef", setup_pax_nouderef);
89011 +
89012 +#ifdef CONFIG_X86_64
89013 +static int __init setup_pax_weakuderef(char *str)
89014 +{
89015 + if (clone_pgd_mask != ~(pgdval_t)0UL)
89016 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
89017 + return 1;
89018 +}
89019 +__setup("pax_weakuderef", setup_pax_weakuderef);
89020 +#endif
89021 +#endif
89022 +
89023 +#ifdef CONFIG_PAX_SOFTMODE
89024 +int pax_softmode;
89025 +
89026 +static int __init setup_pax_softmode(char *str)
89027 +{
89028 + get_option(&str, &pax_softmode);
89029 + return 1;
89030 +}
89031 +__setup("pax_softmode=", setup_pax_softmode);
89032 +#endif
89033 +
89034 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
89035 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
89036 static const char *panic_later, *panic_param;
89037 @@ -727,7 +798,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
89038 struct blacklist_entry *entry;
89039 char *fn_name;
89040
89041 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
89042 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
89043 if (!fn_name)
89044 return false;
89045
89046 @@ -779,7 +850,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
89047 {
89048 int count = preempt_count();
89049 int ret;
89050 - char msgbuf[64];
89051 + const char *msg1 = "", *msg2 = "";
89052
89053 if (initcall_blacklisted(fn))
89054 return -EPERM;
89055 @@ -789,18 +860,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
89056 else
89057 ret = fn();
89058
89059 - msgbuf[0] = 0;
89060 -
89061 if (preempt_count() != count) {
89062 - sprintf(msgbuf, "preemption imbalance ");
89063 + msg1 = " preemption imbalance";
89064 preempt_count_set(count);
89065 }
89066 if (irqs_disabled()) {
89067 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
89068 + msg2 = " disabled interrupts";
89069 local_irq_enable();
89070 }
89071 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
89072 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
89073
89074 + add_latent_entropy();
89075 return ret;
89076 }
89077
89078 @@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
89079 {
89080 argv_init[0] = init_filename;
89081 return do_execve(getname_kernel(init_filename),
89082 - (const char __user *const __user *)argv_init,
89083 - (const char __user *const __user *)envp_init);
89084 + (const char __user *const __force_user *)argv_init,
89085 + (const char __user *const __force_user *)envp_init);
89086 }
89087
89088 static int try_to_run_init_process(const char *init_filename)
89089 @@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
89090 return ret;
89091 }
89092
89093 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
89094 +extern int gr_init_ran;
89095 +#endif
89096 +
89097 static noinline void __init kernel_init_freeable(void);
89098
89099 static int __ref kernel_init(void *unused)
89100 @@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
89101 ramdisk_execute_command, ret);
89102 }
89103
89104 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
89105 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
89106 + gr_init_ran = 1;
89107 +#endif
89108 +
89109 /*
89110 * We try each of these until one succeeds.
89111 *
89112 @@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
89113 do_basic_setup();
89114
89115 /* Open the /dev/console on the rootfs, this should never fail */
89116 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
89117 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
89118 pr_err("Warning: unable to open an initial console.\n");
89119
89120 (void) sys_dup(0);
89121 @@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
89122 if (!ramdisk_execute_command)
89123 ramdisk_execute_command = "/init";
89124
89125 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
89126 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
89127 ramdisk_execute_command = NULL;
89128 prepare_namespace();
89129 }
89130
89131 + grsecurity_init();
89132 +
89133 /*
89134 * Ok, we have completed the initial bootup, and
89135 * we're essentially up and running. Get rid of the
89136 diff --git a/ipc/compat.c b/ipc/compat.c
89137 index b5ef4f7..ff31d87 100644
89138 --- a/ipc/compat.c
89139 +++ b/ipc/compat.c
89140 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
89141 COMPAT_SHMLBA);
89142 if (err < 0)
89143 return err;
89144 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
89145 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
89146 }
89147 case SHMDT:
89148 return sys_shmdt(compat_ptr(ptr));
89149 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
89150 index c3f0326..d4e0579 100644
89151 --- a/ipc/ipc_sysctl.c
89152 +++ b/ipc/ipc_sysctl.c
89153 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
89154 static int proc_ipc_dointvec(struct ctl_table *table, int write,
89155 void __user *buffer, size_t *lenp, loff_t *ppos)
89156 {
89157 - struct ctl_table ipc_table;
89158 + ctl_table_no_const ipc_table;
89159
89160 memcpy(&ipc_table, table, sizeof(ipc_table));
89161 ipc_table.data = get_ipc(table);
89162 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
89163 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
89164 void __user *buffer, size_t *lenp, loff_t *ppos)
89165 {
89166 - struct ctl_table ipc_table;
89167 + ctl_table_no_const ipc_table;
89168
89169 memcpy(&ipc_table, table, sizeof(ipc_table));
89170 ipc_table.data = get_ipc(table);
89171 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
89172 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
89173 void __user *buffer, size_t *lenp, loff_t *ppos)
89174 {
89175 - struct ctl_table ipc_table;
89176 + ctl_table_no_const ipc_table;
89177 size_t lenp_bef = *lenp;
89178 int rc;
89179
89180 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
89181 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
89182 void __user *buffer, size_t *lenp, loff_t *ppos)
89183 {
89184 - struct ctl_table ipc_table;
89185 + ctl_table_no_const ipc_table;
89186 memcpy(&ipc_table, table, sizeof(ipc_table));
89187 ipc_table.data = get_ipc(table);
89188
89189 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
89190 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
89191 void __user *buffer, size_t *lenp, loff_t *ppos)
89192 {
89193 - struct ctl_table ipc_table;
89194 + ctl_table_no_const ipc_table;
89195 size_t lenp_bef = *lenp;
89196 int oldval;
89197 int rc;
89198 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
89199 index 68d4e95..1477ded 100644
89200 --- a/ipc/mq_sysctl.c
89201 +++ b/ipc/mq_sysctl.c
89202 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
89203 static int proc_mq_dointvec(struct ctl_table *table, int write,
89204 void __user *buffer, size_t *lenp, loff_t *ppos)
89205 {
89206 - struct ctl_table mq_table;
89207 + ctl_table_no_const mq_table;
89208 memcpy(&mq_table, table, sizeof(mq_table));
89209 mq_table.data = get_mq(table);
89210
89211 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
89212 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
89213 void __user *buffer, size_t *lenp, loff_t *ppos)
89214 {
89215 - struct ctl_table mq_table;
89216 + ctl_table_no_const mq_table;
89217 memcpy(&mq_table, table, sizeof(mq_table));
89218 mq_table.data = get_mq(table);
89219
89220 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
89221 index 4fcf39a..d3cc2ec 100644
89222 --- a/ipc/mqueue.c
89223 +++ b/ipc/mqueue.c
89224 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
89225 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
89226 info->attr.mq_msgsize);
89227
89228 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
89229 spin_lock(&mq_lock);
89230 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
89231 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
89232 diff --git a/ipc/shm.c b/ipc/shm.c
89233 index 89fc354..cf56786 100644
89234 --- a/ipc/shm.c
89235 +++ b/ipc/shm.c
89236 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
89237 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
89238 #endif
89239
89240 +#ifdef CONFIG_GRKERNSEC
89241 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
89242 + const time_t shm_createtime, const kuid_t cuid,
89243 + const int shmid);
89244 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
89245 + const time_t shm_createtime);
89246 +#endif
89247 +
89248 void shm_init_ns(struct ipc_namespace *ns)
89249 {
89250 ns->shm_ctlmax = SHMMAX;
89251 @@ -557,6 +565,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
89252 shp->shm_lprid = 0;
89253 shp->shm_atim = shp->shm_dtim = 0;
89254 shp->shm_ctim = get_seconds();
89255 +#ifdef CONFIG_GRKERNSEC
89256 + {
89257 + struct timespec timeval;
89258 + do_posix_clock_monotonic_gettime(&timeval);
89259 +
89260 + shp->shm_createtime = timeval.tv_sec;
89261 + }
89262 +#endif
89263 shp->shm_segsz = size;
89264 shp->shm_nattch = 0;
89265 shp->shm_file = file;
89266 @@ -1092,6 +1108,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
89267 f_mode = FMODE_READ | FMODE_WRITE;
89268 }
89269 if (shmflg & SHM_EXEC) {
89270 +
89271 +#ifdef CONFIG_PAX_MPROTECT
89272 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
89273 + goto out;
89274 +#endif
89275 +
89276 prot |= PROT_EXEC;
89277 acc_mode |= S_IXUGO;
89278 }
89279 @@ -1116,6 +1138,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
89280 if (err)
89281 goto out_unlock;
89282
89283 +#ifdef CONFIG_GRKERNSEC
89284 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
89285 + shp->shm_perm.cuid, shmid) ||
89286 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
89287 + err = -EACCES;
89288 + goto out_unlock;
89289 + }
89290 +#endif
89291 +
89292 ipc_lock_object(&shp->shm_perm);
89293
89294 /* check if shm_destroy() is tearing down shp */
89295 @@ -1128,6 +1159,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
89296 path = shp->shm_file->f_path;
89297 path_get(&path);
89298 shp->shm_nattch++;
89299 +#ifdef CONFIG_GRKERNSEC
89300 + shp->shm_lapid = current->pid;
89301 +#endif
89302 size = i_size_read(path.dentry->d_inode);
89303 ipc_unlock_object(&shp->shm_perm);
89304 rcu_read_unlock();
89305 diff --git a/ipc/util.c b/ipc/util.c
89306 index 27d74e6..8be0be2 100644
89307 --- a/ipc/util.c
89308 +++ b/ipc/util.c
89309 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
89310 int (*show)(struct seq_file *, void *);
89311 };
89312
89313 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
89314 +
89315 static void ipc_memory_notifier(struct work_struct *work)
89316 {
89317 ipcns_notify(IPCNS_MEMCHANGED);
89318 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
89319 granted_mode >>= 6;
89320 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
89321 granted_mode >>= 3;
89322 +
89323 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
89324 + return -1;
89325 +
89326 /* is there some bit set in requested_mode but not in granted_mode? */
89327 if ((requested_mode & ~granted_mode & 0007) &&
89328 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
89329 diff --git a/kernel/acct.c b/kernel/acct.c
89330 index 808a86f..da69695 100644
89331 --- a/kernel/acct.c
89332 +++ b/kernel/acct.c
89333 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
89334 */
89335 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
89336 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
89337 - file->f_op->write(file, (char *)&ac,
89338 + file->f_op->write(file, (char __force_user *)&ac,
89339 sizeof(acct_t), &file->f_pos);
89340 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
89341 set_fs(fs);
89342 diff --git a/kernel/audit.c b/kernel/audit.c
89343 index 3ef2e0e..8873765 100644
89344 --- a/kernel/audit.c
89345 +++ b/kernel/audit.c
89346 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
89347 3) suppressed due to audit_rate_limit
89348 4) suppressed due to audit_backlog_limit
89349 */
89350 -static atomic_t audit_lost = ATOMIC_INIT(0);
89351 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
89352
89353 /* The netlink socket. */
89354 static struct sock *audit_sock;
89355 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
89356 unsigned long now;
89357 int print;
89358
89359 - atomic_inc(&audit_lost);
89360 + atomic_inc_unchecked(&audit_lost);
89361
89362 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
89363
89364 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
89365 if (print) {
89366 if (printk_ratelimit())
89367 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
89368 - atomic_read(&audit_lost),
89369 + atomic_read_unchecked(&audit_lost),
89370 audit_rate_limit,
89371 audit_backlog_limit);
89372 audit_panic(message);
89373 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
89374 s.pid = audit_pid;
89375 s.rate_limit = audit_rate_limit;
89376 s.backlog_limit = audit_backlog_limit;
89377 - s.lost = atomic_read(&audit_lost);
89378 + s.lost = atomic_read_unchecked(&audit_lost);
89379 s.backlog = skb_queue_len(&audit_skb_queue);
89380 s.version = AUDIT_VERSION_LATEST;
89381 s.backlog_wait_time = audit_backlog_wait_time;
89382 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
89383 index 21eae3c..66db239 100644
89384 --- a/kernel/auditsc.c
89385 +++ b/kernel/auditsc.c
89386 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
89387 }
89388
89389 /* global counter which is incremented every time something logs in */
89390 -static atomic_t session_id = ATOMIC_INIT(0);
89391 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
89392
89393 static int audit_set_loginuid_perm(kuid_t loginuid)
89394 {
89395 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
89396
89397 /* are we setting or clearing? */
89398 if (uid_valid(loginuid))
89399 - sessionid = (unsigned int)atomic_inc_return(&session_id);
89400 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
89401
89402 task->sessionid = sessionid;
89403 task->loginuid = loginuid;
89404 diff --git a/kernel/capability.c b/kernel/capability.c
89405 index a5cf13c..07a2647 100644
89406 --- a/kernel/capability.c
89407 +++ b/kernel/capability.c
89408 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
89409 * before modification is attempted and the application
89410 * fails.
89411 */
89412 + if (tocopy > ARRAY_SIZE(kdata))
89413 + return -EFAULT;
89414 +
89415 if (copy_to_user(dataptr, kdata, tocopy
89416 * sizeof(struct __user_cap_data_struct))) {
89417 return -EFAULT;
89418 @@ -293,10 +296,11 @@ bool has_ns_capability(struct task_struct *t,
89419 int ret;
89420
89421 rcu_read_lock();
89422 - ret = security_capable(__task_cred(t), ns, cap);
89423 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
89424 + gr_task_is_capable(t, __task_cred(t), cap);
89425 rcu_read_unlock();
89426
89427 - return (ret == 0);
89428 + return ret;
89429 }
89430
89431 /**
89432 @@ -333,10 +337,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
89433 int ret;
89434
89435 rcu_read_lock();
89436 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
89437 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
89438 rcu_read_unlock();
89439
89440 - return (ret == 0);
89441 + return ret;
89442 }
89443
89444 /**
89445 @@ -374,7 +378,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
89446 BUG();
89447 }
89448
89449 - if (security_capable(current_cred(), ns, cap) == 0) {
89450 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
89451 current->flags |= PF_SUPERPRIV;
89452 return true;
89453 }
89454 @@ -382,6 +386,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
89455 }
89456 EXPORT_SYMBOL(ns_capable);
89457
89458 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
89459 +{
89460 + if (unlikely(!cap_valid(cap))) {
89461 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
89462 + BUG();
89463 + }
89464 +
89465 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
89466 + current->flags |= PF_SUPERPRIV;
89467 + return true;
89468 + }
89469 + return false;
89470 +}
89471 +EXPORT_SYMBOL(ns_capable_nolog);
89472 +
89473 /**
89474 * file_ns_capable - Determine if the file's opener had a capability in effect
89475 * @file: The file we want to check
89476 @@ -423,6 +442,12 @@ bool capable(int cap)
89477 }
89478 EXPORT_SYMBOL(capable);
89479
89480 +bool capable_nolog(int cap)
89481 +{
89482 + return ns_capable_nolog(&init_user_ns, cap);
89483 +}
89484 +EXPORT_SYMBOL(capable_nolog);
89485 +
89486 /**
89487 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
89488 * @inode: The inode in question
89489 @@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
89490 kgid_has_mapping(ns, inode->i_gid);
89491 }
89492 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
89493 +
89494 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
89495 +{
89496 + struct user_namespace *ns = current_user_ns();
89497 +
89498 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
89499 + kgid_has_mapping(ns, inode->i_gid);
89500 +}
89501 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
89502 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
89503 index 70776ae..09c4988 100644
89504 --- a/kernel/cgroup.c
89505 +++ b/kernel/cgroup.c
89506 @@ -5146,6 +5146,14 @@ static void cgroup_release_agent(struct work_struct *work)
89507 release_list);
89508 list_del_init(&cgrp->release_list);
89509 raw_spin_unlock(&release_list_lock);
89510 +
89511 + /*
89512 + * don't bother calling call_usermodehelper if we haven't
89513 + * configured a binary to execute
89514 + */
89515 + if (cgrp->root->release_agent_path[0] == '\0')
89516 + goto continue_free;
89517 +
89518 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
89519 if (!pathbuf)
89520 goto continue_free;
89521 @@ -5336,7 +5344,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
89522 struct task_struct *task;
89523 int count = 0;
89524
89525 - seq_printf(seq, "css_set %p\n", cset);
89526 + seq_printf(seq, "css_set %pK\n", cset);
89527
89528 list_for_each_entry(task, &cset->tasks, cg_list) {
89529 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
89530 diff --git a/kernel/compat.c b/kernel/compat.c
89531 index 633394f..bdfa969 100644
89532 --- a/kernel/compat.c
89533 +++ b/kernel/compat.c
89534 @@ -13,6 +13,7 @@
89535
89536 #include <linux/linkage.h>
89537 #include <linux/compat.h>
89538 +#include <linux/module.h>
89539 #include <linux/errno.h>
89540 #include <linux/time.h>
89541 #include <linux/signal.h>
89542 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
89543 mm_segment_t oldfs;
89544 long ret;
89545
89546 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
89547 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
89548 oldfs = get_fs();
89549 set_fs(KERNEL_DS);
89550 ret = hrtimer_nanosleep_restart(restart);
89551 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
89552 oldfs = get_fs();
89553 set_fs(KERNEL_DS);
89554 ret = hrtimer_nanosleep(&tu,
89555 - rmtp ? (struct timespec __user *)&rmt : NULL,
89556 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
89557 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
89558 set_fs(oldfs);
89559
89560 @@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
89561 mm_segment_t old_fs = get_fs();
89562
89563 set_fs(KERNEL_DS);
89564 - ret = sys_sigpending((old_sigset_t __user *) &s);
89565 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
89566 set_fs(old_fs);
89567 if (ret == 0)
89568 ret = put_user(s, set);
89569 @@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
89570 mm_segment_t old_fs = get_fs();
89571
89572 set_fs(KERNEL_DS);
89573 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
89574 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
89575 set_fs(old_fs);
89576
89577 if (!ret) {
89578 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
89579 set_fs (KERNEL_DS);
89580 ret = sys_wait4(pid,
89581 (stat_addr ?
89582 - (unsigned int __user *) &status : NULL),
89583 - options, (struct rusage __user *) &r);
89584 + (unsigned int __force_user *) &status : NULL),
89585 + options, (struct rusage __force_user *) &r);
89586 set_fs (old_fs);
89587
89588 if (ret > 0) {
89589 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
89590 memset(&info, 0, sizeof(info));
89591
89592 set_fs(KERNEL_DS);
89593 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
89594 - uru ? (struct rusage __user *)&ru : NULL);
89595 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
89596 + uru ? (struct rusage __force_user *)&ru : NULL);
89597 set_fs(old_fs);
89598
89599 if ((ret < 0) || (info.si_signo == 0))
89600 @@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
89601 oldfs = get_fs();
89602 set_fs(KERNEL_DS);
89603 err = sys_timer_settime(timer_id, flags,
89604 - (struct itimerspec __user *) &newts,
89605 - (struct itimerspec __user *) &oldts);
89606 + (struct itimerspec __force_user *) &newts,
89607 + (struct itimerspec __force_user *) &oldts);
89608 set_fs(oldfs);
89609 if (!err && old && put_compat_itimerspec(old, &oldts))
89610 return -EFAULT;
89611 @@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
89612 oldfs = get_fs();
89613 set_fs(KERNEL_DS);
89614 err = sys_timer_gettime(timer_id,
89615 - (struct itimerspec __user *) &ts);
89616 + (struct itimerspec __force_user *) &ts);
89617 set_fs(oldfs);
89618 if (!err && put_compat_itimerspec(setting, &ts))
89619 return -EFAULT;
89620 @@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
89621 oldfs = get_fs();
89622 set_fs(KERNEL_DS);
89623 err = sys_clock_settime(which_clock,
89624 - (struct timespec __user *) &ts);
89625 + (struct timespec __force_user *) &ts);
89626 set_fs(oldfs);
89627 return err;
89628 }
89629 @@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
89630 oldfs = get_fs();
89631 set_fs(KERNEL_DS);
89632 err = sys_clock_gettime(which_clock,
89633 - (struct timespec __user *) &ts);
89634 + (struct timespec __force_user *) &ts);
89635 set_fs(oldfs);
89636 if (!err && compat_put_timespec(&ts, tp))
89637 return -EFAULT;
89638 @@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
89639
89640 oldfs = get_fs();
89641 set_fs(KERNEL_DS);
89642 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
89643 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
89644 set_fs(oldfs);
89645
89646 err = compat_put_timex(utp, &txc);
89647 @@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
89648 oldfs = get_fs();
89649 set_fs(KERNEL_DS);
89650 err = sys_clock_getres(which_clock,
89651 - (struct timespec __user *) &ts);
89652 + (struct timespec __force_user *) &ts);
89653 set_fs(oldfs);
89654 if (!err && tp && compat_put_timespec(&ts, tp))
89655 return -EFAULT;
89656 @@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
89657 struct timespec tu;
89658 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
89659
89660 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
89661 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
89662 oldfs = get_fs();
89663 set_fs(KERNEL_DS);
89664 err = clock_nanosleep_restart(restart);
89665 @@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
89666 oldfs = get_fs();
89667 set_fs(KERNEL_DS);
89668 err = sys_clock_nanosleep(which_clock, flags,
89669 - (struct timespec __user *) &in,
89670 - (struct timespec __user *) &out);
89671 + (struct timespec __force_user *) &in,
89672 + (struct timespec __force_user *) &out);
89673 set_fs(oldfs);
89674
89675 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
89676 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
89677 mm_segment_t old_fs = get_fs();
89678
89679 set_fs(KERNEL_DS);
89680 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
89681 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
89682 set_fs(old_fs);
89683 if (compat_put_timespec(&t, interval))
89684 return -EFAULT;
89685 diff --git a/kernel/configs.c b/kernel/configs.c
89686 index c18b1f1..b9a0132 100644
89687 --- a/kernel/configs.c
89688 +++ b/kernel/configs.c
89689 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
89690 struct proc_dir_entry *entry;
89691
89692 /* create the current config file */
89693 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
89694 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
89695 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
89696 + &ikconfig_file_ops);
89697 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89698 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
89699 + &ikconfig_file_ops);
89700 +#endif
89701 +#else
89702 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
89703 &ikconfig_file_ops);
89704 +#endif
89705 +
89706 if (!entry)
89707 return -ENOMEM;
89708
89709 diff --git a/kernel/cred.c b/kernel/cred.c
89710 index e0573a4..26c0fd3 100644
89711 --- a/kernel/cred.c
89712 +++ b/kernel/cred.c
89713 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
89714 validate_creds(cred);
89715 alter_cred_subscribers(cred, -1);
89716 put_cred(cred);
89717 +
89718 +#ifdef CONFIG_GRKERNSEC_SETXID
89719 + cred = (struct cred *) tsk->delayed_cred;
89720 + if (cred != NULL) {
89721 + tsk->delayed_cred = NULL;
89722 + validate_creds(cred);
89723 + alter_cred_subscribers(cred, -1);
89724 + put_cred(cred);
89725 + }
89726 +#endif
89727 }
89728
89729 /**
89730 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
89731 * Always returns 0 thus allowing this function to be tail-called at the end
89732 * of, say, sys_setgid().
89733 */
89734 -int commit_creds(struct cred *new)
89735 +static int __commit_creds(struct cred *new)
89736 {
89737 struct task_struct *task = current;
89738 const struct cred *old = task->real_cred;
89739 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
89740
89741 get_cred(new); /* we will require a ref for the subj creds too */
89742
89743 + gr_set_role_label(task, new->uid, new->gid);
89744 +
89745 /* dumpability changes */
89746 if (!uid_eq(old->euid, new->euid) ||
89747 !gid_eq(old->egid, new->egid) ||
89748 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
89749 put_cred(old);
89750 return 0;
89751 }
89752 +#ifdef CONFIG_GRKERNSEC_SETXID
89753 +extern int set_user(struct cred *new);
89754 +
89755 +void gr_delayed_cred_worker(void)
89756 +{
89757 + const struct cred *new = current->delayed_cred;
89758 + struct cred *ncred;
89759 +
89760 + current->delayed_cred = NULL;
89761 +
89762 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
89763 + // from doing get_cred on it when queueing this
89764 + put_cred(new);
89765 + return;
89766 + } else if (new == NULL)
89767 + return;
89768 +
89769 + ncred = prepare_creds();
89770 + if (!ncred)
89771 + goto die;
89772 + // uids
89773 + ncred->uid = new->uid;
89774 + ncred->euid = new->euid;
89775 + ncred->suid = new->suid;
89776 + ncred->fsuid = new->fsuid;
89777 + // gids
89778 + ncred->gid = new->gid;
89779 + ncred->egid = new->egid;
89780 + ncred->sgid = new->sgid;
89781 + ncred->fsgid = new->fsgid;
89782 + // groups
89783 + set_groups(ncred, new->group_info);
89784 + // caps
89785 + ncred->securebits = new->securebits;
89786 + ncred->cap_inheritable = new->cap_inheritable;
89787 + ncred->cap_permitted = new->cap_permitted;
89788 + ncred->cap_effective = new->cap_effective;
89789 + ncred->cap_bset = new->cap_bset;
89790 +
89791 + if (set_user(ncred)) {
89792 + abort_creds(ncred);
89793 + goto die;
89794 + }
89795 +
89796 + // from doing get_cred on it when queueing this
89797 + put_cred(new);
89798 +
89799 + __commit_creds(ncred);
89800 + return;
89801 +die:
89802 + // from doing get_cred on it when queueing this
89803 + put_cred(new);
89804 + do_group_exit(SIGKILL);
89805 +}
89806 +#endif
89807 +
89808 +int commit_creds(struct cred *new)
89809 +{
89810 +#ifdef CONFIG_GRKERNSEC_SETXID
89811 + int ret;
89812 + int schedule_it = 0;
89813 + struct task_struct *t;
89814 + unsigned oldsecurebits = current_cred()->securebits;
89815 +
89816 + /* we won't get called with tasklist_lock held for writing
89817 + and interrupts disabled as the cred struct in that case is
89818 + init_cred
89819 + */
89820 + if (grsec_enable_setxid && !current_is_single_threaded() &&
89821 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
89822 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
89823 + schedule_it = 1;
89824 + }
89825 + ret = __commit_creds(new);
89826 + if (schedule_it) {
89827 + rcu_read_lock();
89828 + read_lock(&tasklist_lock);
89829 + for (t = next_thread(current); t != current;
89830 + t = next_thread(t)) {
89831 + /* we'll check if the thread has uid 0 in
89832 + * the delayed worker routine
89833 + */
89834 + if (task_securebits(t) == oldsecurebits &&
89835 + t->delayed_cred == NULL) {
89836 + t->delayed_cred = get_cred(new);
89837 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
89838 + set_tsk_need_resched(t);
89839 + }
89840 + }
89841 + read_unlock(&tasklist_lock);
89842 + rcu_read_unlock();
89843 + }
89844 +
89845 + return ret;
89846 +#else
89847 + return __commit_creds(new);
89848 +#endif
89849 +}
89850 +
89851 EXPORT_SYMBOL(commit_creds);
89852
89853 /**
89854 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
89855 index 1adf62b..7736e06 100644
89856 --- a/kernel/debug/debug_core.c
89857 +++ b/kernel/debug/debug_core.c
89858 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
89859 */
89860 static atomic_t masters_in_kgdb;
89861 static atomic_t slaves_in_kgdb;
89862 -static atomic_t kgdb_break_tasklet_var;
89863 +static atomic_unchecked_t kgdb_break_tasklet_var;
89864 atomic_t kgdb_setting_breakpoint;
89865
89866 struct task_struct *kgdb_usethread;
89867 @@ -134,7 +134,7 @@ int kgdb_single_step;
89868 static pid_t kgdb_sstep_pid;
89869
89870 /* to keep track of the CPU which is doing the single stepping*/
89871 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
89872 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
89873
89874 /*
89875 * If you are debugging a problem where roundup (the collection of
89876 @@ -549,7 +549,7 @@ return_normal:
89877 * kernel will only try for the value of sstep_tries before
89878 * giving up and continuing on.
89879 */
89880 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
89881 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
89882 (kgdb_info[cpu].task &&
89883 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
89884 atomic_set(&kgdb_active, -1);
89885 @@ -647,8 +647,8 @@ cpu_master_loop:
89886 }
89887
89888 kgdb_restore:
89889 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
89890 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
89891 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
89892 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
89893 if (kgdb_info[sstep_cpu].task)
89894 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
89895 else
89896 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
89897 static void kgdb_tasklet_bpt(unsigned long ing)
89898 {
89899 kgdb_breakpoint();
89900 - atomic_set(&kgdb_break_tasklet_var, 0);
89901 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
89902 }
89903
89904 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
89905
89906 void kgdb_schedule_breakpoint(void)
89907 {
89908 - if (atomic_read(&kgdb_break_tasklet_var) ||
89909 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
89910 atomic_read(&kgdb_active) != -1 ||
89911 atomic_read(&kgdb_setting_breakpoint))
89912 return;
89913 - atomic_inc(&kgdb_break_tasklet_var);
89914 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
89915 tasklet_schedule(&kgdb_tasklet_breakpoint);
89916 }
89917 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
89918 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
89919 index 2f7c760..95b6a66 100644
89920 --- a/kernel/debug/kdb/kdb_main.c
89921 +++ b/kernel/debug/kdb/kdb_main.c
89922 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
89923 continue;
89924
89925 kdb_printf("%-20s%8u 0x%p ", mod->name,
89926 - mod->core_size, (void *)mod);
89927 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
89928 #ifdef CONFIG_MODULE_UNLOAD
89929 kdb_printf("%4ld ", module_refcount(mod));
89930 #endif
89931 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
89932 kdb_printf(" (Loading)");
89933 else
89934 kdb_printf(" (Live)");
89935 - kdb_printf(" 0x%p", mod->module_core);
89936 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
89937
89938 #ifdef CONFIG_MODULE_UNLOAD
89939 {
89940 diff --git a/kernel/events/core.c b/kernel/events/core.c
89941 index 6b17ac1..00fd505 100644
89942 --- a/kernel/events/core.c
89943 +++ b/kernel/events/core.c
89944 @@ -160,8 +160,15 @@ static struct srcu_struct pmus_srcu;
89945 * 0 - disallow raw tracepoint access for unpriv
89946 * 1 - disallow cpu events for unpriv
89947 * 2 - disallow kernel profiling for unpriv
89948 + * 3 - disallow all unpriv perf event use
89949 */
89950 -int sysctl_perf_event_paranoid __read_mostly = 1;
89951 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89952 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
89953 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
89954 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
89955 +#else
89956 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
89957 +#endif
89958
89959 /* Minimum for 512 kiB + 1 user control page */
89960 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
89961 @@ -187,7 +194,7 @@ void update_perf_cpu_limits(void)
89962
89963 tmp *= sysctl_perf_cpu_time_max_percent;
89964 do_div(tmp, 100);
89965 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
89966 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
89967 }
89968
89969 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
89970 @@ -293,7 +300,7 @@ void perf_sample_event_took(u64 sample_len_ns)
89971 }
89972 }
89973
89974 -static atomic64_t perf_event_id;
89975 +static atomic64_unchecked_t perf_event_id;
89976
89977 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
89978 enum event_type_t event_type);
89979 @@ -3023,7 +3030,7 @@ static void __perf_event_read(void *info)
89980
89981 static inline u64 perf_event_count(struct perf_event *event)
89982 {
89983 - return local64_read(&event->count) + atomic64_read(&event->child_count);
89984 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
89985 }
89986
89987 static u64 perf_event_read(struct perf_event *event)
89988 @@ -3399,9 +3406,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
89989 mutex_lock(&event->child_mutex);
89990 total += perf_event_read(event);
89991 *enabled += event->total_time_enabled +
89992 - atomic64_read(&event->child_total_time_enabled);
89993 + atomic64_read_unchecked(&event->child_total_time_enabled);
89994 *running += event->total_time_running +
89995 - atomic64_read(&event->child_total_time_running);
89996 + atomic64_read_unchecked(&event->child_total_time_running);
89997
89998 list_for_each_entry(child, &event->child_list, child_list) {
89999 total += perf_event_read(child);
90000 @@ -3830,10 +3837,10 @@ void perf_event_update_userpage(struct perf_event *event)
90001 userpg->offset -= local64_read(&event->hw.prev_count);
90002
90003 userpg->time_enabled = enabled +
90004 - atomic64_read(&event->child_total_time_enabled);
90005 + atomic64_read_unchecked(&event->child_total_time_enabled);
90006
90007 userpg->time_running = running +
90008 - atomic64_read(&event->child_total_time_running);
90009 + atomic64_read_unchecked(&event->child_total_time_running);
90010
90011 arch_perf_update_userpage(userpg, now);
90012
90013 @@ -4397,7 +4404,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
90014
90015 /* Data. */
90016 sp = perf_user_stack_pointer(regs);
90017 - rem = __output_copy_user(handle, (void *) sp, dump_size);
90018 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
90019 dyn_size = dump_size - rem;
90020
90021 perf_output_skip(handle, rem);
90022 @@ -4488,11 +4495,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
90023 values[n++] = perf_event_count(event);
90024 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
90025 values[n++] = enabled +
90026 - atomic64_read(&event->child_total_time_enabled);
90027 + atomic64_read_unchecked(&event->child_total_time_enabled);
90028 }
90029 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
90030 values[n++] = running +
90031 - atomic64_read(&event->child_total_time_running);
90032 + atomic64_read_unchecked(&event->child_total_time_running);
90033 }
90034 if (read_format & PERF_FORMAT_ID)
90035 values[n++] = primary_event_id(event);
90036 @@ -6801,7 +6808,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
90037 event->parent = parent_event;
90038
90039 event->ns = get_pid_ns(task_active_pid_ns(current));
90040 - event->id = atomic64_inc_return(&perf_event_id);
90041 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
90042
90043 event->state = PERF_EVENT_STATE_INACTIVE;
90044
90045 @@ -7080,6 +7087,11 @@ SYSCALL_DEFINE5(perf_event_open,
90046 if (flags & ~PERF_FLAG_ALL)
90047 return -EINVAL;
90048
90049 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90050 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
90051 + return -EACCES;
90052 +#endif
90053 +
90054 err = perf_copy_attr(attr_uptr, &attr);
90055 if (err)
90056 return err;
90057 @@ -7432,10 +7444,10 @@ static void sync_child_event(struct perf_event *child_event,
90058 /*
90059 * Add back the child's count to the parent's count:
90060 */
90061 - atomic64_add(child_val, &parent_event->child_count);
90062 - atomic64_add(child_event->total_time_enabled,
90063 + atomic64_add_unchecked(child_val, &parent_event->child_count);
90064 + atomic64_add_unchecked(child_event->total_time_enabled,
90065 &parent_event->child_total_time_enabled);
90066 - atomic64_add(child_event->total_time_running,
90067 + atomic64_add_unchecked(child_event->total_time_running,
90068 &parent_event->child_total_time_running);
90069
90070 /*
90071 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
90072 index 569b2187..19940d9 100644
90073 --- a/kernel/events/internal.h
90074 +++ b/kernel/events/internal.h
90075 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
90076 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
90077 }
90078
90079 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
90080 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
90081 static inline unsigned long \
90082 func_name(struct perf_output_handle *handle, \
90083 - const void *buf, unsigned long len) \
90084 + const void user *buf, unsigned long len) \
90085 { \
90086 unsigned long size, written; \
90087 \
90088 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
90089 return 0;
90090 }
90091
90092 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
90093 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
90094
90095 static inline unsigned long
90096 memcpy_skip(void *dst, const void *src, unsigned long n)
90097 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
90098 return 0;
90099 }
90100
90101 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
90102 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
90103
90104 #ifndef arch_perf_out_copy_user
90105 #define arch_perf_out_copy_user arch_perf_out_copy_user
90106 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
90107 }
90108 #endif
90109
90110 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
90111 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
90112
90113 /* Callchain handling */
90114 extern struct perf_callchain_entry *
90115 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
90116 index 6f3254e..e4c1fe4 100644
90117 --- a/kernel/events/uprobes.c
90118 +++ b/kernel/events/uprobes.c
90119 @@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
90120 {
90121 struct page *page;
90122 uprobe_opcode_t opcode;
90123 - int result;
90124 + long result;
90125
90126 pagefault_disable();
90127 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
90128 diff --git a/kernel/exit.c b/kernel/exit.c
90129 index e5c4668..592d2e5 100644
90130 --- a/kernel/exit.c
90131 +++ b/kernel/exit.c
90132 @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
90133 struct task_struct *leader;
90134 int zap_leader;
90135 repeat:
90136 +#ifdef CONFIG_NET
90137 + gr_del_task_from_ip_table(p);
90138 +#endif
90139 +
90140 /* don't need to get the RCU readlock here - the process is dead and
90141 * can't be modifying its own credentials. But shut RCU-lockdep up */
90142 rcu_read_lock();
90143 @@ -664,6 +668,8 @@ void do_exit(long code)
90144 struct task_struct *tsk = current;
90145 int group_dead;
90146
90147 + set_fs(USER_DS);
90148 +
90149 profile_task_exit(tsk);
90150
90151 WARN_ON(blk_needs_flush_plug(tsk));
90152 @@ -680,7 +686,6 @@ void do_exit(long code)
90153 * mm_release()->clear_child_tid() from writing to a user-controlled
90154 * kernel address.
90155 */
90156 - set_fs(USER_DS);
90157
90158 ptrace_event(PTRACE_EVENT_EXIT, code);
90159
90160 @@ -739,6 +744,9 @@ void do_exit(long code)
90161 tsk->exit_code = code;
90162 taskstats_exit(tsk, group_dead);
90163
90164 + gr_acl_handle_psacct(tsk, code);
90165 + gr_acl_handle_exit();
90166 +
90167 exit_mm(tsk);
90168
90169 if (group_dead)
90170 @@ -858,7 +866,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
90171 * Take down every thread in the group. This is called by fatal signals
90172 * as well as by sys_exit_group (below).
90173 */
90174 -void
90175 +__noreturn void
90176 do_group_exit(int exit_code)
90177 {
90178 struct signal_struct *sig = current->signal;
90179 diff --git a/kernel/fork.c b/kernel/fork.c
90180 index 6a13c46..a623c8e 100644
90181 --- a/kernel/fork.c
90182 +++ b/kernel/fork.c
90183 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
90184 # endif
90185 #endif
90186
90187 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
90188 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
90189 + int node, void **lowmem_stack)
90190 +{
90191 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
90192 + void *ret = NULL;
90193 + unsigned int i;
90194 +
90195 + *lowmem_stack = alloc_thread_info_node(tsk, node);
90196 + if (*lowmem_stack == NULL)
90197 + goto out;
90198 +
90199 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
90200 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
90201 +
90202 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
90203 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
90204 + if (ret == NULL) {
90205 + free_thread_info(*lowmem_stack);
90206 + *lowmem_stack = NULL;
90207 + }
90208 +
90209 +out:
90210 + return ret;
90211 +}
90212 +
90213 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
90214 +{
90215 + unmap_process_stacks(tsk);
90216 +}
90217 +#else
90218 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
90219 + int node, void **lowmem_stack)
90220 +{
90221 + return alloc_thread_info_node(tsk, node);
90222 +}
90223 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
90224 +{
90225 + free_thread_info(ti);
90226 +}
90227 +#endif
90228 +
90229 /* SLAB cache for signal_struct structures (tsk->signal) */
90230 static struct kmem_cache *signal_cachep;
90231
90232 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
90233 /* SLAB cache for mm_struct structures (tsk->mm) */
90234 static struct kmem_cache *mm_cachep;
90235
90236 -static void account_kernel_stack(struct thread_info *ti, int account)
90237 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
90238 {
90239 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
90240 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
90241 +#else
90242 struct zone *zone = page_zone(virt_to_page(ti));
90243 +#endif
90244
90245 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
90246 }
90247
90248 void free_task(struct task_struct *tsk)
90249 {
90250 - account_kernel_stack(tsk->stack, -1);
90251 + account_kernel_stack(tsk, tsk->stack, -1);
90252 arch_release_thread_info(tsk->stack);
90253 - free_thread_info(tsk->stack);
90254 + gr_free_thread_info(tsk, tsk->stack);
90255 rt_mutex_debug_task_free(tsk);
90256 ftrace_graph_exit_task(tsk);
90257 put_seccomp_filter(tsk);
90258 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90259 struct task_struct *tsk;
90260 struct thread_info *ti;
90261 unsigned long *stackend;
90262 + void *lowmem_stack;
90263 int node = tsk_fork_get_node(orig);
90264 int err;
90265
90266 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90267 if (!tsk)
90268 return NULL;
90269
90270 - ti = alloc_thread_info_node(tsk, node);
90271 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
90272 if (!ti)
90273 goto free_tsk;
90274
90275 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90276 goto free_ti;
90277
90278 tsk->stack = ti;
90279 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
90280 + tsk->lowmem_stack = lowmem_stack;
90281 +#endif
90282
90283 setup_thread_stack(tsk, orig);
90284 clear_user_return_notifier(tsk);
90285 @@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90286 *stackend = STACK_END_MAGIC; /* for overflow detection */
90287
90288 #ifdef CONFIG_CC_STACKPROTECTOR
90289 - tsk->stack_canary = get_random_int();
90290 + tsk->stack_canary = pax_get_random_long();
90291 #endif
90292
90293 /*
90294 @@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90295 tsk->splice_pipe = NULL;
90296 tsk->task_frag.page = NULL;
90297
90298 - account_kernel_stack(ti, 1);
90299 + account_kernel_stack(tsk, ti, 1);
90300
90301 return tsk;
90302
90303 free_ti:
90304 - free_thread_info(ti);
90305 + gr_free_thread_info(tsk, ti);
90306 free_tsk:
90307 free_task_struct(tsk);
90308 return NULL;
90309 }
90310
90311 #ifdef CONFIG_MMU
90312 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90313 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
90314 +{
90315 + struct vm_area_struct *tmp;
90316 + unsigned long charge;
90317 + struct file *file;
90318 + int retval;
90319 +
90320 + charge = 0;
90321 + if (mpnt->vm_flags & VM_ACCOUNT) {
90322 + unsigned long len = vma_pages(mpnt);
90323 +
90324 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
90325 + goto fail_nomem;
90326 + charge = len;
90327 + }
90328 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
90329 + if (!tmp)
90330 + goto fail_nomem;
90331 + *tmp = *mpnt;
90332 + tmp->vm_mm = mm;
90333 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
90334 + retval = vma_dup_policy(mpnt, tmp);
90335 + if (retval)
90336 + goto fail_nomem_policy;
90337 + if (anon_vma_fork(tmp, mpnt))
90338 + goto fail_nomem_anon_vma_fork;
90339 + tmp->vm_flags &= ~VM_LOCKED;
90340 + tmp->vm_next = tmp->vm_prev = NULL;
90341 + tmp->vm_mirror = NULL;
90342 + file = tmp->vm_file;
90343 + if (file) {
90344 + struct inode *inode = file_inode(file);
90345 + struct address_space *mapping = file->f_mapping;
90346 +
90347 + get_file(file);
90348 + if (tmp->vm_flags & VM_DENYWRITE)
90349 + atomic_dec(&inode->i_writecount);
90350 + mutex_lock(&mapping->i_mmap_mutex);
90351 + if (tmp->vm_flags & VM_SHARED)
90352 + mapping->i_mmap_writable++;
90353 + flush_dcache_mmap_lock(mapping);
90354 + /* insert tmp into the share list, just after mpnt */
90355 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
90356 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
90357 + else
90358 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
90359 + flush_dcache_mmap_unlock(mapping);
90360 + mutex_unlock(&mapping->i_mmap_mutex);
90361 + }
90362 +
90363 + /*
90364 + * Clear hugetlb-related page reserves for children. This only
90365 + * affects MAP_PRIVATE mappings. Faults generated by the child
90366 + * are not guaranteed to succeed, even if read-only
90367 + */
90368 + if (is_vm_hugetlb_page(tmp))
90369 + reset_vma_resv_huge_pages(tmp);
90370 +
90371 + return tmp;
90372 +
90373 +fail_nomem_anon_vma_fork:
90374 + mpol_put(vma_policy(tmp));
90375 +fail_nomem_policy:
90376 + kmem_cache_free(vm_area_cachep, tmp);
90377 +fail_nomem:
90378 + vm_unacct_memory(charge);
90379 + return NULL;
90380 +}
90381 +
90382 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90383 {
90384 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
90385 struct rb_node **rb_link, *rb_parent;
90386 int retval;
90387 - unsigned long charge;
90388
90389 uprobe_start_dup_mmap();
90390 down_write(&oldmm->mmap_sem);
90391 @@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90392
90393 prev = NULL;
90394 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
90395 - struct file *file;
90396 -
90397 if (mpnt->vm_flags & VM_DONTCOPY) {
90398 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
90399 -vma_pages(mpnt));
90400 continue;
90401 }
90402 - charge = 0;
90403 - if (mpnt->vm_flags & VM_ACCOUNT) {
90404 - unsigned long len = vma_pages(mpnt);
90405 -
90406 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
90407 - goto fail_nomem;
90408 - charge = len;
90409 - }
90410 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
90411 - if (!tmp)
90412 - goto fail_nomem;
90413 - *tmp = *mpnt;
90414 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
90415 - retval = vma_dup_policy(mpnt, tmp);
90416 - if (retval)
90417 - goto fail_nomem_policy;
90418 - tmp->vm_mm = mm;
90419 - if (anon_vma_fork(tmp, mpnt))
90420 - goto fail_nomem_anon_vma_fork;
90421 - tmp->vm_flags &= ~VM_LOCKED;
90422 - tmp->vm_next = tmp->vm_prev = NULL;
90423 - file = tmp->vm_file;
90424 - if (file) {
90425 - struct inode *inode = file_inode(file);
90426 - struct address_space *mapping = file->f_mapping;
90427 -
90428 - get_file(file);
90429 - if (tmp->vm_flags & VM_DENYWRITE)
90430 - atomic_dec(&inode->i_writecount);
90431 - mutex_lock(&mapping->i_mmap_mutex);
90432 - if (tmp->vm_flags & VM_SHARED)
90433 - mapping->i_mmap_writable++;
90434 - flush_dcache_mmap_lock(mapping);
90435 - /* insert tmp into the share list, just after mpnt */
90436 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
90437 - vma_nonlinear_insert(tmp,
90438 - &mapping->i_mmap_nonlinear);
90439 - else
90440 - vma_interval_tree_insert_after(tmp, mpnt,
90441 - &mapping->i_mmap);
90442 - flush_dcache_mmap_unlock(mapping);
90443 - mutex_unlock(&mapping->i_mmap_mutex);
90444 + tmp = dup_vma(mm, oldmm, mpnt);
90445 + if (!tmp) {
90446 + retval = -ENOMEM;
90447 + goto out;
90448 }
90449
90450 /*
90451 @@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90452 if (retval)
90453 goto out;
90454 }
90455 +
90456 +#ifdef CONFIG_PAX_SEGMEXEC
90457 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
90458 + struct vm_area_struct *mpnt_m;
90459 +
90460 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
90461 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
90462 +
90463 + if (!mpnt->vm_mirror)
90464 + continue;
90465 +
90466 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
90467 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
90468 + mpnt->vm_mirror = mpnt_m;
90469 + } else {
90470 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
90471 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
90472 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
90473 + mpnt->vm_mirror->vm_mirror = mpnt;
90474 + }
90475 + }
90476 + BUG_ON(mpnt_m);
90477 + }
90478 +#endif
90479 +
90480 /* a new mm has just been created */
90481 arch_dup_mmap(oldmm, mm);
90482 retval = 0;
90483 @@ -472,14 +575,6 @@ out:
90484 up_write(&oldmm->mmap_sem);
90485 uprobe_end_dup_mmap();
90486 return retval;
90487 -fail_nomem_anon_vma_fork:
90488 - mpol_put(vma_policy(tmp));
90489 -fail_nomem_policy:
90490 - kmem_cache_free(vm_area_cachep, tmp);
90491 -fail_nomem:
90492 - retval = -ENOMEM;
90493 - vm_unacct_memory(charge);
90494 - goto out;
90495 }
90496
90497 static inline int mm_alloc_pgd(struct mm_struct *mm)
90498 @@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
90499 return ERR_PTR(err);
90500
90501 mm = get_task_mm(task);
90502 - if (mm && mm != current->mm &&
90503 - !ptrace_may_access(task, mode)) {
90504 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
90505 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
90506 mmput(mm);
90507 mm = ERR_PTR(-EACCES);
90508 }
90509 @@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
90510 spin_unlock(&fs->lock);
90511 return -EAGAIN;
90512 }
90513 - fs->users++;
90514 + atomic_inc(&fs->users);
90515 spin_unlock(&fs->lock);
90516 return 0;
90517 }
90518 tsk->fs = copy_fs_struct(fs);
90519 if (!tsk->fs)
90520 return -ENOMEM;
90521 + /* Carry through gr_chroot_dentry and is_chrooted instead
90522 + of recomputing it here. Already copied when the task struct
90523 + is duplicated. This allows pivot_root to not be treated as
90524 + a chroot
90525 + */
90526 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
90527 +
90528 return 0;
90529 }
90530
90531 @@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
90532 * parts of the process environment (as per the clone
90533 * flags). The actual kick-off is left to the caller.
90534 */
90535 -static struct task_struct *copy_process(unsigned long clone_flags,
90536 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
90537 unsigned long stack_start,
90538 unsigned long stack_size,
90539 int __user *child_tidptr,
90540 @@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
90541 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
90542 #endif
90543 retval = -EAGAIN;
90544 +
90545 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
90546 +
90547 if (atomic_read(&p->real_cred->user->processes) >=
90548 task_rlimit(p, RLIMIT_NPROC)) {
90549 if (p->real_cred->user != INIT_USER &&
90550 @@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
90551 goto bad_fork_free_pid;
90552 }
90553
90554 + /* synchronizes with gr_set_acls()
90555 + we need to call this past the point of no return for fork()
90556 + */
90557 + gr_copy_label(p);
90558 +
90559 if (likely(p->pid)) {
90560 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
90561
90562 @@ -1541,6 +1651,8 @@ bad_fork_cleanup_count:
90563 bad_fork_free:
90564 free_task(p);
90565 fork_out:
90566 + gr_log_forkfail(retval);
90567 +
90568 return ERR_PTR(retval);
90569 }
90570
90571 @@ -1602,6 +1714,7 @@ long do_fork(unsigned long clone_flags,
90572
90573 p = copy_process(clone_flags, stack_start, stack_size,
90574 child_tidptr, NULL, trace);
90575 + add_latent_entropy();
90576 /*
90577 * Do this prior waking up the new thread - the thread pointer
90578 * might get invalid after that point, if the thread exits quickly.
90579 @@ -1618,6 +1731,8 @@ long do_fork(unsigned long clone_flags,
90580 if (clone_flags & CLONE_PARENT_SETTID)
90581 put_user(nr, parent_tidptr);
90582
90583 + gr_handle_brute_check();
90584 +
90585 if (clone_flags & CLONE_VFORK) {
90586 p->vfork_done = &vfork;
90587 init_completion(&vfork);
90588 @@ -1736,7 +1851,7 @@ void __init proc_caches_init(void)
90589 mm_cachep = kmem_cache_create("mm_struct",
90590 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
90591 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
90592 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
90593 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
90594 mmap_init();
90595 nsproxy_cache_init();
90596 }
90597 @@ -1776,7 +1891,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
90598 return 0;
90599
90600 /* don't need lock here; in the worst case we'll do useless copy */
90601 - if (fs->users == 1)
90602 + if (atomic_read(&fs->users) == 1)
90603 return 0;
90604
90605 *new_fsp = copy_fs_struct(fs);
90606 @@ -1883,7 +1998,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
90607 fs = current->fs;
90608 spin_lock(&fs->lock);
90609 current->fs = new_fs;
90610 - if (--fs->users)
90611 + gr_set_chroot_entries(current, &current->fs->root);
90612 + if (atomic_dec_return(&fs->users))
90613 new_fs = NULL;
90614 else
90615 new_fs = fs;
90616 diff --git a/kernel/futex.c b/kernel/futex.c
90617 index b632b5f..ca00da9 100644
90618 --- a/kernel/futex.c
90619 +++ b/kernel/futex.c
90620 @@ -202,7 +202,7 @@ struct futex_pi_state {
90621 atomic_t refcount;
90622
90623 union futex_key key;
90624 -};
90625 +} __randomize_layout;
90626
90627 /**
90628 * struct futex_q - The hashed futex queue entry, one per waiting task
90629 @@ -236,7 +236,7 @@ struct futex_q {
90630 struct rt_mutex_waiter *rt_waiter;
90631 union futex_key *requeue_pi_key;
90632 u32 bitset;
90633 -};
90634 +} __randomize_layout;
90635
90636 static const struct futex_q futex_q_init = {
90637 /* list gets initialized in queue_me()*/
90638 @@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
90639 struct page *page, *page_head;
90640 int err, ro = 0;
90641
90642 +#ifdef CONFIG_PAX_SEGMEXEC
90643 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
90644 + return -EFAULT;
90645 +#endif
90646 +
90647 /*
90648 * The futex address must be "naturally" aligned.
90649 */
90650 @@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
90651
90652 static int get_futex_value_locked(u32 *dest, u32 __user *from)
90653 {
90654 - int ret;
90655 + unsigned long ret;
90656
90657 pagefault_disable();
90658 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
90659 @@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
90660 {
90661 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
90662 u32 curval;
90663 + mm_segment_t oldfs;
90664
90665 /*
90666 * This will fail and we want it. Some arch implementations do
90667 @@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
90668 * implementation, the non-functional ones will return
90669 * -ENOSYS.
90670 */
90671 + oldfs = get_fs();
90672 + set_fs(USER_DS);
90673 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
90674 futex_cmpxchg_enabled = 1;
90675 + set_fs(oldfs);
90676 #endif
90677 }
90678
90679 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
90680 index 55c8c93..9ba7ad6 100644
90681 --- a/kernel/futex_compat.c
90682 +++ b/kernel/futex_compat.c
90683 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
90684 return 0;
90685 }
90686
90687 -static void __user *futex_uaddr(struct robust_list __user *entry,
90688 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
90689 compat_long_t futex_offset)
90690 {
90691 compat_uptr_t base = ptr_to_compat(entry);
90692 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
90693 index b358a80..fc25240 100644
90694 --- a/kernel/gcov/base.c
90695 +++ b/kernel/gcov/base.c
90696 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
90697 }
90698
90699 #ifdef CONFIG_MODULES
90700 -static inline int within(void *addr, void *start, unsigned long size)
90701 -{
90702 - return ((addr >= start) && (addr < start + size));
90703 -}
90704 -
90705 /* Update list and generate events when modules are unloaded. */
90706 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
90707 void *data)
90708 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
90709
90710 /* Remove entries located in module from linked list. */
90711 while ((info = gcov_info_next(info))) {
90712 - if (within(info, mod->module_core, mod->core_size)) {
90713 + if (within_module_core_rw((unsigned long)info, mod)) {
90714 gcov_info_unlink(prev, info);
90715 if (gcov_events_enabled)
90716 gcov_event(GCOV_REMOVE, info);
90717 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
90718 index 3ab2899..c6ad010 100644
90719 --- a/kernel/hrtimer.c
90720 +++ b/kernel/hrtimer.c
90721 @@ -1449,7 +1449,7 @@ void hrtimer_peek_ahead_timers(void)
90722 local_irq_restore(flags);
90723 }
90724
90725 -static void run_hrtimer_softirq(struct softirq_action *h)
90726 +static __latent_entropy void run_hrtimer_softirq(void)
90727 {
90728 hrtimer_peek_ahead_timers();
90729 }
90730 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
90731 index a82170e..5b01e7f 100644
90732 --- a/kernel/irq_work.c
90733 +++ b/kernel/irq_work.c
90734 @@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
90735 return NOTIFY_OK;
90736 }
90737
90738 -static struct notifier_block cpu_notify;
90739 +static struct notifier_block cpu_notify = {
90740 + .notifier_call = irq_work_cpu_notify,
90741 + .priority = 0,
90742 +};
90743
90744 static __init int irq_work_init_cpu_notifier(void)
90745 {
90746 - cpu_notify.notifier_call = irq_work_cpu_notify;
90747 - cpu_notify.priority = 0;
90748 register_cpu_notifier(&cpu_notify);
90749 return 0;
90750 }
90751 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
90752 index 9019f15..9a3c42e 100644
90753 --- a/kernel/jump_label.c
90754 +++ b/kernel/jump_label.c
90755 @@ -14,6 +14,7 @@
90756 #include <linux/err.h>
90757 #include <linux/static_key.h>
90758 #include <linux/jump_label_ratelimit.h>
90759 +#include <linux/mm.h>
90760
90761 #ifdef HAVE_JUMP_LABEL
90762
90763 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
90764
90765 size = (((unsigned long)stop - (unsigned long)start)
90766 / sizeof(struct jump_entry));
90767 + pax_open_kernel();
90768 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
90769 + pax_close_kernel();
90770 }
90771
90772 static void jump_label_update(struct static_key *key, int enable);
90773 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
90774 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
90775 struct jump_entry *iter;
90776
90777 + pax_open_kernel();
90778 for (iter = iter_start; iter < iter_stop; iter++) {
90779 if (within_module_init(iter->code, mod))
90780 iter->code = 0;
90781 }
90782 + pax_close_kernel();
90783 }
90784
90785 static int
90786 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
90787 index cb0cf37..b69e161 100644
90788 --- a/kernel/kallsyms.c
90789 +++ b/kernel/kallsyms.c
90790 @@ -11,6 +11,9 @@
90791 * Changed the compression method from stem compression to "table lookup"
90792 * compression (see scripts/kallsyms.c for a more complete description)
90793 */
90794 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90795 +#define __INCLUDED_BY_HIDESYM 1
90796 +#endif
90797 #include <linux/kallsyms.h>
90798 #include <linux/module.h>
90799 #include <linux/init.h>
90800 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
90801
90802 static inline int is_kernel_inittext(unsigned long addr)
90803 {
90804 + if (system_state != SYSTEM_BOOTING)
90805 + return 0;
90806 +
90807 if (addr >= (unsigned long)_sinittext
90808 && addr <= (unsigned long)_einittext)
90809 return 1;
90810 return 0;
90811 }
90812
90813 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90814 +#ifdef CONFIG_MODULES
90815 +static inline int is_module_text(unsigned long addr)
90816 +{
90817 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
90818 + return 1;
90819 +
90820 + addr = ktla_ktva(addr);
90821 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
90822 +}
90823 +#else
90824 +static inline int is_module_text(unsigned long addr)
90825 +{
90826 + return 0;
90827 +}
90828 +#endif
90829 +#endif
90830 +
90831 static inline int is_kernel_text(unsigned long addr)
90832 {
90833 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
90834 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
90835
90836 static inline int is_kernel(unsigned long addr)
90837 {
90838 +
90839 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90840 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
90841 + return 1;
90842 +
90843 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
90844 +#else
90845 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
90846 +#endif
90847 +
90848 return 1;
90849 return in_gate_area_no_mm(addr);
90850 }
90851
90852 static int is_ksym_addr(unsigned long addr)
90853 {
90854 +
90855 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90856 + if (is_module_text(addr))
90857 + return 0;
90858 +#endif
90859 +
90860 if (all_var)
90861 return is_kernel(addr);
90862
90863 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
90864
90865 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
90866 {
90867 - iter->name[0] = '\0';
90868 iter->nameoff = get_symbol_offset(new_pos);
90869 iter->pos = new_pos;
90870 }
90871 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
90872 {
90873 struct kallsym_iter *iter = m->private;
90874
90875 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90876 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
90877 + return 0;
90878 +#endif
90879 +
90880 /* Some debugging symbols have no name. Ignore them. */
90881 if (!iter->name[0])
90882 return 0;
90883 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
90884 */
90885 type = iter->exported ? toupper(iter->type) :
90886 tolower(iter->type);
90887 +
90888 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
90889 type, iter->name, iter->module_name);
90890 } else
90891 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
90892 struct kallsym_iter *iter;
90893 int ret;
90894
90895 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
90896 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
90897 if (!iter)
90898 return -ENOMEM;
90899 reset_iter(iter, 0);
90900 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
90901 index e30ac0f..3528cac 100644
90902 --- a/kernel/kcmp.c
90903 +++ b/kernel/kcmp.c
90904 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
90905 struct task_struct *task1, *task2;
90906 int ret;
90907
90908 +#ifdef CONFIG_GRKERNSEC
90909 + return -ENOSYS;
90910 +#endif
90911 +
90912 rcu_read_lock();
90913
90914 /*
90915 diff --git a/kernel/kexec.c b/kernel/kexec.c
90916 index 4b8f0c9..fffd0df 100644
90917 --- a/kernel/kexec.c
90918 +++ b/kernel/kexec.c
90919 @@ -1045,7 +1045,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
90920 compat_ulong_t, flags)
90921 {
90922 struct compat_kexec_segment in;
90923 - struct kexec_segment out, __user *ksegments;
90924 + struct kexec_segment out;
90925 + struct kexec_segment __user *ksegments;
90926 unsigned long i, result;
90927
90928 /* Don't allow clients that don't understand the native
90929 diff --git a/kernel/kmod.c b/kernel/kmod.c
90930 index 8637e04..8b1d0d8 100644
90931 --- a/kernel/kmod.c
90932 +++ b/kernel/kmod.c
90933 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
90934 kfree(info->argv);
90935 }
90936
90937 -static int call_modprobe(char *module_name, int wait)
90938 +static int call_modprobe(char *module_name, char *module_param, int wait)
90939 {
90940 struct subprocess_info *info;
90941 static char *envp[] = {
90942 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
90943 NULL
90944 };
90945
90946 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
90947 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
90948 if (!argv)
90949 goto out;
90950
90951 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
90952 argv[1] = "-q";
90953 argv[2] = "--";
90954 argv[3] = module_name; /* check free_modprobe_argv() */
90955 - argv[4] = NULL;
90956 + argv[4] = module_param;
90957 + argv[5] = NULL;
90958
90959 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
90960 NULL, free_modprobe_argv, NULL);
90961 @@ -129,9 +130,8 @@ out:
90962 * If module auto-loading support is disabled then this function
90963 * becomes a no-operation.
90964 */
90965 -int __request_module(bool wait, const char *fmt, ...)
90966 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
90967 {
90968 - va_list args;
90969 char module_name[MODULE_NAME_LEN];
90970 unsigned int max_modprobes;
90971 int ret;
90972 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
90973 if (!modprobe_path[0])
90974 return 0;
90975
90976 - va_start(args, fmt);
90977 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
90978 - va_end(args);
90979 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
90980 if (ret >= MODULE_NAME_LEN)
90981 return -ENAMETOOLONG;
90982
90983 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
90984 if (ret)
90985 return ret;
90986
90987 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90988 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90989 + /* hack to workaround consolekit/udisks stupidity */
90990 + read_lock(&tasklist_lock);
90991 + if (!strcmp(current->comm, "mount") &&
90992 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
90993 + read_unlock(&tasklist_lock);
90994 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
90995 + return -EPERM;
90996 + }
90997 + read_unlock(&tasklist_lock);
90998 + }
90999 +#endif
91000 +
91001 /* If modprobe needs a service that is in a module, we get a recursive
91002 * loop. Limit the number of running kmod threads to max_threads/2 or
91003 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
91004 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
91005
91006 trace_module_request(module_name, wait, _RET_IP_);
91007
91008 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
91009 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
91010
91011 atomic_dec(&kmod_concurrent);
91012 return ret;
91013 }
91014 +
91015 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
91016 +{
91017 + va_list args;
91018 + int ret;
91019 +
91020 + va_start(args, fmt);
91021 + ret = ____request_module(wait, module_param, fmt, args);
91022 + va_end(args);
91023 +
91024 + return ret;
91025 +}
91026 +
91027 +int __request_module(bool wait, const char *fmt, ...)
91028 +{
91029 + va_list args;
91030 + int ret;
91031 +
91032 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91033 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
91034 + char module_param[MODULE_NAME_LEN];
91035 +
91036 + memset(module_param, 0, sizeof(module_param));
91037 +
91038 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
91039 +
91040 + va_start(args, fmt);
91041 + ret = ____request_module(wait, module_param, fmt, args);
91042 + va_end(args);
91043 +
91044 + return ret;
91045 + }
91046 +#endif
91047 +
91048 + va_start(args, fmt);
91049 + ret = ____request_module(wait, NULL, fmt, args);
91050 + va_end(args);
91051 +
91052 + return ret;
91053 +}
91054 +
91055 EXPORT_SYMBOL(__request_module);
91056 #endif /* CONFIG_MODULES */
91057
91058 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
91059 */
91060 set_user_nice(current, 0);
91061
91062 +#ifdef CONFIG_GRKERNSEC
91063 + /* this is race-free as far as userland is concerned as we copied
91064 + out the path to be used prior to this point and are now operating
91065 + on that copy
91066 + */
91067 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
91068 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
91069 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
91070 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
91071 + retval = -EPERM;
91072 + goto fail;
91073 + }
91074 +#endif
91075 +
91076 retval = -ENOMEM;
91077 new = prepare_kernel_cred(current);
91078 if (!new)
91079 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
91080 commit_creds(new);
91081
91082 retval = do_execve(getname_kernel(sub_info->path),
91083 - (const char __user *const __user *)sub_info->argv,
91084 - (const char __user *const __user *)sub_info->envp);
91085 + (const char __user *const __force_user *)sub_info->argv,
91086 + (const char __user *const __force_user *)sub_info->envp);
91087 if (!retval)
91088 return 0;
91089
91090 @@ -260,6 +327,10 @@ static int call_helper(void *data)
91091
91092 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
91093 {
91094 +#ifdef CONFIG_GRKERNSEC
91095 + kfree(info->path);
91096 + info->path = info->origpath;
91097 +#endif
91098 if (info->cleanup)
91099 (*info->cleanup)(info);
91100 kfree(info);
91101 @@ -300,7 +371,7 @@ static int wait_for_helper(void *data)
91102 *
91103 * Thus the __user pointer cast is valid here.
91104 */
91105 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
91106 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
91107
91108 /*
91109 * If ret is 0, either ____call_usermodehelper failed and the
91110 @@ -539,7 +610,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
91111 goto out;
91112
91113 INIT_WORK(&sub_info->work, __call_usermodehelper);
91114 +#ifdef CONFIG_GRKERNSEC
91115 + sub_info->origpath = path;
91116 + sub_info->path = kstrdup(path, gfp_mask);
91117 +#else
91118 sub_info->path = path;
91119 +#endif
91120 sub_info->argv = argv;
91121 sub_info->envp = envp;
91122
91123 @@ -647,7 +723,7 @@ EXPORT_SYMBOL(call_usermodehelper);
91124 static int proc_cap_handler(struct ctl_table *table, int write,
91125 void __user *buffer, size_t *lenp, loff_t *ppos)
91126 {
91127 - struct ctl_table t;
91128 + ctl_table_no_const t;
91129 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
91130 kernel_cap_t new_cap;
91131 int err, i;
91132 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
91133 index 734e9a7..0a313b8 100644
91134 --- a/kernel/kprobes.c
91135 +++ b/kernel/kprobes.c
91136 @@ -31,6 +31,9 @@
91137 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
91138 * <prasanna@in.ibm.com> added function-return probes.
91139 */
91140 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91141 +#define __INCLUDED_BY_HIDESYM 1
91142 +#endif
91143 #include <linux/kprobes.h>
91144 #include <linux/hash.h>
91145 #include <linux/init.h>
91146 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
91147
91148 static void *alloc_insn_page(void)
91149 {
91150 - return module_alloc(PAGE_SIZE);
91151 + return module_alloc_exec(PAGE_SIZE);
91152 }
91153
91154 static void free_insn_page(void *page)
91155 {
91156 - module_free(NULL, page);
91157 + module_free_exec(NULL, page);
91158 }
91159
91160 struct kprobe_insn_cache kprobe_insn_slots = {
91161 @@ -2176,11 +2179,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
91162 kprobe_type = "k";
91163
91164 if (sym)
91165 - seq_printf(pi, "%p %s %s+0x%x %s ",
91166 + seq_printf(pi, "%pK %s %s+0x%x %s ",
91167 p->addr, kprobe_type, sym, offset,
91168 (modname ? modname : " "));
91169 else
91170 - seq_printf(pi, "%p %s %p ",
91171 + seq_printf(pi, "%pK %s %pK ",
91172 p->addr, kprobe_type, p->addr);
91173
91174 if (!pp)
91175 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
91176 index 6683cce..daf8999 100644
91177 --- a/kernel/ksysfs.c
91178 +++ b/kernel/ksysfs.c
91179 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
91180 {
91181 if (count+1 > UEVENT_HELPER_PATH_LEN)
91182 return -ENOENT;
91183 + if (!capable(CAP_SYS_ADMIN))
91184 + return -EPERM;
91185 memcpy(uevent_helper, buf, count);
91186 uevent_helper[count] = '\0';
91187 if (count && uevent_helper[count-1] == '\n')
91188 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
91189 return count;
91190 }
91191
91192 -static struct bin_attribute notes_attr = {
91193 +static bin_attribute_no_const notes_attr __read_only = {
91194 .attr = {
91195 .name = "notes",
91196 .mode = S_IRUGO,
91197 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
91198 index d24e433..fa04fb8 100644
91199 --- a/kernel/locking/lockdep.c
91200 +++ b/kernel/locking/lockdep.c
91201 @@ -597,6 +597,10 @@ static int static_obj(void *obj)
91202 end = (unsigned long) &_end,
91203 addr = (unsigned long) obj;
91204
91205 +#ifdef CONFIG_PAX_KERNEXEC
91206 + start = ktla_ktva(start);
91207 +#endif
91208 +
91209 /*
91210 * static variable?
91211 */
91212 @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
91213 if (!static_obj(lock->key)) {
91214 debug_locks_off();
91215 printk("INFO: trying to register non-static key.\n");
91216 + printk("lock:%pS key:%pS.\n", lock, lock->key);
91217 printk("the code is fine but needs lockdep annotation.\n");
91218 printk("turning off the locking correctness validator.\n");
91219 dump_stack();
91220 @@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
91221 if (!class)
91222 return 0;
91223 }
91224 - atomic_inc((atomic_t *)&class->ops);
91225 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
91226 if (very_verbose(class)) {
91227 printk("\nacquire class [%p] %s", class->key, class->name);
91228 if (class->name_version > 1)
91229 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
91230 index ef43ac4..2720dfa 100644
91231 --- a/kernel/locking/lockdep_proc.c
91232 +++ b/kernel/locking/lockdep_proc.c
91233 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
91234 return 0;
91235 }
91236
91237 - seq_printf(m, "%p", class->key);
91238 + seq_printf(m, "%pK", class->key);
91239 #ifdef CONFIG_DEBUG_LOCKDEP
91240 seq_printf(m, " OPS:%8ld", class->ops);
91241 #endif
91242 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
91243
91244 list_for_each_entry(entry, &class->locks_after, entry) {
91245 if (entry->distance == 1) {
91246 - seq_printf(m, " -> [%p] ", entry->class->key);
91247 + seq_printf(m, " -> [%pK] ", entry->class->key);
91248 print_name(m, entry->class);
91249 seq_puts(m, "\n");
91250 }
91251 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
91252 if (!class->key)
91253 continue;
91254
91255 - seq_printf(m, "[%p] ", class->key);
91256 + seq_printf(m, "[%pK] ", class->key);
91257 print_name(m, class);
91258 seq_puts(m, "\n");
91259 }
91260 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
91261 if (!i)
91262 seq_line(m, '-', 40-namelen, namelen);
91263
91264 - snprintf(ip, sizeof(ip), "[<%p>]",
91265 + snprintf(ip, sizeof(ip), "[<%pK>]",
91266 (void *)class->contention_point[i]);
91267 seq_printf(m, "%40s %14lu %29s %pS\n",
91268 name, stats->contention_point[i],
91269 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
91270 if (!i)
91271 seq_line(m, '-', 40-namelen, namelen);
91272
91273 - snprintf(ip, sizeof(ip), "[<%p>]",
91274 + snprintf(ip, sizeof(ip), "[<%pK>]",
91275 (void *)class->contending_point[i]);
91276 seq_printf(m, "%40s %14lu %29s %pS\n",
91277 name, stats->contending_point[i],
91278 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
91279 index be9ee15..39d6233 100644
91280 --- a/kernel/locking/mcs_spinlock.c
91281 +++ b/kernel/locking/mcs_spinlock.c
91282 @@ -102,7 +102,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
91283
91284 prev = decode_cpu(old);
91285 node->prev = prev;
91286 - ACCESS_ONCE(prev->next) = node;
91287 + ACCESS_ONCE_RW(prev->next) = node;
91288
91289 /*
91290 * Normally @prev is untouchable after the above store; because at that
91291 @@ -174,8 +174,8 @@ unqueue:
91292 * it will wait in Step-A.
91293 */
91294
91295 - ACCESS_ONCE(next->prev) = prev;
91296 - ACCESS_ONCE(prev->next) = next;
91297 + ACCESS_ONCE_RW(next->prev) = prev;
91298 + ACCESS_ONCE_RW(prev->next) = next;
91299
91300 return false;
91301 }
91302 @@ -197,13 +197,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
91303 node = this_cpu_ptr(&osq_node);
91304 next = xchg(&node->next, NULL);
91305 if (next) {
91306 - ACCESS_ONCE(next->locked) = 1;
91307 + ACCESS_ONCE_RW(next->locked) = 1;
91308 return;
91309 }
91310
91311 next = osq_wait_next(lock, node, NULL);
91312 if (next)
91313 - ACCESS_ONCE(next->locked) = 1;
91314 + ACCESS_ONCE_RW(next->locked) = 1;
91315 }
91316
91317 #endif
91318 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
91319 index 74356dc..48dd5e1 100644
91320 --- a/kernel/locking/mcs_spinlock.h
91321 +++ b/kernel/locking/mcs_spinlock.h
91322 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
91323 */
91324 return;
91325 }
91326 - ACCESS_ONCE(prev->next) = node;
91327 + ACCESS_ONCE_RW(prev->next) = node;
91328
91329 /* Wait until the lock holder passes the lock down. */
91330 arch_mcs_spin_lock_contended(&node->locked);
91331 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
91332 index 5cf6731..ce3bc5a 100644
91333 --- a/kernel/locking/mutex-debug.c
91334 +++ b/kernel/locking/mutex-debug.c
91335 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
91336 }
91337
91338 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
91339 - struct thread_info *ti)
91340 + struct task_struct *task)
91341 {
91342 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
91343
91344 /* Mark the current thread as blocked on the lock: */
91345 - ti->task->blocked_on = waiter;
91346 + task->blocked_on = waiter;
91347 }
91348
91349 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
91350 - struct thread_info *ti)
91351 + struct task_struct *task)
91352 {
91353 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
91354 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
91355 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
91356 - ti->task->blocked_on = NULL;
91357 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
91358 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
91359 + task->blocked_on = NULL;
91360
91361 list_del_init(&waiter->list);
91362 waiter->task = NULL;
91363 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
91364 index 0799fd3..d06ae3b 100644
91365 --- a/kernel/locking/mutex-debug.h
91366 +++ b/kernel/locking/mutex-debug.h
91367 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
91368 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
91369 extern void debug_mutex_add_waiter(struct mutex *lock,
91370 struct mutex_waiter *waiter,
91371 - struct thread_info *ti);
91372 + struct task_struct *task);
91373 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
91374 - struct thread_info *ti);
91375 + struct task_struct *task);
91376 extern void debug_mutex_unlock(struct mutex *lock);
91377 extern void debug_mutex_init(struct mutex *lock, const char *name,
91378 struct lock_class_key *key);
91379 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
91380 index acca2c1..ddeaea8 100644
91381 --- a/kernel/locking/mutex.c
91382 +++ b/kernel/locking/mutex.c
91383 @@ -490,7 +490,7 @@ slowpath:
91384 goto skip_wait;
91385
91386 debug_mutex_lock_common(lock, &waiter);
91387 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
91388 + debug_mutex_add_waiter(lock, &waiter, task);
91389
91390 /* add waiting tasks to the end of the waitqueue (FIFO): */
91391 list_add_tail(&waiter.list, &lock->wait_list);
91392 @@ -534,7 +534,7 @@ slowpath:
91393 schedule_preempt_disabled();
91394 spin_lock_mutex(&lock->wait_lock, flags);
91395 }
91396 - mutex_remove_waiter(lock, &waiter, current_thread_info());
91397 + mutex_remove_waiter(lock, &waiter, task);
91398 /* set it to 0 if there are no waiters left: */
91399 if (likely(list_empty(&lock->wait_list)))
91400 atomic_set(&lock->count, 0);
91401 @@ -571,7 +571,7 @@ skip_wait:
91402 return 0;
91403
91404 err:
91405 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
91406 + mutex_remove_waiter(lock, &waiter, task);
91407 spin_unlock_mutex(&lock->wait_lock, flags);
91408 debug_mutex_free_waiter(&waiter);
91409 mutex_release(&lock->dep_map, 1, ip);
91410 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
91411 index 1d96dd0..994ff19 100644
91412 --- a/kernel/locking/rtmutex-tester.c
91413 +++ b/kernel/locking/rtmutex-tester.c
91414 @@ -22,7 +22,7 @@
91415 #define MAX_RT_TEST_MUTEXES 8
91416
91417 static spinlock_t rttest_lock;
91418 -static atomic_t rttest_event;
91419 +static atomic_unchecked_t rttest_event;
91420
91421 struct test_thread_data {
91422 int opcode;
91423 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91424
91425 case RTTEST_LOCKCONT:
91426 td->mutexes[td->opdata] = 1;
91427 - td->event = atomic_add_return(1, &rttest_event);
91428 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91429 return 0;
91430
91431 case RTTEST_RESET:
91432 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91433 return 0;
91434
91435 case RTTEST_RESETEVENT:
91436 - atomic_set(&rttest_event, 0);
91437 + atomic_set_unchecked(&rttest_event, 0);
91438 return 0;
91439
91440 default:
91441 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91442 return ret;
91443
91444 td->mutexes[id] = 1;
91445 - td->event = atomic_add_return(1, &rttest_event);
91446 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91447 rt_mutex_lock(&mutexes[id]);
91448 - td->event = atomic_add_return(1, &rttest_event);
91449 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91450 td->mutexes[id] = 4;
91451 return 0;
91452
91453 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91454 return ret;
91455
91456 td->mutexes[id] = 1;
91457 - td->event = atomic_add_return(1, &rttest_event);
91458 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91459 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
91460 - td->event = atomic_add_return(1, &rttest_event);
91461 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91462 td->mutexes[id] = ret ? 0 : 4;
91463 return ret ? -EINTR : 0;
91464
91465 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91466 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
91467 return ret;
91468
91469 - td->event = atomic_add_return(1, &rttest_event);
91470 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91471 rt_mutex_unlock(&mutexes[id]);
91472 - td->event = atomic_add_return(1, &rttest_event);
91473 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91474 td->mutexes[id] = 0;
91475 return 0;
91476
91477 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
91478 break;
91479
91480 td->mutexes[dat] = 2;
91481 - td->event = atomic_add_return(1, &rttest_event);
91482 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91483 break;
91484
91485 default:
91486 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
91487 return;
91488
91489 td->mutexes[dat] = 3;
91490 - td->event = atomic_add_return(1, &rttest_event);
91491 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91492 break;
91493
91494 case RTTEST_LOCKNOWAIT:
91495 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
91496 return;
91497
91498 td->mutexes[dat] = 1;
91499 - td->event = atomic_add_return(1, &rttest_event);
91500 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91501 return;
91502
91503 default:
91504 diff --git a/kernel/module.c b/kernel/module.c
91505 index 81e727c..a8ea6f9 100644
91506 --- a/kernel/module.c
91507 +++ b/kernel/module.c
91508 @@ -61,6 +61,7 @@
91509 #include <linux/pfn.h>
91510 #include <linux/bsearch.h>
91511 #include <linux/fips.h>
91512 +#include <linux/grsecurity.h>
91513 #include <uapi/linux/module.h>
91514 #include "module-internal.h"
91515
91516 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
91517
91518 /* Bounds of module allocation, for speeding __module_address.
91519 * Protected by module_mutex. */
91520 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
91521 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
91522 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
91523
91524 int register_module_notifier(struct notifier_block * nb)
91525 {
91526 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
91527 return true;
91528
91529 list_for_each_entry_rcu(mod, &modules, list) {
91530 - struct symsearch arr[] = {
91531 + struct symsearch modarr[] = {
91532 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
91533 NOT_GPL_ONLY, false },
91534 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
91535 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
91536 if (mod->state == MODULE_STATE_UNFORMED)
91537 continue;
91538
91539 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
91540 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
91541 return true;
91542 }
91543 return false;
91544 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
91545 if (!pcpusec->sh_size)
91546 return 0;
91547
91548 - if (align > PAGE_SIZE) {
91549 + if (align-1 >= PAGE_SIZE) {
91550 pr_warn("%s: per-cpu alignment %li > %li\n",
91551 mod->name, align, PAGE_SIZE);
91552 align = PAGE_SIZE;
91553 @@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
91554 static ssize_t show_coresize(struct module_attribute *mattr,
91555 struct module_kobject *mk, char *buffer)
91556 {
91557 - return sprintf(buffer, "%u\n", mk->mod->core_size);
91558 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
91559 }
91560
91561 static struct module_attribute modinfo_coresize =
91562 @@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
91563 static ssize_t show_initsize(struct module_attribute *mattr,
91564 struct module_kobject *mk, char *buffer)
91565 {
91566 - return sprintf(buffer, "%u\n", mk->mod->init_size);
91567 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
91568 }
91569
91570 static struct module_attribute modinfo_initsize =
91571 @@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
91572 goto bad_version;
91573 }
91574
91575 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91576 + /*
91577 + * avoid potentially printing jibberish on attempted load
91578 + * of a module randomized with a different seed
91579 + */
91580 + pr_warn("no symbol version for %s\n", symname);
91581 +#else
91582 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
91583 +#endif
91584 return 0;
91585
91586 bad_version:
91587 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91588 + /*
91589 + * avoid potentially printing jibberish on attempted load
91590 + * of a module randomized with a different seed
91591 + */
91592 + printk("attempted module disagrees about version of symbol %s\n",
91593 + symname);
91594 +#else
91595 printk("%s: disagrees about version of symbol %s\n",
91596 mod->name, symname);
91597 +#endif
91598 return 0;
91599 }
91600
91601 @@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
91602 */
91603 #ifdef CONFIG_SYSFS
91604
91605 -#ifdef CONFIG_KALLSYMS
91606 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
91607 static inline bool sect_empty(const Elf_Shdr *sect)
91608 {
91609 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
91610 @@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
91611 {
91612 unsigned int notes, loaded, i;
91613 struct module_notes_attrs *notes_attrs;
91614 - struct bin_attribute *nattr;
91615 + bin_attribute_no_const *nattr;
91616
91617 /* failed to create section attributes, so can't create notes */
91618 if (!mod->sect_attrs)
91619 @@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
91620 static int module_add_modinfo_attrs(struct module *mod)
91621 {
91622 struct module_attribute *attr;
91623 - struct module_attribute *temp_attr;
91624 + module_attribute_no_const *temp_attr;
91625 int error = 0;
91626 int i;
91627
91628 @@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
91629
91630 static void unset_module_core_ro_nx(struct module *mod)
91631 {
91632 - set_page_attributes(mod->module_core + mod->core_text_size,
91633 - mod->module_core + mod->core_size,
91634 + set_page_attributes(mod->module_core_rw,
91635 + mod->module_core_rw + mod->core_size_rw,
91636 set_memory_x);
91637 - set_page_attributes(mod->module_core,
91638 - mod->module_core + mod->core_ro_size,
91639 + set_page_attributes(mod->module_core_rx,
91640 + mod->module_core_rx + mod->core_size_rx,
91641 set_memory_rw);
91642 }
91643
91644 static void unset_module_init_ro_nx(struct module *mod)
91645 {
91646 - set_page_attributes(mod->module_init + mod->init_text_size,
91647 - mod->module_init + mod->init_size,
91648 + set_page_attributes(mod->module_init_rw,
91649 + mod->module_init_rw + mod->init_size_rw,
91650 set_memory_x);
91651 - set_page_attributes(mod->module_init,
91652 - mod->module_init + mod->init_ro_size,
91653 + set_page_attributes(mod->module_init_rx,
91654 + mod->module_init_rx + mod->init_size_rx,
91655 set_memory_rw);
91656 }
91657
91658 @@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
91659 list_for_each_entry_rcu(mod, &modules, list) {
91660 if (mod->state == MODULE_STATE_UNFORMED)
91661 continue;
91662 - if ((mod->module_core) && (mod->core_text_size)) {
91663 - set_page_attributes(mod->module_core,
91664 - mod->module_core + mod->core_text_size,
91665 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
91666 + set_page_attributes(mod->module_core_rx,
91667 + mod->module_core_rx + mod->core_size_rx,
91668 set_memory_rw);
91669 }
91670 - if ((mod->module_init) && (mod->init_text_size)) {
91671 - set_page_attributes(mod->module_init,
91672 - mod->module_init + mod->init_text_size,
91673 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
91674 + set_page_attributes(mod->module_init_rx,
91675 + mod->module_init_rx + mod->init_size_rx,
91676 set_memory_rw);
91677 }
91678 }
91679 @@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
91680 list_for_each_entry_rcu(mod, &modules, list) {
91681 if (mod->state == MODULE_STATE_UNFORMED)
91682 continue;
91683 - if ((mod->module_core) && (mod->core_text_size)) {
91684 - set_page_attributes(mod->module_core,
91685 - mod->module_core + mod->core_text_size,
91686 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
91687 + set_page_attributes(mod->module_core_rx,
91688 + mod->module_core_rx + mod->core_size_rx,
91689 set_memory_ro);
91690 }
91691 - if ((mod->module_init) && (mod->init_text_size)) {
91692 - set_page_attributes(mod->module_init,
91693 - mod->module_init + mod->init_text_size,
91694 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
91695 + set_page_attributes(mod->module_init_rx,
91696 + mod->module_init_rx + mod->init_size_rx,
91697 set_memory_ro);
91698 }
91699 }
91700 @@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
91701
91702 /* This may be NULL, but that's OK */
91703 unset_module_init_ro_nx(mod);
91704 - module_free(mod, mod->module_init);
91705 + module_free(mod, mod->module_init_rw);
91706 + module_free_exec(mod, mod->module_init_rx);
91707 kfree(mod->args);
91708 percpu_modfree(mod);
91709
91710 /* Free lock-classes: */
91711 - lockdep_free_key_range(mod->module_core, mod->core_size);
91712 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
91713 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
91714
91715 /* Finally, free the core (containing the module structure) */
91716 unset_module_core_ro_nx(mod);
91717 - module_free(mod, mod->module_core);
91718 + module_free_exec(mod, mod->module_core_rx);
91719 + module_free(mod, mod->module_core_rw);
91720
91721 #ifdef CONFIG_MPU
91722 update_protections(current->mm);
91723 @@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
91724 int ret = 0;
91725 const struct kernel_symbol *ksym;
91726
91727 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91728 + int is_fs_load = 0;
91729 + int register_filesystem_found = 0;
91730 + char *p;
91731 +
91732 + p = strstr(mod->args, "grsec_modharden_fs");
91733 + if (p) {
91734 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
91735 + /* copy \0 as well */
91736 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
91737 + is_fs_load = 1;
91738 + }
91739 +#endif
91740 +
91741 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
91742 const char *name = info->strtab + sym[i].st_name;
91743
91744 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91745 + /* it's a real shame this will never get ripped and copied
91746 + upstream! ;(
91747 + */
91748 + if (is_fs_load && !strcmp(name, "register_filesystem"))
91749 + register_filesystem_found = 1;
91750 +#endif
91751 +
91752 switch (sym[i].st_shndx) {
91753 case SHN_COMMON:
91754 /* Ignore common symbols */
91755 @@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
91756 ksym = resolve_symbol_wait(mod, info, name);
91757 /* Ok if resolved. */
91758 if (ksym && !IS_ERR(ksym)) {
91759 + pax_open_kernel();
91760 sym[i].st_value = ksym->value;
91761 + pax_close_kernel();
91762 break;
91763 }
91764
91765 @@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
91766 secbase = (unsigned long)mod_percpu(mod);
91767 else
91768 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
91769 + pax_open_kernel();
91770 sym[i].st_value += secbase;
91771 + pax_close_kernel();
91772 break;
91773 }
91774 }
91775
91776 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91777 + if (is_fs_load && !register_filesystem_found) {
91778 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
91779 + ret = -EPERM;
91780 + }
91781 +#endif
91782 +
91783 return ret;
91784 }
91785
91786 @@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
91787 || s->sh_entsize != ~0UL
91788 || strstarts(sname, ".init"))
91789 continue;
91790 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
91791 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
91792 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
91793 + else
91794 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
91795 pr_debug("\t%s\n", sname);
91796 }
91797 - switch (m) {
91798 - case 0: /* executable */
91799 - mod->core_size = debug_align(mod->core_size);
91800 - mod->core_text_size = mod->core_size;
91801 - break;
91802 - case 1: /* RO: text and ro-data */
91803 - mod->core_size = debug_align(mod->core_size);
91804 - mod->core_ro_size = mod->core_size;
91805 - break;
91806 - case 3: /* whole core */
91807 - mod->core_size = debug_align(mod->core_size);
91808 - break;
91809 - }
91810 }
91811
91812 pr_debug("Init section allocation order:\n");
91813 @@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
91814 || s->sh_entsize != ~0UL
91815 || !strstarts(sname, ".init"))
91816 continue;
91817 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
91818 - | INIT_OFFSET_MASK);
91819 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
91820 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
91821 + else
91822 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
91823 + s->sh_entsize |= INIT_OFFSET_MASK;
91824 pr_debug("\t%s\n", sname);
91825 }
91826 - switch (m) {
91827 - case 0: /* executable */
91828 - mod->init_size = debug_align(mod->init_size);
91829 - mod->init_text_size = mod->init_size;
91830 - break;
91831 - case 1: /* RO: text and ro-data */
91832 - mod->init_size = debug_align(mod->init_size);
91833 - mod->init_ro_size = mod->init_size;
91834 - break;
91835 - case 3: /* whole init */
91836 - mod->init_size = debug_align(mod->init_size);
91837 - break;
91838 - }
91839 }
91840 }
91841
91842 @@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
91843
91844 /* Put symbol section at end of init part of module. */
91845 symsect->sh_flags |= SHF_ALLOC;
91846 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
91847 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
91848 info->index.sym) | INIT_OFFSET_MASK;
91849 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
91850
91851 @@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
91852 }
91853
91854 /* Append room for core symbols at end of core part. */
91855 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
91856 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
91857 - mod->core_size += strtab_size;
91858 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
91859 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
91860 + mod->core_size_rx += strtab_size;
91861
91862 /* Put string table section at end of init part of module. */
91863 strsect->sh_flags |= SHF_ALLOC;
91864 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
91865 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
91866 info->index.str) | INIT_OFFSET_MASK;
91867 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
91868 }
91869 @@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
91870 /* Make sure we get permanent strtab: don't use info->strtab. */
91871 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
91872
91873 + pax_open_kernel();
91874 +
91875 /* Set types up while we still have access to sections. */
91876 for (i = 0; i < mod->num_symtab; i++)
91877 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
91878
91879 - mod->core_symtab = dst = mod->module_core + info->symoffs;
91880 - mod->core_strtab = s = mod->module_core + info->stroffs;
91881 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
91882 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
91883 src = mod->symtab;
91884 for (ndst = i = 0; i < mod->num_symtab; i++) {
91885 if (i == 0 ||
91886 @@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
91887 }
91888 }
91889 mod->core_num_syms = ndst;
91890 +
91891 + pax_close_kernel();
91892 }
91893 #else
91894 static inline void layout_symtab(struct module *mod, struct load_info *info)
91895 @@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
91896 return vmalloc_exec(size);
91897 }
91898
91899 -static void *module_alloc_update_bounds(unsigned long size)
91900 +static void *module_alloc_update_bounds_rw(unsigned long size)
91901 {
91902 void *ret = module_alloc(size);
91903
91904 if (ret) {
91905 mutex_lock(&module_mutex);
91906 /* Update module bounds. */
91907 - if ((unsigned long)ret < module_addr_min)
91908 - module_addr_min = (unsigned long)ret;
91909 - if ((unsigned long)ret + size > module_addr_max)
91910 - module_addr_max = (unsigned long)ret + size;
91911 + if ((unsigned long)ret < module_addr_min_rw)
91912 + module_addr_min_rw = (unsigned long)ret;
91913 + if ((unsigned long)ret + size > module_addr_max_rw)
91914 + module_addr_max_rw = (unsigned long)ret + size;
91915 + mutex_unlock(&module_mutex);
91916 + }
91917 + return ret;
91918 +}
91919 +
91920 +static void *module_alloc_update_bounds_rx(unsigned long size)
91921 +{
91922 + void *ret = module_alloc_exec(size);
91923 +
91924 + if (ret) {
91925 + mutex_lock(&module_mutex);
91926 + /* Update module bounds. */
91927 + if ((unsigned long)ret < module_addr_min_rx)
91928 + module_addr_min_rx = (unsigned long)ret;
91929 + if ((unsigned long)ret + size > module_addr_max_rx)
91930 + module_addr_max_rx = (unsigned long)ret + size;
91931 mutex_unlock(&module_mutex);
91932 }
91933 return ret;
91934 @@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91935 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
91936
91937 if (info->index.sym == 0) {
91938 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91939 + /*
91940 + * avoid potentially printing jibberish on attempted load
91941 + * of a module randomized with a different seed
91942 + */
91943 + pr_warn("module has no symbols (stripped?)\n");
91944 +#else
91945 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
91946 +#endif
91947 return ERR_PTR(-ENOEXEC);
91948 }
91949
91950 @@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91951 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91952 {
91953 const char *modmagic = get_modinfo(info, "vermagic");
91954 + const char *license = get_modinfo(info, "license");
91955 int err;
91956
91957 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
91958 + if (!license || !license_is_gpl_compatible(license))
91959 + return -ENOEXEC;
91960 +#endif
91961 +
91962 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
91963 modmagic = NULL;
91964
91965 @@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91966 }
91967
91968 /* Set up license info based on the info section */
91969 - set_license(mod, get_modinfo(info, "license"));
91970 + set_license(mod, license);
91971
91972 return 0;
91973 }
91974 @@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
91975 void *ptr;
91976
91977 /* Do the allocs. */
91978 - ptr = module_alloc_update_bounds(mod->core_size);
91979 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
91980 /*
91981 * The pointer to this block is stored in the module structure
91982 * which is inside the block. Just mark it as not being a
91983 @@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
91984 if (!ptr)
91985 return -ENOMEM;
91986
91987 - memset(ptr, 0, mod->core_size);
91988 - mod->module_core = ptr;
91989 + memset(ptr, 0, mod->core_size_rw);
91990 + mod->module_core_rw = ptr;
91991
91992 - if (mod->init_size) {
91993 - ptr = module_alloc_update_bounds(mod->init_size);
91994 + if (mod->init_size_rw) {
91995 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
91996 /*
91997 * The pointer to this block is stored in the module structure
91998 * which is inside the block. This block doesn't need to be
91999 @@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
92000 */
92001 kmemleak_ignore(ptr);
92002 if (!ptr) {
92003 - module_free(mod, mod->module_core);
92004 + module_free(mod, mod->module_core_rw);
92005 return -ENOMEM;
92006 }
92007 - memset(ptr, 0, mod->init_size);
92008 - mod->module_init = ptr;
92009 + memset(ptr, 0, mod->init_size_rw);
92010 + mod->module_init_rw = ptr;
92011 } else
92012 - mod->module_init = NULL;
92013 + mod->module_init_rw = NULL;
92014 +
92015 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
92016 + kmemleak_not_leak(ptr);
92017 + if (!ptr) {
92018 + if (mod->module_init_rw)
92019 + module_free(mod, mod->module_init_rw);
92020 + module_free(mod, mod->module_core_rw);
92021 + return -ENOMEM;
92022 + }
92023 +
92024 + pax_open_kernel();
92025 + memset(ptr, 0, mod->core_size_rx);
92026 + pax_close_kernel();
92027 + mod->module_core_rx = ptr;
92028 +
92029 + if (mod->init_size_rx) {
92030 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
92031 + kmemleak_ignore(ptr);
92032 + if (!ptr && mod->init_size_rx) {
92033 + module_free_exec(mod, mod->module_core_rx);
92034 + if (mod->module_init_rw)
92035 + module_free(mod, mod->module_init_rw);
92036 + module_free(mod, mod->module_core_rw);
92037 + return -ENOMEM;
92038 + }
92039 +
92040 + pax_open_kernel();
92041 + memset(ptr, 0, mod->init_size_rx);
92042 + pax_close_kernel();
92043 + mod->module_init_rx = ptr;
92044 + } else
92045 + mod->module_init_rx = NULL;
92046
92047 /* Transfer each section which specifies SHF_ALLOC */
92048 pr_debug("final section addresses:\n");
92049 @@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
92050 if (!(shdr->sh_flags & SHF_ALLOC))
92051 continue;
92052
92053 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
92054 - dest = mod->module_init
92055 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
92056 - else
92057 - dest = mod->module_core + shdr->sh_entsize;
92058 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
92059 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
92060 + dest = mod->module_init_rw
92061 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
92062 + else
92063 + dest = mod->module_init_rx
92064 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
92065 + } else {
92066 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
92067 + dest = mod->module_core_rw + shdr->sh_entsize;
92068 + else
92069 + dest = mod->module_core_rx + shdr->sh_entsize;
92070 + }
92071 +
92072 + if (shdr->sh_type != SHT_NOBITS) {
92073 +
92074 +#ifdef CONFIG_PAX_KERNEXEC
92075 +#ifdef CONFIG_X86_64
92076 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
92077 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
92078 +#endif
92079 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
92080 + pax_open_kernel();
92081 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
92082 + pax_close_kernel();
92083 + } else
92084 +#endif
92085
92086 - if (shdr->sh_type != SHT_NOBITS)
92087 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
92088 + }
92089 /* Update sh_addr to point to copy in image. */
92090 - shdr->sh_addr = (unsigned long)dest;
92091 +
92092 +#ifdef CONFIG_PAX_KERNEXEC
92093 + if (shdr->sh_flags & SHF_EXECINSTR)
92094 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
92095 + else
92096 +#endif
92097 +
92098 + shdr->sh_addr = (unsigned long)dest;
92099 pr_debug("\t0x%lx %s\n",
92100 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
92101 }
92102 @@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
92103 * Do it before processing of module parameters, so the module
92104 * can provide parameter accessor functions of its own.
92105 */
92106 - if (mod->module_init)
92107 - flush_icache_range((unsigned long)mod->module_init,
92108 - (unsigned long)mod->module_init
92109 - + mod->init_size);
92110 - flush_icache_range((unsigned long)mod->module_core,
92111 - (unsigned long)mod->module_core + mod->core_size);
92112 + if (mod->module_init_rx)
92113 + flush_icache_range((unsigned long)mod->module_init_rx,
92114 + (unsigned long)mod->module_init_rx
92115 + + mod->init_size_rx);
92116 + flush_icache_range((unsigned long)mod->module_core_rx,
92117 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
92118
92119 set_fs(old_fs);
92120 }
92121 @@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
92122 static void module_deallocate(struct module *mod, struct load_info *info)
92123 {
92124 percpu_modfree(mod);
92125 - module_free(mod, mod->module_init);
92126 - module_free(mod, mod->module_core);
92127 + module_free_exec(mod, mod->module_init_rx);
92128 + module_free_exec(mod, mod->module_core_rx);
92129 + module_free(mod, mod->module_init_rw);
92130 + module_free(mod, mod->module_core_rw);
92131 }
92132
92133 int __weak module_finalize(const Elf_Ehdr *hdr,
92134 @@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
92135 static int post_relocation(struct module *mod, const struct load_info *info)
92136 {
92137 /* Sort exception table now relocations are done. */
92138 + pax_open_kernel();
92139 sort_extable(mod->extable, mod->extable + mod->num_exentries);
92140 + pax_close_kernel();
92141
92142 /* Copy relocated percpu area over. */
92143 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
92144 @@ -3079,11 +3213,12 @@ static int do_init_module(struct module *mod)
92145 mod->strtab = mod->core_strtab;
92146 #endif
92147 unset_module_init_ro_nx(mod);
92148 - module_free(mod, mod->module_init);
92149 - mod->module_init = NULL;
92150 - mod->init_size = 0;
92151 - mod->init_ro_size = 0;
92152 - mod->init_text_size = 0;
92153 + module_free(mod, mod->module_init_rw);
92154 + module_free_exec(mod, mod->module_init_rx);
92155 + mod->module_init_rw = NULL;
92156 + mod->module_init_rx = NULL;
92157 + mod->init_size_rw = 0;
92158 + mod->init_size_rx = 0;
92159 mutex_unlock(&module_mutex);
92160 wake_up_all(&module_wq);
92161
92162 @@ -3151,16 +3286,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
92163 module_bug_finalize(info->hdr, info->sechdrs, mod);
92164
92165 /* Set RO and NX regions for core */
92166 - set_section_ro_nx(mod->module_core,
92167 - mod->core_text_size,
92168 - mod->core_ro_size,
92169 - mod->core_size);
92170 + set_section_ro_nx(mod->module_core_rx,
92171 + mod->core_size_rx,
92172 + mod->core_size_rx,
92173 + mod->core_size_rx);
92174
92175 /* Set RO and NX regions for init */
92176 - set_section_ro_nx(mod->module_init,
92177 - mod->init_text_size,
92178 - mod->init_ro_size,
92179 - mod->init_size);
92180 + set_section_ro_nx(mod->module_init_rx,
92181 + mod->init_size_rx,
92182 + mod->init_size_rx,
92183 + mod->init_size_rx);
92184
92185 /* Mark state as coming so strong_try_module_get() ignores us,
92186 * but kallsyms etc. can see us. */
92187 @@ -3244,9 +3379,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
92188 if (err)
92189 goto free_unload;
92190
92191 + /* Now copy in args */
92192 + mod->args = strndup_user(uargs, ~0UL >> 1);
92193 + if (IS_ERR(mod->args)) {
92194 + err = PTR_ERR(mod->args);
92195 + goto free_unload;
92196 + }
92197 +
92198 /* Set up MODINFO_ATTR fields */
92199 setup_modinfo(mod, info);
92200
92201 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
92202 + {
92203 + char *p, *p2;
92204 +
92205 + if (strstr(mod->args, "grsec_modharden_netdev")) {
92206 + printk(KERN_ALERT "grsec: denied auto-loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%.64s instead.", mod->name);
92207 + err = -EPERM;
92208 + goto free_modinfo;
92209 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
92210 + p += sizeof("grsec_modharden_normal") - 1;
92211 + p2 = strstr(p, "_");
92212 + if (p2) {
92213 + *p2 = '\0';
92214 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
92215 + *p2 = '_';
92216 + }
92217 + err = -EPERM;
92218 + goto free_modinfo;
92219 + }
92220 + }
92221 +#endif
92222 +
92223 /* Fix up syms, so that st_value is a pointer to location. */
92224 err = simplify_symbols(mod, info);
92225 if (err < 0)
92226 @@ -3262,13 +3426,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
92227
92228 flush_module_icache(mod);
92229
92230 - /* Now copy in args */
92231 - mod->args = strndup_user(uargs, ~0UL >> 1);
92232 - if (IS_ERR(mod->args)) {
92233 - err = PTR_ERR(mod->args);
92234 - goto free_arch_cleanup;
92235 - }
92236 -
92237 dynamic_debug_setup(info->debug, info->num_debug);
92238
92239 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
92240 @@ -3311,11 +3468,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
92241 ddebug_cleanup:
92242 dynamic_debug_remove(info->debug);
92243 synchronize_sched();
92244 - kfree(mod->args);
92245 - free_arch_cleanup:
92246 module_arch_cleanup(mod);
92247 free_modinfo:
92248 free_modinfo(mod);
92249 + kfree(mod->args);
92250 free_unload:
92251 module_unload_free(mod);
92252 unlink_mod:
92253 @@ -3398,10 +3554,16 @@ static const char *get_ksymbol(struct module *mod,
92254 unsigned long nextval;
92255
92256 /* At worse, next value is at end of module */
92257 - if (within_module_init(addr, mod))
92258 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
92259 + if (within_module_init_rx(addr, mod))
92260 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
92261 + else if (within_module_init_rw(addr, mod))
92262 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
92263 + else if (within_module_core_rx(addr, mod))
92264 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
92265 + else if (within_module_core_rw(addr, mod))
92266 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
92267 else
92268 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
92269 + return NULL;
92270
92271 /* Scan for closest preceding symbol, and next symbol. (ELF
92272 starts real symbols at 1). */
92273 @@ -3652,7 +3814,7 @@ static int m_show(struct seq_file *m, void *p)
92274 return 0;
92275
92276 seq_printf(m, "%s %u",
92277 - mod->name, mod->init_size + mod->core_size);
92278 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
92279 print_unload_info(m, mod);
92280
92281 /* Informative for users. */
92282 @@ -3661,7 +3823,7 @@ static int m_show(struct seq_file *m, void *p)
92283 mod->state == MODULE_STATE_COMING ? "Loading":
92284 "Live");
92285 /* Used by oprofile and other similar tools. */
92286 - seq_printf(m, " 0x%pK", mod->module_core);
92287 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
92288
92289 /* Taints info */
92290 if (mod->taints)
92291 @@ -3697,7 +3859,17 @@ static const struct file_operations proc_modules_operations = {
92292
92293 static int __init proc_modules_init(void)
92294 {
92295 +#ifndef CONFIG_GRKERNSEC_HIDESYM
92296 +#ifdef CONFIG_GRKERNSEC_PROC_USER
92297 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
92298 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92299 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
92300 +#else
92301 proc_create("modules", 0, NULL, &proc_modules_operations);
92302 +#endif
92303 +#else
92304 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
92305 +#endif
92306 return 0;
92307 }
92308 module_init(proc_modules_init);
92309 @@ -3758,14 +3930,14 @@ struct module *__module_address(unsigned long addr)
92310 {
92311 struct module *mod;
92312
92313 - if (addr < module_addr_min || addr > module_addr_max)
92314 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
92315 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
92316 return NULL;
92317
92318 list_for_each_entry_rcu(mod, &modules, list) {
92319 if (mod->state == MODULE_STATE_UNFORMED)
92320 continue;
92321 - if (within_module_core(addr, mod)
92322 - || within_module_init(addr, mod))
92323 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
92324 return mod;
92325 }
92326 return NULL;
92327 @@ -3800,11 +3972,20 @@ bool is_module_text_address(unsigned long addr)
92328 */
92329 struct module *__module_text_address(unsigned long addr)
92330 {
92331 - struct module *mod = __module_address(addr);
92332 + struct module *mod;
92333 +
92334 +#ifdef CONFIG_X86_32
92335 + addr = ktla_ktva(addr);
92336 +#endif
92337 +
92338 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
92339 + return NULL;
92340 +
92341 + mod = __module_address(addr);
92342 +
92343 if (mod) {
92344 /* Make sure it's within the text section. */
92345 - if (!within(addr, mod->module_init, mod->init_text_size)
92346 - && !within(addr, mod->module_core, mod->core_text_size))
92347 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
92348 mod = NULL;
92349 }
92350 return mod;
92351 diff --git a/kernel/notifier.c b/kernel/notifier.c
92352 index 4803da6..1c5eea6 100644
92353 --- a/kernel/notifier.c
92354 +++ b/kernel/notifier.c
92355 @@ -5,6 +5,7 @@
92356 #include <linux/rcupdate.h>
92357 #include <linux/vmalloc.h>
92358 #include <linux/reboot.h>
92359 +#include <linux/mm.h>
92360
92361 /*
92362 * Notifier list for kernel code which wants to be called
92363 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
92364 while ((*nl) != NULL) {
92365 if (n->priority > (*nl)->priority)
92366 break;
92367 - nl = &((*nl)->next);
92368 + nl = (struct notifier_block **)&((*nl)->next);
92369 }
92370 - n->next = *nl;
92371 + pax_open_kernel();
92372 + *(const void **)&n->next = *nl;
92373 rcu_assign_pointer(*nl, n);
92374 + pax_close_kernel();
92375 return 0;
92376 }
92377
92378 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
92379 return 0;
92380 if (n->priority > (*nl)->priority)
92381 break;
92382 - nl = &((*nl)->next);
92383 + nl = (struct notifier_block **)&((*nl)->next);
92384 }
92385 - n->next = *nl;
92386 + pax_open_kernel();
92387 + *(const void **)&n->next = *nl;
92388 rcu_assign_pointer(*nl, n);
92389 + pax_close_kernel();
92390 return 0;
92391 }
92392
92393 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
92394 {
92395 while ((*nl) != NULL) {
92396 if ((*nl) == n) {
92397 + pax_open_kernel();
92398 rcu_assign_pointer(*nl, n->next);
92399 + pax_close_kernel();
92400 return 0;
92401 }
92402 - nl = &((*nl)->next);
92403 + nl = (struct notifier_block **)&((*nl)->next);
92404 }
92405 return -ENOENT;
92406 }
92407 diff --git a/kernel/padata.c b/kernel/padata.c
92408 index 161402f..598814c 100644
92409 --- a/kernel/padata.c
92410 +++ b/kernel/padata.c
92411 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
92412 * seq_nr mod. number of cpus in use.
92413 */
92414
92415 - seq_nr = atomic_inc_return(&pd->seq_nr);
92416 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
92417 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
92418
92419 return padata_index_to_cpu(pd, cpu_index);
92420 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
92421 padata_init_pqueues(pd);
92422 padata_init_squeues(pd);
92423 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
92424 - atomic_set(&pd->seq_nr, -1);
92425 + atomic_set_unchecked(&pd->seq_nr, -1);
92426 atomic_set(&pd->reorder_objects, 0);
92427 atomic_set(&pd->refcnt, 0);
92428 pd->pinst = pinst;
92429 diff --git a/kernel/panic.c b/kernel/panic.c
92430 index 62e16ce..9db5047b 100644
92431 --- a/kernel/panic.c
92432 +++ b/kernel/panic.c
92433 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
92434 /*
92435 * Stop ourself in panic -- architecture code may override this
92436 */
92437 -void __weak panic_smp_self_stop(void)
92438 +void __weak __noreturn panic_smp_self_stop(void)
92439 {
92440 while (1)
92441 cpu_relax();
92442 @@ -420,7 +420,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
92443 disable_trace_on_warning();
92444
92445 pr_warn("------------[ cut here ]------------\n");
92446 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
92447 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
92448 raw_smp_processor_id(), current->pid, file, line, caller);
92449
92450 if (args)
92451 @@ -474,7 +474,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
92452 */
92453 __visible void __stack_chk_fail(void)
92454 {
92455 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
92456 + dump_stack();
92457 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
92458 __builtin_return_address(0));
92459 }
92460 EXPORT_SYMBOL(__stack_chk_fail);
92461 diff --git a/kernel/pid.c b/kernel/pid.c
92462 index 9b9a266..c20ef80 100644
92463 --- a/kernel/pid.c
92464 +++ b/kernel/pid.c
92465 @@ -33,6 +33,7 @@
92466 #include <linux/rculist.h>
92467 #include <linux/bootmem.h>
92468 #include <linux/hash.h>
92469 +#include <linux/security.h>
92470 #include <linux/pid_namespace.h>
92471 #include <linux/init_task.h>
92472 #include <linux/syscalls.h>
92473 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
92474
92475 int pid_max = PID_MAX_DEFAULT;
92476
92477 -#define RESERVED_PIDS 300
92478 +#define RESERVED_PIDS 500
92479
92480 int pid_max_min = RESERVED_PIDS + 1;
92481 int pid_max_max = PID_MAX_LIMIT;
92482 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
92483 */
92484 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
92485 {
92486 + struct task_struct *task;
92487 +
92488 rcu_lockdep_assert(rcu_read_lock_held(),
92489 "find_task_by_pid_ns() needs rcu_read_lock()"
92490 " protection");
92491 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
92492 +
92493 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
92494 +
92495 + if (gr_pid_is_chrooted(task))
92496 + return NULL;
92497 +
92498 + return task;
92499 }
92500
92501 struct task_struct *find_task_by_vpid(pid_t vnr)
92502 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
92503 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
92504 }
92505
92506 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
92507 +{
92508 + rcu_lockdep_assert(rcu_read_lock_held(),
92509 + "find_task_by_pid_ns() needs rcu_read_lock()"
92510 + " protection");
92511 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
92512 +}
92513 +
92514 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
92515 {
92516 struct pid *pid;
92517 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
92518 index db95d8e..a0ca23f 100644
92519 --- a/kernel/pid_namespace.c
92520 +++ b/kernel/pid_namespace.c
92521 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
92522 void __user *buffer, size_t *lenp, loff_t *ppos)
92523 {
92524 struct pid_namespace *pid_ns = task_active_pid_ns(current);
92525 - struct ctl_table tmp = *table;
92526 + ctl_table_no_const tmp = *table;
92527
92528 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
92529 return -EPERM;
92530 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
92531 index 3b89464..5e38379 100644
92532 --- a/kernel/posix-cpu-timers.c
92533 +++ b/kernel/posix-cpu-timers.c
92534 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
92535
92536 static __init int init_posix_cpu_timers(void)
92537 {
92538 - struct k_clock process = {
92539 + static struct k_clock process = {
92540 .clock_getres = process_cpu_clock_getres,
92541 .clock_get = process_cpu_clock_get,
92542 .timer_create = process_cpu_timer_create,
92543 .nsleep = process_cpu_nsleep,
92544 .nsleep_restart = process_cpu_nsleep_restart,
92545 };
92546 - struct k_clock thread = {
92547 + static struct k_clock thread = {
92548 .clock_getres = thread_cpu_clock_getres,
92549 .clock_get = thread_cpu_clock_get,
92550 .timer_create = thread_cpu_timer_create,
92551 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
92552 index 424c2d4..679242f 100644
92553 --- a/kernel/posix-timers.c
92554 +++ b/kernel/posix-timers.c
92555 @@ -43,6 +43,7 @@
92556 #include <linux/hash.h>
92557 #include <linux/posix-clock.h>
92558 #include <linux/posix-timers.h>
92559 +#include <linux/grsecurity.h>
92560 #include <linux/syscalls.h>
92561 #include <linux/wait.h>
92562 #include <linux/workqueue.h>
92563 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
92564 * which we beg off on and pass to do_sys_settimeofday().
92565 */
92566
92567 -static struct k_clock posix_clocks[MAX_CLOCKS];
92568 +static struct k_clock *posix_clocks[MAX_CLOCKS];
92569
92570 /*
92571 * These ones are defined below.
92572 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
92573 */
92574 static __init int init_posix_timers(void)
92575 {
92576 - struct k_clock clock_realtime = {
92577 + static struct k_clock clock_realtime = {
92578 .clock_getres = hrtimer_get_res,
92579 .clock_get = posix_clock_realtime_get,
92580 .clock_set = posix_clock_realtime_set,
92581 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
92582 .timer_get = common_timer_get,
92583 .timer_del = common_timer_del,
92584 };
92585 - struct k_clock clock_monotonic = {
92586 + static struct k_clock clock_monotonic = {
92587 .clock_getres = hrtimer_get_res,
92588 .clock_get = posix_ktime_get_ts,
92589 .nsleep = common_nsleep,
92590 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
92591 .timer_get = common_timer_get,
92592 .timer_del = common_timer_del,
92593 };
92594 - struct k_clock clock_monotonic_raw = {
92595 + static struct k_clock clock_monotonic_raw = {
92596 .clock_getres = hrtimer_get_res,
92597 .clock_get = posix_get_monotonic_raw,
92598 };
92599 - struct k_clock clock_realtime_coarse = {
92600 + static struct k_clock clock_realtime_coarse = {
92601 .clock_getres = posix_get_coarse_res,
92602 .clock_get = posix_get_realtime_coarse,
92603 };
92604 - struct k_clock clock_monotonic_coarse = {
92605 + static struct k_clock clock_monotonic_coarse = {
92606 .clock_getres = posix_get_coarse_res,
92607 .clock_get = posix_get_monotonic_coarse,
92608 };
92609 - struct k_clock clock_tai = {
92610 + static struct k_clock clock_tai = {
92611 .clock_getres = hrtimer_get_res,
92612 .clock_get = posix_get_tai,
92613 .nsleep = common_nsleep,
92614 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
92615 .timer_get = common_timer_get,
92616 .timer_del = common_timer_del,
92617 };
92618 - struct k_clock clock_boottime = {
92619 + static struct k_clock clock_boottime = {
92620 .clock_getres = hrtimer_get_res,
92621 .clock_get = posix_get_boottime,
92622 .nsleep = common_nsleep,
92623 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
92624 return;
92625 }
92626
92627 - posix_clocks[clock_id] = *new_clock;
92628 + posix_clocks[clock_id] = new_clock;
92629 }
92630 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
92631
92632 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
92633 return (id & CLOCKFD_MASK) == CLOCKFD ?
92634 &clock_posix_dynamic : &clock_posix_cpu;
92635
92636 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
92637 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
92638 return NULL;
92639 - return &posix_clocks[id];
92640 + return posix_clocks[id];
92641 }
92642
92643 static int common_timer_create(struct k_itimer *new_timer)
92644 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
92645 struct k_clock *kc = clockid_to_kclock(which_clock);
92646 struct k_itimer *new_timer;
92647 int error, new_timer_id;
92648 - sigevent_t event;
92649 + sigevent_t event = { };
92650 int it_id_set = IT_ID_NOT_SET;
92651
92652 if (!kc)
92653 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
92654 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
92655 return -EFAULT;
92656
92657 + /* only the CLOCK_REALTIME clock can be set, all other clocks
92658 + have their clock_set fptr set to a nosettime dummy function
92659 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
92660 + call common_clock_set, which calls do_sys_settimeofday, which
92661 + we hook
92662 + */
92663 +
92664 return kc->clock_set(which_clock, &new_tp);
92665 }
92666
92667 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
92668 index 9a83d78..128bfc0 100644
92669 --- a/kernel/power/Kconfig
92670 +++ b/kernel/power/Kconfig
92671 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
92672 config HIBERNATION
92673 bool "Hibernation (aka 'suspend to disk')"
92674 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
92675 + depends on !GRKERNSEC_KMEM
92676 + depends on !PAX_MEMORY_SANITIZE
92677 select HIBERNATE_CALLBACKS
92678 select LZO_COMPRESS
92679 select LZO_DECOMPRESS
92680 diff --git a/kernel/power/process.c b/kernel/power/process.c
92681 index 4ee194e..925778f 100644
92682 --- a/kernel/power/process.c
92683 +++ b/kernel/power/process.c
92684 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
92685 unsigned int elapsed_msecs;
92686 bool wakeup = false;
92687 int sleep_usecs = USEC_PER_MSEC;
92688 + bool timedout = false;
92689
92690 do_gettimeofday(&start);
92691
92692 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
92693
92694 while (true) {
92695 todo = 0;
92696 + if (time_after(jiffies, end_time))
92697 + timedout = true;
92698 read_lock(&tasklist_lock);
92699 do_each_thread(g, p) {
92700 if (p == current || !freeze_task(p))
92701 continue;
92702
92703 - if (!freezer_should_skip(p))
92704 + if (!freezer_should_skip(p)) {
92705 todo++;
92706 + if (timedout) {
92707 + printk(KERN_ERR "Task refusing to freeze:\n");
92708 + sched_show_task(p);
92709 + }
92710 + }
92711 } while_each_thread(g, p);
92712 read_unlock(&tasklist_lock);
92713
92714 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
92715 todo += wq_busy;
92716 }
92717
92718 - if (!todo || time_after(jiffies, end_time))
92719 + if (!todo || timedout)
92720 break;
92721
92722 if (pm_wakeup_pending()) {
92723 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
92724 index 13e839d..8a71f12 100644
92725 --- a/kernel/printk/printk.c
92726 +++ b/kernel/printk/printk.c
92727 @@ -480,6 +480,11 @@ static int check_syslog_permissions(int type, bool from_file)
92728 if (from_file && type != SYSLOG_ACTION_OPEN)
92729 return 0;
92730
92731 +#ifdef CONFIG_GRKERNSEC_DMESG
92732 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
92733 + return -EPERM;
92734 +#endif
92735 +
92736 if (syslog_action_restricted(type)) {
92737 if (capable(CAP_SYSLOG))
92738 return 0;
92739 diff --git a/kernel/profile.c b/kernel/profile.c
92740 index 54bf5ba..df6e0a2 100644
92741 --- a/kernel/profile.c
92742 +++ b/kernel/profile.c
92743 @@ -37,7 +37,7 @@ struct profile_hit {
92744 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
92745 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
92746
92747 -static atomic_t *prof_buffer;
92748 +static atomic_unchecked_t *prof_buffer;
92749 static unsigned long prof_len, prof_shift;
92750
92751 int prof_on __read_mostly;
92752 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
92753 hits[i].pc = 0;
92754 continue;
92755 }
92756 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
92757 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
92758 hits[i].hits = hits[i].pc = 0;
92759 }
92760 }
92761 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
92762 * Add the current hit(s) and flush the write-queue out
92763 * to the global buffer:
92764 */
92765 - atomic_add(nr_hits, &prof_buffer[pc]);
92766 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
92767 for (i = 0; i < NR_PROFILE_HIT; ++i) {
92768 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
92769 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
92770 hits[i].pc = hits[i].hits = 0;
92771 }
92772 out:
92773 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
92774 {
92775 unsigned long pc;
92776 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
92777 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
92778 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
92779 }
92780 #endif /* !CONFIG_SMP */
92781
92782 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
92783 return -EFAULT;
92784 buf++; p++; count--; read++;
92785 }
92786 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
92787 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
92788 if (copy_to_user(buf, (void *)pnt, count))
92789 return -EFAULT;
92790 read += count;
92791 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
92792 }
92793 #endif
92794 profile_discard_flip_buffers();
92795 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
92796 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
92797 return count;
92798 }
92799
92800 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
92801 index adf9862..9d86345 100644
92802 --- a/kernel/ptrace.c
92803 +++ b/kernel/ptrace.c
92804 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
92805 if (seize)
92806 flags |= PT_SEIZED;
92807 rcu_read_lock();
92808 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
92809 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
92810 flags |= PT_PTRACE_CAP;
92811 rcu_read_unlock();
92812 task->ptrace = flags;
92813 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
92814 break;
92815 return -EIO;
92816 }
92817 - if (copy_to_user(dst, buf, retval))
92818 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
92819 return -EFAULT;
92820 copied += retval;
92821 src += retval;
92822 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
92823 bool seized = child->ptrace & PT_SEIZED;
92824 int ret = -EIO;
92825 siginfo_t siginfo, *si;
92826 - void __user *datavp = (void __user *) data;
92827 + void __user *datavp = (__force void __user *) data;
92828 unsigned long __user *datalp = datavp;
92829 unsigned long flags;
92830
92831 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
92832 goto out;
92833 }
92834
92835 + if (gr_handle_ptrace(child, request)) {
92836 + ret = -EPERM;
92837 + goto out_put_task_struct;
92838 + }
92839 +
92840 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
92841 ret = ptrace_attach(child, request, addr, data);
92842 /*
92843 * Some architectures need to do book-keeping after
92844 * a ptrace attach.
92845 */
92846 - if (!ret)
92847 + if (!ret) {
92848 arch_ptrace_attach(child);
92849 + gr_audit_ptrace(child);
92850 + }
92851 goto out_put_task_struct;
92852 }
92853
92854 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
92855 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
92856 if (copied != sizeof(tmp))
92857 return -EIO;
92858 - return put_user(tmp, (unsigned long __user *)data);
92859 + return put_user(tmp, (__force unsigned long __user *)data);
92860 }
92861
92862 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
92863 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
92864 }
92865
92866 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
92867 - compat_long_t, addr, compat_long_t, data)
92868 + compat_ulong_t, addr, compat_ulong_t, data)
92869 {
92870 struct task_struct *child;
92871 long ret;
92872 @@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
92873 goto out;
92874 }
92875
92876 + if (gr_handle_ptrace(child, request)) {
92877 + ret = -EPERM;
92878 + goto out_put_task_struct;
92879 + }
92880 +
92881 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
92882 ret = ptrace_attach(child, request, addr, data);
92883 /*
92884 * Some architectures need to do book-keeping after
92885 * a ptrace attach.
92886 */
92887 - if (!ret)
92888 + if (!ret) {
92889 arch_ptrace_attach(child);
92890 + gr_audit_ptrace(child);
92891 + }
92892 goto out_put_task_struct;
92893 }
92894
92895 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
92896 index 948a769..5ca842b 100644
92897 --- a/kernel/rcu/rcutorture.c
92898 +++ b/kernel/rcu/rcutorture.c
92899 @@ -124,12 +124,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
92900 rcu_torture_count) = { 0 };
92901 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
92902 rcu_torture_batch) = { 0 };
92903 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
92904 -static atomic_t n_rcu_torture_alloc;
92905 -static atomic_t n_rcu_torture_alloc_fail;
92906 -static atomic_t n_rcu_torture_free;
92907 -static atomic_t n_rcu_torture_mberror;
92908 -static atomic_t n_rcu_torture_error;
92909 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
92910 +static atomic_unchecked_t n_rcu_torture_alloc;
92911 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
92912 +static atomic_unchecked_t n_rcu_torture_free;
92913 +static atomic_unchecked_t n_rcu_torture_mberror;
92914 +static atomic_unchecked_t n_rcu_torture_error;
92915 static long n_rcu_torture_barrier_error;
92916 static long n_rcu_torture_boost_ktrerror;
92917 static long n_rcu_torture_boost_rterror;
92918 @@ -200,11 +200,11 @@ rcu_torture_alloc(void)
92919
92920 spin_lock_bh(&rcu_torture_lock);
92921 if (list_empty(&rcu_torture_freelist)) {
92922 - atomic_inc(&n_rcu_torture_alloc_fail);
92923 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
92924 spin_unlock_bh(&rcu_torture_lock);
92925 return NULL;
92926 }
92927 - atomic_inc(&n_rcu_torture_alloc);
92928 + atomic_inc_unchecked(&n_rcu_torture_alloc);
92929 p = rcu_torture_freelist.next;
92930 list_del_init(p);
92931 spin_unlock_bh(&rcu_torture_lock);
92932 @@ -217,7 +217,7 @@ rcu_torture_alloc(void)
92933 static void
92934 rcu_torture_free(struct rcu_torture *p)
92935 {
92936 - atomic_inc(&n_rcu_torture_free);
92937 + atomic_inc_unchecked(&n_rcu_torture_free);
92938 spin_lock_bh(&rcu_torture_lock);
92939 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
92940 spin_unlock_bh(&rcu_torture_lock);
92941 @@ -301,7 +301,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
92942 i = rp->rtort_pipe_count;
92943 if (i > RCU_TORTURE_PIPE_LEN)
92944 i = RCU_TORTURE_PIPE_LEN;
92945 - atomic_inc(&rcu_torture_wcount[i]);
92946 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
92947 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
92948 rp->rtort_mbtest = 0;
92949 return true;
92950 @@ -808,7 +808,7 @@ rcu_torture_writer(void *arg)
92951 i = old_rp->rtort_pipe_count;
92952 if (i > RCU_TORTURE_PIPE_LEN)
92953 i = RCU_TORTURE_PIPE_LEN;
92954 - atomic_inc(&rcu_torture_wcount[i]);
92955 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
92956 old_rp->rtort_pipe_count++;
92957 switch (synctype[torture_random(&rand) % nsynctypes]) {
92958 case RTWS_DEF_FREE:
92959 @@ -926,7 +926,7 @@ static void rcu_torture_timer(unsigned long unused)
92960 return;
92961 }
92962 if (p->rtort_mbtest == 0)
92963 - atomic_inc(&n_rcu_torture_mberror);
92964 + atomic_inc_unchecked(&n_rcu_torture_mberror);
92965 spin_lock(&rand_lock);
92966 cur_ops->read_delay(&rand);
92967 n_rcu_torture_timers++;
92968 @@ -996,7 +996,7 @@ rcu_torture_reader(void *arg)
92969 continue;
92970 }
92971 if (p->rtort_mbtest == 0)
92972 - atomic_inc(&n_rcu_torture_mberror);
92973 + atomic_inc_unchecked(&n_rcu_torture_mberror);
92974 cur_ops->read_delay(&rand);
92975 preempt_disable();
92976 pipe_count = p->rtort_pipe_count;
92977 @@ -1054,15 +1054,15 @@ rcu_torture_printk(char *page)
92978 }
92979 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
92980 page += sprintf(page,
92981 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
92982 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
92983 rcu_torture_current,
92984 rcu_torture_current_version,
92985 list_empty(&rcu_torture_freelist),
92986 - atomic_read(&n_rcu_torture_alloc),
92987 - atomic_read(&n_rcu_torture_alloc_fail),
92988 - atomic_read(&n_rcu_torture_free));
92989 + atomic_read_unchecked(&n_rcu_torture_alloc),
92990 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
92991 + atomic_read_unchecked(&n_rcu_torture_free));
92992 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
92993 - atomic_read(&n_rcu_torture_mberror),
92994 + atomic_read_unchecked(&n_rcu_torture_mberror),
92995 n_rcu_torture_boost_ktrerror,
92996 n_rcu_torture_boost_rterror);
92997 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
92998 @@ -1075,14 +1075,14 @@ rcu_torture_printk(char *page)
92999 n_barrier_attempts,
93000 n_rcu_torture_barrier_error);
93001 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
93002 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
93003 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
93004 n_rcu_torture_barrier_error != 0 ||
93005 n_rcu_torture_boost_ktrerror != 0 ||
93006 n_rcu_torture_boost_rterror != 0 ||
93007 n_rcu_torture_boost_failure != 0 ||
93008 i > 1) {
93009 page += sprintf(page, "!!! ");
93010 - atomic_inc(&n_rcu_torture_error);
93011 + atomic_inc_unchecked(&n_rcu_torture_error);
93012 WARN_ON_ONCE(1);
93013 }
93014 page += sprintf(page, "Reader Pipe: ");
93015 @@ -1096,7 +1096,7 @@ rcu_torture_printk(char *page)
93016 page += sprintf(page, "Free-Block Circulation: ");
93017 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
93018 page += sprintf(page, " %d",
93019 - atomic_read(&rcu_torture_wcount[i]));
93020 + atomic_read_unchecked(&rcu_torture_wcount[i]));
93021 }
93022 page += sprintf(page, "\n");
93023 if (cur_ops->stats)
93024 @@ -1461,7 +1461,7 @@ rcu_torture_cleanup(void)
93025
93026 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
93027
93028 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
93029 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
93030 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
93031 else if (torture_onoff_failures())
93032 rcu_torture_print_module_parms(cur_ops,
93033 @@ -1584,18 +1584,18 @@ rcu_torture_init(void)
93034
93035 rcu_torture_current = NULL;
93036 rcu_torture_current_version = 0;
93037 - atomic_set(&n_rcu_torture_alloc, 0);
93038 - atomic_set(&n_rcu_torture_alloc_fail, 0);
93039 - atomic_set(&n_rcu_torture_free, 0);
93040 - atomic_set(&n_rcu_torture_mberror, 0);
93041 - atomic_set(&n_rcu_torture_error, 0);
93042 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
93043 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
93044 + atomic_set_unchecked(&n_rcu_torture_free, 0);
93045 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
93046 + atomic_set_unchecked(&n_rcu_torture_error, 0);
93047 n_rcu_torture_barrier_error = 0;
93048 n_rcu_torture_boost_ktrerror = 0;
93049 n_rcu_torture_boost_rterror = 0;
93050 n_rcu_torture_boost_failure = 0;
93051 n_rcu_torture_boosts = 0;
93052 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
93053 - atomic_set(&rcu_torture_wcount[i], 0);
93054 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
93055 for_each_possible_cpu(cpu) {
93056 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
93057 per_cpu(rcu_torture_count, cpu)[i] = 0;
93058 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
93059 index c639556..cf0a0d5 100644
93060 --- a/kernel/rcu/srcu.c
93061 +++ b/kernel/rcu/srcu.c
93062 @@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
93063
93064 idx = ACCESS_ONCE(sp->completed) & 0x1;
93065 preempt_disable();
93066 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
93067 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
93068 smp_mb(); /* B */ /* Avoid leaking the critical section. */
93069 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
93070 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
93071 preempt_enable();
93072 return idx;
93073 }
93074 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
93075 index d9efcc1..ea543e9 100644
93076 --- a/kernel/rcu/tiny.c
93077 +++ b/kernel/rcu/tiny.c
93078 @@ -42,7 +42,7 @@
93079 /* Forward declarations for tiny_plugin.h. */
93080 struct rcu_ctrlblk;
93081 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
93082 -static void rcu_process_callbacks(struct softirq_action *unused);
93083 +static void rcu_process_callbacks(void);
93084 static void __call_rcu(struct rcu_head *head,
93085 void (*func)(struct rcu_head *rcu),
93086 struct rcu_ctrlblk *rcp);
93087 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
93088 false));
93089 }
93090
93091 -static void rcu_process_callbacks(struct softirq_action *unused)
93092 +static __latent_entropy void rcu_process_callbacks(void)
93093 {
93094 __rcu_process_callbacks(&rcu_sched_ctrlblk);
93095 __rcu_process_callbacks(&rcu_bh_ctrlblk);
93096 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
93097 index 858c565..7efd915 100644
93098 --- a/kernel/rcu/tiny_plugin.h
93099 +++ b/kernel/rcu/tiny_plugin.h
93100 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
93101 dump_stack();
93102 }
93103 if (*rcp->curtail && ULONG_CMP_GE(j, js))
93104 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
93105 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
93106 3 * rcu_jiffies_till_stall_check() + 3;
93107 else if (ULONG_CMP_GE(j, js))
93108 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
93109 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
93110 }
93111
93112 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
93113 {
93114 rcp->ticks_this_gp = 0;
93115 rcp->gp_start = jiffies;
93116 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
93117 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
93118 }
93119
93120 static void check_cpu_stalls(void)
93121 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
93122 index 625d0b0..0bce4d6 100644
93123 --- a/kernel/rcu/tree.c
93124 +++ b/kernel/rcu/tree.c
93125 @@ -263,7 +263,7 @@ static void rcu_momentary_dyntick_idle(void)
93126 */
93127 rdtp = this_cpu_ptr(&rcu_dynticks);
93128 smp_mb__before_atomic(); /* Earlier stuff before QS. */
93129 - atomic_add(2, &rdtp->dynticks); /* QS. */
93130 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
93131 smp_mb__after_atomic(); /* Later stuff after QS. */
93132 break;
93133 }
93134 @@ -523,9 +523,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
93135 rcu_prepare_for_idle(smp_processor_id());
93136 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
93137 smp_mb__before_atomic(); /* See above. */
93138 - atomic_inc(&rdtp->dynticks);
93139 + atomic_inc_unchecked(&rdtp->dynticks);
93140 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
93141 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
93142 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
93143
93144 /*
93145 * It is illegal to enter an extended quiescent state while
93146 @@ -643,10 +643,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
93147 int user)
93148 {
93149 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
93150 - atomic_inc(&rdtp->dynticks);
93151 + atomic_inc_unchecked(&rdtp->dynticks);
93152 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
93153 smp_mb__after_atomic(); /* See above. */
93154 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
93155 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
93156 rcu_cleanup_after_idle(smp_processor_id());
93157 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
93158 if (!user && !is_idle_task(current)) {
93159 @@ -767,14 +767,14 @@ void rcu_nmi_enter(void)
93160 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
93161
93162 if (rdtp->dynticks_nmi_nesting == 0 &&
93163 - (atomic_read(&rdtp->dynticks) & 0x1))
93164 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
93165 return;
93166 rdtp->dynticks_nmi_nesting++;
93167 smp_mb__before_atomic(); /* Force delay from prior write. */
93168 - atomic_inc(&rdtp->dynticks);
93169 + atomic_inc_unchecked(&rdtp->dynticks);
93170 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
93171 smp_mb__after_atomic(); /* See above. */
93172 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
93173 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
93174 }
93175
93176 /**
93177 @@ -793,9 +793,9 @@ void rcu_nmi_exit(void)
93178 return;
93179 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
93180 smp_mb__before_atomic(); /* See above. */
93181 - atomic_inc(&rdtp->dynticks);
93182 + atomic_inc_unchecked(&rdtp->dynticks);
93183 smp_mb__after_atomic(); /* Force delay to next write. */
93184 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
93185 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
93186 }
93187
93188 /**
93189 @@ -808,7 +808,7 @@ void rcu_nmi_exit(void)
93190 */
93191 bool notrace __rcu_is_watching(void)
93192 {
93193 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
93194 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
93195 }
93196
93197 /**
93198 @@ -891,7 +891,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
93199 static int dyntick_save_progress_counter(struct rcu_data *rdp,
93200 bool *isidle, unsigned long *maxj)
93201 {
93202 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
93203 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
93204 rcu_sysidle_check_cpu(rdp, isidle, maxj);
93205 if ((rdp->dynticks_snap & 0x1) == 0) {
93206 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
93207 @@ -920,7 +920,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
93208 int *rcrmp;
93209 unsigned int snap;
93210
93211 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
93212 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
93213 snap = (unsigned int)rdp->dynticks_snap;
93214
93215 /*
93216 @@ -983,10 +983,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
93217 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
93218 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
93219 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
93220 - ACCESS_ONCE(rdp->cond_resched_completed) =
93221 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
93222 ACCESS_ONCE(rdp->mynode->completed);
93223 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
93224 - ACCESS_ONCE(*rcrmp) =
93225 + ACCESS_ONCE_RW(*rcrmp) =
93226 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
93227 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
93228 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
93229 @@ -1008,7 +1008,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
93230 rsp->gp_start = j;
93231 smp_wmb(); /* Record start time before stall time. */
93232 j1 = rcu_jiffies_till_stall_check();
93233 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
93234 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
93235 rsp->jiffies_resched = j + j1 / 2;
93236 }
93237
93238 @@ -1052,7 +1052,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
93239 raw_spin_unlock_irqrestore(&rnp->lock, flags);
93240 return;
93241 }
93242 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
93243 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
93244 raw_spin_unlock_irqrestore(&rnp->lock, flags);
93245
93246 /*
93247 @@ -1130,7 +1130,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
93248
93249 raw_spin_lock_irqsave(&rnp->lock, flags);
93250 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
93251 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
93252 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
93253 3 * rcu_jiffies_till_stall_check() + 3;
93254 raw_spin_unlock_irqrestore(&rnp->lock, flags);
93255
93256 @@ -1214,7 +1214,7 @@ void rcu_cpu_stall_reset(void)
93257 struct rcu_state *rsp;
93258
93259 for_each_rcu_flavor(rsp)
93260 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
93261 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
93262 }
93263
93264 /*
93265 @@ -1594,7 +1594,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
93266 raw_spin_unlock_irq(&rnp->lock);
93267 return 0;
93268 }
93269 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
93270 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
93271
93272 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
93273 /*
93274 @@ -1635,9 +1635,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
93275 rdp = this_cpu_ptr(rsp->rda);
93276 rcu_preempt_check_blocked_tasks(rnp);
93277 rnp->qsmask = rnp->qsmaskinit;
93278 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
93279 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
93280 WARN_ON_ONCE(rnp->completed != rsp->completed);
93281 - ACCESS_ONCE(rnp->completed) = rsp->completed;
93282 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
93283 if (rnp == rdp->mynode)
93284 (void)__note_gp_changes(rsp, rnp, rdp);
93285 rcu_preempt_boost_start_gp(rnp);
93286 @@ -1687,7 +1687,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
93287 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
93288 raw_spin_lock_irq(&rnp->lock);
93289 smp_mb__after_unlock_lock();
93290 - ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
93291 + ACCESS_ONCE_RW(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
93292 raw_spin_unlock_irq(&rnp->lock);
93293 }
93294 return fqs_state;
93295 @@ -1732,7 +1732,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
93296 rcu_for_each_node_breadth_first(rsp, rnp) {
93297 raw_spin_lock_irq(&rnp->lock);
93298 smp_mb__after_unlock_lock();
93299 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
93300 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
93301 rdp = this_cpu_ptr(rsp->rda);
93302 if (rnp == rdp->mynode)
93303 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
93304 @@ -1747,14 +1747,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
93305 rcu_nocb_gp_set(rnp, nocb);
93306
93307 /* Declare grace period done. */
93308 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
93309 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
93310 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
93311 rsp->fqs_state = RCU_GP_IDLE;
93312 rdp = this_cpu_ptr(rsp->rda);
93313 /* Advance CBs to reduce false positives below. */
93314 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
93315 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
93316 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
93317 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
93318 trace_rcu_grace_period(rsp->name,
93319 ACCESS_ONCE(rsp->gpnum),
93320 TPS("newreq"));
93321 @@ -1879,7 +1879,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
93322 */
93323 return false;
93324 }
93325 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
93326 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
93327 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
93328 TPS("newreq"));
93329
93330 @@ -2100,7 +2100,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
93331 rsp->qlen += rdp->qlen;
93332 rdp->n_cbs_orphaned += rdp->qlen;
93333 rdp->qlen_lazy = 0;
93334 - ACCESS_ONCE(rdp->qlen) = 0;
93335 + ACCESS_ONCE_RW(rdp->qlen) = 0;
93336 }
93337
93338 /*
93339 @@ -2347,7 +2347,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
93340 }
93341 smp_mb(); /* List handling before counting for rcu_barrier(). */
93342 rdp->qlen_lazy -= count_lazy;
93343 - ACCESS_ONCE(rdp->qlen) -= count;
93344 + ACCESS_ONCE_RW(rdp->qlen) -= count;
93345 rdp->n_cbs_invoked += count;
93346
93347 /* Reinstate batch limit if we have worked down the excess. */
93348 @@ -2492,7 +2492,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
93349 if (rnp_old != NULL)
93350 raw_spin_unlock(&rnp_old->fqslock);
93351 if (ret) {
93352 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
93353 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
93354 return;
93355 }
93356 rnp_old = rnp;
93357 @@ -2504,11 +2504,11 @@ static void force_quiescent_state(struct rcu_state *rsp)
93358 smp_mb__after_unlock_lock();
93359 raw_spin_unlock(&rnp_old->fqslock);
93360 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
93361 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
93362 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
93363 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
93364 return; /* Someone beat us to it. */
93365 }
93366 - ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
93367 + ACCESS_ONCE_RW(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
93368 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
93369 wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */
93370 }
93371 @@ -2553,7 +2553,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
93372 /*
93373 * Do RCU core processing for the current CPU.
93374 */
93375 -static void rcu_process_callbacks(struct softirq_action *unused)
93376 +static void rcu_process_callbacks(void)
93377 {
93378 struct rcu_state *rsp;
93379
93380 @@ -2665,7 +2665,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
93381 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
93382 if (debug_rcu_head_queue(head)) {
93383 /* Probable double call_rcu(), so leak the callback. */
93384 - ACCESS_ONCE(head->func) = rcu_leak_callback;
93385 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
93386 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
93387 return;
93388 }
93389 @@ -2693,7 +2693,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
93390 local_irq_restore(flags);
93391 return;
93392 }
93393 - ACCESS_ONCE(rdp->qlen)++;
93394 + ACCESS_ONCE_RW(rdp->qlen)++;
93395 if (lazy)
93396 rdp->qlen_lazy++;
93397 else
93398 @@ -2968,11 +2968,11 @@ void synchronize_sched_expedited(void)
93399 * counter wrap on a 32-bit system. Quite a few more CPUs would of
93400 * course be required on a 64-bit system.
93401 */
93402 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
93403 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
93404 (ulong)atomic_long_read(&rsp->expedited_done) +
93405 ULONG_MAX / 8)) {
93406 synchronize_sched();
93407 - atomic_long_inc(&rsp->expedited_wrap);
93408 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
93409 return;
93410 }
93411
93412 @@ -2980,7 +2980,7 @@ void synchronize_sched_expedited(void)
93413 * Take a ticket. Note that atomic_inc_return() implies a
93414 * full memory barrier.
93415 */
93416 - snap = atomic_long_inc_return(&rsp->expedited_start);
93417 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
93418 firstsnap = snap;
93419 get_online_cpus();
93420 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
93421 @@ -2993,14 +2993,14 @@ void synchronize_sched_expedited(void)
93422 synchronize_sched_expedited_cpu_stop,
93423 NULL) == -EAGAIN) {
93424 put_online_cpus();
93425 - atomic_long_inc(&rsp->expedited_tryfail);
93426 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
93427
93428 /* Check to see if someone else did our work for us. */
93429 s = atomic_long_read(&rsp->expedited_done);
93430 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
93431 /* ensure test happens before caller kfree */
93432 smp_mb__before_atomic(); /* ^^^ */
93433 - atomic_long_inc(&rsp->expedited_workdone1);
93434 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
93435 return;
93436 }
93437
93438 @@ -3009,7 +3009,7 @@ void synchronize_sched_expedited(void)
93439 udelay(trycount * num_online_cpus());
93440 } else {
93441 wait_rcu_gp(call_rcu_sched);
93442 - atomic_long_inc(&rsp->expedited_normal);
93443 + atomic_long_inc_unchecked(&rsp->expedited_normal);
93444 return;
93445 }
93446
93447 @@ -3018,7 +3018,7 @@ void synchronize_sched_expedited(void)
93448 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
93449 /* ensure test happens before caller kfree */
93450 smp_mb__before_atomic(); /* ^^^ */
93451 - atomic_long_inc(&rsp->expedited_workdone2);
93452 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
93453 return;
93454 }
93455
93456 @@ -3030,10 +3030,10 @@ void synchronize_sched_expedited(void)
93457 * period works for us.
93458 */
93459 get_online_cpus();
93460 - snap = atomic_long_read(&rsp->expedited_start);
93461 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
93462 smp_mb(); /* ensure read is before try_stop_cpus(). */
93463 }
93464 - atomic_long_inc(&rsp->expedited_stoppedcpus);
93465 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
93466
93467 /*
93468 * Everyone up to our most recent fetch is covered by our grace
93469 @@ -3042,16 +3042,16 @@ void synchronize_sched_expedited(void)
93470 * than we did already did their update.
93471 */
93472 do {
93473 - atomic_long_inc(&rsp->expedited_done_tries);
93474 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
93475 s = atomic_long_read(&rsp->expedited_done);
93476 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
93477 /* ensure test happens before caller kfree */
93478 smp_mb__before_atomic(); /* ^^^ */
93479 - atomic_long_inc(&rsp->expedited_done_lost);
93480 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
93481 break;
93482 }
93483 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
93484 - atomic_long_inc(&rsp->expedited_done_exit);
93485 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
93486
93487 put_online_cpus();
93488 }
93489 @@ -3257,7 +3257,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
93490 * ACCESS_ONCE() to prevent the compiler from speculating
93491 * the increment to precede the early-exit check.
93492 */
93493 - ACCESS_ONCE(rsp->n_barrier_done)++;
93494 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
93495 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
93496 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
93497 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
93498 @@ -3307,7 +3307,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
93499
93500 /* Increment ->n_barrier_done to prevent duplicate work. */
93501 smp_mb(); /* Keep increment after above mechanism. */
93502 - ACCESS_ONCE(rsp->n_barrier_done)++;
93503 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
93504 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
93505 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
93506 smp_mb(); /* Keep increment before caller's subsequent code. */
93507 @@ -3352,10 +3352,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
93508 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
93509 init_callback_list(rdp);
93510 rdp->qlen_lazy = 0;
93511 - ACCESS_ONCE(rdp->qlen) = 0;
93512 + ACCESS_ONCE_RW(rdp->qlen) = 0;
93513 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
93514 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
93515 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
93516 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
93517 rdp->cpu = cpu;
93518 rdp->rsp = rsp;
93519 rcu_boot_init_nocb_percpu_data(rdp);
93520 @@ -3388,8 +3388,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
93521 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
93522 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
93523 rcu_sysidle_init_percpu_data(rdp->dynticks);
93524 - atomic_set(&rdp->dynticks->dynticks,
93525 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
93526 + atomic_set_unchecked(&rdp->dynticks->dynticks,
93527 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
93528 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
93529
93530 /* Add CPU to rcu_node bitmasks. */
93531 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
93532 index 0f69a79..c85c2dc 100644
93533 --- a/kernel/rcu/tree.h
93534 +++ b/kernel/rcu/tree.h
93535 @@ -87,11 +87,11 @@ struct rcu_dynticks {
93536 long long dynticks_nesting; /* Track irq/process nesting level. */
93537 /* Process level is worth LLONG_MAX/2. */
93538 int dynticks_nmi_nesting; /* Track NMI nesting level. */
93539 - atomic_t dynticks; /* Even value for idle, else odd. */
93540 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
93541 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
93542 long long dynticks_idle_nesting;
93543 /* irq/process nesting level from idle. */
93544 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
93545 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
93546 /* "Idle" excludes userspace execution. */
93547 unsigned long dynticks_idle_jiffies;
93548 /* End of last non-NMI non-idle period. */
93549 @@ -435,17 +435,17 @@ struct rcu_state {
93550 /* _rcu_barrier(). */
93551 /* End of fields guarded by barrier_mutex. */
93552
93553 - atomic_long_t expedited_start; /* Starting ticket. */
93554 - atomic_long_t expedited_done; /* Done ticket. */
93555 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
93556 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
93557 - atomic_long_t expedited_workdone1; /* # done by others #1. */
93558 - atomic_long_t expedited_workdone2; /* # done by others #2. */
93559 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
93560 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
93561 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
93562 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
93563 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
93564 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
93565 + atomic_long_t expedited_done; /* Done ticket. */
93566 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
93567 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
93568 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
93569 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
93570 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
93571 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
93572 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
93573 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
93574 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
93575
93576 unsigned long jiffies_force_qs; /* Time at which to invoke */
93577 /* force_quiescent_state(). */
93578 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
93579 index 02ac0fb..4aa4a36 100644
93580 --- a/kernel/rcu/tree_plugin.h
93581 +++ b/kernel/rcu/tree_plugin.h
93582 @@ -735,7 +735,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
93583 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
93584 {
93585 return !rcu_preempted_readers_exp(rnp) &&
93586 - ACCESS_ONCE(rnp->expmask) == 0;
93587 + ACCESS_ONCE_RW(rnp->expmask) == 0;
93588 }
93589
93590 /*
93591 @@ -897,7 +897,7 @@ void synchronize_rcu_expedited(void)
93592
93593 /* Clean up and exit. */
93594 smp_mb(); /* ensure expedited GP seen before counter increment. */
93595 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
93596 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
93597 unlock_mb_ret:
93598 mutex_unlock(&sync_rcu_preempt_exp_mutex);
93599 mb_ret:
93600 @@ -1447,7 +1447,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
93601 free_cpumask_var(cm);
93602 }
93603
93604 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
93605 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
93606 .store = &rcu_cpu_kthread_task,
93607 .thread_should_run = rcu_cpu_kthread_should_run,
93608 .thread_fn = rcu_cpu_kthread,
93609 @@ -1926,7 +1926,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
93610 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
93611 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
93612 cpu, ticks_value, ticks_title,
93613 - atomic_read(&rdtp->dynticks) & 0xfff,
93614 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
93615 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
93616 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
93617 fast_no_hz);
93618 @@ -2079,7 +2079,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
93619
93620 /* Enqueue the callback on the nocb list and update counts. */
93621 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
93622 - ACCESS_ONCE(*old_rhpp) = rhp;
93623 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
93624 atomic_long_add(rhcount, &rdp->nocb_q_count);
93625 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
93626
93627 @@ -2255,12 +2255,12 @@ static int rcu_nocb_kthread(void *arg)
93628 * Extract queued callbacks, update counts, and wait
93629 * for a grace period to elapse.
93630 */
93631 - ACCESS_ONCE(rdp->nocb_head) = NULL;
93632 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
93633 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
93634 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
93635 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
93636 - ACCESS_ONCE(rdp->nocb_p_count) += c;
93637 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
93638 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
93639 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
93640 rcu_nocb_wait_gp(rdp);
93641
93642 /* Each pass through the following loop invokes a callback. */
93643 @@ -2286,8 +2286,8 @@ static int rcu_nocb_kthread(void *arg)
93644 list = next;
93645 }
93646 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
93647 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
93648 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
93649 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
93650 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
93651 rdp->n_nocbs_invoked += c;
93652 }
93653 return 0;
93654 @@ -2304,7 +2304,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
93655 {
93656 if (!rcu_nocb_need_deferred_wakeup(rdp))
93657 return;
93658 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
93659 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
93660 wake_up(&rdp->nocb_wq);
93661 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
93662 }
93663 @@ -2330,7 +2330,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
93664 t = kthread_run(rcu_nocb_kthread, rdp,
93665 "rcuo%c/%d", rsp->abbr, cpu);
93666 BUG_ON(IS_ERR(t));
93667 - ACCESS_ONCE(rdp->nocb_kthread) = t;
93668 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
93669 }
93670 }
93671
93672 @@ -2461,11 +2461,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
93673
93674 /* Record start of fully idle period. */
93675 j = jiffies;
93676 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
93677 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
93678 smp_mb__before_atomic();
93679 - atomic_inc(&rdtp->dynticks_idle);
93680 + atomic_inc_unchecked(&rdtp->dynticks_idle);
93681 smp_mb__after_atomic();
93682 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
93683 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
93684 }
93685
93686 /*
93687 @@ -2530,9 +2530,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
93688
93689 /* Record end of idle period. */
93690 smp_mb__before_atomic();
93691 - atomic_inc(&rdtp->dynticks_idle);
93692 + atomic_inc_unchecked(&rdtp->dynticks_idle);
93693 smp_mb__after_atomic();
93694 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
93695 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
93696
93697 /*
93698 * If we are the timekeeping CPU, we are permitted to be non-idle
93699 @@ -2573,7 +2573,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
93700 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
93701
93702 /* Pick up current idle and NMI-nesting counter and check. */
93703 - cur = atomic_read(&rdtp->dynticks_idle);
93704 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
93705 if (cur & 0x1) {
93706 *isidle = false; /* We are not idle! */
93707 return;
93708 @@ -2622,7 +2622,7 @@ static void rcu_sysidle(unsigned long j)
93709 case RCU_SYSIDLE_NOT:
93710
93711 /* First time all are idle, so note a short idle period. */
93712 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
93713 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
93714 break;
93715
93716 case RCU_SYSIDLE_SHORT:
93717 @@ -2660,7 +2660,7 @@ static void rcu_sysidle_cancel(void)
93718 {
93719 smp_mb();
93720 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
93721 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
93722 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
93723 }
93724
93725 /*
93726 @@ -2708,7 +2708,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
93727 smp_mb(); /* grace period precedes setting inuse. */
93728
93729 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
93730 - ACCESS_ONCE(rshp->inuse) = 0;
93731 + ACCESS_ONCE_RW(rshp->inuse) = 0;
93732 }
93733
93734 /*
93735 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
93736 index 5cdc62e..cc52e88 100644
93737 --- a/kernel/rcu/tree_trace.c
93738 +++ b/kernel/rcu/tree_trace.c
93739 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
93740 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
93741 rdp->passed_quiesce, rdp->qs_pending);
93742 seq_printf(m, " dt=%d/%llx/%d df=%lu",
93743 - atomic_read(&rdp->dynticks->dynticks),
93744 + atomic_read_unchecked(&rdp->dynticks->dynticks),
93745 rdp->dynticks->dynticks_nesting,
93746 rdp->dynticks->dynticks_nmi_nesting,
93747 rdp->dynticks_fqs);
93748 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
93749 struct rcu_state *rsp = (struct rcu_state *)m->private;
93750
93751 seq_printf(m, "s=%lu d=%lu w=%lu tf=%lu wd1=%lu wd2=%lu n=%lu sc=%lu dt=%lu dl=%lu dx=%lu\n",
93752 - atomic_long_read(&rsp->expedited_start),
93753 + atomic_long_read_unchecked(&rsp->expedited_start),
93754 atomic_long_read(&rsp->expedited_done),
93755 - atomic_long_read(&rsp->expedited_wrap),
93756 - atomic_long_read(&rsp->expedited_tryfail),
93757 - atomic_long_read(&rsp->expedited_workdone1),
93758 - atomic_long_read(&rsp->expedited_workdone2),
93759 - atomic_long_read(&rsp->expedited_normal),
93760 - atomic_long_read(&rsp->expedited_stoppedcpus),
93761 - atomic_long_read(&rsp->expedited_done_tries),
93762 - atomic_long_read(&rsp->expedited_done_lost),
93763 - atomic_long_read(&rsp->expedited_done_exit));
93764 + atomic_long_read_unchecked(&rsp->expedited_wrap),
93765 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
93766 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
93767 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
93768 + atomic_long_read_unchecked(&rsp->expedited_normal),
93769 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
93770 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
93771 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
93772 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
93773 return 0;
93774 }
93775
93776 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
93777 index bc78835..7691a45 100644
93778 --- a/kernel/rcu/update.c
93779 +++ b/kernel/rcu/update.c
93780 @@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
93781 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
93782 */
93783 if (till_stall_check < 3) {
93784 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
93785 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
93786 till_stall_check = 3;
93787 } else if (till_stall_check > 300) {
93788 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
93789 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
93790 till_stall_check = 300;
93791 }
93792 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
93793 diff --git a/kernel/resource.c b/kernel/resource.c
93794 index 3c2237a..4568d96 100644
93795 --- a/kernel/resource.c
93796 +++ b/kernel/resource.c
93797 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
93798
93799 static int __init ioresources_init(void)
93800 {
93801 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93802 +#ifdef CONFIG_GRKERNSEC_PROC_USER
93803 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
93804 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
93805 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
93806 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
93807 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
93808 +#endif
93809 +#else
93810 proc_create("ioports", 0, NULL, &proc_ioports_operations);
93811 proc_create("iomem", 0, NULL, &proc_iomem_operations);
93812 +#endif
93813 return 0;
93814 }
93815 __initcall(ioresources_init);
93816 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
93817 index e73efba..c9bfbd4 100644
93818 --- a/kernel/sched/auto_group.c
93819 +++ b/kernel/sched/auto_group.c
93820 @@ -11,7 +11,7 @@
93821
93822 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
93823 static struct autogroup autogroup_default;
93824 -static atomic_t autogroup_seq_nr;
93825 +static atomic_unchecked_t autogroup_seq_nr;
93826
93827 void __init autogroup_init(struct task_struct *init_task)
93828 {
93829 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
93830
93831 kref_init(&ag->kref);
93832 init_rwsem(&ag->lock);
93833 - ag->id = atomic_inc_return(&autogroup_seq_nr);
93834 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
93835 ag->tg = tg;
93836 #ifdef CONFIG_RT_GROUP_SCHED
93837 /*
93838 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
93839 index a63f4dc..349bbb0 100644
93840 --- a/kernel/sched/completion.c
93841 +++ b/kernel/sched/completion.c
93842 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
93843 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
93844 * or number of jiffies left till timeout) if completed.
93845 */
93846 -long __sched
93847 +long __sched __intentional_overflow(-1)
93848 wait_for_completion_interruptible_timeout(struct completion *x,
93849 unsigned long timeout)
93850 {
93851 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
93852 *
93853 * Return: -ERESTARTSYS if interrupted, 0 if completed.
93854 */
93855 -int __sched wait_for_completion_killable(struct completion *x)
93856 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
93857 {
93858 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
93859 if (t == -ERESTARTSYS)
93860 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
93861 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
93862 * or number of jiffies left till timeout) if completed.
93863 */
93864 -long __sched
93865 +long __sched __intentional_overflow(-1)
93866 wait_for_completion_killable_timeout(struct completion *x,
93867 unsigned long timeout)
93868 {
93869 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
93870 index 0acf96b..80ba955 100644
93871 --- a/kernel/sched/core.c
93872 +++ b/kernel/sched/core.c
93873 @@ -1849,7 +1849,7 @@ void set_numabalancing_state(bool enabled)
93874 int sysctl_numa_balancing(struct ctl_table *table, int write,
93875 void __user *buffer, size_t *lenp, loff_t *ppos)
93876 {
93877 - struct ctl_table t;
93878 + ctl_table_no_const t;
93879 int err;
93880 int state = numabalancing_enabled;
93881
93882 @@ -2312,8 +2312,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
93883 next->active_mm = oldmm;
93884 atomic_inc(&oldmm->mm_count);
93885 enter_lazy_tlb(oldmm, next);
93886 - } else
93887 + } else {
93888 switch_mm(oldmm, mm, next);
93889 + populate_stack();
93890 + }
93891
93892 if (!prev->mm) {
93893 prev->active_mm = NULL;
93894 @@ -3081,6 +3083,8 @@ int can_nice(const struct task_struct *p, const int nice)
93895 /* convert nice value [19,-20] to rlimit style value [1,40] */
93896 int nice_rlim = nice_to_rlimit(nice);
93897
93898 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
93899 +
93900 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
93901 capable(CAP_SYS_NICE));
93902 }
93903 @@ -3107,7 +3111,8 @@ SYSCALL_DEFINE1(nice, int, increment)
93904 nice = task_nice(current) + increment;
93905
93906 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
93907 - if (increment < 0 && !can_nice(current, nice))
93908 + if (increment < 0 && (!can_nice(current, nice) ||
93909 + gr_handle_chroot_nice()))
93910 return -EPERM;
93911
93912 retval = security_task_setnice(current, nice);
93913 @@ -3380,6 +3385,7 @@ recheck:
93914 if (policy != p->policy && !rlim_rtprio)
93915 return -EPERM;
93916
93917 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
93918 /* can't increase priority */
93919 if (attr->sched_priority > p->rt_priority &&
93920 attr->sched_priority > rlim_rtprio)
93921 @@ -4772,6 +4778,7 @@ void idle_task_exit(void)
93922
93923 if (mm != &init_mm) {
93924 switch_mm(mm, &init_mm, current);
93925 + populate_stack();
93926 finish_arch_post_lock_switch();
93927 }
93928 mmdrop(mm);
93929 @@ -4867,7 +4874,7 @@ static void migrate_tasks(unsigned int dead_cpu)
93930
93931 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
93932
93933 -static struct ctl_table sd_ctl_dir[] = {
93934 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
93935 {
93936 .procname = "sched_domain",
93937 .mode = 0555,
93938 @@ -4884,17 +4891,17 @@ static struct ctl_table sd_ctl_root[] = {
93939 {}
93940 };
93941
93942 -static struct ctl_table *sd_alloc_ctl_entry(int n)
93943 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
93944 {
93945 - struct ctl_table *entry =
93946 + ctl_table_no_const *entry =
93947 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
93948
93949 return entry;
93950 }
93951
93952 -static void sd_free_ctl_entry(struct ctl_table **tablep)
93953 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
93954 {
93955 - struct ctl_table *entry;
93956 + ctl_table_no_const *entry;
93957
93958 /*
93959 * In the intermediate directories, both the child directory and
93960 @@ -4902,22 +4909,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
93961 * will always be set. In the lowest directory the names are
93962 * static strings and all have proc handlers.
93963 */
93964 - for (entry = *tablep; entry->mode; entry++) {
93965 - if (entry->child)
93966 - sd_free_ctl_entry(&entry->child);
93967 + for (entry = tablep; entry->mode; entry++) {
93968 + if (entry->child) {
93969 + sd_free_ctl_entry(entry->child);
93970 + pax_open_kernel();
93971 + entry->child = NULL;
93972 + pax_close_kernel();
93973 + }
93974 if (entry->proc_handler == NULL)
93975 kfree(entry->procname);
93976 }
93977
93978 - kfree(*tablep);
93979 - *tablep = NULL;
93980 + kfree(tablep);
93981 }
93982
93983 static int min_load_idx = 0;
93984 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
93985
93986 static void
93987 -set_table_entry(struct ctl_table *entry,
93988 +set_table_entry(ctl_table_no_const *entry,
93989 const char *procname, void *data, int maxlen,
93990 umode_t mode, proc_handler *proc_handler,
93991 bool load_idx)
93992 @@ -4937,7 +4947,7 @@ set_table_entry(struct ctl_table *entry,
93993 static struct ctl_table *
93994 sd_alloc_ctl_domain_table(struct sched_domain *sd)
93995 {
93996 - struct ctl_table *table = sd_alloc_ctl_entry(14);
93997 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
93998
93999 if (table == NULL)
94000 return NULL;
94001 @@ -4975,9 +4985,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
94002 return table;
94003 }
94004
94005 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
94006 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
94007 {
94008 - struct ctl_table *entry, *table;
94009 + ctl_table_no_const *entry, *table;
94010 struct sched_domain *sd;
94011 int domain_num = 0, i;
94012 char buf[32];
94013 @@ -5004,11 +5014,13 @@ static struct ctl_table_header *sd_sysctl_header;
94014 static void register_sched_domain_sysctl(void)
94015 {
94016 int i, cpu_num = num_possible_cpus();
94017 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
94018 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
94019 char buf[32];
94020
94021 WARN_ON(sd_ctl_dir[0].child);
94022 + pax_open_kernel();
94023 sd_ctl_dir[0].child = entry;
94024 + pax_close_kernel();
94025
94026 if (entry == NULL)
94027 return;
94028 @@ -5031,8 +5043,12 @@ static void unregister_sched_domain_sysctl(void)
94029 if (sd_sysctl_header)
94030 unregister_sysctl_table(sd_sysctl_header);
94031 sd_sysctl_header = NULL;
94032 - if (sd_ctl_dir[0].child)
94033 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
94034 + if (sd_ctl_dir[0].child) {
94035 + sd_free_ctl_entry(sd_ctl_dir[0].child);
94036 + pax_open_kernel();
94037 + sd_ctl_dir[0].child = NULL;
94038 + pax_close_kernel();
94039 + }
94040 }
94041 #else
94042 static void register_sched_domain_sysctl(void)
94043 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
94044 index fea7d33..84faa94 100644
94045 --- a/kernel/sched/fair.c
94046 +++ b/kernel/sched/fair.c
94047 @@ -1857,7 +1857,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
94048
94049 static void reset_ptenuma_scan(struct task_struct *p)
94050 {
94051 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
94052 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
94053 p->mm->numa_scan_offset = 0;
94054 }
94055
94056 @@ -7289,7 +7289,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
94057 * run_rebalance_domains is triggered when needed from the scheduler tick.
94058 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
94059 */
94060 -static void run_rebalance_domains(struct softirq_action *h)
94061 +static __latent_entropy void run_rebalance_domains(void)
94062 {
94063 struct rq *this_rq = this_rq();
94064 enum cpu_idle_type idle = this_rq->idle_balance ?
94065 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
94066 index 31cc02e..734fb85 100644
94067 --- a/kernel/sched/sched.h
94068 +++ b/kernel/sched/sched.h
94069 @@ -1153,7 +1153,7 @@ struct sched_class {
94070 #ifdef CONFIG_FAIR_GROUP_SCHED
94071 void (*task_move_group) (struct task_struct *p, int on_rq);
94072 #endif
94073 -};
94074 +} __do_const;
94075
94076 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
94077 {
94078 diff --git a/kernel/seccomp.c b/kernel/seccomp.c
94079 index 301bbc2..eda2da3 100644
94080 --- a/kernel/seccomp.c
94081 +++ b/kernel/seccomp.c
94082 @@ -39,7 +39,7 @@
94083 * is only needed for handling filters shared across tasks.
94084 * @prev: points to a previously installed, or inherited, filter
94085 * @len: the number of instructions in the program
94086 - * @insnsi: the BPF program instructions to evaluate
94087 + * @insns: the BPF program instructions to evaluate
94088 *
94089 * seccomp_filter objects are organized in a tree linked via the @prev
94090 * pointer. For any task, it appears to be a singly-linked list starting
94091 @@ -54,32 +54,61 @@
94092 struct seccomp_filter {
94093 atomic_t usage;
94094 struct seccomp_filter *prev;
94095 - struct sk_filter *prog;
94096 + unsigned short len; /* Instruction count */
94097 + struct sock_filter insns[];
94098 };
94099
94100 /* Limit any path through the tree to 256KB worth of instructions. */
94101 #define MAX_INSNS_PER_PATH ((1 << 18) / sizeof(struct sock_filter))
94102
94103 -/*
94104 +/**
94105 + * get_u32 - returns a u32 offset into data
94106 + * @data: a unsigned 64 bit value
94107 + * @index: 0 or 1 to return the first or second 32-bits
94108 + *
94109 + * This inline exists to hide the length of unsigned long. If a 32-bit
94110 + * unsigned long is passed in, it will be extended and the top 32-bits will be
94111 + * 0. If it is a 64-bit unsigned long, then whatever data is resident will be
94112 + * properly returned.
94113 + *
94114 * Endianness is explicitly ignored and left for BPF program authors to manage
94115 * as per the specific architecture.
94116 */
94117 -static void populate_seccomp_data(struct seccomp_data *sd)
94118 +static inline u32 get_u32(u64 data, int index)
94119 {
94120 - struct task_struct *task = current;
94121 - struct pt_regs *regs = task_pt_regs(task);
94122 - unsigned long args[6];
94123 + return ((u32 *)&data)[index];
94124 +}
94125
94126 - sd->nr = syscall_get_nr(task, regs);
94127 - sd->arch = syscall_get_arch();
94128 - syscall_get_arguments(task, regs, 0, 6, args);
94129 - sd->args[0] = args[0];
94130 - sd->args[1] = args[1];
94131 - sd->args[2] = args[2];
94132 - sd->args[3] = args[3];
94133 - sd->args[4] = args[4];
94134 - sd->args[5] = args[5];
94135 - sd->instruction_pointer = KSTK_EIP(task);
94136 +/* Helper for bpf_load below. */
94137 +#define BPF_DATA(_name) offsetof(struct seccomp_data, _name)
94138 +/**
94139 + * bpf_load: checks and returns a pointer to the requested offset
94140 + * @off: offset into struct seccomp_data to load from
94141 + *
94142 + * Returns the requested 32-bits of data.
94143 + * seccomp_check_filter() should assure that @off is 32-bit aligned
94144 + * and not out of bounds. Failure to do so is a BUG.
94145 + */
94146 +u32 seccomp_bpf_load(int off)
94147 +{
94148 + struct pt_regs *regs = task_pt_regs(current);
94149 + if (off == BPF_DATA(nr))
94150 + return syscall_get_nr(current, regs);
94151 + if (off == BPF_DATA(arch))
94152 + return syscall_get_arch();
94153 + if (off >= BPF_DATA(args[0]) && off < BPF_DATA(args[6])) {
94154 + unsigned long value;
94155 + int arg = (off - BPF_DATA(args[0])) / sizeof(u64);
94156 + int index = !!(off % sizeof(u64));
94157 + syscall_get_arguments(current, regs, arg, 1, &value);
94158 + return get_u32(value, index);
94159 + }
94160 + if (off == BPF_DATA(instruction_pointer))
94161 + return get_u32(KSTK_EIP(current), 0);
94162 + if (off == BPF_DATA(instruction_pointer) + sizeof(u32))
94163 + return get_u32(KSTK_EIP(current), 1);
94164 + /* seccomp_check_filter should make this impossible. */
94165 + BUG();
94166 }
94167
94168 /**
94169 @@ -103,59 +132,59 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)
94170 u32 k = ftest->k;
94171
94172 switch (code) {
94173 - case BPF_LD | BPF_W | BPF_ABS:
94174 - ftest->code = BPF_LDX | BPF_W | BPF_ABS;
94175 + case BPF_S_LD_W_ABS:
94176 + ftest->code = BPF_S_ANC_SECCOMP_LD_W;
94177 /* 32-bit aligned and not out of bounds. */
94178 if (k >= sizeof(struct seccomp_data) || k & 3)
94179 return -EINVAL;
94180 continue;
94181 - case BPF_LD | BPF_W | BPF_LEN:
94182 - ftest->code = BPF_LD | BPF_IMM;
94183 + case BPF_S_LD_W_LEN:
94184 + ftest->code = BPF_S_LD_IMM;
94185 ftest->k = sizeof(struct seccomp_data);
94186 continue;
94187 - case BPF_LDX | BPF_W | BPF_LEN:
94188 - ftest->code = BPF_LDX | BPF_IMM;
94189 + case BPF_S_LDX_W_LEN:
94190 + ftest->code = BPF_S_LDX_IMM;
94191 ftest->k = sizeof(struct seccomp_data);
94192 continue;
94193 /* Explicitly include allowed calls. */
94194 - case BPF_RET | BPF_K:
94195 - case BPF_RET | BPF_A:
94196 - case BPF_ALU | BPF_ADD | BPF_K:
94197 - case BPF_ALU | BPF_ADD | BPF_X:
94198 - case BPF_ALU | BPF_SUB | BPF_K:
94199 - case BPF_ALU | BPF_SUB | BPF_X:
94200 - case BPF_ALU | BPF_MUL | BPF_K:
94201 - case BPF_ALU | BPF_MUL | BPF_X:
94202 - case BPF_ALU | BPF_DIV | BPF_K:
94203 - case BPF_ALU | BPF_DIV | BPF_X:
94204 - case BPF_ALU | BPF_AND | BPF_K:
94205 - case BPF_ALU | BPF_AND | BPF_X:
94206 - case BPF_ALU | BPF_OR | BPF_K:
94207 - case BPF_ALU | BPF_OR | BPF_X:
94208 - case BPF_ALU | BPF_XOR | BPF_K:
94209 - case BPF_ALU | BPF_XOR | BPF_X:
94210 - case BPF_ALU | BPF_LSH | BPF_K:
94211 - case BPF_ALU | BPF_LSH | BPF_X:
94212 - case BPF_ALU | BPF_RSH | BPF_K:
94213 - case BPF_ALU | BPF_RSH | BPF_X:
94214 - case BPF_ALU | BPF_NEG:
94215 - case BPF_LD | BPF_IMM:
94216 - case BPF_LDX | BPF_IMM:
94217 - case BPF_MISC | BPF_TAX:
94218 - case BPF_MISC | BPF_TXA:
94219 - case BPF_LD | BPF_MEM:
94220 - case BPF_LDX | BPF_MEM:
94221 - case BPF_ST:
94222 - case BPF_STX:
94223 - case BPF_JMP | BPF_JA:
94224 - case BPF_JMP | BPF_JEQ | BPF_K:
94225 - case BPF_JMP | BPF_JEQ | BPF_X:
94226 - case BPF_JMP | BPF_JGE | BPF_K:
94227 - case BPF_JMP | BPF_JGE | BPF_X:
94228 - case BPF_JMP | BPF_JGT | BPF_K:
94229 - case BPF_JMP | BPF_JGT | BPF_X:
94230 - case BPF_JMP | BPF_JSET | BPF_K:
94231 - case BPF_JMP | BPF_JSET | BPF_X:
94232 + case BPF_S_RET_K:
94233 + case BPF_S_RET_A:
94234 + case BPF_S_ALU_ADD_K:
94235 + case BPF_S_ALU_ADD_X:
94236 + case BPF_S_ALU_SUB_K:
94237 + case BPF_S_ALU_SUB_X:
94238 + case BPF_S_ALU_MUL_K:
94239 + case BPF_S_ALU_MUL_X:
94240 + case BPF_S_ALU_DIV_X:
94241 + case BPF_S_ALU_AND_K:
94242 + case BPF_S_ALU_AND_X:
94243 + case BPF_S_ALU_OR_K:
94244 + case BPF_S_ALU_OR_X:
94245 + case BPF_S_ALU_XOR_K:
94246 + case BPF_S_ALU_XOR_X:
94247 + case BPF_S_ALU_LSH_K:
94248 + case BPF_S_ALU_LSH_X:
94249 + case BPF_S_ALU_RSH_K:
94250 + case BPF_S_ALU_RSH_X:
94251 + case BPF_S_ALU_NEG:
94252 + case BPF_S_LD_IMM:
94253 + case BPF_S_LDX_IMM:
94254 + case BPF_S_MISC_TAX:
94255 + case BPF_S_MISC_TXA:
94256 + case BPF_S_ALU_DIV_K:
94257 + case BPF_S_LD_MEM:
94258 + case BPF_S_LDX_MEM:
94259 + case BPF_S_ST:
94260 + case BPF_S_STX:
94261 + case BPF_S_JMP_JA:
94262 + case BPF_S_JMP_JEQ_K:
94263 + case BPF_S_JMP_JEQ_X:
94264 + case BPF_S_JMP_JGE_K:
94265 + case BPF_S_JMP_JGE_X:
94266 + case BPF_S_JMP_JGT_K:
94267 + case BPF_S_JMP_JGT_X:
94268 + case BPF_S_JMP_JSET_K:
94269 + case BPF_S_JMP_JSET_X:
94270 continue;
94271 default:
94272 return -EINVAL;
94273 @@ -173,22 +202,18 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)
94274 static u32 seccomp_run_filters(int syscall)
94275 {
94276 struct seccomp_filter *f;
94277 - struct seccomp_data sd;
94278 u32 ret = SECCOMP_RET_ALLOW;
94279
94280 /* Ensure unexpected behavior doesn't result in failing open. */
94281 if (WARN_ON(current->seccomp.filter == NULL))
94282 return SECCOMP_RET_KILL;
94283
94284 - populate_seccomp_data(&sd);
94285 -
94286 /*
94287 * All filters in the list are evaluated and the lowest BPF return
94288 * value always takes priority (ignoring the DATA).
94289 */
94290 for (f = current->seccomp.filter; f; f = f->prev) {
94291 - u32 cur_ret = SK_RUN_FILTER(f->prog, (void *)&sd);
94292 -
94293 + u32 cur_ret = sk_run_filter(NULL, f->insns);
94294 if ((cur_ret & SECCOMP_RET_ACTION) < (ret & SECCOMP_RET_ACTION))
94295 ret = cur_ret;
94296 }
94297 @@ -206,20 +231,18 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
94298 struct seccomp_filter *filter;
94299 unsigned long fp_size = fprog->len * sizeof(struct sock_filter);
94300 unsigned long total_insns = fprog->len;
94301 - struct sock_filter *fp;
94302 - int new_len;
94303 long ret;
94304
94305 if (fprog->len == 0 || fprog->len > BPF_MAXINSNS)
94306 return -EINVAL;
94307
94308 for (filter = current->seccomp.filter; filter; filter = filter->prev)
94309 - total_insns += filter->prog->len + 4; /* include a 4 instr penalty */
94310 + total_insns += filter->len + 4; /* include a 4 instr penalty */
94311 if (total_insns > MAX_INSNS_PER_PATH)
94312 return -ENOMEM;
94313
94314 /*
94315 - * Installing a seccomp filter requires that the task has
94316 + * Installing a seccomp filter requires that the task have
94317 * CAP_SYS_ADMIN in its namespace or be running with no_new_privs.
94318 * This avoids scenarios where unprivileged tasks can affect the
94319 * behavior of privileged children.
94320 @@ -229,51 +252,28 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
94321 CAP_SYS_ADMIN) != 0)
94322 return -EACCES;
94323
94324 - fp = kzalloc(fp_size, GFP_KERNEL|__GFP_NOWARN);
94325 - if (!fp)
94326 - return -ENOMEM;
94327 -
94328 - /* Copy the instructions from fprog. */
94329 - ret = -EFAULT;
94330 - if (copy_from_user(fp, fprog->filter, fp_size))
94331 - goto free_prog;
94332 -
94333 - /* Check and rewrite the fprog via the skb checker */
94334 - ret = sk_chk_filter(fp, fprog->len);
94335 - if (ret)
94336 - goto free_prog;
94337 -
94338 - /* Check and rewrite the fprog for seccomp use */
94339 - ret = seccomp_check_filter(fp, fprog->len);
94340 - if (ret)
94341 - goto free_prog;
94342 -
94343 - /* Convert 'sock_filter' insns to 'sock_filter_int' insns */
94344 - ret = sk_convert_filter(fp, fprog->len, NULL, &new_len);
94345 - if (ret)
94346 - goto free_prog;
94347 -
94348 /* Allocate a new seccomp_filter */
94349 - ret = -ENOMEM;
94350 - filter = kzalloc(sizeof(struct seccomp_filter),
94351 + filter = kzalloc(sizeof(struct seccomp_filter) + fp_size,
94352 GFP_KERNEL|__GFP_NOWARN);
94353 if (!filter)
94354 - goto free_prog;
94355 -
94356 - filter->prog = kzalloc(sk_filter_size(new_len),
94357 - GFP_KERNEL|__GFP_NOWARN);
94358 - if (!filter->prog)
94359 - goto free_filter;
94360 -
94361 - ret = sk_convert_filter(fp, fprog->len, filter->prog->insnsi, &new_len);
94362 - if (ret)
94363 - goto free_filter_prog;
94364 - kfree(fp);
94365 -
94366 + return -ENOMEM;
94367 atomic_set(&filter->usage, 1);
94368 - filter->prog->len = new_len;
94369 + filter->len = fprog->len;
94370
94371 - sk_filter_select_runtime(filter->prog);
94372 + /* Copy the instructions from fprog. */
94373 + ret = -EFAULT;
94374 + if (copy_from_user(filter->insns, fprog->filter, fp_size))
94375 + goto fail;
94376 +
94377 + /* Check and rewrite the fprog via the skb checker */
94378 + ret = sk_chk_filter(filter->insns, filter->len);
94379 + if (ret)
94380 + goto fail;
94381 +
94382 + /* Check and rewrite the fprog for seccomp use */
94383 + ret = seccomp_check_filter(filter->insns, filter->len);
94384 + if (ret)
94385 + goto fail;
94386
94387 /*
94388 * If there is an existing filter, make it the prev and don't drop its
94389 @@ -282,13 +282,8 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
94390 filter->prev = current->seccomp.filter;
94391 current->seccomp.filter = filter;
94392 return 0;
94393 -
94394 -free_filter_prog:
94395 - kfree(filter->prog);
94396 -free_filter:
94397 +fail:
94398 kfree(filter);
94399 -free_prog:
94400 - kfree(fp);
94401 return ret;
94402 }
94403
94404 @@ -298,7 +293,7 @@ free_prog:
94405 *
94406 * Returns 0 on success and non-zero otherwise.
94407 */
94408 -static long seccomp_attach_user_filter(char __user *user_filter)
94409 +long seccomp_attach_user_filter(char __user *user_filter)
94410 {
94411 struct sock_fprog fprog;
94412 long ret = -EFAULT;
94413 @@ -337,7 +332,6 @@ void put_seccomp_filter(struct task_struct *tsk)
94414 while (orig && atomic_dec_and_test(&orig->usage)) {
94415 struct seccomp_filter *freeme = orig;
94416 orig = orig->prev;
94417 - sk_filter_free(freeme->prog);
94418 kfree(freeme);
94419 }
94420 }
94421 diff --git a/kernel/signal.c b/kernel/signal.c
94422 index a4077e9..f0d4e5c 100644
94423 --- a/kernel/signal.c
94424 +++ b/kernel/signal.c
94425 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
94426
94427 int print_fatal_signals __read_mostly;
94428
94429 -static void __user *sig_handler(struct task_struct *t, int sig)
94430 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
94431 {
94432 return t->sighand->action[sig - 1].sa.sa_handler;
94433 }
94434
94435 -static int sig_handler_ignored(void __user *handler, int sig)
94436 +static int sig_handler_ignored(__sighandler_t handler, int sig)
94437 {
94438 /* Is it explicitly or implicitly ignored? */
94439 return handler == SIG_IGN ||
94440 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
94441
94442 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
94443 {
94444 - void __user *handler;
94445 + __sighandler_t handler;
94446
94447 handler = sig_handler(t, sig);
94448
94449 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
94450 atomic_inc(&user->sigpending);
94451 rcu_read_unlock();
94452
94453 + if (!override_rlimit)
94454 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
94455 +
94456 if (override_rlimit ||
94457 atomic_read(&user->sigpending) <=
94458 task_rlimit(t, RLIMIT_SIGPENDING)) {
94459 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
94460
94461 int unhandled_signal(struct task_struct *tsk, int sig)
94462 {
94463 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
94464 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
94465 if (is_global_init(tsk))
94466 return 1;
94467 if (handler != SIG_IGN && handler != SIG_DFL)
94468 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
94469 }
94470 }
94471
94472 + /* allow glibc communication via tgkill to other threads in our
94473 + thread group */
94474 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
94475 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
94476 + && gr_handle_signal(t, sig))
94477 + return -EPERM;
94478 +
94479 return security_task_kill(t, info, sig, 0);
94480 }
94481
94482 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
94483 return send_signal(sig, info, p, 1);
94484 }
94485
94486 -static int
94487 +int
94488 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
94489 {
94490 return send_signal(sig, info, t, 0);
94491 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
94492 unsigned long int flags;
94493 int ret, blocked, ignored;
94494 struct k_sigaction *action;
94495 + int is_unhandled = 0;
94496
94497 spin_lock_irqsave(&t->sighand->siglock, flags);
94498 action = &t->sighand->action[sig-1];
94499 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
94500 }
94501 if (action->sa.sa_handler == SIG_DFL)
94502 t->signal->flags &= ~SIGNAL_UNKILLABLE;
94503 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
94504 + is_unhandled = 1;
94505 ret = specific_send_sig_info(sig, info, t);
94506 spin_unlock_irqrestore(&t->sighand->siglock, flags);
94507
94508 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
94509 + normal operation */
94510 + if (is_unhandled) {
94511 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
94512 + gr_handle_crash(t, sig);
94513 + }
94514 +
94515 return ret;
94516 }
94517
94518 @@ -1296,8 +1316,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
94519 ret = check_kill_permission(sig, info, p);
94520 rcu_read_unlock();
94521
94522 - if (!ret && sig)
94523 + if (!ret && sig) {
94524 ret = do_send_sig_info(sig, info, p, true);
94525 + if (!ret)
94526 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
94527 + }
94528
94529 return ret;
94530 }
94531 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
94532 int error = -ESRCH;
94533
94534 rcu_read_lock();
94535 - p = find_task_by_vpid(pid);
94536 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
94537 + /* allow glibc communication via tgkill to other threads in our
94538 + thread group */
94539 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
94540 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
94541 + p = find_task_by_vpid_unrestricted(pid);
94542 + else
94543 +#endif
94544 + p = find_task_by_vpid(pid);
94545 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
94546 error = check_kill_permission(sig, info, p);
94547 /*
94548 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
94549 }
94550 seg = get_fs();
94551 set_fs(KERNEL_DS);
94552 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
94553 - (stack_t __force __user *) &uoss,
94554 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
94555 + (stack_t __force_user *) &uoss,
94556 compat_user_stack_pointer());
94557 set_fs(seg);
94558 if (ret >= 0 && uoss_ptr) {
94559 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
94560 index eb89e18..a4e6792 100644
94561 --- a/kernel/smpboot.c
94562 +++ b/kernel/smpboot.c
94563 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
94564 }
94565 smpboot_unpark_thread(plug_thread, cpu);
94566 }
94567 - list_add(&plug_thread->list, &hotplug_threads);
94568 + pax_list_add(&plug_thread->list, &hotplug_threads);
94569 out:
94570 mutex_unlock(&smpboot_threads_lock);
94571 return ret;
94572 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
94573 {
94574 get_online_cpus();
94575 mutex_lock(&smpboot_threads_lock);
94576 - list_del(&plug_thread->list);
94577 + pax_list_del(&plug_thread->list);
94578 smpboot_destroy_threads(plug_thread);
94579 mutex_unlock(&smpboot_threads_lock);
94580 put_online_cpus();
94581 diff --git a/kernel/softirq.c b/kernel/softirq.c
94582 index 5918d22..e95d1926 100644
94583 --- a/kernel/softirq.c
94584 +++ b/kernel/softirq.c
94585 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
94586 EXPORT_SYMBOL(irq_stat);
94587 #endif
94588
94589 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
94590 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
94591
94592 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
94593
94594 @@ -266,7 +266,7 @@ restart:
94595 kstat_incr_softirqs_this_cpu(vec_nr);
94596
94597 trace_softirq_entry(vec_nr);
94598 - h->action(h);
94599 + h->action();
94600 trace_softirq_exit(vec_nr);
94601 if (unlikely(prev_count != preempt_count())) {
94602 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
94603 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
94604 or_softirq_pending(1UL << nr);
94605 }
94606
94607 -void open_softirq(int nr, void (*action)(struct softirq_action *))
94608 +void __init open_softirq(int nr, void (*action)(void))
94609 {
94610 softirq_vec[nr].action = action;
94611 }
94612 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
94613 }
94614 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
94615
94616 -static void tasklet_action(struct softirq_action *a)
94617 +static void tasklet_action(void)
94618 {
94619 struct tasklet_struct *list;
94620
94621 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
94622 }
94623 }
94624
94625 -static void tasklet_hi_action(struct softirq_action *a)
94626 +static __latent_entropy void tasklet_hi_action(void)
94627 {
94628 struct tasklet_struct *list;
94629
94630 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
94631 .notifier_call = cpu_callback
94632 };
94633
94634 -static struct smp_hotplug_thread softirq_threads = {
94635 +static struct smp_hotplug_thread softirq_threads __read_only = {
94636 .store = &ksoftirqd,
94637 .thread_should_run = ksoftirqd_should_run,
94638 .thread_fn = run_ksoftirqd,
94639 diff --git a/kernel/sys.c b/kernel/sys.c
94640 index 66a751e..a42497e 100644
94641 --- a/kernel/sys.c
94642 +++ b/kernel/sys.c
94643 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
94644 error = -EACCES;
94645 goto out;
94646 }
94647 +
94648 + if (gr_handle_chroot_setpriority(p, niceval)) {
94649 + error = -EACCES;
94650 + goto out;
94651 + }
94652 +
94653 no_nice = security_task_setnice(p, niceval);
94654 if (no_nice) {
94655 error = no_nice;
94656 @@ -351,6 +357,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
94657 goto error;
94658 }
94659
94660 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
94661 + goto error;
94662 +
94663 + if (!gid_eq(new->gid, old->gid)) {
94664 + /* make sure we generate a learn log for what will
94665 + end up being a role transition after a full-learning
94666 + policy is generated
94667 + CAP_SETGID is required to perform a transition
94668 + we may not log a CAP_SETGID check above, e.g.
94669 + in the case where new rgid = old egid
94670 + */
94671 + gr_learn_cap(current, new, CAP_SETGID);
94672 + }
94673 +
94674 if (rgid != (gid_t) -1 ||
94675 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
94676 new->sgid = new->egid;
94677 @@ -386,6 +406,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
94678 old = current_cred();
94679
94680 retval = -EPERM;
94681 +
94682 + if (gr_check_group_change(kgid, kgid, kgid))
94683 + goto error;
94684 +
94685 if (ns_capable(old->user_ns, CAP_SETGID))
94686 new->gid = new->egid = new->sgid = new->fsgid = kgid;
94687 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
94688 @@ -403,7 +427,7 @@ error:
94689 /*
94690 * change the user struct in a credentials set to match the new UID
94691 */
94692 -static int set_user(struct cred *new)
94693 +int set_user(struct cred *new)
94694 {
94695 struct user_struct *new_user;
94696
94697 @@ -483,7 +507,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
94698 goto error;
94699 }
94700
94701 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
94702 + goto error;
94703 +
94704 if (!uid_eq(new->uid, old->uid)) {
94705 + /* make sure we generate a learn log for what will
94706 + end up being a role transition after a full-learning
94707 + policy is generated
94708 + CAP_SETUID is required to perform a transition
94709 + we may not log a CAP_SETUID check above, e.g.
94710 + in the case where new ruid = old euid
94711 + */
94712 + gr_learn_cap(current, new, CAP_SETUID);
94713 retval = set_user(new);
94714 if (retval < 0)
94715 goto error;
94716 @@ -533,6 +568,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
94717 old = current_cred();
94718
94719 retval = -EPERM;
94720 +
94721 + if (gr_check_crash_uid(kuid))
94722 + goto error;
94723 + if (gr_check_user_change(kuid, kuid, kuid))
94724 + goto error;
94725 +
94726 if (ns_capable(old->user_ns, CAP_SETUID)) {
94727 new->suid = new->uid = kuid;
94728 if (!uid_eq(kuid, old->uid)) {
94729 @@ -602,6 +643,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
94730 goto error;
94731 }
94732
94733 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
94734 + goto error;
94735 +
94736 if (ruid != (uid_t) -1) {
94737 new->uid = kruid;
94738 if (!uid_eq(kruid, old->uid)) {
94739 @@ -684,6 +728,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
94740 goto error;
94741 }
94742
94743 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
94744 + goto error;
94745 +
94746 if (rgid != (gid_t) -1)
94747 new->gid = krgid;
94748 if (egid != (gid_t) -1)
94749 @@ -745,12 +792,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
94750 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
94751 ns_capable(old->user_ns, CAP_SETUID)) {
94752 if (!uid_eq(kuid, old->fsuid)) {
94753 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
94754 + goto error;
94755 +
94756 new->fsuid = kuid;
94757 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
94758 goto change_okay;
94759 }
94760 }
94761
94762 +error:
94763 abort_creds(new);
94764 return old_fsuid;
94765
94766 @@ -783,12 +834,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
94767 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
94768 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
94769 ns_capable(old->user_ns, CAP_SETGID)) {
94770 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
94771 + goto error;
94772 +
94773 if (!gid_eq(kgid, old->fsgid)) {
94774 new->fsgid = kgid;
94775 goto change_okay;
94776 }
94777 }
94778
94779 +error:
94780 abort_creds(new);
94781 return old_fsgid;
94782
94783 @@ -1167,19 +1222,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
94784 return -EFAULT;
94785
94786 down_read(&uts_sem);
94787 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
94788 + error = __copy_to_user(name->sysname, &utsname()->sysname,
94789 __OLD_UTS_LEN);
94790 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
94791 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
94792 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
94793 __OLD_UTS_LEN);
94794 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
94795 - error |= __copy_to_user(&name->release, &utsname()->release,
94796 + error |= __copy_to_user(name->release, &utsname()->release,
94797 __OLD_UTS_LEN);
94798 error |= __put_user(0, name->release + __OLD_UTS_LEN);
94799 - error |= __copy_to_user(&name->version, &utsname()->version,
94800 + error |= __copy_to_user(name->version, &utsname()->version,
94801 __OLD_UTS_LEN);
94802 error |= __put_user(0, name->version + __OLD_UTS_LEN);
94803 - error |= __copy_to_user(&name->machine, &utsname()->machine,
94804 + error |= __copy_to_user(name->machine, &utsname()->machine,
94805 __OLD_UTS_LEN);
94806 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
94807 up_read(&uts_sem);
94808 @@ -1381,6 +1436,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
94809 */
94810 new_rlim->rlim_cur = 1;
94811 }
94812 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
94813 + is changed to a lower value. Since tasks can be created by the same
94814 + user in between this limit change and an execve by this task, force
94815 + a recheck only for this task by setting PF_NPROC_EXCEEDED
94816 + */
94817 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
94818 + tsk->flags |= PF_NPROC_EXCEEDED;
94819 }
94820 if (!retval) {
94821 if (old_rlim)
94822 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
94823 index 75b22e2..65c0ac8 100644
94824 --- a/kernel/sysctl.c
94825 +++ b/kernel/sysctl.c
94826 @@ -94,7 +94,6 @@
94827
94828
94829 #if defined(CONFIG_SYSCTL)
94830 -
94831 /* External variables not in a header file. */
94832 extern int max_threads;
94833 extern int suid_dumpable;
94834 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
94835
94836 /* Constants used for minimum and maximum */
94837 #ifdef CONFIG_LOCKUP_DETECTOR
94838 -static int sixty = 60;
94839 +static int sixty __read_only = 60;
94840 #endif
94841
94842 -static int __maybe_unused neg_one = -1;
94843 +static int __maybe_unused neg_one __read_only = -1;
94844
94845 -static int zero;
94846 -static int __maybe_unused one = 1;
94847 -static int __maybe_unused two = 2;
94848 -static int __maybe_unused four = 4;
94849 -static unsigned long one_ul = 1;
94850 -static int one_hundred = 100;
94851 +static int zero __read_only = 0;
94852 +static int __maybe_unused one __read_only = 1;
94853 +static int __maybe_unused two __read_only = 2;
94854 +static int __maybe_unused three __read_only = 3;
94855 +static int __maybe_unused four __read_only = 4;
94856 +static unsigned long one_ul __read_only = 1;
94857 +static int one_hundred __read_only = 100;
94858 #ifdef CONFIG_PRINTK
94859 -static int ten_thousand = 10000;
94860 +static int ten_thousand __read_only = 10000;
94861 #endif
94862
94863 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
94864 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
94865 void __user *buffer, size_t *lenp, loff_t *ppos);
94866 #endif
94867
94868 -#ifdef CONFIG_PRINTK
94869 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
94870 void __user *buffer, size_t *lenp, loff_t *ppos);
94871 -#endif
94872
94873 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
94874 void __user *buffer, size_t *lenp, loff_t *ppos);
94875 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
94876
94877 #endif
94878
94879 +extern struct ctl_table grsecurity_table[];
94880 +
94881 static struct ctl_table kern_table[];
94882 static struct ctl_table vm_table[];
94883 static struct ctl_table fs_table[];
94884 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
94885 int sysctl_legacy_va_layout;
94886 #endif
94887
94888 +#ifdef CONFIG_PAX_SOFTMODE
94889 +static ctl_table pax_table[] = {
94890 + {
94891 + .procname = "softmode",
94892 + .data = &pax_softmode,
94893 + .maxlen = sizeof(unsigned int),
94894 + .mode = 0600,
94895 + .proc_handler = &proc_dointvec,
94896 + },
94897 +
94898 + { }
94899 +};
94900 +#endif
94901 +
94902 /* The default sysctl tables: */
94903
94904 static struct ctl_table sysctl_base_table[] = {
94905 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
94906 #endif
94907
94908 static struct ctl_table kern_table[] = {
94909 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
94910 + {
94911 + .procname = "grsecurity",
94912 + .mode = 0500,
94913 + .child = grsecurity_table,
94914 + },
94915 +#endif
94916 +
94917 +#ifdef CONFIG_PAX_SOFTMODE
94918 + {
94919 + .procname = "pax",
94920 + .mode = 0500,
94921 + .child = pax_table,
94922 + },
94923 +#endif
94924 +
94925 {
94926 .procname = "sched_child_runs_first",
94927 .data = &sysctl_sched_child_runs_first,
94928 @@ -641,7 +671,7 @@ static struct ctl_table kern_table[] = {
94929 .data = &modprobe_path,
94930 .maxlen = KMOD_PATH_LEN,
94931 .mode = 0644,
94932 - .proc_handler = proc_dostring,
94933 + .proc_handler = proc_dostring_modpriv,
94934 },
94935 {
94936 .procname = "modules_disabled",
94937 @@ -808,16 +838,20 @@ static struct ctl_table kern_table[] = {
94938 .extra1 = &zero,
94939 .extra2 = &one,
94940 },
94941 +#endif
94942 {
94943 .procname = "kptr_restrict",
94944 .data = &kptr_restrict,
94945 .maxlen = sizeof(int),
94946 .mode = 0644,
94947 .proc_handler = proc_dointvec_minmax_sysadmin,
94948 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94949 + .extra1 = &two,
94950 +#else
94951 .extra1 = &zero,
94952 +#endif
94953 .extra2 = &two,
94954 },
94955 -#endif
94956 {
94957 .procname = "ngroups_max",
94958 .data = &ngroups_max,
94959 @@ -1073,10 +1107,17 @@ static struct ctl_table kern_table[] = {
94960 */
94961 {
94962 .procname = "perf_event_paranoid",
94963 - .data = &sysctl_perf_event_paranoid,
94964 - .maxlen = sizeof(sysctl_perf_event_paranoid),
94965 + .data = &sysctl_perf_event_legitimately_concerned,
94966 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
94967 .mode = 0644,
94968 - .proc_handler = proc_dointvec,
94969 + /* go ahead, be a hero */
94970 + .proc_handler = proc_dointvec_minmax_sysadmin,
94971 + .extra1 = &neg_one,
94972 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
94973 + .extra2 = &three,
94974 +#else
94975 + .extra2 = &two,
94976 +#endif
94977 },
94978 {
94979 .procname = "perf_event_mlock_kb",
94980 @@ -1338,6 +1379,13 @@ static struct ctl_table vm_table[] = {
94981 .proc_handler = proc_dointvec_minmax,
94982 .extra1 = &zero,
94983 },
94984 + {
94985 + .procname = "heap_stack_gap",
94986 + .data = &sysctl_heap_stack_gap,
94987 + .maxlen = sizeof(sysctl_heap_stack_gap),
94988 + .mode = 0644,
94989 + .proc_handler = proc_doulongvec_minmax,
94990 + },
94991 #else
94992 {
94993 .procname = "nr_trim_pages",
94994 @@ -1827,6 +1875,16 @@ int proc_dostring(struct ctl_table *table, int write,
94995 (char __user *)buffer, lenp, ppos);
94996 }
94997
94998 +int proc_dostring_modpriv(struct ctl_table *table, int write,
94999 + void __user *buffer, size_t *lenp, loff_t *ppos)
95000 +{
95001 + if (write && !capable(CAP_SYS_MODULE))
95002 + return -EPERM;
95003 +
95004 + return _proc_do_string(table->data, table->maxlen, write,
95005 + buffer, lenp, ppos);
95006 +}
95007 +
95008 static size_t proc_skip_spaces(char **buf)
95009 {
95010 size_t ret;
95011 @@ -1932,6 +1990,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
95012 len = strlen(tmp);
95013 if (len > *size)
95014 len = *size;
95015 + if (len > sizeof(tmp))
95016 + len = sizeof(tmp);
95017 if (copy_to_user(*buf, tmp, len))
95018 return -EFAULT;
95019 *size -= len;
95020 @@ -2109,7 +2169,7 @@ int proc_dointvec(struct ctl_table *table, int write,
95021 static int proc_taint(struct ctl_table *table, int write,
95022 void __user *buffer, size_t *lenp, loff_t *ppos)
95023 {
95024 - struct ctl_table t;
95025 + ctl_table_no_const t;
95026 unsigned long tmptaint = get_taint();
95027 int err;
95028
95029 @@ -2137,7 +2197,6 @@ static int proc_taint(struct ctl_table *table, int write,
95030 return err;
95031 }
95032
95033 -#ifdef CONFIG_PRINTK
95034 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
95035 void __user *buffer, size_t *lenp, loff_t *ppos)
95036 {
95037 @@ -2146,7 +2205,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
95038
95039 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
95040 }
95041 -#endif
95042
95043 struct do_proc_dointvec_minmax_conv_param {
95044 int *min;
95045 @@ -2706,6 +2764,12 @@ int proc_dostring(struct ctl_table *table, int write,
95046 return -ENOSYS;
95047 }
95048
95049 +int proc_dostring_modpriv(struct ctl_table *table, int write,
95050 + void __user *buffer, size_t *lenp, loff_t *ppos)
95051 +{
95052 + return -ENOSYS;
95053 +}
95054 +
95055 int proc_dointvec(struct ctl_table *table, int write,
95056 void __user *buffer, size_t *lenp, loff_t *ppos)
95057 {
95058 @@ -2762,5 +2826,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
95059 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
95060 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
95061 EXPORT_SYMBOL(proc_dostring);
95062 +EXPORT_SYMBOL(proc_dostring_modpriv);
95063 EXPORT_SYMBOL(proc_doulongvec_minmax);
95064 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
95065 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
95066 index 13d2f7c..c93d0b0 100644
95067 --- a/kernel/taskstats.c
95068 +++ b/kernel/taskstats.c
95069 @@ -28,9 +28,12 @@
95070 #include <linux/fs.h>
95071 #include <linux/file.h>
95072 #include <linux/pid_namespace.h>
95073 +#include <linux/grsecurity.h>
95074 #include <net/genetlink.h>
95075 #include <linux/atomic.h>
95076
95077 +extern int gr_is_taskstats_denied(int pid);
95078 +
95079 /*
95080 * Maximum length of a cpumask that can be specified in
95081 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
95082 @@ -576,6 +579,9 @@ err:
95083
95084 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
95085 {
95086 + if (gr_is_taskstats_denied(current->pid))
95087 + return -EACCES;
95088 +
95089 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
95090 return cmd_attr_register_cpumask(info);
95091 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
95092 diff --git a/kernel/time.c b/kernel/time.c
95093 index 7c7964c..2a0d412 100644
95094 --- a/kernel/time.c
95095 +++ b/kernel/time.c
95096 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
95097 return error;
95098
95099 if (tz) {
95100 + /* we log in do_settimeofday called below, so don't log twice
95101 + */
95102 + if (!tv)
95103 + gr_log_timechange();
95104 +
95105 sys_tz = *tz;
95106 update_vsyscall_tz();
95107 if (firsttime) {
95108 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
95109 index fe75444..190c528 100644
95110 --- a/kernel/time/alarmtimer.c
95111 +++ b/kernel/time/alarmtimer.c
95112 @@ -811,7 +811,7 @@ static int __init alarmtimer_init(void)
95113 struct platform_device *pdev;
95114 int error = 0;
95115 int i;
95116 - struct k_clock alarm_clock = {
95117 + static struct k_clock alarm_clock = {
95118 .clock_getres = alarm_clock_getres,
95119 .clock_get = alarm_clock_get,
95120 .timer_create = alarm_timer_create,
95121 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
95122 index 32d8d6a..11486af 100644
95123 --- a/kernel/time/timekeeping.c
95124 +++ b/kernel/time/timekeeping.c
95125 @@ -15,6 +15,7 @@
95126 #include <linux/init.h>
95127 #include <linux/mm.h>
95128 #include <linux/sched.h>
95129 +#include <linux/grsecurity.h>
95130 #include <linux/syscore_ops.h>
95131 #include <linux/clocksource.h>
95132 #include <linux/jiffies.h>
95133 @@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
95134 if (!timespec_valid_strict(tv))
95135 return -EINVAL;
95136
95137 + gr_log_timechange();
95138 +
95139 raw_spin_lock_irqsave(&timekeeper_lock, flags);
95140 write_seqcount_begin(&timekeeper_seq);
95141
95142 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
95143 index 61ed862..3b52c65 100644
95144 --- a/kernel/time/timer_list.c
95145 +++ b/kernel/time/timer_list.c
95146 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
95147
95148 static void print_name_offset(struct seq_file *m, void *sym)
95149 {
95150 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95151 + SEQ_printf(m, "<%p>", NULL);
95152 +#else
95153 char symname[KSYM_NAME_LEN];
95154
95155 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
95156 SEQ_printf(m, "<%pK>", sym);
95157 else
95158 SEQ_printf(m, "%s", symname);
95159 +#endif
95160 }
95161
95162 static void
95163 @@ -119,7 +123,11 @@ next_one:
95164 static void
95165 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
95166 {
95167 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95168 + SEQ_printf(m, " .base: %p\n", NULL);
95169 +#else
95170 SEQ_printf(m, " .base: %pK\n", base);
95171 +#endif
95172 SEQ_printf(m, " .index: %d\n",
95173 base->index);
95174 SEQ_printf(m, " .resolution: %Lu nsecs\n",
95175 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
95176 {
95177 struct proc_dir_entry *pe;
95178
95179 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
95180 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
95181 +#else
95182 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
95183 +#endif
95184 if (!pe)
95185 return -ENOMEM;
95186 return 0;
95187 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
95188 index 1fb08f2..ca4bb1e 100644
95189 --- a/kernel/time/timer_stats.c
95190 +++ b/kernel/time/timer_stats.c
95191 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
95192 static unsigned long nr_entries;
95193 static struct entry entries[MAX_ENTRIES];
95194
95195 -static atomic_t overflow_count;
95196 +static atomic_unchecked_t overflow_count;
95197
95198 /*
95199 * The entries are in a hash-table, for fast lookup:
95200 @@ -140,7 +140,7 @@ static void reset_entries(void)
95201 nr_entries = 0;
95202 memset(entries, 0, sizeof(entries));
95203 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
95204 - atomic_set(&overflow_count, 0);
95205 + atomic_set_unchecked(&overflow_count, 0);
95206 }
95207
95208 static struct entry *alloc_entry(void)
95209 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
95210 if (likely(entry))
95211 entry->count++;
95212 else
95213 - atomic_inc(&overflow_count);
95214 + atomic_inc_unchecked(&overflow_count);
95215
95216 out_unlock:
95217 raw_spin_unlock_irqrestore(lock, flags);
95218 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
95219
95220 static void print_name_offset(struct seq_file *m, unsigned long addr)
95221 {
95222 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95223 + seq_printf(m, "<%p>", NULL);
95224 +#else
95225 char symname[KSYM_NAME_LEN];
95226
95227 if (lookup_symbol_name(addr, symname) < 0)
95228 - seq_printf(m, "<%p>", (void *)addr);
95229 + seq_printf(m, "<%pK>", (void *)addr);
95230 else
95231 seq_printf(m, "%s", symname);
95232 +#endif
95233 }
95234
95235 static int tstats_show(struct seq_file *m, void *v)
95236 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
95237
95238 seq_puts(m, "Timer Stats Version: v0.3\n");
95239 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
95240 - if (atomic_read(&overflow_count))
95241 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
95242 + if (atomic_read_unchecked(&overflow_count))
95243 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
95244 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
95245
95246 for (i = 0; i < nr_entries; i++) {
95247 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
95248 {
95249 struct proc_dir_entry *pe;
95250
95251 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
95252 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
95253 +#else
95254 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
95255 +#endif
95256 if (!pe)
95257 return -ENOMEM;
95258 return 0;
95259 diff --git a/kernel/timer.c b/kernel/timer.c
95260 index 3bb01a3..0e7760e 100644
95261 --- a/kernel/timer.c
95262 +++ b/kernel/timer.c
95263 @@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
95264 /*
95265 * This function runs timers and the timer-tq in bottom half context.
95266 */
95267 -static void run_timer_softirq(struct softirq_action *h)
95268 +static __latent_entropy void run_timer_softirq(void)
95269 {
95270 struct tvec_base *base = __this_cpu_read(tvec_bases);
95271
95272 @@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
95273 *
95274 * In all cases the return value is guaranteed to be non-negative.
95275 */
95276 -signed long __sched schedule_timeout(signed long timeout)
95277 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
95278 {
95279 struct timer_list timer;
95280 unsigned long expire;
95281 diff --git a/kernel/torture.c b/kernel/torture.c
95282 index 40bb511..91190b9 100644
95283 --- a/kernel/torture.c
95284 +++ b/kernel/torture.c
95285 @@ -484,7 +484,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
95286 mutex_lock(&fullstop_mutex);
95287 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
95288 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
95289 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
95290 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
95291 } else {
95292 pr_warn("Concurrent rmmod and shutdown illegal!\n");
95293 }
95294 @@ -551,14 +551,14 @@ static int torture_stutter(void *arg)
95295 if (!torture_must_stop()) {
95296 if (stutter > 1) {
95297 schedule_timeout_interruptible(stutter - 1);
95298 - ACCESS_ONCE(stutter_pause_test) = 2;
95299 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
95300 }
95301 schedule_timeout_interruptible(1);
95302 - ACCESS_ONCE(stutter_pause_test) = 1;
95303 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
95304 }
95305 if (!torture_must_stop())
95306 schedule_timeout_interruptible(stutter);
95307 - ACCESS_ONCE(stutter_pause_test) = 0;
95308 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
95309 torture_shutdown_absorb("torture_stutter");
95310 } while (!torture_must_stop());
95311 torture_kthread_stopping("torture_stutter");
95312 @@ -645,7 +645,7 @@ bool torture_cleanup(void)
95313 schedule_timeout_uninterruptible(10);
95314 return true;
95315 }
95316 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
95317 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
95318 mutex_unlock(&fullstop_mutex);
95319 torture_shutdown_cleanup();
95320 torture_shuffle_cleanup();
95321 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
95322 index c1bd4ad..4b861dc 100644
95323 --- a/kernel/trace/blktrace.c
95324 +++ b/kernel/trace/blktrace.c
95325 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
95326 struct blk_trace *bt = filp->private_data;
95327 char buf[16];
95328
95329 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
95330 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
95331
95332 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
95333 }
95334 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
95335 return 1;
95336
95337 bt = buf->chan->private_data;
95338 - atomic_inc(&bt->dropped);
95339 + atomic_inc_unchecked(&bt->dropped);
95340 return 0;
95341 }
95342
95343 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
95344
95345 bt->dir = dir;
95346 bt->dev = dev;
95347 - atomic_set(&bt->dropped, 0);
95348 + atomic_set_unchecked(&bt->dropped, 0);
95349 INIT_LIST_HEAD(&bt->running_list);
95350
95351 ret = -EIO;
95352 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
95353 index ac9d1da..ce98b35 100644
95354 --- a/kernel/trace/ftrace.c
95355 +++ b/kernel/trace/ftrace.c
95356 @@ -1920,12 +1920,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
95357 if (unlikely(ftrace_disabled))
95358 return 0;
95359
95360 + ret = ftrace_arch_code_modify_prepare();
95361 + FTRACE_WARN_ON(ret);
95362 + if (ret)
95363 + return 0;
95364 +
95365 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
95366 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
95367 if (ret) {
95368 ftrace_bug(ret, ip);
95369 - return 0;
95370 }
95371 - return 1;
95372 + return ret ? 0 : 1;
95373 }
95374
95375 /*
95376 @@ -4126,8 +4131,10 @@ static int ftrace_process_locs(struct module *mod,
95377 if (!count)
95378 return 0;
95379
95380 + pax_open_kernel();
95381 sort(start, count, sizeof(*start),
95382 ftrace_cmp_ips, ftrace_swap_ips);
95383 + pax_close_kernel();
95384
95385 start_pg = ftrace_allocate_pages(count);
95386 if (!start_pg)
95387 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
95388 index ff70271..4242e69 100644
95389 --- a/kernel/trace/ring_buffer.c
95390 +++ b/kernel/trace/ring_buffer.c
95391 @@ -352,9 +352,9 @@ struct buffer_data_page {
95392 */
95393 struct buffer_page {
95394 struct list_head list; /* list of buffer pages */
95395 - local_t write; /* index for next write */
95396 + local_unchecked_t write; /* index for next write */
95397 unsigned read; /* index for next read */
95398 - local_t entries; /* entries on this page */
95399 + local_unchecked_t entries; /* entries on this page */
95400 unsigned long real_end; /* real end of data */
95401 struct buffer_data_page *page; /* Actual data page */
95402 };
95403 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
95404 unsigned long last_overrun;
95405 local_t entries_bytes;
95406 local_t entries;
95407 - local_t overrun;
95408 - local_t commit_overrun;
95409 + local_unchecked_t overrun;
95410 + local_unchecked_t commit_overrun;
95411 local_t dropped_events;
95412 local_t committing;
95413 local_t commits;
95414 @@ -626,8 +626,22 @@ int ring_buffer_poll_wait(struct ring_buffer *buffer, int cpu,
95415 work = &cpu_buffer->irq_work;
95416 }
95417
95418 - work->waiters_pending = true;
95419 poll_wait(filp, &work->waiters, poll_table);
95420 + work->waiters_pending = true;
95421 + /*
95422 + * There's a tight race between setting the waiters_pending and
95423 + * checking if the ring buffer is empty. Once the waiters_pending bit
95424 + * is set, the next event will wake the task up, but we can get stuck
95425 + * if there's only a single event in.
95426 + *
95427 + * FIXME: Ideally, we need a memory barrier on the writer side as well,
95428 + * but adding a memory barrier to all events will cause too much of a
95429 + * performance hit in the fast path. We only need a memory barrier when
95430 + * the buffer goes from empty to having content. But as this race is
95431 + * extremely small, and it's not a problem if another event comes in, we
95432 + * will fix it later.
95433 + */
95434 + smp_mb();
95435
95436 if ((cpu == RING_BUFFER_ALL_CPUS && !ring_buffer_empty(buffer)) ||
95437 (cpu != RING_BUFFER_ALL_CPUS && !ring_buffer_empty_cpu(buffer, cpu)))
95438 @@ -991,8 +1005,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
95439 *
95440 * We add a counter to the write field to denote this.
95441 */
95442 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
95443 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
95444 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
95445 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
95446
95447 /*
95448 * Just make sure we have seen our old_write and synchronize
95449 @@ -1020,8 +1034,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
95450 * cmpxchg to only update if an interrupt did not already
95451 * do it for us. If the cmpxchg fails, we don't care.
95452 */
95453 - (void)local_cmpxchg(&next_page->write, old_write, val);
95454 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
95455 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
95456 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
95457
95458 /*
95459 * No need to worry about races with clearing out the commit.
95460 @@ -1388,12 +1402,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
95461
95462 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
95463 {
95464 - return local_read(&bpage->entries) & RB_WRITE_MASK;
95465 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
95466 }
95467
95468 static inline unsigned long rb_page_write(struct buffer_page *bpage)
95469 {
95470 - return local_read(&bpage->write) & RB_WRITE_MASK;
95471 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
95472 }
95473
95474 static int
95475 @@ -1488,7 +1502,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
95476 * bytes consumed in ring buffer from here.
95477 * Increment overrun to account for the lost events.
95478 */
95479 - local_add(page_entries, &cpu_buffer->overrun);
95480 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
95481 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
95482 }
95483
95484 @@ -2066,7 +2080,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
95485 * it is our responsibility to update
95486 * the counters.
95487 */
95488 - local_add(entries, &cpu_buffer->overrun);
95489 + local_add_unchecked(entries, &cpu_buffer->overrun);
95490 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
95491
95492 /*
95493 @@ -2216,7 +2230,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
95494 if (tail == BUF_PAGE_SIZE)
95495 tail_page->real_end = 0;
95496
95497 - local_sub(length, &tail_page->write);
95498 + local_sub_unchecked(length, &tail_page->write);
95499 return;
95500 }
95501
95502 @@ -2251,7 +2265,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
95503 rb_event_set_padding(event);
95504
95505 /* Set the write back to the previous setting */
95506 - local_sub(length, &tail_page->write);
95507 + local_sub_unchecked(length, &tail_page->write);
95508 return;
95509 }
95510
95511 @@ -2263,7 +2277,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
95512
95513 /* Set write to end of buffer */
95514 length = (tail + length) - BUF_PAGE_SIZE;
95515 - local_sub(length, &tail_page->write);
95516 + local_sub_unchecked(length, &tail_page->write);
95517 }
95518
95519 /*
95520 @@ -2289,7 +2303,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
95521 * about it.
95522 */
95523 if (unlikely(next_page == commit_page)) {
95524 - local_inc(&cpu_buffer->commit_overrun);
95525 + local_inc_unchecked(&cpu_buffer->commit_overrun);
95526 goto out_reset;
95527 }
95528
95529 @@ -2345,7 +2359,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
95530 cpu_buffer->tail_page) &&
95531 (cpu_buffer->commit_page ==
95532 cpu_buffer->reader_page))) {
95533 - local_inc(&cpu_buffer->commit_overrun);
95534 + local_inc_unchecked(&cpu_buffer->commit_overrun);
95535 goto out_reset;
95536 }
95537 }
95538 @@ -2393,7 +2407,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
95539 length += RB_LEN_TIME_EXTEND;
95540
95541 tail_page = cpu_buffer->tail_page;
95542 - write = local_add_return(length, &tail_page->write);
95543 + write = local_add_return_unchecked(length, &tail_page->write);
95544
95545 /* set write to only the index of the write */
95546 write &= RB_WRITE_MASK;
95547 @@ -2417,7 +2431,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
95548 kmemcheck_annotate_bitfield(event, bitfield);
95549 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
95550
95551 - local_inc(&tail_page->entries);
95552 + local_inc_unchecked(&tail_page->entries);
95553
95554 /*
95555 * If this is the first commit on the page, then update
95556 @@ -2450,7 +2464,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
95557
95558 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
95559 unsigned long write_mask =
95560 - local_read(&bpage->write) & ~RB_WRITE_MASK;
95561 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
95562 unsigned long event_length = rb_event_length(event);
95563 /*
95564 * This is on the tail page. It is possible that
95565 @@ -2460,7 +2474,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
95566 */
95567 old_index += write_mask;
95568 new_index += write_mask;
95569 - index = local_cmpxchg(&bpage->write, old_index, new_index);
95570 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
95571 if (index == old_index) {
95572 /* update counters */
95573 local_sub(event_length, &cpu_buffer->entries_bytes);
95574 @@ -2852,7 +2866,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
95575
95576 /* Do the likely case first */
95577 if (likely(bpage->page == (void *)addr)) {
95578 - local_dec(&bpage->entries);
95579 + local_dec_unchecked(&bpage->entries);
95580 return;
95581 }
95582
95583 @@ -2864,7 +2878,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
95584 start = bpage;
95585 do {
95586 if (bpage->page == (void *)addr) {
95587 - local_dec(&bpage->entries);
95588 + local_dec_unchecked(&bpage->entries);
95589 return;
95590 }
95591 rb_inc_page(cpu_buffer, &bpage);
95592 @@ -3148,7 +3162,7 @@ static inline unsigned long
95593 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
95594 {
95595 return local_read(&cpu_buffer->entries) -
95596 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
95597 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
95598 }
95599
95600 /**
95601 @@ -3237,7 +3251,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
95602 return 0;
95603
95604 cpu_buffer = buffer->buffers[cpu];
95605 - ret = local_read(&cpu_buffer->overrun);
95606 + ret = local_read_unchecked(&cpu_buffer->overrun);
95607
95608 return ret;
95609 }
95610 @@ -3260,7 +3274,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
95611 return 0;
95612
95613 cpu_buffer = buffer->buffers[cpu];
95614 - ret = local_read(&cpu_buffer->commit_overrun);
95615 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
95616
95617 return ret;
95618 }
95619 @@ -3345,7 +3359,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
95620 /* if you care about this being correct, lock the buffer */
95621 for_each_buffer_cpu(buffer, cpu) {
95622 cpu_buffer = buffer->buffers[cpu];
95623 - overruns += local_read(&cpu_buffer->overrun);
95624 + overruns += local_read_unchecked(&cpu_buffer->overrun);
95625 }
95626
95627 return overruns;
95628 @@ -3521,8 +3535,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
95629 /*
95630 * Reset the reader page to size zero.
95631 */
95632 - local_set(&cpu_buffer->reader_page->write, 0);
95633 - local_set(&cpu_buffer->reader_page->entries, 0);
95634 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
95635 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
95636 local_set(&cpu_buffer->reader_page->page->commit, 0);
95637 cpu_buffer->reader_page->real_end = 0;
95638
95639 @@ -3556,7 +3570,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
95640 * want to compare with the last_overrun.
95641 */
95642 smp_mb();
95643 - overwrite = local_read(&(cpu_buffer->overrun));
95644 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
95645
95646 /*
95647 * Here's the tricky part.
95648 @@ -4126,8 +4140,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
95649
95650 cpu_buffer->head_page
95651 = list_entry(cpu_buffer->pages, struct buffer_page, list);
95652 - local_set(&cpu_buffer->head_page->write, 0);
95653 - local_set(&cpu_buffer->head_page->entries, 0);
95654 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
95655 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
95656 local_set(&cpu_buffer->head_page->page->commit, 0);
95657
95658 cpu_buffer->head_page->read = 0;
95659 @@ -4137,14 +4151,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
95660
95661 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
95662 INIT_LIST_HEAD(&cpu_buffer->new_pages);
95663 - local_set(&cpu_buffer->reader_page->write, 0);
95664 - local_set(&cpu_buffer->reader_page->entries, 0);
95665 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
95666 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
95667 local_set(&cpu_buffer->reader_page->page->commit, 0);
95668 cpu_buffer->reader_page->read = 0;
95669
95670 local_set(&cpu_buffer->entries_bytes, 0);
95671 - local_set(&cpu_buffer->overrun, 0);
95672 - local_set(&cpu_buffer->commit_overrun, 0);
95673 + local_set_unchecked(&cpu_buffer->overrun, 0);
95674 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
95675 local_set(&cpu_buffer->dropped_events, 0);
95676 local_set(&cpu_buffer->entries, 0);
95677 local_set(&cpu_buffer->committing, 0);
95678 @@ -4549,8 +4563,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
95679 rb_init_page(bpage);
95680 bpage = reader->page;
95681 reader->page = *data_page;
95682 - local_set(&reader->write, 0);
95683 - local_set(&reader->entries, 0);
95684 + local_set_unchecked(&reader->write, 0);
95685 + local_set_unchecked(&reader->entries, 0);
95686 reader->read = 0;
95687 *data_page = bpage;
95688
95689 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
95690 index 291397e..db3836d 100644
95691 --- a/kernel/trace/trace.c
95692 +++ b/kernel/trace/trace.c
95693 @@ -3510,7 +3510,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
95694 return 0;
95695 }
95696
95697 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
95698 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
95699 {
95700 /* do nothing if flag is already set */
95701 if (!!(trace_flags & mask) == !!enabled)
95702 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
95703 index 9258f5a..9b1e41e 100644
95704 --- a/kernel/trace/trace.h
95705 +++ b/kernel/trace/trace.h
95706 @@ -1278,7 +1278,7 @@ extern const char *__stop___tracepoint_str[];
95707 void trace_printk_init_buffers(void);
95708 void trace_printk_start_comm(void);
95709 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
95710 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
95711 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
95712
95713 /*
95714 * Normal trace_printk() and friends allocates special buffers
95715 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
95716 index 57b67b1..66082a9 100644
95717 --- a/kernel/trace/trace_clock.c
95718 +++ b/kernel/trace/trace_clock.c
95719 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
95720 return now;
95721 }
95722
95723 -static atomic64_t trace_counter;
95724 +static atomic64_unchecked_t trace_counter;
95725
95726 /*
95727 * trace_clock_counter(): simply an atomic counter.
95728 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
95729 */
95730 u64 notrace trace_clock_counter(void)
95731 {
95732 - return atomic64_add_return(1, &trace_counter);
95733 + return atomic64_inc_return_unchecked(&trace_counter);
95734 }
95735 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
95736 index 2de5362..c4c7003 100644
95737 --- a/kernel/trace/trace_events.c
95738 +++ b/kernel/trace/trace_events.c
95739 @@ -1722,7 +1722,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
95740 return 0;
95741 }
95742
95743 -struct ftrace_module_file_ops;
95744 static void __add_event_to_tracers(struct ftrace_event_call *call);
95745
95746 /* Add an additional event_call dynamically */
95747 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
95748 index 0abd9b8..6a663a2 100644
95749 --- a/kernel/trace/trace_mmiotrace.c
95750 +++ b/kernel/trace/trace_mmiotrace.c
95751 @@ -24,7 +24,7 @@ struct header_iter {
95752 static struct trace_array *mmio_trace_array;
95753 static bool overrun_detected;
95754 static unsigned long prev_overruns;
95755 -static atomic_t dropped_count;
95756 +static atomic_unchecked_t dropped_count;
95757
95758 static void mmio_reset_data(struct trace_array *tr)
95759 {
95760 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
95761
95762 static unsigned long count_overruns(struct trace_iterator *iter)
95763 {
95764 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
95765 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
95766 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
95767
95768 if (over > prev_overruns)
95769 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
95770 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
95771 sizeof(*entry), 0, pc);
95772 if (!event) {
95773 - atomic_inc(&dropped_count);
95774 + atomic_inc_unchecked(&dropped_count);
95775 return;
95776 }
95777 entry = ring_buffer_event_data(event);
95778 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
95779 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
95780 sizeof(*entry), 0, pc);
95781 if (!event) {
95782 - atomic_inc(&dropped_count);
95783 + atomic_inc_unchecked(&dropped_count);
95784 return;
95785 }
95786 entry = ring_buffer_event_data(event);
95787 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
95788 index f3dad80..d291d61 100644
95789 --- a/kernel/trace/trace_output.c
95790 +++ b/kernel/trace/trace_output.c
95791 @@ -322,7 +322,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
95792
95793 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
95794 if (!IS_ERR(p)) {
95795 - p = mangle_path(s->buffer + s->len, p, "\n");
95796 + p = mangle_path(s->buffer + s->len, p, "\n\\");
95797 if (p) {
95798 s->len = p - s->buffer;
95799 return 1;
95800 @@ -980,14 +980,16 @@ int register_ftrace_event(struct trace_event *event)
95801 goto out;
95802 }
95803
95804 + pax_open_kernel();
95805 if (event->funcs->trace == NULL)
95806 - event->funcs->trace = trace_nop_print;
95807 + *(void **)&event->funcs->trace = trace_nop_print;
95808 if (event->funcs->raw == NULL)
95809 - event->funcs->raw = trace_nop_print;
95810 + *(void **)&event->funcs->raw = trace_nop_print;
95811 if (event->funcs->hex == NULL)
95812 - event->funcs->hex = trace_nop_print;
95813 + *(void **)&event->funcs->hex = trace_nop_print;
95814 if (event->funcs->binary == NULL)
95815 - event->funcs->binary = trace_nop_print;
95816 + *(void **)&event->funcs->binary = trace_nop_print;
95817 + pax_close_kernel();
95818
95819 key = event->type & (EVENT_HASHSIZE - 1);
95820
95821 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
95822 index 8a4e5cb..64f270d 100644
95823 --- a/kernel/trace/trace_stack.c
95824 +++ b/kernel/trace/trace_stack.c
95825 @@ -91,7 +91,7 @@ check_stack(unsigned long ip, unsigned long *stack)
95826 return;
95827
95828 /* we do not handle interrupt stacks yet */
95829 - if (!object_is_on_stack(stack))
95830 + if (!object_starts_on_stack(stack))
95831 return;
95832
95833 local_irq_save(flags);
95834 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
95835 index fcc0256..aee880f 100644
95836 --- a/kernel/user_namespace.c
95837 +++ b/kernel/user_namespace.c
95838 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
95839 !kgid_has_mapping(parent_ns, group))
95840 return -EPERM;
95841
95842 +#ifdef CONFIG_GRKERNSEC
95843 + /*
95844 + * This doesn't really inspire confidence:
95845 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
95846 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
95847 + * Increases kernel attack surface in areas developers
95848 + * previously cared little about ("low importance due
95849 + * to requiring "root" capability")
95850 + * To be removed when this code receives *proper* review
95851 + */
95852 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
95853 + !capable(CAP_SETGID))
95854 + return -EPERM;
95855 +#endif
95856 +
95857 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
95858 if (!ns)
95859 return -ENOMEM;
95860 @@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
95861 if (atomic_read(&current->mm->mm_users) > 1)
95862 return -EINVAL;
95863
95864 - if (current->fs->users != 1)
95865 + if (atomic_read(&current->fs->users) != 1)
95866 return -EINVAL;
95867
95868 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
95869 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
95870 index c8eac43..4b5f08f 100644
95871 --- a/kernel/utsname_sysctl.c
95872 +++ b/kernel/utsname_sysctl.c
95873 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
95874 static int proc_do_uts_string(struct ctl_table *table, int write,
95875 void __user *buffer, size_t *lenp, loff_t *ppos)
95876 {
95877 - struct ctl_table uts_table;
95878 + ctl_table_no_const uts_table;
95879 int r;
95880 memcpy(&uts_table, table, sizeof(uts_table));
95881 uts_table.data = get_uts(table, write);
95882 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
95883 index c3319bd..67efc3c 100644
95884 --- a/kernel/watchdog.c
95885 +++ b/kernel/watchdog.c
95886 @@ -518,7 +518,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
95887 static void watchdog_nmi_disable(unsigned int cpu) { return; }
95888 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
95889
95890 -static struct smp_hotplug_thread watchdog_threads = {
95891 +static struct smp_hotplug_thread watchdog_threads __read_only = {
95892 .store = &softlockup_watchdog,
95893 .thread_should_run = watchdog_should_run,
95894 .thread_fn = watchdog,
95895 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
95896 index 35974ac..43c9e87 100644
95897 --- a/kernel/workqueue.c
95898 +++ b/kernel/workqueue.c
95899 @@ -4576,7 +4576,7 @@ static void rebind_workers(struct worker_pool *pool)
95900 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
95901 worker_flags |= WORKER_REBOUND;
95902 worker_flags &= ~WORKER_UNBOUND;
95903 - ACCESS_ONCE(worker->flags) = worker_flags;
95904 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
95905 }
95906
95907 spin_unlock_irq(&pool->lock);
95908 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
95909 index 7a638aa..20db901 100644
95910 --- a/lib/Kconfig.debug
95911 +++ b/lib/Kconfig.debug
95912 @@ -858,7 +858,7 @@ config DEBUG_MUTEXES
95913
95914 config DEBUG_WW_MUTEX_SLOWPATH
95915 bool "Wait/wound mutex debugging: Slowpath testing"
95916 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
95917 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
95918 select DEBUG_LOCK_ALLOC
95919 select DEBUG_SPINLOCK
95920 select DEBUG_MUTEXES
95921 @@ -871,7 +871,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
95922
95923 config DEBUG_LOCK_ALLOC
95924 bool "Lock debugging: detect incorrect freeing of live locks"
95925 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
95926 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
95927 select DEBUG_SPINLOCK
95928 select DEBUG_MUTEXES
95929 select LOCKDEP
95930 @@ -885,7 +885,7 @@ config DEBUG_LOCK_ALLOC
95931
95932 config PROVE_LOCKING
95933 bool "Lock debugging: prove locking correctness"
95934 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
95935 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
95936 select LOCKDEP
95937 select DEBUG_SPINLOCK
95938 select DEBUG_MUTEXES
95939 @@ -936,7 +936,7 @@ config LOCKDEP
95940
95941 config LOCK_STAT
95942 bool "Lock usage statistics"
95943 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
95944 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
95945 select LOCKDEP
95946 select DEBUG_SPINLOCK
95947 select DEBUG_MUTEXES
95948 @@ -1418,6 +1418,7 @@ config LATENCYTOP
95949 depends on DEBUG_KERNEL
95950 depends on STACKTRACE_SUPPORT
95951 depends on PROC_FS
95952 + depends on !GRKERNSEC_HIDESYM
95953 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
95954 select KALLSYMS
95955 select KALLSYMS_ALL
95956 @@ -1434,7 +1435,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
95957 config DEBUG_STRICT_USER_COPY_CHECKS
95958 bool "Strict user copy size checks"
95959 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
95960 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
95961 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
95962 help
95963 Enabling this option turns a certain set of sanity checks for user
95964 copy operations into compile time failures.
95965 @@ -1554,7 +1555,7 @@ endmenu # runtime tests
95966
95967 config PROVIDE_OHCI1394_DMA_INIT
95968 bool "Remote debugging over FireWire early on boot"
95969 - depends on PCI && X86
95970 + depends on PCI && X86 && !GRKERNSEC
95971 help
95972 If you want to debug problems which hang or crash the kernel early
95973 on boot and the crashing machine has a FireWire port, you can use
95974 diff --git a/lib/Makefile b/lib/Makefile
95975 index ba967a1..2cc869a 100644
95976 --- a/lib/Makefile
95977 +++ b/lib/Makefile
95978 @@ -33,7 +33,6 @@ obj-y += kstrtox.o
95979 obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
95980 obj-$(CONFIG_TEST_MODULE) += test_module.o
95981 obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o
95982 -obj-$(CONFIG_TEST_BPF) += test_bpf.o
95983
95984 ifeq ($(CONFIG_DEBUG_KOBJECT),y)
95985 CFLAGS_kobject.o += -DDEBUG
95986 @@ -54,7 +53,7 @@ obj-$(CONFIG_BTREE) += btree.o
95987 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
95988 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
95989 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
95990 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
95991 +obj-y += list_debug.o
95992 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
95993
95994 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
95995 diff --git a/lib/assoc_array.c b/lib/assoc_array.c
95996 index c0b1007..ae146f0 100644
95997 --- a/lib/assoc_array.c
95998 +++ b/lib/assoc_array.c
95999 @@ -1735,7 +1735,7 @@ ascend_old_tree:
96000 gc_complete:
96001 edit->set[0].to = new_root;
96002 assoc_array_apply_edit(edit);
96003 - edit->array->nr_leaves_on_tree = nr_leaves_on_tree;
96004 + array->nr_leaves_on_tree = nr_leaves_on_tree;
96005 return 0;
96006
96007 enomem:
96008 diff --git a/lib/average.c b/lib/average.c
96009 index 114d1be..ab0350c 100644
96010 --- a/lib/average.c
96011 +++ b/lib/average.c
96012 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
96013 {
96014 unsigned long internal = ACCESS_ONCE(avg->internal);
96015
96016 - ACCESS_ONCE(avg->internal) = internal ?
96017 + ACCESS_ONCE_RW(avg->internal) = internal ?
96018 (((internal << avg->weight) - internal) +
96019 (val << avg->factor)) >> avg->weight :
96020 (val << avg->factor);
96021 diff --git a/lib/bitmap.c b/lib/bitmap.c
96022 index 06f7e4f..f3cf2b0 100644
96023 --- a/lib/bitmap.c
96024 +++ b/lib/bitmap.c
96025 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
96026 {
96027 int c, old_c, totaldigits, ndigits, nchunks, nbits;
96028 u32 chunk;
96029 - const char __user __force *ubuf = (const char __user __force *)buf;
96030 + const char __user *ubuf = (const char __force_user *)buf;
96031
96032 bitmap_zero(maskp, nmaskbits);
96033
96034 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
96035 {
96036 if (!access_ok(VERIFY_READ, ubuf, ulen))
96037 return -EFAULT;
96038 - return __bitmap_parse((const char __force *)ubuf,
96039 + return __bitmap_parse((const char __force_kernel *)ubuf,
96040 ulen, 1, maskp, nmaskbits);
96041
96042 }
96043 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
96044 {
96045 unsigned a, b;
96046 int c, old_c, totaldigits;
96047 - const char __user __force *ubuf = (const char __user __force *)buf;
96048 + const char __user *ubuf = (const char __force_user *)buf;
96049 int exp_digit, in_range;
96050
96051 totaldigits = c = 0;
96052 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
96053 {
96054 if (!access_ok(VERIFY_READ, ubuf, ulen))
96055 return -EFAULT;
96056 - return __bitmap_parselist((const char __force *)ubuf,
96057 + return __bitmap_parselist((const char __force_kernel *)ubuf,
96058 ulen, 1, maskp, nmaskbits);
96059 }
96060 EXPORT_SYMBOL(bitmap_parselist_user);
96061 diff --git a/lib/bug.c b/lib/bug.c
96062 index d1d7c78..b354235 100644
96063 --- a/lib/bug.c
96064 +++ b/lib/bug.c
96065 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
96066 return BUG_TRAP_TYPE_NONE;
96067
96068 bug = find_bug(bugaddr);
96069 + if (!bug)
96070 + return BUG_TRAP_TYPE_NONE;
96071
96072 file = NULL;
96073 line = 0;
96074 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
96075 index 547f7f9..a6d4ba0 100644
96076 --- a/lib/debugobjects.c
96077 +++ b/lib/debugobjects.c
96078 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
96079 if (limit > 4)
96080 return;
96081
96082 - is_on_stack = object_is_on_stack(addr);
96083 + is_on_stack = object_starts_on_stack(addr);
96084 if (is_on_stack == onstack)
96085 return;
96086
96087 diff --git a/lib/div64.c b/lib/div64.c
96088 index 4382ad7..08aa558 100644
96089 --- a/lib/div64.c
96090 +++ b/lib/div64.c
96091 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
96092 EXPORT_SYMBOL(__div64_32);
96093
96094 #ifndef div_s64_rem
96095 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
96096 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
96097 {
96098 u64 quotient;
96099
96100 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
96101 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
96102 */
96103 #ifndef div64_u64
96104 -u64 div64_u64(u64 dividend, u64 divisor)
96105 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
96106 {
96107 u32 high = divisor >> 32;
96108 u64 quot;
96109 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
96110 index 98f2d7e..899da5c 100644
96111 --- a/lib/dma-debug.c
96112 +++ b/lib/dma-debug.c
96113 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
96114
96115 void dma_debug_add_bus(struct bus_type *bus)
96116 {
96117 - struct notifier_block *nb;
96118 + notifier_block_no_const *nb;
96119
96120 if (global_disable)
96121 return;
96122 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
96123
96124 static void check_for_stack(struct device *dev, void *addr)
96125 {
96126 - if (object_is_on_stack(addr))
96127 + if (object_starts_on_stack(addr))
96128 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
96129 "stack [addr=%p]\n", addr);
96130 }
96131 diff --git a/lib/hash.c b/lib/hash.c
96132 index fea973f..386626f 100644
96133 --- a/lib/hash.c
96134 +++ b/lib/hash.c
96135 @@ -14,7 +14,7 @@
96136 #include <linux/hash.h>
96137 #include <linux/cache.h>
96138
96139 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
96140 +static struct fast_hash_ops arch_hash_ops __read_only = {
96141 .hash = jhash,
96142 .hash2 = jhash2,
96143 };
96144 diff --git a/lib/inflate.c b/lib/inflate.c
96145 index 013a761..c28f3fc 100644
96146 --- a/lib/inflate.c
96147 +++ b/lib/inflate.c
96148 @@ -269,7 +269,7 @@ static void free(void *where)
96149 malloc_ptr = free_mem_ptr;
96150 }
96151 #else
96152 -#define malloc(a) kmalloc(a, GFP_KERNEL)
96153 +#define malloc(a) kmalloc((a), GFP_KERNEL)
96154 #define free(a) kfree(a)
96155 #endif
96156
96157 diff --git a/lib/ioremap.c b/lib/ioremap.c
96158 index 0c9216c..863bd89 100644
96159 --- a/lib/ioremap.c
96160 +++ b/lib/ioremap.c
96161 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
96162 unsigned long next;
96163
96164 phys_addr -= addr;
96165 - pmd = pmd_alloc(&init_mm, pud, addr);
96166 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96167 if (!pmd)
96168 return -ENOMEM;
96169 do {
96170 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
96171 unsigned long next;
96172
96173 phys_addr -= addr;
96174 - pud = pud_alloc(&init_mm, pgd, addr);
96175 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
96176 if (!pud)
96177 return -ENOMEM;
96178 do {
96179 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
96180 index bd2bea9..6b3c95e 100644
96181 --- a/lib/is_single_threaded.c
96182 +++ b/lib/is_single_threaded.c
96183 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
96184 struct task_struct *p, *t;
96185 bool ret;
96186
96187 + if (!mm)
96188 + return true;
96189 +
96190 if (atomic_read(&task->signal->live) != 1)
96191 return false;
96192
96193 diff --git a/lib/kobject.c b/lib/kobject.c
96194 index 58751bb..93a1853 100644
96195 --- a/lib/kobject.c
96196 +++ b/lib/kobject.c
96197 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
96198
96199
96200 static DEFINE_SPINLOCK(kobj_ns_type_lock);
96201 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
96202 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
96203
96204 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
96205 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
96206 {
96207 enum kobj_ns_type type = ops->type;
96208 int error;
96209 diff --git a/lib/list_debug.c b/lib/list_debug.c
96210 index c24c2f7..f0296f4 100644
96211 --- a/lib/list_debug.c
96212 +++ b/lib/list_debug.c
96213 @@ -11,7 +11,9 @@
96214 #include <linux/bug.h>
96215 #include <linux/kernel.h>
96216 #include <linux/rculist.h>
96217 +#include <linux/mm.h>
96218
96219 +#ifdef CONFIG_DEBUG_LIST
96220 /*
96221 * Insert a new entry between two known consecutive entries.
96222 *
96223 @@ -19,21 +21,40 @@
96224 * the prev/next entries already!
96225 */
96226
96227 +static bool __list_add_debug(struct list_head *new,
96228 + struct list_head *prev,
96229 + struct list_head *next)
96230 +{
96231 + if (unlikely(next->prev != prev)) {
96232 + printk(KERN_ERR "list_add corruption. next->prev should be "
96233 + "prev (%p), but was %p. (next=%p).\n",
96234 + prev, next->prev, next);
96235 + BUG();
96236 + return false;
96237 + }
96238 + if (unlikely(prev->next != next)) {
96239 + printk(KERN_ERR "list_add corruption. prev->next should be "
96240 + "next (%p), but was %p. (prev=%p).\n",
96241 + next, prev->next, prev);
96242 + BUG();
96243 + return false;
96244 + }
96245 + if (unlikely(new == prev || new == next)) {
96246 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
96247 + new, prev, next);
96248 + BUG();
96249 + return false;
96250 + }
96251 + return true;
96252 +}
96253 +
96254 void __list_add(struct list_head *new,
96255 - struct list_head *prev,
96256 - struct list_head *next)
96257 + struct list_head *prev,
96258 + struct list_head *next)
96259 {
96260 - WARN(next->prev != prev,
96261 - "list_add corruption. next->prev should be "
96262 - "prev (%p), but was %p. (next=%p).\n",
96263 - prev, next->prev, next);
96264 - WARN(prev->next != next,
96265 - "list_add corruption. prev->next should be "
96266 - "next (%p), but was %p. (prev=%p).\n",
96267 - next, prev->next, prev);
96268 - WARN(new == prev || new == next,
96269 - "list_add double add: new=%p, prev=%p, next=%p.\n",
96270 - new, prev, next);
96271 + if (!__list_add_debug(new, prev, next))
96272 + return;
96273 +
96274 next->prev = new;
96275 new->next = next;
96276 new->prev = prev;
96277 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
96278 }
96279 EXPORT_SYMBOL(__list_add);
96280
96281 -void __list_del_entry(struct list_head *entry)
96282 +static bool __list_del_entry_debug(struct list_head *entry)
96283 {
96284 struct list_head *prev, *next;
96285
96286 prev = entry->prev;
96287 next = entry->next;
96288
96289 - if (WARN(next == LIST_POISON1,
96290 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
96291 - entry, LIST_POISON1) ||
96292 - WARN(prev == LIST_POISON2,
96293 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
96294 - entry, LIST_POISON2) ||
96295 - WARN(prev->next != entry,
96296 - "list_del corruption. prev->next should be %p, "
96297 - "but was %p\n", entry, prev->next) ||
96298 - WARN(next->prev != entry,
96299 - "list_del corruption. next->prev should be %p, "
96300 - "but was %p\n", entry, next->prev))
96301 + if (unlikely(next == LIST_POISON1)) {
96302 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
96303 + entry, LIST_POISON1);
96304 + BUG();
96305 + return false;
96306 + }
96307 + if (unlikely(prev == LIST_POISON2)) {
96308 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
96309 + entry, LIST_POISON2);
96310 + BUG();
96311 + return false;
96312 + }
96313 + if (unlikely(entry->prev->next != entry)) {
96314 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
96315 + "but was %p\n", entry, prev->next);
96316 + BUG();
96317 + return false;
96318 + }
96319 + if (unlikely(entry->next->prev != entry)) {
96320 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
96321 + "but was %p\n", entry, next->prev);
96322 + BUG();
96323 + return false;
96324 + }
96325 + return true;
96326 +}
96327 +
96328 +void __list_del_entry(struct list_head *entry)
96329 +{
96330 + if (!__list_del_entry_debug(entry))
96331 return;
96332
96333 - __list_del(prev, next);
96334 + __list_del(entry->prev, entry->next);
96335 }
96336 EXPORT_SYMBOL(__list_del_entry);
96337
96338 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
96339 void __list_add_rcu(struct list_head *new,
96340 struct list_head *prev, struct list_head *next)
96341 {
96342 - WARN(next->prev != prev,
96343 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
96344 - prev, next->prev, next);
96345 - WARN(prev->next != next,
96346 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
96347 - next, prev->next, prev);
96348 + if (!__list_add_debug(new, prev, next))
96349 + return;
96350 +
96351 new->next = next;
96352 new->prev = prev;
96353 rcu_assign_pointer(list_next_rcu(prev), new);
96354 next->prev = new;
96355 }
96356 EXPORT_SYMBOL(__list_add_rcu);
96357 +#endif
96358 +
96359 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
96360 +{
96361 +#ifdef CONFIG_DEBUG_LIST
96362 + if (!__list_add_debug(new, prev, next))
96363 + return;
96364 +#endif
96365 +
96366 + pax_open_kernel();
96367 + next->prev = new;
96368 + new->next = next;
96369 + new->prev = prev;
96370 + prev->next = new;
96371 + pax_close_kernel();
96372 +}
96373 +EXPORT_SYMBOL(__pax_list_add);
96374 +
96375 +void pax_list_del(struct list_head *entry)
96376 +{
96377 +#ifdef CONFIG_DEBUG_LIST
96378 + if (!__list_del_entry_debug(entry))
96379 + return;
96380 +#endif
96381 +
96382 + pax_open_kernel();
96383 + __list_del(entry->prev, entry->next);
96384 + entry->next = LIST_POISON1;
96385 + entry->prev = LIST_POISON2;
96386 + pax_close_kernel();
96387 +}
96388 +EXPORT_SYMBOL(pax_list_del);
96389 +
96390 +void pax_list_del_init(struct list_head *entry)
96391 +{
96392 + pax_open_kernel();
96393 + __list_del(entry->prev, entry->next);
96394 + INIT_LIST_HEAD(entry);
96395 + pax_close_kernel();
96396 +}
96397 +EXPORT_SYMBOL(pax_list_del_init);
96398 +
96399 +void __pax_list_add_rcu(struct list_head *new,
96400 + struct list_head *prev, struct list_head *next)
96401 +{
96402 +#ifdef CONFIG_DEBUG_LIST
96403 + if (!__list_add_debug(new, prev, next))
96404 + return;
96405 +#endif
96406 +
96407 + pax_open_kernel();
96408 + new->next = next;
96409 + new->prev = prev;
96410 + rcu_assign_pointer(list_next_rcu(prev), new);
96411 + next->prev = new;
96412 + pax_close_kernel();
96413 +}
96414 +EXPORT_SYMBOL(__pax_list_add_rcu);
96415 +
96416 +void pax_list_del_rcu(struct list_head *entry)
96417 +{
96418 +#ifdef CONFIG_DEBUG_LIST
96419 + if (!__list_del_entry_debug(entry))
96420 + return;
96421 +#endif
96422 +
96423 + pax_open_kernel();
96424 + __list_del(entry->prev, entry->next);
96425 + entry->next = LIST_POISON1;
96426 + entry->prev = LIST_POISON2;
96427 + pax_close_kernel();
96428 +}
96429 +EXPORT_SYMBOL(pax_list_del_rcu);
96430 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
96431 index 963b703..438bc51 100644
96432 --- a/lib/percpu-refcount.c
96433 +++ b/lib/percpu-refcount.c
96434 @@ -29,7 +29,7 @@
96435 * can't hit 0 before we've added up all the percpu refs.
96436 */
96437
96438 -#define PCPU_COUNT_BIAS (1U << 31)
96439 +#define PCPU_COUNT_BIAS (1U << 30)
96440
96441 /**
96442 * percpu_ref_init - initialize a percpu refcount
96443 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
96444 index 3291a8e..346a91e 100644
96445 --- a/lib/radix-tree.c
96446 +++ b/lib/radix-tree.c
96447 @@ -67,7 +67,7 @@ struct radix_tree_preload {
96448 int nr;
96449 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
96450 };
96451 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
96452 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
96453
96454 static inline void *ptr_to_indirect(void *ptr)
96455 {
96456 diff --git a/lib/random32.c b/lib/random32.c
96457 index fa5da61..35fe9af 100644
96458 --- a/lib/random32.c
96459 +++ b/lib/random32.c
96460 @@ -42,7 +42,7 @@
96461 static void __init prandom_state_selftest(void);
96462 #endif
96463
96464 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
96465 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
96466
96467 /**
96468 * prandom_u32_state - seeded pseudo-random number generator.
96469 diff --git a/lib/rbtree.c b/lib/rbtree.c
96470 index 65f4eff..2cfa167 100644
96471 --- a/lib/rbtree.c
96472 +++ b/lib/rbtree.c
96473 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
96474 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
96475
96476 static const struct rb_augment_callbacks dummy_callbacks = {
96477 - dummy_propagate, dummy_copy, dummy_rotate
96478 + .propagate = dummy_propagate,
96479 + .copy = dummy_copy,
96480 + .rotate = dummy_rotate
96481 };
96482
96483 void rb_insert_color(struct rb_node *node, struct rb_root *root)
96484 diff --git a/lib/show_mem.c b/lib/show_mem.c
96485 index 0922579..9d7adb9 100644
96486 --- a/lib/show_mem.c
96487 +++ b/lib/show_mem.c
96488 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
96489 quicklist_total_size());
96490 #endif
96491 #ifdef CONFIG_MEMORY_FAILURE
96492 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
96493 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
96494 #endif
96495 }
96496 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
96497 index bb2b201..46abaf9 100644
96498 --- a/lib/strncpy_from_user.c
96499 +++ b/lib/strncpy_from_user.c
96500 @@ -21,7 +21,7 @@
96501 */
96502 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
96503 {
96504 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96505 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96506 long res = 0;
96507
96508 /*
96509 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
96510 index a28df52..3d55877 100644
96511 --- a/lib/strnlen_user.c
96512 +++ b/lib/strnlen_user.c
96513 @@ -26,7 +26,7 @@
96514 */
96515 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
96516 {
96517 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96518 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96519 long align, res = 0;
96520 unsigned long c;
96521
96522 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
96523 index 4abda07..b9d3765 100644
96524 --- a/lib/swiotlb.c
96525 +++ b/lib/swiotlb.c
96526 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
96527
96528 void
96529 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
96530 - dma_addr_t dev_addr)
96531 + dma_addr_t dev_addr, struct dma_attrs *attrs)
96532 {
96533 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
96534
96535 diff --git a/lib/test_bpf.c b/lib/test_bpf.c
96536 deleted file mode 100644
96537 index c579e0f..0000000
96538 --- a/lib/test_bpf.c
96539 +++ /dev/null
96540 @@ -1,1929 +0,0 @@
96541 -/*
96542 - * Testsuite for BPF interpreter and BPF JIT compiler
96543 - *
96544 - * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
96545 - *
96546 - * This program is free software; you can redistribute it and/or
96547 - * modify it under the terms of version 2 of the GNU General Public
96548 - * License as published by the Free Software Foundation.
96549 - *
96550 - * This program is distributed in the hope that it will be useful, but
96551 - * WITHOUT ANY WARRANTY; without even the implied warranty of
96552 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
96553 - * General Public License for more details.
96554 - */
96555 -
96556 -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
96557 -
96558 -#include <linux/init.h>
96559 -#include <linux/module.h>
96560 -#include <linux/filter.h>
96561 -#include <linux/skbuff.h>
96562 -#include <linux/netdevice.h>
96563 -#include <linux/if_vlan.h>
96564 -
96565 -/* General test specific settings */
96566 -#define MAX_SUBTESTS 3
96567 -#define MAX_TESTRUNS 10000
96568 -#define MAX_DATA 128
96569 -#define MAX_INSNS 512
96570 -#define MAX_K 0xffffFFFF
96571 -
96572 -/* Few constants used to init test 'skb' */
96573 -#define SKB_TYPE 3
96574 -#define SKB_MARK 0x1234aaaa
96575 -#define SKB_HASH 0x1234aaab
96576 -#define SKB_QUEUE_MAP 123
96577 -#define SKB_VLAN_TCI 0xffff
96578 -#define SKB_DEV_IFINDEX 577
96579 -#define SKB_DEV_TYPE 588
96580 -
96581 -/* Redefine REGs to make tests less verbose */
96582 -#define R0 BPF_REG_0
96583 -#define R1 BPF_REG_1
96584 -#define R2 BPF_REG_2
96585 -#define R3 BPF_REG_3
96586 -#define R4 BPF_REG_4
96587 -#define R5 BPF_REG_5
96588 -#define R6 BPF_REG_6
96589 -#define R7 BPF_REG_7
96590 -#define R8 BPF_REG_8
96591 -#define R9 BPF_REG_9
96592 -#define R10 BPF_REG_10
96593 -
96594 -/* Flags that can be passed to test cases */
96595 -#define FLAG_NO_DATA BIT(0)
96596 -#define FLAG_EXPECTED_FAIL BIT(1)
96597 -
96598 -enum {
96599 - CLASSIC = BIT(6), /* Old BPF instructions only. */
96600 - INTERNAL = BIT(7), /* Extended instruction set. */
96601 -};
96602 -
96603 -#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
96604 -
96605 -struct bpf_test {
96606 - const char *descr;
96607 - union {
96608 - struct sock_filter insns[MAX_INSNS];
96609 - struct sock_filter_int insns_int[MAX_INSNS];
96610 - } u;
96611 - __u8 aux;
96612 - __u8 data[MAX_DATA];
96613 - struct {
96614 - int data_size;
96615 - __u32 result;
96616 - } test[MAX_SUBTESTS];
96617 -};
96618 -
96619 -static struct bpf_test tests[] = {
96620 - {
96621 - "TAX",
96622 - .u.insns = {
96623 - BPF_STMT(BPF_LD | BPF_IMM, 1),
96624 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96625 - BPF_STMT(BPF_LD | BPF_IMM, 2),
96626 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96627 - BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
96628 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96629 - BPF_STMT(BPF_LD | BPF_LEN, 0),
96630 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96631 - BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
96632 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
96633 - BPF_STMT(BPF_RET | BPF_A, 0)
96634 - },
96635 - CLASSIC,
96636 - { 10, 20, 30, 40, 50 },
96637 - { { 2, 10 }, { 3, 20 }, { 4, 30 } },
96638 - },
96639 - {
96640 - "TXA",
96641 - .u.insns = {
96642 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
96643 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
96644 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96645 - BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
96646 - },
96647 - CLASSIC,
96648 - { 10, 20, 30, 40, 50 },
96649 - { { 1, 2 }, { 3, 6 }, { 4, 8 } },
96650 - },
96651 - {
96652 - "ADD_SUB_MUL_K",
96653 - .u.insns = {
96654 - BPF_STMT(BPF_LD | BPF_IMM, 1),
96655 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
96656 - BPF_STMT(BPF_LDX | BPF_IMM, 3),
96657 - BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
96658 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
96659 - BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
96660 - BPF_STMT(BPF_RET | BPF_A, 0)
96661 - },
96662 - CLASSIC | FLAG_NO_DATA,
96663 - { },
96664 - { { 0, 0xfffffffd } }
96665 - },
96666 - {
96667 - "DIV_KX",
96668 - .u.insns = {
96669 - BPF_STMT(BPF_LD | BPF_IMM, 8),
96670 - BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
96671 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96672 - BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
96673 - BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
96674 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96675 - BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
96676 - BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
96677 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96678 - BPF_STMT(BPF_RET | BPF_A, 0)
96679 - },
96680 - CLASSIC | FLAG_NO_DATA,
96681 - { },
96682 - { { 0, 0x40000001 } }
96683 - },
96684 - {
96685 - "AND_OR_LSH_K",
96686 - .u.insns = {
96687 - BPF_STMT(BPF_LD | BPF_IMM, 0xff),
96688 - BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
96689 - BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
96690 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96691 - BPF_STMT(BPF_LD | BPF_IMM, 0xf),
96692 - BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
96693 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96694 - BPF_STMT(BPF_RET | BPF_A, 0)
96695 - },
96696 - CLASSIC | FLAG_NO_DATA,
96697 - { },
96698 - { { 0, 0x800000ff }, { 1, 0x800000ff } },
96699 - },
96700 - {
96701 - "LD_IMM_0",
96702 - .u.insns = {
96703 - BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
96704 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
96705 - BPF_STMT(BPF_RET | BPF_K, 0),
96706 - BPF_STMT(BPF_RET | BPF_K, 1),
96707 - },
96708 - CLASSIC,
96709 - { },
96710 - { { 1, 1 } },
96711 - },
96712 - {
96713 - "LD_IND",
96714 - .u.insns = {
96715 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
96716 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
96717 - BPF_STMT(BPF_RET | BPF_K, 1)
96718 - },
96719 - CLASSIC,
96720 - { },
96721 - { { 1, 0 }, { 10, 0 }, { 60, 0 } },
96722 - },
96723 - {
96724 - "LD_ABS",
96725 - .u.insns = {
96726 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
96727 - BPF_STMT(BPF_RET | BPF_K, 1)
96728 - },
96729 - CLASSIC,
96730 - { },
96731 - { { 1, 0 }, { 10, 0 }, { 60, 0 } },
96732 - },
96733 - {
96734 - "LD_ABS_LL",
96735 - .u.insns = {
96736 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
96737 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96738 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
96739 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96740 - BPF_STMT(BPF_RET | BPF_A, 0)
96741 - },
96742 - CLASSIC,
96743 - { 1, 2, 3 },
96744 - { { 1, 0 }, { 2, 3 } },
96745 - },
96746 - {
96747 - "LD_IND_LL",
96748 - .u.insns = {
96749 - BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
96750 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
96751 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96752 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96753 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
96754 - BPF_STMT(BPF_RET | BPF_A, 0)
96755 - },
96756 - CLASSIC,
96757 - { 1, 2, 3, 0xff },
96758 - { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
96759 - },
96760 - {
96761 - "LD_ABS_NET",
96762 - .u.insns = {
96763 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
96764 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96765 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
96766 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96767 - BPF_STMT(BPF_RET | BPF_A, 0)
96768 - },
96769 - CLASSIC,
96770 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
96771 - { { 15, 0 }, { 16, 3 } },
96772 - },
96773 - {
96774 - "LD_IND_NET",
96775 - .u.insns = {
96776 - BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
96777 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
96778 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96779 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96780 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
96781 - BPF_STMT(BPF_RET | BPF_A, 0)
96782 - },
96783 - CLASSIC,
96784 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
96785 - { { 14, 0 }, { 15, 1 }, { 17, 3 } },
96786 - },
96787 - {
96788 - "LD_PKTTYPE",
96789 - .u.insns = {
96790 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96791 - SKF_AD_OFF + SKF_AD_PKTTYPE),
96792 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
96793 - BPF_STMT(BPF_RET | BPF_K, 1),
96794 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96795 - SKF_AD_OFF + SKF_AD_PKTTYPE),
96796 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
96797 - BPF_STMT(BPF_RET | BPF_K, 1),
96798 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96799 - SKF_AD_OFF + SKF_AD_PKTTYPE),
96800 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
96801 - BPF_STMT(BPF_RET | BPF_K, 1),
96802 - BPF_STMT(BPF_RET | BPF_A, 0)
96803 - },
96804 - CLASSIC,
96805 - { },
96806 - { { 1, 3 }, { 10, 3 } },
96807 - },
96808 - {
96809 - "LD_MARK",
96810 - .u.insns = {
96811 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96812 - SKF_AD_OFF + SKF_AD_MARK),
96813 - BPF_STMT(BPF_RET | BPF_A, 0)
96814 - },
96815 - CLASSIC,
96816 - { },
96817 - { { 1, SKB_MARK}, { 10, SKB_MARK} },
96818 - },
96819 - {
96820 - "LD_RXHASH",
96821 - .u.insns = {
96822 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96823 - SKF_AD_OFF + SKF_AD_RXHASH),
96824 - BPF_STMT(BPF_RET | BPF_A, 0)
96825 - },
96826 - CLASSIC,
96827 - { },
96828 - { { 1, SKB_HASH}, { 10, SKB_HASH} },
96829 - },
96830 - {
96831 - "LD_QUEUE",
96832 - .u.insns = {
96833 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96834 - SKF_AD_OFF + SKF_AD_QUEUE),
96835 - BPF_STMT(BPF_RET | BPF_A, 0)
96836 - },
96837 - CLASSIC,
96838 - { },
96839 - { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
96840 - },
96841 - {
96842 - "LD_PROTOCOL",
96843 - .u.insns = {
96844 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
96845 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
96846 - BPF_STMT(BPF_RET | BPF_K, 0),
96847 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96848 - SKF_AD_OFF + SKF_AD_PROTOCOL),
96849 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96850 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
96851 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
96852 - BPF_STMT(BPF_RET | BPF_K, 0),
96853 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
96854 - BPF_STMT(BPF_RET | BPF_A, 0)
96855 - },
96856 - CLASSIC,
96857 - { 10, 20, 30 },
96858 - { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
96859 - },
96860 - {
96861 - "LD_VLAN_TAG",
96862 - .u.insns = {
96863 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96864 - SKF_AD_OFF + SKF_AD_VLAN_TAG),
96865 - BPF_STMT(BPF_RET | BPF_A, 0)
96866 - },
96867 - CLASSIC,
96868 - { },
96869 - {
96870 - { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
96871 - { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
96872 - },
96873 - },
96874 - {
96875 - "LD_VLAN_TAG_PRESENT",
96876 - .u.insns = {
96877 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96878 - SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
96879 - BPF_STMT(BPF_RET | BPF_A, 0)
96880 - },
96881 - CLASSIC,
96882 - { },
96883 - {
96884 - { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
96885 - { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
96886 - },
96887 - },
96888 - {
96889 - "LD_IFINDEX",
96890 - .u.insns = {
96891 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96892 - SKF_AD_OFF + SKF_AD_IFINDEX),
96893 - BPF_STMT(BPF_RET | BPF_A, 0)
96894 - },
96895 - CLASSIC,
96896 - { },
96897 - { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
96898 - },
96899 - {
96900 - "LD_HATYPE",
96901 - .u.insns = {
96902 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96903 - SKF_AD_OFF + SKF_AD_HATYPE),
96904 - BPF_STMT(BPF_RET | BPF_A, 0)
96905 - },
96906 - CLASSIC,
96907 - { },
96908 - { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
96909 - },
96910 - {
96911 - "LD_CPU",
96912 - .u.insns = {
96913 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96914 - SKF_AD_OFF + SKF_AD_CPU),
96915 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96916 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96917 - SKF_AD_OFF + SKF_AD_CPU),
96918 - BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
96919 - BPF_STMT(BPF_RET | BPF_A, 0)
96920 - },
96921 - CLASSIC,
96922 - { },
96923 - { { 1, 0 }, { 10, 0 } },
96924 - },
96925 - {
96926 - "LD_NLATTR",
96927 - .u.insns = {
96928 - BPF_STMT(BPF_LDX | BPF_IMM, 2),
96929 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
96930 - BPF_STMT(BPF_LDX | BPF_IMM, 3),
96931 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96932 - SKF_AD_OFF + SKF_AD_NLATTR),
96933 - BPF_STMT(BPF_RET | BPF_A, 0)
96934 - },
96935 - CLASSIC,
96936 -#ifdef __BIG_ENDIAN
96937 - { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
96938 -#else
96939 - { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
96940 -#endif
96941 - { { 4, 0 }, { 20, 6 } },
96942 - },
96943 - {
96944 - "LD_NLATTR_NEST",
96945 - .u.insns = {
96946 - BPF_STMT(BPF_LD | BPF_IMM, 2),
96947 - BPF_STMT(BPF_LDX | BPF_IMM, 3),
96948 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96949 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
96950 - BPF_STMT(BPF_LD | BPF_IMM, 2),
96951 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96952 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
96953 - BPF_STMT(BPF_LD | BPF_IMM, 2),
96954 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96955 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
96956 - BPF_STMT(BPF_LD | BPF_IMM, 2),
96957 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96958 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
96959 - BPF_STMT(BPF_LD | BPF_IMM, 2),
96960 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96961 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
96962 - BPF_STMT(BPF_LD | BPF_IMM, 2),
96963 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96964 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
96965 - BPF_STMT(BPF_LD | BPF_IMM, 2),
96966 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96967 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
96968 - BPF_STMT(BPF_LD | BPF_IMM, 2),
96969 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96970 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
96971 - BPF_STMT(BPF_RET | BPF_A, 0)
96972 - },
96973 - CLASSIC,
96974 -#ifdef __BIG_ENDIAN
96975 - { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
96976 -#else
96977 - { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
96978 -#endif
96979 - { { 4, 0 }, { 20, 10 } },
96980 - },
96981 - {
96982 - "LD_PAYLOAD_OFF",
96983 - .u.insns = {
96984 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96985 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
96986 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96987 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
96988 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96989 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
96990 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96991 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
96992 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
96993 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
96994 - BPF_STMT(BPF_RET | BPF_A, 0)
96995 - },
96996 - CLASSIC,
96997 - /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
96998 - * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
96999 - * id 9737, seq 1, length 64
97000 - */
97001 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97002 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97003 - 0x08, 0x00,
97004 - 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
97005 - 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
97006 - { { 30, 0 }, { 100, 42 } },
97007 - },
97008 - {
97009 - "LD_ANC_XOR",
97010 - .u.insns = {
97011 - BPF_STMT(BPF_LD | BPF_IMM, 10),
97012 - BPF_STMT(BPF_LDX | BPF_IMM, 300),
97013 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97014 - SKF_AD_OFF + SKF_AD_ALU_XOR_X),
97015 - BPF_STMT(BPF_RET | BPF_A, 0)
97016 - },
97017 - CLASSIC,
97018 - { },
97019 - { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
97020 - },
97021 - {
97022 - "SPILL_FILL",
97023 - .u.insns = {
97024 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97025 - BPF_STMT(BPF_LD | BPF_IMM, 2),
97026 - BPF_STMT(BPF_ALU | BPF_RSH, 1),
97027 - BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
97028 - BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
97029 - BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
97030 - BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
97031 - BPF_STMT(BPF_STX, 15), /* M3 = len */
97032 - BPF_STMT(BPF_LDX | BPF_MEM, 1),
97033 - BPF_STMT(BPF_LD | BPF_MEM, 2),
97034 - BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
97035 - BPF_STMT(BPF_LDX | BPF_MEM, 15),
97036 - BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
97037 - BPF_STMT(BPF_RET | BPF_A, 0)
97038 - },
97039 - CLASSIC,
97040 - { },
97041 - { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
97042 - },
97043 - {
97044 - "JEQ",
97045 - .u.insns = {
97046 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97047 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
97048 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
97049 - BPF_STMT(BPF_RET | BPF_K, 1),
97050 - BPF_STMT(BPF_RET | BPF_K, MAX_K)
97051 - },
97052 - CLASSIC,
97053 - { 3, 3, 3, 3, 3 },
97054 - { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
97055 - },
97056 - {
97057 - "JGT",
97058 - .u.insns = {
97059 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97060 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
97061 - BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
97062 - BPF_STMT(BPF_RET | BPF_K, 1),
97063 - BPF_STMT(BPF_RET | BPF_K, MAX_K)
97064 - },
97065 - CLASSIC,
97066 - { 4, 4, 4, 3, 3 },
97067 - { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
97068 - },
97069 - {
97070 - "JGE",
97071 - .u.insns = {
97072 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97073 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
97074 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
97075 - BPF_STMT(BPF_RET | BPF_K, 10),
97076 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
97077 - BPF_STMT(BPF_RET | BPF_K, 20),
97078 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
97079 - BPF_STMT(BPF_RET | BPF_K, 30),
97080 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
97081 - BPF_STMT(BPF_RET | BPF_K, 40),
97082 - BPF_STMT(BPF_RET | BPF_K, MAX_K)
97083 - },
97084 - CLASSIC,
97085 - { 1, 2, 3, 4, 5 },
97086 - { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
97087 - },
97088 - {
97089 - "JSET",
97090 - .u.insns = {
97091 - BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
97092 - BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
97093 - BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
97094 - BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
97095 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97096 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
97097 - BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
97098 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
97099 - BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
97100 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
97101 - BPF_STMT(BPF_RET | BPF_K, 10),
97102 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
97103 - BPF_STMT(BPF_RET | BPF_K, 20),
97104 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97105 - BPF_STMT(BPF_RET | BPF_K, 30),
97106 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97107 - BPF_STMT(BPF_RET | BPF_K, 30),
97108 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97109 - BPF_STMT(BPF_RET | BPF_K, 30),
97110 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97111 - BPF_STMT(BPF_RET | BPF_K, 30),
97112 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97113 - BPF_STMT(BPF_RET | BPF_K, 30),
97114 - BPF_STMT(BPF_RET | BPF_K, MAX_K)
97115 - },
97116 - CLASSIC,
97117 - { 0, 0xAA, 0x55, 1 },
97118 - { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
97119 - },
97120 - {
97121 - "tcpdump port 22",
97122 - .u.insns = {
97123 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
97124 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
97125 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
97126 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
97127 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
97128 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
97129 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
97130 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
97131 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
97132 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
97133 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
97134 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
97135 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
97136 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
97137 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
97138 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
97139 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
97140 - BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
97141 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
97142 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
97143 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
97144 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
97145 - BPF_STMT(BPF_RET | BPF_K, 0xffff),
97146 - BPF_STMT(BPF_RET | BPF_K, 0),
97147 - },
97148 - CLASSIC,
97149 - /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
97150 - * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
97151 - * seq 1305692979:1305693027, ack 3650467037, win 65535,
97152 - * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
97153 - */
97154 - { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
97155 - 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
97156 - 0x08, 0x00,
97157 - 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
97158 - 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
97159 - 0x0a, 0x01, 0x01, 0x95, /* ip src */
97160 - 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
97161 - 0xc2, 0x24,
97162 - 0x00, 0x16 /* dst port */ },
97163 - { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
97164 - },
97165 - {
97166 - "tcpdump complex",
97167 - .u.insns = {
97168 - /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
97169 - * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
97170 - * (len > 115 or len < 30000000000)' -d
97171 - */
97172 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
97173 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
97174 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
97175 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
97176 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
97177 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
97178 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
97179 - BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
97180 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
97181 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
97182 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
97183 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
97184 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
97185 - BPF_STMT(BPF_ST, 1),
97186 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
97187 - BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
97188 - BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
97189 - BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
97190 - BPF_STMT(BPF_LD | BPF_MEM, 1),
97191 - BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
97192 - BPF_STMT(BPF_ST, 5),
97193 - BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
97194 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
97195 - BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
97196 - BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
97197 - BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
97198 - BPF_STMT(BPF_LD | BPF_MEM, 5),
97199 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
97200 - BPF_STMT(BPF_LD | BPF_LEN, 0),
97201 - BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
97202 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
97203 - BPF_STMT(BPF_RET | BPF_K, 0xffff),
97204 - BPF_STMT(BPF_RET | BPF_K, 0),
97205 - },
97206 - CLASSIC,
97207 - { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
97208 - 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
97209 - 0x08, 0x00,
97210 - 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
97211 - 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
97212 - 0x0a, 0x01, 0x01, 0x95, /* ip src */
97213 - 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
97214 - 0xc2, 0x24,
97215 - 0x00, 0x16 /* dst port */ },
97216 - { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
97217 - },
97218 - {
97219 - "RET_A",
97220 - .u.insns = {
97221 - /* check that unitialized X and A contain zeros */
97222 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
97223 - BPF_STMT(BPF_RET | BPF_A, 0)
97224 - },
97225 - CLASSIC,
97226 - { },
97227 - { {1, 0}, {2, 0} },
97228 - },
97229 - {
97230 - "INT: ADD trivial",
97231 - .u.insns_int = {
97232 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
97233 - BPF_ALU64_IMM(BPF_ADD, R1, 2),
97234 - BPF_ALU64_IMM(BPF_MOV, R2, 3),
97235 - BPF_ALU64_REG(BPF_SUB, R1, R2),
97236 - BPF_ALU64_IMM(BPF_ADD, R1, -1),
97237 - BPF_ALU64_IMM(BPF_MUL, R1, 3),
97238 - BPF_ALU64_REG(BPF_MOV, R0, R1),
97239 - BPF_EXIT_INSN(),
97240 - },
97241 - INTERNAL,
97242 - { },
97243 - { { 0, 0xfffffffd } }
97244 - },
97245 - {
97246 - "INT: MUL_X",
97247 - .u.insns_int = {
97248 - BPF_ALU64_IMM(BPF_MOV, R0, -1),
97249 - BPF_ALU64_IMM(BPF_MOV, R1, -1),
97250 - BPF_ALU64_IMM(BPF_MOV, R2, 3),
97251 - BPF_ALU64_REG(BPF_MUL, R1, R2),
97252 - BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
97253 - BPF_EXIT_INSN(),
97254 - BPF_ALU64_IMM(BPF_MOV, R0, 1),
97255 - BPF_EXIT_INSN(),
97256 - },
97257 - INTERNAL,
97258 - { },
97259 - { { 0, 1 } }
97260 - },
97261 - {
97262 - "INT: MUL_X2",
97263 - .u.insns_int = {
97264 - BPF_ALU32_IMM(BPF_MOV, R0, -1),
97265 - BPF_ALU32_IMM(BPF_MOV, R1, -1),
97266 - BPF_ALU32_IMM(BPF_MOV, R2, 3),
97267 - BPF_ALU64_REG(BPF_MUL, R1, R2),
97268 - BPF_ALU64_IMM(BPF_RSH, R1, 8),
97269 - BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
97270 - BPF_EXIT_INSN(),
97271 - BPF_ALU32_IMM(BPF_MOV, R0, 1),
97272 - BPF_EXIT_INSN(),
97273 - },
97274 - INTERNAL,
97275 - { },
97276 - { { 0, 1 } }
97277 - },
97278 - {
97279 - "INT: MUL32_X",
97280 - .u.insns_int = {
97281 - BPF_ALU32_IMM(BPF_MOV, R0, -1),
97282 - BPF_ALU64_IMM(BPF_MOV, R1, -1),
97283 - BPF_ALU32_IMM(BPF_MOV, R2, 3),
97284 - BPF_ALU32_REG(BPF_MUL, R1, R2),
97285 - BPF_ALU64_IMM(BPF_RSH, R1, 8),
97286 - BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
97287 - BPF_EXIT_INSN(),
97288 - BPF_ALU32_IMM(BPF_MOV, R0, 1),
97289 - BPF_EXIT_INSN(),
97290 - },
97291 - INTERNAL,
97292 - { },
97293 - { { 0, 1 } }
97294 - },
97295 - {
97296 - /* Have to test all register combinations, since
97297 - * JITing of different registers will produce
97298 - * different asm code.
97299 - */
97300 - "INT: ADD 64-bit",
97301 - .u.insns_int = {
97302 - BPF_ALU64_IMM(BPF_MOV, R0, 0),
97303 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
97304 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
97305 - BPF_ALU64_IMM(BPF_MOV, R3, 3),
97306 - BPF_ALU64_IMM(BPF_MOV, R4, 4),
97307 - BPF_ALU64_IMM(BPF_MOV, R5, 5),
97308 - BPF_ALU64_IMM(BPF_MOV, R6, 6),
97309 - BPF_ALU64_IMM(BPF_MOV, R7, 7),
97310 - BPF_ALU64_IMM(BPF_MOV, R8, 8),
97311 - BPF_ALU64_IMM(BPF_MOV, R9, 9),
97312 - BPF_ALU64_IMM(BPF_ADD, R0, 20),
97313 - BPF_ALU64_IMM(BPF_ADD, R1, 20),
97314 - BPF_ALU64_IMM(BPF_ADD, R2, 20),
97315 - BPF_ALU64_IMM(BPF_ADD, R3, 20),
97316 - BPF_ALU64_IMM(BPF_ADD, R4, 20),
97317 - BPF_ALU64_IMM(BPF_ADD, R5, 20),
97318 - BPF_ALU64_IMM(BPF_ADD, R6, 20),
97319 - BPF_ALU64_IMM(BPF_ADD, R7, 20),
97320 - BPF_ALU64_IMM(BPF_ADD, R8, 20),
97321 - BPF_ALU64_IMM(BPF_ADD, R9, 20),
97322 - BPF_ALU64_IMM(BPF_SUB, R0, 10),
97323 - BPF_ALU64_IMM(BPF_SUB, R1, 10),
97324 - BPF_ALU64_IMM(BPF_SUB, R2, 10),
97325 - BPF_ALU64_IMM(BPF_SUB, R3, 10),
97326 - BPF_ALU64_IMM(BPF_SUB, R4, 10),
97327 - BPF_ALU64_IMM(BPF_SUB, R5, 10),
97328 - BPF_ALU64_IMM(BPF_SUB, R6, 10),
97329 - BPF_ALU64_IMM(BPF_SUB, R7, 10),
97330 - BPF_ALU64_IMM(BPF_SUB, R8, 10),
97331 - BPF_ALU64_IMM(BPF_SUB, R9, 10),
97332 - BPF_ALU64_REG(BPF_ADD, R0, R0),
97333 - BPF_ALU64_REG(BPF_ADD, R0, R1),
97334 - BPF_ALU64_REG(BPF_ADD, R0, R2),
97335 - BPF_ALU64_REG(BPF_ADD, R0, R3),
97336 - BPF_ALU64_REG(BPF_ADD, R0, R4),
97337 - BPF_ALU64_REG(BPF_ADD, R0, R5),
97338 - BPF_ALU64_REG(BPF_ADD, R0, R6),
97339 - BPF_ALU64_REG(BPF_ADD, R0, R7),
97340 - BPF_ALU64_REG(BPF_ADD, R0, R8),
97341 - BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
97342 - BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
97343 - BPF_EXIT_INSN(),
97344 - BPF_ALU64_REG(BPF_ADD, R1, R0),
97345 - BPF_ALU64_REG(BPF_ADD, R1, R1),
97346 - BPF_ALU64_REG(BPF_ADD, R1, R2),
97347 - BPF_ALU64_REG(BPF_ADD, R1, R3),
97348 - BPF_ALU64_REG(BPF_ADD, R1, R4),
97349 - BPF_ALU64_REG(BPF_ADD, R1, R5),
97350 - BPF_ALU64_REG(BPF_ADD, R1, R6),
97351 - BPF_ALU64_REG(BPF_ADD, R1, R7),
97352 - BPF_ALU64_REG(BPF_ADD, R1, R8),
97353 - BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
97354 - BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
97355 - BPF_EXIT_INSN(),
97356 - BPF_ALU64_REG(BPF_ADD, R2, R0),
97357 - BPF_ALU64_REG(BPF_ADD, R2, R1),
97358 - BPF_ALU64_REG(BPF_ADD, R2, R2),
97359 - BPF_ALU64_REG(BPF_ADD, R2, R3),
97360 - BPF_ALU64_REG(BPF_ADD, R2, R4),
97361 - BPF_ALU64_REG(BPF_ADD, R2, R5),
97362 - BPF_ALU64_REG(BPF_ADD, R2, R6),
97363 - BPF_ALU64_REG(BPF_ADD, R2, R7),
97364 - BPF_ALU64_REG(BPF_ADD, R2, R8),
97365 - BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
97366 - BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
97367 - BPF_EXIT_INSN(),
97368 - BPF_ALU64_REG(BPF_ADD, R3, R0),
97369 - BPF_ALU64_REG(BPF_ADD, R3, R1),
97370 - BPF_ALU64_REG(BPF_ADD, R3, R2),
97371 - BPF_ALU64_REG(BPF_ADD, R3, R3),
97372 - BPF_ALU64_REG(BPF_ADD, R3, R4),
97373 - BPF_ALU64_REG(BPF_ADD, R3, R5),
97374 - BPF_ALU64_REG(BPF_ADD, R3, R6),
97375 - BPF_ALU64_REG(BPF_ADD, R3, R7),
97376 - BPF_ALU64_REG(BPF_ADD, R3, R8),
97377 - BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
97378 - BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
97379 - BPF_EXIT_INSN(),
97380 - BPF_ALU64_REG(BPF_ADD, R4, R0),
97381 - BPF_ALU64_REG(BPF_ADD, R4, R1),
97382 - BPF_ALU64_REG(BPF_ADD, R4, R2),
97383 - BPF_ALU64_REG(BPF_ADD, R4, R3),
97384 - BPF_ALU64_REG(BPF_ADD, R4, R4),
97385 - BPF_ALU64_REG(BPF_ADD, R4, R5),
97386 - BPF_ALU64_REG(BPF_ADD, R4, R6),
97387 - BPF_ALU64_REG(BPF_ADD, R4, R7),
97388 - BPF_ALU64_REG(BPF_ADD, R4, R8),
97389 - BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
97390 - BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
97391 - BPF_EXIT_INSN(),
97392 - BPF_ALU64_REG(BPF_ADD, R5, R0),
97393 - BPF_ALU64_REG(BPF_ADD, R5, R1),
97394 - BPF_ALU64_REG(BPF_ADD, R5, R2),
97395 - BPF_ALU64_REG(BPF_ADD, R5, R3),
97396 - BPF_ALU64_REG(BPF_ADD, R5, R4),
97397 - BPF_ALU64_REG(BPF_ADD, R5, R5),
97398 - BPF_ALU64_REG(BPF_ADD, R5, R6),
97399 - BPF_ALU64_REG(BPF_ADD, R5, R7),
97400 - BPF_ALU64_REG(BPF_ADD, R5, R8),
97401 - BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
97402 - BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
97403 - BPF_EXIT_INSN(),
97404 - BPF_ALU64_REG(BPF_ADD, R6, R0),
97405 - BPF_ALU64_REG(BPF_ADD, R6, R1),
97406 - BPF_ALU64_REG(BPF_ADD, R6, R2),
97407 - BPF_ALU64_REG(BPF_ADD, R6, R3),
97408 - BPF_ALU64_REG(BPF_ADD, R6, R4),
97409 - BPF_ALU64_REG(BPF_ADD, R6, R5),
97410 - BPF_ALU64_REG(BPF_ADD, R6, R6),
97411 - BPF_ALU64_REG(BPF_ADD, R6, R7),
97412 - BPF_ALU64_REG(BPF_ADD, R6, R8),
97413 - BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
97414 - BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
97415 - BPF_EXIT_INSN(),
97416 - BPF_ALU64_REG(BPF_ADD, R7, R0),
97417 - BPF_ALU64_REG(BPF_ADD, R7, R1),
97418 - BPF_ALU64_REG(BPF_ADD, R7, R2),
97419 - BPF_ALU64_REG(BPF_ADD, R7, R3),
97420 - BPF_ALU64_REG(BPF_ADD, R7, R4),
97421 - BPF_ALU64_REG(BPF_ADD, R7, R5),
97422 - BPF_ALU64_REG(BPF_ADD, R7, R6),
97423 - BPF_ALU64_REG(BPF_ADD, R7, R7),
97424 - BPF_ALU64_REG(BPF_ADD, R7, R8),
97425 - BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
97426 - BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
97427 - BPF_EXIT_INSN(),
97428 - BPF_ALU64_REG(BPF_ADD, R8, R0),
97429 - BPF_ALU64_REG(BPF_ADD, R8, R1),
97430 - BPF_ALU64_REG(BPF_ADD, R8, R2),
97431 - BPF_ALU64_REG(BPF_ADD, R8, R3),
97432 - BPF_ALU64_REG(BPF_ADD, R8, R4),
97433 - BPF_ALU64_REG(BPF_ADD, R8, R5),
97434 - BPF_ALU64_REG(BPF_ADD, R8, R6),
97435 - BPF_ALU64_REG(BPF_ADD, R8, R7),
97436 - BPF_ALU64_REG(BPF_ADD, R8, R8),
97437 - BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
97438 - BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
97439 - BPF_EXIT_INSN(),
97440 - BPF_ALU64_REG(BPF_ADD, R9, R0),
97441 - BPF_ALU64_REG(BPF_ADD, R9, R1),
97442 - BPF_ALU64_REG(BPF_ADD, R9, R2),
97443 - BPF_ALU64_REG(BPF_ADD, R9, R3),
97444 - BPF_ALU64_REG(BPF_ADD, R9, R4),
97445 - BPF_ALU64_REG(BPF_ADD, R9, R5),
97446 - BPF_ALU64_REG(BPF_ADD, R9, R6),
97447 - BPF_ALU64_REG(BPF_ADD, R9, R7),
97448 - BPF_ALU64_REG(BPF_ADD, R9, R8),
97449 - BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
97450 - BPF_ALU64_REG(BPF_MOV, R0, R9),
97451 - BPF_EXIT_INSN(),
97452 - },
97453 - INTERNAL,
97454 - { },
97455 - { { 0, 2957380 } }
97456 - },
97457 - {
97458 - "INT: ADD 32-bit",
97459 - .u.insns_int = {
97460 - BPF_ALU32_IMM(BPF_MOV, R0, 20),
97461 - BPF_ALU32_IMM(BPF_MOV, R1, 1),
97462 - BPF_ALU32_IMM(BPF_MOV, R2, 2),
97463 - BPF_ALU32_IMM(BPF_MOV, R3, 3),
97464 - BPF_ALU32_IMM(BPF_MOV, R4, 4),
97465 - BPF_ALU32_IMM(BPF_MOV, R5, 5),
97466 - BPF_ALU32_IMM(BPF_MOV, R6, 6),
97467 - BPF_ALU32_IMM(BPF_MOV, R7, 7),
97468 - BPF_ALU32_IMM(BPF_MOV, R8, 8),
97469 - BPF_ALU32_IMM(BPF_MOV, R9, 9),
97470 - BPF_ALU64_IMM(BPF_ADD, R1, 10),
97471 - BPF_ALU64_IMM(BPF_ADD, R2, 10),
97472 - BPF_ALU64_IMM(BPF_ADD, R3, 10),
97473 - BPF_ALU64_IMM(BPF_ADD, R4, 10),
97474 - BPF_ALU64_IMM(BPF_ADD, R5, 10),
97475 - BPF_ALU64_IMM(BPF_ADD, R6, 10),
97476 - BPF_ALU64_IMM(BPF_ADD, R7, 10),
97477 - BPF_ALU64_IMM(BPF_ADD, R8, 10),
97478 - BPF_ALU64_IMM(BPF_ADD, R9, 10),
97479 - BPF_ALU32_REG(BPF_ADD, R0, R1),
97480 - BPF_ALU32_REG(BPF_ADD, R0, R2),
97481 - BPF_ALU32_REG(BPF_ADD, R0, R3),
97482 - BPF_ALU32_REG(BPF_ADD, R0, R4),
97483 - BPF_ALU32_REG(BPF_ADD, R0, R5),
97484 - BPF_ALU32_REG(BPF_ADD, R0, R6),
97485 - BPF_ALU32_REG(BPF_ADD, R0, R7),
97486 - BPF_ALU32_REG(BPF_ADD, R0, R8),
97487 - BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
97488 - BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
97489 - BPF_EXIT_INSN(),
97490 - BPF_ALU32_REG(BPF_ADD, R1, R0),
97491 - BPF_ALU32_REG(BPF_ADD, R1, R1),
97492 - BPF_ALU32_REG(BPF_ADD, R1, R2),
97493 - BPF_ALU32_REG(BPF_ADD, R1, R3),
97494 - BPF_ALU32_REG(BPF_ADD, R1, R4),
97495 - BPF_ALU32_REG(BPF_ADD, R1, R5),
97496 - BPF_ALU32_REG(BPF_ADD, R1, R6),
97497 - BPF_ALU32_REG(BPF_ADD, R1, R7),
97498 - BPF_ALU32_REG(BPF_ADD, R1, R8),
97499 - BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
97500 - BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
97501 - BPF_EXIT_INSN(),
97502 - BPF_ALU32_REG(BPF_ADD, R2, R0),
97503 - BPF_ALU32_REG(BPF_ADD, R2, R1),
97504 - BPF_ALU32_REG(BPF_ADD, R2, R2),
97505 - BPF_ALU32_REG(BPF_ADD, R2, R3),
97506 - BPF_ALU32_REG(BPF_ADD, R2, R4),
97507 - BPF_ALU32_REG(BPF_ADD, R2, R5),
97508 - BPF_ALU32_REG(BPF_ADD, R2, R6),
97509 - BPF_ALU32_REG(BPF_ADD, R2, R7),
97510 - BPF_ALU32_REG(BPF_ADD, R2, R8),
97511 - BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
97512 - BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
97513 - BPF_EXIT_INSN(),
97514 - BPF_ALU32_REG(BPF_ADD, R3, R0),
97515 - BPF_ALU32_REG(BPF_ADD, R3, R1),
97516 - BPF_ALU32_REG(BPF_ADD, R3, R2),
97517 - BPF_ALU32_REG(BPF_ADD, R3, R3),
97518 - BPF_ALU32_REG(BPF_ADD, R3, R4),
97519 - BPF_ALU32_REG(BPF_ADD, R3, R5),
97520 - BPF_ALU32_REG(BPF_ADD, R3, R6),
97521 - BPF_ALU32_REG(BPF_ADD, R3, R7),
97522 - BPF_ALU32_REG(BPF_ADD, R3, R8),
97523 - BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
97524 - BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
97525 - BPF_EXIT_INSN(),
97526 - BPF_ALU32_REG(BPF_ADD, R4, R0),
97527 - BPF_ALU32_REG(BPF_ADD, R4, R1),
97528 - BPF_ALU32_REG(BPF_ADD, R4, R2),
97529 - BPF_ALU32_REG(BPF_ADD, R4, R3),
97530 - BPF_ALU32_REG(BPF_ADD, R4, R4),
97531 - BPF_ALU32_REG(BPF_ADD, R4, R5),
97532 - BPF_ALU32_REG(BPF_ADD, R4, R6),
97533 - BPF_ALU32_REG(BPF_ADD, R4, R7),
97534 - BPF_ALU32_REG(BPF_ADD, R4, R8),
97535 - BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
97536 - BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
97537 - BPF_EXIT_INSN(),
97538 - BPF_ALU32_REG(BPF_ADD, R5, R0),
97539 - BPF_ALU32_REG(BPF_ADD, R5, R1),
97540 - BPF_ALU32_REG(BPF_ADD, R5, R2),
97541 - BPF_ALU32_REG(BPF_ADD, R5, R3),
97542 - BPF_ALU32_REG(BPF_ADD, R5, R4),
97543 - BPF_ALU32_REG(BPF_ADD, R5, R5),
97544 - BPF_ALU32_REG(BPF_ADD, R5, R6),
97545 - BPF_ALU32_REG(BPF_ADD, R5, R7),
97546 - BPF_ALU32_REG(BPF_ADD, R5, R8),
97547 - BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
97548 - BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
97549 - BPF_EXIT_INSN(),
97550 - BPF_ALU32_REG(BPF_ADD, R6, R0),
97551 - BPF_ALU32_REG(BPF_ADD, R6, R1),
97552 - BPF_ALU32_REG(BPF_ADD, R6, R2),
97553 - BPF_ALU32_REG(BPF_ADD, R6, R3),
97554 - BPF_ALU32_REG(BPF_ADD, R6, R4),
97555 - BPF_ALU32_REG(BPF_ADD, R6, R5),
97556 - BPF_ALU32_REG(BPF_ADD, R6, R6),
97557 - BPF_ALU32_REG(BPF_ADD, R6, R7),
97558 - BPF_ALU32_REG(BPF_ADD, R6, R8),
97559 - BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
97560 - BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
97561 - BPF_EXIT_INSN(),
97562 - BPF_ALU32_REG(BPF_ADD, R7, R0),
97563 - BPF_ALU32_REG(BPF_ADD, R7, R1),
97564 - BPF_ALU32_REG(BPF_ADD, R7, R2),
97565 - BPF_ALU32_REG(BPF_ADD, R7, R3),
97566 - BPF_ALU32_REG(BPF_ADD, R7, R4),
97567 - BPF_ALU32_REG(BPF_ADD, R7, R5),
97568 - BPF_ALU32_REG(BPF_ADD, R7, R6),
97569 - BPF_ALU32_REG(BPF_ADD, R7, R7),
97570 - BPF_ALU32_REG(BPF_ADD, R7, R8),
97571 - BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
97572 - BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
97573 - BPF_EXIT_INSN(),
97574 - BPF_ALU32_REG(BPF_ADD, R8, R0),
97575 - BPF_ALU32_REG(BPF_ADD, R8, R1),
97576 - BPF_ALU32_REG(BPF_ADD, R8, R2),
97577 - BPF_ALU32_REG(BPF_ADD, R8, R3),
97578 - BPF_ALU32_REG(BPF_ADD, R8, R4),
97579 - BPF_ALU32_REG(BPF_ADD, R8, R5),
97580 - BPF_ALU32_REG(BPF_ADD, R8, R6),
97581 - BPF_ALU32_REG(BPF_ADD, R8, R7),
97582 - BPF_ALU32_REG(BPF_ADD, R8, R8),
97583 - BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
97584 - BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
97585 - BPF_EXIT_INSN(),
97586 - BPF_ALU32_REG(BPF_ADD, R9, R0),
97587 - BPF_ALU32_REG(BPF_ADD, R9, R1),
97588 - BPF_ALU32_REG(BPF_ADD, R9, R2),
97589 - BPF_ALU32_REG(BPF_ADD, R9, R3),
97590 - BPF_ALU32_REG(BPF_ADD, R9, R4),
97591 - BPF_ALU32_REG(BPF_ADD, R9, R5),
97592 - BPF_ALU32_REG(BPF_ADD, R9, R6),
97593 - BPF_ALU32_REG(BPF_ADD, R9, R7),
97594 - BPF_ALU32_REG(BPF_ADD, R9, R8),
97595 - BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
97596 - BPF_ALU32_REG(BPF_MOV, R0, R9),
97597 - BPF_EXIT_INSN(),
97598 - },
97599 - INTERNAL,
97600 - { },
97601 - { { 0, 2957380 } }
97602 - },
97603 - { /* Mainly checking JIT here. */
97604 - "INT: SUB",
97605 - .u.insns_int = {
97606 - BPF_ALU64_IMM(BPF_MOV, R0, 0),
97607 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
97608 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
97609 - BPF_ALU64_IMM(BPF_MOV, R3, 3),
97610 - BPF_ALU64_IMM(BPF_MOV, R4, 4),
97611 - BPF_ALU64_IMM(BPF_MOV, R5, 5),
97612 - BPF_ALU64_IMM(BPF_MOV, R6, 6),
97613 - BPF_ALU64_IMM(BPF_MOV, R7, 7),
97614 - BPF_ALU64_IMM(BPF_MOV, R8, 8),
97615 - BPF_ALU64_IMM(BPF_MOV, R9, 9),
97616 - BPF_ALU64_REG(BPF_SUB, R0, R0),
97617 - BPF_ALU64_REG(BPF_SUB, R0, R1),
97618 - BPF_ALU64_REG(BPF_SUB, R0, R2),
97619 - BPF_ALU64_REG(BPF_SUB, R0, R3),
97620 - BPF_ALU64_REG(BPF_SUB, R0, R4),
97621 - BPF_ALU64_REG(BPF_SUB, R0, R5),
97622 - BPF_ALU64_REG(BPF_SUB, R0, R6),
97623 - BPF_ALU64_REG(BPF_SUB, R0, R7),
97624 - BPF_ALU64_REG(BPF_SUB, R0, R8),
97625 - BPF_ALU64_REG(BPF_SUB, R0, R9),
97626 - BPF_ALU64_IMM(BPF_SUB, R0, 10),
97627 - BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
97628 - BPF_EXIT_INSN(),
97629 - BPF_ALU64_REG(BPF_SUB, R1, R0),
97630 - BPF_ALU64_REG(BPF_SUB, R1, R2),
97631 - BPF_ALU64_REG(BPF_SUB, R1, R3),
97632 - BPF_ALU64_REG(BPF_SUB, R1, R4),
97633 - BPF_ALU64_REG(BPF_SUB, R1, R5),
97634 - BPF_ALU64_REG(BPF_SUB, R1, R6),
97635 - BPF_ALU64_REG(BPF_SUB, R1, R7),
97636 - BPF_ALU64_REG(BPF_SUB, R1, R8),
97637 - BPF_ALU64_REG(BPF_SUB, R1, R9),
97638 - BPF_ALU64_IMM(BPF_SUB, R1, 10),
97639 - BPF_ALU64_REG(BPF_SUB, R2, R0),
97640 - BPF_ALU64_REG(BPF_SUB, R2, R1),
97641 - BPF_ALU64_REG(BPF_SUB, R2, R3),
97642 - BPF_ALU64_REG(BPF_SUB, R2, R4),
97643 - BPF_ALU64_REG(BPF_SUB, R2, R5),
97644 - BPF_ALU64_REG(BPF_SUB, R2, R6),
97645 - BPF_ALU64_REG(BPF_SUB, R2, R7),
97646 - BPF_ALU64_REG(BPF_SUB, R2, R8),
97647 - BPF_ALU64_REG(BPF_SUB, R2, R9),
97648 - BPF_ALU64_IMM(BPF_SUB, R2, 10),
97649 - BPF_ALU64_REG(BPF_SUB, R3, R0),
97650 - BPF_ALU64_REG(BPF_SUB, R3, R1),
97651 - BPF_ALU64_REG(BPF_SUB, R3, R2),
97652 - BPF_ALU64_REG(BPF_SUB, R3, R4),
97653 - BPF_ALU64_REG(BPF_SUB, R3, R5),
97654 - BPF_ALU64_REG(BPF_SUB, R3, R6),
97655 - BPF_ALU64_REG(BPF_SUB, R3, R7),
97656 - BPF_ALU64_REG(BPF_SUB, R3, R8),
97657 - BPF_ALU64_REG(BPF_SUB, R3, R9),
97658 - BPF_ALU64_IMM(BPF_SUB, R3, 10),
97659 - BPF_ALU64_REG(BPF_SUB, R4, R0),
97660 - BPF_ALU64_REG(BPF_SUB, R4, R1),
97661 - BPF_ALU64_REG(BPF_SUB, R4, R2),
97662 - BPF_ALU64_REG(BPF_SUB, R4, R3),
97663 - BPF_ALU64_REG(BPF_SUB, R4, R5),
97664 - BPF_ALU64_REG(BPF_SUB, R4, R6),
97665 - BPF_ALU64_REG(BPF_SUB, R4, R7),
97666 - BPF_ALU64_REG(BPF_SUB, R4, R8),
97667 - BPF_ALU64_REG(BPF_SUB, R4, R9),
97668 - BPF_ALU64_IMM(BPF_SUB, R4, 10),
97669 - BPF_ALU64_REG(BPF_SUB, R5, R0),
97670 - BPF_ALU64_REG(BPF_SUB, R5, R1),
97671 - BPF_ALU64_REG(BPF_SUB, R5, R2),
97672 - BPF_ALU64_REG(BPF_SUB, R5, R3),
97673 - BPF_ALU64_REG(BPF_SUB, R5, R4),
97674 - BPF_ALU64_REG(BPF_SUB, R5, R6),
97675 - BPF_ALU64_REG(BPF_SUB, R5, R7),
97676 - BPF_ALU64_REG(BPF_SUB, R5, R8),
97677 - BPF_ALU64_REG(BPF_SUB, R5, R9),
97678 - BPF_ALU64_IMM(BPF_SUB, R5, 10),
97679 - BPF_ALU64_REG(BPF_SUB, R6, R0),
97680 - BPF_ALU64_REG(BPF_SUB, R6, R1),
97681 - BPF_ALU64_REG(BPF_SUB, R6, R2),
97682 - BPF_ALU64_REG(BPF_SUB, R6, R3),
97683 - BPF_ALU64_REG(BPF_SUB, R6, R4),
97684 - BPF_ALU64_REG(BPF_SUB, R6, R5),
97685 - BPF_ALU64_REG(BPF_SUB, R6, R7),
97686 - BPF_ALU64_REG(BPF_SUB, R6, R8),
97687 - BPF_ALU64_REG(BPF_SUB, R6, R9),
97688 - BPF_ALU64_IMM(BPF_SUB, R6, 10),
97689 - BPF_ALU64_REG(BPF_SUB, R7, R0),
97690 - BPF_ALU64_REG(BPF_SUB, R7, R1),
97691 - BPF_ALU64_REG(BPF_SUB, R7, R2),
97692 - BPF_ALU64_REG(BPF_SUB, R7, R3),
97693 - BPF_ALU64_REG(BPF_SUB, R7, R4),
97694 - BPF_ALU64_REG(BPF_SUB, R7, R5),
97695 - BPF_ALU64_REG(BPF_SUB, R7, R6),
97696 - BPF_ALU64_REG(BPF_SUB, R7, R8),
97697 - BPF_ALU64_REG(BPF_SUB, R7, R9),
97698 - BPF_ALU64_IMM(BPF_SUB, R7, 10),
97699 - BPF_ALU64_REG(BPF_SUB, R8, R0),
97700 - BPF_ALU64_REG(BPF_SUB, R8, R1),
97701 - BPF_ALU64_REG(BPF_SUB, R8, R2),
97702 - BPF_ALU64_REG(BPF_SUB, R8, R3),
97703 - BPF_ALU64_REG(BPF_SUB, R8, R4),
97704 - BPF_ALU64_REG(BPF_SUB, R8, R5),
97705 - BPF_ALU64_REG(BPF_SUB, R8, R6),
97706 - BPF_ALU64_REG(BPF_SUB, R8, R7),
97707 - BPF_ALU64_REG(BPF_SUB, R8, R9),
97708 - BPF_ALU64_IMM(BPF_SUB, R8, 10),
97709 - BPF_ALU64_REG(BPF_SUB, R9, R0),
97710 - BPF_ALU64_REG(BPF_SUB, R9, R1),
97711 - BPF_ALU64_REG(BPF_SUB, R9, R2),
97712 - BPF_ALU64_REG(BPF_SUB, R9, R3),
97713 - BPF_ALU64_REG(BPF_SUB, R9, R4),
97714 - BPF_ALU64_REG(BPF_SUB, R9, R5),
97715 - BPF_ALU64_REG(BPF_SUB, R9, R6),
97716 - BPF_ALU64_REG(BPF_SUB, R9, R7),
97717 - BPF_ALU64_REG(BPF_SUB, R9, R8),
97718 - BPF_ALU64_IMM(BPF_SUB, R9, 10),
97719 - BPF_ALU64_IMM(BPF_SUB, R0, 10),
97720 - BPF_ALU64_IMM(BPF_NEG, R0, 0),
97721 - BPF_ALU64_REG(BPF_SUB, R0, R1),
97722 - BPF_ALU64_REG(BPF_SUB, R0, R2),
97723 - BPF_ALU64_REG(BPF_SUB, R0, R3),
97724 - BPF_ALU64_REG(BPF_SUB, R0, R4),
97725 - BPF_ALU64_REG(BPF_SUB, R0, R5),
97726 - BPF_ALU64_REG(BPF_SUB, R0, R6),
97727 - BPF_ALU64_REG(BPF_SUB, R0, R7),
97728 - BPF_ALU64_REG(BPF_SUB, R0, R8),
97729 - BPF_ALU64_REG(BPF_SUB, R0, R9),
97730 - BPF_EXIT_INSN(),
97731 - },
97732 - INTERNAL,
97733 - { },
97734 - { { 0, 11 } }
97735 - },
97736 - { /* Mainly checking JIT here. */
97737 - "INT: XOR",
97738 - .u.insns_int = {
97739 - BPF_ALU64_REG(BPF_SUB, R0, R0),
97740 - BPF_ALU64_REG(BPF_XOR, R1, R1),
97741 - BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
97742 - BPF_EXIT_INSN(),
97743 - BPF_ALU64_IMM(BPF_MOV, R0, 10),
97744 - BPF_ALU64_IMM(BPF_MOV, R1, -1),
97745 - BPF_ALU64_REG(BPF_SUB, R1, R1),
97746 - BPF_ALU64_REG(BPF_XOR, R2, R2),
97747 - BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
97748 - BPF_EXIT_INSN(),
97749 - BPF_ALU64_REG(BPF_SUB, R2, R2),
97750 - BPF_ALU64_REG(BPF_XOR, R3, R3),
97751 - BPF_ALU64_IMM(BPF_MOV, R0, 10),
97752 - BPF_ALU64_IMM(BPF_MOV, R1, -1),
97753 - BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
97754 - BPF_EXIT_INSN(),
97755 - BPF_ALU64_REG(BPF_SUB, R3, R3),
97756 - BPF_ALU64_REG(BPF_XOR, R4, R4),
97757 - BPF_ALU64_IMM(BPF_MOV, R2, 1),
97758 - BPF_ALU64_IMM(BPF_MOV, R5, -1),
97759 - BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
97760 - BPF_EXIT_INSN(),
97761 - BPF_ALU64_REG(BPF_SUB, R4, R4),
97762 - BPF_ALU64_REG(BPF_XOR, R5, R5),
97763 - BPF_ALU64_IMM(BPF_MOV, R3, 1),
97764 - BPF_ALU64_IMM(BPF_MOV, R7, -1),
97765 - BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
97766 - BPF_EXIT_INSN(),
97767 - BPF_ALU64_IMM(BPF_MOV, R5, 1),
97768 - BPF_ALU64_REG(BPF_SUB, R5, R5),
97769 - BPF_ALU64_REG(BPF_XOR, R6, R6),
97770 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
97771 - BPF_ALU64_IMM(BPF_MOV, R8, -1),
97772 - BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
97773 - BPF_EXIT_INSN(),
97774 - BPF_ALU64_REG(BPF_SUB, R6, R6),
97775 - BPF_ALU64_REG(BPF_XOR, R7, R7),
97776 - BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
97777 - BPF_EXIT_INSN(),
97778 - BPF_ALU64_REG(BPF_SUB, R7, R7),
97779 - BPF_ALU64_REG(BPF_XOR, R8, R8),
97780 - BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
97781 - BPF_EXIT_INSN(),
97782 - BPF_ALU64_REG(BPF_SUB, R8, R8),
97783 - BPF_ALU64_REG(BPF_XOR, R9, R9),
97784 - BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
97785 - BPF_EXIT_INSN(),
97786 - BPF_ALU64_REG(BPF_SUB, R9, R9),
97787 - BPF_ALU64_REG(BPF_XOR, R0, R0),
97788 - BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
97789 - BPF_EXIT_INSN(),
97790 - BPF_ALU64_REG(BPF_SUB, R1, R1),
97791 - BPF_ALU64_REG(BPF_XOR, R0, R0),
97792 - BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
97793 - BPF_ALU64_IMM(BPF_MOV, R0, 0),
97794 - BPF_EXIT_INSN(),
97795 - BPF_ALU64_IMM(BPF_MOV, R0, 1),
97796 - BPF_EXIT_INSN(),
97797 - },
97798 - INTERNAL,
97799 - { },
97800 - { { 0, 1 } }
97801 - },
97802 - { /* Mainly checking JIT here. */
97803 - "INT: MUL",
97804 - .u.insns_int = {
97805 - BPF_ALU64_IMM(BPF_MOV, R0, 11),
97806 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
97807 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
97808 - BPF_ALU64_IMM(BPF_MOV, R3, 3),
97809 - BPF_ALU64_IMM(BPF_MOV, R4, 4),
97810 - BPF_ALU64_IMM(BPF_MOV, R5, 5),
97811 - BPF_ALU64_IMM(BPF_MOV, R6, 6),
97812 - BPF_ALU64_IMM(BPF_MOV, R7, 7),
97813 - BPF_ALU64_IMM(BPF_MOV, R8, 8),
97814 - BPF_ALU64_IMM(BPF_MOV, R9, 9),
97815 - BPF_ALU64_REG(BPF_MUL, R0, R0),
97816 - BPF_ALU64_REG(BPF_MUL, R0, R1),
97817 - BPF_ALU64_REG(BPF_MUL, R0, R2),
97818 - BPF_ALU64_REG(BPF_MUL, R0, R3),
97819 - BPF_ALU64_REG(BPF_MUL, R0, R4),
97820 - BPF_ALU64_REG(BPF_MUL, R0, R5),
97821 - BPF_ALU64_REG(BPF_MUL, R0, R6),
97822 - BPF_ALU64_REG(BPF_MUL, R0, R7),
97823 - BPF_ALU64_REG(BPF_MUL, R0, R8),
97824 - BPF_ALU64_REG(BPF_MUL, R0, R9),
97825 - BPF_ALU64_IMM(BPF_MUL, R0, 10),
97826 - BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
97827 - BPF_EXIT_INSN(),
97828 - BPF_ALU64_REG(BPF_MUL, R1, R0),
97829 - BPF_ALU64_REG(BPF_MUL, R1, R2),
97830 - BPF_ALU64_REG(BPF_MUL, R1, R3),
97831 - BPF_ALU64_REG(BPF_MUL, R1, R4),
97832 - BPF_ALU64_REG(BPF_MUL, R1, R5),
97833 - BPF_ALU64_REG(BPF_MUL, R1, R6),
97834 - BPF_ALU64_REG(BPF_MUL, R1, R7),
97835 - BPF_ALU64_REG(BPF_MUL, R1, R8),
97836 - BPF_ALU64_REG(BPF_MUL, R1, R9),
97837 - BPF_ALU64_IMM(BPF_MUL, R1, 10),
97838 - BPF_ALU64_REG(BPF_MOV, R2, R1),
97839 - BPF_ALU64_IMM(BPF_RSH, R2, 32),
97840 - BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
97841 - BPF_EXIT_INSN(),
97842 - BPF_ALU64_IMM(BPF_LSH, R1, 32),
97843 - BPF_ALU64_IMM(BPF_ARSH, R1, 32),
97844 - BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
97845 - BPF_EXIT_INSN(),
97846 - BPF_ALU64_REG(BPF_MUL, R2, R0),
97847 - BPF_ALU64_REG(BPF_MUL, R2, R1),
97848 - BPF_ALU64_REG(BPF_MUL, R2, R3),
97849 - BPF_ALU64_REG(BPF_MUL, R2, R4),
97850 - BPF_ALU64_REG(BPF_MUL, R2, R5),
97851 - BPF_ALU64_REG(BPF_MUL, R2, R6),
97852 - BPF_ALU64_REG(BPF_MUL, R2, R7),
97853 - BPF_ALU64_REG(BPF_MUL, R2, R8),
97854 - BPF_ALU64_REG(BPF_MUL, R2, R9),
97855 - BPF_ALU64_IMM(BPF_MUL, R2, 10),
97856 - BPF_ALU64_IMM(BPF_RSH, R2, 32),
97857 - BPF_ALU64_REG(BPF_MOV, R0, R2),
97858 - BPF_EXIT_INSN(),
97859 - },
97860 - INTERNAL,
97861 - { },
97862 - { { 0, 0x35d97ef2 } }
97863 - },
97864 - {
97865 - "INT: ALU MIX",
97866 - .u.insns_int = {
97867 - BPF_ALU64_IMM(BPF_MOV, R0, 11),
97868 - BPF_ALU64_IMM(BPF_ADD, R0, -1),
97869 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
97870 - BPF_ALU64_IMM(BPF_XOR, R2, 3),
97871 - BPF_ALU64_REG(BPF_DIV, R0, R2),
97872 - BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
97873 - BPF_EXIT_INSN(),
97874 - BPF_ALU64_IMM(BPF_MOD, R0, 3),
97875 - BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
97876 - BPF_EXIT_INSN(),
97877 - BPF_ALU64_IMM(BPF_MOV, R0, -1),
97878 - BPF_EXIT_INSN(),
97879 - },
97880 - INTERNAL,
97881 - { },
97882 - { { 0, -1 } }
97883 - },
97884 - {
97885 - "INT: DIV + ABS",
97886 - .u.insns_int = {
97887 - BPF_ALU64_REG(BPF_MOV, R6, R1),
97888 - BPF_LD_ABS(BPF_B, 3),
97889 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
97890 - BPF_ALU32_REG(BPF_DIV, R0, R2),
97891 - BPF_ALU64_REG(BPF_MOV, R8, R0),
97892 - BPF_LD_ABS(BPF_B, 4),
97893 - BPF_ALU64_REG(BPF_ADD, R8, R0),
97894 - BPF_LD_IND(BPF_B, R8, -70),
97895 - BPF_EXIT_INSN(),
97896 - },
97897 - INTERNAL,
97898 - { 10, 20, 30, 40, 50 },
97899 - { { 4, 0 }, { 5, 10 } }
97900 - },
97901 - {
97902 - "INT: DIV by zero",
97903 - .u.insns_int = {
97904 - BPF_ALU64_REG(BPF_MOV, R6, R1),
97905 - BPF_ALU64_IMM(BPF_MOV, R7, 0),
97906 - BPF_LD_ABS(BPF_B, 3),
97907 - BPF_ALU32_REG(BPF_DIV, R0, R7),
97908 - BPF_EXIT_INSN(),
97909 - },
97910 - INTERNAL,
97911 - { 10, 20, 30, 40, 50 },
97912 - { { 3, 0 }, { 4, 0 } }
97913 - },
97914 - {
97915 - "check: missing ret",
97916 - .u.insns = {
97917 - BPF_STMT(BPF_LD | BPF_IMM, 1),
97918 - },
97919 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
97920 - { },
97921 - { }
97922 - },
97923 - {
97924 - "check: div_k_0",
97925 - .u.insns = {
97926 - BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
97927 - BPF_STMT(BPF_RET | BPF_K, 0)
97928 - },
97929 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
97930 - { },
97931 - { }
97932 - },
97933 - {
97934 - "check: unknown insn",
97935 - .u.insns = {
97936 - /* seccomp insn, rejected in socket filter */
97937 - BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
97938 - BPF_STMT(BPF_RET | BPF_K, 0)
97939 - },
97940 - CLASSIC | FLAG_EXPECTED_FAIL,
97941 - { },
97942 - { }
97943 - },
97944 - {
97945 - "check: out of range spill/fill",
97946 - .u.insns = {
97947 - BPF_STMT(BPF_STX, 16),
97948 - BPF_STMT(BPF_RET | BPF_K, 0)
97949 - },
97950 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
97951 - { },
97952 - { }
97953 - },
97954 - {
97955 - "JUMPS + HOLES",
97956 - .u.insns = {
97957 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97958 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
97959 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97960 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97961 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97962 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97963 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97964 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97965 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97966 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97967 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97968 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97969 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97970 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97971 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97972 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
97973 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97974 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
97975 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97976 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
97977 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
97978 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97979 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97980 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97981 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97982 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97983 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97984 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97985 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97986 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97987 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97988 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97989 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97990 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97991 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
97992 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
97993 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97994 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
97995 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
97996 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97997 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97998 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
97999 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98000 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98001 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98002 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98003 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98004 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98005 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98006 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98007 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98008 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98009 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
98010 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
98011 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98012 - BPF_STMT(BPF_RET | BPF_A, 0),
98013 - BPF_STMT(BPF_RET | BPF_A, 0),
98014 - },
98015 - CLASSIC,
98016 - { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
98017 - 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
98018 - 0x08, 0x00,
98019 - 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
98020 - 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
98021 - 0xc0, 0xa8, 0x33, 0x01,
98022 - 0xc0, 0xa8, 0x33, 0x02,
98023 - 0xbb, 0xb6,
98024 - 0xa9, 0xfa,
98025 - 0x00, 0x14, 0x00, 0x00,
98026 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98027 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98028 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98029 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98030 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98031 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98032 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98033 - 0xcc, 0xcc, 0xcc, 0xcc },
98034 - { { 88, 0x001b } }
98035 - },
98036 - {
98037 - "check: RET X",
98038 - .u.insns = {
98039 - BPF_STMT(BPF_RET | BPF_X, 0),
98040 - },
98041 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98042 - { },
98043 - { },
98044 - },
98045 - {
98046 - "check: LDX + RET X",
98047 - .u.insns = {
98048 - BPF_STMT(BPF_LDX | BPF_IMM, 42),
98049 - BPF_STMT(BPF_RET | BPF_X, 0),
98050 - },
98051 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98052 - { },
98053 - { },
98054 - },
98055 - { /* Mainly checking JIT here. */
98056 - "M[]: alt STX + LDX",
98057 - .u.insns = {
98058 - BPF_STMT(BPF_LDX | BPF_IMM, 100),
98059 - BPF_STMT(BPF_STX, 0),
98060 - BPF_STMT(BPF_LDX | BPF_MEM, 0),
98061 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98062 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98063 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98064 - BPF_STMT(BPF_STX, 1),
98065 - BPF_STMT(BPF_LDX | BPF_MEM, 1),
98066 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98067 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98068 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98069 - BPF_STMT(BPF_STX, 2),
98070 - BPF_STMT(BPF_LDX | BPF_MEM, 2),
98071 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98072 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98073 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98074 - BPF_STMT(BPF_STX, 3),
98075 - BPF_STMT(BPF_LDX | BPF_MEM, 3),
98076 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98077 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98078 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98079 - BPF_STMT(BPF_STX, 4),
98080 - BPF_STMT(BPF_LDX | BPF_MEM, 4),
98081 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98082 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98083 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98084 - BPF_STMT(BPF_STX, 5),
98085 - BPF_STMT(BPF_LDX | BPF_MEM, 5),
98086 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98087 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98088 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98089 - BPF_STMT(BPF_STX, 6),
98090 - BPF_STMT(BPF_LDX | BPF_MEM, 6),
98091 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98092 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98093 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98094 - BPF_STMT(BPF_STX, 7),
98095 - BPF_STMT(BPF_LDX | BPF_MEM, 7),
98096 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98097 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98098 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98099 - BPF_STMT(BPF_STX, 8),
98100 - BPF_STMT(BPF_LDX | BPF_MEM, 8),
98101 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98102 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98103 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98104 - BPF_STMT(BPF_STX, 9),
98105 - BPF_STMT(BPF_LDX | BPF_MEM, 9),
98106 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98107 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98108 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98109 - BPF_STMT(BPF_STX, 10),
98110 - BPF_STMT(BPF_LDX | BPF_MEM, 10),
98111 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98112 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98113 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98114 - BPF_STMT(BPF_STX, 11),
98115 - BPF_STMT(BPF_LDX | BPF_MEM, 11),
98116 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98117 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98118 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98119 - BPF_STMT(BPF_STX, 12),
98120 - BPF_STMT(BPF_LDX | BPF_MEM, 12),
98121 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98122 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98123 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98124 - BPF_STMT(BPF_STX, 13),
98125 - BPF_STMT(BPF_LDX | BPF_MEM, 13),
98126 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98127 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98128 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98129 - BPF_STMT(BPF_STX, 14),
98130 - BPF_STMT(BPF_LDX | BPF_MEM, 14),
98131 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98132 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98133 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98134 - BPF_STMT(BPF_STX, 15),
98135 - BPF_STMT(BPF_LDX | BPF_MEM, 15),
98136 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98137 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98138 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98139 - BPF_STMT(BPF_RET | BPF_A, 0),
98140 - },
98141 - CLASSIC | FLAG_NO_DATA,
98142 - { },
98143 - { { 0, 116 } },
98144 - },
98145 - { /* Mainly checking JIT here. */
98146 - "M[]: full STX + full LDX",
98147 - .u.insns = {
98148 - BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
98149 - BPF_STMT(BPF_STX, 0),
98150 - BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
98151 - BPF_STMT(BPF_STX, 1),
98152 - BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
98153 - BPF_STMT(BPF_STX, 2),
98154 - BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
98155 - BPF_STMT(BPF_STX, 3),
98156 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
98157 - BPF_STMT(BPF_STX, 4),
98158 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
98159 - BPF_STMT(BPF_STX, 5),
98160 - BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
98161 - BPF_STMT(BPF_STX, 6),
98162 - BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
98163 - BPF_STMT(BPF_STX, 7),
98164 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
98165 - BPF_STMT(BPF_STX, 8),
98166 - BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
98167 - BPF_STMT(BPF_STX, 9),
98168 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
98169 - BPF_STMT(BPF_STX, 10),
98170 - BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
98171 - BPF_STMT(BPF_STX, 11),
98172 - BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
98173 - BPF_STMT(BPF_STX, 12),
98174 - BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
98175 - BPF_STMT(BPF_STX, 13),
98176 - BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
98177 - BPF_STMT(BPF_STX, 14),
98178 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
98179 - BPF_STMT(BPF_STX, 15),
98180 - BPF_STMT(BPF_LDX | BPF_MEM, 0),
98181 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98182 - BPF_STMT(BPF_LDX | BPF_MEM, 1),
98183 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98184 - BPF_STMT(BPF_LDX | BPF_MEM, 2),
98185 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98186 - BPF_STMT(BPF_LDX | BPF_MEM, 3),
98187 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98188 - BPF_STMT(BPF_LDX | BPF_MEM, 4),
98189 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98190 - BPF_STMT(BPF_LDX | BPF_MEM, 5),
98191 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98192 - BPF_STMT(BPF_LDX | BPF_MEM, 6),
98193 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98194 - BPF_STMT(BPF_LDX | BPF_MEM, 7),
98195 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98196 - BPF_STMT(BPF_LDX | BPF_MEM, 8),
98197 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98198 - BPF_STMT(BPF_LDX | BPF_MEM, 9),
98199 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98200 - BPF_STMT(BPF_LDX | BPF_MEM, 10),
98201 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98202 - BPF_STMT(BPF_LDX | BPF_MEM, 11),
98203 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98204 - BPF_STMT(BPF_LDX | BPF_MEM, 12),
98205 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98206 - BPF_STMT(BPF_LDX | BPF_MEM, 13),
98207 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98208 - BPF_STMT(BPF_LDX | BPF_MEM, 14),
98209 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98210 - BPF_STMT(BPF_LDX | BPF_MEM, 15),
98211 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98212 - BPF_STMT(BPF_RET | BPF_A, 0),
98213 - },
98214 - CLASSIC | FLAG_NO_DATA,
98215 - { },
98216 - { { 0, 0x2a5a5e5 } },
98217 - },
98218 - {
98219 - "check: SKF_AD_MAX",
98220 - .u.insns = {
98221 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98222 - SKF_AD_OFF + SKF_AD_MAX),
98223 - BPF_STMT(BPF_RET | BPF_A, 0),
98224 - },
98225 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98226 - { },
98227 - { },
98228 - },
98229 - { /* Passes checker but fails during runtime. */
98230 - "LD [SKF_AD_OFF-1]",
98231 - .u.insns = {
98232 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98233 - SKF_AD_OFF - 1),
98234 - BPF_STMT(BPF_RET | BPF_K, 1),
98235 - },
98236 - CLASSIC,
98237 - { },
98238 - { { 1, 0 } },
98239 - },
98240 -};
98241 -
98242 -static struct net_device dev;
98243 -
98244 -static struct sk_buff *populate_skb(char *buf, int size)
98245 -{
98246 - struct sk_buff *skb;
98247 -
98248 - if (size >= MAX_DATA)
98249 - return NULL;
98250 -
98251 - skb = alloc_skb(MAX_DATA, GFP_KERNEL);
98252 - if (!skb)
98253 - return NULL;
98254 -
98255 - memcpy(__skb_put(skb, size), buf, size);
98256 -
98257 - /* Initialize a fake skb with test pattern. */
98258 - skb_reset_mac_header(skb);
98259 - skb->protocol = htons(ETH_P_IP);
98260 - skb->pkt_type = SKB_TYPE;
98261 - skb->mark = SKB_MARK;
98262 - skb->hash = SKB_HASH;
98263 - skb->queue_mapping = SKB_QUEUE_MAP;
98264 - skb->vlan_tci = SKB_VLAN_TCI;
98265 - skb->dev = &dev;
98266 - skb->dev->ifindex = SKB_DEV_IFINDEX;
98267 - skb->dev->type = SKB_DEV_TYPE;
98268 - skb_set_network_header(skb, min(size, ETH_HLEN));
98269 -
98270 - return skb;
98271 -}
98272 -
98273 -static void *generate_test_data(struct bpf_test *test, int sub)
98274 -{
98275 - if (test->aux & FLAG_NO_DATA)
98276 - return NULL;
98277 -
98278 - /* Test case expects an skb, so populate one. Various
98279 - * subtests generate skbs of different sizes based on
98280 - * the same data.
98281 - */
98282 - return populate_skb(test->data, test->test[sub].data_size);
98283 -}
98284 -
98285 -static void release_test_data(const struct bpf_test *test, void *data)
98286 -{
98287 - if (test->aux & FLAG_NO_DATA)
98288 - return;
98289 -
98290 - kfree_skb(data);
98291 -}
98292 -
98293 -static int probe_filter_length(struct sock_filter *fp)
98294 -{
98295 - int len = 0;
98296 -
98297 - for (len = MAX_INSNS - 1; len > 0; --len)
98298 - if (fp[len].code != 0 || fp[len].k != 0)
98299 - break;
98300 -
98301 - return len + 1;
98302 -}
98303 -
98304 -static struct sk_filter *generate_filter(int which, int *err)
98305 -{
98306 - struct sk_filter *fp;
98307 - struct sock_fprog_kern fprog;
98308 - unsigned int flen = probe_filter_length(tests[which].u.insns);
98309 - __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
98310 -
98311 - switch (test_type) {
98312 - case CLASSIC:
98313 - fprog.filter = tests[which].u.insns;
98314 - fprog.len = flen;
98315 -
98316 - *err = sk_unattached_filter_create(&fp, &fprog);
98317 - if (tests[which].aux & FLAG_EXPECTED_FAIL) {
98318 - if (*err == -EINVAL) {
98319 - pr_cont("PASS\n");
98320 - /* Verifier rejected filter as expected. */
98321 - *err = 0;
98322 - return NULL;
98323 - } else {
98324 - pr_cont("UNEXPECTED_PASS\n");
98325 - /* Verifier didn't reject the test that's
98326 - * bad enough, just return!
98327 - */
98328 - *err = -EINVAL;
98329 - return NULL;
98330 - }
98331 - }
98332 - /* We don't expect to fail. */
98333 - if (*err) {
98334 - pr_cont("FAIL to attach err=%d len=%d\n",
98335 - *err, fprog.len);
98336 - return NULL;
98337 - }
98338 - break;
98339 -
98340 - case INTERNAL:
98341 - fp = kzalloc(sk_filter_size(flen), GFP_KERNEL);
98342 - if (fp == NULL) {
98343 - pr_cont("UNEXPECTED_FAIL no memory left\n");
98344 - *err = -ENOMEM;
98345 - return NULL;
98346 - }
98347 -
98348 - fp->len = flen;
98349 - memcpy(fp->insnsi, tests[which].u.insns_int,
98350 - fp->len * sizeof(struct sock_filter_int));
98351 -
98352 - sk_filter_select_runtime(fp);
98353 - break;
98354 - }
98355 -
98356 - *err = 0;
98357 - return fp;
98358 -}
98359 -
98360 -static void release_filter(struct sk_filter *fp, int which)
98361 -{
98362 - __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
98363 -
98364 - switch (test_type) {
98365 - case CLASSIC:
98366 - sk_unattached_filter_destroy(fp);
98367 - break;
98368 - case INTERNAL:
98369 - sk_filter_free(fp);
98370 - break;
98371 - }
98372 -}
98373 -
98374 -static int __run_one(const struct sk_filter *fp, const void *data,
98375 - int runs, u64 *duration)
98376 -{
98377 - u64 start, finish;
98378 - int ret, i;
98379 -
98380 - start = ktime_to_us(ktime_get());
98381 -
98382 - for (i = 0; i < runs; i++)
98383 - ret = SK_RUN_FILTER(fp, data);
98384 -
98385 - finish = ktime_to_us(ktime_get());
98386 -
98387 - *duration = (finish - start) * 1000ULL;
98388 - do_div(*duration, runs);
98389 -
98390 - return ret;
98391 -}
98392 -
98393 -static int run_one(const struct sk_filter *fp, struct bpf_test *test)
98394 -{
98395 - int err_cnt = 0, i, runs = MAX_TESTRUNS;
98396 -
98397 - for (i = 0; i < MAX_SUBTESTS; i++) {
98398 - void *data;
98399 - u64 duration;
98400 - u32 ret;
98401 -
98402 - if (test->test[i].data_size == 0 &&
98403 - test->test[i].result == 0)
98404 - break;
98405 -
98406 - data = generate_test_data(test, i);
98407 - ret = __run_one(fp, data, runs, &duration);
98408 - release_test_data(test, data);
98409 -
98410 - if (ret == test->test[i].result) {
98411 - pr_cont("%lld ", duration);
98412 - } else {
98413 - pr_cont("ret %d != %d ", ret,
98414 - test->test[i].result);
98415 - err_cnt++;
98416 - }
98417 - }
98418 -
98419 - return err_cnt;
98420 -}
98421 -
98422 -static __init int test_bpf(void)
98423 -{
98424 - int i, err_cnt = 0, pass_cnt = 0;
98425 -
98426 - for (i = 0; i < ARRAY_SIZE(tests); i++) {
98427 - struct sk_filter *fp;
98428 - int err;
98429 -
98430 - pr_info("#%d %s ", i, tests[i].descr);
98431 -
98432 - fp = generate_filter(i, &err);
98433 - if (fp == NULL) {
98434 - if (err == 0) {
98435 - pass_cnt++;
98436 - continue;
98437 - }
98438 -
98439 - return err;
98440 - }
98441 - err = run_one(fp, &tests[i]);
98442 - release_filter(fp, i);
98443 -
98444 - if (err) {
98445 - pr_cont("FAIL (%d times)\n", err);
98446 - err_cnt++;
98447 - } else {
98448 - pr_cont("PASS\n");
98449 - pass_cnt++;
98450 - }
98451 - }
98452 -
98453 - pr_info("Summary: %d PASSED, %d FAILED\n", pass_cnt, err_cnt);
98454 - return err_cnt ? -EINVAL : 0;
98455 -}
98456 -
98457 -static int __init test_bpf_init(void)
98458 -{
98459 - return test_bpf();
98460 -}
98461 -
98462 -static void __exit test_bpf_exit(void)
98463 -{
98464 -}
98465 -
98466 -module_init(test_bpf_init);
98467 -module_exit(test_bpf_exit);
98468 -
98469 -MODULE_LICENSE("GPL");
98470 diff --git a/lib/usercopy.c b/lib/usercopy.c
98471 index 4f5b1dd..7cab418 100644
98472 --- a/lib/usercopy.c
98473 +++ b/lib/usercopy.c
98474 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
98475 WARN(1, "Buffer overflow detected!\n");
98476 }
98477 EXPORT_SYMBOL(copy_from_user_overflow);
98478 +
98479 +void copy_to_user_overflow(void)
98480 +{
98481 + WARN(1, "Buffer overflow detected!\n");
98482 +}
98483 +EXPORT_SYMBOL(copy_to_user_overflow);
98484 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
98485 index 6fe2c84..2fe5ec6 100644
98486 --- a/lib/vsprintf.c
98487 +++ b/lib/vsprintf.c
98488 @@ -16,6 +16,9 @@
98489 * - scnprintf and vscnprintf
98490 */
98491
98492 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98493 +#define __INCLUDED_BY_HIDESYM 1
98494 +#endif
98495 #include <stdarg.h>
98496 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
98497 #include <linux/types.h>
98498 @@ -624,7 +627,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
98499 #ifdef CONFIG_KALLSYMS
98500 if (*fmt == 'B')
98501 sprint_backtrace(sym, value);
98502 - else if (*fmt != 'f' && *fmt != 's')
98503 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
98504 sprint_symbol(sym, value);
98505 else
98506 sprint_symbol_no_offset(sym, value);
98507 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
98508 return number(buf, end, num, spec);
98509 }
98510
98511 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98512 +int kptr_restrict __read_mostly = 2;
98513 +#else
98514 int kptr_restrict __read_mostly;
98515 +#endif
98516
98517 /*
98518 * Show a '%p' thing. A kernel extension is that the '%p' is followed
98519 @@ -1194,8 +1201,10 @@ int kptr_restrict __read_mostly;
98520 *
98521 * - 'F' For symbolic function descriptor pointers with offset
98522 * - 'f' For simple symbolic function names without offset
98523 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
98524 * - 'S' For symbolic direct pointers with offset
98525 * - 's' For symbolic direct pointers without offset
98526 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
98527 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
98528 * - 'B' For backtraced symbolic direct pointers with offset
98529 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
98530 @@ -1263,12 +1272,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
98531
98532 if (!ptr && *fmt != 'K') {
98533 /*
98534 - * Print (null) with the same width as a pointer so it makes
98535 + * Print (nil) with the same width as a pointer so it makes
98536 * tabular output look nice.
98537 */
98538 if (spec.field_width == -1)
98539 spec.field_width = default_width;
98540 - return string(buf, end, "(null)", spec);
98541 + return string(buf, end, "(nil)", spec);
98542 }
98543
98544 switch (*fmt) {
98545 @@ -1278,6 +1287,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
98546 /* Fallthrough */
98547 case 'S':
98548 case 's':
98549 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98550 + break;
98551 +#else
98552 + return symbol_string(buf, end, ptr, spec, fmt);
98553 +#endif
98554 + case 'X':
98555 + ptr = dereference_function_descriptor(ptr);
98556 + case 'A':
98557 case 'B':
98558 return symbol_string(buf, end, ptr, spec, fmt);
98559 case 'R':
98560 @@ -1333,6 +1350,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
98561 va_end(va);
98562 return buf;
98563 }
98564 + case 'P':
98565 + break;
98566 case 'K':
98567 /*
98568 * %pK cannot be used in IRQ context because its test
98569 @@ -1390,6 +1409,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
98570 ((const struct file *)ptr)->f_path.dentry,
98571 spec, fmt);
98572 }
98573 +
98574 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98575 + /* 'P' = approved pointers to copy to userland,
98576 + as in the /proc/kallsyms case, as we make it display nothing
98577 + for non-root users, and the real contents for root users
98578 + 'X' = approved simple symbols
98579 + Also ignore 'K' pointers, since we force their NULLing for non-root users
98580 + above
98581 + */
98582 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
98583 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
98584 + dump_stack();
98585 + ptr = NULL;
98586 + }
98587 +#endif
98588 +
98589 spec.flags |= SMALL;
98590 if (spec.field_width == -1) {
98591 spec.field_width = default_width;
98592 @@ -2089,11 +2124,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
98593 typeof(type) value; \
98594 if (sizeof(type) == 8) { \
98595 args = PTR_ALIGN(args, sizeof(u32)); \
98596 - *(u32 *)&value = *(u32 *)args; \
98597 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
98598 + *(u32 *)&value = *(const u32 *)args; \
98599 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
98600 } else { \
98601 args = PTR_ALIGN(args, sizeof(type)); \
98602 - value = *(typeof(type) *)args; \
98603 + value = *(const typeof(type) *)args; \
98604 } \
98605 args += sizeof(type); \
98606 value; \
98607 @@ -2156,7 +2191,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
98608 case FORMAT_TYPE_STR: {
98609 const char *str_arg = args;
98610 args += strlen(str_arg) + 1;
98611 - str = string(str, end, (char *)str_arg, spec);
98612 + str = string(str, end, str_arg, spec);
98613 break;
98614 }
98615
98616 diff --git a/localversion-grsec b/localversion-grsec
98617 new file mode 100644
98618 index 0000000..7cd6065
98619 --- /dev/null
98620 +++ b/localversion-grsec
98621 @@ -0,0 +1 @@
98622 +-grsec
98623 diff --git a/mm/Kconfig b/mm/Kconfig
98624 index 3e9977a..205074f 100644
98625 --- a/mm/Kconfig
98626 +++ b/mm/Kconfig
98627 @@ -333,10 +333,11 @@ config KSM
98628 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
98629
98630 config DEFAULT_MMAP_MIN_ADDR
98631 - int "Low address space to protect from user allocation"
98632 + int "Low address space to protect from user allocation"
98633 depends on MMU
98634 - default 4096
98635 - help
98636 + default 32768 if ALPHA || ARM || PARISC || SPARC32
98637 + default 65536
98638 + help
98639 This is the portion of low virtual memory which should be protected
98640 from userspace allocation. Keeping a user from writing to low pages
98641 can help reduce the impact of kernel NULL pointer bugs.
98642 @@ -367,7 +368,7 @@ config MEMORY_FAILURE
98643
98644 config HWPOISON_INJECT
98645 tristate "HWPoison pages injector"
98646 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
98647 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
98648 select PROC_PAGE_MONITOR
98649
98650 config NOMMU_INITIAL_TRIM_EXCESS
98651 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
98652 index 1706cbb..f89dbca 100644
98653 --- a/mm/backing-dev.c
98654 +++ b/mm/backing-dev.c
98655 @@ -12,7 +12,7 @@
98656 #include <linux/device.h>
98657 #include <trace/events/writeback.h>
98658
98659 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
98660 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
98661
98662 struct backing_dev_info default_backing_dev_info = {
98663 .name = "default",
98664 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
98665 return err;
98666
98667 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
98668 - atomic_long_inc_return(&bdi_seq));
98669 + atomic_long_inc_return_unchecked(&bdi_seq));
98670 if (err) {
98671 bdi_destroy(bdi);
98672 return err;
98673 diff --git a/mm/filemap.c b/mm/filemap.c
98674 index 900edfa..ff056b1 100644
98675 --- a/mm/filemap.c
98676 +++ b/mm/filemap.c
98677 @@ -2074,7 +2074,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
98678 struct address_space *mapping = file->f_mapping;
98679
98680 if (!mapping->a_ops->readpage)
98681 - return -ENOEXEC;
98682 + return -ENODEV;
98683 file_accessed(file);
98684 vma->vm_ops = &generic_file_vm_ops;
98685 return 0;
98686 @@ -2252,6 +2252,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
98687 *pos = i_size_read(inode);
98688
98689 if (limit != RLIM_INFINITY) {
98690 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
98691 if (*pos >= limit) {
98692 send_sig(SIGXFSZ, current, 0);
98693 return -EFBIG;
98694 diff --git a/mm/fremap.c b/mm/fremap.c
98695 index 72b8fa3..c5b39f1 100644
98696 --- a/mm/fremap.c
98697 +++ b/mm/fremap.c
98698 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
98699 retry:
98700 vma = find_vma(mm, start);
98701
98702 +#ifdef CONFIG_PAX_SEGMEXEC
98703 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
98704 + goto out;
98705 +#endif
98706 +
98707 /*
98708 * Make sure the vma is shared, that it supports prefaulting,
98709 * and that the remapped range is valid and fully within
98710 diff --git a/mm/gup.c b/mm/gup.c
98711 index cc5a9e7..d496acf 100644
98712 --- a/mm/gup.c
98713 +++ b/mm/gup.c
98714 @@ -265,11 +265,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
98715 unsigned int fault_flags = 0;
98716 int ret;
98717
98718 - /* For mlock, just skip the stack guard page. */
98719 - if ((*flags & FOLL_MLOCK) &&
98720 - (stack_guard_page_start(vma, address) ||
98721 - stack_guard_page_end(vma, address + PAGE_SIZE)))
98722 - return -ENOENT;
98723 if (*flags & FOLL_WRITE)
98724 fault_flags |= FAULT_FLAG_WRITE;
98725 if (nonblocking)
98726 @@ -424,14 +419,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
98727 if (!(gup_flags & FOLL_FORCE))
98728 gup_flags |= FOLL_NUMA;
98729
98730 - do {
98731 + while (nr_pages) {
98732 struct page *page;
98733 unsigned int foll_flags = gup_flags;
98734 unsigned int page_increm;
98735
98736 /* first iteration or cross vma bound */
98737 if (!vma || start >= vma->vm_end) {
98738 - vma = find_extend_vma(mm, start);
98739 + vma = find_vma(mm, start);
98740 if (!vma && in_gate_area(mm, start)) {
98741 int ret;
98742 ret = get_gate_page(mm, start & PAGE_MASK,
98743 @@ -443,7 +438,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
98744 goto next_page;
98745 }
98746
98747 - if (!vma || check_vma_flags(vma, gup_flags))
98748 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
98749 return i ? : -EFAULT;
98750 if (is_vm_hugetlb_page(vma)) {
98751 i = follow_hugetlb_page(mm, vma, pages, vmas,
98752 @@ -498,7 +493,7 @@ next_page:
98753 i += page_increm;
98754 start += page_increm * PAGE_SIZE;
98755 nr_pages -= page_increm;
98756 - } while (nr_pages);
98757 + }
98758 return i;
98759 }
98760 EXPORT_SYMBOL(__get_user_pages);
98761 diff --git a/mm/highmem.c b/mm/highmem.c
98762 index b32b70c..e512eb0 100644
98763 --- a/mm/highmem.c
98764 +++ b/mm/highmem.c
98765 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
98766 * So no dangers, even with speculative execution.
98767 */
98768 page = pte_page(pkmap_page_table[i]);
98769 + pax_open_kernel();
98770 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
98771 -
98772 + pax_close_kernel();
98773 set_page_address(page, NULL);
98774 need_flush = 1;
98775 }
98776 @@ -198,9 +199,11 @@ start:
98777 }
98778 }
98779 vaddr = PKMAP_ADDR(last_pkmap_nr);
98780 +
98781 + pax_open_kernel();
98782 set_pte_at(&init_mm, vaddr,
98783 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
98784 -
98785 + pax_close_kernel();
98786 pkmap_count[last_pkmap_nr] = 1;
98787 set_page_address(page, (void *)vaddr);
98788
98789 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
98790 index 7a0a73d..d583cca 100644
98791 --- a/mm/hugetlb.c
98792 +++ b/mm/hugetlb.c
98793 @@ -2250,6 +2250,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
98794 struct hstate *h = &default_hstate;
98795 unsigned long tmp;
98796 int ret;
98797 + ctl_table_no_const hugetlb_table;
98798
98799 if (!hugepages_supported())
98800 return -ENOTSUPP;
98801 @@ -2259,9 +2260,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
98802 if (write && hstate_is_gigantic(h) && !gigantic_page_supported())
98803 return -EINVAL;
98804
98805 - table->data = &tmp;
98806 - table->maxlen = sizeof(unsigned long);
98807 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
98808 + hugetlb_table = *table;
98809 + hugetlb_table.data = &tmp;
98810 + hugetlb_table.maxlen = sizeof(unsigned long);
98811 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
98812 if (ret)
98813 goto out;
98814
98815 @@ -2306,6 +2308,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
98816 struct hstate *h = &default_hstate;
98817 unsigned long tmp;
98818 int ret;
98819 + ctl_table_no_const hugetlb_table;
98820
98821 if (!hugepages_supported())
98822 return -ENOTSUPP;
98823 @@ -2315,9 +2318,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
98824 if (write && hstate_is_gigantic(h))
98825 return -EINVAL;
98826
98827 - table->data = &tmp;
98828 - table->maxlen = sizeof(unsigned long);
98829 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
98830 + hugetlb_table = *table;
98831 + hugetlb_table.data = &tmp;
98832 + hugetlb_table.maxlen = sizeof(unsigned long);
98833 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
98834 if (ret)
98835 goto out;
98836
98837 @@ -2798,6 +2802,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
98838 return 1;
98839 }
98840
98841 +#ifdef CONFIG_PAX_SEGMEXEC
98842 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
98843 +{
98844 + struct mm_struct *mm = vma->vm_mm;
98845 + struct vm_area_struct *vma_m;
98846 + unsigned long address_m;
98847 + pte_t *ptep_m;
98848 +
98849 + vma_m = pax_find_mirror_vma(vma);
98850 + if (!vma_m)
98851 + return;
98852 +
98853 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
98854 + address_m = address + SEGMEXEC_TASK_SIZE;
98855 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
98856 + get_page(page_m);
98857 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
98858 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
98859 +}
98860 +#endif
98861 +
98862 /*
98863 * Hugetlb_cow() should be called with page lock of the original hugepage held.
98864 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
98865 @@ -2915,6 +2940,11 @@ retry_avoidcopy:
98866 make_huge_pte(vma, new_page, 1));
98867 page_remove_rmap(old_page);
98868 hugepage_add_new_anon_rmap(new_page, vma, address);
98869 +
98870 +#ifdef CONFIG_PAX_SEGMEXEC
98871 + pax_mirror_huge_pte(vma, address, new_page);
98872 +#endif
98873 +
98874 /* Make the old page be freed below */
98875 new_page = old_page;
98876 }
98877 @@ -3074,6 +3104,10 @@ retry:
98878 && (vma->vm_flags & VM_SHARED)));
98879 set_huge_pte_at(mm, address, ptep, new_pte);
98880
98881 +#ifdef CONFIG_PAX_SEGMEXEC
98882 + pax_mirror_huge_pte(vma, address, page);
98883 +#endif
98884 +
98885 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
98886 /* Optimization, do the COW without a second fault */
98887 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
98888 @@ -3140,6 +3174,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
98889 struct hstate *h = hstate_vma(vma);
98890 struct address_space *mapping;
98891
98892 +#ifdef CONFIG_PAX_SEGMEXEC
98893 + struct vm_area_struct *vma_m;
98894 +#endif
98895 +
98896 address &= huge_page_mask(h);
98897
98898 ptep = huge_pte_offset(mm, address);
98899 @@ -3153,6 +3191,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
98900 VM_FAULT_SET_HINDEX(hstate_index(h));
98901 }
98902
98903 +#ifdef CONFIG_PAX_SEGMEXEC
98904 + vma_m = pax_find_mirror_vma(vma);
98905 + if (vma_m) {
98906 + unsigned long address_m;
98907 +
98908 + if (vma->vm_start > vma_m->vm_start) {
98909 + address_m = address;
98910 + address -= SEGMEXEC_TASK_SIZE;
98911 + vma = vma_m;
98912 + h = hstate_vma(vma);
98913 + } else
98914 + address_m = address + SEGMEXEC_TASK_SIZE;
98915 +
98916 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
98917 + return VM_FAULT_OOM;
98918 + address_m &= HPAGE_MASK;
98919 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
98920 + }
98921 +#endif
98922 +
98923 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
98924 if (!ptep)
98925 return VM_FAULT_OOM;
98926 diff --git a/mm/internal.h b/mm/internal.h
98927 index 7f22a11f..f3c207f 100644
98928 --- a/mm/internal.h
98929 +++ b/mm/internal.h
98930 @@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
98931 * in mm/page_alloc.c
98932 */
98933 extern void __free_pages_bootmem(struct page *page, unsigned int order);
98934 +extern void free_compound_page(struct page *page);
98935 extern void prep_compound_page(struct page *page, unsigned long order);
98936 #ifdef CONFIG_MEMORY_FAILURE
98937 extern bool is_free_buddy_page(struct page *page);
98938 @@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
98939
98940 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
98941 unsigned long, unsigned long,
98942 - unsigned long, unsigned long);
98943 + unsigned long, unsigned long) __intentional_overflow(-1);
98944
98945 extern void set_pageblock_order(void);
98946 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
98947 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
98948 index 7b5dbd1..af0e329 100644
98949 --- a/mm/iov_iter.c
98950 +++ b/mm/iov_iter.c
98951 @@ -173,7 +173,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
98952
98953 while (bytes) {
98954 char __user *buf = iov->iov_base + base;
98955 - int copy = min(bytes, iov->iov_len - base);
98956 + size_t copy = min(bytes, iov->iov_len - base);
98957
98958 base = 0;
98959 left = __copy_from_user_inatomic(vaddr, buf, copy);
98960 @@ -201,7 +201,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
98961
98962 kaddr = kmap_atomic(page);
98963 if (likely(i->nr_segs == 1)) {
98964 - int left;
98965 + size_t left;
98966 char __user *buf = i->iov->iov_base + i->iov_offset;
98967 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
98968 copied = bytes - left;
98969 @@ -231,7 +231,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
98970 * zero-length segments (without overruning the iovec).
98971 */
98972 while (bytes || unlikely(i->count && !iov->iov_len)) {
98973 - int copy;
98974 + size_t copy;
98975
98976 copy = min(bytes, iov->iov_len - base);
98977 BUG_ON(!i->count || i->count < copy);
98978 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
98979 index 3cda50c..032ba634 100644
98980 --- a/mm/kmemleak.c
98981 +++ b/mm/kmemleak.c
98982 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
98983
98984 for (i = 0; i < object->trace_len; i++) {
98985 void *ptr = (void *)object->trace[i];
98986 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
98987 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
98988 }
98989 }
98990
98991 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
98992 return -ENOMEM;
98993 }
98994
98995 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
98996 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
98997 &kmemleak_fops);
98998 if (!dentry)
98999 pr_warning("Failed to create the debugfs kmemleak file\n");
99000 diff --git a/mm/maccess.c b/mm/maccess.c
99001 index d53adf9..03a24bf 100644
99002 --- a/mm/maccess.c
99003 +++ b/mm/maccess.c
99004 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
99005 set_fs(KERNEL_DS);
99006 pagefault_disable();
99007 ret = __copy_from_user_inatomic(dst,
99008 - (__force const void __user *)src, size);
99009 + (const void __force_user *)src, size);
99010 pagefault_enable();
99011 set_fs(old_fs);
99012
99013 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
99014
99015 set_fs(KERNEL_DS);
99016 pagefault_disable();
99017 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
99018 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
99019 pagefault_enable();
99020 set_fs(old_fs);
99021
99022 diff --git a/mm/madvise.c b/mm/madvise.c
99023 index a402f8f..f5e5daa 100644
99024 --- a/mm/madvise.c
99025 +++ b/mm/madvise.c
99026 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
99027 pgoff_t pgoff;
99028 unsigned long new_flags = vma->vm_flags;
99029
99030 +#ifdef CONFIG_PAX_SEGMEXEC
99031 + struct vm_area_struct *vma_m;
99032 +#endif
99033 +
99034 switch (behavior) {
99035 case MADV_NORMAL:
99036 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
99037 @@ -126,6 +130,13 @@ success:
99038 /*
99039 * vm_flags is protected by the mmap_sem held in write mode.
99040 */
99041 +
99042 +#ifdef CONFIG_PAX_SEGMEXEC
99043 + vma_m = pax_find_mirror_vma(vma);
99044 + if (vma_m)
99045 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
99046 +#endif
99047 +
99048 vma->vm_flags = new_flags;
99049
99050 out:
99051 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
99052 struct vm_area_struct **prev,
99053 unsigned long start, unsigned long end)
99054 {
99055 +
99056 +#ifdef CONFIG_PAX_SEGMEXEC
99057 + struct vm_area_struct *vma_m;
99058 +#endif
99059 +
99060 *prev = vma;
99061 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
99062 return -EINVAL;
99063 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
99064 zap_page_range(vma, start, end - start, &details);
99065 } else
99066 zap_page_range(vma, start, end - start, NULL);
99067 +
99068 +#ifdef CONFIG_PAX_SEGMEXEC
99069 + vma_m = pax_find_mirror_vma(vma);
99070 + if (vma_m) {
99071 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
99072 + struct zap_details details = {
99073 + .nonlinear_vma = vma_m,
99074 + .last_index = ULONG_MAX,
99075 + };
99076 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
99077 + } else
99078 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
99079 + }
99080 +#endif
99081 +
99082 return 0;
99083 }
99084
99085 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
99086 if (end < start)
99087 return error;
99088
99089 +#ifdef CONFIG_PAX_SEGMEXEC
99090 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
99091 + if (end > SEGMEXEC_TASK_SIZE)
99092 + return error;
99093 + } else
99094 +#endif
99095 +
99096 + if (end > TASK_SIZE)
99097 + return error;
99098 +
99099 error = 0;
99100 if (end == start)
99101 return error;
99102 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
99103 index a013bc9..a897a14 100644
99104 --- a/mm/memory-failure.c
99105 +++ b/mm/memory-failure.c
99106 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
99107
99108 int sysctl_memory_failure_recovery __read_mostly = 1;
99109
99110 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
99111 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
99112
99113 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
99114
99115 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
99116 pfn, t->comm, t->pid);
99117 si.si_signo = SIGBUS;
99118 si.si_errno = 0;
99119 - si.si_addr = (void *)addr;
99120 + si.si_addr = (void __user *)addr;
99121 #ifdef __ARCH_SI_TRAPNO
99122 si.si_trapno = trapno;
99123 #endif
99124 @@ -791,7 +791,7 @@ static struct page_state {
99125 unsigned long res;
99126 char *msg;
99127 int (*action)(struct page *p, unsigned long pfn);
99128 -} error_states[] = {
99129 +} __do_const error_states[] = {
99130 { reserved, reserved, "reserved kernel", me_kernel },
99131 /*
99132 * free pages are specially detected outside this table:
99133 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
99134 nr_pages = 1 << compound_order(hpage);
99135 else /* normal page or thp */
99136 nr_pages = 1;
99137 - atomic_long_add(nr_pages, &num_poisoned_pages);
99138 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
99139
99140 /*
99141 * We need/can do nothing about count=0 pages.
99142 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
99143 if (PageHWPoison(hpage)) {
99144 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
99145 || (p != hpage && TestSetPageHWPoison(hpage))) {
99146 - atomic_long_sub(nr_pages, &num_poisoned_pages);
99147 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
99148 unlock_page(hpage);
99149 return 0;
99150 }
99151 @@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
99152 */
99153 if (!PageHWPoison(p)) {
99154 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
99155 - atomic_long_sub(nr_pages, &num_poisoned_pages);
99156 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
99157 put_page(hpage);
99158 res = 0;
99159 goto out;
99160 }
99161 if (hwpoison_filter(p)) {
99162 if (TestClearPageHWPoison(p))
99163 - atomic_long_sub(nr_pages, &num_poisoned_pages);
99164 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
99165 unlock_page(hpage);
99166 put_page(hpage);
99167 return 0;
99168 @@ -1423,7 +1423,7 @@ int unpoison_memory(unsigned long pfn)
99169 return 0;
99170 }
99171 if (TestClearPageHWPoison(p))
99172 - atomic_long_dec(&num_poisoned_pages);
99173 + atomic_long_dec_unchecked(&num_poisoned_pages);
99174 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
99175 return 0;
99176 }
99177 @@ -1437,7 +1437,7 @@ int unpoison_memory(unsigned long pfn)
99178 */
99179 if (TestClearPageHWPoison(page)) {
99180 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
99181 - atomic_long_sub(nr_pages, &num_poisoned_pages);
99182 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
99183 freeit = 1;
99184 if (PageHuge(page))
99185 clear_page_hwpoison_huge_page(page);
99186 @@ -1562,11 +1562,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
99187 if (PageHuge(page)) {
99188 set_page_hwpoison_huge_page(hpage);
99189 dequeue_hwpoisoned_huge_page(hpage);
99190 - atomic_long_add(1 << compound_order(hpage),
99191 + atomic_long_add_unchecked(1 << compound_order(hpage),
99192 &num_poisoned_pages);
99193 } else {
99194 SetPageHWPoison(page);
99195 - atomic_long_inc(&num_poisoned_pages);
99196 + atomic_long_inc_unchecked(&num_poisoned_pages);
99197 }
99198 }
99199 return ret;
99200 @@ -1605,7 +1605,7 @@ static int __soft_offline_page(struct page *page, int flags)
99201 put_page(page);
99202 pr_info("soft_offline: %#lx: invalidated\n", pfn);
99203 SetPageHWPoison(page);
99204 - atomic_long_inc(&num_poisoned_pages);
99205 + atomic_long_inc_unchecked(&num_poisoned_pages);
99206 return 0;
99207 }
99208
99209 @@ -1656,7 +1656,7 @@ static int __soft_offline_page(struct page *page, int flags)
99210 if (!is_free_buddy_page(page))
99211 pr_info("soft offline: %#lx: page leaked\n",
99212 pfn);
99213 - atomic_long_inc(&num_poisoned_pages);
99214 + atomic_long_inc_unchecked(&num_poisoned_pages);
99215 }
99216 } else {
99217 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
99218 @@ -1726,11 +1726,11 @@ int soft_offline_page(struct page *page, int flags)
99219 if (PageHuge(page)) {
99220 set_page_hwpoison_huge_page(hpage);
99221 dequeue_hwpoisoned_huge_page(hpage);
99222 - atomic_long_add(1 << compound_order(hpage),
99223 + atomic_long_add_unchecked(1 << compound_order(hpage),
99224 &num_poisoned_pages);
99225 } else {
99226 SetPageHWPoison(page);
99227 - atomic_long_inc(&num_poisoned_pages);
99228 + atomic_long_inc_unchecked(&num_poisoned_pages);
99229 }
99230 }
99231 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
99232 diff --git a/mm/memory.c b/mm/memory.c
99233 index 0a21f3d..babeaec 100644
99234 --- a/mm/memory.c
99235 +++ b/mm/memory.c
99236 @@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
99237 free_pte_range(tlb, pmd, addr);
99238 } while (pmd++, addr = next, addr != end);
99239
99240 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
99241 start &= PUD_MASK;
99242 if (start < floor)
99243 return;
99244 @@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
99245 pmd = pmd_offset(pud, start);
99246 pud_clear(pud);
99247 pmd_free_tlb(tlb, pmd, start);
99248 +#endif
99249 +
99250 }
99251
99252 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
99253 @@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
99254 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
99255 } while (pud++, addr = next, addr != end);
99256
99257 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
99258 start &= PGDIR_MASK;
99259 if (start < floor)
99260 return;
99261 @@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
99262 pud = pud_offset(pgd, start);
99263 pgd_clear(pgd);
99264 pud_free_tlb(tlb, pud, start);
99265 +#endif
99266 +
99267 }
99268
99269 /*
99270 @@ -1500,6 +1506,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
99271 page_add_file_rmap(page);
99272 set_pte_at(mm, addr, pte, mk_pte(page, prot));
99273
99274 +#ifdef CONFIG_PAX_SEGMEXEC
99275 + pax_mirror_file_pte(vma, addr, page, ptl);
99276 +#endif
99277 +
99278 retval = 0;
99279 pte_unmap_unlock(pte, ptl);
99280 return retval;
99281 @@ -1544,9 +1554,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
99282 if (!page_count(page))
99283 return -EINVAL;
99284 if (!(vma->vm_flags & VM_MIXEDMAP)) {
99285 +
99286 +#ifdef CONFIG_PAX_SEGMEXEC
99287 + struct vm_area_struct *vma_m;
99288 +#endif
99289 +
99290 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
99291 BUG_ON(vma->vm_flags & VM_PFNMAP);
99292 vma->vm_flags |= VM_MIXEDMAP;
99293 +
99294 +#ifdef CONFIG_PAX_SEGMEXEC
99295 + vma_m = pax_find_mirror_vma(vma);
99296 + if (vma_m)
99297 + vma_m->vm_flags |= VM_MIXEDMAP;
99298 +#endif
99299 +
99300 }
99301 return insert_page(vma, addr, page, vma->vm_page_prot);
99302 }
99303 @@ -1629,6 +1651,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
99304 unsigned long pfn)
99305 {
99306 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
99307 + BUG_ON(vma->vm_mirror);
99308
99309 if (addr < vma->vm_start || addr >= vma->vm_end)
99310 return -EFAULT;
99311 @@ -1876,7 +1899,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
99312
99313 BUG_ON(pud_huge(*pud));
99314
99315 - pmd = pmd_alloc(mm, pud, addr);
99316 + pmd = (mm == &init_mm) ?
99317 + pmd_alloc_kernel(mm, pud, addr) :
99318 + pmd_alloc(mm, pud, addr);
99319 if (!pmd)
99320 return -ENOMEM;
99321 do {
99322 @@ -1896,7 +1921,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
99323 unsigned long next;
99324 int err;
99325
99326 - pud = pud_alloc(mm, pgd, addr);
99327 + pud = (mm == &init_mm) ?
99328 + pud_alloc_kernel(mm, pgd, addr) :
99329 + pud_alloc(mm, pgd, addr);
99330 if (!pud)
99331 return -ENOMEM;
99332 do {
99333 @@ -2018,6 +2045,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
99334 return ret;
99335 }
99336
99337 +#ifdef CONFIG_PAX_SEGMEXEC
99338 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
99339 +{
99340 + struct mm_struct *mm = vma->vm_mm;
99341 + spinlock_t *ptl;
99342 + pte_t *pte, entry;
99343 +
99344 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
99345 + entry = *pte;
99346 + if (!pte_present(entry)) {
99347 + if (!pte_none(entry)) {
99348 + BUG_ON(pte_file(entry));
99349 + free_swap_and_cache(pte_to_swp_entry(entry));
99350 + pte_clear_not_present_full(mm, address, pte, 0);
99351 + }
99352 + } else {
99353 + struct page *page;
99354 +
99355 + flush_cache_page(vma, address, pte_pfn(entry));
99356 + entry = ptep_clear_flush(vma, address, pte);
99357 + BUG_ON(pte_dirty(entry));
99358 + page = vm_normal_page(vma, address, entry);
99359 + if (page) {
99360 + update_hiwater_rss(mm);
99361 + if (PageAnon(page))
99362 + dec_mm_counter_fast(mm, MM_ANONPAGES);
99363 + else
99364 + dec_mm_counter_fast(mm, MM_FILEPAGES);
99365 + page_remove_rmap(page);
99366 + page_cache_release(page);
99367 + }
99368 + }
99369 + pte_unmap_unlock(pte, ptl);
99370 +}
99371 +
99372 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
99373 + *
99374 + * the ptl of the lower mapped page is held on entry and is not released on exit
99375 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
99376 + */
99377 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
99378 +{
99379 + struct mm_struct *mm = vma->vm_mm;
99380 + unsigned long address_m;
99381 + spinlock_t *ptl_m;
99382 + struct vm_area_struct *vma_m;
99383 + pmd_t *pmd_m;
99384 + pte_t *pte_m, entry_m;
99385 +
99386 + BUG_ON(!page_m || !PageAnon(page_m));
99387 +
99388 + vma_m = pax_find_mirror_vma(vma);
99389 + if (!vma_m)
99390 + return;
99391 +
99392 + BUG_ON(!PageLocked(page_m));
99393 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
99394 + address_m = address + SEGMEXEC_TASK_SIZE;
99395 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
99396 + pte_m = pte_offset_map(pmd_m, address_m);
99397 + ptl_m = pte_lockptr(mm, pmd_m);
99398 + if (ptl != ptl_m) {
99399 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
99400 + if (!pte_none(*pte_m))
99401 + goto out;
99402 + }
99403 +
99404 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
99405 + page_cache_get(page_m);
99406 + page_add_anon_rmap(page_m, vma_m, address_m);
99407 + inc_mm_counter_fast(mm, MM_ANONPAGES);
99408 + set_pte_at(mm, address_m, pte_m, entry_m);
99409 + update_mmu_cache(vma_m, address_m, pte_m);
99410 +out:
99411 + if (ptl != ptl_m)
99412 + spin_unlock(ptl_m);
99413 + pte_unmap(pte_m);
99414 + unlock_page(page_m);
99415 +}
99416 +
99417 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
99418 +{
99419 + struct mm_struct *mm = vma->vm_mm;
99420 + unsigned long address_m;
99421 + spinlock_t *ptl_m;
99422 + struct vm_area_struct *vma_m;
99423 + pmd_t *pmd_m;
99424 + pte_t *pte_m, entry_m;
99425 +
99426 + BUG_ON(!page_m || PageAnon(page_m));
99427 +
99428 + vma_m = pax_find_mirror_vma(vma);
99429 + if (!vma_m)
99430 + return;
99431 +
99432 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
99433 + address_m = address + SEGMEXEC_TASK_SIZE;
99434 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
99435 + pte_m = pte_offset_map(pmd_m, address_m);
99436 + ptl_m = pte_lockptr(mm, pmd_m);
99437 + if (ptl != ptl_m) {
99438 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
99439 + if (!pte_none(*pte_m))
99440 + goto out;
99441 + }
99442 +
99443 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
99444 + page_cache_get(page_m);
99445 + page_add_file_rmap(page_m);
99446 + inc_mm_counter_fast(mm, MM_FILEPAGES);
99447 + set_pte_at(mm, address_m, pte_m, entry_m);
99448 + update_mmu_cache(vma_m, address_m, pte_m);
99449 +out:
99450 + if (ptl != ptl_m)
99451 + spin_unlock(ptl_m);
99452 + pte_unmap(pte_m);
99453 +}
99454 +
99455 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
99456 +{
99457 + struct mm_struct *mm = vma->vm_mm;
99458 + unsigned long address_m;
99459 + spinlock_t *ptl_m;
99460 + struct vm_area_struct *vma_m;
99461 + pmd_t *pmd_m;
99462 + pte_t *pte_m, entry_m;
99463 +
99464 + vma_m = pax_find_mirror_vma(vma);
99465 + if (!vma_m)
99466 + return;
99467 +
99468 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
99469 + address_m = address + SEGMEXEC_TASK_SIZE;
99470 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
99471 + pte_m = pte_offset_map(pmd_m, address_m);
99472 + ptl_m = pte_lockptr(mm, pmd_m);
99473 + if (ptl != ptl_m) {
99474 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
99475 + if (!pte_none(*pte_m))
99476 + goto out;
99477 + }
99478 +
99479 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
99480 + set_pte_at(mm, address_m, pte_m, entry_m);
99481 +out:
99482 + if (ptl != ptl_m)
99483 + spin_unlock(ptl_m);
99484 + pte_unmap(pte_m);
99485 +}
99486 +
99487 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
99488 +{
99489 + struct page *page_m;
99490 + pte_t entry;
99491 +
99492 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
99493 + goto out;
99494 +
99495 + entry = *pte;
99496 + page_m = vm_normal_page(vma, address, entry);
99497 + if (!page_m)
99498 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
99499 + else if (PageAnon(page_m)) {
99500 + if (pax_find_mirror_vma(vma)) {
99501 + pte_unmap_unlock(pte, ptl);
99502 + lock_page(page_m);
99503 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
99504 + if (pte_same(entry, *pte))
99505 + pax_mirror_anon_pte(vma, address, page_m, ptl);
99506 + else
99507 + unlock_page(page_m);
99508 + }
99509 + } else
99510 + pax_mirror_file_pte(vma, address, page_m, ptl);
99511 +
99512 +out:
99513 + pte_unmap_unlock(pte, ptl);
99514 +}
99515 +#endif
99516 +
99517 /*
99518 * This routine handles present pages, when users try to write
99519 * to a shared page. It is done by copying the page to a new address
99520 @@ -2215,6 +2422,12 @@ gotten:
99521 */
99522 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
99523 if (likely(pte_same(*page_table, orig_pte))) {
99524 +
99525 +#ifdef CONFIG_PAX_SEGMEXEC
99526 + if (pax_find_mirror_vma(vma))
99527 + BUG_ON(!trylock_page(new_page));
99528 +#endif
99529 +
99530 if (old_page) {
99531 if (!PageAnon(old_page)) {
99532 dec_mm_counter_fast(mm, MM_FILEPAGES);
99533 @@ -2266,6 +2479,10 @@ gotten:
99534 page_remove_rmap(old_page);
99535 }
99536
99537 +#ifdef CONFIG_PAX_SEGMEXEC
99538 + pax_mirror_anon_pte(vma, address, new_page, ptl);
99539 +#endif
99540 +
99541 /* Free the old page.. */
99542 new_page = old_page;
99543 ret |= VM_FAULT_WRITE;
99544 @@ -2539,6 +2756,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
99545 swap_free(entry);
99546 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
99547 try_to_free_swap(page);
99548 +
99549 +#ifdef CONFIG_PAX_SEGMEXEC
99550 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
99551 +#endif
99552 +
99553 unlock_page(page);
99554 if (page != swapcache) {
99555 /*
99556 @@ -2562,6 +2784,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
99557
99558 /* No need to invalidate - it was non-present before */
99559 update_mmu_cache(vma, address, page_table);
99560 +
99561 +#ifdef CONFIG_PAX_SEGMEXEC
99562 + pax_mirror_anon_pte(vma, address, page, ptl);
99563 +#endif
99564 +
99565 unlock:
99566 pte_unmap_unlock(page_table, ptl);
99567 out:
99568 @@ -2581,40 +2808,6 @@ out_release:
99569 }
99570
99571 /*
99572 - * This is like a special single-page "expand_{down|up}wards()",
99573 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
99574 - * doesn't hit another vma.
99575 - */
99576 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
99577 -{
99578 - address &= PAGE_MASK;
99579 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
99580 - struct vm_area_struct *prev = vma->vm_prev;
99581 -
99582 - /*
99583 - * Is there a mapping abutting this one below?
99584 - *
99585 - * That's only ok if it's the same stack mapping
99586 - * that has gotten split..
99587 - */
99588 - if (prev && prev->vm_end == address)
99589 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
99590 -
99591 - expand_downwards(vma, address - PAGE_SIZE);
99592 - }
99593 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
99594 - struct vm_area_struct *next = vma->vm_next;
99595 -
99596 - /* As VM_GROWSDOWN but s/below/above/ */
99597 - if (next && next->vm_start == address + PAGE_SIZE)
99598 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
99599 -
99600 - expand_upwards(vma, address + PAGE_SIZE);
99601 - }
99602 - return 0;
99603 -}
99604 -
99605 -/*
99606 * We enter with non-exclusive mmap_sem (to exclude vma changes,
99607 * but allow concurrent faults), and pte mapped but not yet locked.
99608 * We return with mmap_sem still held, but pte unmapped and unlocked.
99609 @@ -2623,27 +2816,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
99610 unsigned long address, pte_t *page_table, pmd_t *pmd,
99611 unsigned int flags)
99612 {
99613 - struct page *page;
99614 + struct page *page = NULL;
99615 spinlock_t *ptl;
99616 pte_t entry;
99617
99618 - pte_unmap(page_table);
99619 -
99620 - /* Check if we need to add a guard page to the stack */
99621 - if (check_stack_guard_page(vma, address) < 0)
99622 - return VM_FAULT_SIGBUS;
99623 -
99624 - /* Use the zero-page for reads */
99625 if (!(flags & FAULT_FLAG_WRITE)) {
99626 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
99627 vma->vm_page_prot));
99628 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
99629 + ptl = pte_lockptr(mm, pmd);
99630 + spin_lock(ptl);
99631 if (!pte_none(*page_table))
99632 goto unlock;
99633 goto setpte;
99634 }
99635
99636 /* Allocate our own private page. */
99637 + pte_unmap(page_table);
99638 +
99639 if (unlikely(anon_vma_prepare(vma)))
99640 goto oom;
99641 page = alloc_zeroed_user_highpage_movable(vma, address);
99642 @@ -2667,6 +2856,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
99643 if (!pte_none(*page_table))
99644 goto release;
99645
99646 +#ifdef CONFIG_PAX_SEGMEXEC
99647 + if (pax_find_mirror_vma(vma))
99648 + BUG_ON(!trylock_page(page));
99649 +#endif
99650 +
99651 inc_mm_counter_fast(mm, MM_ANONPAGES);
99652 page_add_new_anon_rmap(page, vma, address);
99653 setpte:
99654 @@ -2674,6 +2868,12 @@ setpte:
99655
99656 /* No need to invalidate - it was non-present before */
99657 update_mmu_cache(vma, address, page_table);
99658 +
99659 +#ifdef CONFIG_PAX_SEGMEXEC
99660 + if (page)
99661 + pax_mirror_anon_pte(vma, address, page, ptl);
99662 +#endif
99663 +
99664 unlock:
99665 pte_unmap_unlock(page_table, ptl);
99666 return 0;
99667 @@ -2905,6 +3105,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
99668 return ret;
99669 }
99670 do_set_pte(vma, address, fault_page, pte, false, false);
99671 +
99672 +#ifdef CONFIG_PAX_SEGMEXEC
99673 + pax_mirror_file_pte(vma, address, fault_page, ptl);
99674 +#endif
99675 +
99676 unlock_page(fault_page);
99677 unlock_out:
99678 pte_unmap_unlock(pte, ptl);
99679 @@ -2946,7 +3151,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
99680 page_cache_release(fault_page);
99681 goto uncharge_out;
99682 }
99683 +
99684 +#ifdef CONFIG_PAX_SEGMEXEC
99685 + if (pax_find_mirror_vma(vma))
99686 + BUG_ON(!trylock_page(new_page));
99687 +#endif
99688 +
99689 do_set_pte(vma, address, new_page, pte, true, true);
99690 +
99691 +#ifdef CONFIG_PAX_SEGMEXEC
99692 + pax_mirror_anon_pte(vma, address, new_page, ptl);
99693 +#endif
99694 +
99695 pte_unmap_unlock(pte, ptl);
99696 unlock_page(fault_page);
99697 page_cache_release(fault_page);
99698 @@ -2994,6 +3210,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
99699 return ret;
99700 }
99701 do_set_pte(vma, address, fault_page, pte, true, false);
99702 +
99703 +#ifdef CONFIG_PAX_SEGMEXEC
99704 + pax_mirror_file_pte(vma, address, fault_page, ptl);
99705 +#endif
99706 +
99707 pte_unmap_unlock(pte, ptl);
99708
99709 if (set_page_dirty(fault_page))
99710 @@ -3224,6 +3445,12 @@ static int handle_pte_fault(struct mm_struct *mm,
99711 if (flags & FAULT_FLAG_WRITE)
99712 flush_tlb_fix_spurious_fault(vma, address);
99713 }
99714 +
99715 +#ifdef CONFIG_PAX_SEGMEXEC
99716 + pax_mirror_pte(vma, address, pte, pmd, ptl);
99717 + return 0;
99718 +#endif
99719 +
99720 unlock:
99721 pte_unmap_unlock(pte, ptl);
99722 return 0;
99723 @@ -3240,9 +3467,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
99724 pmd_t *pmd;
99725 pte_t *pte;
99726
99727 +#ifdef CONFIG_PAX_SEGMEXEC
99728 + struct vm_area_struct *vma_m;
99729 +#endif
99730 +
99731 if (unlikely(is_vm_hugetlb_page(vma)))
99732 return hugetlb_fault(mm, vma, address, flags);
99733
99734 +#ifdef CONFIG_PAX_SEGMEXEC
99735 + vma_m = pax_find_mirror_vma(vma);
99736 + if (vma_m) {
99737 + unsigned long address_m;
99738 + pgd_t *pgd_m;
99739 + pud_t *pud_m;
99740 + pmd_t *pmd_m;
99741 +
99742 + if (vma->vm_start > vma_m->vm_start) {
99743 + address_m = address;
99744 + address -= SEGMEXEC_TASK_SIZE;
99745 + vma = vma_m;
99746 + } else
99747 + address_m = address + SEGMEXEC_TASK_SIZE;
99748 +
99749 + pgd_m = pgd_offset(mm, address_m);
99750 + pud_m = pud_alloc(mm, pgd_m, address_m);
99751 + if (!pud_m)
99752 + return VM_FAULT_OOM;
99753 + pmd_m = pmd_alloc(mm, pud_m, address_m);
99754 + if (!pmd_m)
99755 + return VM_FAULT_OOM;
99756 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
99757 + return VM_FAULT_OOM;
99758 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
99759 + }
99760 +#endif
99761 +
99762 pgd = pgd_offset(mm, address);
99763 pud = pud_alloc(mm, pgd, address);
99764 if (!pud)
99765 @@ -3370,6 +3629,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
99766 spin_unlock(&mm->page_table_lock);
99767 return 0;
99768 }
99769 +
99770 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
99771 +{
99772 + pud_t *new = pud_alloc_one(mm, address);
99773 + if (!new)
99774 + return -ENOMEM;
99775 +
99776 + smp_wmb(); /* See comment in __pte_alloc */
99777 +
99778 + spin_lock(&mm->page_table_lock);
99779 + if (pgd_present(*pgd)) /* Another has populated it */
99780 + pud_free(mm, new);
99781 + else
99782 + pgd_populate_kernel(mm, pgd, new);
99783 + spin_unlock(&mm->page_table_lock);
99784 + return 0;
99785 +}
99786 #endif /* __PAGETABLE_PUD_FOLDED */
99787
99788 #ifndef __PAGETABLE_PMD_FOLDED
99789 @@ -3400,6 +3676,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
99790 spin_unlock(&mm->page_table_lock);
99791 return 0;
99792 }
99793 +
99794 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
99795 +{
99796 + pmd_t *new = pmd_alloc_one(mm, address);
99797 + if (!new)
99798 + return -ENOMEM;
99799 +
99800 + smp_wmb(); /* See comment in __pte_alloc */
99801 +
99802 + spin_lock(&mm->page_table_lock);
99803 +#ifndef __ARCH_HAS_4LEVEL_HACK
99804 + if (pud_present(*pud)) /* Another has populated it */
99805 + pmd_free(mm, new);
99806 + else
99807 + pud_populate_kernel(mm, pud, new);
99808 +#else
99809 + if (pgd_present(*pud)) /* Another has populated it */
99810 + pmd_free(mm, new);
99811 + else
99812 + pgd_populate_kernel(mm, pud, new);
99813 +#endif /* __ARCH_HAS_4LEVEL_HACK */
99814 + spin_unlock(&mm->page_table_lock);
99815 + return 0;
99816 +}
99817 #endif /* __PAGETABLE_PMD_FOLDED */
99818
99819 #if !defined(__HAVE_ARCH_GATE_AREA)
99820 @@ -3413,7 +3713,7 @@ static int __init gate_vma_init(void)
99821 gate_vma.vm_start = FIXADDR_USER_START;
99822 gate_vma.vm_end = FIXADDR_USER_END;
99823 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
99824 - gate_vma.vm_page_prot = __P101;
99825 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
99826
99827 return 0;
99828 }
99829 @@ -3547,8 +3847,8 @@ out:
99830 return ret;
99831 }
99832
99833 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
99834 - void *buf, int len, int write)
99835 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
99836 + void *buf, size_t len, int write)
99837 {
99838 resource_size_t phys_addr;
99839 unsigned long prot = 0;
99840 @@ -3574,8 +3874,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
99841 * Access another process' address space as given in mm. If non-NULL, use the
99842 * given task for page fault accounting.
99843 */
99844 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
99845 - unsigned long addr, void *buf, int len, int write)
99846 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
99847 + unsigned long addr, void *buf, size_t len, int write)
99848 {
99849 struct vm_area_struct *vma;
99850 void *old_buf = buf;
99851 @@ -3583,7 +3883,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
99852 down_read(&mm->mmap_sem);
99853 /* ignore errors, just check how much was successfully transferred */
99854 while (len) {
99855 - int bytes, ret, offset;
99856 + ssize_t bytes, ret, offset;
99857 void *maddr;
99858 struct page *page = NULL;
99859
99860 @@ -3642,8 +3942,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
99861 *
99862 * The caller must hold a reference on @mm.
99863 */
99864 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
99865 - void *buf, int len, int write)
99866 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
99867 + void *buf, size_t len, int write)
99868 {
99869 return __access_remote_vm(NULL, mm, addr, buf, len, write);
99870 }
99871 @@ -3653,11 +3953,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
99872 * Source/target buffer must be kernel space,
99873 * Do not walk the page table directly, use get_user_pages
99874 */
99875 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
99876 - void *buf, int len, int write)
99877 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
99878 + void *buf, size_t len, int write)
99879 {
99880 struct mm_struct *mm;
99881 - int ret;
99882 + ssize_t ret;
99883
99884 mm = get_task_mm(tsk);
99885 if (!mm)
99886 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
99887 index 8f5330d..b41914b 100644
99888 --- a/mm/mempolicy.c
99889 +++ b/mm/mempolicy.c
99890 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
99891 unsigned long vmstart;
99892 unsigned long vmend;
99893
99894 +#ifdef CONFIG_PAX_SEGMEXEC
99895 + struct vm_area_struct *vma_m;
99896 +#endif
99897 +
99898 vma = find_vma(mm, start);
99899 if (!vma || vma->vm_start > start)
99900 return -EFAULT;
99901 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
99902 err = vma_replace_policy(vma, new_pol);
99903 if (err)
99904 goto out;
99905 +
99906 +#ifdef CONFIG_PAX_SEGMEXEC
99907 + vma_m = pax_find_mirror_vma(vma);
99908 + if (vma_m) {
99909 + err = vma_replace_policy(vma_m, new_pol);
99910 + if (err)
99911 + goto out;
99912 + }
99913 +#endif
99914 +
99915 }
99916
99917 out:
99918 @@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
99919
99920 if (end < start)
99921 return -EINVAL;
99922 +
99923 +#ifdef CONFIG_PAX_SEGMEXEC
99924 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
99925 + if (end > SEGMEXEC_TASK_SIZE)
99926 + return -EINVAL;
99927 + } else
99928 +#endif
99929 +
99930 + if (end > TASK_SIZE)
99931 + return -EINVAL;
99932 +
99933 if (end == start)
99934 return 0;
99935
99936 @@ -1450,8 +1475,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
99937 */
99938 tcred = __task_cred(task);
99939 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
99940 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
99941 - !capable(CAP_SYS_NICE)) {
99942 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
99943 rcu_read_unlock();
99944 err = -EPERM;
99945 goto out_put;
99946 @@ -1482,6 +1506,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
99947 goto out;
99948 }
99949
99950 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
99951 + if (mm != current->mm &&
99952 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
99953 + mmput(mm);
99954 + err = -EPERM;
99955 + goto out;
99956 + }
99957 +#endif
99958 +
99959 err = do_migrate_pages(mm, old, new,
99960 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
99961
99962 diff --git a/mm/migrate.c b/mm/migrate.c
99963 index be6dbf9..febb8ec 100644
99964 --- a/mm/migrate.c
99965 +++ b/mm/migrate.c
99966 @@ -1506,8 +1506,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
99967 */
99968 tcred = __task_cred(task);
99969 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
99970 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
99971 - !capable(CAP_SYS_NICE)) {
99972 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
99973 rcu_read_unlock();
99974 err = -EPERM;
99975 goto out;
99976 diff --git a/mm/mlock.c b/mm/mlock.c
99977 index b1eb536..091d154 100644
99978 --- a/mm/mlock.c
99979 +++ b/mm/mlock.c
99980 @@ -14,6 +14,7 @@
99981 #include <linux/pagevec.h>
99982 #include <linux/mempolicy.h>
99983 #include <linux/syscalls.h>
99984 +#include <linux/security.h>
99985 #include <linux/sched.h>
99986 #include <linux/export.h>
99987 #include <linux/rmap.h>
99988 @@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
99989 {
99990 unsigned long nstart, end, tmp;
99991 struct vm_area_struct * vma, * prev;
99992 - int error;
99993 + int error = 0;
99994
99995 VM_BUG_ON(start & ~PAGE_MASK);
99996 VM_BUG_ON(len != PAGE_ALIGN(len));
99997 @@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
99998 return -EINVAL;
99999 if (end == start)
100000 return 0;
100001 + if (end > TASK_SIZE)
100002 + return -EINVAL;
100003 +
100004 vma = find_vma(current->mm, start);
100005 if (!vma || vma->vm_start > start)
100006 return -ENOMEM;
100007 @@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
100008 for (nstart = start ; ; ) {
100009 vm_flags_t newflags;
100010
100011 +#ifdef CONFIG_PAX_SEGMEXEC
100012 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
100013 + break;
100014 +#endif
100015 +
100016 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
100017
100018 newflags = vma->vm_flags & ~VM_LOCKED;
100019 @@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
100020 locked += current->mm->locked_vm;
100021
100022 /* check against resource limits */
100023 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
100024 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
100025 error = do_mlock(start, len, 1);
100026
100027 @@ -776,6 +786,11 @@ static int do_mlockall(int flags)
100028 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
100029 vm_flags_t newflags;
100030
100031 +#ifdef CONFIG_PAX_SEGMEXEC
100032 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
100033 + break;
100034 +#endif
100035 +
100036 newflags = vma->vm_flags & ~VM_LOCKED;
100037 if (flags & MCL_CURRENT)
100038 newflags |= VM_LOCKED;
100039 @@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
100040 lock_limit >>= PAGE_SHIFT;
100041
100042 ret = -ENOMEM;
100043 +
100044 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
100045 +
100046 down_write(&current->mm->mmap_sem);
100047 -
100048 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
100049 capable(CAP_IPC_LOCK))
100050 ret = do_mlockall(flags);
100051 diff --git a/mm/mmap.c b/mm/mmap.c
100052 index 129b847..fbed804 100644
100053 --- a/mm/mmap.c
100054 +++ b/mm/mmap.c
100055 @@ -40,6 +40,7 @@
100056 #include <linux/notifier.h>
100057 #include <linux/memory.h>
100058 #include <linux/printk.h>
100059 +#include <linux/random.h>
100060
100061 #include <asm/uaccess.h>
100062 #include <asm/cacheflush.h>
100063 @@ -56,6 +57,16 @@
100064 #define arch_rebalance_pgtables(addr, len) (addr)
100065 #endif
100066
100067 +static inline void verify_mm_writelocked(struct mm_struct *mm)
100068 +{
100069 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
100070 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
100071 + up_read(&mm->mmap_sem);
100072 + BUG();
100073 + }
100074 +#endif
100075 +}
100076 +
100077 static void unmap_region(struct mm_struct *mm,
100078 struct vm_area_struct *vma, struct vm_area_struct *prev,
100079 unsigned long start, unsigned long end);
100080 @@ -75,16 +86,25 @@ static void unmap_region(struct mm_struct *mm,
100081 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
100082 *
100083 */
100084 -pgprot_t protection_map[16] = {
100085 +pgprot_t protection_map[16] __read_only = {
100086 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
100087 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
100088 };
100089
100090 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
100091 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
100092 {
100093 - return __pgprot(pgprot_val(protection_map[vm_flags &
100094 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
100095 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
100096 pgprot_val(arch_vm_get_page_prot(vm_flags)));
100097 +
100098 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
100099 + if (!(__supported_pte_mask & _PAGE_NX) &&
100100 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
100101 + (vm_flags & (VM_READ | VM_WRITE)))
100102 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
100103 +#endif
100104 +
100105 + return prot;
100106 }
100107 EXPORT_SYMBOL(vm_get_page_prot);
100108
100109 @@ -94,6 +114,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
100110 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
100111 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
100112 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
100113 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
100114 /*
100115 * Make sure vm_committed_as in one cacheline and not cacheline shared with
100116 * other variables. It can be updated by several CPUs frequently.
100117 @@ -250,6 +271,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
100118 struct vm_area_struct *next = vma->vm_next;
100119
100120 might_sleep();
100121 + BUG_ON(vma->vm_mirror);
100122 if (vma->vm_ops && vma->vm_ops->close)
100123 vma->vm_ops->close(vma);
100124 if (vma->vm_file)
100125 @@ -294,6 +316,12 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
100126 * not page aligned -Ram Gupta
100127 */
100128 rlim = rlimit(RLIMIT_DATA);
100129 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
100130 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
100131 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
100132 + rlim = 4096 * PAGE_SIZE;
100133 +#endif
100134 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
100135 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
100136 (mm->end_data - mm->start_data) > rlim)
100137 goto out;
100138 @@ -944,6 +972,12 @@ static int
100139 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
100140 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
100141 {
100142 +
100143 +#ifdef CONFIG_PAX_SEGMEXEC
100144 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
100145 + return 0;
100146 +#endif
100147 +
100148 if (is_mergeable_vma(vma, file, vm_flags) &&
100149 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
100150 if (vma->vm_pgoff == vm_pgoff)
100151 @@ -963,6 +997,12 @@ static int
100152 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
100153 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
100154 {
100155 +
100156 +#ifdef CONFIG_PAX_SEGMEXEC
100157 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
100158 + return 0;
100159 +#endif
100160 +
100161 if (is_mergeable_vma(vma, file, vm_flags) &&
100162 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
100163 pgoff_t vm_pglen;
100164 @@ -1005,13 +1045,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
100165 struct vm_area_struct *vma_merge(struct mm_struct *mm,
100166 struct vm_area_struct *prev, unsigned long addr,
100167 unsigned long end, unsigned long vm_flags,
100168 - struct anon_vma *anon_vma, struct file *file,
100169 + struct anon_vma *anon_vma, struct file *file,
100170 pgoff_t pgoff, struct mempolicy *policy)
100171 {
100172 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
100173 struct vm_area_struct *area, *next;
100174 int err;
100175
100176 +#ifdef CONFIG_PAX_SEGMEXEC
100177 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
100178 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
100179 +
100180 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
100181 +#endif
100182 +
100183 /*
100184 * We later require that vma->vm_flags == vm_flags,
100185 * so this tests vma->vm_flags & VM_SPECIAL, too.
100186 @@ -1027,6 +1074,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
100187 if (next && next->vm_end == end) /* cases 6, 7, 8 */
100188 next = next->vm_next;
100189
100190 +#ifdef CONFIG_PAX_SEGMEXEC
100191 + if (prev)
100192 + prev_m = pax_find_mirror_vma(prev);
100193 + if (area)
100194 + area_m = pax_find_mirror_vma(area);
100195 + if (next)
100196 + next_m = pax_find_mirror_vma(next);
100197 +#endif
100198 +
100199 /*
100200 * Can it merge with the predecessor?
100201 */
100202 @@ -1046,9 +1102,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
100203 /* cases 1, 6 */
100204 err = vma_adjust(prev, prev->vm_start,
100205 next->vm_end, prev->vm_pgoff, NULL);
100206 - } else /* cases 2, 5, 7 */
100207 +
100208 +#ifdef CONFIG_PAX_SEGMEXEC
100209 + if (!err && prev_m)
100210 + err = vma_adjust(prev_m, prev_m->vm_start,
100211 + next_m->vm_end, prev_m->vm_pgoff, NULL);
100212 +#endif
100213 +
100214 + } else { /* cases 2, 5, 7 */
100215 err = vma_adjust(prev, prev->vm_start,
100216 end, prev->vm_pgoff, NULL);
100217 +
100218 +#ifdef CONFIG_PAX_SEGMEXEC
100219 + if (!err && prev_m)
100220 + err = vma_adjust(prev_m, prev_m->vm_start,
100221 + end_m, prev_m->vm_pgoff, NULL);
100222 +#endif
100223 +
100224 + }
100225 if (err)
100226 return NULL;
100227 khugepaged_enter_vma_merge(prev);
100228 @@ -1062,12 +1133,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
100229 mpol_equal(policy, vma_policy(next)) &&
100230 can_vma_merge_before(next, vm_flags,
100231 anon_vma, file, pgoff+pglen)) {
100232 - if (prev && addr < prev->vm_end) /* case 4 */
100233 + if (prev && addr < prev->vm_end) { /* case 4 */
100234 err = vma_adjust(prev, prev->vm_start,
100235 addr, prev->vm_pgoff, NULL);
100236 - else /* cases 3, 8 */
100237 +
100238 +#ifdef CONFIG_PAX_SEGMEXEC
100239 + if (!err && prev_m)
100240 + err = vma_adjust(prev_m, prev_m->vm_start,
100241 + addr_m, prev_m->vm_pgoff, NULL);
100242 +#endif
100243 +
100244 + } else { /* cases 3, 8 */
100245 err = vma_adjust(area, addr, next->vm_end,
100246 next->vm_pgoff - pglen, NULL);
100247 +
100248 +#ifdef CONFIG_PAX_SEGMEXEC
100249 + if (!err && area_m)
100250 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
100251 + next_m->vm_pgoff - pglen, NULL);
100252 +#endif
100253 +
100254 + }
100255 if (err)
100256 return NULL;
100257 khugepaged_enter_vma_merge(area);
100258 @@ -1176,8 +1262,10 @@ none:
100259 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
100260 struct file *file, long pages)
100261 {
100262 - const unsigned long stack_flags
100263 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
100264 +
100265 +#ifdef CONFIG_PAX_RANDMMAP
100266 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
100267 +#endif
100268
100269 mm->total_vm += pages;
100270
100271 @@ -1185,7 +1273,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
100272 mm->shared_vm += pages;
100273 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
100274 mm->exec_vm += pages;
100275 - } else if (flags & stack_flags)
100276 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
100277 mm->stack_vm += pages;
100278 }
100279 #endif /* CONFIG_PROC_FS */
100280 @@ -1215,6 +1303,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
100281 locked += mm->locked_vm;
100282 lock_limit = rlimit(RLIMIT_MEMLOCK);
100283 lock_limit >>= PAGE_SHIFT;
100284 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
100285 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
100286 return -EAGAIN;
100287 }
100288 @@ -1241,7 +1330,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
100289 * (the exception is when the underlying filesystem is noexec
100290 * mounted, in which case we dont add PROT_EXEC.)
100291 */
100292 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
100293 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
100294 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
100295 prot |= PROT_EXEC;
100296
100297 @@ -1267,7 +1356,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
100298 /* Obtain the address to map to. we verify (or select) it and ensure
100299 * that it represents a valid section of the address space.
100300 */
100301 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
100302 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
100303 if (addr & ~PAGE_MASK)
100304 return addr;
100305
100306 @@ -1278,6 +1367,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
100307 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
100308 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
100309
100310 +#ifdef CONFIG_PAX_MPROTECT
100311 + if (mm->pax_flags & MF_PAX_MPROTECT) {
100312 +
100313 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
100314 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
100315 + mm->binfmt->handle_mmap)
100316 + mm->binfmt->handle_mmap(file);
100317 +#endif
100318 +
100319 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
100320 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
100321 + gr_log_rwxmmap(file);
100322 +
100323 +#ifdef CONFIG_PAX_EMUPLT
100324 + vm_flags &= ~VM_EXEC;
100325 +#else
100326 + return -EPERM;
100327 +#endif
100328 +
100329 + }
100330 +
100331 + if (!(vm_flags & VM_EXEC))
100332 + vm_flags &= ~VM_MAYEXEC;
100333 +#else
100334 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
100335 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
100336 +#endif
100337 + else
100338 + vm_flags &= ~VM_MAYWRITE;
100339 + }
100340 +#endif
100341 +
100342 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
100343 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
100344 + vm_flags &= ~VM_PAGEEXEC;
100345 +#endif
100346 +
100347 if (flags & MAP_LOCKED)
100348 if (!can_do_mlock())
100349 return -EPERM;
100350 @@ -1365,6 +1491,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
100351 vm_flags |= VM_NORESERVE;
100352 }
100353
100354 + if (!gr_acl_handle_mmap(file, prot))
100355 + return -EACCES;
100356 +
100357 addr = mmap_region(file, addr, len, vm_flags, pgoff);
100358 if (!IS_ERR_VALUE(addr) &&
100359 ((vm_flags & VM_LOCKED) ||
100360 @@ -1458,7 +1587,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
100361 vm_flags_t vm_flags = vma->vm_flags;
100362
100363 /* If it was private or non-writable, the write bit is already clear */
100364 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
100365 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
100366 return 0;
100367
100368 /* The backer wishes to know when pages are first written to? */
100369 @@ -1504,7 +1633,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
100370 struct rb_node **rb_link, *rb_parent;
100371 unsigned long charged = 0;
100372
100373 +#ifdef CONFIG_PAX_SEGMEXEC
100374 + struct vm_area_struct *vma_m = NULL;
100375 +#endif
100376 +
100377 + /*
100378 + * mm->mmap_sem is required to protect against another thread
100379 + * changing the mappings in case we sleep.
100380 + */
100381 + verify_mm_writelocked(mm);
100382 +
100383 /* Check against address space limit. */
100384 +
100385 +#ifdef CONFIG_PAX_RANDMMAP
100386 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
100387 +#endif
100388 +
100389 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
100390 unsigned long nr_pages;
100391
100392 @@ -1523,11 +1667,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
100393
100394 /* Clear old maps */
100395 error = -ENOMEM;
100396 -munmap_back:
100397 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
100398 if (do_munmap(mm, addr, len))
100399 return -ENOMEM;
100400 - goto munmap_back;
100401 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
100402 }
100403
100404 /*
100405 @@ -1558,6 +1701,16 @@ munmap_back:
100406 goto unacct_error;
100407 }
100408
100409 +#ifdef CONFIG_PAX_SEGMEXEC
100410 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
100411 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
100412 + if (!vma_m) {
100413 + error = -ENOMEM;
100414 + goto free_vma;
100415 + }
100416 + }
100417 +#endif
100418 +
100419 vma->vm_mm = mm;
100420 vma->vm_start = addr;
100421 vma->vm_end = addr + len;
100422 @@ -1577,6 +1730,13 @@ munmap_back:
100423 if (error)
100424 goto unmap_and_free_vma;
100425
100426 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
100427 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
100428 + vma->vm_flags |= VM_PAGEEXEC;
100429 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
100430 + }
100431 +#endif
100432 +
100433 /* Can addr have changed??
100434 *
100435 * Answer: Yes, several device drivers can do it in their
100436 @@ -1610,6 +1770,12 @@ munmap_back:
100437 }
100438
100439 vma_link(mm, vma, prev, rb_link, rb_parent);
100440 +
100441 +#ifdef CONFIG_PAX_SEGMEXEC
100442 + if (vma_m)
100443 + BUG_ON(pax_mirror_vma(vma_m, vma));
100444 +#endif
100445 +
100446 /* Once vma denies write, undo our temporary denial count */
100447 if (vm_flags & VM_DENYWRITE)
100448 allow_write_access(file);
100449 @@ -1618,6 +1784,7 @@ out:
100450 perf_event_mmap(vma);
100451
100452 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
100453 + track_exec_limit(mm, addr, addr + len, vm_flags);
100454 if (vm_flags & VM_LOCKED) {
100455 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
100456 vma == get_gate_vma(current->mm)))
100457 @@ -1650,6 +1817,12 @@ unmap_and_free_vma:
100458 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
100459 charged = 0;
100460 free_vma:
100461 +
100462 +#ifdef CONFIG_PAX_SEGMEXEC
100463 + if (vma_m)
100464 + kmem_cache_free(vm_area_cachep, vma_m);
100465 +#endif
100466 +
100467 kmem_cache_free(vm_area_cachep, vma);
100468 unacct_error:
100469 if (charged)
100470 @@ -1657,7 +1830,63 @@ unacct_error:
100471 return error;
100472 }
100473
100474 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
100475 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
100476 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
100477 +{
100478 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
100479 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
100480 +
100481 + return 0;
100482 +}
100483 +#endif
100484 +
100485 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
100486 +{
100487 + if (!vma) {
100488 +#ifdef CONFIG_STACK_GROWSUP
100489 + if (addr > sysctl_heap_stack_gap)
100490 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
100491 + else
100492 + vma = find_vma(current->mm, 0);
100493 + if (vma && (vma->vm_flags & VM_GROWSUP))
100494 + return false;
100495 +#endif
100496 + return true;
100497 + }
100498 +
100499 + if (addr + len > vma->vm_start)
100500 + return false;
100501 +
100502 + if (vma->vm_flags & VM_GROWSDOWN)
100503 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
100504 +#ifdef CONFIG_STACK_GROWSUP
100505 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
100506 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
100507 +#endif
100508 + else if (offset)
100509 + return offset <= vma->vm_start - addr - len;
100510 +
100511 + return true;
100512 +}
100513 +
100514 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
100515 +{
100516 + if (vma->vm_start < len)
100517 + return -ENOMEM;
100518 +
100519 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
100520 + if (offset <= vma->vm_start - len)
100521 + return vma->vm_start - len - offset;
100522 + else
100523 + return -ENOMEM;
100524 + }
100525 +
100526 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
100527 + return vma->vm_start - len - sysctl_heap_stack_gap;
100528 + return -ENOMEM;
100529 +}
100530 +
100531 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
100532 {
100533 /*
100534 * We implement the search by looking for an rbtree node that
100535 @@ -1705,11 +1934,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
100536 }
100537 }
100538
100539 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
100540 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
100541 check_current:
100542 /* Check if current node has a suitable gap */
100543 if (gap_start > high_limit)
100544 return -ENOMEM;
100545 +
100546 + if (gap_end - gap_start > info->threadstack_offset)
100547 + gap_start += info->threadstack_offset;
100548 + else
100549 + gap_start = gap_end;
100550 +
100551 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
100552 + if (gap_end - gap_start > sysctl_heap_stack_gap)
100553 + gap_start += sysctl_heap_stack_gap;
100554 + else
100555 + gap_start = gap_end;
100556 + }
100557 + if (vma->vm_flags & VM_GROWSDOWN) {
100558 + if (gap_end - gap_start > sysctl_heap_stack_gap)
100559 + gap_end -= sysctl_heap_stack_gap;
100560 + else
100561 + gap_end = gap_start;
100562 + }
100563 if (gap_end >= low_limit && gap_end - gap_start >= length)
100564 goto found;
100565
100566 @@ -1759,7 +2006,7 @@ found:
100567 return gap_start;
100568 }
100569
100570 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
100571 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
100572 {
100573 struct mm_struct *mm = current->mm;
100574 struct vm_area_struct *vma;
100575 @@ -1813,6 +2060,24 @@ check_current:
100576 gap_end = vma->vm_start;
100577 if (gap_end < low_limit)
100578 return -ENOMEM;
100579 +
100580 + if (gap_end - gap_start > info->threadstack_offset)
100581 + gap_end -= info->threadstack_offset;
100582 + else
100583 + gap_end = gap_start;
100584 +
100585 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
100586 + if (gap_end - gap_start > sysctl_heap_stack_gap)
100587 + gap_start += sysctl_heap_stack_gap;
100588 + else
100589 + gap_start = gap_end;
100590 + }
100591 + if (vma->vm_flags & VM_GROWSDOWN) {
100592 + if (gap_end - gap_start > sysctl_heap_stack_gap)
100593 + gap_end -= sysctl_heap_stack_gap;
100594 + else
100595 + gap_end = gap_start;
100596 + }
100597 if (gap_start <= high_limit && gap_end - gap_start >= length)
100598 goto found;
100599
100600 @@ -1876,6 +2141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
100601 struct mm_struct *mm = current->mm;
100602 struct vm_area_struct *vma;
100603 struct vm_unmapped_area_info info;
100604 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
100605
100606 if (len > TASK_SIZE - mmap_min_addr)
100607 return -ENOMEM;
100608 @@ -1883,11 +2149,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
100609 if (flags & MAP_FIXED)
100610 return addr;
100611
100612 +#ifdef CONFIG_PAX_RANDMMAP
100613 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
100614 +#endif
100615 +
100616 if (addr) {
100617 addr = PAGE_ALIGN(addr);
100618 vma = find_vma(mm, addr);
100619 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
100620 - (!vma || addr + len <= vma->vm_start))
100621 + check_heap_stack_gap(vma, addr, len, offset))
100622 return addr;
100623 }
100624
100625 @@ -1896,6 +2166,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
100626 info.low_limit = mm->mmap_base;
100627 info.high_limit = TASK_SIZE;
100628 info.align_mask = 0;
100629 + info.threadstack_offset = offset;
100630 return vm_unmapped_area(&info);
100631 }
100632 #endif
100633 @@ -1914,6 +2185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
100634 struct mm_struct *mm = current->mm;
100635 unsigned long addr = addr0;
100636 struct vm_unmapped_area_info info;
100637 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
100638
100639 /* requested length too big for entire address space */
100640 if (len > TASK_SIZE - mmap_min_addr)
100641 @@ -1922,12 +2194,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
100642 if (flags & MAP_FIXED)
100643 return addr;
100644
100645 +#ifdef CONFIG_PAX_RANDMMAP
100646 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
100647 +#endif
100648 +
100649 /* requesting a specific address */
100650 if (addr) {
100651 addr = PAGE_ALIGN(addr);
100652 vma = find_vma(mm, addr);
100653 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
100654 - (!vma || addr + len <= vma->vm_start))
100655 + check_heap_stack_gap(vma, addr, len, offset))
100656 return addr;
100657 }
100658
100659 @@ -1936,6 +2212,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
100660 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
100661 info.high_limit = mm->mmap_base;
100662 info.align_mask = 0;
100663 + info.threadstack_offset = offset;
100664 addr = vm_unmapped_area(&info);
100665
100666 /*
100667 @@ -1948,6 +2225,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
100668 VM_BUG_ON(addr != -ENOMEM);
100669 info.flags = 0;
100670 info.low_limit = TASK_UNMAPPED_BASE;
100671 +
100672 +#ifdef CONFIG_PAX_RANDMMAP
100673 + if (mm->pax_flags & MF_PAX_RANDMMAP)
100674 + info.low_limit += mm->delta_mmap;
100675 +#endif
100676 +
100677 info.high_limit = TASK_SIZE;
100678 addr = vm_unmapped_area(&info);
100679 }
100680 @@ -2048,6 +2331,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
100681 return vma;
100682 }
100683
100684 +#ifdef CONFIG_PAX_SEGMEXEC
100685 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
100686 +{
100687 + struct vm_area_struct *vma_m;
100688 +
100689 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
100690 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
100691 + BUG_ON(vma->vm_mirror);
100692 + return NULL;
100693 + }
100694 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
100695 + vma_m = vma->vm_mirror;
100696 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
100697 + BUG_ON(vma->vm_file != vma_m->vm_file);
100698 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
100699 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
100700 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
100701 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
100702 + return vma_m;
100703 +}
100704 +#endif
100705 +
100706 /*
100707 * Verify that the stack growth is acceptable and
100708 * update accounting. This is shared with both the
100709 @@ -2064,6 +2369,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
100710 return -ENOMEM;
100711
100712 /* Stack limit test */
100713 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
100714 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
100715 return -ENOMEM;
100716
100717 @@ -2074,6 +2380,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
100718 locked = mm->locked_vm + grow;
100719 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
100720 limit >>= PAGE_SHIFT;
100721 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
100722 if (locked > limit && !capable(CAP_IPC_LOCK))
100723 return -ENOMEM;
100724 }
100725 @@ -2103,37 +2410,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
100726 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
100727 * vma is the last one with address > vma->vm_end. Have to extend vma.
100728 */
100729 +#ifndef CONFIG_IA64
100730 +static
100731 +#endif
100732 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
100733 {
100734 int error;
100735 + bool locknext;
100736
100737 if (!(vma->vm_flags & VM_GROWSUP))
100738 return -EFAULT;
100739
100740 + /* Also guard against wrapping around to address 0. */
100741 + if (address < PAGE_ALIGN(address+1))
100742 + address = PAGE_ALIGN(address+1);
100743 + else
100744 + return -ENOMEM;
100745 +
100746 /*
100747 * We must make sure the anon_vma is allocated
100748 * so that the anon_vma locking is not a noop.
100749 */
100750 if (unlikely(anon_vma_prepare(vma)))
100751 return -ENOMEM;
100752 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
100753 + if (locknext && anon_vma_prepare(vma->vm_next))
100754 + return -ENOMEM;
100755 vma_lock_anon_vma(vma);
100756 + if (locknext)
100757 + vma_lock_anon_vma(vma->vm_next);
100758
100759 /*
100760 * vma->vm_start/vm_end cannot change under us because the caller
100761 * is required to hold the mmap_sem in read mode. We need the
100762 - * anon_vma lock to serialize against concurrent expand_stacks.
100763 - * Also guard against wrapping around to address 0.
100764 + * anon_vma locks to serialize against concurrent expand_stacks
100765 + * and expand_upwards.
100766 */
100767 - if (address < PAGE_ALIGN(address+4))
100768 - address = PAGE_ALIGN(address+4);
100769 - else {
100770 - vma_unlock_anon_vma(vma);
100771 - return -ENOMEM;
100772 - }
100773 error = 0;
100774
100775 /* Somebody else might have raced and expanded it already */
100776 - if (address > vma->vm_end) {
100777 + if (vma->vm_next && (vma->vm_next->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && vma->vm_next->vm_start - address < sysctl_heap_stack_gap)
100778 + error = -ENOMEM;
100779 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
100780 unsigned long size, grow;
100781
100782 size = address - vma->vm_start;
100783 @@ -2168,6 +2486,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
100784 }
100785 }
100786 }
100787 + if (locknext)
100788 + vma_unlock_anon_vma(vma->vm_next);
100789 vma_unlock_anon_vma(vma);
100790 khugepaged_enter_vma_merge(vma);
100791 validate_mm(vma->vm_mm);
100792 @@ -2182,6 +2502,8 @@ int expand_downwards(struct vm_area_struct *vma,
100793 unsigned long address)
100794 {
100795 int error;
100796 + bool lockprev = false;
100797 + struct vm_area_struct *prev;
100798
100799 /*
100800 * We must make sure the anon_vma is allocated
100801 @@ -2195,6 +2517,15 @@ int expand_downwards(struct vm_area_struct *vma,
100802 if (error)
100803 return error;
100804
100805 + prev = vma->vm_prev;
100806 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
100807 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
100808 +#endif
100809 + if (lockprev && anon_vma_prepare(prev))
100810 + return -ENOMEM;
100811 + if (lockprev)
100812 + vma_lock_anon_vma(prev);
100813 +
100814 vma_lock_anon_vma(vma);
100815
100816 /*
100817 @@ -2204,9 +2535,17 @@ int expand_downwards(struct vm_area_struct *vma,
100818 */
100819
100820 /* Somebody else might have raced and expanded it already */
100821 - if (address < vma->vm_start) {
100822 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
100823 + error = -ENOMEM;
100824 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
100825 unsigned long size, grow;
100826
100827 +#ifdef CONFIG_PAX_SEGMEXEC
100828 + struct vm_area_struct *vma_m;
100829 +
100830 + vma_m = pax_find_mirror_vma(vma);
100831 +#endif
100832 +
100833 size = vma->vm_end - address;
100834 grow = (vma->vm_start - address) >> PAGE_SHIFT;
100835
100836 @@ -2231,13 +2570,27 @@ int expand_downwards(struct vm_area_struct *vma,
100837 vma->vm_pgoff -= grow;
100838 anon_vma_interval_tree_post_update_vma(vma);
100839 vma_gap_update(vma);
100840 +
100841 +#ifdef CONFIG_PAX_SEGMEXEC
100842 + if (vma_m) {
100843 + anon_vma_interval_tree_pre_update_vma(vma_m);
100844 + vma_m->vm_start -= grow << PAGE_SHIFT;
100845 + vma_m->vm_pgoff -= grow;
100846 + anon_vma_interval_tree_post_update_vma(vma_m);
100847 + vma_gap_update(vma_m);
100848 + }
100849 +#endif
100850 +
100851 spin_unlock(&vma->vm_mm->page_table_lock);
100852
100853 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
100854 perf_event_mmap(vma);
100855 }
100856 }
100857 }
100858 vma_unlock_anon_vma(vma);
100859 + if (lockprev)
100860 + vma_unlock_anon_vma(prev);
100861 khugepaged_enter_vma_merge(vma);
100862 validate_mm(vma->vm_mm);
100863 return error;
100864 @@ -2335,6 +2688,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
100865 do {
100866 long nrpages = vma_pages(vma);
100867
100868 +#ifdef CONFIG_PAX_SEGMEXEC
100869 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
100870 + vma = remove_vma(vma);
100871 + continue;
100872 + }
100873 +#endif
100874 +
100875 if (vma->vm_flags & VM_ACCOUNT)
100876 nr_accounted += nrpages;
100877 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
100878 @@ -2379,6 +2739,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
100879 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
100880 vma->vm_prev = NULL;
100881 do {
100882 +
100883 +#ifdef CONFIG_PAX_SEGMEXEC
100884 + if (vma->vm_mirror) {
100885 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
100886 + vma->vm_mirror->vm_mirror = NULL;
100887 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
100888 + vma->vm_mirror = NULL;
100889 + }
100890 +#endif
100891 +
100892 vma_rb_erase(vma, &mm->mm_rb);
100893 mm->map_count--;
100894 tail_vma = vma;
100895 @@ -2406,14 +2776,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
100896 struct vm_area_struct *new;
100897 int err = -ENOMEM;
100898
100899 +#ifdef CONFIG_PAX_SEGMEXEC
100900 + struct vm_area_struct *vma_m, *new_m = NULL;
100901 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
100902 +#endif
100903 +
100904 if (is_vm_hugetlb_page(vma) && (addr &
100905 ~(huge_page_mask(hstate_vma(vma)))))
100906 return -EINVAL;
100907
100908 +#ifdef CONFIG_PAX_SEGMEXEC
100909 + vma_m = pax_find_mirror_vma(vma);
100910 +#endif
100911 +
100912 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
100913 if (!new)
100914 goto out_err;
100915
100916 +#ifdef CONFIG_PAX_SEGMEXEC
100917 + if (vma_m) {
100918 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
100919 + if (!new_m) {
100920 + kmem_cache_free(vm_area_cachep, new);
100921 + goto out_err;
100922 + }
100923 + }
100924 +#endif
100925 +
100926 /* most fields are the same, copy all, and then fixup */
100927 *new = *vma;
100928
100929 @@ -2426,6 +2815,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
100930 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
100931 }
100932
100933 +#ifdef CONFIG_PAX_SEGMEXEC
100934 + if (vma_m) {
100935 + *new_m = *vma_m;
100936 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
100937 + new_m->vm_mirror = new;
100938 + new->vm_mirror = new_m;
100939 +
100940 + if (new_below)
100941 + new_m->vm_end = addr_m;
100942 + else {
100943 + new_m->vm_start = addr_m;
100944 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
100945 + }
100946 + }
100947 +#endif
100948 +
100949 err = vma_dup_policy(vma, new);
100950 if (err)
100951 goto out_free_vma;
100952 @@ -2445,6 +2850,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
100953 else
100954 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
100955
100956 +#ifdef CONFIG_PAX_SEGMEXEC
100957 + if (!err && vma_m) {
100958 + struct mempolicy *pol = vma_policy(new);
100959 +
100960 + if (anon_vma_clone(new_m, vma_m))
100961 + goto out_free_mpol;
100962 +
100963 + mpol_get(pol);
100964 + set_vma_policy(new_m, pol);
100965 +
100966 + if (new_m->vm_file)
100967 + get_file(new_m->vm_file);
100968 +
100969 + if (new_m->vm_ops && new_m->vm_ops->open)
100970 + new_m->vm_ops->open(new_m);
100971 +
100972 + if (new_below)
100973 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
100974 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
100975 + else
100976 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
100977 +
100978 + if (err) {
100979 + if (new_m->vm_ops && new_m->vm_ops->close)
100980 + new_m->vm_ops->close(new_m);
100981 + if (new_m->vm_file)
100982 + fput(new_m->vm_file);
100983 + mpol_put(pol);
100984 + }
100985 + }
100986 +#endif
100987 +
100988 /* Success. */
100989 if (!err)
100990 return 0;
100991 @@ -2454,10 +2891,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
100992 new->vm_ops->close(new);
100993 if (new->vm_file)
100994 fput(new->vm_file);
100995 - unlink_anon_vmas(new);
100996 out_free_mpol:
100997 mpol_put(vma_policy(new));
100998 out_free_vma:
100999 +
101000 +#ifdef CONFIG_PAX_SEGMEXEC
101001 + if (new_m) {
101002 + unlink_anon_vmas(new_m);
101003 + kmem_cache_free(vm_area_cachep, new_m);
101004 + }
101005 +#endif
101006 +
101007 + unlink_anon_vmas(new);
101008 kmem_cache_free(vm_area_cachep, new);
101009 out_err:
101010 return err;
101011 @@ -2470,6 +2915,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
101012 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
101013 unsigned long addr, int new_below)
101014 {
101015 +
101016 +#ifdef CONFIG_PAX_SEGMEXEC
101017 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
101018 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
101019 + if (mm->map_count >= sysctl_max_map_count-1)
101020 + return -ENOMEM;
101021 + } else
101022 +#endif
101023 +
101024 if (mm->map_count >= sysctl_max_map_count)
101025 return -ENOMEM;
101026
101027 @@ -2481,11 +2935,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
101028 * work. This now handles partial unmappings.
101029 * Jeremy Fitzhardinge <jeremy@goop.org>
101030 */
101031 +#ifdef CONFIG_PAX_SEGMEXEC
101032 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
101033 {
101034 + int ret = __do_munmap(mm, start, len);
101035 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
101036 + return ret;
101037 +
101038 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
101039 +}
101040 +
101041 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
101042 +#else
101043 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
101044 +#endif
101045 +{
101046 unsigned long end;
101047 struct vm_area_struct *vma, *prev, *last;
101048
101049 + /*
101050 + * mm->mmap_sem is required to protect against another thread
101051 + * changing the mappings in case we sleep.
101052 + */
101053 + verify_mm_writelocked(mm);
101054 +
101055 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
101056 return -EINVAL;
101057
101058 @@ -2560,6 +3033,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
101059 /* Fix up all other VM information */
101060 remove_vma_list(mm, vma);
101061
101062 + track_exec_limit(mm, start, end, 0UL);
101063 +
101064 return 0;
101065 }
101066
101067 @@ -2568,6 +3043,13 @@ int vm_munmap(unsigned long start, size_t len)
101068 int ret;
101069 struct mm_struct *mm = current->mm;
101070
101071 +
101072 +#ifdef CONFIG_PAX_SEGMEXEC
101073 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
101074 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
101075 + return -EINVAL;
101076 +#endif
101077 +
101078 down_write(&mm->mmap_sem);
101079 ret = do_munmap(mm, start, len);
101080 up_write(&mm->mmap_sem);
101081 @@ -2581,16 +3063,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
101082 return vm_munmap(addr, len);
101083 }
101084
101085 -static inline void verify_mm_writelocked(struct mm_struct *mm)
101086 -{
101087 -#ifdef CONFIG_DEBUG_VM
101088 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
101089 - WARN_ON(1);
101090 - up_read(&mm->mmap_sem);
101091 - }
101092 -#endif
101093 -}
101094 -
101095 /*
101096 * this is really a simplified "do_mmap". it only handles
101097 * anonymous maps. eventually we may be able to do some
101098 @@ -2604,6 +3076,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101099 struct rb_node ** rb_link, * rb_parent;
101100 pgoff_t pgoff = addr >> PAGE_SHIFT;
101101 int error;
101102 + unsigned long charged;
101103
101104 len = PAGE_ALIGN(len);
101105 if (!len)
101106 @@ -2611,10 +3084,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101107
101108 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
101109
101110 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
101111 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
101112 + flags &= ~VM_EXEC;
101113 +
101114 +#ifdef CONFIG_PAX_MPROTECT
101115 + if (mm->pax_flags & MF_PAX_MPROTECT)
101116 + flags &= ~VM_MAYEXEC;
101117 +#endif
101118 +
101119 + }
101120 +#endif
101121 +
101122 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
101123 if (error & ~PAGE_MASK)
101124 return error;
101125
101126 + charged = len >> PAGE_SHIFT;
101127 +
101128 error = mlock_future_check(mm, mm->def_flags, len);
101129 if (error)
101130 return error;
101131 @@ -2628,21 +3115,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101132 /*
101133 * Clear old maps. this also does some error checking for us
101134 */
101135 - munmap_back:
101136 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
101137 if (do_munmap(mm, addr, len))
101138 return -ENOMEM;
101139 - goto munmap_back;
101140 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
101141 }
101142
101143 /* Check against address space limits *after* clearing old maps... */
101144 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
101145 + if (!may_expand_vm(mm, charged))
101146 return -ENOMEM;
101147
101148 if (mm->map_count > sysctl_max_map_count)
101149 return -ENOMEM;
101150
101151 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
101152 + if (security_vm_enough_memory_mm(mm, charged))
101153 return -ENOMEM;
101154
101155 /* Can we just expand an old private anonymous mapping? */
101156 @@ -2656,7 +3142,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101157 */
101158 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
101159 if (!vma) {
101160 - vm_unacct_memory(len >> PAGE_SHIFT);
101161 + vm_unacct_memory(charged);
101162 return -ENOMEM;
101163 }
101164
101165 @@ -2670,10 +3156,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101166 vma_link(mm, vma, prev, rb_link, rb_parent);
101167 out:
101168 perf_event_mmap(vma);
101169 - mm->total_vm += len >> PAGE_SHIFT;
101170 + mm->total_vm += charged;
101171 if (flags & VM_LOCKED)
101172 - mm->locked_vm += (len >> PAGE_SHIFT);
101173 + mm->locked_vm += charged;
101174 vma->vm_flags |= VM_SOFTDIRTY;
101175 + track_exec_limit(mm, addr, addr + len, flags);
101176 return addr;
101177 }
101178
101179 @@ -2735,6 +3222,7 @@ void exit_mmap(struct mm_struct *mm)
101180 while (vma) {
101181 if (vma->vm_flags & VM_ACCOUNT)
101182 nr_accounted += vma_pages(vma);
101183 + vma->vm_mirror = NULL;
101184 vma = remove_vma(vma);
101185 }
101186 vm_unacct_memory(nr_accounted);
101187 @@ -2752,6 +3240,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
101188 struct vm_area_struct *prev;
101189 struct rb_node **rb_link, *rb_parent;
101190
101191 +#ifdef CONFIG_PAX_SEGMEXEC
101192 + struct vm_area_struct *vma_m = NULL;
101193 +#endif
101194 +
101195 + if (security_mmap_addr(vma->vm_start))
101196 + return -EPERM;
101197 +
101198 /*
101199 * The vm_pgoff of a purely anonymous vma should be irrelevant
101200 * until its first write fault, when page's anon_vma and index
101201 @@ -2775,7 +3270,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
101202 security_vm_enough_memory_mm(mm, vma_pages(vma)))
101203 return -ENOMEM;
101204
101205 +#ifdef CONFIG_PAX_SEGMEXEC
101206 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
101207 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
101208 + if (!vma_m)
101209 + return -ENOMEM;
101210 + }
101211 +#endif
101212 +
101213 vma_link(mm, vma, prev, rb_link, rb_parent);
101214 +
101215 +#ifdef CONFIG_PAX_SEGMEXEC
101216 + if (vma_m)
101217 + BUG_ON(pax_mirror_vma(vma_m, vma));
101218 +#endif
101219 +
101220 return 0;
101221 }
101222
101223 @@ -2794,6 +3303,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
101224 struct rb_node **rb_link, *rb_parent;
101225 bool faulted_in_anon_vma = true;
101226
101227 + BUG_ON(vma->vm_mirror);
101228 +
101229 /*
101230 * If anonymous vma has not yet been faulted, update new pgoff
101231 * to match new location, to increase its chance of merging.
101232 @@ -2858,6 +3369,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
101233 return NULL;
101234 }
101235
101236 +#ifdef CONFIG_PAX_SEGMEXEC
101237 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
101238 +{
101239 + struct vm_area_struct *prev_m;
101240 + struct rb_node **rb_link_m, *rb_parent_m;
101241 + struct mempolicy *pol_m;
101242 +
101243 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
101244 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
101245 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
101246 + *vma_m = *vma;
101247 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
101248 + if (anon_vma_clone(vma_m, vma))
101249 + return -ENOMEM;
101250 + pol_m = vma_policy(vma_m);
101251 + mpol_get(pol_m);
101252 + set_vma_policy(vma_m, pol_m);
101253 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
101254 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
101255 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
101256 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
101257 + if (vma_m->vm_file)
101258 + get_file(vma_m->vm_file);
101259 + if (vma_m->vm_ops && vma_m->vm_ops->open)
101260 + vma_m->vm_ops->open(vma_m);
101261 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
101262 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
101263 + vma_m->vm_mirror = vma;
101264 + vma->vm_mirror = vma_m;
101265 + return 0;
101266 +}
101267 +#endif
101268 +
101269 /*
101270 * Return true if the calling process may expand its vm space by the passed
101271 * number of pages
101272 @@ -2869,6 +3413,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
101273
101274 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
101275
101276 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
101277 if (cur + npages > lim)
101278 return 0;
101279 return 1;
101280 @@ -2951,6 +3496,22 @@ static struct vm_area_struct *__install_special_mapping(
101281 vma->vm_start = addr;
101282 vma->vm_end = addr + len;
101283
101284 +#ifdef CONFIG_PAX_MPROTECT
101285 + if (mm->pax_flags & MF_PAX_MPROTECT) {
101286 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
101287 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
101288 + return ERR_PTR(-EPERM);
101289 + if (!(vm_flags & VM_EXEC))
101290 + vm_flags &= ~VM_MAYEXEC;
101291 +#else
101292 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
101293 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
101294 +#endif
101295 + else
101296 + vm_flags &= ~VM_MAYWRITE;
101297 + }
101298 +#endif
101299 +
101300 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
101301 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
101302
101303 diff --git a/mm/mprotect.c b/mm/mprotect.c
101304 index c43d557..0b7ccd2 100644
101305 --- a/mm/mprotect.c
101306 +++ b/mm/mprotect.c
101307 @@ -24,10 +24,18 @@
101308 #include <linux/migrate.h>
101309 #include <linux/perf_event.h>
101310 #include <linux/ksm.h>
101311 +#include <linux/sched/sysctl.h>
101312 +
101313 +#ifdef CONFIG_PAX_MPROTECT
101314 +#include <linux/elf.h>
101315 +#include <linux/binfmts.h>
101316 +#endif
101317 +
101318 #include <asm/uaccess.h>
101319 #include <asm/pgtable.h>
101320 #include <asm/cacheflush.h>
101321 #include <asm/tlbflush.h>
101322 +#include <asm/mmu_context.h>
101323
101324 #ifndef pgprot_modify
101325 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
101326 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
101327 return pages;
101328 }
101329
101330 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
101331 +/* called while holding the mmap semaphor for writing except stack expansion */
101332 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
101333 +{
101334 + unsigned long oldlimit, newlimit = 0UL;
101335 +
101336 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
101337 + return;
101338 +
101339 + spin_lock(&mm->page_table_lock);
101340 + oldlimit = mm->context.user_cs_limit;
101341 + if ((prot & VM_EXEC) && oldlimit < end)
101342 + /* USER_CS limit moved up */
101343 + newlimit = end;
101344 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
101345 + /* USER_CS limit moved down */
101346 + newlimit = start;
101347 +
101348 + if (newlimit) {
101349 + mm->context.user_cs_limit = newlimit;
101350 +
101351 +#ifdef CONFIG_SMP
101352 + wmb();
101353 + cpus_clear(mm->context.cpu_user_cs_mask);
101354 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
101355 +#endif
101356 +
101357 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
101358 + }
101359 + spin_unlock(&mm->page_table_lock);
101360 + if (newlimit == end) {
101361 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
101362 +
101363 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
101364 + if (is_vm_hugetlb_page(vma))
101365 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
101366 + else
101367 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
101368 + }
101369 +}
101370 +#endif
101371 +
101372 int
101373 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
101374 unsigned long start, unsigned long end, unsigned long newflags)
101375 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
101376 int error;
101377 int dirty_accountable = 0;
101378
101379 +#ifdef CONFIG_PAX_SEGMEXEC
101380 + struct vm_area_struct *vma_m = NULL;
101381 + unsigned long start_m, end_m;
101382 +
101383 + start_m = start + SEGMEXEC_TASK_SIZE;
101384 + end_m = end + SEGMEXEC_TASK_SIZE;
101385 +#endif
101386 +
101387 if (newflags == oldflags) {
101388 *pprev = vma;
101389 return 0;
101390 }
101391
101392 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
101393 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
101394 +
101395 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
101396 + return -ENOMEM;
101397 +
101398 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
101399 + return -ENOMEM;
101400 + }
101401 +
101402 /*
101403 * If we make a private mapping writable we increase our commit;
101404 * but (without finer accounting) cannot reduce our commit if we
101405 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
101406 }
101407 }
101408
101409 +#ifdef CONFIG_PAX_SEGMEXEC
101410 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
101411 + if (start != vma->vm_start) {
101412 + error = split_vma(mm, vma, start, 1);
101413 + if (error)
101414 + goto fail;
101415 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
101416 + *pprev = (*pprev)->vm_next;
101417 + }
101418 +
101419 + if (end != vma->vm_end) {
101420 + error = split_vma(mm, vma, end, 0);
101421 + if (error)
101422 + goto fail;
101423 + }
101424 +
101425 + if (pax_find_mirror_vma(vma)) {
101426 + error = __do_munmap(mm, start_m, end_m - start_m);
101427 + if (error)
101428 + goto fail;
101429 + } else {
101430 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
101431 + if (!vma_m) {
101432 + error = -ENOMEM;
101433 + goto fail;
101434 + }
101435 + vma->vm_flags = newflags;
101436 + error = pax_mirror_vma(vma_m, vma);
101437 + if (error) {
101438 + vma->vm_flags = oldflags;
101439 + goto fail;
101440 + }
101441 + }
101442 + }
101443 +#endif
101444 +
101445 /*
101446 * First try to merge with previous and/or next vma.
101447 */
101448 @@ -319,9 +423,21 @@ success:
101449 * vm_flags and vm_page_prot are protected by the mmap_sem
101450 * held in write mode.
101451 */
101452 +
101453 +#ifdef CONFIG_PAX_SEGMEXEC
101454 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
101455 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
101456 +#endif
101457 +
101458 vma->vm_flags = newflags;
101459 +
101460 +#ifdef CONFIG_PAX_MPROTECT
101461 + if (mm->binfmt && mm->binfmt->handle_mprotect)
101462 + mm->binfmt->handle_mprotect(vma, newflags);
101463 +#endif
101464 +
101465 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
101466 - vm_get_page_prot(newflags));
101467 + vm_get_page_prot(vma->vm_flags));
101468
101469 if (vma_wants_writenotify(vma)) {
101470 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
101471 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101472 end = start + len;
101473 if (end <= start)
101474 return -ENOMEM;
101475 +
101476 +#ifdef CONFIG_PAX_SEGMEXEC
101477 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
101478 + if (end > SEGMEXEC_TASK_SIZE)
101479 + return -EINVAL;
101480 + } else
101481 +#endif
101482 +
101483 + if (end > TASK_SIZE)
101484 + return -EINVAL;
101485 +
101486 if (!arch_validate_prot(prot))
101487 return -EINVAL;
101488
101489 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101490 /*
101491 * Does the application expect PROT_READ to imply PROT_EXEC:
101492 */
101493 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
101494 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
101495 prot |= PROT_EXEC;
101496
101497 vm_flags = calc_vm_prot_bits(prot);
101498 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101499 if (start > vma->vm_start)
101500 prev = vma;
101501
101502 +#ifdef CONFIG_PAX_MPROTECT
101503 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
101504 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
101505 +#endif
101506 +
101507 for (nstart = start ; ; ) {
101508 unsigned long newflags;
101509
101510 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101511
101512 /* newflags >> 4 shift VM_MAY% in place of VM_% */
101513 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
101514 + if (prot & (PROT_WRITE | PROT_EXEC))
101515 + gr_log_rwxmprotect(vma);
101516 +
101517 + error = -EACCES;
101518 + goto out;
101519 + }
101520 +
101521 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
101522 error = -EACCES;
101523 goto out;
101524 }
101525 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101526 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
101527 if (error)
101528 goto out;
101529 +
101530 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
101531 +
101532 nstart = tmp;
101533
101534 if (nstart < prev->vm_end)
101535 diff --git a/mm/mremap.c b/mm/mremap.c
101536 index 05f1180..c3cde48 100644
101537 --- a/mm/mremap.c
101538 +++ b/mm/mremap.c
101539 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
101540 continue;
101541 pte = ptep_get_and_clear(mm, old_addr, old_pte);
101542 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
101543 +
101544 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
101545 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
101546 + pte = pte_exprotect(pte);
101547 +#endif
101548 +
101549 pte = move_soft_dirty_pte(pte);
101550 set_pte_at(mm, new_addr, new_pte, pte);
101551 }
101552 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
101553 if (is_vm_hugetlb_page(vma))
101554 goto Einval;
101555
101556 +#ifdef CONFIG_PAX_SEGMEXEC
101557 + if (pax_find_mirror_vma(vma))
101558 + goto Einval;
101559 +#endif
101560 +
101561 /* We can't remap across vm area boundaries */
101562 if (old_len > vma->vm_end - addr)
101563 goto Efault;
101564 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
101565 unsigned long ret = -EINVAL;
101566 unsigned long charged = 0;
101567 unsigned long map_flags;
101568 + unsigned long pax_task_size = TASK_SIZE;
101569
101570 if (new_addr & ~PAGE_MASK)
101571 goto out;
101572
101573 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
101574 +#ifdef CONFIG_PAX_SEGMEXEC
101575 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
101576 + pax_task_size = SEGMEXEC_TASK_SIZE;
101577 +#endif
101578 +
101579 + pax_task_size -= PAGE_SIZE;
101580 +
101581 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
101582 goto out;
101583
101584 /* Check if the location we're moving into overlaps the
101585 * old location at all, and fail if it does.
101586 */
101587 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
101588 - goto out;
101589 -
101590 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
101591 + if (addr + old_len > new_addr && new_addr + new_len > addr)
101592 goto out;
101593
101594 ret = do_munmap(mm, new_addr, new_len);
101595 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
101596 unsigned long ret = -EINVAL;
101597 unsigned long charged = 0;
101598 bool locked = false;
101599 + unsigned long pax_task_size = TASK_SIZE;
101600
101601 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
101602 return ret;
101603 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
101604 if (!new_len)
101605 return ret;
101606
101607 +#ifdef CONFIG_PAX_SEGMEXEC
101608 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
101609 + pax_task_size = SEGMEXEC_TASK_SIZE;
101610 +#endif
101611 +
101612 + pax_task_size -= PAGE_SIZE;
101613 +
101614 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
101615 + old_len > pax_task_size || addr > pax_task_size-old_len)
101616 + return ret;
101617 +
101618 down_write(&current->mm->mmap_sem);
101619
101620 if (flags & MREMAP_FIXED) {
101621 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
101622 new_addr = addr;
101623 }
101624 ret = addr;
101625 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
101626 goto out;
101627 }
101628 }
101629 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
101630 goto out;
101631 }
101632
101633 + map_flags = vma->vm_flags;
101634 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
101635 + if (!(ret & ~PAGE_MASK)) {
101636 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
101637 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
101638 + }
101639 }
101640 out:
101641 if (ret & ~PAGE_MASK)
101642 diff --git a/mm/nommu.c b/mm/nommu.c
101643 index 4a852f6..4371a6b 100644
101644 --- a/mm/nommu.c
101645 +++ b/mm/nommu.c
101646 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
101647 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
101648 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
101649 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
101650 -int heap_stack_gap = 0;
101651
101652 atomic_long_t mmap_pages_allocated;
101653
101654 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
101655 EXPORT_SYMBOL(find_vma);
101656
101657 /*
101658 - * find a VMA
101659 - * - we don't extend stack VMAs under NOMMU conditions
101660 - */
101661 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
101662 -{
101663 - return find_vma(mm, addr);
101664 -}
101665 -
101666 -/*
101667 * expand a stack to a given address
101668 * - not supported under NOMMU conditions
101669 */
101670 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
101671
101672 /* most fields are the same, copy all, and then fixup */
101673 *new = *vma;
101674 + INIT_LIST_HEAD(&new->anon_vma_chain);
101675 *region = *vma->vm_region;
101676 new->vm_region = region;
101677
101678 @@ -2007,8 +1998,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
101679 }
101680 EXPORT_SYMBOL(generic_file_remap_pages);
101681
101682 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
101683 - unsigned long addr, void *buf, int len, int write)
101684 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
101685 + unsigned long addr, void *buf, size_t len, int write)
101686 {
101687 struct vm_area_struct *vma;
101688
101689 @@ -2049,8 +2040,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
101690 *
101691 * The caller must hold a reference on @mm.
101692 */
101693 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
101694 - void *buf, int len, int write)
101695 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
101696 + void *buf, size_t len, int write)
101697 {
101698 return __access_remote_vm(NULL, mm, addr, buf, len, write);
101699 }
101700 @@ -2059,7 +2050,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
101701 * Access another process' address space.
101702 * - source/target buffer must be kernel space
101703 */
101704 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
101705 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
101706 {
101707 struct mm_struct *mm;
101708
101709 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
101710 index e0c9430..3c6bf79 100644
101711 --- a/mm/page-writeback.c
101712 +++ b/mm/page-writeback.c
101713 @@ -667,7 +667,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
101714 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
101715 * - the bdi dirty thresh drops quickly due to change of JBOD workload
101716 */
101717 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
101718 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
101719 unsigned long thresh,
101720 unsigned long bg_thresh,
101721 unsigned long dirty,
101722 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
101723 index ef44ad7..1056bc7 100644
101724 --- a/mm/page_alloc.c
101725 +++ b/mm/page_alloc.c
101726 @@ -61,6 +61,7 @@
101727 #include <linux/page-debug-flags.h>
101728 #include <linux/hugetlb.h>
101729 #include <linux/sched/rt.h>
101730 +#include <linux/random.h>
101731
101732 #include <asm/sections.h>
101733 #include <asm/tlbflush.h>
101734 @@ -357,7 +358,7 @@ out:
101735 * This usage means that zero-order pages may not be compound.
101736 */
101737
101738 -static void free_compound_page(struct page *page)
101739 +void free_compound_page(struct page *page)
101740 {
101741 __free_pages_ok(page, compound_order(page));
101742 }
101743 @@ -745,6 +746,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
101744 int i;
101745 int bad = 0;
101746
101747 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
101748 + unsigned long index = 1UL << order;
101749 +#endif
101750 +
101751 trace_mm_page_free(page, order);
101752 kmemcheck_free_shadow(page, order);
101753
101754 @@ -761,6 +766,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
101755 debug_check_no_obj_freed(page_address(page),
101756 PAGE_SIZE << order);
101757 }
101758 +
101759 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
101760 + for (; index; --index)
101761 + sanitize_highpage(page + index - 1);
101762 +#endif
101763 +
101764 arch_free_page(page, order);
101765 kernel_map_pages(page, 1 << order, 0);
101766
101767 @@ -784,6 +795,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
101768 local_irq_restore(flags);
101769 }
101770
101771 +#ifdef CONFIG_PAX_LATENT_ENTROPY
101772 +bool __meminitdata extra_latent_entropy;
101773 +
101774 +static int __init setup_pax_extra_latent_entropy(char *str)
101775 +{
101776 + extra_latent_entropy = true;
101777 + return 0;
101778 +}
101779 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
101780 +
101781 +volatile u64 latent_entropy __latent_entropy;
101782 +EXPORT_SYMBOL(latent_entropy);
101783 +#endif
101784 +
101785 void __init __free_pages_bootmem(struct page *page, unsigned int order)
101786 {
101787 unsigned int nr_pages = 1 << order;
101788 @@ -799,6 +824,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
101789 __ClearPageReserved(p);
101790 set_page_count(p, 0);
101791
101792 +#ifdef CONFIG_PAX_LATENT_ENTROPY
101793 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
101794 + u64 hash = 0;
101795 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
101796 + const u64 *data = lowmem_page_address(page);
101797 +
101798 + for (index = 0; index < end; index++)
101799 + hash ^= hash + data[index];
101800 + latent_entropy ^= hash;
101801 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
101802 + }
101803 +#endif
101804 +
101805 page_zone(page)->managed_pages += nr_pages;
101806 set_page_refcounted(page);
101807 __free_pages(page, order);
101808 @@ -927,8 +965,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
101809 arch_alloc_page(page, order);
101810 kernel_map_pages(page, 1 << order, 1);
101811
101812 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
101813 if (gfp_flags & __GFP_ZERO)
101814 prep_zero_page(page, order, gfp_flags);
101815 +#endif
101816
101817 if (order && (gfp_flags & __GFP_COMP))
101818 prep_compound_page(page, order);
101819 @@ -2427,7 +2467,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
101820 continue;
101821 mod_zone_page_state(zone, NR_ALLOC_BATCH,
101822 high_wmark_pages(zone) - low_wmark_pages(zone) -
101823 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
101824 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
101825 }
101826 }
101827
101828 diff --git a/mm/percpu.c b/mm/percpu.c
101829 index 2ddf9a9..f8fc075 100644
101830 --- a/mm/percpu.c
101831 +++ b/mm/percpu.c
101832 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
101833 static unsigned int pcpu_high_unit_cpu __read_mostly;
101834
101835 /* the address of the first chunk which starts with the kernel static area */
101836 -void *pcpu_base_addr __read_mostly;
101837 +void *pcpu_base_addr __read_only;
101838 EXPORT_SYMBOL_GPL(pcpu_base_addr);
101839
101840 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
101841 diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c
101842 index a8b9199..dfb79e0 100644
101843 --- a/mm/pgtable-generic.c
101844 +++ b/mm/pgtable-generic.c
101845 @@ -195,7 +195,7 @@ void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
101846 pmd_t entry = *pmdp;
101847 if (pmd_numa(entry))
101848 entry = pmd_mknonnuma(entry);
101849 - set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(*pmdp));
101850 + set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(entry));
101851 flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
101852 }
101853 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
101854 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
101855 index 5077afc..846c9ef 100644
101856 --- a/mm/process_vm_access.c
101857 +++ b/mm/process_vm_access.c
101858 @@ -13,6 +13,7 @@
101859 #include <linux/uio.h>
101860 #include <linux/sched.h>
101861 #include <linux/highmem.h>
101862 +#include <linux/security.h>
101863 #include <linux/ptrace.h>
101864 #include <linux/slab.h>
101865 #include <linux/syscalls.h>
101866 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
101867 ssize_t iov_len;
101868 size_t total_len = iov_iter_count(iter);
101869
101870 + return -ENOSYS; // PaX: until properly audited
101871 +
101872 /*
101873 * Work out how many pages of struct pages we're going to need
101874 * when eventually calling get_user_pages
101875 */
101876 for (i = 0; i < riovcnt; i++) {
101877 iov_len = rvec[i].iov_len;
101878 - if (iov_len > 0) {
101879 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
101880 - + iov_len)
101881 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
101882 - / PAGE_SIZE + 1;
101883 - nr_pages = max(nr_pages, nr_pages_iov);
101884 - }
101885 + if (iov_len <= 0)
101886 + continue;
101887 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
101888 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
101889 + nr_pages = max(nr_pages, nr_pages_iov);
101890 }
101891
101892 if (nr_pages == 0)
101893 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
101894 goto free_proc_pages;
101895 }
101896
101897 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
101898 + rc = -EPERM;
101899 + goto put_task_struct;
101900 + }
101901 +
101902 mm = mm_access(task, PTRACE_MODE_ATTACH);
101903 if (!mm || IS_ERR(mm)) {
101904 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
101905 diff --git a/mm/rmap.c b/mm/rmap.c
101906 index 22a4a76..9551288 100644
101907 --- a/mm/rmap.c
101908 +++ b/mm/rmap.c
101909 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
101910 struct anon_vma *anon_vma = vma->anon_vma;
101911 struct anon_vma_chain *avc;
101912
101913 +#ifdef CONFIG_PAX_SEGMEXEC
101914 + struct anon_vma_chain *avc_m = NULL;
101915 +#endif
101916 +
101917 might_sleep();
101918 if (unlikely(!anon_vma)) {
101919 struct mm_struct *mm = vma->vm_mm;
101920 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
101921 if (!avc)
101922 goto out_enomem;
101923
101924 +#ifdef CONFIG_PAX_SEGMEXEC
101925 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
101926 + if (!avc_m)
101927 + goto out_enomem_free_avc;
101928 +#endif
101929 +
101930 anon_vma = find_mergeable_anon_vma(vma);
101931 allocated = NULL;
101932 if (!anon_vma) {
101933 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
101934 /* page_table_lock to protect against threads */
101935 spin_lock(&mm->page_table_lock);
101936 if (likely(!vma->anon_vma)) {
101937 +
101938 +#ifdef CONFIG_PAX_SEGMEXEC
101939 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
101940 +
101941 + if (vma_m) {
101942 + BUG_ON(vma_m->anon_vma);
101943 + vma_m->anon_vma = anon_vma;
101944 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
101945 + avc_m = NULL;
101946 + }
101947 +#endif
101948 +
101949 vma->anon_vma = anon_vma;
101950 anon_vma_chain_link(vma, avc, anon_vma);
101951 allocated = NULL;
101952 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
101953
101954 if (unlikely(allocated))
101955 put_anon_vma(allocated);
101956 +
101957 +#ifdef CONFIG_PAX_SEGMEXEC
101958 + if (unlikely(avc_m))
101959 + anon_vma_chain_free(avc_m);
101960 +#endif
101961 +
101962 if (unlikely(avc))
101963 anon_vma_chain_free(avc);
101964 }
101965 return 0;
101966
101967 out_enomem_free_avc:
101968 +
101969 +#ifdef CONFIG_PAX_SEGMEXEC
101970 + if (avc_m)
101971 + anon_vma_chain_free(avc_m);
101972 +#endif
101973 +
101974 anon_vma_chain_free(avc);
101975 out_enomem:
101976 return -ENOMEM;
101977 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
101978 * Attach the anon_vmas from src to dst.
101979 * Returns 0 on success, -ENOMEM on failure.
101980 */
101981 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
101982 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
101983 {
101984 struct anon_vma_chain *avc, *pavc;
101985 struct anon_vma *root = NULL;
101986 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
101987 * the corresponding VMA in the parent process is attached to.
101988 * Returns 0 on success, non-zero on failure.
101989 */
101990 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
101991 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
101992 {
101993 struct anon_vma_chain *avc;
101994 struct anon_vma *anon_vma;
101995 @@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
101996 void __init anon_vma_init(void)
101997 {
101998 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
101999 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
102000 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
102001 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
102002 + anon_vma_ctor);
102003 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
102004 + SLAB_PANIC|SLAB_NO_SANITIZE);
102005 }
102006
102007 /*
102008 diff --git a/mm/shmem.c b/mm/shmem.c
102009 index af68b15..1227320 100644
102010 --- a/mm/shmem.c
102011 +++ b/mm/shmem.c
102012 @@ -33,7 +33,7 @@
102013 #include <linux/swap.h>
102014 #include <linux/aio.h>
102015
102016 -static struct vfsmount *shm_mnt;
102017 +struct vfsmount *shm_mnt;
102018
102019 #ifdef CONFIG_SHMEM
102020 /*
102021 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
102022 #define BOGO_DIRENT_SIZE 20
102023
102024 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
102025 -#define SHORT_SYMLINK_LEN 128
102026 +#define SHORT_SYMLINK_LEN 64
102027
102028 /*
102029 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
102030 @@ -2219,6 +2219,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
102031 static int shmem_xattr_validate(const char *name)
102032 {
102033 struct { const char *prefix; size_t len; } arr[] = {
102034 +
102035 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
102036 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
102037 +#endif
102038 +
102039 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
102040 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
102041 };
102042 @@ -2274,6 +2279,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
102043 if (err)
102044 return err;
102045
102046 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
102047 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
102048 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
102049 + return -EOPNOTSUPP;
102050 + if (size > 8)
102051 + return -EINVAL;
102052 + }
102053 +#endif
102054 +
102055 return simple_xattr_set(&info->xattrs, name, value, size, flags);
102056 }
102057
102058 @@ -2586,8 +2600,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
102059 int err = -ENOMEM;
102060
102061 /* Round up to L1_CACHE_BYTES to resist false sharing */
102062 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
102063 - L1_CACHE_BYTES), GFP_KERNEL);
102064 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
102065 if (!sbinfo)
102066 return -ENOMEM;
102067
102068 diff --git a/mm/slab.c b/mm/slab.c
102069 index 3070b92..bcfff83 100644
102070 --- a/mm/slab.c
102071 +++ b/mm/slab.c
102072 @@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
102073 if ((x)->max_freeable < i) \
102074 (x)->max_freeable = i; \
102075 } while (0)
102076 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
102077 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
102078 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
102079 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
102080 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
102081 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
102082 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
102083 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
102084 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
102085 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
102086 #else
102087 #define STATS_INC_ACTIVE(x) do { } while (0)
102088 #define STATS_DEC_ACTIVE(x) do { } while (0)
102089 @@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
102090 #define STATS_INC_ALLOCMISS(x) do { } while (0)
102091 #define STATS_INC_FREEHIT(x) do { } while (0)
102092 #define STATS_INC_FREEMISS(x) do { } while (0)
102093 +#define STATS_INC_SANITIZED(x) do { } while (0)
102094 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
102095 #endif
102096
102097 #if DEBUG
102098 @@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
102099 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
102100 */
102101 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
102102 - const struct page *page, void *obj)
102103 + const struct page *page, const void *obj)
102104 {
102105 u32 offset = (obj - page->s_mem);
102106 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
102107 @@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
102108 */
102109
102110 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
102111 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
102112 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
102113
102114 if (INDEX_AC != INDEX_NODE)
102115 kmalloc_caches[INDEX_NODE] =
102116 create_kmalloc_cache("kmalloc-node",
102117 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
102118 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
102119
102120 slab_early_init = 0;
102121
102122 @@ -3512,6 +3516,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
102123 struct array_cache *ac = cpu_cache_get(cachep);
102124
102125 check_irq_off();
102126 +
102127 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102128 + if (pax_sanitize_slab) {
102129 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
102130 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
102131 +
102132 + if (cachep->ctor)
102133 + cachep->ctor(objp);
102134 +
102135 + STATS_INC_SANITIZED(cachep);
102136 + } else
102137 + STATS_INC_NOT_SANITIZED(cachep);
102138 + }
102139 +#endif
102140 +
102141 kmemleak_free_recursive(objp, cachep->flags);
102142 objp = cache_free_debugcheck(cachep, objp, caller);
102143
102144 @@ -3735,6 +3754,7 @@ void kfree(const void *objp)
102145
102146 if (unlikely(ZERO_OR_NULL_PTR(objp)))
102147 return;
102148 + VM_BUG_ON(!virt_addr_valid(objp));
102149 local_irq_save(flags);
102150 kfree_debugcheck(objp);
102151 c = virt_to_cache(objp);
102152 @@ -4176,14 +4196,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
102153 }
102154 /* cpu stats */
102155 {
102156 - unsigned long allochit = atomic_read(&cachep->allochit);
102157 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
102158 - unsigned long freehit = atomic_read(&cachep->freehit);
102159 - unsigned long freemiss = atomic_read(&cachep->freemiss);
102160 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
102161 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
102162 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
102163 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
102164
102165 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
102166 allochit, allocmiss, freehit, freemiss);
102167 }
102168 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102169 + {
102170 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
102171 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
102172 +
102173 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
102174 + }
102175 +#endif
102176 #endif
102177 }
102178
102179 @@ -4404,13 +4432,69 @@ static const struct file_operations proc_slabstats_operations = {
102180 static int __init slab_proc_init(void)
102181 {
102182 #ifdef CONFIG_DEBUG_SLAB_LEAK
102183 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
102184 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
102185 #endif
102186 return 0;
102187 }
102188 module_init(slab_proc_init);
102189 #endif
102190
102191 +bool is_usercopy_object(const void *ptr)
102192 +{
102193 + struct page *page;
102194 + struct kmem_cache *cachep;
102195 +
102196 + if (ZERO_OR_NULL_PTR(ptr))
102197 + return false;
102198 +
102199 + if (!slab_is_available())
102200 + return false;
102201 +
102202 + if (!virt_addr_valid(ptr))
102203 + return false;
102204 +
102205 + page = virt_to_head_page(ptr);
102206 +
102207 + if (!PageSlab(page))
102208 + return false;
102209 +
102210 + cachep = page->slab_cache;
102211 + return cachep->flags & SLAB_USERCOPY;
102212 +}
102213 +
102214 +#ifdef CONFIG_PAX_USERCOPY
102215 +const char *check_heap_object(const void *ptr, unsigned long n)
102216 +{
102217 + struct page *page;
102218 + struct kmem_cache *cachep;
102219 + unsigned int objnr;
102220 + unsigned long offset;
102221 +
102222 + if (ZERO_OR_NULL_PTR(ptr))
102223 + return "<null>";
102224 +
102225 + if (!virt_addr_valid(ptr))
102226 + return NULL;
102227 +
102228 + page = virt_to_head_page(ptr);
102229 +
102230 + if (!PageSlab(page))
102231 + return NULL;
102232 +
102233 + cachep = page->slab_cache;
102234 + if (!(cachep->flags & SLAB_USERCOPY))
102235 + return cachep->name;
102236 +
102237 + objnr = obj_to_index(cachep, page, ptr);
102238 + BUG_ON(objnr >= cachep->num);
102239 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
102240 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
102241 + return NULL;
102242 +
102243 + return cachep->name;
102244 +}
102245 +#endif
102246 +
102247 /**
102248 * ksize - get the actual amount of memory allocated for a given object
102249 * @objp: Pointer to the object
102250 diff --git a/mm/slab.h b/mm/slab.h
102251 index 961a3fb..6b12514 100644
102252 --- a/mm/slab.h
102253 +++ b/mm/slab.h
102254 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
102255 /* The slab cache that manages slab cache information */
102256 extern struct kmem_cache *kmem_cache;
102257
102258 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102259 +#ifdef CONFIG_X86_64
102260 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
102261 +#else
102262 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
102263 +#endif
102264 +extern bool pax_sanitize_slab;
102265 +#endif
102266 +
102267 unsigned long calculate_alignment(unsigned long flags,
102268 unsigned long align, unsigned long size);
102269
102270 @@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
102271
102272 /* Legal flag mask for kmem_cache_create(), for various configurations */
102273 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
102274 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
102275 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
102276 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
102277
102278 #if defined(CONFIG_DEBUG_SLAB)
102279 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
102280 @@ -251,6 +261,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
102281 return s;
102282
102283 page = virt_to_head_page(x);
102284 +
102285 + BUG_ON(!PageSlab(page));
102286 +
102287 cachep = page->slab_cache;
102288 if (slab_equal_or_root(cachep, s))
102289 return cachep;
102290 diff --git a/mm/slab_common.c b/mm/slab_common.c
102291 index d31c4ba..1121296 100644
102292 --- a/mm/slab_common.c
102293 +++ b/mm/slab_common.c
102294 @@ -23,11 +23,22 @@
102295
102296 #include "slab.h"
102297
102298 -enum slab_state slab_state;
102299 +enum slab_state slab_state __read_only;
102300 LIST_HEAD(slab_caches);
102301 DEFINE_MUTEX(slab_mutex);
102302 struct kmem_cache *kmem_cache;
102303
102304 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102305 +bool pax_sanitize_slab __read_only = true;
102306 +static int __init pax_sanitize_slab_setup(char *str)
102307 +{
102308 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
102309 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
102310 + return 1;
102311 +}
102312 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
102313 +#endif
102314 +
102315 #ifdef CONFIG_DEBUG_VM
102316 static int kmem_cache_sanity_check(const char *name, size_t size)
102317 {
102318 @@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
102319 if (err)
102320 goto out_free_cache;
102321
102322 - s->refcount = 1;
102323 + atomic_set(&s->refcount, 1);
102324 list_add(&s->list, &slab_caches);
102325 out:
102326 if (err)
102327 @@ -339,8 +350,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
102328
102329 mutex_lock(&slab_mutex);
102330
102331 - s->refcount--;
102332 - if (s->refcount)
102333 + if (!atomic_dec_and_test(&s->refcount))
102334 goto out_unlock;
102335
102336 if (memcg_cleanup_cache_params(s) != 0)
102337 @@ -360,7 +370,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
102338 rcu_barrier();
102339
102340 memcg_free_cache_params(s);
102341 -#ifdef SLAB_SUPPORTS_SYSFS
102342 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
102343 sysfs_slab_remove(s);
102344 #else
102345 slab_kmem_cache_release(s);
102346 @@ -416,7 +426,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
102347 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
102348 name, size, err);
102349
102350 - s->refcount = -1; /* Exempt from merging for now */
102351 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
102352 }
102353
102354 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
102355 @@ -429,7 +439,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
102356
102357 create_boot_cache(s, name, size, flags);
102358 list_add(&s->list, &slab_caches);
102359 - s->refcount = 1;
102360 + atomic_set(&s->refcount, 1);
102361 return s;
102362 }
102363
102364 @@ -441,6 +451,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
102365 EXPORT_SYMBOL(kmalloc_dma_caches);
102366 #endif
102367
102368 +#ifdef CONFIG_PAX_USERCOPY_SLABS
102369 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
102370 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
102371 +#endif
102372 +
102373 /*
102374 * Conversion table for small slabs sizes / 8 to the index in the
102375 * kmalloc array. This is necessary for slabs < 192 since we have non power
102376 @@ -505,6 +520,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
102377 return kmalloc_dma_caches[index];
102378
102379 #endif
102380 +
102381 +#ifdef CONFIG_PAX_USERCOPY_SLABS
102382 + if (unlikely((flags & GFP_USERCOPY)))
102383 + return kmalloc_usercopy_caches[index];
102384 +
102385 +#endif
102386 +
102387 return kmalloc_caches[index];
102388 }
102389
102390 @@ -561,7 +583,7 @@ void __init create_kmalloc_caches(unsigned long flags)
102391 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
102392 if (!kmalloc_caches[i]) {
102393 kmalloc_caches[i] = create_kmalloc_cache(NULL,
102394 - 1 << i, flags);
102395 + 1 << i, SLAB_USERCOPY | flags);
102396 }
102397
102398 /*
102399 @@ -570,10 +592,10 @@ void __init create_kmalloc_caches(unsigned long flags)
102400 * earlier power of two caches
102401 */
102402 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
102403 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
102404 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
102405
102406 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
102407 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
102408 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
102409 }
102410
102411 /* Kmalloc array is now usable */
102412 @@ -606,6 +628,23 @@ void __init create_kmalloc_caches(unsigned long flags)
102413 }
102414 }
102415 #endif
102416 +
102417 +#ifdef CONFIG_PAX_USERCOPY_SLABS
102418 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
102419 + struct kmem_cache *s = kmalloc_caches[i];
102420 +
102421 + if (s) {
102422 + int size = kmalloc_size(i);
102423 + char *n = kasprintf(GFP_NOWAIT,
102424 + "usercopy-kmalloc-%d", size);
102425 +
102426 + BUG_ON(!n);
102427 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
102428 + size, SLAB_USERCOPY | flags);
102429 + }
102430 + }
102431 +#endif
102432 +
102433 }
102434 #endif /* !CONFIG_SLOB */
102435
102436 @@ -664,6 +703,9 @@ void print_slabinfo_header(struct seq_file *m)
102437 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
102438 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
102439 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
102440 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102441 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
102442 +#endif
102443 #endif
102444 seq_putc(m, '\n');
102445 }
102446 diff --git a/mm/slob.c b/mm/slob.c
102447 index 21980e0..ed9a648 100644
102448 --- a/mm/slob.c
102449 +++ b/mm/slob.c
102450 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
102451 /*
102452 * Return the size of a slob block.
102453 */
102454 -static slobidx_t slob_units(slob_t *s)
102455 +static slobidx_t slob_units(const slob_t *s)
102456 {
102457 if (s->units > 0)
102458 return s->units;
102459 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
102460 /*
102461 * Return the next free slob block pointer after this one.
102462 */
102463 -static slob_t *slob_next(slob_t *s)
102464 +static slob_t *slob_next(const slob_t *s)
102465 {
102466 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
102467 slobidx_t next;
102468 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
102469 /*
102470 * Returns true if s is the last free block in its page.
102471 */
102472 -static int slob_last(slob_t *s)
102473 +static int slob_last(const slob_t *s)
102474 {
102475 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
102476 }
102477
102478 -static void *slob_new_pages(gfp_t gfp, int order, int node)
102479 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
102480 {
102481 - void *page;
102482 + struct page *page;
102483
102484 #ifdef CONFIG_NUMA
102485 if (node != NUMA_NO_NODE)
102486 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
102487 if (!page)
102488 return NULL;
102489
102490 - return page_address(page);
102491 + __SetPageSlab(page);
102492 + return page;
102493 }
102494
102495 -static void slob_free_pages(void *b, int order)
102496 +static void slob_free_pages(struct page *sp, int order)
102497 {
102498 if (current->reclaim_state)
102499 current->reclaim_state->reclaimed_slab += 1 << order;
102500 - free_pages((unsigned long)b, order);
102501 + __ClearPageSlab(sp);
102502 + page_mapcount_reset(sp);
102503 + sp->private = 0;
102504 + __free_pages(sp, order);
102505 }
102506
102507 /*
102508 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
102509
102510 /* Not enough space: must allocate a new page */
102511 if (!b) {
102512 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
102513 - if (!b)
102514 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
102515 + if (!sp)
102516 return NULL;
102517 - sp = virt_to_page(b);
102518 - __SetPageSlab(sp);
102519 + b = page_address(sp);
102520
102521 spin_lock_irqsave(&slob_lock, flags);
102522 sp->units = SLOB_UNITS(PAGE_SIZE);
102523 sp->freelist = b;
102524 + sp->private = 0;
102525 INIT_LIST_HEAD(&sp->lru);
102526 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
102527 set_slob_page_free(sp, slob_list);
102528 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
102529 if (slob_page_free(sp))
102530 clear_slob_page_free(sp);
102531 spin_unlock_irqrestore(&slob_lock, flags);
102532 - __ClearPageSlab(sp);
102533 - page_mapcount_reset(sp);
102534 - slob_free_pages(b, 0);
102535 + slob_free_pages(sp, 0);
102536 return;
102537 }
102538
102539 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102540 + if (pax_sanitize_slab)
102541 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
102542 +#endif
102543 +
102544 if (!slob_page_free(sp)) {
102545 /* This slob page is about to become partially free. Easy! */
102546 sp->units = units;
102547 @@ -424,11 +431,10 @@ out:
102548 */
102549
102550 static __always_inline void *
102551 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
102552 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
102553 {
102554 - unsigned int *m;
102555 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
102556 - void *ret;
102557 + slob_t *m;
102558 + void *ret = NULL;
102559
102560 gfp &= gfp_allowed_mask;
102561
102562 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
102563
102564 if (!m)
102565 return NULL;
102566 - *m = size;
102567 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
102568 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
102569 + m[0].units = size;
102570 + m[1].units = align;
102571 ret = (void *)m + align;
102572
102573 trace_kmalloc_node(caller, ret,
102574 size, size + align, gfp, node);
102575 } else {
102576 unsigned int order = get_order(size);
102577 + struct page *page;
102578
102579 if (likely(order))
102580 gfp |= __GFP_COMP;
102581 - ret = slob_new_pages(gfp, order, node);
102582 + page = slob_new_pages(gfp, order, node);
102583 + if (page) {
102584 + ret = page_address(page);
102585 + page->private = size;
102586 + }
102587
102588 trace_kmalloc_node(caller, ret,
102589 size, PAGE_SIZE << order, gfp, node);
102590 }
102591
102592 - kmemleak_alloc(ret, size, 1, gfp);
102593 + return ret;
102594 +}
102595 +
102596 +static __always_inline void *
102597 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
102598 +{
102599 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
102600 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
102601 +
102602 + if (!ZERO_OR_NULL_PTR(ret))
102603 + kmemleak_alloc(ret, size, 1, gfp);
102604 return ret;
102605 }
102606
102607 @@ -493,34 +517,112 @@ void kfree(const void *block)
102608 return;
102609 kmemleak_free(block);
102610
102611 + VM_BUG_ON(!virt_addr_valid(block));
102612 sp = virt_to_page(block);
102613 - if (PageSlab(sp)) {
102614 + VM_BUG_ON(!PageSlab(sp));
102615 + if (!sp->private) {
102616 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
102617 - unsigned int *m = (unsigned int *)(block - align);
102618 - slob_free(m, *m + align);
102619 - } else
102620 + slob_t *m = (slob_t *)(block - align);
102621 + slob_free(m, m[0].units + align);
102622 + } else {
102623 + __ClearPageSlab(sp);
102624 + page_mapcount_reset(sp);
102625 + sp->private = 0;
102626 __free_pages(sp, compound_order(sp));
102627 + }
102628 }
102629 EXPORT_SYMBOL(kfree);
102630
102631 +bool is_usercopy_object(const void *ptr)
102632 +{
102633 + if (!slab_is_available())
102634 + return false;
102635 +
102636 + // PAX: TODO
102637 +
102638 + return false;
102639 +}
102640 +
102641 +#ifdef CONFIG_PAX_USERCOPY
102642 +const char *check_heap_object(const void *ptr, unsigned long n)
102643 +{
102644 + struct page *page;
102645 + const slob_t *free;
102646 + const void *base;
102647 + unsigned long flags;
102648 +
102649 + if (ZERO_OR_NULL_PTR(ptr))
102650 + return "<null>";
102651 +
102652 + if (!virt_addr_valid(ptr))
102653 + return NULL;
102654 +
102655 + page = virt_to_head_page(ptr);
102656 + if (!PageSlab(page))
102657 + return NULL;
102658 +
102659 + if (page->private) {
102660 + base = page;
102661 + if (base <= ptr && n <= page->private - (ptr - base))
102662 + return NULL;
102663 + return "<slob>";
102664 + }
102665 +
102666 + /* some tricky double walking to find the chunk */
102667 + spin_lock_irqsave(&slob_lock, flags);
102668 + base = (void *)((unsigned long)ptr & PAGE_MASK);
102669 + free = page->freelist;
102670 +
102671 + while (!slob_last(free) && (void *)free <= ptr) {
102672 + base = free + slob_units(free);
102673 + free = slob_next(free);
102674 + }
102675 +
102676 + while (base < (void *)free) {
102677 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
102678 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
102679 + int offset;
102680 +
102681 + if (ptr < base + align)
102682 + break;
102683 +
102684 + offset = ptr - base - align;
102685 + if (offset >= m) {
102686 + base += size;
102687 + continue;
102688 + }
102689 +
102690 + if (n > m - offset)
102691 + break;
102692 +
102693 + spin_unlock_irqrestore(&slob_lock, flags);
102694 + return NULL;
102695 + }
102696 +
102697 + spin_unlock_irqrestore(&slob_lock, flags);
102698 + return "<slob>";
102699 +}
102700 +#endif
102701 +
102702 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
102703 size_t ksize(const void *block)
102704 {
102705 struct page *sp;
102706 int align;
102707 - unsigned int *m;
102708 + slob_t *m;
102709
102710 BUG_ON(!block);
102711 if (unlikely(block == ZERO_SIZE_PTR))
102712 return 0;
102713
102714 sp = virt_to_page(block);
102715 - if (unlikely(!PageSlab(sp)))
102716 - return PAGE_SIZE << compound_order(sp);
102717 + VM_BUG_ON(!PageSlab(sp));
102718 + if (sp->private)
102719 + return sp->private;
102720
102721 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
102722 - m = (unsigned int *)(block - align);
102723 - return SLOB_UNITS(*m) * SLOB_UNIT;
102724 + m = (slob_t *)(block - align);
102725 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
102726 }
102727 EXPORT_SYMBOL(ksize);
102728
102729 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
102730
102731 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
102732 {
102733 - void *b;
102734 + void *b = NULL;
102735
102736 flags &= gfp_allowed_mask;
102737
102738 lockdep_trace_alloc(flags);
102739
102740 +#ifdef CONFIG_PAX_USERCOPY_SLABS
102741 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
102742 +#else
102743 if (c->size < PAGE_SIZE) {
102744 b = slob_alloc(c->size, flags, c->align, node);
102745 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
102746 SLOB_UNITS(c->size) * SLOB_UNIT,
102747 flags, node);
102748 } else {
102749 - b = slob_new_pages(flags, get_order(c->size), node);
102750 + struct page *sp;
102751 +
102752 + sp = slob_new_pages(flags, get_order(c->size), node);
102753 + if (sp) {
102754 + b = page_address(sp);
102755 + sp->private = c->size;
102756 + }
102757 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
102758 PAGE_SIZE << get_order(c->size),
102759 flags, node);
102760 }
102761 +#endif
102762
102763 if (b && c->ctor)
102764 c->ctor(b);
102765 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
102766
102767 static void __kmem_cache_free(void *b, int size)
102768 {
102769 - if (size < PAGE_SIZE)
102770 + struct page *sp;
102771 +
102772 + sp = virt_to_page(b);
102773 + BUG_ON(!PageSlab(sp));
102774 + if (!sp->private)
102775 slob_free(b, size);
102776 else
102777 - slob_free_pages(b, get_order(size));
102778 + slob_free_pages(sp, get_order(size));
102779 }
102780
102781 static void kmem_rcu_free(struct rcu_head *head)
102782 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
102783
102784 void kmem_cache_free(struct kmem_cache *c, void *b)
102785 {
102786 + int size = c->size;
102787 +
102788 +#ifdef CONFIG_PAX_USERCOPY_SLABS
102789 + if (size + c->align < PAGE_SIZE) {
102790 + size += c->align;
102791 + b -= c->align;
102792 + }
102793 +#endif
102794 +
102795 kmemleak_free_recursive(b, c->flags);
102796 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
102797 struct slob_rcu *slob_rcu;
102798 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
102799 - slob_rcu->size = c->size;
102800 + slob_rcu = b + (size - sizeof(struct slob_rcu));
102801 + slob_rcu->size = size;
102802 call_rcu(&slob_rcu->head, kmem_rcu_free);
102803 } else {
102804 - __kmem_cache_free(b, c->size);
102805 + __kmem_cache_free(b, size);
102806 }
102807
102808 +#ifdef CONFIG_PAX_USERCOPY_SLABS
102809 + trace_kfree(_RET_IP_, b);
102810 +#else
102811 trace_kmem_cache_free(_RET_IP_, b);
102812 +#endif
102813 +
102814 }
102815 EXPORT_SYMBOL(kmem_cache_free);
102816
102817 diff --git a/mm/slub.c b/mm/slub.c
102818 index 7300480..cb92846 100644
102819 --- a/mm/slub.c
102820 +++ b/mm/slub.c
102821 @@ -207,7 +207,7 @@ struct track {
102822
102823 enum track_item { TRACK_ALLOC, TRACK_FREE };
102824
102825 -#ifdef CONFIG_SYSFS
102826 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
102827 static int sysfs_slab_add(struct kmem_cache *);
102828 static int sysfs_slab_alias(struct kmem_cache *, const char *);
102829 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
102830 @@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
102831 if (!t->addr)
102832 return;
102833
102834 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
102835 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
102836 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
102837 #ifdef CONFIG_STACKTRACE
102838 {
102839 @@ -2673,6 +2673,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
102840
102841 slab_free_hook(s, x);
102842
102843 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102844 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
102845 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
102846 + if (s->ctor)
102847 + s->ctor(x);
102848 + }
102849 +#endif
102850 +
102851 redo:
102852 /*
102853 * Determine the currently cpus per cpu slab.
102854 @@ -2740,7 +2748,7 @@ static int slub_min_objects;
102855 * Merge control. If this is set then no merging of slab caches will occur.
102856 * (Could be removed. This was introduced to pacify the merge skeptics.)
102857 */
102858 -static int slub_nomerge;
102859 +static int slub_nomerge = 1;
102860
102861 /*
102862 * Calculate the order of allocation given an slab object size.
102863 @@ -3019,6 +3027,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
102864 s->inuse = size;
102865
102866 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
102867 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102868 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
102869 +#endif
102870 s->ctor)) {
102871 /*
102872 * Relocate free pointer after the object if it is not
102873 @@ -3347,6 +3358,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
102874 EXPORT_SYMBOL(__kmalloc_node);
102875 #endif
102876
102877 +bool is_usercopy_object(const void *ptr)
102878 +{
102879 + struct page *page;
102880 + struct kmem_cache *s;
102881 +
102882 + if (ZERO_OR_NULL_PTR(ptr))
102883 + return false;
102884 +
102885 + if (!slab_is_available())
102886 + return false;
102887 +
102888 + if (!virt_addr_valid(ptr))
102889 + return false;
102890 +
102891 + page = virt_to_head_page(ptr);
102892 +
102893 + if (!PageSlab(page))
102894 + return false;
102895 +
102896 + s = page->slab_cache;
102897 + return s->flags & SLAB_USERCOPY;
102898 +}
102899 +
102900 +#ifdef CONFIG_PAX_USERCOPY
102901 +const char *check_heap_object(const void *ptr, unsigned long n)
102902 +{
102903 + struct page *page;
102904 + struct kmem_cache *s;
102905 + unsigned long offset;
102906 +
102907 + if (ZERO_OR_NULL_PTR(ptr))
102908 + return "<null>";
102909 +
102910 + if (!virt_addr_valid(ptr))
102911 + return NULL;
102912 +
102913 + page = virt_to_head_page(ptr);
102914 +
102915 + if (!PageSlab(page))
102916 + return NULL;
102917 +
102918 + s = page->slab_cache;
102919 + if (!(s->flags & SLAB_USERCOPY))
102920 + return s->name;
102921 +
102922 + offset = (ptr - page_address(page)) % s->size;
102923 + if (offset <= s->object_size && n <= s->object_size - offset)
102924 + return NULL;
102925 +
102926 + return s->name;
102927 +}
102928 +#endif
102929 +
102930 size_t ksize(const void *object)
102931 {
102932 struct page *page;
102933 @@ -3375,6 +3439,7 @@ void kfree(const void *x)
102934 if (unlikely(ZERO_OR_NULL_PTR(x)))
102935 return;
102936
102937 + VM_BUG_ON(!virt_addr_valid(x));
102938 page = virt_to_head_page(x);
102939 if (unlikely(!PageSlab(page))) {
102940 BUG_ON(!PageCompound(page));
102941 @@ -3680,7 +3745,7 @@ static int slab_unmergeable(struct kmem_cache *s)
102942 /*
102943 * We may have set a slab to be unmergeable during bootstrap.
102944 */
102945 - if (s->refcount < 0)
102946 + if (atomic_read(&s->refcount) < 0)
102947 return 1;
102948
102949 return 0;
102950 @@ -3737,7 +3802,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
102951 int i;
102952 struct kmem_cache *c;
102953
102954 - s->refcount++;
102955 + atomic_inc(&s->refcount);
102956
102957 /*
102958 * Adjust the object sizes so that we clear
102959 @@ -3756,7 +3821,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
102960 }
102961
102962 if (sysfs_slab_alias(s, name)) {
102963 - s->refcount--;
102964 + atomic_dec(&s->refcount);
102965 s = NULL;
102966 }
102967 }
102968 @@ -3873,7 +3938,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
102969 }
102970 #endif
102971
102972 -#ifdef CONFIG_SYSFS
102973 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
102974 static int count_inuse(struct page *page)
102975 {
102976 return page->inuse;
102977 @@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
102978 len += sprintf(buf + len, "%7ld ", l->count);
102979
102980 if (l->addr)
102981 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102982 + len += sprintf(buf + len, "%pS", NULL);
102983 +#else
102984 len += sprintf(buf + len, "%pS", (void *)l->addr);
102985 +#endif
102986 else
102987 len += sprintf(buf + len, "<not-available>");
102988
102989 @@ -4258,12 +4327,12 @@ static void resiliency_test(void)
102990 validate_slab_cache(kmalloc_caches[9]);
102991 }
102992 #else
102993 -#ifdef CONFIG_SYSFS
102994 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
102995 static void resiliency_test(void) {};
102996 #endif
102997 #endif
102998
102999 -#ifdef CONFIG_SYSFS
103000 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103001 enum slab_stat_type {
103002 SL_ALL, /* All slabs */
103003 SL_PARTIAL, /* Only partially allocated slabs */
103004 @@ -4503,13 +4572,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
103005 {
103006 if (!s->ctor)
103007 return 0;
103008 +#ifdef CONFIG_GRKERNSEC_HIDESYM
103009 + return sprintf(buf, "%pS\n", NULL);
103010 +#else
103011 return sprintf(buf, "%pS\n", s->ctor);
103012 +#endif
103013 }
103014 SLAB_ATTR_RO(ctor);
103015
103016 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
103017 {
103018 - return sprintf(buf, "%d\n", s->refcount - 1);
103019 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
103020 }
103021 SLAB_ATTR_RO(aliases);
103022
103023 @@ -4597,6 +4670,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
103024 SLAB_ATTR_RO(cache_dma);
103025 #endif
103026
103027 +#ifdef CONFIG_PAX_USERCOPY_SLABS
103028 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
103029 +{
103030 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
103031 +}
103032 +SLAB_ATTR_RO(usercopy);
103033 +#endif
103034 +
103035 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
103036 {
103037 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
103038 @@ -4931,6 +5012,9 @@ static struct attribute *slab_attrs[] = {
103039 #ifdef CONFIG_ZONE_DMA
103040 &cache_dma_attr.attr,
103041 #endif
103042 +#ifdef CONFIG_PAX_USERCOPY_SLABS
103043 + &usercopy_attr.attr,
103044 +#endif
103045 #ifdef CONFIG_NUMA
103046 &remote_node_defrag_ratio_attr.attr,
103047 #endif
103048 @@ -5181,6 +5265,7 @@ static char *create_unique_id(struct kmem_cache *s)
103049 return name;
103050 }
103051
103052 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103053 static int sysfs_slab_add(struct kmem_cache *s)
103054 {
103055 int err;
103056 @@ -5254,6 +5339,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
103057 kobject_del(&s->kobj);
103058 kobject_put(&s->kobj);
103059 }
103060 +#endif
103061
103062 /*
103063 * Need to buffer aliases during bootup until sysfs becomes
103064 @@ -5267,6 +5353,7 @@ struct saved_alias {
103065
103066 static struct saved_alias *alias_list;
103067
103068 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103069 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
103070 {
103071 struct saved_alias *al;
103072 @@ -5289,6 +5376,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
103073 alias_list = al;
103074 return 0;
103075 }
103076 +#endif
103077
103078 static int __init slab_sysfs_init(void)
103079 {
103080 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
103081 index 4cba9c2..b4f9fcc 100644
103082 --- a/mm/sparse-vmemmap.c
103083 +++ b/mm/sparse-vmemmap.c
103084 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
103085 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
103086 if (!p)
103087 return NULL;
103088 - pud_populate(&init_mm, pud, p);
103089 + pud_populate_kernel(&init_mm, pud, p);
103090 }
103091 return pud;
103092 }
103093 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
103094 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
103095 if (!p)
103096 return NULL;
103097 - pgd_populate(&init_mm, pgd, p);
103098 + pgd_populate_kernel(&init_mm, pgd, p);
103099 }
103100 return pgd;
103101 }
103102 diff --git a/mm/sparse.c b/mm/sparse.c
103103 index d1b48b6..6e8590e 100644
103104 --- a/mm/sparse.c
103105 +++ b/mm/sparse.c
103106 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
103107
103108 for (i = 0; i < PAGES_PER_SECTION; i++) {
103109 if (PageHWPoison(&memmap[i])) {
103110 - atomic_long_sub(1, &num_poisoned_pages);
103111 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
103112 ClearPageHWPoison(&memmap[i]);
103113 }
103114 }
103115 diff --git a/mm/swap.c b/mm/swap.c
103116 index 9e8e347..3c22e0f 100644
103117 --- a/mm/swap.c
103118 +++ b/mm/swap.c
103119 @@ -31,6 +31,7 @@
103120 #include <linux/memcontrol.h>
103121 #include <linux/gfp.h>
103122 #include <linux/uio.h>
103123 +#include <linux/hugetlb.h>
103124
103125 #include "internal.h"
103126
103127 @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
103128
103129 __page_cache_release(page);
103130 dtor = get_compound_page_dtor(page);
103131 + if (!PageHuge(page))
103132 + BUG_ON(dtor != free_compound_page);
103133 (*dtor)(page);
103134 }
103135
103136 diff --git a/mm/swapfile.c b/mm/swapfile.c
103137 index 4c524f7..f7601f17 100644
103138 --- a/mm/swapfile.c
103139 +++ b/mm/swapfile.c
103140 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
103141
103142 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
103143 /* Activity counter to indicate that a swapon or swapoff has occurred */
103144 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
103145 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
103146
103147 static inline unsigned char swap_count(unsigned char ent)
103148 {
103149 @@ -1945,7 +1945,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
103150 spin_unlock(&swap_lock);
103151
103152 err = 0;
103153 - atomic_inc(&proc_poll_event);
103154 + atomic_inc_unchecked(&proc_poll_event);
103155 wake_up_interruptible(&proc_poll_wait);
103156
103157 out_dput:
103158 @@ -1962,8 +1962,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
103159
103160 poll_wait(file, &proc_poll_wait, wait);
103161
103162 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
103163 - seq->poll_event = atomic_read(&proc_poll_event);
103164 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
103165 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
103166 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
103167 }
103168
103169 @@ -2061,7 +2061,7 @@ static int swaps_open(struct inode *inode, struct file *file)
103170 return ret;
103171
103172 seq = file->private_data;
103173 - seq->poll_event = atomic_read(&proc_poll_event);
103174 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
103175 return 0;
103176 }
103177
103178 @@ -2521,7 +2521,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
103179 (frontswap_map) ? "FS" : "");
103180
103181 mutex_unlock(&swapon_mutex);
103182 - atomic_inc(&proc_poll_event);
103183 + atomic_inc_unchecked(&proc_poll_event);
103184 wake_up_interruptible(&proc_poll_wait);
103185
103186 if (S_ISREG(inode->i_mode))
103187 diff --git a/mm/util.c b/mm/util.c
103188 index 33e9f44..be026b2 100644
103189 --- a/mm/util.c
103190 +++ b/mm/util.c
103191 @@ -296,6 +296,12 @@ done:
103192 void arch_pick_mmap_layout(struct mm_struct *mm)
103193 {
103194 mm->mmap_base = TASK_UNMAPPED_BASE;
103195 +
103196 +#ifdef CONFIG_PAX_RANDMMAP
103197 + if (mm->pax_flags & MF_PAX_RANDMMAP)
103198 + mm->mmap_base += mm->delta_mmap;
103199 +#endif
103200 +
103201 mm->get_unmapped_area = arch_get_unmapped_area;
103202 }
103203 #endif
103204 @@ -472,6 +478,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
103205 if (!mm->arg_end)
103206 goto out_mm; /* Shh! No looking before we're done */
103207
103208 + if (gr_acl_handle_procpidmem(task))
103209 + goto out_mm;
103210 +
103211 len = mm->arg_end - mm->arg_start;
103212
103213 if (len > buflen)
103214 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
103215 index f64632b..e8c52e7 100644
103216 --- a/mm/vmalloc.c
103217 +++ b/mm/vmalloc.c
103218 @@ -40,6 +40,21 @@ struct vfree_deferred {
103219 };
103220 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
103221
103222 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103223 +struct stack_deferred_llist {
103224 + struct llist_head list;
103225 + void *stack;
103226 + void *lowmem_stack;
103227 +};
103228 +
103229 +struct stack_deferred {
103230 + struct stack_deferred_llist list;
103231 + struct work_struct wq;
103232 +};
103233 +
103234 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
103235 +#endif
103236 +
103237 static void __vunmap(const void *, int);
103238
103239 static void free_work(struct work_struct *w)
103240 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
103241 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
103242 struct llist_node *llnode = llist_del_all(&p->list);
103243 while (llnode) {
103244 - void *p = llnode;
103245 + void *x = llnode;
103246 llnode = llist_next(llnode);
103247 - __vunmap(p, 1);
103248 + __vunmap(x, 1);
103249 }
103250 }
103251
103252 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103253 +static void unmap_work(struct work_struct *w)
103254 +{
103255 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
103256 + struct llist_node *llnode = llist_del_all(&p->list.list);
103257 + while (llnode) {
103258 + struct stack_deferred_llist *x =
103259 + llist_entry((struct llist_head *)llnode,
103260 + struct stack_deferred_llist, list);
103261 + void *stack = ACCESS_ONCE(x->stack);
103262 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
103263 + llnode = llist_next(llnode);
103264 + __vunmap(stack, 0);
103265 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
103266 + }
103267 +}
103268 +#endif
103269 +
103270 /*** Page table manipulation functions ***/
103271
103272 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
103273 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
103274
103275 pte = pte_offset_kernel(pmd, addr);
103276 do {
103277 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
103278 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
103279 +
103280 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
103281 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
103282 + BUG_ON(!pte_exec(*pte));
103283 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
103284 + continue;
103285 + }
103286 +#endif
103287 +
103288 + {
103289 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
103290 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
103291 + }
103292 } while (pte++, addr += PAGE_SIZE, addr != end);
103293 }
103294
103295 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
103296 pte = pte_alloc_kernel(pmd, addr);
103297 if (!pte)
103298 return -ENOMEM;
103299 +
103300 + pax_open_kernel();
103301 do {
103302 struct page *page = pages[*nr];
103303
103304 - if (WARN_ON(!pte_none(*pte)))
103305 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
103306 + if (pgprot_val(prot) & _PAGE_NX)
103307 +#endif
103308 +
103309 + if (!pte_none(*pte)) {
103310 + pax_close_kernel();
103311 + WARN_ON(1);
103312 return -EBUSY;
103313 - if (WARN_ON(!page))
103314 + }
103315 + if (!page) {
103316 + pax_close_kernel();
103317 + WARN_ON(1);
103318 return -ENOMEM;
103319 + }
103320 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
103321 (*nr)++;
103322 } while (pte++, addr += PAGE_SIZE, addr != end);
103323 + pax_close_kernel();
103324 return 0;
103325 }
103326
103327 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
103328 pmd_t *pmd;
103329 unsigned long next;
103330
103331 - pmd = pmd_alloc(&init_mm, pud, addr);
103332 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
103333 if (!pmd)
103334 return -ENOMEM;
103335 do {
103336 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
103337 pud_t *pud;
103338 unsigned long next;
103339
103340 - pud = pud_alloc(&init_mm, pgd, addr);
103341 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
103342 if (!pud)
103343 return -ENOMEM;
103344 do {
103345 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
103346 if (addr >= MODULES_VADDR && addr < MODULES_END)
103347 return 1;
103348 #endif
103349 +
103350 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
103351 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
103352 + return 1;
103353 +#endif
103354 +
103355 return is_vmalloc_addr(x);
103356 }
103357
103358 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
103359
103360 if (!pgd_none(*pgd)) {
103361 pud_t *pud = pud_offset(pgd, addr);
103362 +#ifdef CONFIG_X86
103363 + if (!pud_large(*pud))
103364 +#endif
103365 if (!pud_none(*pud)) {
103366 pmd_t *pmd = pmd_offset(pud, addr);
103367 +#ifdef CONFIG_X86
103368 + if (!pmd_large(*pmd))
103369 +#endif
103370 if (!pmd_none(*pmd)) {
103371 pte_t *ptep, pte;
103372
103373 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
103374 for_each_possible_cpu(i) {
103375 struct vmap_block_queue *vbq;
103376 struct vfree_deferred *p;
103377 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103378 + struct stack_deferred *p2;
103379 +#endif
103380
103381 vbq = &per_cpu(vmap_block_queue, i);
103382 spin_lock_init(&vbq->lock);
103383 INIT_LIST_HEAD(&vbq->free);
103384 +
103385 p = &per_cpu(vfree_deferred, i);
103386 init_llist_head(&p->list);
103387 INIT_WORK(&p->wq, free_work);
103388 +
103389 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103390 + p2 = &per_cpu(stack_deferred, i);
103391 + init_llist_head(&p2->list.list);
103392 + INIT_WORK(&p2->wq, unmap_work);
103393 +#endif
103394 }
103395
103396 /* Import existing vmlist entries. */
103397 @@ -1318,6 +1397,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
103398 struct vm_struct *area;
103399
103400 BUG_ON(in_interrupt());
103401 +
103402 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
103403 + if (flags & VM_KERNEXEC) {
103404 + if (start != VMALLOC_START || end != VMALLOC_END)
103405 + return NULL;
103406 + start = (unsigned long)MODULES_EXEC_VADDR;
103407 + end = (unsigned long)MODULES_EXEC_END;
103408 + }
103409 +#endif
103410 +
103411 if (flags & VM_IOREMAP)
103412 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
103413
103414 @@ -1523,6 +1612,23 @@ void vunmap(const void *addr)
103415 }
103416 EXPORT_SYMBOL(vunmap);
103417
103418 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103419 +void unmap_process_stacks(struct task_struct *task)
103420 +{
103421 + if (unlikely(in_interrupt())) {
103422 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
103423 + struct stack_deferred_llist *list = task->stack;
103424 + list->stack = task->stack;
103425 + list->lowmem_stack = task->lowmem_stack;
103426 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
103427 + schedule_work(&p->wq);
103428 + } else {
103429 + __vunmap(task->stack, 0);
103430 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
103431 + }
103432 +}
103433 +#endif
103434 +
103435 /**
103436 * vmap - map an array of pages into virtually contiguous space
103437 * @pages: array of page pointers
103438 @@ -1543,6 +1649,11 @@ void *vmap(struct page **pages, unsigned int count,
103439 if (count > totalram_pages)
103440 return NULL;
103441
103442 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
103443 + if (!(pgprot_val(prot) & _PAGE_NX))
103444 + flags |= VM_KERNEXEC;
103445 +#endif
103446 +
103447 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
103448 __builtin_return_address(0));
103449 if (!area)
103450 @@ -1643,6 +1754,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
103451 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
103452 goto fail;
103453
103454 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
103455 + if (!(pgprot_val(prot) & _PAGE_NX))
103456 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
103457 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
103458 + else
103459 +#endif
103460 +
103461 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
103462 start, end, node, gfp_mask, caller);
103463 if (!area)
103464 @@ -1819,10 +1937,9 @@ EXPORT_SYMBOL(vzalloc_node);
103465 * For tight control over page level allocator and protection flags
103466 * use __vmalloc() instead.
103467 */
103468 -
103469 void *vmalloc_exec(unsigned long size)
103470 {
103471 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
103472 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
103473 NUMA_NO_NODE, __builtin_return_address(0));
103474 }
103475
103476 @@ -2129,6 +2246,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
103477 {
103478 struct vm_struct *area;
103479
103480 + BUG_ON(vma->vm_mirror);
103481 +
103482 size = PAGE_ALIGN(size);
103483
103484 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
103485 @@ -2611,7 +2730,11 @@ static int s_show(struct seq_file *m, void *p)
103486 v->addr, v->addr + v->size, v->size);
103487
103488 if (v->caller)
103489 +#ifdef CONFIG_GRKERNSEC_HIDESYM
103490 + seq_printf(m, " %pK", v->caller);
103491 +#else
103492 seq_printf(m, " %pS", v->caller);
103493 +#endif
103494
103495 if (v->nr_pages)
103496 seq_printf(m, " pages=%d", v->nr_pages);
103497 diff --git a/mm/vmstat.c b/mm/vmstat.c
103498 index b37bd49..4d7b3da 100644
103499 --- a/mm/vmstat.c
103500 +++ b/mm/vmstat.c
103501 @@ -20,6 +20,7 @@
103502 #include <linux/writeback.h>
103503 #include <linux/compaction.h>
103504 #include <linux/mm_inline.h>
103505 +#include <linux/grsecurity.h>
103506
103507 #include "internal.h"
103508
103509 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
103510 *
103511 * vm_stat contains the global counters
103512 */
103513 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
103514 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
103515 EXPORT_SYMBOL(vm_stat);
103516
103517 #ifdef CONFIG_SMP
103518 @@ -425,7 +426,7 @@ static inline void fold_diff(int *diff)
103519
103520 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
103521 if (diff[i])
103522 - atomic_long_add(diff[i], &vm_stat[i]);
103523 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
103524 }
103525
103526 /*
103527 @@ -457,7 +458,7 @@ static void refresh_cpu_vm_stats(void)
103528 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
103529 if (v) {
103530
103531 - atomic_long_add(v, &zone->vm_stat[i]);
103532 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
103533 global_diff[i] += v;
103534 #ifdef CONFIG_NUMA
103535 /* 3 seconds idle till flush */
103536 @@ -519,7 +520,7 @@ void cpu_vm_stats_fold(int cpu)
103537
103538 v = p->vm_stat_diff[i];
103539 p->vm_stat_diff[i] = 0;
103540 - atomic_long_add(v, &zone->vm_stat[i]);
103541 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
103542 global_diff[i] += v;
103543 }
103544 }
103545 @@ -539,8 +540,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
103546 if (pset->vm_stat_diff[i]) {
103547 int v = pset->vm_stat_diff[i];
103548 pset->vm_stat_diff[i] = 0;
103549 - atomic_long_add(v, &zone->vm_stat[i]);
103550 - atomic_long_add(v, &vm_stat[i]);
103551 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
103552 + atomic_long_add_unchecked(v, &vm_stat[i]);
103553 }
103554 }
103555 #endif
103556 @@ -1162,10 +1163,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
103557 stat_items_size += sizeof(struct vm_event_state);
103558 #endif
103559
103560 - v = kmalloc(stat_items_size, GFP_KERNEL);
103561 + v = kzalloc(stat_items_size, GFP_KERNEL);
103562 m->private = v;
103563 if (!v)
103564 return ERR_PTR(-ENOMEM);
103565 +
103566 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
103567 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
103568 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
103569 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
103570 + && !in_group_p(grsec_proc_gid)
103571 +#endif
103572 + )
103573 + return (unsigned long *)m->private + *pos;
103574 +#endif
103575 +#endif
103576 +
103577 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
103578 v[i] = global_page_state(i);
103579 v += NR_VM_ZONE_STAT_ITEMS;
103580 @@ -1314,10 +1327,16 @@ static int __init setup_vmstat(void)
103581 cpu_notifier_register_done();
103582 #endif
103583 #ifdef CONFIG_PROC_FS
103584 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
103585 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
103586 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
103587 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
103588 + {
103589 + mode_t gr_mode = S_IRUGO;
103590 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
103591 + gr_mode = S_IRUSR;
103592 +#endif
103593 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
103594 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
103595 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
103596 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
103597 + }
103598 #endif
103599 return 0;
103600 }
103601 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
103602 index 44ebd5c..1f732bae 100644
103603 --- a/net/8021q/vlan.c
103604 +++ b/net/8021q/vlan.c
103605 @@ -475,7 +475,7 @@ out:
103606 return NOTIFY_DONE;
103607 }
103608
103609 -static struct notifier_block vlan_notifier_block __read_mostly = {
103610 +static struct notifier_block vlan_notifier_block = {
103611 .notifier_call = vlan_device_event,
103612 };
103613
103614 @@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
103615 err = -EPERM;
103616 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
103617 break;
103618 - if ((args.u.name_type >= 0) &&
103619 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
103620 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
103621 struct vlan_net *vn;
103622
103623 vn = net_generic(net, vlan_net_id);
103624 diff --git a/net/9p/client.c b/net/9p/client.c
103625 index 0004cba..feba240 100644
103626 --- a/net/9p/client.c
103627 +++ b/net/9p/client.c
103628 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
103629 len - inline_len);
103630 } else {
103631 err = copy_from_user(ename + inline_len,
103632 - uidata, len - inline_len);
103633 + (char __force_user *)uidata, len - inline_len);
103634 if (err) {
103635 err = -EFAULT;
103636 goto out_err;
103637 @@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
103638 kernel_buf = 1;
103639 indata = data;
103640 } else
103641 - indata = (__force char *)udata;
103642 + indata = (__force_kernel char *)udata;
103643 /*
103644 * response header len is 11
103645 * PDU Header(7) + IO Size (4)
103646 @@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
103647 kernel_buf = 1;
103648 odata = data;
103649 } else
103650 - odata = (char *)udata;
103651 + odata = (char __force_kernel *)udata;
103652 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
103653 P9_ZC_HDR_SZ, kernel_buf, "dqd",
103654 fid->fid, offset, rsize);
103655 diff --git a/net/9p/mod.c b/net/9p/mod.c
103656 index 6ab36ae..6f1841b 100644
103657 --- a/net/9p/mod.c
103658 +++ b/net/9p/mod.c
103659 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
103660 void v9fs_register_trans(struct p9_trans_module *m)
103661 {
103662 spin_lock(&v9fs_trans_lock);
103663 - list_add_tail(&m->list, &v9fs_trans_list);
103664 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
103665 spin_unlock(&v9fs_trans_lock);
103666 }
103667 EXPORT_SYMBOL(v9fs_register_trans);
103668 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
103669 void v9fs_unregister_trans(struct p9_trans_module *m)
103670 {
103671 spin_lock(&v9fs_trans_lock);
103672 - list_del_init(&m->list);
103673 + pax_list_del_init((struct list_head *)&m->list);
103674 spin_unlock(&v9fs_trans_lock);
103675 }
103676 EXPORT_SYMBOL(v9fs_unregister_trans);
103677 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
103678 index 80d08f6..de63fd1 100644
103679 --- a/net/9p/trans_fd.c
103680 +++ b/net/9p/trans_fd.c
103681 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
103682 oldfs = get_fs();
103683 set_fs(get_ds());
103684 /* The cast to a user pointer is valid due to the set_fs() */
103685 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
103686 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
103687 set_fs(oldfs);
103688
103689 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
103690 diff --git a/net/Kconfig b/net/Kconfig
103691 index d92afe4..ab63892 100644
103692 --- a/net/Kconfig
103693 +++ b/net/Kconfig
103694 @@ -89,12 +89,8 @@ config NETWORK_SECMARK
103695 to nfmark, but designated for security purposes.
103696 If you are unsure how to answer this question, answer N.
103697
103698 -config NET_PTP_CLASSIFY
103699 - def_bool n
103700 -
103701 config NETWORK_PHY_TIMESTAMPING
103702 bool "Timestamping in PHY devices"
103703 - select NET_PTP_CLASSIFY
103704 help
103705 This allows timestamping of network packets by PHYs with
103706 hardware timestamping capabilities. This option adds some
103707 @@ -269,7 +265,7 @@ config BQL
103708 config BPF_JIT
103709 bool "enable BPF Just In Time compiler"
103710 depends on HAVE_BPF_JIT
103711 - depends on MODULES
103712 + depends on MODULES && X86
103713 ---help---
103714 Berkeley Packet Filter filtering capabilities are normally handled
103715 by an interpreter. This option allows kernel to generate a native
103716 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
103717 index af46bc4..f9adfcd 100644
103718 --- a/net/appletalk/atalk_proc.c
103719 +++ b/net/appletalk/atalk_proc.c
103720 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
103721 struct proc_dir_entry *p;
103722 int rc = -ENOMEM;
103723
103724 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
103725 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
103726 if (!atalk_proc_dir)
103727 goto out;
103728
103729 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
103730 index 876fbe8..8bbea9f 100644
103731 --- a/net/atm/atm_misc.c
103732 +++ b/net/atm/atm_misc.c
103733 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
103734 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
103735 return 1;
103736 atm_return(vcc, truesize);
103737 - atomic_inc(&vcc->stats->rx_drop);
103738 + atomic_inc_unchecked(&vcc->stats->rx_drop);
103739 return 0;
103740 }
103741 EXPORT_SYMBOL(atm_charge);
103742 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
103743 }
103744 }
103745 atm_return(vcc, guess);
103746 - atomic_inc(&vcc->stats->rx_drop);
103747 + atomic_inc_unchecked(&vcc->stats->rx_drop);
103748 return NULL;
103749 }
103750 EXPORT_SYMBOL(atm_alloc_charge);
103751 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
103752
103753 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
103754 {
103755 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
103756 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
103757 __SONET_ITEMS
103758 #undef __HANDLE_ITEM
103759 }
103760 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
103761
103762 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
103763 {
103764 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
103765 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
103766 __SONET_ITEMS
103767 #undef __HANDLE_ITEM
103768 }
103769 diff --git a/net/atm/lec.c b/net/atm/lec.c
103770 index 4c5b8ba..95f7005 100644
103771 --- a/net/atm/lec.c
103772 +++ b/net/atm/lec.c
103773 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
103774 }
103775
103776 static struct lane2_ops lane2_ops = {
103777 - lane2_resolve, /* resolve, spec 3.1.3 */
103778 - lane2_associate_req, /* associate_req, spec 3.1.4 */
103779 - NULL /* associate indicator, spec 3.1.5 */
103780 + .resolve = lane2_resolve,
103781 + .associate_req = lane2_associate_req,
103782 + .associate_indicator = NULL
103783 };
103784
103785 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
103786 diff --git a/net/atm/lec.h b/net/atm/lec.h
103787 index 4149db1..f2ab682 100644
103788 --- a/net/atm/lec.h
103789 +++ b/net/atm/lec.h
103790 @@ -48,7 +48,7 @@ struct lane2_ops {
103791 const u8 *tlvs, u32 sizeoftlvs);
103792 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
103793 const u8 *tlvs, u32 sizeoftlvs);
103794 -};
103795 +} __no_const;
103796
103797 /*
103798 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
103799 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
103800 index d1b2d9a..d549f7f 100644
103801 --- a/net/atm/mpoa_caches.c
103802 +++ b/net/atm/mpoa_caches.c
103803 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
103804
103805
103806 static struct in_cache_ops ingress_ops = {
103807 - in_cache_add_entry, /* add_entry */
103808 - in_cache_get, /* get */
103809 - in_cache_get_with_mask, /* get_with_mask */
103810 - in_cache_get_by_vcc, /* get_by_vcc */
103811 - in_cache_put, /* put */
103812 - in_cache_remove_entry, /* remove_entry */
103813 - cache_hit, /* cache_hit */
103814 - clear_count_and_expired, /* clear_count */
103815 - check_resolving_entries, /* check_resolving */
103816 - refresh_entries, /* refresh */
103817 - in_destroy_cache /* destroy_cache */
103818 + .add_entry = in_cache_add_entry,
103819 + .get = in_cache_get,
103820 + .get_with_mask = in_cache_get_with_mask,
103821 + .get_by_vcc = in_cache_get_by_vcc,
103822 + .put = in_cache_put,
103823 + .remove_entry = in_cache_remove_entry,
103824 + .cache_hit = cache_hit,
103825 + .clear_count = clear_count_and_expired,
103826 + .check_resolving = check_resolving_entries,
103827 + .refresh = refresh_entries,
103828 + .destroy_cache = in_destroy_cache
103829 };
103830
103831 static struct eg_cache_ops egress_ops = {
103832 - eg_cache_add_entry, /* add_entry */
103833 - eg_cache_get_by_cache_id, /* get_by_cache_id */
103834 - eg_cache_get_by_tag, /* get_by_tag */
103835 - eg_cache_get_by_vcc, /* get_by_vcc */
103836 - eg_cache_get_by_src_ip, /* get_by_src_ip */
103837 - eg_cache_put, /* put */
103838 - eg_cache_remove_entry, /* remove_entry */
103839 - update_eg_cache_entry, /* update */
103840 - clear_expired, /* clear_expired */
103841 - eg_destroy_cache /* destroy_cache */
103842 + .add_entry = eg_cache_add_entry,
103843 + .get_by_cache_id = eg_cache_get_by_cache_id,
103844 + .get_by_tag = eg_cache_get_by_tag,
103845 + .get_by_vcc = eg_cache_get_by_vcc,
103846 + .get_by_src_ip = eg_cache_get_by_src_ip,
103847 + .put = eg_cache_put,
103848 + .remove_entry = eg_cache_remove_entry,
103849 + .update = update_eg_cache_entry,
103850 + .clear_expired = clear_expired,
103851 + .destroy_cache = eg_destroy_cache
103852 };
103853
103854
103855 diff --git a/net/atm/proc.c b/net/atm/proc.c
103856 index bbb6461..cf04016 100644
103857 --- a/net/atm/proc.c
103858 +++ b/net/atm/proc.c
103859 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
103860 const struct k_atm_aal_stats *stats)
103861 {
103862 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
103863 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
103864 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
103865 - atomic_read(&stats->rx_drop));
103866 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
103867 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
103868 + atomic_read_unchecked(&stats->rx_drop));
103869 }
103870
103871 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
103872 diff --git a/net/atm/resources.c b/net/atm/resources.c
103873 index 0447d5d..3cf4728 100644
103874 --- a/net/atm/resources.c
103875 +++ b/net/atm/resources.c
103876 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
103877 static void copy_aal_stats(struct k_atm_aal_stats *from,
103878 struct atm_aal_stats *to)
103879 {
103880 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
103881 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
103882 __AAL_STAT_ITEMS
103883 #undef __HANDLE_ITEM
103884 }
103885 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
103886 static void subtract_aal_stats(struct k_atm_aal_stats *from,
103887 struct atm_aal_stats *to)
103888 {
103889 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
103890 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
103891 __AAL_STAT_ITEMS
103892 #undef __HANDLE_ITEM
103893 }
103894 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
103895 index 919a5ce..cc6b444 100644
103896 --- a/net/ax25/sysctl_net_ax25.c
103897 +++ b/net/ax25/sysctl_net_ax25.c
103898 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
103899 {
103900 char path[sizeof("net/ax25/") + IFNAMSIZ];
103901 int k;
103902 - struct ctl_table *table;
103903 + ctl_table_no_const *table;
103904
103905 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
103906 if (!table)
103907 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
103908 index f04224c..f326579 100644
103909 --- a/net/batman-adv/bat_iv_ogm.c
103910 +++ b/net/batman-adv/bat_iv_ogm.c
103911 @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
103912
103913 /* randomize initial seqno to avoid collision */
103914 get_random_bytes(&random_seqno, sizeof(random_seqno));
103915 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
103916 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
103917
103918 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
103919 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
103920 @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
103921 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
103922
103923 /* change sequence number to network order */
103924 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
103925 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
103926 batadv_ogm_packet->seqno = htonl(seqno);
103927 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
103928 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
103929
103930 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
103931
103932 @@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
103933 return;
103934
103935 /* could be changed by schedule_own_packet() */
103936 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
103937 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
103938
103939 if (ogm_packet->flags & BATADV_DIRECTLINK)
103940 has_directlink_flag = true;
103941 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
103942 index 022d18a..919daff 100644
103943 --- a/net/batman-adv/fragmentation.c
103944 +++ b/net/batman-adv/fragmentation.c
103945 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
103946 frag_header.packet_type = BATADV_UNICAST_FRAG;
103947 frag_header.version = BATADV_COMPAT_VERSION;
103948 frag_header.ttl = BATADV_TTL;
103949 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
103950 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
103951 frag_header.reserved = 0;
103952 frag_header.no = 0;
103953 frag_header.total_size = htons(skb->len);
103954 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
103955 index cbd677f..b783347 100644
103956 --- a/net/batman-adv/soft-interface.c
103957 +++ b/net/batman-adv/soft-interface.c
103958 @@ -296,7 +296,7 @@ send:
103959 primary_if->net_dev->dev_addr);
103960
103961 /* set broadcast sequence number */
103962 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
103963 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
103964 bcast_packet->seqno = htonl(seqno);
103965
103966 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
103967 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
103968 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
103969
103970 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
103971 - atomic_set(&bat_priv->bcast_seqno, 1);
103972 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
103973 atomic_set(&bat_priv->tt.vn, 0);
103974 atomic_set(&bat_priv->tt.local_changes, 0);
103975 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
103976 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
103977
103978 /* randomize initial seqno to avoid collision */
103979 get_random_bytes(&random_seqno, sizeof(random_seqno));
103980 - atomic_set(&bat_priv->frag_seqno, random_seqno);
103981 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
103982
103983 bat_priv->primary_if = NULL;
103984 bat_priv->num_ifaces = 0;
103985 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
103986 index 8854c05..ee5d5497 100644
103987 --- a/net/batman-adv/types.h
103988 +++ b/net/batman-adv/types.h
103989 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
103990 struct batadv_hard_iface_bat_iv {
103991 unsigned char *ogm_buff;
103992 int ogm_buff_len;
103993 - atomic_t ogm_seqno;
103994 + atomic_unchecked_t ogm_seqno;
103995 };
103996
103997 /**
103998 @@ -768,7 +768,7 @@ struct batadv_priv {
103999 atomic_t bonding;
104000 atomic_t fragmentation;
104001 atomic_t packet_size_max;
104002 - atomic_t frag_seqno;
104003 + atomic_unchecked_t frag_seqno;
104004 #ifdef CONFIG_BATMAN_ADV_BLA
104005 atomic_t bridge_loop_avoidance;
104006 #endif
104007 @@ -787,7 +787,7 @@ struct batadv_priv {
104008 #endif
104009 uint32_t isolation_mark;
104010 uint32_t isolation_mark_mask;
104011 - atomic_t bcast_seqno;
104012 + atomic_unchecked_t bcast_seqno;
104013 atomic_t bcast_queue_left;
104014 atomic_t batman_queue_left;
104015 char num_ifaces;
104016 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
104017 index 80d25c1..aa99a98 100644
104018 --- a/net/bluetooth/hci_sock.c
104019 +++ b/net/bluetooth/hci_sock.c
104020 @@ -1044,7 +1044,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
104021 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
104022 }
104023
104024 - len = min_t(unsigned int, len, sizeof(uf));
104025 + len = min((size_t)len, sizeof(uf));
104026 if (copy_from_user(&uf, optval, len)) {
104027 err = -EFAULT;
104028 break;
104029 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
104030 index 323f23c..5e27529 100644
104031 --- a/net/bluetooth/l2cap_core.c
104032 +++ b/net/bluetooth/l2cap_core.c
104033 @@ -3548,8 +3548,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
104034 break;
104035
104036 case L2CAP_CONF_RFC:
104037 - if (olen == sizeof(rfc))
104038 - memcpy(&rfc, (void *)val, olen);
104039 + if (olen != sizeof(rfc))
104040 + break;
104041 +
104042 + memcpy(&rfc, (void *)val, olen);
104043
104044 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
104045 rfc.mode != chan->mode)
104046 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
104047 index e137869..33f3ebd 100644
104048 --- a/net/bluetooth/l2cap_sock.c
104049 +++ b/net/bluetooth/l2cap_sock.c
104050 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
104051 struct sock *sk = sock->sk;
104052 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
104053 struct l2cap_options opts;
104054 - int len, err = 0;
104055 + int err = 0;
104056 + size_t len = optlen;
104057 u32 opt;
104058
104059 BT_DBG("sk %p", sk);
104060 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
104061 opts.max_tx = chan->max_tx;
104062 opts.txwin_size = chan->tx_win;
104063
104064 - len = min_t(unsigned int, sizeof(opts), optlen);
104065 + len = min(sizeof(opts), len);
104066 if (copy_from_user((char *) &opts, optval, len)) {
104067 err = -EFAULT;
104068 break;
104069 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
104070 struct bt_security sec;
104071 struct bt_power pwr;
104072 struct l2cap_conn *conn;
104073 - int len, err = 0;
104074 + int err = 0;
104075 + size_t len = optlen;
104076 u32 opt;
104077
104078 BT_DBG("sk %p", sk);
104079 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
104080
104081 sec.level = BT_SECURITY_LOW;
104082
104083 - len = min_t(unsigned int, sizeof(sec), optlen);
104084 + len = min(sizeof(sec), len);
104085 if (copy_from_user((char *) &sec, optval, len)) {
104086 err = -EFAULT;
104087 break;
104088 @@ -861,7 +863,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
104089
104090 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
104091
104092 - len = min_t(unsigned int, sizeof(pwr), optlen);
104093 + len = min(sizeof(pwr), len);
104094 if (copy_from_user((char *) &pwr, optval, len)) {
104095 err = -EFAULT;
104096 break;
104097 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
104098 index c603a5e..7f08991 100644
104099 --- a/net/bluetooth/rfcomm/sock.c
104100 +++ b/net/bluetooth/rfcomm/sock.c
104101 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
104102 struct sock *sk = sock->sk;
104103 struct bt_security sec;
104104 int err = 0;
104105 - size_t len;
104106 + size_t len = optlen;
104107 u32 opt;
104108
104109 BT_DBG("sk %p", sk);
104110 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
104111
104112 sec.level = BT_SECURITY_LOW;
104113
104114 - len = min_t(unsigned int, sizeof(sec), optlen);
104115 + len = min(sizeof(sec), len);
104116 if (copy_from_user((char *) &sec, optval, len)) {
104117 err = -EFAULT;
104118 break;
104119 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
104120 index 8e385a0..a5bdd8e 100644
104121 --- a/net/bluetooth/rfcomm/tty.c
104122 +++ b/net/bluetooth/rfcomm/tty.c
104123 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
104124 BT_DBG("tty %p id %d", tty, tty->index);
104125
104126 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
104127 - dev->channel, dev->port.count);
104128 + dev->channel, atomic_read(&dev->port.count));
104129
104130 err = tty_port_open(&dev->port, tty, filp);
104131 if (err)
104132 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
104133 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
104134
104135 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
104136 - dev->port.count);
104137 + atomic_read(&dev->port.count));
104138
104139 tty_port_close(&dev->port, tty, filp);
104140 }
104141 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
104142 index 1059ed3..d70846a 100644
104143 --- a/net/bridge/netfilter/ebtables.c
104144 +++ b/net/bridge/netfilter/ebtables.c
104145 @@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104146 tmp.valid_hooks = t->table->valid_hooks;
104147 }
104148 mutex_unlock(&ebt_mutex);
104149 - if (copy_to_user(user, &tmp, *len) != 0) {
104150 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
104151 BUGPRINT("c2u Didn't work\n");
104152 ret = -EFAULT;
104153 break;
104154 @@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
104155 goto out;
104156 tmp.valid_hooks = t->valid_hooks;
104157
104158 - if (copy_to_user(user, &tmp, *len) != 0) {
104159 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
104160 ret = -EFAULT;
104161 break;
104162 }
104163 @@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
104164 tmp.entries_size = t->table->entries_size;
104165 tmp.valid_hooks = t->table->valid_hooks;
104166
104167 - if (copy_to_user(user, &tmp, *len) != 0) {
104168 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
104169 ret = -EFAULT;
104170 break;
104171 }
104172 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
104173 index 0f45522..dab651f 100644
104174 --- a/net/caif/cfctrl.c
104175 +++ b/net/caif/cfctrl.c
104176 @@ -10,6 +10,7 @@
104177 #include <linux/spinlock.h>
104178 #include <linux/slab.h>
104179 #include <linux/pkt_sched.h>
104180 +#include <linux/sched.h>
104181 #include <net/caif/caif_layer.h>
104182 #include <net/caif/cfpkt.h>
104183 #include <net/caif/cfctrl.h>
104184 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
104185 memset(&dev_info, 0, sizeof(dev_info));
104186 dev_info.id = 0xff;
104187 cfsrvl_init(&this->serv, 0, &dev_info, false);
104188 - atomic_set(&this->req_seq_no, 1);
104189 - atomic_set(&this->rsp_seq_no, 1);
104190 + atomic_set_unchecked(&this->req_seq_no, 1);
104191 + atomic_set_unchecked(&this->rsp_seq_no, 1);
104192 this->serv.layer.receive = cfctrl_recv;
104193 sprintf(this->serv.layer.name, "ctrl");
104194 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
104195 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
104196 struct cfctrl_request_info *req)
104197 {
104198 spin_lock_bh(&ctrl->info_list_lock);
104199 - atomic_inc(&ctrl->req_seq_no);
104200 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
104201 + atomic_inc_unchecked(&ctrl->req_seq_no);
104202 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
104203 list_add_tail(&req->list, &ctrl->list);
104204 spin_unlock_bh(&ctrl->info_list_lock);
104205 }
104206 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
104207 if (p != first)
104208 pr_warn("Requests are not received in order\n");
104209
104210 - atomic_set(&ctrl->rsp_seq_no,
104211 + atomic_set_unchecked(&ctrl->rsp_seq_no,
104212 p->sequence_no);
104213 list_del(&p->list);
104214 goto out;
104215 diff --git a/net/can/af_can.c b/net/can/af_can.c
104216 index ce82337..5d17b4d 100644
104217 --- a/net/can/af_can.c
104218 +++ b/net/can/af_can.c
104219 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
104220 };
104221
104222 /* notifier block for netdevice event */
104223 -static struct notifier_block can_netdev_notifier __read_mostly = {
104224 +static struct notifier_block can_netdev_notifier = {
104225 .notifier_call = can_notifier,
104226 };
104227
104228 diff --git a/net/can/bcm.c b/net/can/bcm.c
104229 index dcb75c0..24b1b43 100644
104230 --- a/net/can/bcm.c
104231 +++ b/net/can/bcm.c
104232 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
104233 }
104234
104235 /* create /proc/net/can-bcm directory */
104236 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
104237 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
104238 return 0;
104239 }
104240
104241 diff --git a/net/can/gw.c b/net/can/gw.c
104242 index 050a211..bb9fe33 100644
104243 --- a/net/can/gw.c
104244 +++ b/net/can/gw.c
104245 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
104246 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
104247
104248 static HLIST_HEAD(cgw_list);
104249 -static struct notifier_block notifier;
104250
104251 static struct kmem_cache *cgw_cache __read_mostly;
104252
104253 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
104254 return err;
104255 }
104256
104257 +static struct notifier_block notifier = {
104258 + .notifier_call = cgw_notifier
104259 +};
104260 +
104261 static __init int cgw_module_init(void)
104262 {
104263 /* sanitize given module parameter */
104264 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
104265 return -ENOMEM;
104266
104267 /* set notifier */
104268 - notifier.notifier_call = cgw_notifier;
104269 register_netdevice_notifier(&notifier);
104270
104271 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
104272 diff --git a/net/can/proc.c b/net/can/proc.c
104273 index 1a19b98..df2b4ec 100644
104274 --- a/net/can/proc.c
104275 +++ b/net/can/proc.c
104276 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
104277 void can_init_proc(void)
104278 {
104279 /* create /proc/net/can directory */
104280 - can_dir = proc_mkdir("can", init_net.proc_net);
104281 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
104282
104283 if (!can_dir) {
104284 printk(KERN_INFO "can: failed to create /proc/net/can . "
104285 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
104286 index 1948d59..9e854d5 100644
104287 --- a/net/ceph/messenger.c
104288 +++ b/net/ceph/messenger.c
104289 @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
104290 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
104291
104292 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
104293 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
104294 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
104295
104296 static struct page *zero_page; /* used in certain error cases */
104297
104298 @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
104299 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
104300 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
104301
104302 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
104303 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
104304 s = addr_str[i];
104305
104306 switch (ss->ss_family) {
104307 diff --git a/net/compat.c b/net/compat.c
104308 index bc8aeef..f9c070c 100644
104309 --- a/net/compat.c
104310 +++ b/net/compat.c
104311 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
104312 return -EFAULT;
104313 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
104314 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
104315 - kmsg->msg_name = compat_ptr(tmp1);
104316 - kmsg->msg_iov = compat_ptr(tmp2);
104317 - kmsg->msg_control = compat_ptr(tmp3);
104318 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
104319 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
104320 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
104321 return 0;
104322 }
104323
104324 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
104325
104326 if (kern_msg->msg_name && kern_msg->msg_namelen) {
104327 if (mode == VERIFY_READ) {
104328 - int err = move_addr_to_kernel(kern_msg->msg_name,
104329 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
104330 kern_msg->msg_namelen,
104331 kern_address);
104332 if (err < 0)
104333 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
104334 }
104335
104336 tot_len = iov_from_user_compat_to_kern(kern_iov,
104337 - (struct compat_iovec __user *)kern_msg->msg_iov,
104338 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
104339 kern_msg->msg_iovlen);
104340 if (tot_len >= 0)
104341 kern_msg->msg_iov = kern_iov;
104342 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
104343
104344 #define CMSG_COMPAT_FIRSTHDR(msg) \
104345 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
104346 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
104347 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
104348 (struct compat_cmsghdr __user *)NULL)
104349
104350 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
104351 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
104352 (ucmlen) <= (unsigned long) \
104353 ((mhdr)->msg_controllen - \
104354 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
104355 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
104356
104357 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
104358 struct compat_cmsghdr __user *cmsg, int cmsg_len)
104359 {
104360 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
104361 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
104362 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
104363 msg->msg_controllen)
104364 return NULL;
104365 return (struct compat_cmsghdr __user *)ptr;
104366 @@ -223,7 +223,7 @@ Efault:
104367
104368 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
104369 {
104370 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
104371 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
104372 struct compat_cmsghdr cmhdr;
104373 struct compat_timeval ctv;
104374 struct compat_timespec cts[3];
104375 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
104376
104377 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
104378 {
104379 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
104380 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
104381 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
104382 int fdnum = scm->fp->count;
104383 struct file **fp = scm->fp->fp;
104384 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
104385 return -EFAULT;
104386 old_fs = get_fs();
104387 set_fs(KERNEL_DS);
104388 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
104389 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
104390 set_fs(old_fs);
104391
104392 return err;
104393 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
104394 len = sizeof(ktime);
104395 old_fs = get_fs();
104396 set_fs(KERNEL_DS);
104397 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
104398 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
104399 set_fs(old_fs);
104400
104401 if (!err) {
104402 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
104403 case MCAST_JOIN_GROUP:
104404 case MCAST_LEAVE_GROUP:
104405 {
104406 - struct compat_group_req __user *gr32 = (void *)optval;
104407 + struct compat_group_req __user *gr32 = (void __user *)optval;
104408 struct group_req __user *kgr =
104409 compat_alloc_user_space(sizeof(struct group_req));
104410 u32 interface;
104411 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
104412 case MCAST_BLOCK_SOURCE:
104413 case MCAST_UNBLOCK_SOURCE:
104414 {
104415 - struct compat_group_source_req __user *gsr32 = (void *)optval;
104416 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
104417 struct group_source_req __user *kgsr = compat_alloc_user_space(
104418 sizeof(struct group_source_req));
104419 u32 interface;
104420 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
104421 }
104422 case MCAST_MSFILTER:
104423 {
104424 - struct compat_group_filter __user *gf32 = (void *)optval;
104425 + struct compat_group_filter __user *gf32 = (void __user *)optval;
104426 struct group_filter __user *kgf;
104427 u32 interface, fmode, numsrc;
104428
104429 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
104430 char __user *optval, int __user *optlen,
104431 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
104432 {
104433 - struct compat_group_filter __user *gf32 = (void *)optval;
104434 + struct compat_group_filter __user *gf32 = (void __user *)optval;
104435 struct group_filter __user *kgf;
104436 int __user *koptlen;
104437 u32 interface, fmode, numsrc;
104438 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
104439
104440 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
104441 return -EINVAL;
104442 - if (copy_from_user(a, args, nas[call]))
104443 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
104444 return -EFAULT;
104445 a0 = a[0];
104446 a1 = a[1];
104447 diff --git a/net/core/Makefile b/net/core/Makefile
104448 index 71093d9..a8a035b 100644
104449 --- a/net/core/Makefile
104450 +++ b/net/core/Makefile
104451 @@ -21,6 +21,5 @@ obj-$(CONFIG_FIB_RULES) += fib_rules.o
104452 obj-$(CONFIG_TRACEPOINTS) += net-traces.o
104453 obj-$(CONFIG_NET_DROP_MONITOR) += drop_monitor.o
104454 obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += timestamping.o
104455 -obj-$(CONFIG_NET_PTP_CLASSIFY) += ptp_classifier.o
104456 obj-$(CONFIG_CGROUP_NET_PRIO) += netprio_cgroup.o
104457 obj-$(CONFIG_CGROUP_NET_CLASSID) += netclassid_cgroup.o
104458 diff --git a/net/core/datagram.c b/net/core/datagram.c
104459 index 488dd1a..7179f0f 100644
104460 --- a/net/core/datagram.c
104461 +++ b/net/core/datagram.c
104462 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
104463 }
104464
104465 kfree_skb(skb);
104466 - atomic_inc(&sk->sk_drops);
104467 + atomic_inc_unchecked(&sk->sk_drops);
104468 sk_mem_reclaim_partial(sk);
104469
104470 return err;
104471 diff --git a/net/core/dev.c b/net/core/dev.c
104472 index 367a586..ef2fe17 100644
104473 --- a/net/core/dev.c
104474 +++ b/net/core/dev.c
104475 @@ -1672,14 +1672,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
104476 {
104477 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
104478 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
104479 - atomic_long_inc(&dev->rx_dropped);
104480 + atomic_long_inc_unchecked(&dev->rx_dropped);
104481 kfree_skb(skb);
104482 return NET_RX_DROP;
104483 }
104484 }
104485
104486 if (unlikely(!is_skb_forwardable(dev, skb))) {
104487 - atomic_long_inc(&dev->rx_dropped);
104488 + atomic_long_inc_unchecked(&dev->rx_dropped);
104489 kfree_skb(skb);
104490 return NET_RX_DROP;
104491 }
104492 @@ -2476,7 +2476,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
104493
104494 struct dev_gso_cb {
104495 void (*destructor)(struct sk_buff *skb);
104496 -};
104497 +} __no_const;
104498
104499 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
104500
104501 @@ -2932,7 +2932,7 @@ recursion_alert:
104502 rc = -ENETDOWN;
104503 rcu_read_unlock_bh();
104504
104505 - atomic_long_inc(&dev->tx_dropped);
104506 + atomic_long_inc_unchecked(&dev->tx_dropped);
104507 kfree_skb(skb);
104508 return rc;
104509 out:
104510 @@ -3276,7 +3276,7 @@ enqueue:
104511
104512 local_irq_restore(flags);
104513
104514 - atomic_long_inc(&skb->dev->rx_dropped);
104515 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
104516 kfree_skb(skb);
104517 return NET_RX_DROP;
104518 }
104519 @@ -3353,7 +3353,7 @@ int netif_rx_ni(struct sk_buff *skb)
104520 }
104521 EXPORT_SYMBOL(netif_rx_ni);
104522
104523 -static void net_tx_action(struct softirq_action *h)
104524 +static __latent_entropy void net_tx_action(void)
104525 {
104526 struct softnet_data *sd = &__get_cpu_var(softnet_data);
104527
104528 @@ -3686,7 +3686,7 @@ ncls:
104529 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
104530 } else {
104531 drop:
104532 - atomic_long_inc(&skb->dev->rx_dropped);
104533 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
104534 kfree_skb(skb);
104535 /* Jamal, now you will not able to escape explaining
104536 * me how you were going to use this. :-)
104537 @@ -4406,7 +4406,7 @@ void netif_napi_del(struct napi_struct *napi)
104538 }
104539 EXPORT_SYMBOL(netif_napi_del);
104540
104541 -static void net_rx_action(struct softirq_action *h)
104542 +static __latent_entropy void net_rx_action(void)
104543 {
104544 struct softnet_data *sd = &__get_cpu_var(softnet_data);
104545 unsigned long time_limit = jiffies + 2;
104546 @@ -6403,8 +6403,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
104547 } else {
104548 netdev_stats_to_stats64(storage, &dev->stats);
104549 }
104550 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
104551 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
104552 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
104553 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
104554 return storage;
104555 }
104556 EXPORT_SYMBOL(dev_get_stats);
104557 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
104558 index cf999e0..c59a975 100644
104559 --- a/net/core/dev_ioctl.c
104560 +++ b/net/core/dev_ioctl.c
104561 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
104562 if (no_module && capable(CAP_NET_ADMIN))
104563 no_module = request_module("netdev-%s", name);
104564 if (no_module && capable(CAP_SYS_MODULE)) {
104565 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
104566 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
104567 +#else
104568 if (!request_module("%s", name))
104569 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
104570 name);
104571 +#endif
104572 }
104573 }
104574 EXPORT_SYMBOL(dev_load);
104575 diff --git a/net/core/filter.c b/net/core/filter.c
104576 index 1dbf646..0f95703 100644
104577 --- a/net/core/filter.c
104578 +++ b/net/core/filter.c
104579 @@ -1,16 +1,11 @@
104580 /*
104581 * Linux Socket Filter - Kernel level socket filtering
104582 *
104583 - * Based on the design of the Berkeley Packet Filter. The new
104584 - * internal format has been designed by PLUMgrid:
104585 + * Author:
104586 + * Jay Schulist <jschlst@samba.org>
104587 *
104588 - * Copyright (c) 2011 - 2014 PLUMgrid, http://plumgrid.com
104589 - *
104590 - * Authors:
104591 - *
104592 - * Jay Schulist <jschlst@samba.org>
104593 - * Alexei Starovoitov <ast@plumgrid.com>
104594 - * Daniel Borkmann <dborkman@redhat.com>
104595 + * Based on the design of:
104596 + * - The Berkeley Packet Filter
104597 *
104598 * This program is free software; you can redistribute it and/or
104599 * modify it under the terms of the GNU General Public License
104600 @@ -45,27 +40,6 @@
104601 #include <linux/seccomp.h>
104602 #include <linux/if_vlan.h>
104603
104604 -/* Registers */
104605 -#define BPF_R0 regs[BPF_REG_0]
104606 -#define BPF_R1 regs[BPF_REG_1]
104607 -#define BPF_R2 regs[BPF_REG_2]
104608 -#define BPF_R3 regs[BPF_REG_3]
104609 -#define BPF_R4 regs[BPF_REG_4]
104610 -#define BPF_R5 regs[BPF_REG_5]
104611 -#define BPF_R6 regs[BPF_REG_6]
104612 -#define BPF_R7 regs[BPF_REG_7]
104613 -#define BPF_R8 regs[BPF_REG_8]
104614 -#define BPF_R9 regs[BPF_REG_9]
104615 -#define BPF_R10 regs[BPF_REG_10]
104616 -
104617 -/* Named registers */
104618 -#define DST regs[insn->dst_reg]
104619 -#define SRC regs[insn->src_reg]
104620 -#define FP regs[BPF_REG_FP]
104621 -#define ARG1 regs[BPF_REG_ARG1]
104622 -#define CTX regs[BPF_REG_CTX]
104623 -#define IMM insn->imm
104624 -
104625 /* No hurry in this branch
104626 *
104627 * Exported for the bpf jit load helper.
104628 @@ -78,9 +52,9 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
104629 ptr = skb_network_header(skb) + k - SKF_NET_OFF;
104630 else if (k >= SKF_LL_OFF)
104631 ptr = skb_mac_header(skb) + k - SKF_LL_OFF;
104632 +
104633 if (ptr >= skb->head && ptr + size <= skb_tail_pointer(skb))
104634 return ptr;
104635 -
104636 return NULL;
104637 }
104638
104639 @@ -89,7 +63,6 @@ static inline void *load_pointer(const struct sk_buff *skb, int k,
104640 {
104641 if (k >= 0)
104642 return skb_header_pointer(skb, k, size, buffer);
104643 -
104644 return bpf_internal_load_pointer_neg_helper(skb, k, size);
104645 }
104646
104647 @@ -135,960 +108,309 @@ int sk_filter(struct sock *sk, struct sk_buff *skb)
104648 }
104649 EXPORT_SYMBOL(sk_filter);
104650
104651 -/* Base function for offset calculation. Needs to go into .text section,
104652 - * therefore keeping it non-static as well; will also be used by JITs
104653 - * anyway later on, so do not let the compiler omit it.
104654 - */
104655 -noinline u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
104656 -{
104657 - return 0;
104658 -}
104659 -
104660 /**
104661 - * __sk_run_filter - run a filter on a given context
104662 - * @ctx: buffer to run the filter on
104663 - * @insn: filter to apply
104664 + * sk_run_filter - run a filter on a socket
104665 + * @skb: buffer to run the filter on
104666 + * @fentry: filter to apply
104667 *
104668 - * Decode and apply filter instructions to the skb->data. Return length to
104669 - * keep, 0 for none. @ctx is the data we are operating on, @insn is the
104670 - * array of filter instructions.
104671 + * Decode and apply filter instructions to the skb->data.
104672 + * Return length to keep, 0 for none. @skb is the data we are
104673 + * filtering, @filter is the array of filter instructions.
104674 + * Because all jumps are guaranteed to be before last instruction,
104675 + * and last instruction guaranteed to be a RET, we dont need to check
104676 + * flen. (We used to pass to this function the length of filter)
104677 */
104678 -static unsigned int __sk_run_filter(void *ctx, const struct sock_filter_int *insn)
104679 +unsigned int sk_run_filter(const struct sk_buff *skb,
104680 + const struct sock_filter *fentry)
104681 {
104682 - u64 stack[MAX_BPF_STACK / sizeof(u64)];
104683 - u64 regs[MAX_BPF_REG], tmp;
104684 - static const void *jumptable[256] = {
104685 - [0 ... 255] = &&default_label,
104686 - /* Now overwrite non-defaults ... */
104687 - /* 32 bit ALU operations */
104688 - [BPF_ALU | BPF_ADD | BPF_X] = &&ALU_ADD_X,
104689 - [BPF_ALU | BPF_ADD | BPF_K] = &&ALU_ADD_K,
104690 - [BPF_ALU | BPF_SUB | BPF_X] = &&ALU_SUB_X,
104691 - [BPF_ALU | BPF_SUB | BPF_K] = &&ALU_SUB_K,
104692 - [BPF_ALU | BPF_AND | BPF_X] = &&ALU_AND_X,
104693 - [BPF_ALU | BPF_AND | BPF_K] = &&ALU_AND_K,
104694 - [BPF_ALU | BPF_OR | BPF_X] = &&ALU_OR_X,
104695 - [BPF_ALU | BPF_OR | BPF_K] = &&ALU_OR_K,
104696 - [BPF_ALU | BPF_LSH | BPF_X] = &&ALU_LSH_X,
104697 - [BPF_ALU | BPF_LSH | BPF_K] = &&ALU_LSH_K,
104698 - [BPF_ALU | BPF_RSH | BPF_X] = &&ALU_RSH_X,
104699 - [BPF_ALU | BPF_RSH | BPF_K] = &&ALU_RSH_K,
104700 - [BPF_ALU | BPF_XOR | BPF_X] = &&ALU_XOR_X,
104701 - [BPF_ALU | BPF_XOR | BPF_K] = &&ALU_XOR_K,
104702 - [BPF_ALU | BPF_MUL | BPF_X] = &&ALU_MUL_X,
104703 - [BPF_ALU | BPF_MUL | BPF_K] = &&ALU_MUL_K,
104704 - [BPF_ALU | BPF_MOV | BPF_X] = &&ALU_MOV_X,
104705 - [BPF_ALU | BPF_MOV | BPF_K] = &&ALU_MOV_K,
104706 - [BPF_ALU | BPF_DIV | BPF_X] = &&ALU_DIV_X,
104707 - [BPF_ALU | BPF_DIV | BPF_K] = &&ALU_DIV_K,
104708 - [BPF_ALU | BPF_MOD | BPF_X] = &&ALU_MOD_X,
104709 - [BPF_ALU | BPF_MOD | BPF_K] = &&ALU_MOD_K,
104710 - [BPF_ALU | BPF_NEG] = &&ALU_NEG,
104711 - [BPF_ALU | BPF_END | BPF_TO_BE] = &&ALU_END_TO_BE,
104712 - [BPF_ALU | BPF_END | BPF_TO_LE] = &&ALU_END_TO_LE,
104713 - /* 64 bit ALU operations */
104714 - [BPF_ALU64 | BPF_ADD | BPF_X] = &&ALU64_ADD_X,
104715 - [BPF_ALU64 | BPF_ADD | BPF_K] = &&ALU64_ADD_K,
104716 - [BPF_ALU64 | BPF_SUB | BPF_X] = &&ALU64_SUB_X,
104717 - [BPF_ALU64 | BPF_SUB | BPF_K] = &&ALU64_SUB_K,
104718 - [BPF_ALU64 | BPF_AND | BPF_X] = &&ALU64_AND_X,
104719 - [BPF_ALU64 | BPF_AND | BPF_K] = &&ALU64_AND_K,
104720 - [BPF_ALU64 | BPF_OR | BPF_X] = &&ALU64_OR_X,
104721 - [BPF_ALU64 | BPF_OR | BPF_K] = &&ALU64_OR_K,
104722 - [BPF_ALU64 | BPF_LSH | BPF_X] = &&ALU64_LSH_X,
104723 - [BPF_ALU64 | BPF_LSH | BPF_K] = &&ALU64_LSH_K,
104724 - [BPF_ALU64 | BPF_RSH | BPF_X] = &&ALU64_RSH_X,
104725 - [BPF_ALU64 | BPF_RSH | BPF_K] = &&ALU64_RSH_K,
104726 - [BPF_ALU64 | BPF_XOR | BPF_X] = &&ALU64_XOR_X,
104727 - [BPF_ALU64 | BPF_XOR | BPF_K] = &&ALU64_XOR_K,
104728 - [BPF_ALU64 | BPF_MUL | BPF_X] = &&ALU64_MUL_X,
104729 - [BPF_ALU64 | BPF_MUL | BPF_K] = &&ALU64_MUL_K,
104730 - [BPF_ALU64 | BPF_MOV | BPF_X] = &&ALU64_MOV_X,
104731 - [BPF_ALU64 | BPF_MOV | BPF_K] = &&ALU64_MOV_K,
104732 - [BPF_ALU64 | BPF_ARSH | BPF_X] = &&ALU64_ARSH_X,
104733 - [BPF_ALU64 | BPF_ARSH | BPF_K] = &&ALU64_ARSH_K,
104734 - [BPF_ALU64 | BPF_DIV | BPF_X] = &&ALU64_DIV_X,
104735 - [BPF_ALU64 | BPF_DIV | BPF_K] = &&ALU64_DIV_K,
104736 - [BPF_ALU64 | BPF_MOD | BPF_X] = &&ALU64_MOD_X,
104737 - [BPF_ALU64 | BPF_MOD | BPF_K] = &&ALU64_MOD_K,
104738 - [BPF_ALU64 | BPF_NEG] = &&ALU64_NEG,
104739 - /* Call instruction */
104740 - [BPF_JMP | BPF_CALL] = &&JMP_CALL,
104741 - /* Jumps */
104742 - [BPF_JMP | BPF_JA] = &&JMP_JA,
104743 - [BPF_JMP | BPF_JEQ | BPF_X] = &&JMP_JEQ_X,
104744 - [BPF_JMP | BPF_JEQ | BPF_K] = &&JMP_JEQ_K,
104745 - [BPF_JMP | BPF_JNE | BPF_X] = &&JMP_JNE_X,
104746 - [BPF_JMP | BPF_JNE | BPF_K] = &&JMP_JNE_K,
104747 - [BPF_JMP | BPF_JGT | BPF_X] = &&JMP_JGT_X,
104748 - [BPF_JMP | BPF_JGT | BPF_K] = &&JMP_JGT_K,
104749 - [BPF_JMP | BPF_JGE | BPF_X] = &&JMP_JGE_X,
104750 - [BPF_JMP | BPF_JGE | BPF_K] = &&JMP_JGE_K,
104751 - [BPF_JMP | BPF_JSGT | BPF_X] = &&JMP_JSGT_X,
104752 - [BPF_JMP | BPF_JSGT | BPF_K] = &&JMP_JSGT_K,
104753 - [BPF_JMP | BPF_JSGE | BPF_X] = &&JMP_JSGE_X,
104754 - [BPF_JMP | BPF_JSGE | BPF_K] = &&JMP_JSGE_K,
104755 - [BPF_JMP | BPF_JSET | BPF_X] = &&JMP_JSET_X,
104756 - [BPF_JMP | BPF_JSET | BPF_K] = &&JMP_JSET_K,
104757 - /* Program return */
104758 - [BPF_JMP | BPF_EXIT] = &&JMP_EXIT,
104759 - /* Store instructions */
104760 - [BPF_STX | BPF_MEM | BPF_B] = &&STX_MEM_B,
104761 - [BPF_STX | BPF_MEM | BPF_H] = &&STX_MEM_H,
104762 - [BPF_STX | BPF_MEM | BPF_W] = &&STX_MEM_W,
104763 - [BPF_STX | BPF_MEM | BPF_DW] = &&STX_MEM_DW,
104764 - [BPF_STX | BPF_XADD | BPF_W] = &&STX_XADD_W,
104765 - [BPF_STX | BPF_XADD | BPF_DW] = &&STX_XADD_DW,
104766 - [BPF_ST | BPF_MEM | BPF_B] = &&ST_MEM_B,
104767 - [BPF_ST | BPF_MEM | BPF_H] = &&ST_MEM_H,
104768 - [BPF_ST | BPF_MEM | BPF_W] = &&ST_MEM_W,
104769 - [BPF_ST | BPF_MEM | BPF_DW] = &&ST_MEM_DW,
104770 - /* Load instructions */
104771 - [BPF_LDX | BPF_MEM | BPF_B] = &&LDX_MEM_B,
104772 - [BPF_LDX | BPF_MEM | BPF_H] = &&LDX_MEM_H,
104773 - [BPF_LDX | BPF_MEM | BPF_W] = &&LDX_MEM_W,
104774 - [BPF_LDX | BPF_MEM | BPF_DW] = &&LDX_MEM_DW,
104775 - [BPF_LD | BPF_ABS | BPF_W] = &&LD_ABS_W,
104776 - [BPF_LD | BPF_ABS | BPF_H] = &&LD_ABS_H,
104777 - [BPF_LD | BPF_ABS | BPF_B] = &&LD_ABS_B,
104778 - [BPF_LD | BPF_IND | BPF_W] = &&LD_IND_W,
104779 - [BPF_LD | BPF_IND | BPF_H] = &&LD_IND_H,
104780 - [BPF_LD | BPF_IND | BPF_B] = &&LD_IND_B,
104781 - };
104782 void *ptr;
104783 - int off;
104784 -
104785 -#define CONT ({ insn++; goto select_insn; })
104786 -#define CONT_JMP ({ insn++; goto select_insn; })
104787 -
104788 - FP = (u64) (unsigned long) &stack[ARRAY_SIZE(stack)];
104789 - ARG1 = (u64) (unsigned long) ctx;
104790 -
104791 - /* Registers used in classic BPF programs need to be reset first. */
104792 - regs[BPF_REG_A] = 0;
104793 - regs[BPF_REG_X] = 0;
104794 -
104795 -select_insn:
104796 - goto *jumptable[insn->code];
104797 -
104798 - /* ALU */
104799 -#define ALU(OPCODE, OP) \
104800 - ALU64_##OPCODE##_X: \
104801 - DST = DST OP SRC; \
104802 - CONT; \
104803 - ALU_##OPCODE##_X: \
104804 - DST = (u32) DST OP (u32) SRC; \
104805 - CONT; \
104806 - ALU64_##OPCODE##_K: \
104807 - DST = DST OP IMM; \
104808 - CONT; \
104809 - ALU_##OPCODE##_K: \
104810 - DST = (u32) DST OP (u32) IMM; \
104811 - CONT;
104812 -
104813 - ALU(ADD, +)
104814 - ALU(SUB, -)
104815 - ALU(AND, &)
104816 - ALU(OR, |)
104817 - ALU(LSH, <<)
104818 - ALU(RSH, >>)
104819 - ALU(XOR, ^)
104820 - ALU(MUL, *)
104821 -#undef ALU
104822 - ALU_NEG:
104823 - DST = (u32) -DST;
104824 - CONT;
104825 - ALU64_NEG:
104826 - DST = -DST;
104827 - CONT;
104828 - ALU_MOV_X:
104829 - DST = (u32) SRC;
104830 - CONT;
104831 - ALU_MOV_K:
104832 - DST = (u32) IMM;
104833 - CONT;
104834 - ALU64_MOV_X:
104835 - DST = SRC;
104836 - CONT;
104837 - ALU64_MOV_K:
104838 - DST = IMM;
104839 - CONT;
104840 - ALU64_ARSH_X:
104841 - (*(s64 *) &DST) >>= SRC;
104842 - CONT;
104843 - ALU64_ARSH_K:
104844 - (*(s64 *) &DST) >>= IMM;
104845 - CONT;
104846 - ALU64_MOD_X:
104847 - if (unlikely(SRC == 0))
104848 - return 0;
104849 - tmp = DST;
104850 - DST = do_div(tmp, SRC);
104851 - CONT;
104852 - ALU_MOD_X:
104853 - if (unlikely(SRC == 0))
104854 - return 0;
104855 - tmp = (u32) DST;
104856 - DST = do_div(tmp, (u32) SRC);
104857 - CONT;
104858 - ALU64_MOD_K:
104859 - tmp = DST;
104860 - DST = do_div(tmp, IMM);
104861 - CONT;
104862 - ALU_MOD_K:
104863 - tmp = (u32) DST;
104864 - DST = do_div(tmp, (u32) IMM);
104865 - CONT;
104866 - ALU64_DIV_X:
104867 - if (unlikely(SRC == 0))
104868 - return 0;
104869 - do_div(DST, SRC);
104870 - CONT;
104871 - ALU_DIV_X:
104872 - if (unlikely(SRC == 0))
104873 - return 0;
104874 - tmp = (u32) DST;
104875 - do_div(tmp, (u32) SRC);
104876 - DST = (u32) tmp;
104877 - CONT;
104878 - ALU64_DIV_K:
104879 - do_div(DST, IMM);
104880 - CONT;
104881 - ALU_DIV_K:
104882 - tmp = (u32) DST;
104883 - do_div(tmp, (u32) IMM);
104884 - DST = (u32) tmp;
104885 - CONT;
104886 - ALU_END_TO_BE:
104887 - switch (IMM) {
104888 - case 16:
104889 - DST = (__force u16) cpu_to_be16(DST);
104890 - break;
104891 - case 32:
104892 - DST = (__force u32) cpu_to_be32(DST);
104893 - break;
104894 - case 64:
104895 - DST = (__force u64) cpu_to_be64(DST);
104896 - break;
104897 - }
104898 - CONT;
104899 - ALU_END_TO_LE:
104900 - switch (IMM) {
104901 - case 16:
104902 - DST = (__force u16) cpu_to_le16(DST);
104903 - break;
104904 - case 32:
104905 - DST = (__force u32) cpu_to_le32(DST);
104906 - break;
104907 - case 64:
104908 - DST = (__force u64) cpu_to_le64(DST);
104909 - break;
104910 - }
104911 - CONT;
104912 -
104913 - /* CALL */
104914 - JMP_CALL:
104915 - /* Function call scratches BPF_R1-BPF_R5 registers,
104916 - * preserves BPF_R6-BPF_R9, and stores return value
104917 - * into BPF_R0.
104918 - */
104919 - BPF_R0 = (__bpf_call_base + insn->imm)(BPF_R1, BPF_R2, BPF_R3,
104920 - BPF_R4, BPF_R5);
104921 - CONT;
104922 -
104923 - /* JMP */
104924 - JMP_JA:
104925 - insn += insn->off;
104926 - CONT;
104927 - JMP_JEQ_X:
104928 - if (DST == SRC) {
104929 - insn += insn->off;
104930 - CONT_JMP;
104931 - }
104932 - CONT;
104933 - JMP_JEQ_K:
104934 - if (DST == IMM) {
104935 - insn += insn->off;
104936 - CONT_JMP;
104937 - }
104938 - CONT;
104939 - JMP_JNE_X:
104940 - if (DST != SRC) {
104941 - insn += insn->off;
104942 - CONT_JMP;
104943 - }
104944 - CONT;
104945 - JMP_JNE_K:
104946 - if (DST != IMM) {
104947 - insn += insn->off;
104948 - CONT_JMP;
104949 - }
104950 - CONT;
104951 - JMP_JGT_X:
104952 - if (DST > SRC) {
104953 - insn += insn->off;
104954 - CONT_JMP;
104955 - }
104956 - CONT;
104957 - JMP_JGT_K:
104958 - if (DST > IMM) {
104959 - insn += insn->off;
104960 - CONT_JMP;
104961 - }
104962 - CONT;
104963 - JMP_JGE_X:
104964 - if (DST >= SRC) {
104965 - insn += insn->off;
104966 - CONT_JMP;
104967 - }
104968 - CONT;
104969 - JMP_JGE_K:
104970 - if (DST >= IMM) {
104971 - insn += insn->off;
104972 - CONT_JMP;
104973 - }
104974 - CONT;
104975 - JMP_JSGT_X:
104976 - if (((s64) DST) > ((s64) SRC)) {
104977 - insn += insn->off;
104978 - CONT_JMP;
104979 - }
104980 - CONT;
104981 - JMP_JSGT_K:
104982 - if (((s64) DST) > ((s64) IMM)) {
104983 - insn += insn->off;
104984 - CONT_JMP;
104985 - }
104986 - CONT;
104987 - JMP_JSGE_X:
104988 - if (((s64) DST) >= ((s64) SRC)) {
104989 - insn += insn->off;
104990 - CONT_JMP;
104991 - }
104992 - CONT;
104993 - JMP_JSGE_K:
104994 - if (((s64) DST) >= ((s64) IMM)) {
104995 - insn += insn->off;
104996 - CONT_JMP;
104997 - }
104998 - CONT;
104999 - JMP_JSET_X:
105000 - if (DST & SRC) {
105001 - insn += insn->off;
105002 - CONT_JMP;
105003 - }
105004 - CONT;
105005 - JMP_JSET_K:
105006 - if (DST & IMM) {
105007 - insn += insn->off;
105008 - CONT_JMP;
105009 - }
105010 - CONT;
105011 - JMP_EXIT:
105012 - return BPF_R0;
105013 -
105014 - /* STX and ST and LDX*/
105015 -#define LDST(SIZEOP, SIZE) \
105016 - STX_MEM_##SIZEOP: \
105017 - *(SIZE *)(unsigned long) (DST + insn->off) = SRC; \
105018 - CONT; \
105019 - ST_MEM_##SIZEOP: \
105020 - *(SIZE *)(unsigned long) (DST + insn->off) = IMM; \
105021 - CONT; \
105022 - LDX_MEM_##SIZEOP: \
105023 - DST = *(SIZE *)(unsigned long) (SRC + insn->off); \
105024 - CONT;
105025 -
105026 - LDST(B, u8)
105027 - LDST(H, u16)
105028 - LDST(W, u32)
105029 - LDST(DW, u64)
105030 -#undef LDST
105031 - STX_XADD_W: /* lock xadd *(u32 *)(dst_reg + off16) += src_reg */
105032 - atomic_add((u32) SRC, (atomic_t *)(unsigned long)
105033 - (DST + insn->off));
105034 - CONT;
105035 - STX_XADD_DW: /* lock xadd *(u64 *)(dst_reg + off16) += src_reg */
105036 - atomic64_add((u64) SRC, (atomic64_t *)(unsigned long)
105037 - (DST + insn->off));
105038 - CONT;
105039 - LD_ABS_W: /* BPF_R0 = ntohl(*(u32 *) (skb->data + imm32)) */
105040 - off = IMM;
105041 -load_word:
105042 - /* BPF_LD + BPD_ABS and BPF_LD + BPF_IND insns are
105043 - * only appearing in the programs where ctx ==
105044 - * skb. All programs keep 'ctx' in regs[BPF_REG_CTX]
105045 - * == BPF_R6, sk_convert_filter() saves it in BPF_R6,
105046 - * internal BPF verifier will check that BPF_R6 ==
105047 - * ctx.
105048 - *
105049 - * BPF_ABS and BPF_IND are wrappers of function calls,
105050 - * so they scratch BPF_R1-BPF_R5 registers, preserve
105051 - * BPF_R6-BPF_R9, and store return value into BPF_R0.
105052 - *
105053 - * Implicit input:
105054 - * ctx == skb == BPF_R6 == CTX
105055 - *
105056 - * Explicit input:
105057 - * SRC == any register
105058 - * IMM == 32-bit immediate
105059 - *
105060 - * Output:
105061 - * BPF_R0 - 8/16/32-bit skb data converted to cpu endianness
105062 - */
105063 -
105064 - ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 4, &tmp);
105065 - if (likely(ptr != NULL)) {
105066 - BPF_R0 = get_unaligned_be32(ptr);
105067 - CONT;
105068 - }
105069 -
105070 - return 0;
105071 - LD_ABS_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + imm32)) */
105072 - off = IMM;
105073 -load_half:
105074 - ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 2, &tmp);
105075 - if (likely(ptr != NULL)) {
105076 - BPF_R0 = get_unaligned_be16(ptr);
105077 - CONT;
105078 - }
105079 -
105080 - return 0;
105081 - LD_ABS_B: /* BPF_R0 = *(u8 *) (skb->data + imm32) */
105082 - off = IMM;
105083 -load_byte:
105084 - ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 1, &tmp);
105085 - if (likely(ptr != NULL)) {
105086 - BPF_R0 = *(u8 *)ptr;
105087 - CONT;
105088 - }
105089 -
105090 - return 0;
105091 - LD_IND_W: /* BPF_R0 = ntohl(*(u32 *) (skb->data + src_reg + imm32)) */
105092 - off = IMM + SRC;
105093 - goto load_word;
105094 - LD_IND_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + src_reg + imm32)) */
105095 - off = IMM + SRC;
105096 - goto load_half;
105097 - LD_IND_B: /* BPF_R0 = *(u8 *) (skb->data + src_reg + imm32) */
105098 - off = IMM + SRC;
105099 - goto load_byte;
105100 -
105101 - default_label:
105102 - /* If we ever reach this, we have a bug somewhere. */
105103 - WARN_RATELIMIT(1, "unknown opcode %02x\n", insn->code);
105104 - return 0;
105105 -}
105106 -
105107 -/* Helper to find the offset of pkt_type in sk_buff structure. We want
105108 - * to make sure its still a 3bit field starting at a byte boundary;
105109 - * taken from arch/x86/net/bpf_jit_comp.c.
105110 - */
105111 -#ifdef __BIG_ENDIAN_BITFIELD
105112 -#define PKT_TYPE_MAX (7 << 5)
105113 + u32 A = 0; /* Accumulator */
105114 + u32 X = 0; /* Index Register */
105115 + u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
105116 + u32 tmp;
105117 + int k;
105118 +
105119 + /*
105120 + * Process array of filter instructions.
105121 + */
105122 + for (;; fentry++) {
105123 +#if defined(CONFIG_X86_32)
105124 +#define K (fentry->k)
105125 #else
105126 -#define PKT_TYPE_MAX 7
105127 + const u32 K = fentry->k;
105128 #endif
105129 -static unsigned int pkt_type_offset(void)
105130 -{
105131 - struct sk_buff skb_probe = { .pkt_type = ~0, };
105132 - u8 *ct = (u8 *) &skb_probe;
105133 - unsigned int off;
105134
105135 - for (off = 0; off < sizeof(struct sk_buff); off++) {
105136 - if (ct[off] == PKT_TYPE_MAX)
105137 - return off;
105138 - }
105139 -
105140 - pr_err_once("Please fix %s, as pkt_type couldn't be found!\n", __func__);
105141 - return -1;
105142 -}
105143 -
105144 -static u64 __skb_get_pay_offset(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105145 -{
105146 - return __skb_get_poff((struct sk_buff *)(unsigned long) ctx);
105147 -}
105148 -
105149 -static u64 __skb_get_nlattr(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105150 -{
105151 - struct sk_buff *skb = (struct sk_buff *)(unsigned long) ctx;
105152 - struct nlattr *nla;
105153 -
105154 - if (skb_is_nonlinear(skb))
105155 - return 0;
105156 -
105157 - if (skb->len < sizeof(struct nlattr))
105158 - return 0;
105159 -
105160 - if (a > skb->len - sizeof(struct nlattr))
105161 - return 0;
105162 -
105163 - nla = nla_find((struct nlattr *) &skb->data[a], skb->len - a, x);
105164 - if (nla)
105165 - return (void *) nla - (void *) skb->data;
105166 -
105167 - return 0;
105168 -}
105169 -
105170 -static u64 __skb_get_nlattr_nest(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105171 -{
105172 - struct sk_buff *skb = (struct sk_buff *)(unsigned long) ctx;
105173 - struct nlattr *nla;
105174 -
105175 - if (skb_is_nonlinear(skb))
105176 - return 0;
105177 -
105178 - if (skb->len < sizeof(struct nlattr))
105179 - return 0;
105180 -
105181 - if (a > skb->len - sizeof(struct nlattr))
105182 - return 0;
105183 -
105184 - nla = (struct nlattr *) &skb->data[a];
105185 - if (nla->nla_len > skb->len - a)
105186 - return 0;
105187 -
105188 - nla = nla_find_nested(nla, x);
105189 - if (nla)
105190 - return (void *) nla - (void *) skb->data;
105191 -
105192 - return 0;
105193 -}
105194 -
105195 -static u64 __get_raw_cpu_id(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105196 -{
105197 - return raw_smp_processor_id();
105198 -}
105199 -
105200 -/* note that this only generates 32-bit random numbers */
105201 -static u64 __get_random_u32(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105202 -{
105203 - return prandom_u32();
105204 -}
105205 -
105206 -static bool convert_bpf_extensions(struct sock_filter *fp,
105207 - struct sock_filter_int **insnp)
105208 -{
105209 - struct sock_filter_int *insn = *insnp;
105210 -
105211 - switch (fp->k) {
105212 - case SKF_AD_OFF + SKF_AD_PROTOCOL:
105213 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, protocol) != 2);
105214 -
105215 - /* A = *(u16 *) (CTX + offsetof(protocol)) */
105216 - *insn++ = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_CTX,
105217 - offsetof(struct sk_buff, protocol));
105218 - /* A = ntohs(A) [emitting a nop or swap16] */
105219 - *insn = BPF_ENDIAN(BPF_FROM_BE, BPF_REG_A, 16);
105220 - break;
105221 -
105222 - case SKF_AD_OFF + SKF_AD_PKTTYPE:
105223 - *insn = BPF_LDX_MEM(BPF_B, BPF_REG_A, BPF_REG_CTX,
105224 - pkt_type_offset());
105225 - if (insn->off < 0)
105226 - return false;
105227 - insn++;
105228 - *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, PKT_TYPE_MAX);
105229 -#ifdef __BIG_ENDIAN_BITFIELD
105230 - insn++;
105231 - *insn = BPF_ALU32_IMM(BPF_RSH, BPF_REG_A, 5);
105232 -#endif
105233 - break;
105234 -
105235 - case SKF_AD_OFF + SKF_AD_IFINDEX:
105236 - case SKF_AD_OFF + SKF_AD_HATYPE:
105237 - BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
105238 - BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, type) != 2);
105239 - BUILD_BUG_ON(bytes_to_bpf_size(FIELD_SIZEOF(struct sk_buff, dev)) < 0);
105240 -
105241 - *insn++ = BPF_LDX_MEM(bytes_to_bpf_size(FIELD_SIZEOF(struct sk_buff, dev)),
105242 - BPF_REG_TMP, BPF_REG_CTX,
105243 - offsetof(struct sk_buff, dev));
105244 - /* if (tmp != 0) goto pc + 1 */
105245 - *insn++ = BPF_JMP_IMM(BPF_JNE, BPF_REG_TMP, 0, 1);
105246 - *insn++ = BPF_EXIT_INSN();
105247 - if (fp->k == SKF_AD_OFF + SKF_AD_IFINDEX)
105248 - *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_TMP,
105249 - offsetof(struct net_device, ifindex));
105250 - else
105251 - *insn = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_TMP,
105252 - offsetof(struct net_device, type));
105253 - break;
105254 -
105255 - case SKF_AD_OFF + SKF_AD_MARK:
105256 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, mark) != 4);
105257 -
105258 - *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_CTX,
105259 - offsetof(struct sk_buff, mark));
105260 - break;
105261 -
105262 - case SKF_AD_OFF + SKF_AD_RXHASH:
105263 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, hash) != 4);
105264 -
105265 - *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_CTX,
105266 - offsetof(struct sk_buff, hash));
105267 - break;
105268 -
105269 - case SKF_AD_OFF + SKF_AD_QUEUE:
105270 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, queue_mapping) != 2);
105271 -
105272 - *insn = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_CTX,
105273 - offsetof(struct sk_buff, queue_mapping));
105274 - break;
105275 -
105276 - case SKF_AD_OFF + SKF_AD_VLAN_TAG:
105277 - case SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT:
105278 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
105279 - BUILD_BUG_ON(VLAN_TAG_PRESENT != 0x1000);
105280 -
105281 - /* A = *(u16 *) (CTX + offsetof(vlan_tci)) */
105282 - *insn++ = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_CTX,
105283 - offsetof(struct sk_buff, vlan_tci));
105284 - if (fp->k == SKF_AD_OFF + SKF_AD_VLAN_TAG) {
105285 - *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A,
105286 - ~VLAN_TAG_PRESENT);
105287 - } else {
105288 - /* A >>= 12 */
105289 - *insn++ = BPF_ALU32_IMM(BPF_RSH, BPF_REG_A, 12);
105290 - /* A &= 1 */
105291 - *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, 1);
105292 - }
105293 - break;
105294 -
105295 - case SKF_AD_OFF + SKF_AD_PAY_OFFSET:
105296 - case SKF_AD_OFF + SKF_AD_NLATTR:
105297 - case SKF_AD_OFF + SKF_AD_NLATTR_NEST:
105298 - case SKF_AD_OFF + SKF_AD_CPU:
105299 - case SKF_AD_OFF + SKF_AD_RANDOM:
105300 - /* arg1 = CTX */
105301 - *insn++ = BPF_MOV64_REG(BPF_REG_ARG1, BPF_REG_CTX);
105302 - /* arg2 = A */
105303 - *insn++ = BPF_MOV64_REG(BPF_REG_ARG2, BPF_REG_A);
105304 - /* arg3 = X */
105305 - *insn++ = BPF_MOV64_REG(BPF_REG_ARG3, BPF_REG_X);
105306 - /* Emit call(arg1=CTX, arg2=A, arg3=X) */
105307 - switch (fp->k) {
105308 - case SKF_AD_OFF + SKF_AD_PAY_OFFSET:
105309 - *insn = BPF_EMIT_CALL(__skb_get_pay_offset);
105310 - break;
105311 - case SKF_AD_OFF + SKF_AD_NLATTR:
105312 - *insn = BPF_EMIT_CALL(__skb_get_nlattr);
105313 - break;
105314 - case SKF_AD_OFF + SKF_AD_NLATTR_NEST:
105315 - *insn = BPF_EMIT_CALL(__skb_get_nlattr_nest);
105316 - break;
105317 - case SKF_AD_OFF + SKF_AD_CPU:
105318 - *insn = BPF_EMIT_CALL(__get_raw_cpu_id);
105319 - break;
105320 - case SKF_AD_OFF + SKF_AD_RANDOM:
105321 - *insn = BPF_EMIT_CALL(__get_random_u32);
105322 - break;
105323 - }
105324 - break;
105325 -
105326 - case SKF_AD_OFF + SKF_AD_ALU_XOR_X:
105327 - /* A ^= X */
105328 - *insn = BPF_ALU32_REG(BPF_XOR, BPF_REG_A, BPF_REG_X);
105329 - break;
105330 -
105331 - default:
105332 - /* This is just a dummy call to avoid letting the compiler
105333 - * evict __bpf_call_base() as an optimization. Placed here
105334 - * where no-one bothers.
105335 - */
105336 - BUG_ON(__bpf_call_base(0, 0, 0, 0, 0) != 0);
105337 - return false;
105338 - }
105339 -
105340 - *insnp = insn;
105341 - return true;
105342 -}
105343 -
105344 -/**
105345 - * sk_convert_filter - convert filter program
105346 - * @prog: the user passed filter program
105347 - * @len: the length of the user passed filter program
105348 - * @new_prog: buffer where converted program will be stored
105349 - * @new_len: pointer to store length of converted program
105350 - *
105351 - * Remap 'sock_filter' style BPF instruction set to 'sock_filter_ext' style.
105352 - * Conversion workflow:
105353 - *
105354 - * 1) First pass for calculating the new program length:
105355 - * sk_convert_filter(old_prog, old_len, NULL, &new_len)
105356 - *
105357 - * 2) 2nd pass to remap in two passes: 1st pass finds new
105358 - * jump offsets, 2nd pass remapping:
105359 - * new_prog = kmalloc(sizeof(struct sock_filter_int) * new_len);
105360 - * sk_convert_filter(old_prog, old_len, new_prog, &new_len);
105361 - *
105362 - * User BPF's register A is mapped to our BPF register 6, user BPF
105363 - * register X is mapped to BPF register 7; frame pointer is always
105364 - * register 10; Context 'void *ctx' is stored in register 1, that is,
105365 - * for socket filters: ctx == 'struct sk_buff *', for seccomp:
105366 - * ctx == 'struct seccomp_data *'.
105367 - */
105368 -int sk_convert_filter(struct sock_filter *prog, int len,
105369 - struct sock_filter_int *new_prog, int *new_len)
105370 -{
105371 - int new_flen = 0, pass = 0, target, i;
105372 - struct sock_filter_int *new_insn;
105373 - struct sock_filter *fp;
105374 - int *addrs = NULL;
105375 - u8 bpf_src;
105376 -
105377 - BUILD_BUG_ON(BPF_MEMWORDS * sizeof(u32) > MAX_BPF_STACK);
105378 - BUILD_BUG_ON(BPF_REG_FP + 1 != MAX_BPF_REG);
105379 -
105380 - if (len <= 0 || len > BPF_MAXINSNS)
105381 - return -EINVAL;
105382 -
105383 - if (new_prog) {
105384 - addrs = kcalloc(len, sizeof(*addrs), GFP_KERNEL);
105385 - if (!addrs)
105386 - return -ENOMEM;
105387 - }
105388 -
105389 -do_pass:
105390 - new_insn = new_prog;
105391 - fp = prog;
105392 -
105393 - if (new_insn)
105394 - *new_insn = BPF_MOV64_REG(BPF_REG_CTX, BPF_REG_ARG1);
105395 - new_insn++;
105396 -
105397 - for (i = 0; i < len; fp++, i++) {
105398 - struct sock_filter_int tmp_insns[6] = { };
105399 - struct sock_filter_int *insn = tmp_insns;
105400 -
105401 - if (addrs)
105402 - addrs[i] = new_insn - new_prog;
105403 -
105404 - switch (fp->code) {
105405 - /* All arithmetic insns and skb loads map as-is. */
105406 - case BPF_ALU | BPF_ADD | BPF_X:
105407 - case BPF_ALU | BPF_ADD | BPF_K:
105408 - case BPF_ALU | BPF_SUB | BPF_X:
105409 - case BPF_ALU | BPF_SUB | BPF_K:
105410 - case BPF_ALU | BPF_AND | BPF_X:
105411 - case BPF_ALU | BPF_AND | BPF_K:
105412 - case BPF_ALU | BPF_OR | BPF_X:
105413 - case BPF_ALU | BPF_OR | BPF_K:
105414 - case BPF_ALU | BPF_LSH | BPF_X:
105415 - case BPF_ALU | BPF_LSH | BPF_K:
105416 - case BPF_ALU | BPF_RSH | BPF_X:
105417 - case BPF_ALU | BPF_RSH | BPF_K:
105418 - case BPF_ALU | BPF_XOR | BPF_X:
105419 - case BPF_ALU | BPF_XOR | BPF_K:
105420 - case BPF_ALU | BPF_MUL | BPF_X:
105421 - case BPF_ALU | BPF_MUL | BPF_K:
105422 - case BPF_ALU | BPF_DIV | BPF_X:
105423 - case BPF_ALU | BPF_DIV | BPF_K:
105424 - case BPF_ALU | BPF_MOD | BPF_X:
105425 - case BPF_ALU | BPF_MOD | BPF_K:
105426 - case BPF_ALU | BPF_NEG:
105427 - case BPF_LD | BPF_ABS | BPF_W:
105428 - case BPF_LD | BPF_ABS | BPF_H:
105429 - case BPF_LD | BPF_ABS | BPF_B:
105430 - case BPF_LD | BPF_IND | BPF_W:
105431 - case BPF_LD | BPF_IND | BPF_H:
105432 - case BPF_LD | BPF_IND | BPF_B:
105433 - /* Check for overloaded BPF extension and
105434 - * directly convert it if found, otherwise
105435 - * just move on with mapping.
105436 - */
105437 - if (BPF_CLASS(fp->code) == BPF_LD &&
105438 - BPF_MODE(fp->code) == BPF_ABS &&
105439 - convert_bpf_extensions(fp, &insn))
105440 - break;
105441 -
105442 - *insn = BPF_RAW_INSN(fp->code, BPF_REG_A, BPF_REG_X, 0, fp->k);
105443 - break;
105444 -
105445 - /* Jump transformation cannot use BPF block macros
105446 - * everywhere as offset calculation and target updates
105447 - * require a bit more work than the rest, i.e. jump
105448 - * opcodes map as-is, but offsets need adjustment.
105449 - */
105450 -
105451 -#define BPF_EMIT_JMP \
105452 - do { \
105453 - if (target >= len || target < 0) \
105454 - goto err; \
105455 - insn->off = addrs ? addrs[target] - addrs[i] - 1 : 0; \
105456 - /* Adjust pc relative offset for 2nd or 3rd insn. */ \
105457 - insn->off -= insn - tmp_insns; \
105458 - } while (0)
105459 -
105460 - case BPF_JMP | BPF_JA:
105461 - target = i + fp->k + 1;
105462 - insn->code = fp->code;
105463 - BPF_EMIT_JMP;
105464 - break;
105465 -
105466 - case BPF_JMP | BPF_JEQ | BPF_K:
105467 - case BPF_JMP | BPF_JEQ | BPF_X:
105468 - case BPF_JMP | BPF_JSET | BPF_K:
105469 - case BPF_JMP | BPF_JSET | BPF_X:
105470 - case BPF_JMP | BPF_JGT | BPF_K:
105471 - case BPF_JMP | BPF_JGT | BPF_X:
105472 - case BPF_JMP | BPF_JGE | BPF_K:
105473 - case BPF_JMP | BPF_JGE | BPF_X:
105474 - if (BPF_SRC(fp->code) == BPF_K && (int) fp->k < 0) {
105475 - /* BPF immediates are signed, zero extend
105476 - * immediate into tmp register and use it
105477 - * in compare insn.
105478 - */
105479 - *insn++ = BPF_MOV32_IMM(BPF_REG_TMP, fp->k);
105480 -
105481 - insn->dst_reg = BPF_REG_A;
105482 - insn->src_reg = BPF_REG_TMP;
105483 - bpf_src = BPF_X;
105484 - } else {
105485 - insn->dst_reg = BPF_REG_A;
105486 - insn->src_reg = BPF_REG_X;
105487 - insn->imm = fp->k;
105488 - bpf_src = BPF_SRC(fp->code);
105489 + switch (fentry->code) {
105490 + case BPF_S_ALU_ADD_X:
105491 + A += X;
105492 + continue;
105493 + case BPF_S_ALU_ADD_K:
105494 + A += K;
105495 + continue;
105496 + case BPF_S_ALU_SUB_X:
105497 + A -= X;
105498 + continue;
105499 + case BPF_S_ALU_SUB_K:
105500 + A -= K;
105501 + continue;
105502 + case BPF_S_ALU_MUL_X:
105503 + A *= X;
105504 + continue;
105505 + case BPF_S_ALU_MUL_K:
105506 + A *= K;
105507 + continue;
105508 + case BPF_S_ALU_DIV_X:
105509 + if (X == 0)
105510 + return 0;
105511 + A /= X;
105512 + continue;
105513 + case BPF_S_ALU_DIV_K:
105514 + A /= K;
105515 + continue;
105516 + case BPF_S_ALU_MOD_X:
105517 + if (X == 0)
105518 + return 0;
105519 + A %= X;
105520 + continue;
105521 + case BPF_S_ALU_MOD_K:
105522 + A %= K;
105523 + continue;
105524 + case BPF_S_ALU_AND_X:
105525 + A &= X;
105526 + continue;
105527 + case BPF_S_ALU_AND_K:
105528 + A &= K;
105529 + continue;
105530 + case BPF_S_ALU_OR_X:
105531 + A |= X;
105532 + continue;
105533 + case BPF_S_ALU_OR_K:
105534 + A |= K;
105535 + continue;
105536 + case BPF_S_ANC_ALU_XOR_X:
105537 + case BPF_S_ALU_XOR_X:
105538 + A ^= X;
105539 + continue;
105540 + case BPF_S_ALU_XOR_K:
105541 + A ^= K;
105542 + continue;
105543 + case BPF_S_ALU_LSH_X:
105544 + A <<= X;
105545 + continue;
105546 + case BPF_S_ALU_LSH_K:
105547 + A <<= K;
105548 + continue;
105549 + case BPF_S_ALU_RSH_X:
105550 + A >>= X;
105551 + continue;
105552 + case BPF_S_ALU_RSH_K:
105553 + A >>= K;
105554 + continue;
105555 + case BPF_S_ALU_NEG:
105556 + A = -A;
105557 + continue;
105558 + case BPF_S_JMP_JA:
105559 + fentry += K;
105560 + continue;
105561 + case BPF_S_JMP_JGT_K:
105562 + fentry += (A > K) ? fentry->jt : fentry->jf;
105563 + continue;
105564 + case BPF_S_JMP_JGE_K:
105565 + fentry += (A >= K) ? fentry->jt : fentry->jf;
105566 + continue;
105567 + case BPF_S_JMP_JEQ_K:
105568 + fentry += (A == K) ? fentry->jt : fentry->jf;
105569 + continue;
105570 + case BPF_S_JMP_JSET_K:
105571 + fentry += (A & K) ? fentry->jt : fentry->jf;
105572 + continue;
105573 + case BPF_S_JMP_JGT_X:
105574 + fentry += (A > X) ? fentry->jt : fentry->jf;
105575 + continue;
105576 + case BPF_S_JMP_JGE_X:
105577 + fentry += (A >= X) ? fentry->jt : fentry->jf;
105578 + continue;
105579 + case BPF_S_JMP_JEQ_X:
105580 + fentry += (A == X) ? fentry->jt : fentry->jf;
105581 + continue;
105582 + case BPF_S_JMP_JSET_X:
105583 + fentry += (A & X) ? fentry->jt : fentry->jf;
105584 + continue;
105585 + case BPF_S_LD_W_ABS:
105586 + k = K;
105587 +load_w:
105588 + ptr = load_pointer(skb, k, 4, &tmp);
105589 + if (ptr != NULL) {
105590 + A = get_unaligned_be32(ptr);
105591 + continue;
105592 }
105593 -
105594 - /* Common case where 'jump_false' is next insn. */
105595 - if (fp->jf == 0) {
105596 - insn->code = BPF_JMP | BPF_OP(fp->code) | bpf_src;
105597 - target = i + fp->jt + 1;
105598 - BPF_EMIT_JMP;
105599 - break;
105600 + return 0;
105601 + case BPF_S_LD_H_ABS:
105602 + k = K;
105603 +load_h:
105604 + ptr = load_pointer(skb, k, 2, &tmp);
105605 + if (ptr != NULL) {
105606 + A = get_unaligned_be16(ptr);
105607 + continue;
105608 }
105609 -
105610 - /* Convert JEQ into JNE when 'jump_true' is next insn. */
105611 - if (fp->jt == 0 && BPF_OP(fp->code) == BPF_JEQ) {
105612 - insn->code = BPF_JMP | BPF_JNE | bpf_src;
105613 - target = i + fp->jf + 1;
105614 - BPF_EMIT_JMP;
105615 - break;
105616 + return 0;
105617 + case BPF_S_LD_B_ABS:
105618 + k = K;
105619 +load_b:
105620 + ptr = load_pointer(skb, k, 1, &tmp);
105621 + if (ptr != NULL) {
105622 + A = *(u8 *)ptr;
105623 + continue;
105624 }
105625 -
105626 - /* Other jumps are mapped into two insns: Jxx and JA. */
105627 - target = i + fp->jt + 1;
105628 - insn->code = BPF_JMP | BPF_OP(fp->code) | bpf_src;
105629 - BPF_EMIT_JMP;
105630 - insn++;
105631 -
105632 - insn->code = BPF_JMP | BPF_JA;
105633 - target = i + fp->jf + 1;
105634 - BPF_EMIT_JMP;
105635 - break;
105636 -
105637 - /* ldxb 4 * ([14] & 0xf) is remaped into 6 insns. */
105638 - case BPF_LDX | BPF_MSH | BPF_B:
105639 - /* tmp = A */
105640 - *insn++ = BPF_MOV64_REG(BPF_REG_TMP, BPF_REG_A);
105641 - /* A = BPF_R0 = *(u8 *) (skb->data + K) */
105642 - *insn++ = BPF_LD_ABS(BPF_B, fp->k);
105643 - /* A &= 0xf */
105644 - *insn++ = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, 0xf);
105645 - /* A <<= 2 */
105646 - *insn++ = BPF_ALU32_IMM(BPF_LSH, BPF_REG_A, 2);
105647 - /* X = A */
105648 - *insn++ = BPF_MOV64_REG(BPF_REG_X, BPF_REG_A);
105649 - /* A = tmp */
105650 - *insn = BPF_MOV64_REG(BPF_REG_A, BPF_REG_TMP);
105651 - break;
105652 -
105653 - /* RET_K, RET_A are remaped into 2 insns. */
105654 - case BPF_RET | BPF_A:
105655 - case BPF_RET | BPF_K:
105656 - *insn++ = BPF_MOV32_RAW(BPF_RVAL(fp->code) == BPF_K ?
105657 - BPF_K : BPF_X, BPF_REG_0,
105658 - BPF_REG_A, fp->k);
105659 - *insn = BPF_EXIT_INSN();
105660 - break;
105661 -
105662 - /* Store to stack. */
105663 - case BPF_ST:
105664 - case BPF_STX:
105665 - *insn = BPF_STX_MEM(BPF_W, BPF_REG_FP, BPF_CLASS(fp->code) ==
105666 - BPF_ST ? BPF_REG_A : BPF_REG_X,
105667 - -(BPF_MEMWORDS - fp->k) * 4);
105668 - break;
105669 -
105670 - /* Load from stack. */
105671 - case BPF_LD | BPF_MEM:
105672 - case BPF_LDX | BPF_MEM:
105673 - *insn = BPF_LDX_MEM(BPF_W, BPF_CLASS(fp->code) == BPF_LD ?
105674 - BPF_REG_A : BPF_REG_X, BPF_REG_FP,
105675 - -(BPF_MEMWORDS - fp->k) * 4);
105676 - break;
105677 -
105678 - /* A = K or X = K */
105679 - case BPF_LD | BPF_IMM:
105680 - case BPF_LDX | BPF_IMM:
105681 - *insn = BPF_MOV32_IMM(BPF_CLASS(fp->code) == BPF_LD ?
105682 - BPF_REG_A : BPF_REG_X, fp->k);
105683 - break;
105684 -
105685 - /* X = A */
105686 - case BPF_MISC | BPF_TAX:
105687 - *insn = BPF_MOV64_REG(BPF_REG_X, BPF_REG_A);
105688 - break;
105689 -
105690 - /* A = X */
105691 - case BPF_MISC | BPF_TXA:
105692 - *insn = BPF_MOV64_REG(BPF_REG_A, BPF_REG_X);
105693 - break;
105694 -
105695 - /* A = skb->len or X = skb->len */
105696 - case BPF_LD | BPF_W | BPF_LEN:
105697 - case BPF_LDX | BPF_W | BPF_LEN:
105698 - *insn = BPF_LDX_MEM(BPF_W, BPF_CLASS(fp->code) == BPF_LD ?
105699 - BPF_REG_A : BPF_REG_X, BPF_REG_CTX,
105700 - offsetof(struct sk_buff, len));
105701 - break;
105702 -
105703 - /* Access seccomp_data fields. */
105704 - case BPF_LDX | BPF_ABS | BPF_W:
105705 - /* A = *(u32 *) (ctx + K) */
105706 - *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_CTX, fp->k);
105707 - break;
105708 -
105709 - /* Unkown instruction. */
105710 + return 0;
105711 + case BPF_S_LD_W_LEN:
105712 + A = skb->len;
105713 + continue;
105714 + case BPF_S_LDX_W_LEN:
105715 + X = skb->len;
105716 + continue;
105717 + case BPF_S_LD_W_IND:
105718 + k = X + K;
105719 + goto load_w;
105720 + case BPF_S_LD_H_IND:
105721 + k = X + K;
105722 + goto load_h;
105723 + case BPF_S_LD_B_IND:
105724 + k = X + K;
105725 + goto load_b;
105726 + case BPF_S_LDX_B_MSH:
105727 + ptr = load_pointer(skb, K, 1, &tmp);
105728 + if (ptr != NULL) {
105729 + X = (*(u8 *)ptr & 0xf) << 2;
105730 + continue;
105731 + }
105732 + return 0;
105733 + case BPF_S_LD_IMM:
105734 + A = K;
105735 + continue;
105736 + case BPF_S_LDX_IMM:
105737 + X = K;
105738 + continue;
105739 + case BPF_S_LD_MEM:
105740 + A = mem[K&15];
105741 + continue;
105742 + case BPF_S_LDX_MEM:
105743 + X = mem[K&15];
105744 + continue;
105745 + case BPF_S_MISC_TAX:
105746 + X = A;
105747 + continue;
105748 + case BPF_S_MISC_TXA:
105749 + A = X;
105750 + continue;
105751 + case BPF_S_RET_K:
105752 + return K;
105753 + case BPF_S_RET_A:
105754 + return A;
105755 + case BPF_S_ST:
105756 + mem[K&15] = A;
105757 + continue;
105758 + case BPF_S_STX:
105759 + mem[K&15] = X;
105760 + continue;
105761 + case BPF_S_ANC_PROTOCOL:
105762 + A = ntohs(skb->protocol);
105763 + continue;
105764 + case BPF_S_ANC_PKTTYPE:
105765 + A = skb->pkt_type;
105766 + continue;
105767 + case BPF_S_ANC_IFINDEX:
105768 + if (!skb->dev)
105769 + return 0;
105770 + A = skb->dev->ifindex;
105771 + continue;
105772 + case BPF_S_ANC_MARK:
105773 + A = skb->mark;
105774 + continue;
105775 + case BPF_S_ANC_QUEUE:
105776 + A = skb->queue_mapping;
105777 + continue;
105778 + case BPF_S_ANC_HATYPE:
105779 + if (!skb->dev)
105780 + return 0;
105781 + A = skb->dev->type;
105782 + continue;
105783 + case BPF_S_ANC_RXHASH:
105784 + A = skb->hash;
105785 + continue;
105786 + case BPF_S_ANC_CPU:
105787 + A = raw_smp_processor_id();
105788 + continue;
105789 + case BPF_S_ANC_VLAN_TAG:
105790 + A = vlan_tx_tag_get(skb);
105791 + continue;
105792 + case BPF_S_ANC_VLAN_TAG_PRESENT:
105793 + A = !!vlan_tx_tag_present(skb);
105794 + continue;
105795 + case BPF_S_ANC_PAY_OFFSET:
105796 + A = __skb_get_poff(skb);
105797 + continue;
105798 + case BPF_S_ANC_NLATTR: {
105799 + struct nlattr *nla;
105800 +
105801 + if (skb_is_nonlinear(skb))
105802 + return 0;
105803 + if (skb->len < sizeof(struct nlattr))
105804 + return 0;
105805 + if (A > skb->len - sizeof(struct nlattr))
105806 + return 0;
105807 +
105808 + nla = nla_find((struct nlattr *)&skb->data[A],
105809 + skb->len - A, X);
105810 + if (nla)
105811 + A = (void *)nla - (void *)skb->data;
105812 + else
105813 + A = 0;
105814 + continue;
105815 + }
105816 + case BPF_S_ANC_NLATTR_NEST: {
105817 + struct nlattr *nla;
105818 +
105819 + if (skb_is_nonlinear(skb))
105820 + return 0;
105821 + if (skb->len < sizeof(struct nlattr))
105822 + return 0;
105823 + if (A > skb->len - sizeof(struct nlattr))
105824 + return 0;
105825 +
105826 + nla = (struct nlattr *)&skb->data[A];
105827 + if (nla->nla_len > skb->len - A)
105828 + return 0;
105829 +
105830 + nla = nla_find_nested(nla, X);
105831 + if (nla)
105832 + A = (void *)nla - (void *)skb->data;
105833 + else
105834 + A = 0;
105835 + continue;
105836 + }
105837 +#ifdef CONFIG_SECCOMP_FILTER
105838 + case BPF_S_ANC_SECCOMP_LD_W:
105839 + A = seccomp_bpf_load(fentry->k);
105840 + continue;
105841 +#endif
105842 default:
105843 - goto err;
105844 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
105845 + fentry->code, fentry->jt,
105846 + fentry->jf, fentry->k);
105847 + BUG();
105848 + return 0;
105849 }
105850 -
105851 - insn++;
105852 - if (new_prog)
105853 - memcpy(new_insn, tmp_insns,
105854 - sizeof(*insn) * (insn - tmp_insns));
105855 - new_insn += insn - tmp_insns;
105856 - }
105857 -
105858 - if (!new_prog) {
105859 - /* Only calculating new length. */
105860 - *new_len = new_insn - new_prog;
105861 - return 0;
105862 - }
105863 -
105864 - pass++;
105865 - if (new_flen != new_insn - new_prog) {
105866 - new_flen = new_insn - new_prog;
105867 - if (pass > 2)
105868 - goto err;
105869 - goto do_pass;
105870 }
105871
105872 - kfree(addrs);
105873 - BUG_ON(*new_len != new_flen);
105874 return 0;
105875 -err:
105876 - kfree(addrs);
105877 - return -EINVAL;
105878 }
105879 +EXPORT_SYMBOL(sk_run_filter);
105880
105881 -/* Security:
105882 - *
105883 +/*
105884 + * Security :
105885 * A BPF program is able to use 16 cells of memory to store intermediate
105886 - * values (check u32 mem[BPF_MEMWORDS] in sk_run_filter()).
105887 - *
105888 + * values (check u32 mem[BPF_MEMWORDS] in sk_run_filter())
105889 * As we dont want to clear mem[] array for each packet going through
105890 * sk_run_filter(), we check that filter loaded by user never try to read
105891 * a cell if not previously written, and we check all branches to be sure
105892 @@ -1096,46 +418,44 @@ err:
105893 */
105894 static int check_load_and_stores(struct sock_filter *filter, int flen)
105895 {
105896 - u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
105897 + u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
105898 int pc, ret = 0;
105899
105900 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
105901 -
105902 - masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
105903 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
105904 + masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
105905 if (!masks)
105906 return -ENOMEM;
105907 -
105908 memset(masks, 0xff, flen * sizeof(*masks));
105909
105910 for (pc = 0; pc < flen; pc++) {
105911 memvalid &= masks[pc];
105912
105913 switch (filter[pc].code) {
105914 - case BPF_ST:
105915 - case BPF_STX:
105916 + case BPF_S_ST:
105917 + case BPF_S_STX:
105918 memvalid |= (1 << filter[pc].k);
105919 break;
105920 - case BPF_LD | BPF_MEM:
105921 - case BPF_LDX | BPF_MEM:
105922 + case BPF_S_LD_MEM:
105923 + case BPF_S_LDX_MEM:
105924 if (!(memvalid & (1 << filter[pc].k))) {
105925 ret = -EINVAL;
105926 goto error;
105927 }
105928 break;
105929 - case BPF_JMP | BPF_JA:
105930 - /* A jump must set masks on target */
105931 + case BPF_S_JMP_JA:
105932 + /* a jump must set masks on target */
105933 masks[pc + 1 + filter[pc].k] &= memvalid;
105934 memvalid = ~0;
105935 break;
105936 - case BPF_JMP | BPF_JEQ | BPF_K:
105937 - case BPF_JMP | BPF_JEQ | BPF_X:
105938 - case BPF_JMP | BPF_JGE | BPF_K:
105939 - case BPF_JMP | BPF_JGE | BPF_X:
105940 - case BPF_JMP | BPF_JGT | BPF_K:
105941 - case BPF_JMP | BPF_JGT | BPF_X:
105942 - case BPF_JMP | BPF_JSET | BPF_K:
105943 - case BPF_JMP | BPF_JSET | BPF_X:
105944 - /* A jump must set masks on targets */
105945 + case BPF_S_JMP_JEQ_K:
105946 + case BPF_S_JMP_JEQ_X:
105947 + case BPF_S_JMP_JGE_K:
105948 + case BPF_S_JMP_JGE_X:
105949 + case BPF_S_JMP_JGT_K:
105950 + case BPF_S_JMP_JGT_X:
105951 + case BPF_S_JMP_JSET_X:
105952 + case BPF_S_JMP_JSET_K:
105953 + /* a jump must set masks on targets */
105954 masks[pc + 1 + filter[pc].jt] &= memvalid;
105955 masks[pc + 1 + filter[pc].jf] &= memvalid;
105956 memvalid = ~0;
105957 @@ -1147,72 +467,6 @@ error:
105958 return ret;
105959 }
105960
105961 -static bool chk_code_allowed(u16 code_to_probe)
105962 -{
105963 - static const bool codes[] = {
105964 - /* 32 bit ALU operations */
105965 - [BPF_ALU | BPF_ADD | BPF_K] = true,
105966 - [BPF_ALU | BPF_ADD | BPF_X] = true,
105967 - [BPF_ALU | BPF_SUB | BPF_K] = true,
105968 - [BPF_ALU | BPF_SUB | BPF_X] = true,
105969 - [BPF_ALU | BPF_MUL | BPF_K] = true,
105970 - [BPF_ALU | BPF_MUL | BPF_X] = true,
105971 - [BPF_ALU | BPF_DIV | BPF_K] = true,
105972 - [BPF_ALU | BPF_DIV | BPF_X] = true,
105973 - [BPF_ALU | BPF_MOD | BPF_K] = true,
105974 - [BPF_ALU | BPF_MOD | BPF_X] = true,
105975 - [BPF_ALU | BPF_AND | BPF_K] = true,
105976 - [BPF_ALU | BPF_AND | BPF_X] = true,
105977 - [BPF_ALU | BPF_OR | BPF_K] = true,
105978 - [BPF_ALU | BPF_OR | BPF_X] = true,
105979 - [BPF_ALU | BPF_XOR | BPF_K] = true,
105980 - [BPF_ALU | BPF_XOR | BPF_X] = true,
105981 - [BPF_ALU | BPF_LSH | BPF_K] = true,
105982 - [BPF_ALU | BPF_LSH | BPF_X] = true,
105983 - [BPF_ALU | BPF_RSH | BPF_K] = true,
105984 - [BPF_ALU | BPF_RSH | BPF_X] = true,
105985 - [BPF_ALU | BPF_NEG] = true,
105986 - /* Load instructions */
105987 - [BPF_LD | BPF_W | BPF_ABS] = true,
105988 - [BPF_LD | BPF_H | BPF_ABS] = true,
105989 - [BPF_LD | BPF_B | BPF_ABS] = true,
105990 - [BPF_LD | BPF_W | BPF_LEN] = true,
105991 - [BPF_LD | BPF_W | BPF_IND] = true,
105992 - [BPF_LD | BPF_H | BPF_IND] = true,
105993 - [BPF_LD | BPF_B | BPF_IND] = true,
105994 - [BPF_LD | BPF_IMM] = true,
105995 - [BPF_LD | BPF_MEM] = true,
105996 - [BPF_LDX | BPF_W | BPF_LEN] = true,
105997 - [BPF_LDX | BPF_B | BPF_MSH] = true,
105998 - [BPF_LDX | BPF_IMM] = true,
105999 - [BPF_LDX | BPF_MEM] = true,
106000 - /* Store instructions */
106001 - [BPF_ST] = true,
106002 - [BPF_STX] = true,
106003 - /* Misc instructions */
106004 - [BPF_MISC | BPF_TAX] = true,
106005 - [BPF_MISC | BPF_TXA] = true,
106006 - /* Return instructions */
106007 - [BPF_RET | BPF_K] = true,
106008 - [BPF_RET | BPF_A] = true,
106009 - /* Jump instructions */
106010 - [BPF_JMP | BPF_JA] = true,
106011 - [BPF_JMP | BPF_JEQ | BPF_K] = true,
106012 - [BPF_JMP | BPF_JEQ | BPF_X] = true,
106013 - [BPF_JMP | BPF_JGE | BPF_K] = true,
106014 - [BPF_JMP | BPF_JGE | BPF_X] = true,
106015 - [BPF_JMP | BPF_JGT | BPF_K] = true,
106016 - [BPF_JMP | BPF_JGT | BPF_X] = true,
106017 - [BPF_JMP | BPF_JSET | BPF_K] = true,
106018 - [BPF_JMP | BPF_JSET | BPF_X] = true,
106019 - };
106020 -
106021 - if (code_to_probe >= ARRAY_SIZE(codes))
106022 - return false;
106023 -
106024 - return codes[code_to_probe];
106025 -}
106026 -
106027 /**
106028 * sk_chk_filter - verify socket filter code
106029 * @filter: filter to verify
106030 @@ -1229,303 +483,187 @@ static bool chk_code_allowed(u16 code_to_probe)
106031 */
106032 int sk_chk_filter(struct sock_filter *filter, unsigned int flen)
106033 {
106034 - bool anc_found;
106035 + /*
106036 + * Valid instructions are initialized to non-0.
106037 + * Invalid instructions are initialized to 0.
106038 + */
106039 + static const u8 codes[] = {
106040 + [BPF_ALU|BPF_ADD|BPF_K] = BPF_S_ALU_ADD_K,
106041 + [BPF_ALU|BPF_ADD|BPF_X] = BPF_S_ALU_ADD_X,
106042 + [BPF_ALU|BPF_SUB|BPF_K] = BPF_S_ALU_SUB_K,
106043 + [BPF_ALU|BPF_SUB|BPF_X] = BPF_S_ALU_SUB_X,
106044 + [BPF_ALU|BPF_MUL|BPF_K] = BPF_S_ALU_MUL_K,
106045 + [BPF_ALU|BPF_MUL|BPF_X] = BPF_S_ALU_MUL_X,
106046 + [BPF_ALU|BPF_DIV|BPF_X] = BPF_S_ALU_DIV_X,
106047 + [BPF_ALU|BPF_MOD|BPF_K] = BPF_S_ALU_MOD_K,
106048 + [BPF_ALU|BPF_MOD|BPF_X] = BPF_S_ALU_MOD_X,
106049 + [BPF_ALU|BPF_AND|BPF_K] = BPF_S_ALU_AND_K,
106050 + [BPF_ALU|BPF_AND|BPF_X] = BPF_S_ALU_AND_X,
106051 + [BPF_ALU|BPF_OR|BPF_K] = BPF_S_ALU_OR_K,
106052 + [BPF_ALU|BPF_OR|BPF_X] = BPF_S_ALU_OR_X,
106053 + [BPF_ALU|BPF_XOR|BPF_K] = BPF_S_ALU_XOR_K,
106054 + [BPF_ALU|BPF_XOR|BPF_X] = BPF_S_ALU_XOR_X,
106055 + [BPF_ALU|BPF_LSH|BPF_K] = BPF_S_ALU_LSH_K,
106056 + [BPF_ALU|BPF_LSH|BPF_X] = BPF_S_ALU_LSH_X,
106057 + [BPF_ALU|BPF_RSH|BPF_K] = BPF_S_ALU_RSH_K,
106058 + [BPF_ALU|BPF_RSH|BPF_X] = BPF_S_ALU_RSH_X,
106059 + [BPF_ALU|BPF_NEG] = BPF_S_ALU_NEG,
106060 + [BPF_LD|BPF_W|BPF_ABS] = BPF_S_LD_W_ABS,
106061 + [BPF_LD|BPF_H|BPF_ABS] = BPF_S_LD_H_ABS,
106062 + [BPF_LD|BPF_B|BPF_ABS] = BPF_S_LD_B_ABS,
106063 + [BPF_LD|BPF_W|BPF_LEN] = BPF_S_LD_W_LEN,
106064 + [BPF_LD|BPF_W|BPF_IND] = BPF_S_LD_W_IND,
106065 + [BPF_LD|BPF_H|BPF_IND] = BPF_S_LD_H_IND,
106066 + [BPF_LD|BPF_B|BPF_IND] = BPF_S_LD_B_IND,
106067 + [BPF_LD|BPF_IMM] = BPF_S_LD_IMM,
106068 + [BPF_LDX|BPF_W|BPF_LEN] = BPF_S_LDX_W_LEN,
106069 + [BPF_LDX|BPF_B|BPF_MSH] = BPF_S_LDX_B_MSH,
106070 + [BPF_LDX|BPF_IMM] = BPF_S_LDX_IMM,
106071 + [BPF_MISC|BPF_TAX] = BPF_S_MISC_TAX,
106072 + [BPF_MISC|BPF_TXA] = BPF_S_MISC_TXA,
106073 + [BPF_RET|BPF_K] = BPF_S_RET_K,
106074 + [BPF_RET|BPF_A] = BPF_S_RET_A,
106075 + [BPF_ALU|BPF_DIV|BPF_K] = BPF_S_ALU_DIV_K,
106076 + [BPF_LD|BPF_MEM] = BPF_S_LD_MEM,
106077 + [BPF_LDX|BPF_MEM] = BPF_S_LDX_MEM,
106078 + [BPF_ST] = BPF_S_ST,
106079 + [BPF_STX] = BPF_S_STX,
106080 + [BPF_JMP|BPF_JA] = BPF_S_JMP_JA,
106081 + [BPF_JMP|BPF_JEQ|BPF_K] = BPF_S_JMP_JEQ_K,
106082 + [BPF_JMP|BPF_JEQ|BPF_X] = BPF_S_JMP_JEQ_X,
106083 + [BPF_JMP|BPF_JGE|BPF_K] = BPF_S_JMP_JGE_K,
106084 + [BPF_JMP|BPF_JGE|BPF_X] = BPF_S_JMP_JGE_X,
106085 + [BPF_JMP|BPF_JGT|BPF_K] = BPF_S_JMP_JGT_K,
106086 + [BPF_JMP|BPF_JGT|BPF_X] = BPF_S_JMP_JGT_X,
106087 + [BPF_JMP|BPF_JSET|BPF_K] = BPF_S_JMP_JSET_K,
106088 + [BPF_JMP|BPF_JSET|BPF_X] = BPF_S_JMP_JSET_X,
106089 + };
106090 int pc;
106091 + bool anc_found;
106092
106093 if (flen == 0 || flen > BPF_MAXINSNS)
106094 return -EINVAL;
106095
106096 - /* Check the filter code now */
106097 + /* check the filter code now */
106098 for (pc = 0; pc < flen; pc++) {
106099 struct sock_filter *ftest = &filter[pc];
106100 + u16 code = ftest->code;
106101
106102 - /* May we actually operate on this code? */
106103 - if (!chk_code_allowed(ftest->code))
106104 + if (code >= ARRAY_SIZE(codes))
106105 + return -EINVAL;
106106 + code = codes[code];
106107 + if (!code)
106108 return -EINVAL;
106109 -
106110 /* Some instructions need special checks */
106111 - switch (ftest->code) {
106112 - case BPF_ALU | BPF_DIV | BPF_K:
106113 - case BPF_ALU | BPF_MOD | BPF_K:
106114 - /* Check for division by zero */
106115 + switch (code) {
106116 + case BPF_S_ALU_DIV_K:
106117 + case BPF_S_ALU_MOD_K:
106118 + /* check for division by zero */
106119 if (ftest->k == 0)
106120 return -EINVAL;
106121 break;
106122 - case BPF_LD | BPF_MEM:
106123 - case BPF_LDX | BPF_MEM:
106124 - case BPF_ST:
106125 - case BPF_STX:
106126 - /* Check for invalid memory addresses */
106127 + case BPF_S_LD_MEM:
106128 + case BPF_S_LDX_MEM:
106129 + case BPF_S_ST:
106130 + case BPF_S_STX:
106131 + /* check for invalid memory addresses */
106132 if (ftest->k >= BPF_MEMWORDS)
106133 return -EINVAL;
106134 break;
106135 - case BPF_JMP | BPF_JA:
106136 - /* Note, the large ftest->k might cause loops.
106137 + case BPF_S_JMP_JA:
106138 + /*
106139 + * Note, the large ftest->k might cause loops.
106140 * Compare this with conditional jumps below,
106141 * where offsets are limited. --ANK (981016)
106142 */
106143 - if (ftest->k >= (unsigned int)(flen - pc - 1))
106144 + if (ftest->k >= (unsigned int)(flen-pc-1))
106145 return -EINVAL;
106146 break;
106147 - case BPF_JMP | BPF_JEQ | BPF_K:
106148 - case BPF_JMP | BPF_JEQ | BPF_X:
106149 - case BPF_JMP | BPF_JGE | BPF_K:
106150 - case BPF_JMP | BPF_JGE | BPF_X:
106151 - case BPF_JMP | BPF_JGT | BPF_K:
106152 - case BPF_JMP | BPF_JGT | BPF_X:
106153 - case BPF_JMP | BPF_JSET | BPF_K:
106154 - case BPF_JMP | BPF_JSET | BPF_X:
106155 - /* Both conditionals must be safe */
106156 + case BPF_S_JMP_JEQ_K:
106157 + case BPF_S_JMP_JEQ_X:
106158 + case BPF_S_JMP_JGE_K:
106159 + case BPF_S_JMP_JGE_X:
106160 + case BPF_S_JMP_JGT_K:
106161 + case BPF_S_JMP_JGT_X:
106162 + case BPF_S_JMP_JSET_X:
106163 + case BPF_S_JMP_JSET_K:
106164 + /* for conditionals both must be safe */
106165 if (pc + ftest->jt + 1 >= flen ||
106166 pc + ftest->jf + 1 >= flen)
106167 return -EINVAL;
106168 break;
106169 - case BPF_LD | BPF_W | BPF_ABS:
106170 - case BPF_LD | BPF_H | BPF_ABS:
106171 - case BPF_LD | BPF_B | BPF_ABS:
106172 + case BPF_S_LD_W_ABS:
106173 + case BPF_S_LD_H_ABS:
106174 + case BPF_S_LD_B_ABS:
106175 anc_found = false;
106176 - if (bpf_anc_helper(ftest) & BPF_ANC)
106177 - anc_found = true;
106178 - /* Ancillary operation unknown or unsupported */
106179 +#define ANCILLARY(CODE) case SKF_AD_OFF + SKF_AD_##CODE: \
106180 + code = BPF_S_ANC_##CODE; \
106181 + anc_found = true; \
106182 + break
106183 + switch (ftest->k) {
106184 + ANCILLARY(PROTOCOL);
106185 + ANCILLARY(PKTTYPE);
106186 + ANCILLARY(IFINDEX);
106187 + ANCILLARY(NLATTR);
106188 + ANCILLARY(NLATTR_NEST);
106189 + ANCILLARY(MARK);
106190 + ANCILLARY(QUEUE);
106191 + ANCILLARY(HATYPE);
106192 + ANCILLARY(RXHASH);
106193 + ANCILLARY(CPU);
106194 + ANCILLARY(ALU_XOR_X);
106195 + ANCILLARY(VLAN_TAG);
106196 + ANCILLARY(VLAN_TAG_PRESENT);
106197 + ANCILLARY(PAY_OFFSET);
106198 + }
106199 +
106200 + /* ancillary operation unknown or unsupported */
106201 if (anc_found == false && ftest->k >= SKF_AD_OFF)
106202 return -EINVAL;
106203 }
106204 + ftest->code = code;
106205 }
106206
106207 - /* Last instruction must be a RET code */
106208 + /* last instruction must be a RET code */
106209 switch (filter[flen - 1].code) {
106210 - case BPF_RET | BPF_K:
106211 - case BPF_RET | BPF_A:
106212 + case BPF_S_RET_K:
106213 + case BPF_S_RET_A:
106214 return check_load_and_stores(filter, flen);
106215 }
106216 -
106217 return -EINVAL;
106218 }
106219 EXPORT_SYMBOL(sk_chk_filter);
106220
106221 -static int sk_store_orig_filter(struct sk_filter *fp,
106222 - const struct sock_fprog *fprog)
106223 -{
106224 - unsigned int fsize = sk_filter_proglen(fprog);
106225 - struct sock_fprog_kern *fkprog;
106226 -
106227 - fp->orig_prog = kmalloc(sizeof(*fkprog), GFP_KERNEL);
106228 - if (!fp->orig_prog)
106229 - return -ENOMEM;
106230 -
106231 - fkprog = fp->orig_prog;
106232 - fkprog->len = fprog->len;
106233 - fkprog->filter = kmemdup(fp->insns, fsize, GFP_KERNEL);
106234 - if (!fkprog->filter) {
106235 - kfree(fp->orig_prog);
106236 - return -ENOMEM;
106237 - }
106238 -
106239 - return 0;
106240 -}
106241 -
106242 -static void sk_release_orig_filter(struct sk_filter *fp)
106243 -{
106244 - struct sock_fprog_kern *fprog = fp->orig_prog;
106245 -
106246 - if (fprog) {
106247 - kfree(fprog->filter);
106248 - kfree(fprog);
106249 - }
106250 -}
106251 -
106252 /**
106253 * sk_filter_release_rcu - Release a socket filter by rcu_head
106254 * @rcu: rcu_head that contains the sk_filter to free
106255 */
106256 -static void sk_filter_release_rcu(struct rcu_head *rcu)
106257 +void sk_filter_release_rcu(struct rcu_head *rcu)
106258 {
106259 struct sk_filter *fp = container_of(rcu, struct sk_filter, rcu);
106260
106261 - sk_release_orig_filter(fp);
106262 - sk_filter_free(fp);
106263 -}
106264 -
106265 -/**
106266 - * sk_filter_release - release a socket filter
106267 - * @fp: filter to remove
106268 - *
106269 - * Remove a filter from a socket and release its resources.
106270 - */
106271 -static void sk_filter_release(struct sk_filter *fp)
106272 -{
106273 - if (atomic_dec_and_test(&fp->refcnt))
106274 - call_rcu(&fp->rcu, sk_filter_release_rcu);
106275 -}
106276 -
106277 -void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp)
106278 -{
106279 - atomic_sub(sk_filter_size(fp->len), &sk->sk_omem_alloc);
106280 - sk_filter_release(fp);
106281 -}
106282 -
106283 -void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
106284 -{
106285 - atomic_inc(&fp->refcnt);
106286 - atomic_add(sk_filter_size(fp->len), &sk->sk_omem_alloc);
106287 -}
106288 -
106289 -static struct sk_filter *__sk_migrate_realloc(struct sk_filter *fp,
106290 - struct sock *sk,
106291 - unsigned int len)
106292 -{
106293 - struct sk_filter *fp_new;
106294 -
106295 - if (sk == NULL)
106296 - return krealloc(fp, len, GFP_KERNEL);
106297 -
106298 - fp_new = sock_kmalloc(sk, len, GFP_KERNEL);
106299 - if (fp_new) {
106300 - *fp_new = *fp;
106301 - /* As we're keeping orig_prog in fp_new along,
106302 - * we need to make sure we're not evicting it
106303 - * from the old fp.
106304 - */
106305 - fp->orig_prog = NULL;
106306 - sk_filter_uncharge(sk, fp);
106307 - }
106308 -
106309 - return fp_new;
106310 -}
106311 -
106312 -static struct sk_filter *__sk_migrate_filter(struct sk_filter *fp,
106313 - struct sock *sk)
106314 -{
106315 - struct sock_filter *old_prog;
106316 - struct sk_filter *old_fp;
106317 - int err, new_len, old_len = fp->len;
106318 -
106319 - /* We are free to overwrite insns et al right here as it
106320 - * won't be used at this point in time anymore internally
106321 - * after the migration to the internal BPF instruction
106322 - * representation.
106323 - */
106324 - BUILD_BUG_ON(sizeof(struct sock_filter) !=
106325 - sizeof(struct sock_filter_int));
106326 -
106327 - /* Conversion cannot happen on overlapping memory areas,
106328 - * so we need to keep the user BPF around until the 2nd
106329 - * pass. At this time, the user BPF is stored in fp->insns.
106330 - */
106331 - old_prog = kmemdup(fp->insns, old_len * sizeof(struct sock_filter),
106332 - GFP_KERNEL);
106333 - if (!old_prog) {
106334 - err = -ENOMEM;
106335 - goto out_err;
106336 - }
106337 -
106338 - /* 1st pass: calculate the new program length. */
106339 - err = sk_convert_filter(old_prog, old_len, NULL, &new_len);
106340 - if (err)
106341 - goto out_err_free;
106342 -
106343 - /* Expand fp for appending the new filter representation. */
106344 - old_fp = fp;
106345 - fp = __sk_migrate_realloc(old_fp, sk, sk_filter_size(new_len));
106346 - if (!fp) {
106347 - /* The old_fp is still around in case we couldn't
106348 - * allocate new memory, so uncharge on that one.
106349 - */
106350 - fp = old_fp;
106351 - err = -ENOMEM;
106352 - goto out_err_free;
106353 - }
106354 -
106355 - fp->len = new_len;
106356 -
106357 - /* 2nd pass: remap sock_filter insns into sock_filter_int insns. */
106358 - err = sk_convert_filter(old_prog, old_len, fp->insnsi, &new_len);
106359 - if (err)
106360 - /* 2nd sk_convert_filter() can fail only if it fails
106361 - * to allocate memory, remapping must succeed. Note,
106362 - * that at this time old_fp has already been released
106363 - * by __sk_migrate_realloc().
106364 - */
106365 - goto out_err_free;
106366 -
106367 - sk_filter_select_runtime(fp);
106368 -
106369 - kfree(old_prog);
106370 - return fp;
106371 -
106372 -out_err_free:
106373 - kfree(old_prog);
106374 -out_err:
106375 - /* Rollback filter setup. */
106376 - if (sk != NULL)
106377 - sk_filter_uncharge(sk, fp);
106378 - else
106379 - kfree(fp);
106380 - return ERR_PTR(err);
106381 -}
106382 -
106383 -void __weak bpf_int_jit_compile(struct sk_filter *prog)
106384 -{
106385 -}
106386 -
106387 -/**
106388 - * sk_filter_select_runtime - select execution runtime for BPF program
106389 - * @fp: sk_filter populated with internal BPF program
106390 - *
106391 - * try to JIT internal BPF program, if JIT is not available select interpreter
106392 - * BPF program will be executed via SK_RUN_FILTER() macro
106393 - */
106394 -void sk_filter_select_runtime(struct sk_filter *fp)
106395 -{
106396 - fp->bpf_func = (void *) __sk_run_filter;
106397 -
106398 - /* Probe if internal BPF can be JITed */
106399 - bpf_int_jit_compile(fp);
106400 -}
106401 -EXPORT_SYMBOL_GPL(sk_filter_select_runtime);
106402 -
106403 -/* free internal BPF program */
106404 -void sk_filter_free(struct sk_filter *fp)
106405 -{
106406 bpf_jit_free(fp);
106407 }
106408 -EXPORT_SYMBOL_GPL(sk_filter_free);
106409 +EXPORT_SYMBOL(sk_filter_release_rcu);
106410
106411 -static struct sk_filter *__sk_prepare_filter(struct sk_filter *fp,
106412 - struct sock *sk)
106413 +static int __sk_prepare_filter(struct sk_filter *fp)
106414 {
106415 int err;
106416
106417 - fp->bpf_func = NULL;
106418 - fp->jited = 0;
106419 + fp->bpf_func = sk_run_filter;
106420
106421 err = sk_chk_filter(fp->insns, fp->len);
106422 - if (err) {
106423 - if (sk != NULL)
106424 - sk_filter_uncharge(sk, fp);
106425 - else
106426 - kfree(fp);
106427 - return ERR_PTR(err);
106428 - }
106429 + if (err)
106430 + return err;
106431
106432 - /* Probe if we can JIT compile the filter and if so, do
106433 - * the compilation of the filter.
106434 - */
106435 bpf_jit_compile(fp);
106436 -
106437 - /* JIT compiler couldn't process this filter, so do the
106438 - * internal BPF translation for the optimized interpreter.
106439 - */
106440 - if (!fp->jited)
106441 - fp = __sk_migrate_filter(fp, sk);
106442 -
106443 - return fp;
106444 + return 0;
106445 }
106446
106447 /**
106448 * sk_unattached_filter_create - create an unattached filter
106449 + * @fprog: the filter program
106450 * @pfp: the unattached filter that is created
106451 - * @fprog: the filter program
106452 *
106453 * Create a filter independent of any socket. We first run some
106454 * sanity checks on it to make sure it does not explode on us later.
106455 @@ -1533,10 +671,11 @@ static struct sk_filter *__sk_prepare_filter(struct sk_filter *fp,
106456 * a negative errno code is returned. On success the return is zero.
106457 */
106458 int sk_unattached_filter_create(struct sk_filter **pfp,
106459 - struct sock_fprog_kern *fprog)
106460 + struct sock_fprog *fprog)
106461 {
106462 - unsigned int fsize = sk_filter_proglen(fprog);
106463 struct sk_filter *fp;
106464 + unsigned int fsize = sizeof(struct sock_filter) * fprog->len;
106465 + int err;
106466
106467 /* Make sure new filter is there and in the right amounts. */
106468 if (fprog->filter == NULL)
106469 @@ -1545,26 +684,20 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
106470 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
106471 if (!fp)
106472 return -ENOMEM;
106473 -
106474 - memcpy(fp->insns, fprog->filter, fsize);
106475 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
106476
106477 atomic_set(&fp->refcnt, 1);
106478 fp->len = fprog->len;
106479 - /* Since unattached filters are not copied back to user
106480 - * space through sk_get_filter(), we do not need to hold
106481 - * a copy here, and can spare us the work.
106482 - */
106483 - fp->orig_prog = NULL;
106484
106485 - /* __sk_prepare_filter() already takes care of uncharging
106486 - * memory in case something goes wrong.
106487 - */
106488 - fp = __sk_prepare_filter(fp, NULL);
106489 - if (IS_ERR(fp))
106490 - return PTR_ERR(fp);
106491 + err = __sk_prepare_filter(fp);
106492 + if (err)
106493 + goto free_mem;
106494
106495 *pfp = fp;
106496 return 0;
106497 +free_mem:
106498 + kfree(fp);
106499 + return err;
106500 }
106501 EXPORT_SYMBOL_GPL(sk_unattached_filter_create);
106502
106503 @@ -1587,7 +720,7 @@ EXPORT_SYMBOL_GPL(sk_unattached_filter_destroy);
106504 int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
106505 {
106506 struct sk_filter *fp, *old_fp;
106507 - unsigned int fsize = sk_filter_proglen(fprog);
106508 + unsigned int fsize = sizeof(struct sock_filter) * fprog->len;
106509 unsigned int sk_fsize = sk_filter_size(fprog->len);
106510 int err;
106511
106512 @@ -1601,7 +734,6 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
106513 fp = sock_kmalloc(sk, sk_fsize, GFP_KERNEL);
106514 if (!fp)
106515 return -ENOMEM;
106516 -
106517 if (copy_from_user(fp->insns, fprog->filter, fsize)) {
106518 sock_kfree_s(sk, fp, sk_fsize);
106519 return -EFAULT;
106520 @@ -1610,26 +742,18 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
106521 atomic_set(&fp->refcnt, 1);
106522 fp->len = fprog->len;
106523
106524 - err = sk_store_orig_filter(fp, fprog);
106525 + err = __sk_prepare_filter(fp);
106526 if (err) {
106527 sk_filter_uncharge(sk, fp);
106528 - return -ENOMEM;
106529 + return err;
106530 }
106531
106532 - /* __sk_prepare_filter() already takes care of uncharging
106533 - * memory in case something goes wrong.
106534 - */
106535 - fp = __sk_prepare_filter(fp, sk);
106536 - if (IS_ERR(fp))
106537 - return PTR_ERR(fp);
106538 -
106539 old_fp = rcu_dereference_protected(sk->sk_filter,
106540 sock_owned_by_user(sk));
106541 rcu_assign_pointer(sk->sk_filter, fp);
106542
106543 if (old_fp)
106544 sk_filter_uncharge(sk, old_fp);
106545 -
106546 return 0;
106547 }
106548 EXPORT_SYMBOL_GPL(sk_attach_filter);
106549 @@ -1649,46 +773,116 @@ int sk_detach_filter(struct sock *sk)
106550 sk_filter_uncharge(sk, filter);
106551 ret = 0;
106552 }
106553 -
106554 return ret;
106555 }
106556 EXPORT_SYMBOL_GPL(sk_detach_filter);
106557
106558 -int sk_get_filter(struct sock *sk, struct sock_filter __user *ubuf,
106559 - unsigned int len)
106560 +void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to)
106561 +{
106562 + static const u16 decodes[] = {
106563 + [BPF_S_ALU_ADD_K] = BPF_ALU|BPF_ADD|BPF_K,
106564 + [BPF_S_ALU_ADD_X] = BPF_ALU|BPF_ADD|BPF_X,
106565 + [BPF_S_ALU_SUB_K] = BPF_ALU|BPF_SUB|BPF_K,
106566 + [BPF_S_ALU_SUB_X] = BPF_ALU|BPF_SUB|BPF_X,
106567 + [BPF_S_ALU_MUL_K] = BPF_ALU|BPF_MUL|BPF_K,
106568 + [BPF_S_ALU_MUL_X] = BPF_ALU|BPF_MUL|BPF_X,
106569 + [BPF_S_ALU_DIV_X] = BPF_ALU|BPF_DIV|BPF_X,
106570 + [BPF_S_ALU_MOD_K] = BPF_ALU|BPF_MOD|BPF_K,
106571 + [BPF_S_ALU_MOD_X] = BPF_ALU|BPF_MOD|BPF_X,
106572 + [BPF_S_ALU_AND_K] = BPF_ALU|BPF_AND|BPF_K,
106573 + [BPF_S_ALU_AND_X] = BPF_ALU|BPF_AND|BPF_X,
106574 + [BPF_S_ALU_OR_K] = BPF_ALU|BPF_OR|BPF_K,
106575 + [BPF_S_ALU_OR_X] = BPF_ALU|BPF_OR|BPF_X,
106576 + [BPF_S_ALU_XOR_K] = BPF_ALU|BPF_XOR|BPF_K,
106577 + [BPF_S_ALU_XOR_X] = BPF_ALU|BPF_XOR|BPF_X,
106578 + [BPF_S_ALU_LSH_K] = BPF_ALU|BPF_LSH|BPF_K,
106579 + [BPF_S_ALU_LSH_X] = BPF_ALU|BPF_LSH|BPF_X,
106580 + [BPF_S_ALU_RSH_K] = BPF_ALU|BPF_RSH|BPF_K,
106581 + [BPF_S_ALU_RSH_X] = BPF_ALU|BPF_RSH|BPF_X,
106582 + [BPF_S_ALU_NEG] = BPF_ALU|BPF_NEG,
106583 + [BPF_S_LD_W_ABS] = BPF_LD|BPF_W|BPF_ABS,
106584 + [BPF_S_LD_H_ABS] = BPF_LD|BPF_H|BPF_ABS,
106585 + [BPF_S_LD_B_ABS] = BPF_LD|BPF_B|BPF_ABS,
106586 + [BPF_S_ANC_PROTOCOL] = BPF_LD|BPF_B|BPF_ABS,
106587 + [BPF_S_ANC_PKTTYPE] = BPF_LD|BPF_B|BPF_ABS,
106588 + [BPF_S_ANC_IFINDEX] = BPF_LD|BPF_B|BPF_ABS,
106589 + [BPF_S_ANC_NLATTR] = BPF_LD|BPF_B|BPF_ABS,
106590 + [BPF_S_ANC_NLATTR_NEST] = BPF_LD|BPF_B|BPF_ABS,
106591 + [BPF_S_ANC_MARK] = BPF_LD|BPF_B|BPF_ABS,
106592 + [BPF_S_ANC_QUEUE] = BPF_LD|BPF_B|BPF_ABS,
106593 + [BPF_S_ANC_HATYPE] = BPF_LD|BPF_B|BPF_ABS,
106594 + [BPF_S_ANC_RXHASH] = BPF_LD|BPF_B|BPF_ABS,
106595 + [BPF_S_ANC_CPU] = BPF_LD|BPF_B|BPF_ABS,
106596 + [BPF_S_ANC_ALU_XOR_X] = BPF_LD|BPF_B|BPF_ABS,
106597 + [BPF_S_ANC_SECCOMP_LD_W] = BPF_LD|BPF_B|BPF_ABS,
106598 + [BPF_S_ANC_VLAN_TAG] = BPF_LD|BPF_B|BPF_ABS,
106599 + [BPF_S_ANC_VLAN_TAG_PRESENT] = BPF_LD|BPF_B|BPF_ABS,
106600 + [BPF_S_ANC_PAY_OFFSET] = BPF_LD|BPF_B|BPF_ABS,
106601 + [BPF_S_LD_W_LEN] = BPF_LD|BPF_W|BPF_LEN,
106602 + [BPF_S_LD_W_IND] = BPF_LD|BPF_W|BPF_IND,
106603 + [BPF_S_LD_H_IND] = BPF_LD|BPF_H|BPF_IND,
106604 + [BPF_S_LD_B_IND] = BPF_LD|BPF_B|BPF_IND,
106605 + [BPF_S_LD_IMM] = BPF_LD|BPF_IMM,
106606 + [BPF_S_LDX_W_LEN] = BPF_LDX|BPF_W|BPF_LEN,
106607 + [BPF_S_LDX_B_MSH] = BPF_LDX|BPF_B|BPF_MSH,
106608 + [BPF_S_LDX_IMM] = BPF_LDX|BPF_IMM,
106609 + [BPF_S_MISC_TAX] = BPF_MISC|BPF_TAX,
106610 + [BPF_S_MISC_TXA] = BPF_MISC|BPF_TXA,
106611 + [BPF_S_RET_K] = BPF_RET|BPF_K,
106612 + [BPF_S_RET_A] = BPF_RET|BPF_A,
106613 + [BPF_S_ALU_DIV_K] = BPF_ALU|BPF_DIV|BPF_K,
106614 + [BPF_S_LD_MEM] = BPF_LD|BPF_MEM,
106615 + [BPF_S_LDX_MEM] = BPF_LDX|BPF_MEM,
106616 + [BPF_S_ST] = BPF_ST,
106617 + [BPF_S_STX] = BPF_STX,
106618 + [BPF_S_JMP_JA] = BPF_JMP|BPF_JA,
106619 + [BPF_S_JMP_JEQ_K] = BPF_JMP|BPF_JEQ|BPF_K,
106620 + [BPF_S_JMP_JEQ_X] = BPF_JMP|BPF_JEQ|BPF_X,
106621 + [BPF_S_JMP_JGE_K] = BPF_JMP|BPF_JGE|BPF_K,
106622 + [BPF_S_JMP_JGE_X] = BPF_JMP|BPF_JGE|BPF_X,
106623 + [BPF_S_JMP_JGT_K] = BPF_JMP|BPF_JGT|BPF_K,
106624 + [BPF_S_JMP_JGT_X] = BPF_JMP|BPF_JGT|BPF_X,
106625 + [BPF_S_JMP_JSET_K] = BPF_JMP|BPF_JSET|BPF_K,
106626 + [BPF_S_JMP_JSET_X] = BPF_JMP|BPF_JSET|BPF_X,
106627 + };
106628 + u16 code;
106629 +
106630 + code = filt->code;
106631 +
106632 + to->code = decodes[code];
106633 + to->jt = filt->jt;
106634 + to->jf = filt->jf;
106635 + to->k = filt->k;
106636 +}
106637 +
106638 +int sk_get_filter(struct sock *sk, struct sock_filter __user *ubuf, unsigned int len)
106639 {
106640 - struct sock_fprog_kern *fprog;
106641 struct sk_filter *filter;
106642 - int ret = 0;
106643 + int i, ret;
106644
106645 lock_sock(sk);
106646 filter = rcu_dereference_protected(sk->sk_filter,
106647 - sock_owned_by_user(sk));
106648 + sock_owned_by_user(sk));
106649 + ret = 0;
106650 if (!filter)
106651 goto out;
106652 -
106653 - /* We're copying the filter that has been originally attached,
106654 - * so no conversion/decode needed anymore.
106655 - */
106656 - fprog = filter->orig_prog;
106657 -
106658 - ret = fprog->len;
106659 + ret = filter->len;
106660 if (!len)
106661 - /* User space only enquires number of filter blocks. */
106662 goto out;
106663 -
106664 ret = -EINVAL;
106665 - if (len < fprog->len)
106666 + if (len < filter->len)
106667 goto out;
106668
106669 ret = -EFAULT;
106670 - if (copy_to_user(ubuf, fprog->filter, sk_filter_proglen(fprog)))
106671 - goto out;
106672 + for (i = 0; i < filter->len; i++) {
106673 + struct sock_filter fb;
106674
106675 - /* Instead of bytes, the API requests to return the number
106676 - * of filter blocks.
106677 - */
106678 - ret = fprog->len;
106679 + sk_decode_filter(&filter->insns[i], &fb);
106680 + if (copy_to_user(&ubuf[i], &fb, sizeof(fb)))
106681 + goto out;
106682 + }
106683 +
106684 + ret = filter->len;
106685 out:
106686 release_sock(sk);
106687 return ret;
106688 diff --git a/net/core/flow.c b/net/core/flow.c
106689 index a0348fd..6951c76 100644
106690 --- a/net/core/flow.c
106691 +++ b/net/core/flow.c
106692 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
106693 static int flow_entry_valid(struct flow_cache_entry *fle,
106694 struct netns_xfrm *xfrm)
106695 {
106696 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
106697 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
106698 return 0;
106699 if (fle->object && !fle->object->ops->check(fle->object))
106700 return 0;
106701 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
106702 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
106703 fcp->hash_count++;
106704 }
106705 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
106706 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
106707 flo = fle->object;
106708 if (!flo)
106709 goto ret_object;
106710 @@ -263,7 +263,7 @@ nocache:
106711 }
106712 flo = resolver(net, key, family, dir, flo, ctx);
106713 if (fle) {
106714 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
106715 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
106716 if (!IS_ERR(flo))
106717 fle->object = flo;
106718 else
106719 diff --git a/net/core/iovec.c b/net/core/iovec.c
106720 index e1ec45a..e5c6f16 100644
106721 --- a/net/core/iovec.c
106722 +++ b/net/core/iovec.c
106723 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
106724 if (m->msg_name && m->msg_namelen) {
106725 if (mode == VERIFY_READ) {
106726 void __user *namep;
106727 - namep = (void __user __force *) m->msg_name;
106728 + namep = (void __force_user *) m->msg_name;
106729 err = move_addr_to_kernel(namep, m->msg_namelen,
106730 address);
106731 if (err < 0)
106732 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
106733 }
106734
106735 size = m->msg_iovlen * sizeof(struct iovec);
106736 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
106737 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
106738 return -EFAULT;
106739
106740 m->msg_iov = iov;
106741 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
106742 index ef31fef..8be66d9 100644
106743 --- a/net/core/neighbour.c
106744 +++ b/net/core/neighbour.c
106745 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
106746 void __user *buffer, size_t *lenp, loff_t *ppos)
106747 {
106748 int size, ret;
106749 - struct ctl_table tmp = *ctl;
106750 + ctl_table_no_const tmp = *ctl;
106751
106752 tmp.extra1 = &zero;
106753 tmp.extra2 = &unres_qlen_max;
106754 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
106755 void __user *buffer,
106756 size_t *lenp, loff_t *ppos)
106757 {
106758 - struct ctl_table tmp = *ctl;
106759 + ctl_table_no_const tmp = *ctl;
106760 int ret;
106761
106762 tmp.extra1 = &zero;
106763 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
106764 index 2bf8329..2eb1423 100644
106765 --- a/net/core/net-procfs.c
106766 +++ b/net/core/net-procfs.c
106767 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
106768 struct rtnl_link_stats64 temp;
106769 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
106770
106771 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
106772 + if (gr_proc_is_restricted())
106773 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
106774 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
106775 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
106776 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
106777 + else
106778 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
106779 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
106780 dev->name, stats->rx_bytes, stats->rx_packets,
106781 stats->rx_errors,
106782 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
106783 return 0;
106784 }
106785
106786 -static const struct seq_operations dev_seq_ops = {
106787 +const struct seq_operations dev_seq_ops = {
106788 .start = dev_seq_start,
106789 .next = dev_seq_next,
106790 .stop = dev_seq_stop,
106791 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
106792
106793 static int softnet_seq_open(struct inode *inode, struct file *file)
106794 {
106795 - return seq_open(file, &softnet_seq_ops);
106796 + return seq_open_restrict(file, &softnet_seq_ops);
106797 }
106798
106799 static const struct file_operations softnet_seq_fops = {
106800 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
106801 else
106802 seq_printf(seq, "%04x", ntohs(pt->type));
106803
106804 +#ifdef CONFIG_GRKERNSEC_HIDESYM
106805 + seq_printf(seq, " %-8s %pf\n",
106806 + pt->dev ? pt->dev->name : "", NULL);
106807 +#else
106808 seq_printf(seq, " %-8s %pf\n",
106809 pt->dev ? pt->dev->name : "", pt->func);
106810 +#endif
106811 }
106812
106813 return 0;
106814 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
106815 index 1cac29e..fb482f3 100644
106816 --- a/net/core/net-sysfs.c
106817 +++ b/net/core/net-sysfs.c
106818 @@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
106819 {
106820 struct net_device *netdev = to_net_dev(dev);
106821 return sprintf(buf, fmt_dec,
106822 - atomic_read(&netdev->carrier_changes));
106823 + atomic_read_unchecked(&netdev->carrier_changes));
106824 }
106825 static DEVICE_ATTR_RO(carrier_changes);
106826
106827 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
106828 index 85b6269..fc77ea0 100644
106829 --- a/net/core/net_namespace.c
106830 +++ b/net/core/net_namespace.c
106831 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
106832 int error;
106833 LIST_HEAD(net_exit_list);
106834
106835 - list_add_tail(&ops->list, list);
106836 + pax_list_add_tail((struct list_head *)&ops->list, list);
106837 if (ops->init || (ops->id && ops->size)) {
106838 for_each_net(net) {
106839 error = ops_init(ops, net);
106840 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
106841
106842 out_undo:
106843 /* If I have an error cleanup all namespaces I initialized */
106844 - list_del(&ops->list);
106845 + pax_list_del((struct list_head *)&ops->list);
106846 ops_exit_list(ops, &net_exit_list);
106847 ops_free_list(ops, &net_exit_list);
106848 return error;
106849 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
106850 struct net *net;
106851 LIST_HEAD(net_exit_list);
106852
106853 - list_del(&ops->list);
106854 + pax_list_del((struct list_head *)&ops->list);
106855 for_each_net(net)
106856 list_add_tail(&net->exit_list, &net_exit_list);
106857 ops_exit_list(ops, &net_exit_list);
106858 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
106859 mutex_lock(&net_mutex);
106860 error = register_pernet_operations(&pernet_list, ops);
106861 if (!error && (first_device == &pernet_list))
106862 - first_device = &ops->list;
106863 + first_device = (struct list_head *)&ops->list;
106864 mutex_unlock(&net_mutex);
106865 return error;
106866 }
106867 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
106868 index e33937f..b2b4981 100644
106869 --- a/net/core/netpoll.c
106870 +++ b/net/core/netpoll.c
106871 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
106872 struct udphdr *udph;
106873 struct iphdr *iph;
106874 struct ethhdr *eth;
106875 - static atomic_t ip_ident;
106876 + static atomic_unchecked_t ip_ident;
106877 struct ipv6hdr *ip6h;
106878
106879 udp_len = len + sizeof(*udph);
106880 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
106881 put_unaligned(0x45, (unsigned char *)iph);
106882 iph->tos = 0;
106883 put_unaligned(htons(ip_len), &(iph->tot_len));
106884 - iph->id = htons(atomic_inc_return(&ip_ident));
106885 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
106886 iph->frag_off = 0;
106887 iph->ttl = 64;
106888 iph->protocol = IPPROTO_UDP;
106889 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
106890 index fc17a9d..d4a3d88 100644
106891 --- a/net/core/pktgen.c
106892 +++ b/net/core/pktgen.c
106893 @@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
106894 pn->net = net;
106895 INIT_LIST_HEAD(&pn->pktgen_threads);
106896 pn->pktgen_exiting = false;
106897 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
106898 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
106899 if (!pn->proc_dir) {
106900 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
106901 return -ENODEV;
106902 diff --git a/net/core/ptp_classifier.c b/net/core/ptp_classifier.c
106903 deleted file mode 100644
106904 index d3027a7..0000000
106905 --- a/net/core/ptp_classifier.c
106906 +++ /dev/null
106907 @@ -1,141 +0,0 @@
106908 -/* PTP classifier
106909 - *
106910 - * This program is free software; you can redistribute it and/or
106911 - * modify it under the terms of version 2 of the GNU General Public
106912 - * License as published by the Free Software Foundation.
106913 - *
106914 - * This program is distributed in the hope that it will be useful, but
106915 - * WITHOUT ANY WARRANTY; without even the implied warranty of
106916 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
106917 - * General Public License for more details.
106918 - */
106919 -
106920 -/* The below program is the bpf_asm (tools/net/) representation of
106921 - * the opcode array in the ptp_filter structure.
106922 - *
106923 - * For convenience, this can easily be altered and reviewed with
106924 - * bpf_asm and bpf_dbg, e.g. `./bpf_asm -c prog` where prog is a
106925 - * simple file containing the below program:
106926 - *
106927 - * ldh [12] ; load ethertype
106928 - *
106929 - * ; PTP over UDP over IPv4 over Ethernet
106930 - * test_ipv4:
106931 - * jneq #0x800, test_ipv6 ; ETH_P_IP ?
106932 - * ldb [23] ; load proto
106933 - * jneq #17, drop_ipv4 ; IPPROTO_UDP ?
106934 - * ldh [20] ; load frag offset field
106935 - * jset #0x1fff, drop_ipv4 ; don't allow fragments
106936 - * ldxb 4*([14]&0xf) ; load IP header len
106937 - * ldh [x + 16] ; load UDP dst port
106938 - * jneq #319, drop_ipv4 ; is port PTP_EV_PORT ?
106939 - * ldh [x + 22] ; load payload
106940 - * and #0xf ; mask PTP_CLASS_VMASK
106941 - * or #0x10 ; PTP_CLASS_IPV4
106942 - * ret a ; return PTP class
106943 - * drop_ipv4: ret #0x0 ; PTP_CLASS_NONE
106944 - *
106945 - * ; PTP over UDP over IPv6 over Ethernet
106946 - * test_ipv6:
106947 - * jneq #0x86dd, test_8021q ; ETH_P_IPV6 ?
106948 - * ldb [20] ; load proto
106949 - * jneq #17, drop_ipv6 ; IPPROTO_UDP ?
106950 - * ldh [56] ; load UDP dst port
106951 - * jneq #319, drop_ipv6 ; is port PTP_EV_PORT ?
106952 - * ldh [62] ; load payload
106953 - * and #0xf ; mask PTP_CLASS_VMASK
106954 - * or #0x20 ; PTP_CLASS_IPV6
106955 - * ret a ; return PTP class
106956 - * drop_ipv6: ret #0x0 ; PTP_CLASS_NONE
106957 - *
106958 - * ; PTP over 802.1Q over Ethernet
106959 - * test_8021q:
106960 - * jneq #0x8100, test_ieee1588 ; ETH_P_8021Q ?
106961 - * ldh [16] ; load inner type
106962 - * jneq #0x88f7, drop_ieee1588 ; ETH_P_1588 ?
106963 - * ldb [18] ; load payload
106964 - * and #0x8 ; as we don't have ports here, test
106965 - * jneq #0x0, drop_ieee1588 ; for PTP_GEN_BIT and drop these
106966 - * ldh [18] ; reload payload
106967 - * and #0xf ; mask PTP_CLASS_VMASK
106968 - * or #0x40 ; PTP_CLASS_V2_VLAN
106969 - * ret a ; return PTP class
106970 - *
106971 - * ; PTP over Ethernet
106972 - * test_ieee1588:
106973 - * jneq #0x88f7, drop_ieee1588 ; ETH_P_1588 ?
106974 - * ldb [14] ; load payload
106975 - * and #0x8 ; as we don't have ports here, test
106976 - * jneq #0x0, drop_ieee1588 ; for PTP_GEN_BIT and drop these
106977 - * ldh [14] ; reload payload
106978 - * and #0xf ; mask PTP_CLASS_VMASK
106979 - * or #0x30 ; PTP_CLASS_L2
106980 - * ret a ; return PTP class
106981 - * drop_ieee1588: ret #0x0 ; PTP_CLASS_NONE
106982 - */
106983 -
106984 -#include <linux/skbuff.h>
106985 -#include <linux/filter.h>
106986 -#include <linux/ptp_classify.h>
106987 -
106988 -static struct sk_filter *ptp_insns __read_mostly;
106989 -
106990 -unsigned int ptp_classify_raw(const struct sk_buff *skb)
106991 -{
106992 - return SK_RUN_FILTER(ptp_insns, skb);
106993 -}
106994 -EXPORT_SYMBOL_GPL(ptp_classify_raw);
106995 -
106996 -void __init ptp_classifier_init(void)
106997 -{
106998 - static struct sock_filter ptp_filter[] __initdata = {
106999 - { 0x28, 0, 0, 0x0000000c },
107000 - { 0x15, 0, 12, 0x00000800 },
107001 - { 0x30, 0, 0, 0x00000017 },
107002 - { 0x15, 0, 9, 0x00000011 },
107003 - { 0x28, 0, 0, 0x00000014 },
107004 - { 0x45, 7, 0, 0x00001fff },
107005 - { 0xb1, 0, 0, 0x0000000e },
107006 - { 0x48, 0, 0, 0x00000010 },
107007 - { 0x15, 0, 4, 0x0000013f },
107008 - { 0x48, 0, 0, 0x00000016 },
107009 - { 0x54, 0, 0, 0x0000000f },
107010 - { 0x44, 0, 0, 0x00000010 },
107011 - { 0x16, 0, 0, 0x00000000 },
107012 - { 0x06, 0, 0, 0x00000000 },
107013 - { 0x15, 0, 9, 0x000086dd },
107014 - { 0x30, 0, 0, 0x00000014 },
107015 - { 0x15, 0, 6, 0x00000011 },
107016 - { 0x28, 0, 0, 0x00000038 },
107017 - { 0x15, 0, 4, 0x0000013f },
107018 - { 0x28, 0, 0, 0x0000003e },
107019 - { 0x54, 0, 0, 0x0000000f },
107020 - { 0x44, 0, 0, 0x00000020 },
107021 - { 0x16, 0, 0, 0x00000000 },
107022 - { 0x06, 0, 0, 0x00000000 },
107023 - { 0x15, 0, 9, 0x00008100 },
107024 - { 0x28, 0, 0, 0x00000010 },
107025 - { 0x15, 0, 15, 0x000088f7 },
107026 - { 0x30, 0, 0, 0x00000012 },
107027 - { 0x54, 0, 0, 0x00000008 },
107028 - { 0x15, 0, 12, 0x00000000 },
107029 - { 0x28, 0, 0, 0x00000012 },
107030 - { 0x54, 0, 0, 0x0000000f },
107031 - { 0x44, 0, 0, 0x00000040 },
107032 - { 0x16, 0, 0, 0x00000000 },
107033 - { 0x15, 0, 7, 0x000088f7 },
107034 - { 0x30, 0, 0, 0x0000000e },
107035 - { 0x54, 0, 0, 0x00000008 },
107036 - { 0x15, 0, 4, 0x00000000 },
107037 - { 0x28, 0, 0, 0x0000000e },
107038 - { 0x54, 0, 0, 0x0000000f },
107039 - { 0x44, 0, 0, 0x00000030 },
107040 - { 0x16, 0, 0, 0x00000000 },
107041 - { 0x06, 0, 0, 0x00000000 },
107042 - };
107043 - struct sock_fprog_kern ptp_prog = {
107044 - .len = ARRAY_SIZE(ptp_filter), .filter = ptp_filter,
107045 - };
107046 -
107047 - BUG_ON(sk_unattached_filter_create(&ptp_insns, &ptp_prog));
107048 -}
107049 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
107050 index 1063996..0729c19 100644
107051 --- a/net/core/rtnetlink.c
107052 +++ b/net/core/rtnetlink.c
107053 @@ -58,7 +58,7 @@ struct rtnl_link {
107054 rtnl_doit_func doit;
107055 rtnl_dumpit_func dumpit;
107056 rtnl_calcit_func calcit;
107057 -};
107058 +} __no_const;
107059
107060 static DEFINE_MUTEX(rtnl_mutex);
107061
107062 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
107063 if (rtnl_link_ops_get(ops->kind))
107064 return -EEXIST;
107065
107066 - if (!ops->dellink)
107067 - ops->dellink = unregister_netdevice_queue;
107068 + if (!ops->dellink) {
107069 + pax_open_kernel();
107070 + *(void **)&ops->dellink = unregister_netdevice_queue;
107071 + pax_close_kernel();
107072 + }
107073
107074 - list_add_tail(&ops->list, &link_ops);
107075 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
107076 return 0;
107077 }
107078 EXPORT_SYMBOL_GPL(__rtnl_link_register);
107079 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
107080 for_each_net(net) {
107081 __rtnl_kill_links(net, ops);
107082 }
107083 - list_del(&ops->list);
107084 + pax_list_del((struct list_head *)&ops->list);
107085 }
107086 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
107087
107088 @@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
107089 (dev->ifalias &&
107090 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
107091 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
107092 - atomic_read(&dev->carrier_changes)))
107093 + atomic_read_unchecked(&dev->carrier_changes)))
107094 goto nla_put_failure;
107095
107096 if (1) {
107097 diff --git a/net/core/scm.c b/net/core/scm.c
107098 index b442e7e..6f5b5a2 100644
107099 --- a/net/core/scm.c
107100 +++ b/net/core/scm.c
107101 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
107102 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
107103 {
107104 struct cmsghdr __user *cm
107105 - = (__force struct cmsghdr __user *)msg->msg_control;
107106 + = (struct cmsghdr __force_user *)msg->msg_control;
107107 struct cmsghdr cmhdr;
107108 int cmlen = CMSG_LEN(len);
107109 int err;
107110 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
107111 err = -EFAULT;
107112 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
107113 goto out;
107114 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
107115 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
107116 goto out;
107117 cmlen = CMSG_SPACE(len);
107118 if (msg->msg_controllen < cmlen)
107119 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
107120 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
107121 {
107122 struct cmsghdr __user *cm
107123 - = (__force struct cmsghdr __user*)msg->msg_control;
107124 + = (struct cmsghdr __force_user *)msg->msg_control;
107125
107126 int fdmax = 0;
107127 int fdnum = scm->fp->count;
107128 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
107129 if (fdnum < fdmax)
107130 fdmax = fdnum;
107131
107132 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
107133 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
107134 i++, cmfptr++)
107135 {
107136 struct socket *sock;
107137 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
107138 index 58ff88e..af9b458 100644
107139 --- a/net/core/skbuff.c
107140 +++ b/net/core/skbuff.c
107141 @@ -2010,7 +2010,7 @@ EXPORT_SYMBOL(__skb_checksum);
107142 __wsum skb_checksum(const struct sk_buff *skb, int offset,
107143 int len, __wsum csum)
107144 {
107145 - const struct skb_checksum_ops ops = {
107146 + static const struct skb_checksum_ops ops = {
107147 .update = csum_partial_ext,
107148 .combine = csum_block_add_ext,
107149 };
107150 @@ -3233,13 +3233,15 @@ void __init skb_init(void)
107151 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
107152 sizeof(struct sk_buff),
107153 0,
107154 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
107155 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
107156 + SLAB_NO_SANITIZE,
107157 NULL);
107158 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
107159 (2*sizeof(struct sk_buff)) +
107160 sizeof(atomic_t),
107161 0,
107162 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
107163 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
107164 + SLAB_NO_SANITIZE,
107165 NULL);
107166 }
107167
107168 diff --git a/net/core/sock.c b/net/core/sock.c
107169 index 026e01f..f54f908 100644
107170 --- a/net/core/sock.c
107171 +++ b/net/core/sock.c
107172 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
107173 struct sk_buff_head *list = &sk->sk_receive_queue;
107174
107175 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
107176 - atomic_inc(&sk->sk_drops);
107177 + atomic_inc_unchecked(&sk->sk_drops);
107178 trace_sock_rcvqueue_full(sk, skb);
107179 return -ENOMEM;
107180 }
107181 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
107182 return err;
107183
107184 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
107185 - atomic_inc(&sk->sk_drops);
107186 + atomic_inc_unchecked(&sk->sk_drops);
107187 return -ENOBUFS;
107188 }
107189
107190 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
107191 skb_dst_force(skb);
107192
107193 spin_lock_irqsave(&list->lock, flags);
107194 - skb->dropcount = atomic_read(&sk->sk_drops);
107195 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
107196 __skb_queue_tail(list, skb);
107197 spin_unlock_irqrestore(&list->lock, flags);
107198
107199 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
107200 skb->dev = NULL;
107201
107202 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
107203 - atomic_inc(&sk->sk_drops);
107204 + atomic_inc_unchecked(&sk->sk_drops);
107205 goto discard_and_relse;
107206 }
107207 if (nested)
107208 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
107209 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
107210 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
107211 bh_unlock_sock(sk);
107212 - atomic_inc(&sk->sk_drops);
107213 + atomic_inc_unchecked(&sk->sk_drops);
107214 goto discard_and_relse;
107215 }
107216
107217 @@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
107218 struct timeval tm;
107219 } v;
107220
107221 - int lv = sizeof(int);
107222 - int len;
107223 + unsigned int lv = sizeof(int);
107224 + unsigned int len;
107225
107226 if (get_user(len, optlen))
107227 return -EFAULT;
107228 - if (len < 0)
107229 + if (len > INT_MAX)
107230 return -EINVAL;
107231
107232 memset(&v, 0, sizeof(v));
107233 @@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
107234
107235 case SO_PEERNAME:
107236 {
107237 - char address[128];
107238 + char address[_K_SS_MAXSIZE];
107239
107240 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
107241 return -ENOTCONN;
107242 - if (lv < len)
107243 + if (lv < len || sizeof address < len)
107244 return -EINVAL;
107245 if (copy_to_user(optval, address, len))
107246 return -EFAULT;
107247 @@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
107248
107249 if (len > lv)
107250 len = lv;
107251 - if (copy_to_user(optval, &v, len))
107252 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
107253 return -EFAULT;
107254 lenout:
107255 if (put_user(len, optlen))
107256 @@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
107257 */
107258 smp_wmb();
107259 atomic_set(&sk->sk_refcnt, 1);
107260 - atomic_set(&sk->sk_drops, 0);
107261 + atomic_set_unchecked(&sk->sk_drops, 0);
107262 }
107263 EXPORT_SYMBOL(sock_init_data);
107264
107265 @@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
107266 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
107267 int level, int type)
107268 {
107269 + struct sock_extended_err ee;
107270 struct sock_exterr_skb *serr;
107271 struct sk_buff *skb, *skb2;
107272 int copied, err;
107273 @@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
107274 sock_recv_timestamp(msg, sk, skb);
107275
107276 serr = SKB_EXT_ERR(skb);
107277 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
107278 + ee = serr->ee;
107279 + put_cmsg(msg, level, type, sizeof ee, &ee);
107280
107281 msg->msg_flags |= MSG_ERRQUEUE;
107282 err = copied;
107283 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
107284 index a4216a4..773e3d7 100644
107285 --- a/net/core/sock_diag.c
107286 +++ b/net/core/sock_diag.c
107287 @@ -9,26 +9,33 @@
107288 #include <linux/inet_diag.h>
107289 #include <linux/sock_diag.h>
107290
107291 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
107292 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
107293 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
107294 static DEFINE_MUTEX(sock_diag_table_mutex);
107295
107296 int sock_diag_check_cookie(void *sk, __u32 *cookie)
107297 {
107298 +#ifndef CONFIG_GRKERNSEC_HIDESYM
107299 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
107300 cookie[1] != INET_DIAG_NOCOOKIE) &&
107301 ((u32)(unsigned long)sk != cookie[0] ||
107302 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
107303 return -ESTALE;
107304 else
107305 +#endif
107306 return 0;
107307 }
107308 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
107309
107310 void sock_diag_save_cookie(void *sk, __u32 *cookie)
107311 {
107312 +#ifdef CONFIG_GRKERNSEC_HIDESYM
107313 + cookie[0] = 0;
107314 + cookie[1] = 0;
107315 +#else
107316 cookie[0] = (u32)(unsigned long)sk;
107317 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
107318 +#endif
107319 }
107320 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
107321
107322 @@ -52,10 +59,9 @@ EXPORT_SYMBOL_GPL(sock_diag_put_meminfo);
107323 int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
107324 struct sk_buff *skb, int attrtype)
107325 {
107326 - struct sock_fprog_kern *fprog;
107327 - struct sk_filter *filter;
107328 struct nlattr *attr;
107329 - unsigned int flen;
107330 + struct sk_filter *filter;
107331 + unsigned int len;
107332 int err = 0;
107333
107334 if (!may_report_filterinfo) {
107335 @@ -64,20 +70,24 @@ int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
107336 }
107337
107338 rcu_read_lock();
107339 +
107340 filter = rcu_dereference(sk->sk_filter);
107341 - if (!filter)
107342 - goto out;
107343 + len = filter ? filter->len * sizeof(struct sock_filter) : 0;
107344
107345 - fprog = filter->orig_prog;
107346 - flen = sk_filter_proglen(fprog);
107347 -
107348 - attr = nla_reserve(skb, attrtype, flen);
107349 + attr = nla_reserve(skb, attrtype, len);
107350 if (attr == NULL) {
107351 err = -EMSGSIZE;
107352 goto out;
107353 }
107354
107355 - memcpy(nla_data(attr), fprog->filter, flen);
107356 + if (filter) {
107357 + struct sock_filter *fb = (struct sock_filter *)nla_data(attr);
107358 + int i;
107359 +
107360 + for (i = 0; i < filter->len; i++, fb++)
107361 + sk_decode_filter(&filter->insns[i], fb);
107362 + }
107363 +
107364 out:
107365 rcu_read_unlock();
107366 return err;
107367 @@ -110,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
107368 mutex_lock(&sock_diag_table_mutex);
107369 if (sock_diag_handlers[hndl->family])
107370 err = -EBUSY;
107371 - else
107372 + else {
107373 + pax_open_kernel();
107374 sock_diag_handlers[hndl->family] = hndl;
107375 + pax_close_kernel();
107376 + }
107377 mutex_unlock(&sock_diag_table_mutex);
107378
107379 return err;
107380 @@ -127,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
107381
107382 mutex_lock(&sock_diag_table_mutex);
107383 BUG_ON(sock_diag_handlers[family] != hnld);
107384 + pax_open_kernel();
107385 sock_diag_handlers[family] = NULL;
107386 + pax_close_kernel();
107387 mutex_unlock(&sock_diag_table_mutex);
107388 }
107389 EXPORT_SYMBOL_GPL(sock_diag_unregister);
107390 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
107391 index cf9cd13..8b56af3 100644
107392 --- a/net/core/sysctl_net_core.c
107393 +++ b/net/core/sysctl_net_core.c
107394 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
107395 {
107396 unsigned int orig_size, size;
107397 int ret, i;
107398 - struct ctl_table tmp = {
107399 + ctl_table_no_const tmp = {
107400 .data = &size,
107401 .maxlen = sizeof(size),
107402 .mode = table->mode
107403 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
107404 void __user *buffer, size_t *lenp, loff_t *ppos)
107405 {
107406 char id[IFNAMSIZ];
107407 - struct ctl_table tbl = {
107408 + ctl_table_no_const tbl = {
107409 .data = id,
107410 .maxlen = IFNAMSIZ,
107411 };
107412 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
107413
107414 static __net_init int sysctl_core_net_init(struct net *net)
107415 {
107416 - struct ctl_table *tbl;
107417 + ctl_table_no_const *tbl = NULL;
107418
107419 net->core.sysctl_somaxconn = SOMAXCONN;
107420
107421 - tbl = netns_core_table;
107422 if (!net_eq(net, &init_net)) {
107423 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
107424 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
107425 if (tbl == NULL)
107426 goto err_dup;
107427
107428 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
107429 if (net->user_ns != &init_user_ns) {
107430 tbl[0].procname = NULL;
107431 }
107432 - }
107433 -
107434 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
107435 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
107436 + } else
107437 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
107438 if (net->core.sysctl_hdr == NULL)
107439 goto err_reg;
107440
107441 return 0;
107442
107443 err_reg:
107444 - if (tbl != netns_core_table)
107445 - kfree(tbl);
107446 + kfree(tbl);
107447 err_dup:
107448 return -ENOMEM;
107449 }
107450 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
107451 kfree(tbl);
107452 }
107453
107454 -static __net_initdata struct pernet_operations sysctl_core_ops = {
107455 +static __net_initconst struct pernet_operations sysctl_core_ops = {
107456 .init = sysctl_core_net_init,
107457 .exit = sysctl_core_net_exit,
107458 };
107459 diff --git a/net/core/timestamping.c b/net/core/timestamping.c
107460 index 6521dfd..661b5a4 100644
107461 --- a/net/core/timestamping.c
107462 +++ b/net/core/timestamping.c
107463 @@ -23,11 +23,16 @@
107464 #include <linux/skbuff.h>
107465 #include <linux/export.h>
107466
107467 +static struct sock_filter ptp_filter[] = {
107468 + PTP_FILTER
107469 +};
107470 +
107471 static unsigned int classify(const struct sk_buff *skb)
107472 {
107473 - if (likely(skb->dev && skb->dev->phydev &&
107474 + if (likely(skb->dev &&
107475 + skb->dev->phydev &&
107476 skb->dev->phydev->drv))
107477 - return ptp_classify_raw(skb);
107478 + return sk_run_filter(skb, ptp_filter);
107479 else
107480 return PTP_CLASS_NONE;
107481 }
107482 @@ -55,13 +60,11 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
107483 if (likely(phydev->drv->txtstamp)) {
107484 if (!atomic_inc_not_zero(&sk->sk_refcnt))
107485 return;
107486 -
107487 clone = skb_clone(skb, GFP_ATOMIC);
107488 if (!clone) {
107489 sock_put(sk);
107490 return;
107491 }
107492 -
107493 clone->sk = sk;
107494 phydev->drv->txtstamp(phydev, clone, type);
107495 }
107496 @@ -86,15 +89,12 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
107497 }
107498
107499 *skb_hwtstamps(skb) = *hwtstamps;
107500 -
107501 serr = SKB_EXT_ERR(skb);
107502 memset(serr, 0, sizeof(*serr));
107503 serr->ee.ee_errno = ENOMSG;
107504 serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
107505 skb->sk = NULL;
107506 -
107507 err = sock_queue_err_skb(sk, skb);
107508 -
107509 sock_put(sk);
107510 if (err)
107511 kfree_skb(skb);
107512 @@ -132,3 +132,8 @@ bool skb_defer_rx_timestamp(struct sk_buff *skb)
107513 return false;
107514 }
107515 EXPORT_SYMBOL_GPL(skb_defer_rx_timestamp);
107516 +
107517 +void __init skb_timestamping_init(void)
107518 +{
107519 + BUG_ON(sk_chk_filter(ptp_filter, ARRAY_SIZE(ptp_filter)));
107520 +}
107521 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
107522 index ae011b4..d2d18bf 100644
107523 --- a/net/decnet/af_decnet.c
107524 +++ b/net/decnet/af_decnet.c
107525 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
107526 .sysctl_rmem = sysctl_decnet_rmem,
107527 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
107528 .obj_size = sizeof(struct dn_sock),
107529 + .slab_flags = SLAB_USERCOPY,
107530 };
107531
107532 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
107533 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
107534 index 3b726f3..1af6368 100644
107535 --- a/net/decnet/dn_dev.c
107536 +++ b/net/decnet/dn_dev.c
107537 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
107538 .extra1 = &min_t3,
107539 .extra2 = &max_t3
107540 },
107541 - {0}
107542 + { }
107543 },
107544 };
107545
107546 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
107547 index 5325b54..a0d4d69 100644
107548 --- a/net/decnet/sysctl_net_decnet.c
107549 +++ b/net/decnet/sysctl_net_decnet.c
107550 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
107551
107552 if (len > *lenp) len = *lenp;
107553
107554 - if (copy_to_user(buffer, addr, len))
107555 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
107556 return -EFAULT;
107557
107558 *lenp = len;
107559 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
107560
107561 if (len > *lenp) len = *lenp;
107562
107563 - if (copy_to_user(buffer, devname, len))
107564 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
107565 return -EFAULT;
107566
107567 *lenp = len;
107568 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
107569 index 6f1428c..9586b83 100644
107570 --- a/net/ieee802154/reassembly.c
107571 +++ b/net/ieee802154/reassembly.c
107572 @@ -438,14 +438,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
107573
107574 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
107575 {
107576 - struct ctl_table *table;
107577 + ctl_table_no_const *table = NULL;
107578 struct ctl_table_header *hdr;
107579 struct netns_ieee802154_lowpan *ieee802154_lowpan =
107580 net_ieee802154_lowpan(net);
107581
107582 - table = lowpan_frags_ns_ctl_table;
107583 if (!net_eq(net, &init_net)) {
107584 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
107585 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
107586 GFP_KERNEL);
107587 if (table == NULL)
107588 goto err_alloc;
107589 @@ -458,9 +457,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
107590 /* Don't export sysctls to unprivileged users */
107591 if (net->user_ns != &init_user_ns)
107592 table[0].procname = NULL;
107593 - }
107594 -
107595 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
107596 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
107597 + } else
107598 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
107599 if (hdr == NULL)
107600 goto err_reg;
107601
107602 @@ -468,8 +467,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
107603 return 0;
107604
107605 err_reg:
107606 - if (!net_eq(net, &init_net))
107607 - kfree(table);
107608 + kfree(table);
107609 err_alloc:
107610 return -ENOMEM;
107611 }
107612 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
107613 index e944937..368fe78 100644
107614 --- a/net/ipv4/devinet.c
107615 +++ b/net/ipv4/devinet.c
107616 @@ -1540,7 +1540,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
107617 idx = 0;
107618 head = &net->dev_index_head[h];
107619 rcu_read_lock();
107620 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
107621 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
107622 net->dev_base_seq;
107623 hlist_for_each_entry_rcu(dev, head, index_hlist) {
107624 if (idx < s_idx)
107625 @@ -1858,7 +1858,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
107626 idx = 0;
107627 head = &net->dev_index_head[h];
107628 rcu_read_lock();
107629 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
107630 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
107631 net->dev_base_seq;
107632 hlist_for_each_entry_rcu(dev, head, index_hlist) {
107633 if (idx < s_idx)
107634 @@ -2093,7 +2093,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
107635 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
107636 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
107637
107638 -static struct devinet_sysctl_table {
107639 +static const struct devinet_sysctl_table {
107640 struct ctl_table_header *sysctl_header;
107641 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
107642 } devinet_sysctl = {
107643 @@ -2215,7 +2215,7 @@ static __net_init int devinet_init_net(struct net *net)
107644 int err;
107645 struct ipv4_devconf *all, *dflt;
107646 #ifdef CONFIG_SYSCTL
107647 - struct ctl_table *tbl = ctl_forward_entry;
107648 + ctl_table_no_const *tbl = NULL;
107649 struct ctl_table_header *forw_hdr;
107650 #endif
107651
107652 @@ -2233,7 +2233,7 @@ static __net_init int devinet_init_net(struct net *net)
107653 goto err_alloc_dflt;
107654
107655 #ifdef CONFIG_SYSCTL
107656 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
107657 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
107658 if (tbl == NULL)
107659 goto err_alloc_ctl;
107660
107661 @@ -2253,7 +2253,10 @@ static __net_init int devinet_init_net(struct net *net)
107662 goto err_reg_dflt;
107663
107664 err = -ENOMEM;
107665 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
107666 + if (!net_eq(net, &init_net))
107667 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
107668 + else
107669 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
107670 if (forw_hdr == NULL)
107671 goto err_reg_ctl;
107672 net->ipv4.forw_hdr = forw_hdr;
107673 @@ -2269,8 +2272,7 @@ err_reg_ctl:
107674 err_reg_dflt:
107675 __devinet_sysctl_unregister(all);
107676 err_reg_all:
107677 - if (tbl != ctl_forward_entry)
107678 - kfree(tbl);
107679 + kfree(tbl);
107680 err_alloc_ctl:
107681 #endif
107682 if (dflt != &ipv4_devconf_dflt)
107683 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
107684 index 255aa99..45c78f8 100644
107685 --- a/net/ipv4/fib_frontend.c
107686 +++ b/net/ipv4/fib_frontend.c
107687 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
107688 #ifdef CONFIG_IP_ROUTE_MULTIPATH
107689 fib_sync_up(dev);
107690 #endif
107691 - atomic_inc(&net->ipv4.dev_addr_genid);
107692 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
107693 rt_cache_flush(dev_net(dev));
107694 break;
107695 case NETDEV_DOWN:
107696 fib_del_ifaddr(ifa, NULL);
107697 - atomic_inc(&net->ipv4.dev_addr_genid);
107698 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
107699 if (ifa->ifa_dev->ifa_list == NULL) {
107700 /* Last address was deleted from this interface.
107701 * Disable IP.
107702 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
107703 #ifdef CONFIG_IP_ROUTE_MULTIPATH
107704 fib_sync_up(dev);
107705 #endif
107706 - atomic_inc(&net->ipv4.dev_addr_genid);
107707 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
107708 rt_cache_flush(net);
107709 break;
107710 case NETDEV_DOWN:
107711 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
107712 index b10cd43a..22327f9 100644
107713 --- a/net/ipv4/fib_semantics.c
107714 +++ b/net/ipv4/fib_semantics.c
107715 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
107716 nh->nh_saddr = inet_select_addr(nh->nh_dev,
107717 nh->nh_gw,
107718 nh->nh_parent->fib_scope);
107719 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
107720 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
107721
107722 return nh->nh_saddr;
107723 }
107724 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
107725 index 43116e8..e3e6159 100644
107726 --- a/net/ipv4/inet_hashtables.c
107727 +++ b/net/ipv4/inet_hashtables.c
107728 @@ -18,6 +18,7 @@
107729 #include <linux/sched.h>
107730 #include <linux/slab.h>
107731 #include <linux/wait.h>
107732 +#include <linux/security.h>
107733
107734 #include <net/inet_connection_sock.h>
107735 #include <net/inet_hashtables.h>
107736 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
107737 return inet_ehashfn(net, laddr, lport, faddr, fport);
107738 }
107739
107740 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
107741 +
107742 /*
107743 * Allocate and initialize a new local port bind bucket.
107744 * The bindhash mutex for snum's hash chain must be held here.
107745 @@ -554,6 +557,8 @@ ok:
107746 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
107747 spin_unlock(&head->lock);
107748
107749 + gr_update_task_in_ip_table(current, inet_sk(sk));
107750 +
107751 if (tw) {
107752 inet_twsk_deschedule(tw, death_row);
107753 while (twrefcnt) {
107754 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
107755 index bd5f592..e80e605 100644
107756 --- a/net/ipv4/inetpeer.c
107757 +++ b/net/ipv4/inetpeer.c
107758 @@ -482,7 +482,7 @@ relookup:
107759 if (p) {
107760 p->daddr = *daddr;
107761 atomic_set(&p->refcnt, 1);
107762 - atomic_set(&p->rid, 0);
107763 + atomic_set_unchecked(&p->rid, 0);
107764 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
107765 p->rate_tokens = 0;
107766 /* 60*HZ is arbitrary, but chosen enough high so that the first
107767 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
107768 index ed32313..3762abe 100644
107769 --- a/net/ipv4/ip_fragment.c
107770 +++ b/net/ipv4/ip_fragment.c
107771 @@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
107772 return 0;
107773
107774 start = qp->rid;
107775 - end = atomic_inc_return(&peer->rid);
107776 + end = atomic_inc_return_unchecked(&peer->rid);
107777 qp->rid = end;
107778
107779 rc = qp->q.fragments && (end - start) > max;
107780 @@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
107781
107782 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
107783 {
107784 - struct ctl_table *table;
107785 + ctl_table_no_const *table = NULL;
107786 struct ctl_table_header *hdr;
107787
107788 - table = ip4_frags_ns_ctl_table;
107789 if (!net_eq(net, &init_net)) {
107790 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
107791 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
107792 if (table == NULL)
107793 goto err_alloc;
107794
107795 @@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
107796 /* Don't export sysctls to unprivileged users */
107797 if (net->user_ns != &init_user_ns)
107798 table[0].procname = NULL;
107799 - }
107800 + hdr = register_net_sysctl(net, "net/ipv4", table);
107801 + } else
107802 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
107803
107804 - hdr = register_net_sysctl(net, "net/ipv4", table);
107805 if (hdr == NULL)
107806 goto err_reg;
107807
107808 @@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
107809 return 0;
107810
107811 err_reg:
107812 - if (!net_eq(net, &init_net))
107813 - kfree(table);
107814 + kfree(table);
107815 err_alloc:
107816 return -ENOMEM;
107817 }
107818 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
107819 index 9b84254..c776611 100644
107820 --- a/net/ipv4/ip_gre.c
107821 +++ b/net/ipv4/ip_gre.c
107822 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
107823 module_param(log_ecn_error, bool, 0644);
107824 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
107825
107826 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
107827 +static struct rtnl_link_ops ipgre_link_ops;
107828 static int ipgre_tunnel_init(struct net_device *dev);
107829
107830 static int ipgre_net_id __read_mostly;
107831 @@ -733,7 +733,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
107832 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
107833 };
107834
107835 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
107836 +static struct rtnl_link_ops ipgre_link_ops = {
107837 .kind = "gre",
107838 .maxtype = IFLA_GRE_MAX,
107839 .policy = ipgre_policy,
107840 @@ -747,7 +747,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
107841 .fill_info = ipgre_fill_info,
107842 };
107843
107844 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
107845 +static struct rtnl_link_ops ipgre_tap_ops = {
107846 .kind = "gretap",
107847 .maxtype = IFLA_GRE_MAX,
107848 .policy = ipgre_policy,
107849 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
107850 index 64741b9..6f334a2 100644
107851 --- a/net/ipv4/ip_sockglue.c
107852 +++ b/net/ipv4/ip_sockglue.c
107853 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
107854 len = min_t(unsigned int, len, opt->optlen);
107855 if (put_user(len, optlen))
107856 return -EFAULT;
107857 - if (copy_to_user(optval, opt->__data, len))
107858 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
107859 + copy_to_user(optval, opt->__data, len))
107860 return -EFAULT;
107861 return 0;
107862 }
107863 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
107864 if (sk->sk_type != SOCK_STREAM)
107865 return -ENOPROTOOPT;
107866
107867 - msg.msg_control = optval;
107868 + msg.msg_control = (void __force_kernel *)optval;
107869 msg.msg_controllen = len;
107870 msg.msg_flags = flags;
107871
107872 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
107873 index b8960f3..0f025db 100644
107874 --- a/net/ipv4/ip_vti.c
107875 +++ b/net/ipv4/ip_vti.c
107876 @@ -45,7 +45,7 @@
107877 #include <net/net_namespace.h>
107878 #include <net/netns/generic.h>
107879
107880 -static struct rtnl_link_ops vti_link_ops __read_mostly;
107881 +static struct rtnl_link_ops vti_link_ops;
107882
107883 static int vti_net_id __read_mostly;
107884 static int vti_tunnel_init(struct net_device *dev);
107885 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
107886 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
107887 };
107888
107889 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
107890 +static struct rtnl_link_ops vti_link_ops = {
107891 .kind = "vti",
107892 .maxtype = IFLA_VTI_MAX,
107893 .policy = vti_policy,
107894 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
107895 index b3e86ea..18ce98c 100644
107896 --- a/net/ipv4/ipconfig.c
107897 +++ b/net/ipv4/ipconfig.c
107898 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
107899
107900 mm_segment_t oldfs = get_fs();
107901 set_fs(get_ds());
107902 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
107903 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
107904 set_fs(oldfs);
107905 return res;
107906 }
107907 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
107908
107909 mm_segment_t oldfs = get_fs();
107910 set_fs(get_ds());
107911 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
107912 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
107913 set_fs(oldfs);
107914 return res;
107915 }
107916 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
107917
107918 mm_segment_t oldfs = get_fs();
107919 set_fs(get_ds());
107920 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
107921 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
107922 set_fs(oldfs);
107923 return res;
107924 }
107925 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
107926 index 62eaa00..29b2dc2 100644
107927 --- a/net/ipv4/ipip.c
107928 +++ b/net/ipv4/ipip.c
107929 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
107930 static int ipip_net_id __read_mostly;
107931
107932 static int ipip_tunnel_init(struct net_device *dev);
107933 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
107934 +static struct rtnl_link_ops ipip_link_ops;
107935
107936 static int ipip_err(struct sk_buff *skb, u32 info)
107937 {
107938 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
107939 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
107940 };
107941
107942 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
107943 +static struct rtnl_link_ops ipip_link_ops = {
107944 .kind = "ipip",
107945 .maxtype = IFLA_IPTUN_MAX,
107946 .policy = ipip_policy,
107947 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
107948 index f95b6f9..2ee2097 100644
107949 --- a/net/ipv4/netfilter/arp_tables.c
107950 +++ b/net/ipv4/netfilter/arp_tables.c
107951 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
107952 #endif
107953
107954 static int get_info(struct net *net, void __user *user,
107955 - const int *len, int compat)
107956 + int len, int compat)
107957 {
107958 char name[XT_TABLE_MAXNAMELEN];
107959 struct xt_table *t;
107960 int ret;
107961
107962 - if (*len != sizeof(struct arpt_getinfo)) {
107963 - duprintf("length %u != %Zu\n", *len,
107964 + if (len != sizeof(struct arpt_getinfo)) {
107965 + duprintf("length %u != %Zu\n", len,
107966 sizeof(struct arpt_getinfo));
107967 return -EINVAL;
107968 }
107969 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
107970 info.size = private->size;
107971 strcpy(info.name, name);
107972
107973 - if (copy_to_user(user, &info, *len) != 0)
107974 + if (copy_to_user(user, &info, len) != 0)
107975 ret = -EFAULT;
107976 else
107977 ret = 0;
107978 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
107979
107980 switch (cmd) {
107981 case ARPT_SO_GET_INFO:
107982 - ret = get_info(sock_net(sk), user, len, 1);
107983 + ret = get_info(sock_net(sk), user, *len, 1);
107984 break;
107985 case ARPT_SO_GET_ENTRIES:
107986 ret = compat_get_entries(sock_net(sk), user, len);
107987 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
107988
107989 switch (cmd) {
107990 case ARPT_SO_GET_INFO:
107991 - ret = get_info(sock_net(sk), user, len, 0);
107992 + ret = get_info(sock_net(sk), user, *len, 0);
107993 break;
107994
107995 case ARPT_SO_GET_ENTRIES:
107996 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
107997 index 99e810f..3711b81 100644
107998 --- a/net/ipv4/netfilter/ip_tables.c
107999 +++ b/net/ipv4/netfilter/ip_tables.c
108000 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
108001 #endif
108002
108003 static int get_info(struct net *net, void __user *user,
108004 - const int *len, int compat)
108005 + int len, int compat)
108006 {
108007 char name[XT_TABLE_MAXNAMELEN];
108008 struct xt_table *t;
108009 int ret;
108010
108011 - if (*len != sizeof(struct ipt_getinfo)) {
108012 - duprintf("length %u != %zu\n", *len,
108013 + if (len != sizeof(struct ipt_getinfo)) {
108014 + duprintf("length %u != %zu\n", len,
108015 sizeof(struct ipt_getinfo));
108016 return -EINVAL;
108017 }
108018 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
108019 info.size = private->size;
108020 strcpy(info.name, name);
108021
108022 - if (copy_to_user(user, &info, *len) != 0)
108023 + if (copy_to_user(user, &info, len) != 0)
108024 ret = -EFAULT;
108025 else
108026 ret = 0;
108027 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
108028
108029 switch (cmd) {
108030 case IPT_SO_GET_INFO:
108031 - ret = get_info(sock_net(sk), user, len, 1);
108032 + ret = get_info(sock_net(sk), user, *len, 1);
108033 break;
108034 case IPT_SO_GET_ENTRIES:
108035 ret = compat_get_entries(sock_net(sk), user, len);
108036 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
108037
108038 switch (cmd) {
108039 case IPT_SO_GET_INFO:
108040 - ret = get_info(sock_net(sk), user, len, 0);
108041 + ret = get_info(sock_net(sk), user, *len, 0);
108042 break;
108043
108044 case IPT_SO_GET_ENTRIES:
108045 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
108046 index 2510c02..cfb34fa 100644
108047 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
108048 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
108049 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
108050 spin_lock_init(&cn->lock);
108051
108052 #ifdef CONFIG_PROC_FS
108053 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
108054 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
108055 if (!cn->procdir) {
108056 pr_err("Unable to proc dir entry\n");
108057 return -ENOMEM;
108058 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
108059 index 044a0dd..3399751 100644
108060 --- a/net/ipv4/ping.c
108061 +++ b/net/ipv4/ping.c
108062 @@ -59,7 +59,7 @@ struct ping_table {
108063 };
108064
108065 static struct ping_table ping_table;
108066 -struct pingv6_ops pingv6_ops;
108067 +struct pingv6_ops *pingv6_ops;
108068 EXPORT_SYMBOL_GPL(pingv6_ops);
108069
108070 static u16 ping_port_rover;
108071 @@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
108072 return -ENODEV;
108073 }
108074 }
108075 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
108076 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
108077 scoped);
108078 rcu_read_unlock();
108079
108080 @@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
108081 }
108082 #if IS_ENABLED(CONFIG_IPV6)
108083 } else if (skb->protocol == htons(ETH_P_IPV6)) {
108084 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
108085 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
108086 #endif
108087 }
108088
108089 @@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
108090 info, (u8 *)icmph);
108091 #if IS_ENABLED(CONFIG_IPV6)
108092 } else if (family == AF_INET6) {
108093 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
108094 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
108095 info, (u8 *)icmph);
108096 #endif
108097 }
108098 @@ -858,7 +858,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
108099 return ip_recv_error(sk, msg, len, addr_len);
108100 #if IS_ENABLED(CONFIG_IPV6)
108101 } else if (family == AF_INET6) {
108102 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
108103 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
108104 addr_len);
108105 #endif
108106 }
108107 @@ -916,10 +916,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
108108 }
108109
108110 if (inet6_sk(sk)->rxopt.all)
108111 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
108112 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
108113 if (skb->protocol == htons(ETH_P_IPV6) &&
108114 inet6_sk(sk)->rxopt.all)
108115 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
108116 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
108117 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
108118 ip_cmsg_recv(msg, skb);
108119 #endif
108120 @@ -1111,7 +1111,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
108121 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
108122 0, sock_i_ino(sp),
108123 atomic_read(&sp->sk_refcnt), sp,
108124 - atomic_read(&sp->sk_drops));
108125 + atomic_read_unchecked(&sp->sk_drops));
108126 }
108127
108128 static int ping_v4_seq_show(struct seq_file *seq, void *v)
108129 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
108130 index 2c65160..213ecdf 100644
108131 --- a/net/ipv4/raw.c
108132 +++ b/net/ipv4/raw.c
108133 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
108134 int raw_rcv(struct sock *sk, struct sk_buff *skb)
108135 {
108136 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
108137 - atomic_inc(&sk->sk_drops);
108138 + atomic_inc_unchecked(&sk->sk_drops);
108139 kfree_skb(skb);
108140 return NET_RX_DROP;
108141 }
108142 @@ -748,16 +748,20 @@ static int raw_init(struct sock *sk)
108143
108144 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
108145 {
108146 + struct icmp_filter filter;
108147 +
108148 if (optlen > sizeof(struct icmp_filter))
108149 optlen = sizeof(struct icmp_filter);
108150 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
108151 + if (copy_from_user(&filter, optval, optlen))
108152 return -EFAULT;
108153 + raw_sk(sk)->filter = filter;
108154 return 0;
108155 }
108156
108157 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
108158 {
108159 int len, ret = -EFAULT;
108160 + struct icmp_filter filter;
108161
108162 if (get_user(len, optlen))
108163 goto out;
108164 @@ -767,8 +771,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
108165 if (len > sizeof(struct icmp_filter))
108166 len = sizeof(struct icmp_filter);
108167 ret = -EFAULT;
108168 - if (put_user(len, optlen) ||
108169 - copy_to_user(optval, &raw_sk(sk)->filter, len))
108170 + filter = raw_sk(sk)->filter;
108171 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
108172 goto out;
108173 ret = 0;
108174 out: return ret;
108175 @@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
108176 0, 0L, 0,
108177 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
108178 0, sock_i_ino(sp),
108179 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
108180 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
108181 }
108182
108183 static int raw_seq_show(struct seq_file *seq, void *v)
108184 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
108185 index 1901998..a9a850a 100644
108186 --- a/net/ipv4/route.c
108187 +++ b/net/ipv4/route.c
108188 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
108189
108190 static int rt_cache_seq_open(struct inode *inode, struct file *file)
108191 {
108192 - return seq_open(file, &rt_cache_seq_ops);
108193 + return seq_open_restrict(file, &rt_cache_seq_ops);
108194 }
108195
108196 static const struct file_operations rt_cache_seq_fops = {
108197 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
108198
108199 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
108200 {
108201 - return seq_open(file, &rt_cpu_seq_ops);
108202 + return seq_open_restrict(file, &rt_cpu_seq_ops);
108203 }
108204
108205 static const struct file_operations rt_cpu_seq_fops = {
108206 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
108207
108208 static int rt_acct_proc_open(struct inode *inode, struct file *file)
108209 {
108210 - return single_open(file, rt_acct_proc_show, NULL);
108211 + return single_open_restrict(file, rt_acct_proc_show, NULL);
108212 }
108213
108214 static const struct file_operations rt_acct_proc_fops = {
108215 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
108216
108217 #define IP_IDENTS_SZ 2048u
108218 struct ip_ident_bucket {
108219 - atomic_t id;
108220 + atomic_unchecked_t id;
108221 u32 stamp32;
108222 };
108223
108224 -static struct ip_ident_bucket *ip_idents __read_mostly;
108225 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
108226
108227 /* In order to protect privacy, we add a perturbation to identifiers
108228 * if one generator is seldom used. This makes hard for an attacker
108229 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
108230 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
108231 delta = prandom_u32_max(now - old);
108232
108233 - return atomic_add_return(segs + delta, &bucket->id) - segs;
108234 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
108235 }
108236 EXPORT_SYMBOL(ip_idents_reserve);
108237
108238 @@ -2625,34 +2625,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
108239 .maxlen = sizeof(int),
108240 .mode = 0200,
108241 .proc_handler = ipv4_sysctl_rtcache_flush,
108242 + .extra1 = &init_net,
108243 },
108244 { },
108245 };
108246
108247 static __net_init int sysctl_route_net_init(struct net *net)
108248 {
108249 - struct ctl_table *tbl;
108250 + ctl_table_no_const *tbl = NULL;
108251
108252 - tbl = ipv4_route_flush_table;
108253 if (!net_eq(net, &init_net)) {
108254 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
108255 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
108256 if (tbl == NULL)
108257 goto err_dup;
108258
108259 /* Don't export sysctls to unprivileged users */
108260 if (net->user_ns != &init_user_ns)
108261 tbl[0].procname = NULL;
108262 - }
108263 - tbl[0].extra1 = net;
108264 + tbl[0].extra1 = net;
108265 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
108266 + } else
108267 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
108268
108269 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
108270 if (net->ipv4.route_hdr == NULL)
108271 goto err_reg;
108272 return 0;
108273
108274 err_reg:
108275 - if (tbl != ipv4_route_flush_table)
108276 - kfree(tbl);
108277 + kfree(tbl);
108278 err_dup:
108279 return -ENOMEM;
108280 }
108281 @@ -2675,8 +2675,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
108282
108283 static __net_init int rt_genid_init(struct net *net)
108284 {
108285 - atomic_set(&net->ipv4.rt_genid, 0);
108286 - atomic_set(&net->fnhe_genid, 0);
108287 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
108288 + atomic_set_unchecked(&net->fnhe_genid, 0);
108289 get_random_bytes(&net->ipv4.dev_addr_genid,
108290 sizeof(net->ipv4.dev_addr_genid));
108291 return 0;
108292 @@ -2719,11 +2719,7 @@ int __init ip_rt_init(void)
108293 {
108294 int rc = 0;
108295
108296 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
108297 - if (!ip_idents)
108298 - panic("IP: failed to allocate ip_idents\n");
108299 -
108300 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
108301 + prandom_bytes(ip_idents, sizeof(ip_idents));
108302
108303 #ifdef CONFIG_IP_ROUTE_CLASSID
108304 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
108305 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
108306 index 79a007c..5023029 100644
108307 --- a/net/ipv4/sysctl_net_ipv4.c
108308 +++ b/net/ipv4/sysctl_net_ipv4.c
108309 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
108310 container_of(table->data, struct net, ipv4.ip_local_ports.range);
108311 int ret;
108312 int range[2];
108313 - struct ctl_table tmp = {
108314 + ctl_table_no_const tmp = {
108315 .data = &range,
108316 .maxlen = sizeof(range),
108317 .mode = table->mode,
108318 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
108319 int ret;
108320 gid_t urange[2];
108321 kgid_t low, high;
108322 - struct ctl_table tmp = {
108323 + ctl_table_no_const tmp = {
108324 .data = &urange,
108325 .maxlen = sizeof(urange),
108326 .mode = table->mode,
108327 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
108328 void __user *buffer, size_t *lenp, loff_t *ppos)
108329 {
108330 char val[TCP_CA_NAME_MAX];
108331 - struct ctl_table tbl = {
108332 + ctl_table_no_const tbl = {
108333 .data = val,
108334 .maxlen = TCP_CA_NAME_MAX,
108335 };
108336 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
108337 void __user *buffer, size_t *lenp,
108338 loff_t *ppos)
108339 {
108340 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
108341 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
108342 int ret;
108343
108344 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
108345 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
108346 void __user *buffer, size_t *lenp,
108347 loff_t *ppos)
108348 {
108349 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
108350 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
108351 int ret;
108352
108353 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
108354 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
108355 void __user *buffer, size_t *lenp,
108356 loff_t *ppos)
108357 {
108358 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
108359 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
108360 struct tcp_fastopen_context *ctxt;
108361 int ret;
108362 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
108363 @@ -857,13 +857,12 @@ static struct ctl_table ipv4_net_table[] = {
108364
108365 static __net_init int ipv4_sysctl_init_net(struct net *net)
108366 {
108367 - struct ctl_table *table;
108368 + ctl_table_no_const *table = NULL;
108369
108370 - table = ipv4_net_table;
108371 if (!net_eq(net, &init_net)) {
108372 int i;
108373
108374 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
108375 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
108376 if (table == NULL)
108377 goto err_alloc;
108378
108379 @@ -872,7 +871,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
108380 table[i].data += (void *)net - (void *)&init_net;
108381 }
108382
108383 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
108384 + if (!net_eq(net, &init_net))
108385 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
108386 + else
108387 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
108388 if (net->ipv4.ipv4_hdr == NULL)
108389 goto err_reg;
108390
108391 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
108392 index 40639c2..dfc86b2 100644
108393 --- a/net/ipv4/tcp_input.c
108394 +++ b/net/ipv4/tcp_input.c
108395 @@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
108396 * without any lock. We want to make sure compiler wont store
108397 * intermediate values in this location.
108398 */
108399 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
108400 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
108401 sk->sk_max_pacing_rate);
108402 }
108403
108404 @@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
108405 * simplifies code)
108406 */
108407 static void
108408 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
108409 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
108410 struct sk_buff *head, struct sk_buff *tail,
108411 u32 start, u32 end)
108412 {
108413 @@ -5536,6 +5536,7 @@ discard:
108414 tcp_paws_reject(&tp->rx_opt, 0))
108415 goto discard_and_undo;
108416
108417 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
108418 if (th->syn) {
108419 /* We see SYN without ACK. It is attempt of
108420 * simultaneous connect with crossed SYNs.
108421 @@ -5586,6 +5587,7 @@ discard:
108422 goto discard;
108423 #endif
108424 }
108425 +#endif
108426 /* "fifth, if neither of the SYN or RST bits is set then
108427 * drop the segment and return."
108428 */
108429 @@ -5632,7 +5634,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
108430 goto discard;
108431
108432 if (th->syn) {
108433 - if (th->fin)
108434 + if (th->fin || th->urg || th->psh)
108435 goto discard;
108436 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
108437 return 1;
108438 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
108439 index 77cccda..10122c4 100644
108440 --- a/net/ipv4/tcp_ipv4.c
108441 +++ b/net/ipv4/tcp_ipv4.c
108442 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
108443 EXPORT_SYMBOL(sysctl_tcp_low_latency);
108444
108445
108446 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108447 +extern int grsec_enable_blackhole;
108448 +#endif
108449 +
108450 #ifdef CONFIG_TCP_MD5SIG
108451 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
108452 __be32 daddr, __be32 saddr, const struct tcphdr *th);
108453 @@ -1591,6 +1595,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
108454 return 0;
108455
108456 reset:
108457 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108458 + if (!grsec_enable_blackhole)
108459 +#endif
108460 tcp_v4_send_reset(rsk, skb);
108461 discard:
108462 kfree_skb(skb);
108463 @@ -1737,12 +1744,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
108464 TCP_SKB_CB(skb)->sacked = 0;
108465
108466 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
108467 - if (!sk)
108468 + if (!sk) {
108469 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108470 + ret = 1;
108471 +#endif
108472 goto no_tcp_socket;
108473 -
108474 + }
108475 process:
108476 - if (sk->sk_state == TCP_TIME_WAIT)
108477 + if (sk->sk_state == TCP_TIME_WAIT) {
108478 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108479 + ret = 2;
108480 +#endif
108481 goto do_time_wait;
108482 + }
108483
108484 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
108485 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
108486 @@ -1796,6 +1810,10 @@ csum_error:
108487 bad_packet:
108488 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
108489 } else {
108490 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108491 + if (!grsec_enable_blackhole || (ret == 1 &&
108492 + (skb->dev->flags & IFF_LOOPBACK)))
108493 +#endif
108494 tcp_v4_send_reset(NULL, skb);
108495 }
108496
108497 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
108498 index e68e0d4..0334263 100644
108499 --- a/net/ipv4/tcp_minisocks.c
108500 +++ b/net/ipv4/tcp_minisocks.c
108501 @@ -27,6 +27,10 @@
108502 #include <net/inet_common.h>
108503 #include <net/xfrm.h>
108504
108505 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108506 +extern int grsec_enable_blackhole;
108507 +#endif
108508 +
108509 int sysctl_tcp_syncookies __read_mostly = 1;
108510 EXPORT_SYMBOL(sysctl_tcp_syncookies);
108511
108512 @@ -740,7 +744,10 @@ embryonic_reset:
108513 * avoid becoming vulnerable to outside attack aiming at
108514 * resetting legit local connections.
108515 */
108516 - req->rsk_ops->send_reset(sk, skb);
108517 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108518 + if (!grsec_enable_blackhole)
108519 +#endif
108520 + req->rsk_ops->send_reset(sk, skb);
108521 } else if (fastopen) { /* received a valid RST pkt */
108522 reqsk_fastopen_remove(sk, req, true);
108523 tcp_reset(sk);
108524 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
108525 index 3b66610..bfbe23a 100644
108526 --- a/net/ipv4/tcp_probe.c
108527 +++ b/net/ipv4/tcp_probe.c
108528 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
108529 if (cnt + width >= len)
108530 break;
108531
108532 - if (copy_to_user(buf + cnt, tbuf, width))
108533 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
108534 return -EFAULT;
108535 cnt += width;
108536 }
108537 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
108538 index 286227a..c495a76 100644
108539 --- a/net/ipv4/tcp_timer.c
108540 +++ b/net/ipv4/tcp_timer.c
108541 @@ -22,6 +22,10 @@
108542 #include <linux/gfp.h>
108543 #include <net/tcp.h>
108544
108545 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108546 +extern int grsec_lastack_retries;
108547 +#endif
108548 +
108549 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
108550 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
108551 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
108552 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
108553 }
108554 }
108555
108556 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108557 + if ((sk->sk_state == TCP_LAST_ACK) &&
108558 + (grsec_lastack_retries > 0) &&
108559 + (grsec_lastack_retries < retry_until))
108560 + retry_until = grsec_lastack_retries;
108561 +#endif
108562 +
108563 if (retransmits_timed_out(sk, retry_until,
108564 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
108565 /* Has it gone just too far? */
108566 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
108567 index 7d5a866..4874211 100644
108568 --- a/net/ipv4/udp.c
108569 +++ b/net/ipv4/udp.c
108570 @@ -87,6 +87,7 @@
108571 #include <linux/types.h>
108572 #include <linux/fcntl.h>
108573 #include <linux/module.h>
108574 +#include <linux/security.h>
108575 #include <linux/socket.h>
108576 #include <linux/sockios.h>
108577 #include <linux/igmp.h>
108578 @@ -113,6 +114,10 @@
108579 #include <net/busy_poll.h>
108580 #include "udp_impl.h"
108581
108582 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108583 +extern int grsec_enable_blackhole;
108584 +#endif
108585 +
108586 struct udp_table udp_table __read_mostly;
108587 EXPORT_SYMBOL(udp_table);
108588
108589 @@ -615,6 +620,9 @@ found:
108590 return s;
108591 }
108592
108593 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
108594 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
108595 +
108596 /*
108597 * This routine is called by the ICMP module when it gets some
108598 * sort of error condition. If err < 0 then the socket should
108599 @@ -952,9 +960,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
108600 dport = usin->sin_port;
108601 if (dport == 0)
108602 return -EINVAL;
108603 +
108604 + err = gr_search_udp_sendmsg(sk, usin);
108605 + if (err)
108606 + return err;
108607 } else {
108608 if (sk->sk_state != TCP_ESTABLISHED)
108609 return -EDESTADDRREQ;
108610 +
108611 + err = gr_search_udp_sendmsg(sk, NULL);
108612 + if (err)
108613 + return err;
108614 +
108615 daddr = inet->inet_daddr;
108616 dport = inet->inet_dport;
108617 /* Open fast path for connected socket.
108618 @@ -1202,7 +1219,7 @@ static unsigned int first_packet_length(struct sock *sk)
108619 IS_UDPLITE(sk));
108620 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
108621 IS_UDPLITE(sk));
108622 - atomic_inc(&sk->sk_drops);
108623 + atomic_inc_unchecked(&sk->sk_drops);
108624 __skb_unlink(skb, rcvq);
108625 __skb_queue_tail(&list_kill, skb);
108626 }
108627 @@ -1282,6 +1299,10 @@ try_again:
108628 if (!skb)
108629 goto out;
108630
108631 + err = gr_search_udp_recvmsg(sk, skb);
108632 + if (err)
108633 + goto out_free;
108634 +
108635 ulen = skb->len - sizeof(struct udphdr);
108636 copied = len;
108637 if (copied > ulen)
108638 @@ -1315,7 +1336,7 @@ try_again:
108639 if (unlikely(err)) {
108640 trace_kfree_skb(skb, udp_recvmsg);
108641 if (!peeked) {
108642 - atomic_inc(&sk->sk_drops);
108643 + atomic_inc_unchecked(&sk->sk_drops);
108644 UDP_INC_STATS_USER(sock_net(sk),
108645 UDP_MIB_INERRORS, is_udplite);
108646 }
108647 @@ -1612,7 +1633,7 @@ csum_error:
108648 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
108649 drop:
108650 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
108651 - atomic_inc(&sk->sk_drops);
108652 + atomic_inc_unchecked(&sk->sk_drops);
108653 kfree_skb(skb);
108654 return -1;
108655 }
108656 @@ -1631,7 +1652,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
108657 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
108658
108659 if (!skb1) {
108660 - atomic_inc(&sk->sk_drops);
108661 + atomic_inc_unchecked(&sk->sk_drops);
108662 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
108663 IS_UDPLITE(sk));
108664 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
108665 @@ -1817,6 +1838,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
108666 goto csum_error;
108667
108668 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
108669 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108670 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
108671 +#endif
108672 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
108673
108674 /*
108675 @@ -2403,7 +2427,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
108676 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
108677 0, sock_i_ino(sp),
108678 atomic_read(&sp->sk_refcnt), sp,
108679 - atomic_read(&sp->sk_drops));
108680 + atomic_read_unchecked(&sp->sk_drops));
108681 }
108682
108683 int udp4_seq_show(struct seq_file *seq, void *v)
108684 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
108685 index 6156f68..d6ab46d 100644
108686 --- a/net/ipv4/xfrm4_policy.c
108687 +++ b/net/ipv4/xfrm4_policy.c
108688 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
108689 fl4->flowi4_tos = iph->tos;
108690 }
108691
108692 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
108693 +static int xfrm4_garbage_collect(struct dst_ops *ops)
108694 {
108695 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
108696
108697 - xfrm4_policy_afinfo.garbage_collect(net);
108698 + xfrm_garbage_collect_deferred(net);
108699 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
108700 }
108701
108702 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
108703
108704 static int __net_init xfrm4_net_init(struct net *net)
108705 {
108706 - struct ctl_table *table;
108707 + ctl_table_no_const *table = NULL;
108708 struct ctl_table_header *hdr;
108709
108710 - table = xfrm4_policy_table;
108711 if (!net_eq(net, &init_net)) {
108712 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
108713 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
108714 if (!table)
108715 goto err_alloc;
108716
108717 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
108718 - }
108719 -
108720 - hdr = register_net_sysctl(net, "net/ipv4", table);
108721 + hdr = register_net_sysctl(net, "net/ipv4", table);
108722 + } else
108723 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
108724 if (!hdr)
108725 goto err_reg;
108726
108727 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
108728 return 0;
108729
108730 err_reg:
108731 - if (!net_eq(net, &init_net))
108732 - kfree(table);
108733 + kfree(table);
108734 err_alloc:
108735 return -ENOMEM;
108736 }
108737 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
108738 index 5667b30..2044f61 100644
108739 --- a/net/ipv6/addrconf.c
108740 +++ b/net/ipv6/addrconf.c
108741 @@ -593,7 +593,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
108742 idx = 0;
108743 head = &net->dev_index_head[h];
108744 rcu_read_lock();
108745 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
108746 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
108747 net->dev_base_seq;
108748 hlist_for_each_entry_rcu(dev, head, index_hlist) {
108749 if (idx < s_idx)
108750 @@ -2390,7 +2390,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
108751 p.iph.ihl = 5;
108752 p.iph.protocol = IPPROTO_IPV6;
108753 p.iph.ttl = 64;
108754 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
108755 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
108756
108757 if (ops->ndo_do_ioctl) {
108758 mm_segment_t oldfs = get_fs();
108759 @@ -3516,16 +3516,23 @@ static const struct file_operations if6_fops = {
108760 .release = seq_release_net,
108761 };
108762
108763 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
108764 +extern void unregister_ipv6_seq_ops_addr(void);
108765 +
108766 static int __net_init if6_proc_net_init(struct net *net)
108767 {
108768 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
108769 + register_ipv6_seq_ops_addr(&if6_seq_ops);
108770 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
108771 + unregister_ipv6_seq_ops_addr();
108772 return -ENOMEM;
108773 + }
108774 return 0;
108775 }
108776
108777 static void __net_exit if6_proc_net_exit(struct net *net)
108778 {
108779 remove_proc_entry("if_inet6", net->proc_net);
108780 + unregister_ipv6_seq_ops_addr();
108781 }
108782
108783 static struct pernet_operations if6_proc_net_ops = {
108784 @@ -4141,7 +4148,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
108785 s_ip_idx = ip_idx = cb->args[2];
108786
108787 rcu_read_lock();
108788 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
108789 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
108790 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
108791 idx = 0;
108792 head = &net->dev_index_head[h];
108793 @@ -4741,11 +4748,8 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
108794
108795 rt = rt6_lookup(dev_net(dev), &ifp->peer_addr, NULL,
108796 dev->ifindex, 1);
108797 - if (rt) {
108798 - dst_hold(&rt->dst);
108799 - if (ip6_del_rt(rt))
108800 - dst_free(&rt->dst);
108801 - }
108802 + if (rt && ip6_del_rt(rt))
108803 + dst_free(&rt->dst);
108804 }
108805 dst_hold(&ifp->rt->dst);
108806
108807 @@ -4753,7 +4757,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
108808 dst_free(&ifp->rt->dst);
108809 break;
108810 }
108811 - atomic_inc(&net->ipv6.dev_addr_genid);
108812 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
108813 rt_genid_bump_ipv6(net);
108814 }
108815
108816 @@ -4774,7 +4778,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
108817 int *valp = ctl->data;
108818 int val = *valp;
108819 loff_t pos = *ppos;
108820 - struct ctl_table lctl;
108821 + ctl_table_no_const lctl;
108822 int ret;
108823
108824 /*
108825 @@ -4859,7 +4863,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
108826 int *valp = ctl->data;
108827 int val = *valp;
108828 loff_t pos = *ppos;
108829 - struct ctl_table lctl;
108830 + ctl_table_no_const lctl;
108831 int ret;
108832
108833 /*
108834 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
108835 index 7cb4392..dc96d28 100644
108836 --- a/net/ipv6/af_inet6.c
108837 +++ b/net/ipv6/af_inet6.c
108838 @@ -765,7 +765,7 @@ static int __net_init inet6_net_init(struct net *net)
108839 net->ipv6.sysctl.bindv6only = 0;
108840 net->ipv6.sysctl.icmpv6_time = 1*HZ;
108841 net->ipv6.sysctl.flowlabel_consistency = 1;
108842 - atomic_set(&net->ipv6.rt_genid, 0);
108843 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
108844
108845 err = ipv6_init_mibs(net);
108846 if (err)
108847 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
108848 index c3bf2d2..1f00573 100644
108849 --- a/net/ipv6/datagram.c
108850 +++ b/net/ipv6/datagram.c
108851 @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
108852 0,
108853 sock_i_ino(sp),
108854 atomic_read(&sp->sk_refcnt), sp,
108855 - atomic_read(&sp->sk_drops));
108856 + atomic_read_unchecked(&sp->sk_drops));
108857 }
108858 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
108859 index f6c84a6..9f2084e 100644
108860 --- a/net/ipv6/icmp.c
108861 +++ b/net/ipv6/icmp.c
108862 @@ -990,7 +990,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
108863
108864 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
108865 {
108866 - struct ctl_table *table;
108867 + ctl_table_no_const *table;
108868
108869 table = kmemdup(ipv6_icmp_table_template,
108870 sizeof(ipv6_icmp_table_template),
108871 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
108872 index 3873181..220ad3f 100644
108873 --- a/net/ipv6/ip6_gre.c
108874 +++ b/net/ipv6/ip6_gre.c
108875 @@ -71,8 +71,8 @@ struct ip6gre_net {
108876 struct net_device *fb_tunnel_dev;
108877 };
108878
108879 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
108880 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
108881 +static struct rtnl_link_ops ip6gre_link_ops;
108882 +static struct rtnl_link_ops ip6gre_tap_ops;
108883 static int ip6gre_tunnel_init(struct net_device *dev);
108884 static void ip6gre_tunnel_setup(struct net_device *dev);
108885 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
108886 @@ -1280,7 +1280,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
108887 }
108888
108889
108890 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
108891 +static struct inet6_protocol ip6gre_protocol = {
108892 .handler = ip6gre_rcv,
108893 .err_handler = ip6gre_err,
108894 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
108895 @@ -1638,7 +1638,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
108896 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
108897 };
108898
108899 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
108900 +static struct rtnl_link_ops ip6gre_link_ops = {
108901 .kind = "ip6gre",
108902 .maxtype = IFLA_GRE_MAX,
108903 .policy = ip6gre_policy,
108904 @@ -1652,7 +1652,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
108905 .fill_info = ip6gre_fill_info,
108906 };
108907
108908 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
108909 +static struct rtnl_link_ops ip6gre_tap_ops = {
108910 .kind = "ip6gretap",
108911 .maxtype = IFLA_GRE_MAX,
108912 .policy = ip6gre_policy,
108913 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
108914 index afa0824..04ba530 100644
108915 --- a/net/ipv6/ip6_tunnel.c
108916 +++ b/net/ipv6/ip6_tunnel.c
108917 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
108918
108919 static int ip6_tnl_dev_init(struct net_device *dev);
108920 static void ip6_tnl_dev_setup(struct net_device *dev);
108921 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
108922 +static struct rtnl_link_ops ip6_link_ops;
108923
108924 static int ip6_tnl_net_id __read_mostly;
108925 struct ip6_tnl_net {
108926 @@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
108927 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
108928 };
108929
108930 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
108931 +static struct rtnl_link_ops ip6_link_ops = {
108932 .kind = "ip6tnl",
108933 .maxtype = IFLA_IPTUN_MAX,
108934 .policy = ip6_tnl_policy,
108935 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
108936 index 9aaa6bb..5c13e57 100644
108937 --- a/net/ipv6/ip6_vti.c
108938 +++ b/net/ipv6/ip6_vti.c
108939 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
108940
108941 static int vti6_dev_init(struct net_device *dev);
108942 static void vti6_dev_setup(struct net_device *dev);
108943 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
108944 +static struct rtnl_link_ops vti6_link_ops;
108945
108946 static int vti6_net_id __read_mostly;
108947 struct vti6_net {
108948 @@ -977,7 +977,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
108949 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
108950 };
108951
108952 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
108953 +static struct rtnl_link_ops vti6_link_ops = {
108954 .kind = "vti6",
108955 .maxtype = IFLA_VTI_MAX,
108956 .policy = vti6_policy,
108957 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
108958 index edb58af..78de133 100644
108959 --- a/net/ipv6/ipv6_sockglue.c
108960 +++ b/net/ipv6/ipv6_sockglue.c
108961 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
108962 if (sk->sk_type != SOCK_STREAM)
108963 return -ENOPROTOOPT;
108964
108965 - msg.msg_control = optval;
108966 + msg.msg_control = (void __force_kernel *)optval;
108967 msg.msg_controllen = len;
108968 msg.msg_flags = flags;
108969
108970 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
108971 index e080fbb..412b3cf 100644
108972 --- a/net/ipv6/netfilter/ip6_tables.c
108973 +++ b/net/ipv6/netfilter/ip6_tables.c
108974 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
108975 #endif
108976
108977 static int get_info(struct net *net, void __user *user,
108978 - const int *len, int compat)
108979 + int len, int compat)
108980 {
108981 char name[XT_TABLE_MAXNAMELEN];
108982 struct xt_table *t;
108983 int ret;
108984
108985 - if (*len != sizeof(struct ip6t_getinfo)) {
108986 - duprintf("length %u != %zu\n", *len,
108987 + if (len != sizeof(struct ip6t_getinfo)) {
108988 + duprintf("length %u != %zu\n", len,
108989 sizeof(struct ip6t_getinfo));
108990 return -EINVAL;
108991 }
108992 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
108993 info.size = private->size;
108994 strcpy(info.name, name);
108995
108996 - if (copy_to_user(user, &info, *len) != 0)
108997 + if (copy_to_user(user, &info, len) != 0)
108998 ret = -EFAULT;
108999 else
109000 ret = 0;
109001 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
109002
109003 switch (cmd) {
109004 case IP6T_SO_GET_INFO:
109005 - ret = get_info(sock_net(sk), user, len, 1);
109006 + ret = get_info(sock_net(sk), user, *len, 1);
109007 break;
109008 case IP6T_SO_GET_ENTRIES:
109009 ret = compat_get_entries(sock_net(sk), user, len);
109010 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
109011
109012 switch (cmd) {
109013 case IP6T_SO_GET_INFO:
109014 - ret = get_info(sock_net(sk), user, len, 0);
109015 + ret = get_info(sock_net(sk), user, *len, 0);
109016 break;
109017
109018 case IP6T_SO_GET_ENTRIES:
109019 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
109020 index 0d5279f..89d9f6f 100644
109021 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
109022 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
109023 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
109024
109025 static int nf_ct_frag6_sysctl_register(struct net *net)
109026 {
109027 - struct ctl_table *table;
109028 + ctl_table_no_const *table = NULL;
109029 struct ctl_table_header *hdr;
109030
109031 - table = nf_ct_frag6_sysctl_table;
109032 if (!net_eq(net, &init_net)) {
109033 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
109034 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
109035 GFP_KERNEL);
109036 if (table == NULL)
109037 goto err_alloc;
109038 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
109039 table[0].data = &net->nf_frag.frags.timeout;
109040 table[1].data = &net->nf_frag.frags.low_thresh;
109041 table[2].data = &net->nf_frag.frags.high_thresh;
109042 - }
109043 -
109044 - hdr = register_net_sysctl(net, "net/netfilter", table);
109045 + hdr = register_net_sysctl(net, "net/netfilter", table);
109046 + } else
109047 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
109048 if (hdr == NULL)
109049 goto err_reg;
109050
109051 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
109052 return 0;
109053
109054 err_reg:
109055 - if (!net_eq(net, &init_net))
109056 - kfree(table);
109057 + kfree(table);
109058 err_alloc:
109059 return -ENOMEM;
109060 }
109061 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
109062 index 5b7a1ed..d9da205 100644
109063 --- a/net/ipv6/ping.c
109064 +++ b/net/ipv6/ping.c
109065 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
109066 };
109067 #endif
109068
109069 +static struct pingv6_ops real_pingv6_ops = {
109070 + .ipv6_recv_error = ipv6_recv_error,
109071 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
109072 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
109073 + .icmpv6_err_convert = icmpv6_err_convert,
109074 + .ipv6_icmp_error = ipv6_icmp_error,
109075 + .ipv6_chk_addr = ipv6_chk_addr,
109076 +};
109077 +
109078 +static struct pingv6_ops dummy_pingv6_ops = {
109079 + .ipv6_recv_error = dummy_ipv6_recv_error,
109080 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
109081 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
109082 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
109083 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
109084 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
109085 +};
109086 +
109087 int __init pingv6_init(void)
109088 {
109089 #ifdef CONFIG_PROC_FS
109090 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
109091 if (ret)
109092 return ret;
109093 #endif
109094 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
109095 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
109096 - pingv6_ops.ip6_datagram_recv_specific_ctl =
109097 - ip6_datagram_recv_specific_ctl;
109098 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
109099 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
109100 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
109101 + pingv6_ops = &real_pingv6_ops;
109102 return inet6_register_protosw(&pingv6_protosw);
109103 }
109104
109105 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
109106 */
109107 void pingv6_exit(void)
109108 {
109109 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
109110 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
109111 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
109112 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
109113 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
109114 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
109115 #ifdef CONFIG_PROC_FS
109116 unregister_pernet_subsys(&ping_v6_net_ops);
109117 #endif
109118 + pingv6_ops = &dummy_pingv6_ops;
109119 inet6_unregister_protosw(&pingv6_protosw);
109120 }
109121 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
109122 index 3317440..201764e 100644
109123 --- a/net/ipv6/proc.c
109124 +++ b/net/ipv6/proc.c
109125 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
109126 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
109127 goto proc_snmp6_fail;
109128
109129 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
109130 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
109131 if (!net->mib.proc_net_devsnmp6)
109132 goto proc_dev_snmp6_fail;
109133 return 0;
109134 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
109135 index b2dc60b..a6b6c10 100644
109136 --- a/net/ipv6/raw.c
109137 +++ b/net/ipv6/raw.c
109138 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
109139 {
109140 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
109141 skb_checksum_complete(skb)) {
109142 - atomic_inc(&sk->sk_drops);
109143 + atomic_inc_unchecked(&sk->sk_drops);
109144 kfree_skb(skb);
109145 return NET_RX_DROP;
109146 }
109147 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
109148 struct raw6_sock *rp = raw6_sk(sk);
109149
109150 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
109151 - atomic_inc(&sk->sk_drops);
109152 + atomic_inc_unchecked(&sk->sk_drops);
109153 kfree_skb(skb);
109154 return NET_RX_DROP;
109155 }
109156 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
109157
109158 if (inet->hdrincl) {
109159 if (skb_checksum_complete(skb)) {
109160 - atomic_inc(&sk->sk_drops);
109161 + atomic_inc_unchecked(&sk->sk_drops);
109162 kfree_skb(skb);
109163 return NET_RX_DROP;
109164 }
109165 @@ -610,7 +610,7 @@ out:
109166 return err;
109167 }
109168
109169 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
109170 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
109171 struct flowi6 *fl6, struct dst_entry **dstp,
109172 unsigned int flags)
109173 {
109174 @@ -916,12 +916,15 @@ do_confirm:
109175 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
109176 char __user *optval, int optlen)
109177 {
109178 + struct icmp6_filter filter;
109179 +
109180 switch (optname) {
109181 case ICMPV6_FILTER:
109182 if (optlen > sizeof(struct icmp6_filter))
109183 optlen = sizeof(struct icmp6_filter);
109184 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
109185 + if (copy_from_user(&filter, optval, optlen))
109186 return -EFAULT;
109187 + raw6_sk(sk)->filter = filter;
109188 return 0;
109189 default:
109190 return -ENOPROTOOPT;
109191 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
109192 char __user *optval, int __user *optlen)
109193 {
109194 int len;
109195 + struct icmp6_filter filter;
109196
109197 switch (optname) {
109198 case ICMPV6_FILTER:
109199 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
109200 len = sizeof(struct icmp6_filter);
109201 if (put_user(len, optlen))
109202 return -EFAULT;
109203 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
109204 + filter = raw6_sk(sk)->filter;
109205 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
109206 return -EFAULT;
109207 return 0;
109208 default:
109209 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
109210 index cc85a9b..526a133 100644
109211 --- a/net/ipv6/reassembly.c
109212 +++ b/net/ipv6/reassembly.c
109213 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
109214
109215 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
109216 {
109217 - struct ctl_table *table;
109218 + ctl_table_no_const *table = NULL;
109219 struct ctl_table_header *hdr;
109220
109221 - table = ip6_frags_ns_ctl_table;
109222 if (!net_eq(net, &init_net)) {
109223 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
109224 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
109225 if (table == NULL)
109226 goto err_alloc;
109227
109228 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
109229 /* Don't export sysctls to unprivileged users */
109230 if (net->user_ns != &init_user_ns)
109231 table[0].procname = NULL;
109232 - }
109233 + hdr = register_net_sysctl(net, "net/ipv6", table);
109234 + } else
109235 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
109236
109237 - hdr = register_net_sysctl(net, "net/ipv6", table);
109238 if (hdr == NULL)
109239 goto err_reg;
109240
109241 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
109242 return 0;
109243
109244 err_reg:
109245 - if (!net_eq(net, &init_net))
109246 - kfree(table);
109247 + kfree(table);
109248 err_alloc:
109249 return -ENOMEM;
109250 }
109251 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
109252 index f23fbd2..7868241 100644
109253 --- a/net/ipv6/route.c
109254 +++ b/net/ipv6/route.c
109255 @@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
109256
109257 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
109258 {
109259 - struct ctl_table *table;
109260 + ctl_table_no_const *table;
109261
109262 table = kmemdup(ipv6_route_table_template,
109263 sizeof(ipv6_route_table_template),
109264 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
109265 index 4f40817..54dcbef 100644
109266 --- a/net/ipv6/sit.c
109267 +++ b/net/ipv6/sit.c
109268 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
109269 static void ipip6_dev_free(struct net_device *dev);
109270 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
109271 __be32 *v4dst);
109272 -static struct rtnl_link_ops sit_link_ops __read_mostly;
109273 +static struct rtnl_link_ops sit_link_ops;
109274
109275 static int sit_net_id __read_mostly;
109276 struct sit_net {
109277 @@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
109278 unregister_netdevice_queue(dev, head);
109279 }
109280
109281 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
109282 +static struct rtnl_link_ops sit_link_ops = {
109283 .kind = "sit",
109284 .maxtype = IFLA_IPTUN_MAX,
109285 .policy = ipip6_policy,
109286 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
109287 index 058f3ec..dec973d 100644
109288 --- a/net/ipv6/sysctl_net_ipv6.c
109289 +++ b/net/ipv6/sysctl_net_ipv6.c
109290 @@ -61,7 +61,7 @@ static struct ctl_table ipv6_rotable[] = {
109291
109292 static int __net_init ipv6_sysctl_net_init(struct net *net)
109293 {
109294 - struct ctl_table *ipv6_table;
109295 + ctl_table_no_const *ipv6_table;
109296 struct ctl_table *ipv6_route_table;
109297 struct ctl_table *ipv6_icmp_table;
109298 int err;
109299 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
109300 index 229239ad..ee2802f 100644
109301 --- a/net/ipv6/tcp_ipv6.c
109302 +++ b/net/ipv6/tcp_ipv6.c
109303 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
109304 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
109305 }
109306
109307 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109308 +extern int grsec_enable_blackhole;
109309 +#endif
109310 +
109311 static void tcp_v6_hash(struct sock *sk)
109312 {
109313 if (sk->sk_state != TCP_CLOSE) {
109314 @@ -1424,6 +1428,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
109315 return 0;
109316
109317 reset:
109318 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109319 + if (!grsec_enable_blackhole)
109320 +#endif
109321 tcp_v6_send_reset(sk, skb);
109322 discard:
109323 if (opt_skb)
109324 @@ -1508,12 +1515,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
109325 TCP_SKB_CB(skb)->sacked = 0;
109326
109327 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
109328 - if (!sk)
109329 + if (!sk) {
109330 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109331 + ret = 1;
109332 +#endif
109333 goto no_tcp_socket;
109334 + }
109335
109336 process:
109337 - if (sk->sk_state == TCP_TIME_WAIT)
109338 + if (sk->sk_state == TCP_TIME_WAIT) {
109339 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109340 + ret = 2;
109341 +#endif
109342 goto do_time_wait;
109343 + }
109344
109345 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
109346 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
109347 @@ -1565,6 +1580,10 @@ csum_error:
109348 bad_packet:
109349 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
109350 } else {
109351 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109352 + if (!grsec_enable_blackhole || (ret == 1 &&
109353 + (skb->dev->flags & IFF_LOOPBACK)))
109354 +#endif
109355 tcp_v6_send_reset(NULL, skb);
109356 }
109357
109358 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
109359 index 7092ff7..3fd0eb4 100644
109360 --- a/net/ipv6/udp.c
109361 +++ b/net/ipv6/udp.c
109362 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
109363 udp_ipv6_hash_secret + net_hash_mix(net));
109364 }
109365
109366 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109367 +extern int grsec_enable_blackhole;
109368 +#endif
109369 +
109370 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
109371 {
109372 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
109373 @@ -435,7 +439,7 @@ try_again:
109374 if (unlikely(err)) {
109375 trace_kfree_skb(skb, udpv6_recvmsg);
109376 if (!peeked) {
109377 - atomic_inc(&sk->sk_drops);
109378 + atomic_inc_unchecked(&sk->sk_drops);
109379 if (is_udp4)
109380 UDP_INC_STATS_USER(sock_net(sk),
109381 UDP_MIB_INERRORS,
109382 @@ -698,7 +702,7 @@ csum_error:
109383 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
109384 drop:
109385 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
109386 - atomic_inc(&sk->sk_drops);
109387 + atomic_inc_unchecked(&sk->sk_drops);
109388 kfree_skb(skb);
109389 return -1;
109390 }
109391 @@ -754,7 +758,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
109392 if (likely(skb1 == NULL))
109393 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
109394 if (!skb1) {
109395 - atomic_inc(&sk->sk_drops);
109396 + atomic_inc_unchecked(&sk->sk_drops);
109397 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
109398 IS_UDPLITE(sk));
109399 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
109400 @@ -920,6 +924,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
109401 goto csum_error;
109402
109403 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
109404 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109405 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
109406 +#endif
109407 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
109408
109409 kfree_skb(skb);
109410 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
109411 index 2a0bbda..d75ca57 100644
109412 --- a/net/ipv6/xfrm6_policy.c
109413 +++ b/net/ipv6/xfrm6_policy.c
109414 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
109415 }
109416 }
109417
109418 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
109419 +static int xfrm6_garbage_collect(struct dst_ops *ops)
109420 {
109421 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
109422
109423 - xfrm6_policy_afinfo.garbage_collect(net);
109424 + xfrm_garbage_collect_deferred(net);
109425 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
109426 }
109427
109428 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
109429
109430 static int __net_init xfrm6_net_init(struct net *net)
109431 {
109432 - struct ctl_table *table;
109433 + ctl_table_no_const *table = NULL;
109434 struct ctl_table_header *hdr;
109435
109436 - table = xfrm6_policy_table;
109437 if (!net_eq(net, &init_net)) {
109438 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
109439 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
109440 if (!table)
109441 goto err_alloc;
109442
109443 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
109444 - }
109445 + hdr = register_net_sysctl(net, "net/ipv6", table);
109446 + } else
109447 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
109448
109449 - hdr = register_net_sysctl(net, "net/ipv6", table);
109450 if (!hdr)
109451 goto err_reg;
109452
109453 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
109454 return 0;
109455
109456 err_reg:
109457 - if (!net_eq(net, &init_net))
109458 - kfree(table);
109459 + kfree(table);
109460 err_alloc:
109461 return -ENOMEM;
109462 }
109463 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
109464 index e15c16a..7cf07aa 100644
109465 --- a/net/ipx/ipx_proc.c
109466 +++ b/net/ipx/ipx_proc.c
109467 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
109468 struct proc_dir_entry *p;
109469 int rc = -ENOMEM;
109470
109471 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
109472 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
109473
109474 if (!ipx_proc_dir)
109475 goto out;
109476 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
109477 index 2ba8b97..6d33010 100644
109478 --- a/net/irda/ircomm/ircomm_tty.c
109479 +++ b/net/irda/ircomm/ircomm_tty.c
109480 @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
109481 add_wait_queue(&port->open_wait, &wait);
109482
109483 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
109484 - __FILE__, __LINE__, tty->driver->name, port->count);
109485 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
109486
109487 spin_lock_irqsave(&port->lock, flags);
109488 if (!tty_hung_up_p(filp))
109489 - port->count--;
109490 + atomic_dec(&port->count);
109491 port->blocked_open++;
109492 spin_unlock_irqrestore(&port->lock, flags);
109493
109494 @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
109495 }
109496
109497 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
109498 - __FILE__, __LINE__, tty->driver->name, port->count);
109499 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
109500
109501 schedule();
109502 }
109503 @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
109504
109505 spin_lock_irqsave(&port->lock, flags);
109506 if (!tty_hung_up_p(filp))
109507 - port->count++;
109508 + atomic_inc(&port->count);
109509 port->blocked_open--;
109510 spin_unlock_irqrestore(&port->lock, flags);
109511
109512 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
109513 - __FILE__, __LINE__, tty->driver->name, port->count);
109514 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
109515
109516 if (!retval)
109517 port->flags |= ASYNC_NORMAL_ACTIVE;
109518 @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
109519
109520 /* ++ is not atomic, so this should be protected - Jean II */
109521 spin_lock_irqsave(&self->port.lock, flags);
109522 - self->port.count++;
109523 + atomic_inc(&self->port.count);
109524 spin_unlock_irqrestore(&self->port.lock, flags);
109525 tty_port_tty_set(&self->port, tty);
109526
109527 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
109528 - self->line, self->port.count);
109529 + self->line, atomic_read(&self->port.count));
109530
109531 /* Not really used by us, but lets do it anyway */
109532 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
109533 @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
109534 tty_kref_put(port->tty);
109535 }
109536 port->tty = NULL;
109537 - port->count = 0;
109538 + atomic_set(&port->count, 0);
109539 spin_unlock_irqrestore(&port->lock, flags);
109540
109541 wake_up_interruptible(&port->open_wait);
109542 @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
109543 seq_putc(m, '\n');
109544
109545 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
109546 - seq_printf(m, "Open count: %d\n", self->port.count);
109547 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
109548 seq_printf(m, "Max data size: %d\n", self->max_data_size);
109549 seq_printf(m, "Max header size: %d\n", self->max_header_size);
109550
109551 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
109552 index b9ac598..f88cc56 100644
109553 --- a/net/irda/irproc.c
109554 +++ b/net/irda/irproc.c
109555 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
109556 {
109557 int i;
109558
109559 - proc_irda = proc_mkdir("irda", init_net.proc_net);
109560 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
109561 if (proc_irda == NULL)
109562 return;
109563
109564 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
109565 index 7a95fa4..57be196 100644
109566 --- a/net/iucv/af_iucv.c
109567 +++ b/net/iucv/af_iucv.c
109568 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
109569 {
109570 char name[12];
109571
109572 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
109573 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
109574 while (__iucv_get_sock_by_name(name)) {
109575 sprintf(name, "%08x",
109576 - atomic_inc_return(&iucv_sk_list.autobind_name));
109577 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
109578 }
109579 memcpy(iucv->src_name, name, 8);
109580 }
109581 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
109582 index da78793..bdd78cf 100644
109583 --- a/net/iucv/iucv.c
109584 +++ b/net/iucv/iucv.c
109585 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
109586 return NOTIFY_OK;
109587 }
109588
109589 -static struct notifier_block __refdata iucv_cpu_notifier = {
109590 +static struct notifier_block iucv_cpu_notifier = {
109591 .notifier_call = iucv_cpu_notify,
109592 };
109593
109594 diff --git a/net/key/af_key.c b/net/key/af_key.c
109595 index ba2a2f9..b658bc3 100644
109596 --- a/net/key/af_key.c
109597 +++ b/net/key/af_key.c
109598 @@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
109599 static u32 get_acqseq(void)
109600 {
109601 u32 res;
109602 - static atomic_t acqseq;
109603 + static atomic_unchecked_t acqseq;
109604
109605 do {
109606 - res = atomic_inc_return(&acqseq);
109607 + res = atomic_inc_return_unchecked(&acqseq);
109608 } while (!res);
109609 return res;
109610 }
109611 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
109612 index 76125c5..e474828 100644
109613 --- a/net/l2tp/l2tp_eth.c
109614 +++ b/net/l2tp/l2tp_eth.c
109615 @@ -42,12 +42,12 @@ struct l2tp_eth {
109616 struct sock *tunnel_sock;
109617 struct l2tp_session *session;
109618 struct list_head list;
109619 - atomic_long_t tx_bytes;
109620 - atomic_long_t tx_packets;
109621 - atomic_long_t tx_dropped;
109622 - atomic_long_t rx_bytes;
109623 - atomic_long_t rx_packets;
109624 - atomic_long_t rx_errors;
109625 + atomic_long_unchecked_t tx_bytes;
109626 + atomic_long_unchecked_t tx_packets;
109627 + atomic_long_unchecked_t tx_dropped;
109628 + atomic_long_unchecked_t rx_bytes;
109629 + atomic_long_unchecked_t rx_packets;
109630 + atomic_long_unchecked_t rx_errors;
109631 };
109632
109633 /* via l2tp_session_priv() */
109634 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
109635 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
109636
109637 if (likely(ret == NET_XMIT_SUCCESS)) {
109638 - atomic_long_add(len, &priv->tx_bytes);
109639 - atomic_long_inc(&priv->tx_packets);
109640 + atomic_long_add_unchecked(len, &priv->tx_bytes);
109641 + atomic_long_inc_unchecked(&priv->tx_packets);
109642 } else {
109643 - atomic_long_inc(&priv->tx_dropped);
109644 + atomic_long_inc_unchecked(&priv->tx_dropped);
109645 }
109646 return NETDEV_TX_OK;
109647 }
109648 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
109649 {
109650 struct l2tp_eth *priv = netdev_priv(dev);
109651
109652 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
109653 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
109654 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
109655 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
109656 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
109657 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
109658 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
109659 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
109660 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
109661 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
109662 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
109663 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
109664 return stats;
109665 }
109666
109667 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
109668 nf_reset(skb);
109669
109670 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
109671 - atomic_long_inc(&priv->rx_packets);
109672 - atomic_long_add(data_len, &priv->rx_bytes);
109673 + atomic_long_inc_unchecked(&priv->rx_packets);
109674 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
109675 } else {
109676 - atomic_long_inc(&priv->rx_errors);
109677 + atomic_long_inc_unchecked(&priv->rx_errors);
109678 }
109679 return;
109680
109681 error:
109682 - atomic_long_inc(&priv->rx_errors);
109683 + atomic_long_inc_unchecked(&priv->rx_errors);
109684 kfree_skb(skb);
109685 }
109686
109687 diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
109688 index 13752d9..b704a93 100644
109689 --- a/net/l2tp/l2tp_ppp.c
109690 +++ b/net/l2tp/l2tp_ppp.c
109691 @@ -755,7 +755,8 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
109692 /* If PMTU discovery was enabled, use the MTU that was discovered */
109693 dst = sk_dst_get(tunnel->sock);
109694 if (dst != NULL) {
109695 - u32 pmtu = dst_mtu(__sk_dst_get(tunnel->sock));
109696 + u32 pmtu = dst_mtu(dst);
109697 +
109698 if (pmtu != 0)
109699 session->mtu = session->mru = pmtu -
109700 PPPOL2TP_HEADER_OVERHEAD;
109701 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
109702 index 1a3c7e0..80f8b0c 100644
109703 --- a/net/llc/llc_proc.c
109704 +++ b/net/llc/llc_proc.c
109705 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
109706 int rc = -ENOMEM;
109707 struct proc_dir_entry *p;
109708
109709 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
109710 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
109711 if (!llc_proc_dir)
109712 goto out;
109713
109714 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
109715 index 592f4b1..efa7aa9 100644
109716 --- a/net/mac80211/cfg.c
109717 +++ b/net/mac80211/cfg.c
109718 @@ -864,7 +864,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
109719 ret = ieee80211_vif_use_channel(sdata, chandef,
109720 IEEE80211_CHANCTX_EXCLUSIVE);
109721 }
109722 - } else if (local->open_count == local->monitors) {
109723 + } else if (local_read(&local->open_count) == local->monitors) {
109724 local->_oper_chandef = *chandef;
109725 ieee80211_hw_config(local, 0);
109726 }
109727 @@ -3574,7 +3574,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
109728 else
109729 local->probe_req_reg--;
109730
109731 - if (!local->open_count)
109732 + if (!local_read(&local->open_count))
109733 break;
109734
109735 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
109736 @@ -3723,8 +3723,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
109737 if (chanctx_conf) {
109738 *chandef = chanctx_conf->def;
109739 ret = 0;
109740 - } else if (local->open_count > 0 &&
109741 - local->open_count == local->monitors &&
109742 + } else if (local_read(&local->open_count) > 0 &&
109743 + local_read(&local->open_count) == local->monitors &&
109744 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
109745 if (local->use_chanctx)
109746 *chandef = local->monitor_chandef;
109747 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
109748 index ac9836e..32613c1 100644
109749 --- a/net/mac80211/ieee80211_i.h
109750 +++ b/net/mac80211/ieee80211_i.h
109751 @@ -28,6 +28,7 @@
109752 #include <net/ieee80211_radiotap.h>
109753 #include <net/cfg80211.h>
109754 #include <net/mac80211.h>
109755 +#include <asm/local.h>
109756 #include "key.h"
109757 #include "sta_info.h"
109758 #include "debug.h"
109759 @@ -1011,7 +1012,7 @@ struct ieee80211_local {
109760 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
109761 spinlock_t queue_stop_reason_lock;
109762
109763 - int open_count;
109764 + local_t open_count;
109765 int monitors, cooked_mntrs;
109766 /* number of interfaces with corresponding FIF_ flags */
109767 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
109768 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
109769 index 388b863..6575b55 100644
109770 --- a/net/mac80211/iface.c
109771 +++ b/net/mac80211/iface.c
109772 @@ -531,7 +531,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
109773 break;
109774 }
109775
109776 - if (local->open_count == 0) {
109777 + if (local_read(&local->open_count) == 0) {
109778 res = drv_start(local);
109779 if (res)
109780 goto err_del_bss;
109781 @@ -578,7 +578,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
109782 res = drv_add_interface(local, sdata);
109783 if (res)
109784 goto err_stop;
109785 - } else if (local->monitors == 0 && local->open_count == 0) {
109786 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
109787 res = ieee80211_add_virtual_monitor(local);
109788 if (res)
109789 goto err_stop;
109790 @@ -687,7 +687,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
109791 atomic_inc(&local->iff_promiscs);
109792
109793 if (coming_up)
109794 - local->open_count++;
109795 + local_inc(&local->open_count);
109796
109797 if (hw_reconf_flags)
109798 ieee80211_hw_config(local, hw_reconf_flags);
109799 @@ -725,7 +725,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
109800 err_del_interface:
109801 drv_remove_interface(local, sdata);
109802 err_stop:
109803 - if (!local->open_count)
109804 + if (!local_read(&local->open_count))
109805 drv_stop(local);
109806 err_del_bss:
109807 sdata->bss = NULL;
109808 @@ -888,7 +888,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
109809 }
109810
109811 if (going_down)
109812 - local->open_count--;
109813 + local_dec(&local->open_count);
109814
109815 switch (sdata->vif.type) {
109816 case NL80211_IFTYPE_AP_VLAN:
109817 @@ -949,7 +949,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
109818 }
109819 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
109820
109821 - if (local->open_count == 0)
109822 + if (local_read(&local->open_count) == 0)
109823 ieee80211_clear_tx_pending(local);
109824
109825 /*
109826 @@ -989,7 +989,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
109827
109828 ieee80211_recalc_ps(local, -1);
109829
109830 - if (local->open_count == 0) {
109831 + if (local_read(&local->open_count) == 0) {
109832 ieee80211_stop_device(local);
109833
109834 /* no reconfiguring after stop! */
109835 @@ -1000,7 +1000,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
109836 ieee80211_configure_filter(local);
109837 ieee80211_hw_config(local, hw_reconf_flags);
109838
109839 - if (local->monitors == local->open_count)
109840 + if (local->monitors == local_read(&local->open_count))
109841 ieee80211_add_virtual_monitor(local);
109842 }
109843
109844 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
109845 index d17c26d..43d6bfb 100644
109846 --- a/net/mac80211/main.c
109847 +++ b/net/mac80211/main.c
109848 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
109849 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
109850 IEEE80211_CONF_CHANGE_POWER);
109851
109852 - if (changed && local->open_count) {
109853 + if (changed && local_read(&local->open_count)) {
109854 ret = drv_config(local, changed);
109855 /*
109856 * Goal:
109857 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
109858 index d478b88..8c8d157 100644
109859 --- a/net/mac80211/pm.c
109860 +++ b/net/mac80211/pm.c
109861 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
109862 struct ieee80211_sub_if_data *sdata;
109863 struct sta_info *sta;
109864
109865 - if (!local->open_count)
109866 + if (!local_read(&local->open_count))
109867 goto suspend;
109868
109869 ieee80211_scan_cancel(local);
109870 @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
109871 cancel_work_sync(&local->dynamic_ps_enable_work);
109872 del_timer_sync(&local->dynamic_ps_timer);
109873
109874 - local->wowlan = wowlan && local->open_count;
109875 + local->wowlan = wowlan && local_read(&local->open_count);
109876 if (local->wowlan) {
109877 int err = drv_suspend(local, wowlan);
109878 if (err < 0) {
109879 @@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
109880 WARN_ON(!list_empty(&local->chanctx_list));
109881
109882 /* stop hardware - this must stop RX */
109883 - if (local->open_count)
109884 + if (local_read(&local->open_count))
109885 ieee80211_stop_device(local);
109886
109887 suspend:
109888 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
109889 index 8fdadfd..a4f72b8 100644
109890 --- a/net/mac80211/rate.c
109891 +++ b/net/mac80211/rate.c
109892 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
109893
109894 ASSERT_RTNL();
109895
109896 - if (local->open_count)
109897 + if (local_read(&local->open_count))
109898 return -EBUSY;
109899
109900 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
109901 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
109902 index 6ff1346..936ca9a 100644
109903 --- a/net/mac80211/rc80211_pid_debugfs.c
109904 +++ b/net/mac80211/rc80211_pid_debugfs.c
109905 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
109906
109907 spin_unlock_irqrestore(&events->lock, status);
109908
109909 - if (copy_to_user(buf, pb, p))
109910 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
109911 return -EFAULT;
109912
109913 return p;
109914 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
109915 index a6cda52..f3b6776 100644
109916 --- a/net/mac80211/util.c
109917 +++ b/net/mac80211/util.c
109918 @@ -1548,7 +1548,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
109919 }
109920 #endif
109921 /* everything else happens only if HW was up & running */
109922 - if (!local->open_count)
109923 + if (!local_read(&local->open_count))
109924 goto wake_up;
109925
109926 /*
109927 @@ -1772,7 +1772,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
109928 local->in_reconfig = false;
109929 barrier();
109930
109931 - if (local->monitors == local->open_count && local->monitors > 0)
109932 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
109933 ieee80211_add_virtual_monitor(local);
109934
109935 /*
109936 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
109937 index e9410d1..77b6378 100644
109938 --- a/net/netfilter/Kconfig
109939 +++ b/net/netfilter/Kconfig
109940 @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
109941
109942 To compile it as a module, choose M here. If unsure, say N.
109943
109944 +config NETFILTER_XT_MATCH_GRADM
109945 + tristate '"gradm" match support'
109946 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
109947 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
109948 + ---help---
109949 + The gradm match allows to match on grsecurity RBAC being enabled.
109950 + It is useful when iptables rules are applied early on bootup to
109951 + prevent connections to the machine (except from a trusted host)
109952 + while the RBAC system is disabled.
109953 +
109954 config NETFILTER_XT_MATCH_HASHLIMIT
109955 tristate '"hashlimit" match support'
109956 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
109957 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
109958 index bffdad7..f9317d1 100644
109959 --- a/net/netfilter/Makefile
109960 +++ b/net/netfilter/Makefile
109961 @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
109962 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
109963 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
109964 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
109965 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
109966 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
109967 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
109968 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
109969 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
109970 index ec8114f..6b2bfba 100644
109971 --- a/net/netfilter/ipset/ip_set_core.c
109972 +++ b/net/netfilter/ipset/ip_set_core.c
109973 @@ -1921,7 +1921,7 @@ done:
109974 return ret;
109975 }
109976
109977 -static struct nf_sockopt_ops so_set __read_mostly = {
109978 +static struct nf_sockopt_ops so_set = {
109979 .pf = PF_INET,
109980 .get_optmin = SO_IP_SET,
109981 .get_optmax = SO_IP_SET + 1,
109982 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
109983 index 610e19c..08d0c3f 100644
109984 --- a/net/netfilter/ipvs/ip_vs_conn.c
109985 +++ b/net/netfilter/ipvs/ip_vs_conn.c
109986 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
109987 /* Increase the refcnt counter of the dest */
109988 ip_vs_dest_hold(dest);
109989
109990 - conn_flags = atomic_read(&dest->conn_flags);
109991 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
109992 if (cp->protocol != IPPROTO_UDP)
109993 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
109994 flags = cp->flags;
109995 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
109996
109997 cp->control = NULL;
109998 atomic_set(&cp->n_control, 0);
109999 - atomic_set(&cp->in_pkts, 0);
110000 + atomic_set_unchecked(&cp->in_pkts, 0);
110001
110002 cp->packet_xmit = NULL;
110003 cp->app = NULL;
110004 @@ -1187,7 +1187,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
110005
110006 /* Don't drop the entry if its number of incoming packets is not
110007 located in [0, 8] */
110008 - i = atomic_read(&cp->in_pkts);
110009 + i = atomic_read_unchecked(&cp->in_pkts);
110010 if (i > 8 || i < 0) return 0;
110011
110012 if (!todrop_rate[i]) return 0;
110013 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
110014 index e683675..67cb16b 100644
110015 --- a/net/netfilter/ipvs/ip_vs_core.c
110016 +++ b/net/netfilter/ipvs/ip_vs_core.c
110017 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
110018 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
110019 /* do not touch skb anymore */
110020
110021 - atomic_inc(&cp->in_pkts);
110022 + atomic_inc_unchecked(&cp->in_pkts);
110023 ip_vs_conn_put(cp);
110024 return ret;
110025 }
110026 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
110027 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
110028 pkts = sysctl_sync_threshold(ipvs);
110029 else
110030 - pkts = atomic_add_return(1, &cp->in_pkts);
110031 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
110032
110033 if (ipvs->sync_state & IP_VS_STATE_MASTER)
110034 ip_vs_sync_conn(net, cp, pkts);
110035 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
110036 index 581a658..910e112 100644
110037 --- a/net/netfilter/ipvs/ip_vs_ctl.c
110038 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
110039 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
110040 */
110041 ip_vs_rs_hash(ipvs, dest);
110042 }
110043 - atomic_set(&dest->conn_flags, conn_flags);
110044 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
110045
110046 /* bind the service */
110047 old_svc = rcu_dereference_protected(dest->svc, 1);
110048 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
110049 * align with netns init in ip_vs_control_net_init()
110050 */
110051
110052 -static struct ctl_table vs_vars[] = {
110053 +static ctl_table_no_const vs_vars[] __read_only = {
110054 {
110055 .procname = "amemthresh",
110056 .maxlen = sizeof(int),
110057 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
110058 " %-7s %-6d %-10d %-10d\n",
110059 &dest->addr.in6,
110060 ntohs(dest->port),
110061 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
110062 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
110063 atomic_read(&dest->weight),
110064 atomic_read(&dest->activeconns),
110065 atomic_read(&dest->inactconns));
110066 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
110067 "%-7s %-6d %-10d %-10d\n",
110068 ntohl(dest->addr.ip),
110069 ntohs(dest->port),
110070 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
110071 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
110072 atomic_read(&dest->weight),
110073 atomic_read(&dest->activeconns),
110074 atomic_read(&dest->inactconns));
110075 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
110076
110077 entry.addr = dest->addr.ip;
110078 entry.port = dest->port;
110079 - entry.conn_flags = atomic_read(&dest->conn_flags);
110080 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
110081 entry.weight = atomic_read(&dest->weight);
110082 entry.u_threshold = dest->u_threshold;
110083 entry.l_threshold = dest->l_threshold;
110084 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
110085 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
110086 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
110087 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
110088 - (atomic_read(&dest->conn_flags) &
110089 + (atomic_read_unchecked(&dest->conn_flags) &
110090 IP_VS_CONN_F_FWD_MASK)) ||
110091 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
110092 atomic_read(&dest->weight)) ||
110093 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
110094 {
110095 int idx;
110096 struct netns_ipvs *ipvs = net_ipvs(net);
110097 - struct ctl_table *tbl;
110098 + ctl_table_no_const *tbl;
110099
110100 atomic_set(&ipvs->dropentry, 0);
110101 spin_lock_init(&ipvs->dropentry_lock);
110102 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
110103 index 547ff33..c8c8117 100644
110104 --- a/net/netfilter/ipvs/ip_vs_lblc.c
110105 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
110106 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
110107 * IPVS LBLC sysctl table
110108 */
110109 #ifdef CONFIG_SYSCTL
110110 -static struct ctl_table vs_vars_table[] = {
110111 +static ctl_table_no_const vs_vars_table[] __read_only = {
110112 {
110113 .procname = "lblc_expiration",
110114 .data = NULL,
110115 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
110116 index 3f21a2f..a112e85 100644
110117 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
110118 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
110119 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
110120 * IPVS LBLCR sysctl table
110121 */
110122
110123 -static struct ctl_table vs_vars_table[] = {
110124 +static ctl_table_no_const vs_vars_table[] __read_only = {
110125 {
110126 .procname = "lblcr_expiration",
110127 .data = NULL,
110128 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
110129 index db80126..ef7110e 100644
110130 --- a/net/netfilter/ipvs/ip_vs_sync.c
110131 +++ b/net/netfilter/ipvs/ip_vs_sync.c
110132 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
110133 cp = cp->control;
110134 if (cp) {
110135 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
110136 - pkts = atomic_add_return(1, &cp->in_pkts);
110137 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
110138 else
110139 pkts = sysctl_sync_threshold(ipvs);
110140 ip_vs_sync_conn(net, cp->control, pkts);
110141 @@ -771,7 +771,7 @@ control:
110142 if (!cp)
110143 return;
110144 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
110145 - pkts = atomic_add_return(1, &cp->in_pkts);
110146 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
110147 else
110148 pkts = sysctl_sync_threshold(ipvs);
110149 goto sloop;
110150 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
110151
110152 if (opt)
110153 memcpy(&cp->in_seq, opt, sizeof(*opt));
110154 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
110155 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
110156 cp->state = state;
110157 cp->old_state = cp->state;
110158 /*
110159 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
110160 index 73ba1cc..1adfc7a 100644
110161 --- a/net/netfilter/ipvs/ip_vs_xmit.c
110162 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
110163 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
110164 else
110165 rc = NF_ACCEPT;
110166 /* do not touch skb anymore */
110167 - atomic_inc(&cp->in_pkts);
110168 + atomic_inc_unchecked(&cp->in_pkts);
110169 goto out;
110170 }
110171
110172 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
110173 else
110174 rc = NF_ACCEPT;
110175 /* do not touch skb anymore */
110176 - atomic_inc(&cp->in_pkts);
110177 + atomic_inc_unchecked(&cp->in_pkts);
110178 goto out;
110179 }
110180
110181 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
110182 index a4b5e2a..13b1de3 100644
110183 --- a/net/netfilter/nf_conntrack_acct.c
110184 +++ b/net/netfilter/nf_conntrack_acct.c
110185 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
110186 #ifdef CONFIG_SYSCTL
110187 static int nf_conntrack_acct_init_sysctl(struct net *net)
110188 {
110189 - struct ctl_table *table;
110190 + ctl_table_no_const *table;
110191
110192 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
110193 GFP_KERNEL);
110194 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
110195 index 1f4f954..e364ad7 100644
110196 --- a/net/netfilter/nf_conntrack_core.c
110197 +++ b/net/netfilter/nf_conntrack_core.c
110198 @@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
110199 #define DYING_NULLS_VAL ((1<<30)+1)
110200 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
110201
110202 +#ifdef CONFIG_GRKERNSEC_HIDESYM
110203 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
110204 +#endif
110205 +
110206 int nf_conntrack_init_net(struct net *net)
110207 {
110208 int ret = -ENOMEM;
110209 @@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
110210 if (!net->ct.stat)
110211 goto err_pcpu_lists;
110212
110213 +#ifdef CONFIG_GRKERNSEC_HIDESYM
110214 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
110215 +#else
110216 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
110217 +#endif
110218 if (!net->ct.slabname)
110219 goto err_slabname;
110220
110221 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
110222 index 1df1761..ce8b88a 100644
110223 --- a/net/netfilter/nf_conntrack_ecache.c
110224 +++ b/net/netfilter/nf_conntrack_ecache.c
110225 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
110226 #ifdef CONFIG_SYSCTL
110227 static int nf_conntrack_event_init_sysctl(struct net *net)
110228 {
110229 - struct ctl_table *table;
110230 + ctl_table_no_const *table;
110231
110232 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
110233 GFP_KERNEL);
110234 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
110235 index 5b3eae7..dd4b8fe 100644
110236 --- a/net/netfilter/nf_conntrack_helper.c
110237 +++ b/net/netfilter/nf_conntrack_helper.c
110238 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
110239
110240 static int nf_conntrack_helper_init_sysctl(struct net *net)
110241 {
110242 - struct ctl_table *table;
110243 + ctl_table_no_const *table;
110244
110245 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
110246 GFP_KERNEL);
110247 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
110248 index b65d586..beec902 100644
110249 --- a/net/netfilter/nf_conntrack_proto.c
110250 +++ b/net/netfilter/nf_conntrack_proto.c
110251 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
110252
110253 static void
110254 nf_ct_unregister_sysctl(struct ctl_table_header **header,
110255 - struct ctl_table **table,
110256 + ctl_table_no_const **table,
110257 unsigned int users)
110258 {
110259 if (users > 0)
110260 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
110261 index f641751..d3c5b51 100644
110262 --- a/net/netfilter/nf_conntrack_standalone.c
110263 +++ b/net/netfilter/nf_conntrack_standalone.c
110264 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
110265
110266 static int nf_conntrack_standalone_init_sysctl(struct net *net)
110267 {
110268 - struct ctl_table *table;
110269 + ctl_table_no_const *table;
110270
110271 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
110272 GFP_KERNEL);
110273 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
110274 index 7a394df..bd91a8a 100644
110275 --- a/net/netfilter/nf_conntrack_timestamp.c
110276 +++ b/net/netfilter/nf_conntrack_timestamp.c
110277 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
110278 #ifdef CONFIG_SYSCTL
110279 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
110280 {
110281 - struct ctl_table *table;
110282 + ctl_table_no_const *table;
110283
110284 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
110285 GFP_KERNEL);
110286 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
110287 index 85296d4..8becdec 100644
110288 --- a/net/netfilter/nf_log.c
110289 +++ b/net/netfilter/nf_log.c
110290 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
110291
110292 #ifdef CONFIG_SYSCTL
110293 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
110294 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
110295 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
110296
110297 static int nf_log_proc_dostring(struct ctl_table *table, int write,
110298 void __user *buffer, size_t *lenp, loff_t *ppos)
110299 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
110300 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
110301 mutex_unlock(&nf_log_mutex);
110302 } else {
110303 + ctl_table_no_const nf_log_table = *table;
110304 +
110305 mutex_lock(&nf_log_mutex);
110306 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
110307 lockdep_is_held(&nf_log_mutex));
110308 if (!logger)
110309 - table->data = "NONE";
110310 + nf_log_table.data = "NONE";
110311 else
110312 - table->data = logger->name;
110313 - r = proc_dostring(table, write, buffer, lenp, ppos);
110314 + nf_log_table.data = logger->name;
110315 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
110316 mutex_unlock(&nf_log_mutex);
110317 }
110318
110319 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
110320 index f042ae5..30ea486 100644
110321 --- a/net/netfilter/nf_sockopt.c
110322 +++ b/net/netfilter/nf_sockopt.c
110323 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
110324 }
110325 }
110326
110327 - list_add(&reg->list, &nf_sockopts);
110328 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
110329 out:
110330 mutex_unlock(&nf_sockopt_mutex);
110331 return ret;
110332 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
110333 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
110334 {
110335 mutex_lock(&nf_sockopt_mutex);
110336 - list_del(&reg->list);
110337 + pax_list_del((struct list_head *)&reg->list);
110338 mutex_unlock(&nf_sockopt_mutex);
110339 }
110340 EXPORT_SYMBOL(nf_unregister_sockopt);
110341 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
110342 index d292c8d..9f1e166 100644
110343 --- a/net/netfilter/nfnetlink_log.c
110344 +++ b/net/netfilter/nfnetlink_log.c
110345 @@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
110346 struct nfnl_log_net {
110347 spinlock_t instances_lock;
110348 struct hlist_head instance_table[INSTANCE_BUCKETS];
110349 - atomic_t global_seq;
110350 + atomic_unchecked_t global_seq;
110351 };
110352
110353 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
110354 @@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
110355 /* global sequence number */
110356 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
110357 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
110358 - htonl(atomic_inc_return(&log->global_seq))))
110359 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
110360 goto nla_put_failure;
110361
110362 if (data_len) {
110363 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
110364 index 1840989..6895744 100644
110365 --- a/net/netfilter/nft_compat.c
110366 +++ b/net/netfilter/nft_compat.c
110367 @@ -225,7 +225,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
110368 /* We want to reuse existing compat_to_user */
110369 old_fs = get_fs();
110370 set_fs(KERNEL_DS);
110371 - t->compat_to_user(out, in);
110372 + t->compat_to_user((void __force_user *)out, in);
110373 set_fs(old_fs);
110374 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
110375 kfree(out);
110376 @@ -421,7 +421,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
110377 /* We want to reuse existing compat_to_user */
110378 old_fs = get_fs();
110379 set_fs(KERNEL_DS);
110380 - m->compat_to_user(out, in);
110381 + m->compat_to_user((void __force_user *)out, in);
110382 set_fs(old_fs);
110383 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
110384 kfree(out);
110385 diff --git a/net/netfilter/xt_bpf.c b/net/netfilter/xt_bpf.c
110386 index bbffdbda..12d4da8 100644
110387 --- a/net/netfilter/xt_bpf.c
110388 +++ b/net/netfilter/xt_bpf.c
110389 @@ -23,11 +23,10 @@ MODULE_ALIAS("ip6t_bpf");
110390 static int bpf_mt_check(const struct xt_mtchk_param *par)
110391 {
110392 struct xt_bpf_info *info = par->matchinfo;
110393 - struct sock_fprog_kern program;
110394 + struct sock_fprog program;
110395
110396 program.len = info->bpf_program_num_elem;
110397 - program.filter = info->bpf_program;
110398 -
110399 + program.filter = (struct sock_filter __user *) info->bpf_program;
110400 if (sk_unattached_filter_create(&info->filter, &program)) {
110401 pr_info("bpf: check failed: parse error\n");
110402 return -EINVAL;
110403 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
110404 new file mode 100644
110405 index 0000000..c566332
110406 --- /dev/null
110407 +++ b/net/netfilter/xt_gradm.c
110408 @@ -0,0 +1,51 @@
110409 +/*
110410 + * gradm match for netfilter
110411 + * Copyright © Zbigniew Krzystolik, 2010
110412 + *
110413 + * This program is free software; you can redistribute it and/or modify
110414 + * it under the terms of the GNU General Public License; either version
110415 + * 2 or 3 as published by the Free Software Foundation.
110416 + */
110417 +#include <linux/module.h>
110418 +#include <linux/moduleparam.h>
110419 +#include <linux/skbuff.h>
110420 +#include <linux/netfilter/x_tables.h>
110421 +#include <linux/grsecurity.h>
110422 +#include <linux/netfilter/xt_gradm.h>
110423 +
110424 +static bool
110425 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
110426 +{
110427 + const struct xt_gradm_mtinfo *info = par->matchinfo;
110428 + bool retval = false;
110429 + if (gr_acl_is_enabled())
110430 + retval = true;
110431 + return retval ^ info->invflags;
110432 +}
110433 +
110434 +static struct xt_match gradm_mt_reg __read_mostly = {
110435 + .name = "gradm",
110436 + .revision = 0,
110437 + .family = NFPROTO_UNSPEC,
110438 + .match = gradm_mt,
110439 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
110440 + .me = THIS_MODULE,
110441 +};
110442 +
110443 +static int __init gradm_mt_init(void)
110444 +{
110445 + return xt_register_match(&gradm_mt_reg);
110446 +}
110447 +
110448 +static void __exit gradm_mt_exit(void)
110449 +{
110450 + xt_unregister_match(&gradm_mt_reg);
110451 +}
110452 +
110453 +module_init(gradm_mt_init);
110454 +module_exit(gradm_mt_exit);
110455 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
110456 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
110457 +MODULE_LICENSE("GPL");
110458 +MODULE_ALIAS("ipt_gradm");
110459 +MODULE_ALIAS("ip6t_gradm");
110460 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
110461 index a3910fc..2d2ba14 100644
110462 --- a/net/netfilter/xt_hashlimit.c
110463 +++ b/net/netfilter/xt_hashlimit.c
110464 @@ -870,11 +870,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
110465 {
110466 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
110467
110468 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
110469 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
110470 if (!hashlimit_net->ipt_hashlimit)
110471 return -ENOMEM;
110472 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
110473 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
110474 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
110475 if (!hashlimit_net->ip6t_hashlimit) {
110476 remove_proc_entry("ipt_hashlimit", net->proc_net);
110477 return -ENOMEM;
110478 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
110479 index a9faae8..1ea30e0 100644
110480 --- a/net/netfilter/xt_recent.c
110481 +++ b/net/netfilter/xt_recent.c
110482 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
110483 {
110484 struct recent_net *recent_net = recent_pernet(net);
110485
110486 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
110487 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
110488 if (!recent_net->xt_recent)
110489 return -ENOMEM;
110490 return 0;
110491 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
110492 index 11de55e..f25e448 100644
110493 --- a/net/netfilter/xt_statistic.c
110494 +++ b/net/netfilter/xt_statistic.c
110495 @@ -19,7 +19,7 @@
110496 #include <linux/module.h>
110497
110498 struct xt_statistic_priv {
110499 - atomic_t count;
110500 + atomic_unchecked_t count;
110501 } ____cacheline_aligned_in_smp;
110502
110503 MODULE_LICENSE("GPL");
110504 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
110505 break;
110506 case XT_STATISTIC_MODE_NTH:
110507 do {
110508 - oval = atomic_read(&info->master->count);
110509 + oval = atomic_read_unchecked(&info->master->count);
110510 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
110511 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
110512 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
110513 if (nval == 0)
110514 ret = !ret;
110515 break;
110516 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
110517 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
110518 if (info->master == NULL)
110519 return -ENOMEM;
110520 - atomic_set(&info->master->count, info->u.nth.count);
110521 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
110522
110523 return 0;
110524 }
110525 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
110526 index e6fac7e..cdcd25e 100644
110527 --- a/net/netlink/af_netlink.c
110528 +++ b/net/netlink/af_netlink.c
110529 @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
110530 sk->sk_error_report(sk);
110531 }
110532 }
110533 - atomic_inc(&sk->sk_drops);
110534 + atomic_inc_unchecked(&sk->sk_drops);
110535 }
110536
110537 static void netlink_rcv_wake(struct sock *sk)
110538 @@ -3058,7 +3058,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
110539 sk_wmem_alloc_get(s),
110540 nlk->cb_running,
110541 atomic_read(&s->sk_refcnt),
110542 - atomic_read(&s->sk_drops),
110543 + atomic_read_unchecked(&s->sk_drops),
110544 sock_i_ino(s)
110545 );
110546
110547 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
110548 index b85c67c..09705b7 100644
110549 --- a/net/packet/af_packet.c
110550 +++ b/net/packet/af_packet.c
110551 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
110552
110553 return ret;
110554 drop:
110555 - atomic_long_inc(&dev->tx_dropped);
110556 + atomic_long_inc_unchecked(&dev->tx_dropped);
110557 kfree_skb(skb);
110558 return NET_XMIT_DROP;
110559 }
110560 @@ -636,6 +636,7 @@ static void init_prb_bdqc(struct packet_sock *po,
110561 p1->tov_in_jiffies = msecs_to_jiffies(p1->retire_blk_tov);
110562 p1->blk_sizeof_priv = req_u->req3.tp_sizeof_priv;
110563
110564 + p1->max_frame_len = p1->kblk_size - BLK_PLUS_PRIV(p1->blk_sizeof_priv);
110565 prb_init_ft_ops(p1, req_u);
110566 prb_setup_retire_blk_timer(po, tx_ring);
110567 prb_open_block(p1, pbd);
110568 @@ -1845,7 +1846,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
110569
110570 spin_lock(&sk->sk_receive_queue.lock);
110571 po->stats.stats1.tp_packets++;
110572 - skb->dropcount = atomic_read(&sk->sk_drops);
110573 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
110574 __skb_queue_tail(&sk->sk_receive_queue, skb);
110575 spin_unlock(&sk->sk_receive_queue.lock);
110576 sk->sk_data_ready(sk);
110577 @@ -1854,7 +1855,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
110578 drop_n_acct:
110579 spin_lock(&sk->sk_receive_queue.lock);
110580 po->stats.stats1.tp_drops++;
110581 - atomic_inc(&sk->sk_drops);
110582 + atomic_inc_unchecked(&sk->sk_drops);
110583 spin_unlock(&sk->sk_receive_queue.lock);
110584
110585 drop_n_restore:
110586 @@ -1946,6 +1947,18 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
110587 if ((int)snaplen < 0)
110588 snaplen = 0;
110589 }
110590 + } else if (unlikely(macoff + snaplen >
110591 + GET_PBDQC_FROM_RB(&po->rx_ring)->max_frame_len)) {
110592 + u32 nval;
110593 +
110594 + nval = GET_PBDQC_FROM_RB(&po->rx_ring)->max_frame_len - macoff;
110595 + pr_err_once("tpacket_rcv: packet too big, clamped from %u to %u. macoff=%u\n",
110596 + snaplen, nval, macoff);
110597 + snaplen = nval;
110598 + if (unlikely((int)snaplen < 0)) {
110599 + snaplen = 0;
110600 + macoff = GET_PBDQC_FROM_RB(&po->rx_ring)->max_frame_len;
110601 + }
110602 }
110603 spin_lock(&sk->sk_receive_queue.lock);
110604 h.raw = packet_current_rx_frame(po, skb,
110605 @@ -3459,7 +3472,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
110606 case PACKET_HDRLEN:
110607 if (len > sizeof(int))
110608 len = sizeof(int);
110609 - if (copy_from_user(&val, optval, len))
110610 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
110611 return -EFAULT;
110612 switch (val) {
110613 case TPACKET_V1:
110614 @@ -3505,7 +3518,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
110615 len = lv;
110616 if (put_user(len, optlen))
110617 return -EFAULT;
110618 - if (copy_to_user(optval, data, len))
110619 + if (len > sizeof(st) || copy_to_user(optval, data, len))
110620 return -EFAULT;
110621 return 0;
110622 }
110623 @@ -3789,6 +3802,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
110624 goto out;
110625 if (unlikely(req->tp_block_size & (PAGE_SIZE - 1)))
110626 goto out;
110627 + if (po->tp_version >= TPACKET_V3 &&
110628 + (int)(req->tp_block_size -
110629 + BLK_PLUS_PRIV(req_u->req3.tp_sizeof_priv)) <= 0)
110630 + goto out;
110631 if (unlikely(req->tp_frame_size < po->tp_hdrlen +
110632 po->tp_reserve))
110633 goto out;
110634 diff --git a/net/packet/internal.h b/net/packet/internal.h
110635 index eb9580a..cdddf6a 100644
110636 --- a/net/packet/internal.h
110637 +++ b/net/packet/internal.h
110638 @@ -29,6 +29,7 @@ struct tpacket_kbdq_core {
110639 char *pkblk_start;
110640 char *pkblk_end;
110641 int kblk_size;
110642 + unsigned int max_frame_len;
110643 unsigned int knum_blocks;
110644 uint64_t knxt_seq_num;
110645 char *prev;
110646 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
110647 index 70a547e..23477fe 100644
110648 --- a/net/phonet/pep.c
110649 +++ b/net/phonet/pep.c
110650 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
110651
110652 case PNS_PEP_CTRL_REQ:
110653 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
110654 - atomic_inc(&sk->sk_drops);
110655 + atomic_inc_unchecked(&sk->sk_drops);
110656 break;
110657 }
110658 __skb_pull(skb, 4);
110659 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
110660 }
110661
110662 if (pn->rx_credits == 0) {
110663 - atomic_inc(&sk->sk_drops);
110664 + atomic_inc_unchecked(&sk->sk_drops);
110665 err = -ENOBUFS;
110666 break;
110667 }
110668 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
110669 }
110670
110671 if (pn->rx_credits == 0) {
110672 - atomic_inc(&sk->sk_drops);
110673 + atomic_inc_unchecked(&sk->sk_drops);
110674 err = NET_RX_DROP;
110675 break;
110676 }
110677 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
110678 index 008214a..bb68240 100644
110679 --- a/net/phonet/socket.c
110680 +++ b/net/phonet/socket.c
110681 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
110682 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
110683 sock_i_ino(sk),
110684 atomic_read(&sk->sk_refcnt), sk,
110685 - atomic_read(&sk->sk_drops));
110686 + atomic_read_unchecked(&sk->sk_drops));
110687 }
110688 seq_pad(seq, '\n');
110689 return 0;
110690 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
110691 index c02a8c4..3c5b600 100644
110692 --- a/net/phonet/sysctl.c
110693 +++ b/net/phonet/sysctl.c
110694 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
110695 {
110696 int ret;
110697 int range[2] = {local_port_range[0], local_port_range[1]};
110698 - struct ctl_table tmp = {
110699 + ctl_table_no_const tmp = {
110700 .data = &range,
110701 .maxlen = sizeof(range),
110702 .mode = table->mode,
110703 diff --git a/net/rds/cong.c b/net/rds/cong.c
110704 index e5b65ac..f3b6fb7 100644
110705 --- a/net/rds/cong.c
110706 +++ b/net/rds/cong.c
110707 @@ -78,7 +78,7 @@
110708 * finds that the saved generation number is smaller than the global generation
110709 * number, it wakes up the process.
110710 */
110711 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
110712 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
110713
110714 /*
110715 * Congestion monitoring
110716 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
110717 rdsdebug("waking map %p for %pI4\n",
110718 map, &map->m_addr);
110719 rds_stats_inc(s_cong_update_received);
110720 - atomic_inc(&rds_cong_generation);
110721 + atomic_inc_unchecked(&rds_cong_generation);
110722 if (waitqueue_active(&map->m_waitq))
110723 wake_up(&map->m_waitq);
110724 if (waitqueue_active(&rds_poll_waitq))
110725 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
110726
110727 int rds_cong_updated_since(unsigned long *recent)
110728 {
110729 - unsigned long gen = atomic_read(&rds_cong_generation);
110730 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
110731
110732 if (likely(*recent == gen))
110733 return 0;
110734 diff --git a/net/rds/ib.h b/net/rds/ib.h
110735 index 7280ab8..e04f4ea 100644
110736 --- a/net/rds/ib.h
110737 +++ b/net/rds/ib.h
110738 @@ -128,7 +128,7 @@ struct rds_ib_connection {
110739 /* sending acks */
110740 unsigned long i_ack_flags;
110741 #ifdef KERNEL_HAS_ATOMIC64
110742 - atomic64_t i_ack_next; /* next ACK to send */
110743 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
110744 #else
110745 spinlock_t i_ack_lock; /* protect i_ack_next */
110746 u64 i_ack_next; /* next ACK to send */
110747 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
110748 index 31b74f5..dc1fbfa 100644
110749 --- a/net/rds/ib_cm.c
110750 +++ b/net/rds/ib_cm.c
110751 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
110752 /* Clear the ACK state */
110753 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
110754 #ifdef KERNEL_HAS_ATOMIC64
110755 - atomic64_set(&ic->i_ack_next, 0);
110756 + atomic64_set_unchecked(&ic->i_ack_next, 0);
110757 #else
110758 ic->i_ack_next = 0;
110759 #endif
110760 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
110761 index d67de45..73dbf51 100644
110762 --- a/net/rds/ib_recv.c
110763 +++ b/net/rds/ib_recv.c
110764 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
110765 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
110766 int ack_required)
110767 {
110768 - atomic64_set(&ic->i_ack_next, seq);
110769 + atomic64_set_unchecked(&ic->i_ack_next, seq);
110770 if (ack_required) {
110771 smp_mb__before_atomic();
110772 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
110773 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
110774 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
110775 smp_mb__after_atomic();
110776
110777 - return atomic64_read(&ic->i_ack_next);
110778 + return atomic64_read_unchecked(&ic->i_ack_next);
110779 }
110780 #endif
110781
110782 diff --git a/net/rds/iw.h b/net/rds/iw.h
110783 index 04ce3b1..48119a6 100644
110784 --- a/net/rds/iw.h
110785 +++ b/net/rds/iw.h
110786 @@ -134,7 +134,7 @@ struct rds_iw_connection {
110787 /* sending acks */
110788 unsigned long i_ack_flags;
110789 #ifdef KERNEL_HAS_ATOMIC64
110790 - atomic64_t i_ack_next; /* next ACK to send */
110791 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
110792 #else
110793 spinlock_t i_ack_lock; /* protect i_ack_next */
110794 u64 i_ack_next; /* next ACK to send */
110795 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
110796 index a91e1db..cf3053f 100644
110797 --- a/net/rds/iw_cm.c
110798 +++ b/net/rds/iw_cm.c
110799 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
110800 /* Clear the ACK state */
110801 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
110802 #ifdef KERNEL_HAS_ATOMIC64
110803 - atomic64_set(&ic->i_ack_next, 0);
110804 + atomic64_set_unchecked(&ic->i_ack_next, 0);
110805 #else
110806 ic->i_ack_next = 0;
110807 #endif
110808 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
110809 index aa8bf67..b70133c 100644
110810 --- a/net/rds/iw_recv.c
110811 +++ b/net/rds/iw_recv.c
110812 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
110813 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
110814 int ack_required)
110815 {
110816 - atomic64_set(&ic->i_ack_next, seq);
110817 + atomic64_set_unchecked(&ic->i_ack_next, seq);
110818 if (ack_required) {
110819 smp_mb__before_atomic();
110820 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
110821 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
110822 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
110823 smp_mb__after_atomic();
110824
110825 - return atomic64_read(&ic->i_ack_next);
110826 + return atomic64_read_unchecked(&ic->i_ack_next);
110827 }
110828 #endif
110829
110830 diff --git a/net/rds/rds.h b/net/rds/rds.h
110831 index 48f8ffc..0ef3eec 100644
110832 --- a/net/rds/rds.h
110833 +++ b/net/rds/rds.h
110834 @@ -449,7 +449,7 @@ struct rds_transport {
110835 void (*sync_mr)(void *trans_private, int direction);
110836 void (*free_mr)(void *trans_private, int invalidate);
110837 void (*flush_mrs)(void);
110838 -};
110839 +} __do_const;
110840
110841 struct rds_sock {
110842 struct sock rs_sk;
110843 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
110844 index edac9ef..16bcb98 100644
110845 --- a/net/rds/tcp.c
110846 +++ b/net/rds/tcp.c
110847 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
110848 int val = 1;
110849
110850 set_fs(KERNEL_DS);
110851 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
110852 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
110853 sizeof(val));
110854 set_fs(oldfs);
110855 }
110856 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
110857 index 53b17ca..45463e7 100644
110858 --- a/net/rds/tcp_send.c
110859 +++ b/net/rds/tcp_send.c
110860 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
110861
110862 oldfs = get_fs();
110863 set_fs(KERNEL_DS);
110864 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
110865 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
110866 sizeof(val));
110867 set_fs(oldfs);
110868 }
110869 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
110870 index 7b16704..9628ec6 100644
110871 --- a/net/rxrpc/af_rxrpc.c
110872 +++ b/net/rxrpc/af_rxrpc.c
110873 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
110874 __be32 rxrpc_epoch;
110875
110876 /* current debugging ID */
110877 -atomic_t rxrpc_debug_id;
110878 +atomic_unchecked_t rxrpc_debug_id;
110879
110880 /* count of skbs currently in use */
110881 atomic_t rxrpc_n_skbs;
110882 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
110883 index c6be17a..2a6200a 100644
110884 --- a/net/rxrpc/ar-ack.c
110885 +++ b/net/rxrpc/ar-ack.c
110886 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
110887
110888 _enter("{%d,%d,%d,%d},",
110889 call->acks_hard, call->acks_unacked,
110890 - atomic_read(&call->sequence),
110891 + atomic_read_unchecked(&call->sequence),
110892 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
110893
110894 stop = 0;
110895 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
110896
110897 /* each Tx packet has a new serial number */
110898 sp->hdr.serial =
110899 - htonl(atomic_inc_return(&call->conn->serial));
110900 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
110901
110902 hdr = (struct rxrpc_header *) txb->head;
110903 hdr->serial = sp->hdr.serial;
110904 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
110905 */
110906 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
110907 {
110908 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
110909 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
110910 }
110911
110912 /*
110913 @@ -677,7 +677,7 @@ process_further:
110914
110915 latest = ntohl(sp->hdr.serial);
110916 hard = ntohl(ack.firstPacket);
110917 - tx = atomic_read(&call->sequence);
110918 + tx = atomic_read_unchecked(&call->sequence);
110919
110920 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
110921 latest,
110922 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
110923 goto maybe_reschedule;
110924
110925 send_ACK_with_skew:
110926 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
110927 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
110928 ntohl(ack.serial));
110929 send_ACK:
110930 mtu = call->conn->trans->peer->if_mtu;
110931 @@ -1221,7 +1221,7 @@ send_ACK:
110932 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
110933 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
110934
110935 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
110936 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
110937 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
110938 ntohl(hdr.serial),
110939 ntohs(ack.maxSkew),
110940 @@ -1239,7 +1239,7 @@ send_ACK:
110941 send_message:
110942 _debug("send message");
110943
110944 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
110945 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
110946 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
110947 send_message_2:
110948
110949 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
110950 index a9e05db..194e793 100644
110951 --- a/net/rxrpc/ar-call.c
110952 +++ b/net/rxrpc/ar-call.c
110953 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
110954 spin_lock_init(&call->lock);
110955 rwlock_init(&call->state_lock);
110956 atomic_set(&call->usage, 1);
110957 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
110958 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
110959 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
110960
110961 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
110962 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
110963 index 6631f4f..bfdf056 100644
110964 --- a/net/rxrpc/ar-connection.c
110965 +++ b/net/rxrpc/ar-connection.c
110966 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
110967 rwlock_init(&conn->lock);
110968 spin_lock_init(&conn->state_lock);
110969 atomic_set(&conn->usage, 1);
110970 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
110971 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
110972 conn->avail_calls = RXRPC_MAXCALLS;
110973 conn->size_align = 4;
110974 conn->header_size = sizeof(struct rxrpc_header);
110975 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
110976 index e7ed43a..6afa140 100644
110977 --- a/net/rxrpc/ar-connevent.c
110978 +++ b/net/rxrpc/ar-connevent.c
110979 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
110980
110981 len = iov[0].iov_len + iov[1].iov_len;
110982
110983 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
110984 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
110985 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
110986
110987 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
110988 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
110989 index 63b21e5..330232e 100644
110990 --- a/net/rxrpc/ar-input.c
110991 +++ b/net/rxrpc/ar-input.c
110992 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
110993 /* track the latest serial number on this connection for ACK packet
110994 * information */
110995 serial = ntohl(sp->hdr.serial);
110996 - hi_serial = atomic_read(&call->conn->hi_serial);
110997 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
110998 while (serial > hi_serial)
110999 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
111000 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
111001 serial);
111002
111003 /* request ACK generation for any ACK or DATA packet that requests
111004 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
111005 index ba9fd36..9bbfe01 100644
111006 --- a/net/rxrpc/ar-internal.h
111007 +++ b/net/rxrpc/ar-internal.h
111008 @@ -272,8 +272,8 @@ struct rxrpc_connection {
111009 int error; /* error code for local abort */
111010 int debug_id; /* debug ID for printks */
111011 unsigned int call_counter; /* call ID counter */
111012 - atomic_t serial; /* packet serial number counter */
111013 - atomic_t hi_serial; /* highest serial number received */
111014 + atomic_unchecked_t serial; /* packet serial number counter */
111015 + atomic_unchecked_t hi_serial; /* highest serial number received */
111016 u8 avail_calls; /* number of calls available */
111017 u8 size_align; /* data size alignment (for security) */
111018 u8 header_size; /* rxrpc + security header size */
111019 @@ -346,7 +346,7 @@ struct rxrpc_call {
111020 spinlock_t lock;
111021 rwlock_t state_lock; /* lock for state transition */
111022 atomic_t usage;
111023 - atomic_t sequence; /* Tx data packet sequence counter */
111024 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
111025 u32 abort_code; /* local/remote abort code */
111026 enum { /* current state of call */
111027 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
111028 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
111029 */
111030 extern atomic_t rxrpc_n_skbs;
111031 extern __be32 rxrpc_epoch;
111032 -extern atomic_t rxrpc_debug_id;
111033 +extern atomic_unchecked_t rxrpc_debug_id;
111034 extern struct workqueue_struct *rxrpc_workqueue;
111035
111036 /*
111037 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
111038 index 87f7135..74d3703 100644
111039 --- a/net/rxrpc/ar-local.c
111040 +++ b/net/rxrpc/ar-local.c
111041 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
111042 spin_lock_init(&local->lock);
111043 rwlock_init(&local->services_lock);
111044 atomic_set(&local->usage, 1);
111045 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
111046 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
111047 memcpy(&local->srx, srx, sizeof(*srx));
111048 }
111049
111050 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
111051 index 0b4b9a7..966ffbb 100644
111052 --- a/net/rxrpc/ar-output.c
111053 +++ b/net/rxrpc/ar-output.c
111054 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
111055 memset(skb_put(skb, pad), 0, pad);
111056 }
111057
111058 - seq = atomic_inc_return(&call->sequence);
111059 + seq = atomic_inc_return_unchecked(&call->sequence);
111060
111061 sp->hdr.epoch = conn->epoch;
111062 sp->hdr.cid = call->cid;
111063 sp->hdr.callNumber = call->call_id;
111064 sp->hdr.seq = htonl(seq);
111065 sp->hdr.serial =
111066 - htonl(atomic_inc_return(&conn->serial));
111067 + htonl(atomic_inc_return_unchecked(&conn->serial));
111068 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
111069 sp->hdr.userStatus = 0;
111070 sp->hdr.securityIndex = conn->security_ix;
111071 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
111072 index bebaa43..2644591 100644
111073 --- a/net/rxrpc/ar-peer.c
111074 +++ b/net/rxrpc/ar-peer.c
111075 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
111076 INIT_LIST_HEAD(&peer->error_targets);
111077 spin_lock_init(&peer->lock);
111078 atomic_set(&peer->usage, 1);
111079 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
111080 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
111081 memcpy(&peer->srx, srx, sizeof(*srx));
111082
111083 rxrpc_assess_MTU_size(peer);
111084 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
111085 index 38047f7..9f48511 100644
111086 --- a/net/rxrpc/ar-proc.c
111087 +++ b/net/rxrpc/ar-proc.c
111088 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
111089 atomic_read(&conn->usage),
111090 rxrpc_conn_states[conn->state],
111091 key_serial(conn->key),
111092 - atomic_read(&conn->serial),
111093 - atomic_read(&conn->hi_serial));
111094 + atomic_read_unchecked(&conn->serial),
111095 + atomic_read_unchecked(&conn->hi_serial));
111096
111097 return 0;
111098 }
111099 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
111100 index 1976dec..aa70be5 100644
111101 --- a/net/rxrpc/ar-transport.c
111102 +++ b/net/rxrpc/ar-transport.c
111103 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
111104 spin_lock_init(&trans->client_lock);
111105 rwlock_init(&trans->conn_lock);
111106 atomic_set(&trans->usage, 1);
111107 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
111108 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
111109
111110 if (peer->srx.transport.family == AF_INET) {
111111 switch (peer->srx.transport_type) {
111112 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
111113 index f226709..0e735a8 100644
111114 --- a/net/rxrpc/rxkad.c
111115 +++ b/net/rxrpc/rxkad.c
111116 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
111117
111118 len = iov[0].iov_len + iov[1].iov_len;
111119
111120 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
111121 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
111122 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
111123
111124 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
111125 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
111126
111127 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
111128
111129 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
111130 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
111131 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
111132
111133 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
111134 diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
111135 index 13f64df..1618696 100644
111136 --- a/net/sched/cls_bpf.c
111137 +++ b/net/sched/cls_bpf.c
111138 @@ -160,7 +160,7 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
111139 {
111140 struct sock_filter *bpf_ops, *bpf_old;
111141 struct tcf_exts exts;
111142 - struct sock_fprog_kern tmp;
111143 + struct sock_fprog tmp;
111144 struct sk_filter *fp, *fp_old;
111145 u16 bpf_size, bpf_len;
111146 u32 classid;
111147 @@ -191,7 +191,7 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
111148 memcpy(bpf_ops, nla_data(tb[TCA_BPF_OPS]), bpf_size);
111149
111150 tmp.len = bpf_len;
111151 - tmp.filter = bpf_ops;
111152 + tmp.filter = (struct sock_filter __user *) bpf_ops;
111153
111154 ret = sk_unattached_filter_create(&fp, &tmp);
111155 if (ret)
111156 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
111157 index e1543b0..7ce8bd0 100644
111158 --- a/net/sched/sch_generic.c
111159 +++ b/net/sched/sch_generic.c
111160 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
111161 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
111162 if (dev->reg_state == NETREG_UNINITIALIZED)
111163 return;
111164 - atomic_inc(&dev->carrier_changes);
111165 + atomic_inc_unchecked(&dev->carrier_changes);
111166 linkwatch_fire_event(dev);
111167 if (netif_running(dev))
111168 __netdev_watchdog_up(dev);
111169 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
111170 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
111171 if (dev->reg_state == NETREG_UNINITIALIZED)
111172 return;
111173 - atomic_inc(&dev->carrier_changes);
111174 + atomic_inc_unchecked(&dev->carrier_changes);
111175 linkwatch_fire_event(dev);
111176 }
111177 }
111178 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
111179 index 1999592..6684af6 100644
111180 --- a/net/sctp/ipv6.c
111181 +++ b/net/sctp/ipv6.c
111182 @@ -964,7 +964,7 @@ static const struct inet6_protocol sctpv6_protocol = {
111183 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
111184 };
111185
111186 -static struct sctp_af sctp_af_inet6 = {
111187 +static struct sctp_af sctp_af_inet6 __read_only = {
111188 .sa_family = AF_INET6,
111189 .sctp_xmit = sctp_v6_xmit,
111190 .setsockopt = ipv6_setsockopt,
111191 @@ -996,7 +996,7 @@ static struct sctp_af sctp_af_inet6 = {
111192 #endif
111193 };
111194
111195 -static struct sctp_pf sctp_pf_inet6 = {
111196 +static struct sctp_pf sctp_pf_inet6 __read_only = {
111197 .event_msgname = sctp_inet6_event_msgname,
111198 .skb_msgname = sctp_inet6_skb_msgname,
111199 .af_supported = sctp_inet6_af_supported,
111200 @@ -1021,7 +1021,7 @@ void sctp_v6_pf_init(void)
111201
111202 void sctp_v6_pf_exit(void)
111203 {
111204 - list_del(&sctp_af_inet6.list);
111205 + pax_list_del(&sctp_af_inet6.list);
111206 }
111207
111208 /* Initialize IPv6 support and register with socket layer. */
111209 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
111210 index 6789d785..0798d76 100644
111211 --- a/net/sctp/protocol.c
111212 +++ b/net/sctp/protocol.c
111213 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
111214 return 0;
111215 }
111216
111217 + pax_open_kernel();
111218 INIT_LIST_HEAD(&af->list);
111219 - list_add_tail(&af->list, &sctp_address_families);
111220 + pax_close_kernel();
111221 + pax_list_add_tail(&af->list, &sctp_address_families);
111222 return 1;
111223 }
111224
111225 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
111226
111227 static struct sctp_af sctp_af_inet;
111228
111229 -static struct sctp_pf sctp_pf_inet = {
111230 +static struct sctp_pf sctp_pf_inet __read_only = {
111231 .event_msgname = sctp_inet_event_msgname,
111232 .skb_msgname = sctp_inet_skb_msgname,
111233 .af_supported = sctp_inet_af_supported,
111234 @@ -1037,7 +1039,7 @@ static const struct net_protocol sctp_protocol = {
111235 };
111236
111237 /* IPv4 address related functions. */
111238 -static struct sctp_af sctp_af_inet = {
111239 +static struct sctp_af sctp_af_inet __read_only = {
111240 .sa_family = AF_INET,
111241 .sctp_xmit = sctp_v4_xmit,
111242 .setsockopt = ip_setsockopt,
111243 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
111244
111245 static void sctp_v4_pf_exit(void)
111246 {
111247 - list_del(&sctp_af_inet.list);
111248 + pax_list_del(&sctp_af_inet.list);
111249 }
111250
111251 static int sctp_v4_protosw_init(void)
111252 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
111253 index fef2acd..c705c4f 100644
111254 --- a/net/sctp/sm_sideeffect.c
111255 +++ b/net/sctp/sm_sideeffect.c
111256 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
111257 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
111258 }
111259
111260 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
111261 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
111262 NULL,
111263 sctp_generate_t1_cookie_event,
111264 sctp_generate_t1_init_event,
111265 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
111266 index 4298996..fa5f636 100644
111267 --- a/net/sctp/socket.c
111268 +++ b/net/sctp/socket.c
111269 @@ -2176,11 +2176,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
111270 {
111271 struct sctp_association *asoc;
111272 struct sctp_ulpevent *event;
111273 + struct sctp_event_subscribe subscribe;
111274
111275 if (optlen > sizeof(struct sctp_event_subscribe))
111276 return -EINVAL;
111277 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
111278 + if (copy_from_user(&subscribe, optval, optlen))
111279 return -EFAULT;
111280 + sctp_sk(sk)->subscribe = subscribe;
111281
111282 /*
111283 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
111284 @@ -4260,13 +4262,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
111285 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
111286 int __user *optlen)
111287 {
111288 + struct sctp_event_subscribe subscribe;
111289 +
111290 if (len <= 0)
111291 return -EINVAL;
111292 if (len > sizeof(struct sctp_event_subscribe))
111293 len = sizeof(struct sctp_event_subscribe);
111294 if (put_user(len, optlen))
111295 return -EFAULT;
111296 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
111297 + subscribe = sctp_sk(sk)->subscribe;
111298 + if (copy_to_user(optval, &subscribe, len))
111299 return -EFAULT;
111300 return 0;
111301 }
111302 @@ -4284,6 +4289,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
111303 */
111304 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
111305 {
111306 + __u32 autoclose;
111307 +
111308 /* Applicable to UDP-style socket only */
111309 if (sctp_style(sk, TCP))
111310 return -EOPNOTSUPP;
111311 @@ -4292,7 +4299,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
111312 len = sizeof(int);
111313 if (put_user(len, optlen))
111314 return -EFAULT;
111315 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
111316 + autoclose = sctp_sk(sk)->autoclose;
111317 + if (copy_to_user(optval, &autoclose, sizeof(int)))
111318 return -EFAULT;
111319 return 0;
111320 }
111321 @@ -4667,12 +4675,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
111322 */
111323 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
111324 {
111325 + struct sctp_initmsg initmsg;
111326 +
111327 if (len < sizeof(struct sctp_initmsg))
111328 return -EINVAL;
111329 len = sizeof(struct sctp_initmsg);
111330 if (put_user(len, optlen))
111331 return -EFAULT;
111332 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
111333 + initmsg = sctp_sk(sk)->initmsg;
111334 + if (copy_to_user(optval, &initmsg, len))
111335 return -EFAULT;
111336 return 0;
111337 }
111338 @@ -4713,6 +4724,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
111339 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
111340 if (space_left < addrlen)
111341 return -ENOMEM;
111342 + if (addrlen > sizeof(temp) || addrlen < 0)
111343 + return -EFAULT;
111344 if (copy_to_user(to, &temp, addrlen))
111345 return -EFAULT;
111346 to += addrlen;
111347 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
111348 index 12c7e01..a755b3e 100644
111349 --- a/net/sctp/sysctl.c
111350 +++ b/net/sctp/sysctl.c
111351 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
111352 loff_t *ppos)
111353 {
111354 struct net *net = current->nsproxy->net_ns;
111355 - struct ctl_table tbl;
111356 + ctl_table_no_const tbl;
111357 bool changed = false;
111358 char *none = "none";
111359 char tmp[8];
111360 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
111361 struct net *net = current->nsproxy->net_ns;
111362 unsigned int min = *(unsigned int *) ctl->extra1;
111363 unsigned int max = *(unsigned int *) ctl->extra2;
111364 - struct ctl_table tbl;
111365 + ctl_table_no_const tbl;
111366 int ret, new_value;
111367
111368 memset(&tbl, 0, sizeof(struct ctl_table));
111369 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
111370 struct net *net = current->nsproxy->net_ns;
111371 unsigned int min = *(unsigned int *) ctl->extra1;
111372 unsigned int max = *(unsigned int *) ctl->extra2;
111373 - struct ctl_table tbl;
111374 + ctl_table_no_const tbl;
111375 int ret, new_value;
111376
111377 memset(&tbl, 0, sizeof(struct ctl_table));
111378 @@ -435,7 +435,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
111379 loff_t *ppos)
111380 {
111381 struct net *net = current->nsproxy->net_ns;
111382 - struct ctl_table tbl;
111383 + ctl_table_no_const tbl;
111384 int new_value, ret;
111385
111386 memset(&tbl, 0, sizeof(struct ctl_table));
111387 @@ -462,7 +462,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
111388
111389 int sctp_sysctl_net_register(struct net *net)
111390 {
111391 - struct ctl_table *table;
111392 + ctl_table_no_const *table;
111393 int i;
111394
111395 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
111396 diff --git a/net/socket.c b/net/socket.c
111397 index abf56b2..4cac767 100644
111398 --- a/net/socket.c
111399 +++ b/net/socket.c
111400 @@ -72,7 +72,6 @@
111401 #include <linux/if_bridge.h>
111402 #include <linux/if_frad.h>
111403 #include <linux/if_vlan.h>
111404 -#include <linux/ptp_classify.h>
111405 #include <linux/init.h>
111406 #include <linux/poll.h>
111407 #include <linux/cache.h>
111408 @@ -89,6 +88,7 @@
111409 #include <linux/magic.h>
111410 #include <linux/slab.h>
111411 #include <linux/xattr.h>
111412 +#include <linux/in.h>
111413
111414 #include <asm/uaccess.h>
111415 #include <asm/unistd.h>
111416 @@ -112,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
111417 unsigned int sysctl_net_busy_poll __read_mostly;
111418 #endif
111419
111420 +#include <linux/grsock.h>
111421 +
111422 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
111423 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
111424 unsigned long nr_segs, loff_t pos);
111425 @@ -163,7 +165,7 @@ static const struct file_operations socket_file_ops = {
111426 */
111427
111428 static DEFINE_SPINLOCK(net_family_lock);
111429 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
111430 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
111431
111432 /*
111433 * Statistics counters of the socket lists
111434 @@ -329,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
111435 &sockfs_dentry_operations, SOCKFS_MAGIC);
111436 }
111437
111438 -static struct vfsmount *sock_mnt __read_mostly;
111439 +struct vfsmount *sock_mnt __read_mostly;
111440
111441 static struct file_system_type sock_fs_type = {
111442 .name = "sockfs",
111443 @@ -1257,6 +1259,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
111444 return -EAFNOSUPPORT;
111445 if (type < 0 || type >= SOCK_MAX)
111446 return -EINVAL;
111447 + if (protocol < 0)
111448 + return -EINVAL;
111449
111450 /* Compatibility.
111451
111452 @@ -1277,6 +1281,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
111453 if (err)
111454 return err;
111455
111456 + if(!kern && !gr_search_socket(family, type, protocol)) {
111457 + if (rcu_access_pointer(net_families[family]) == NULL)
111458 + return -EAFNOSUPPORT;
111459 + else
111460 + return -EACCES;
111461 + }
111462 +
111463 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
111464 + if (rcu_access_pointer(net_families[family]) == NULL)
111465 + return -EAFNOSUPPORT;
111466 + else
111467 + return -EACCES;
111468 + }
111469 +
111470 /*
111471 * Allocate the socket and allow the family to set things up. if
111472 * the protocol is 0, the family is instructed to select an appropriate
111473 @@ -1528,6 +1546,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
111474 if (sock) {
111475 err = move_addr_to_kernel(umyaddr, addrlen, &address);
111476 if (err >= 0) {
111477 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
111478 + err = -EACCES;
111479 + goto error;
111480 + }
111481 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
111482 + if (err)
111483 + goto error;
111484 +
111485 err = security_socket_bind(sock,
111486 (struct sockaddr *)&address,
111487 addrlen);
111488 @@ -1536,6 +1562,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
111489 (struct sockaddr *)
111490 &address, addrlen);
111491 }
111492 +error:
111493 fput_light(sock->file, fput_needed);
111494 }
111495 return err;
111496 @@ -1559,10 +1586,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
111497 if ((unsigned int)backlog > somaxconn)
111498 backlog = somaxconn;
111499
111500 + if (gr_handle_sock_server_other(sock->sk)) {
111501 + err = -EPERM;
111502 + goto error;
111503 + }
111504 +
111505 + err = gr_search_listen(sock);
111506 + if (err)
111507 + goto error;
111508 +
111509 err = security_socket_listen(sock, backlog);
111510 if (!err)
111511 err = sock->ops->listen(sock, backlog);
111512
111513 +error:
111514 fput_light(sock->file, fput_needed);
111515 }
111516 return err;
111517 @@ -1606,6 +1643,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
111518 newsock->type = sock->type;
111519 newsock->ops = sock->ops;
111520
111521 + if (gr_handle_sock_server_other(sock->sk)) {
111522 + err = -EPERM;
111523 + sock_release(newsock);
111524 + goto out_put;
111525 + }
111526 +
111527 + err = gr_search_accept(sock);
111528 + if (err) {
111529 + sock_release(newsock);
111530 + goto out_put;
111531 + }
111532 +
111533 /*
111534 * We don't need try_module_get here, as the listening socket (sock)
111535 * has the protocol module (sock->ops->owner) held.
111536 @@ -1651,6 +1700,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
111537 fd_install(newfd, newfile);
111538 err = newfd;
111539
111540 + gr_attach_curr_ip(newsock->sk);
111541 +
111542 out_put:
111543 fput_light(sock->file, fput_needed);
111544 out:
111545 @@ -1683,6 +1734,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
111546 int, addrlen)
111547 {
111548 struct socket *sock;
111549 + struct sockaddr *sck;
111550 struct sockaddr_storage address;
111551 int err, fput_needed;
111552
111553 @@ -1693,6 +1745,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
111554 if (err < 0)
111555 goto out_put;
111556
111557 + sck = (struct sockaddr *)&address;
111558 +
111559 + if (gr_handle_sock_client(sck)) {
111560 + err = -EACCES;
111561 + goto out_put;
111562 + }
111563 +
111564 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
111565 + if (err)
111566 + goto out_put;
111567 +
111568 err =
111569 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
111570 if (err)
111571 @@ -1774,6 +1837,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
111572 * the protocol.
111573 */
111574
111575 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
111576 +
111577 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
111578 unsigned int, flags, struct sockaddr __user *, addr,
111579 int, addr_len)
111580 @@ -1840,7 +1905,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
111581 struct socket *sock;
111582 struct iovec iov;
111583 struct msghdr msg;
111584 - struct sockaddr_storage address;
111585 + struct sockaddr_storage address = { };
111586 int err, err2;
111587 int fput_needed;
111588
111589 @@ -2066,7 +2131,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
111590 * checking falls down on this.
111591 */
111592 if (copy_from_user(ctl_buf,
111593 - (void __user __force *)msg_sys->msg_control,
111594 + (void __force_user *)msg_sys->msg_control,
111595 ctl_len))
111596 goto out_freectl;
111597 msg_sys->msg_control = ctl_buf;
111598 @@ -2217,7 +2282,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
111599 int err, total_len, len;
111600
111601 /* kernel mode address */
111602 - struct sockaddr_storage addr;
111603 + struct sockaddr_storage addr = { };
111604
111605 /* user mode address pointers */
111606 struct sockaddr __user *uaddr;
111607 @@ -2246,7 +2311,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
111608 /* Save the user-mode address (verify_iovec will change the
111609 * kernel msghdr to use the kernel address space)
111610 */
111611 - uaddr = (__force void __user *)msg_sys->msg_name;
111612 + uaddr = (void __force_user *)msg_sys->msg_name;
111613 uaddr_len = COMPAT_NAMELEN(msg);
111614 if (MSG_CMSG_COMPAT & flags)
111615 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
111616 @@ -2686,7 +2751,9 @@ static int __init sock_init(void)
111617 goto out;
111618 #endif
111619
111620 - ptp_classifier_init();
111621 +#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
111622 + skb_timestamping_init();
111623 +#endif
111624
111625 out:
111626 return err;
111627 @@ -2887,7 +2954,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
111628 ifr = compat_alloc_user_space(buf_size);
111629 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
111630
111631 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
111632 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
111633 return -EFAULT;
111634
111635 if (put_user(convert_in ? rxnfc : compat_ptr(data),
111636 @@ -2998,7 +3065,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
111637 old_fs = get_fs();
111638 set_fs(KERNEL_DS);
111639 err = dev_ioctl(net, cmd,
111640 - (struct ifreq __user __force *) &kifr);
111641 + (struct ifreq __force_user *) &kifr);
111642 set_fs(old_fs);
111643
111644 return err;
111645 @@ -3091,7 +3158,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
111646
111647 old_fs = get_fs();
111648 set_fs(KERNEL_DS);
111649 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
111650 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
111651 set_fs(old_fs);
111652
111653 if (cmd == SIOCGIFMAP && !err) {
111654 @@ -3175,7 +3242,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
111655 ret |= get_user(rtdev, &(ur4->rt_dev));
111656 if (rtdev) {
111657 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
111658 - r4.rt_dev = (char __user __force *)devname;
111659 + r4.rt_dev = (char __force_user *)devname;
111660 devname[15] = 0;
111661 } else
111662 r4.rt_dev = NULL;
111663 @@ -3402,8 +3469,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
111664 int __user *uoptlen;
111665 int err;
111666
111667 - uoptval = (char __user __force *) optval;
111668 - uoptlen = (int __user __force *) optlen;
111669 + uoptval = (char __force_user *) optval;
111670 + uoptlen = (int __force_user *) optlen;
111671
111672 set_fs(KERNEL_DS);
111673 if (level == SOL_SOCKET)
111674 @@ -3423,7 +3490,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
111675 char __user *uoptval;
111676 int err;
111677
111678 - uoptval = (char __user __force *) optval;
111679 + uoptval = (char __force_user *) optval;
111680
111681 set_fs(KERNEL_DS);
111682 if (level == SOL_SOCKET)
111683 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
111684 index 4ce5ecce..7bef300 100644
111685 --- a/net/sunrpc/auth_gss/svcauth_gss.c
111686 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
111687 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
111688 uint64_t *handle)
111689 {
111690 struct rsc rsci, *rscp = NULL;
111691 - static atomic64_t ctxhctr;
111692 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
111693 long long ctxh;
111694 struct gss_api_mech *gm = NULL;
111695 time_t expiry;
111696 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
111697 status = -ENOMEM;
111698 /* the handle needs to be just a unique id,
111699 * use a static counter */
111700 - ctxh = atomic64_inc_return(&ctxhctr);
111701 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
111702
111703 /* make a copy for the caller */
111704 *handle = ctxh;
111705 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
111706 index 0663621..c4928d4 100644
111707 --- a/net/sunrpc/cache.c
111708 +++ b/net/sunrpc/cache.c
111709 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
111710 struct sunrpc_net *sn;
111711
111712 sn = net_generic(net, sunrpc_net_id);
111713 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
111714 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
111715 if (cd->u.procfs.proc_ent == NULL)
111716 goto out_nomem;
111717 cd->u.procfs.channel_ent = NULL;
111718 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
111719 index 2e6ab10..3170800 100644
111720 --- a/net/sunrpc/clnt.c
111721 +++ b/net/sunrpc/clnt.c
111722 @@ -1425,7 +1425,9 @@ call_start(struct rpc_task *task)
111723 (RPC_IS_ASYNC(task) ? "async" : "sync"));
111724
111725 /* Increment call count */
111726 - task->tk_msg.rpc_proc->p_count++;
111727 + pax_open_kernel();
111728 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
111729 + pax_close_kernel();
111730 clnt->cl_stats->rpccnt++;
111731 task->tk_action = call_reserve;
111732 }
111733 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
111734 index c0365c1..b7f02b3 100644
111735 --- a/net/sunrpc/sched.c
111736 +++ b/net/sunrpc/sched.c
111737 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
111738 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
111739 static void rpc_task_set_debuginfo(struct rpc_task *task)
111740 {
111741 - static atomic_t rpc_pid;
111742 + static atomic_unchecked_t rpc_pid;
111743
111744 - task->tk_pid = atomic_inc_return(&rpc_pid);
111745 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
111746 }
111747 #else
111748 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
111749 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
111750 index 5453049..465669a 100644
111751 --- a/net/sunrpc/stats.c
111752 +++ b/net/sunrpc/stats.c
111753 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
111754
111755 dprintk("RPC: registering /proc/net/rpc\n");
111756 sn = net_generic(net, sunrpc_net_id);
111757 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
111758 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
111759 if (sn->proc_net_rpc == NULL)
111760 return -ENOMEM;
111761
111762 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
111763 index 5de6801..b4e330d 100644
111764 --- a/net/sunrpc/svc.c
111765 +++ b/net/sunrpc/svc.c
111766 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
111767 svc_putnl(resv, RPC_SUCCESS);
111768
111769 /* Bump per-procedure stats counter */
111770 - procp->pc_count++;
111771 + pax_open_kernel();
111772 + (*(unsigned int *)&procp->pc_count)++;
111773 + pax_close_kernel();
111774
111775 /* Initialize storage for argp and resp */
111776 memset(rqstp->rq_argp, 0, procp->pc_argsize);
111777 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
111778 index 621ca7b..59421dd 100644
111779 --- a/net/sunrpc/svcauth_unix.c
111780 +++ b/net/sunrpc/svcauth_unix.c
111781 @@ -414,7 +414,7 @@ struct unix_gid {
111782 struct group_info *gi;
111783 };
111784
111785 -static int unix_gid_hash(kuid_t uid)
111786 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
111787 {
111788 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
111789 }
111790 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
111791 (*bpp)[-1] = '\n';
111792 }
111793
111794 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
111795 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
111796
111797 static int unix_gid_parse(struct cache_detail *cd,
111798 char *mesg, int mlen)
111799 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
111800 index c1b6270..05089c1 100644
111801 --- a/net/sunrpc/xprtrdma/svc_rdma.c
111802 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
111803 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
111804 static unsigned int min_max_inline = 4096;
111805 static unsigned int max_max_inline = 65536;
111806
111807 -atomic_t rdma_stat_recv;
111808 -atomic_t rdma_stat_read;
111809 -atomic_t rdma_stat_write;
111810 -atomic_t rdma_stat_sq_starve;
111811 -atomic_t rdma_stat_rq_starve;
111812 -atomic_t rdma_stat_rq_poll;
111813 -atomic_t rdma_stat_rq_prod;
111814 -atomic_t rdma_stat_sq_poll;
111815 -atomic_t rdma_stat_sq_prod;
111816 +atomic_unchecked_t rdma_stat_recv;
111817 +atomic_unchecked_t rdma_stat_read;
111818 +atomic_unchecked_t rdma_stat_write;
111819 +atomic_unchecked_t rdma_stat_sq_starve;
111820 +atomic_unchecked_t rdma_stat_rq_starve;
111821 +atomic_unchecked_t rdma_stat_rq_poll;
111822 +atomic_unchecked_t rdma_stat_rq_prod;
111823 +atomic_unchecked_t rdma_stat_sq_poll;
111824 +atomic_unchecked_t rdma_stat_sq_prod;
111825
111826 /* Temporary NFS request map and context caches */
111827 struct kmem_cache *svc_rdma_map_cachep;
111828 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
111829 len -= *ppos;
111830 if (len > *lenp)
111831 len = *lenp;
111832 - if (len && copy_to_user(buffer, str_buf, len))
111833 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
111834 return -EFAULT;
111835 *lenp = len;
111836 *ppos += len;
111837 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
111838 {
111839 .procname = "rdma_stat_read",
111840 .data = &rdma_stat_read,
111841 - .maxlen = sizeof(atomic_t),
111842 + .maxlen = sizeof(atomic_unchecked_t),
111843 .mode = 0644,
111844 .proc_handler = read_reset_stat,
111845 },
111846 {
111847 .procname = "rdma_stat_recv",
111848 .data = &rdma_stat_recv,
111849 - .maxlen = sizeof(atomic_t),
111850 + .maxlen = sizeof(atomic_unchecked_t),
111851 .mode = 0644,
111852 .proc_handler = read_reset_stat,
111853 },
111854 {
111855 .procname = "rdma_stat_write",
111856 .data = &rdma_stat_write,
111857 - .maxlen = sizeof(atomic_t),
111858 + .maxlen = sizeof(atomic_unchecked_t),
111859 .mode = 0644,
111860 .proc_handler = read_reset_stat,
111861 },
111862 {
111863 .procname = "rdma_stat_sq_starve",
111864 .data = &rdma_stat_sq_starve,
111865 - .maxlen = sizeof(atomic_t),
111866 + .maxlen = sizeof(atomic_unchecked_t),
111867 .mode = 0644,
111868 .proc_handler = read_reset_stat,
111869 },
111870 {
111871 .procname = "rdma_stat_rq_starve",
111872 .data = &rdma_stat_rq_starve,
111873 - .maxlen = sizeof(atomic_t),
111874 + .maxlen = sizeof(atomic_unchecked_t),
111875 .mode = 0644,
111876 .proc_handler = read_reset_stat,
111877 },
111878 {
111879 .procname = "rdma_stat_rq_poll",
111880 .data = &rdma_stat_rq_poll,
111881 - .maxlen = sizeof(atomic_t),
111882 + .maxlen = sizeof(atomic_unchecked_t),
111883 .mode = 0644,
111884 .proc_handler = read_reset_stat,
111885 },
111886 {
111887 .procname = "rdma_stat_rq_prod",
111888 .data = &rdma_stat_rq_prod,
111889 - .maxlen = sizeof(atomic_t),
111890 + .maxlen = sizeof(atomic_unchecked_t),
111891 .mode = 0644,
111892 .proc_handler = read_reset_stat,
111893 },
111894 {
111895 .procname = "rdma_stat_sq_poll",
111896 .data = &rdma_stat_sq_poll,
111897 - .maxlen = sizeof(atomic_t),
111898 + .maxlen = sizeof(atomic_unchecked_t),
111899 .mode = 0644,
111900 .proc_handler = read_reset_stat,
111901 },
111902 {
111903 .procname = "rdma_stat_sq_prod",
111904 .data = &rdma_stat_sq_prod,
111905 - .maxlen = sizeof(atomic_t),
111906 + .maxlen = sizeof(atomic_unchecked_t),
111907 .mode = 0644,
111908 .proc_handler = read_reset_stat,
111909 },
111910 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
111911 index 8f92a61..eb13b74 100644
111912 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
111913 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
111914 @@ -219,7 +219,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
111915 *page_no = pg_no;
111916 *page_offset = pg_off;
111917 ret = read;
111918 - atomic_inc(&rdma_stat_read);
111919 + atomic_inc_unchecked(&rdma_stat_read);
111920 return ret;
111921 err:
111922 svc_rdma_unmap_dma(ctxt);
111923 @@ -355,7 +355,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
111924 *page_no = pg_no;
111925 *page_offset = pg_off;
111926 ret = read;
111927 - atomic_inc(&rdma_stat_read);
111928 + atomic_inc_unchecked(&rdma_stat_read);
111929 return ret;
111930 err:
111931 svc_rdma_unmap_dma(ctxt);
111932 @@ -512,7 +512,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
111933 dto_q);
111934 list_del_init(&ctxt->dto_q);
111935 } else {
111936 - atomic_inc(&rdma_stat_rq_starve);
111937 + atomic_inc_unchecked(&rdma_stat_rq_starve);
111938 clear_bit(XPT_DATA, &xprt->xpt_flags);
111939 ctxt = NULL;
111940 }
111941 @@ -531,7 +531,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
111942 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
111943 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
111944 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
111945 - atomic_inc(&rdma_stat_recv);
111946 + atomic_inc_unchecked(&rdma_stat_recv);
111947
111948 /* Build up the XDR from the receive buffers. */
111949 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
111950 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
111951 index 49fd21a..4bc455b 100644
111952 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
111953 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
111954 @@ -206,7 +206,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
111955 write_wr.wr.rdma.remote_addr = to;
111956
111957 /* Post It */
111958 - atomic_inc(&rdma_stat_write);
111959 + atomic_inc_unchecked(&rdma_stat_write);
111960 if (svc_rdma_send(xprt, &write_wr))
111961 goto err;
111962 return 0;
111963 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
111964 index 06a5d92..c2fa21a 100644
111965 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
111966 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
111967 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
111968 return;
111969
111970 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
111971 - atomic_inc(&rdma_stat_rq_poll);
111972 + atomic_inc_unchecked(&rdma_stat_rq_poll);
111973
111974 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
111975 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
111976 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
111977 }
111978
111979 if (ctxt)
111980 - atomic_inc(&rdma_stat_rq_prod);
111981 + atomic_inc_unchecked(&rdma_stat_rq_prod);
111982
111983 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
111984 /*
111985 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
111986 return;
111987
111988 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
111989 - atomic_inc(&rdma_stat_sq_poll);
111990 + atomic_inc_unchecked(&rdma_stat_sq_poll);
111991 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
111992 int i;
111993
111994 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
111995 }
111996
111997 if (ctxt)
111998 - atomic_inc(&rdma_stat_sq_prod);
111999 + atomic_inc_unchecked(&rdma_stat_sq_prod);
112000 }
112001
112002 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
112003 @@ -1279,7 +1279,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
112004 spin_lock_bh(&xprt->sc_lock);
112005 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
112006 spin_unlock_bh(&xprt->sc_lock);
112007 - atomic_inc(&rdma_stat_sq_starve);
112008 + atomic_inc_unchecked(&rdma_stat_sq_starve);
112009
112010 /* See if we can opportunistically reap SQ WR to make room */
112011 sq_cq_reap(xprt);
112012 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
112013 index e7000be..e3b0ba7 100644
112014 --- a/net/sysctl_net.c
112015 +++ b/net/sysctl_net.c
112016 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
112017 kgid_t root_gid = make_kgid(net->user_ns, 0);
112018
112019 /* Allow network administrator to have same access as root. */
112020 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
112021 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
112022 uid_eq(root_uid, current_euid())) {
112023 int mode = (table->mode >> 6) & 7;
112024 return (mode << 6) | (mode << 3) | mode;
112025 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
112026 index 6424372..afd36e9 100644
112027 --- a/net/tipc/subscr.c
112028 +++ b/net/tipc/subscr.c
112029 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
112030 struct tipc_subscriber *subscriber = sub->subscriber;
112031 struct kvec msg_sect;
112032
112033 - msg_sect.iov_base = (void *)&sub->evt;
112034 + msg_sect.iov_base = &sub->evt;
112035 msg_sect.iov_len = sizeof(struct tipc_event);
112036 sub->evt.event = htohl(event, sub->swap);
112037 sub->evt.found_lower = htohl(found_lower, sub->swap);
112038 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
112039 index e968843..bc95776 100644
112040 --- a/net/unix/af_unix.c
112041 +++ b/net/unix/af_unix.c
112042 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
112043 err = -ECONNREFUSED;
112044 if (!S_ISSOCK(inode->i_mode))
112045 goto put_fail;
112046 +
112047 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
112048 + err = -EACCES;
112049 + goto put_fail;
112050 + }
112051 +
112052 u = unix_find_socket_byinode(inode);
112053 if (!u)
112054 goto put_fail;
112055 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
112056 if (u) {
112057 struct dentry *dentry;
112058 dentry = unix_sk(u)->path.dentry;
112059 +
112060 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
112061 + err = -EPERM;
112062 + sock_put(u);
112063 + goto fail;
112064 + }
112065 +
112066 if (dentry)
112067 touch_atime(&unix_sk(u)->path);
112068 } else
112069 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
112070 */
112071 err = security_path_mknod(&path, dentry, mode, 0);
112072 if (!err) {
112073 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
112074 + err = -EACCES;
112075 + goto out;
112076 + }
112077 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
112078 if (!err) {
112079 res->mnt = mntget(path.mnt);
112080 res->dentry = dget(dentry);
112081 + gr_handle_create(dentry, path.mnt);
112082 }
112083 }
112084 +out:
112085 done_path_create(&path, dentry);
112086 return err;
112087 }
112088 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
112089 seq_puts(seq, "Num RefCount Protocol Flags Type St "
112090 "Inode Path\n");
112091 else {
112092 - struct sock *s = v;
112093 + struct sock *s = v, *peer;
112094 struct unix_sock *u = unix_sk(s);
112095 unix_state_lock(s);
112096 + peer = unix_peer(s);
112097 + unix_state_unlock(s);
112098 +
112099 + unix_state_double_lock(s, peer);
112100
112101 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
112102 s,
112103 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
112104 }
112105 for ( ; i < len; i++)
112106 seq_putc(seq, u->addr->name->sun_path[i]);
112107 - }
112108 - unix_state_unlock(s);
112109 + } else if (peer)
112110 + seq_printf(seq, " P%lu", sock_i_ino(peer));
112111 +
112112 + unix_state_double_unlock(s, peer);
112113 seq_putc(seq, '\n');
112114 }
112115
112116 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
112117 index b3d5150..ff3a837 100644
112118 --- a/net/unix/sysctl_net_unix.c
112119 +++ b/net/unix/sysctl_net_unix.c
112120 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
112121
112122 int __net_init unix_sysctl_register(struct net *net)
112123 {
112124 - struct ctl_table *table;
112125 + ctl_table_no_const *table;
112126
112127 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
112128 if (table == NULL)
112129 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
112130 index 9b7f207..2596621 100644
112131 --- a/net/vmw_vsock/vmci_transport_notify.c
112132 +++ b/net/vmw_vsock/vmci_transport_notify.c
112133 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
112134
112135 /* Socket control packet based operations. */
112136 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
112137 - vmci_transport_notify_pkt_socket_init,
112138 - vmci_transport_notify_pkt_socket_destruct,
112139 - vmci_transport_notify_pkt_poll_in,
112140 - vmci_transport_notify_pkt_poll_out,
112141 - vmci_transport_notify_pkt_handle_pkt,
112142 - vmci_transport_notify_pkt_recv_init,
112143 - vmci_transport_notify_pkt_recv_pre_block,
112144 - vmci_transport_notify_pkt_recv_pre_dequeue,
112145 - vmci_transport_notify_pkt_recv_post_dequeue,
112146 - vmci_transport_notify_pkt_send_init,
112147 - vmci_transport_notify_pkt_send_pre_block,
112148 - vmci_transport_notify_pkt_send_pre_enqueue,
112149 - vmci_transport_notify_pkt_send_post_enqueue,
112150 - vmci_transport_notify_pkt_process_request,
112151 - vmci_transport_notify_pkt_process_negotiate,
112152 + .socket_init = vmci_transport_notify_pkt_socket_init,
112153 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
112154 + .poll_in = vmci_transport_notify_pkt_poll_in,
112155 + .poll_out = vmci_transport_notify_pkt_poll_out,
112156 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
112157 + .recv_init = vmci_transport_notify_pkt_recv_init,
112158 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
112159 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
112160 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
112161 + .send_init = vmci_transport_notify_pkt_send_init,
112162 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
112163 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
112164 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
112165 + .process_request = vmci_transport_notify_pkt_process_request,
112166 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
112167 };
112168 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
112169 index dc9c792..3089de0 100644
112170 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
112171 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
112172 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
112173
112174 /* Socket always on control packet based operations. */
112175 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
112176 - vmci_transport_notify_pkt_socket_init,
112177 - vmci_transport_notify_pkt_socket_destruct,
112178 - vmci_transport_notify_pkt_poll_in,
112179 - vmci_transport_notify_pkt_poll_out,
112180 - vmci_transport_notify_pkt_handle_pkt,
112181 - vmci_transport_notify_pkt_recv_init,
112182 - vmci_transport_notify_pkt_recv_pre_block,
112183 - vmci_transport_notify_pkt_recv_pre_dequeue,
112184 - vmci_transport_notify_pkt_recv_post_dequeue,
112185 - vmci_transport_notify_pkt_send_init,
112186 - vmci_transport_notify_pkt_send_pre_block,
112187 - vmci_transport_notify_pkt_send_pre_enqueue,
112188 - vmci_transport_notify_pkt_send_post_enqueue,
112189 - vmci_transport_notify_pkt_process_request,
112190 - vmci_transport_notify_pkt_process_negotiate,
112191 + .socket_init = vmci_transport_notify_pkt_socket_init,
112192 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
112193 + .poll_in = vmci_transport_notify_pkt_poll_in,
112194 + .poll_out = vmci_transport_notify_pkt_poll_out,
112195 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
112196 + .recv_init = vmci_transport_notify_pkt_recv_init,
112197 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
112198 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
112199 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
112200 + .send_init = vmci_transport_notify_pkt_send_init,
112201 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
112202 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
112203 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
112204 + .process_request = vmci_transport_notify_pkt_process_request,
112205 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
112206 };
112207 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
112208 index c8717c1..08539f5 100644
112209 --- a/net/wireless/wext-core.c
112210 +++ b/net/wireless/wext-core.c
112211 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
112212 */
112213
112214 /* Support for very large requests */
112215 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
112216 - (user_length > descr->max_tokens)) {
112217 + if (user_length > descr->max_tokens) {
112218 /* Allow userspace to GET more than max so
112219 * we can support any size GET requests.
112220 * There is still a limit : -ENOMEM.
112221 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
112222 }
112223 }
112224
112225 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
112226 - /*
112227 - * If this is a GET, but not NOMAX, it means that the extra
112228 - * data is not bounded by userspace, but by max_tokens. Thus
112229 - * set the length to max_tokens. This matches the extra data
112230 - * allocation.
112231 - * The driver should fill it with the number of tokens it
112232 - * provided, and it may check iwp->length rather than having
112233 - * knowledge of max_tokens. If the driver doesn't change the
112234 - * iwp->length, this ioctl just copies back max_token tokens
112235 - * filled with zeroes. Hopefully the driver isn't claiming
112236 - * them to be valid data.
112237 - */
112238 - iwp->length = descr->max_tokens;
112239 - }
112240 -
112241 err = handler(dev, info, (union iwreq_data *) iwp, extra);
112242
112243 iwp->length += essid_compat;
112244 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
112245 index 4323952..a06dfe1 100644
112246 --- a/net/x25/sysctl_net_x25.c
112247 +++ b/net/x25/sysctl_net_x25.c
112248 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
112249 .mode = 0644,
112250 .proc_handler = proc_dointvec,
112251 },
112252 - { 0, },
112253 + { },
112254 };
112255
112256 void __init x25_register_sysctl(void)
112257 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
112258 index 0917f04..f4e3d8c 100644
112259 --- a/net/x25/x25_proc.c
112260 +++ b/net/x25/x25_proc.c
112261 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
112262
112263 int __init x25_proc_init(void)
112264 {
112265 - if (!proc_mkdir("x25", init_net.proc_net))
112266 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
112267 return -ENOMEM;
112268
112269 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
112270 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
112271 index 0525d78..cccf7fd 100644
112272 --- a/net/xfrm/xfrm_policy.c
112273 +++ b/net/xfrm/xfrm_policy.c
112274 @@ -325,7 +325,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
112275 {
112276 policy->walk.dead = 1;
112277
112278 - atomic_inc(&policy->genid);
112279 + atomic_inc_unchecked(&policy->genid);
112280
112281 if (del_timer(&policy->polq.hold_timer))
112282 xfrm_pol_put(policy);
112283 @@ -659,7 +659,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
112284 hlist_add_head(&policy->bydst, chain);
112285 xfrm_pol_hold(policy);
112286 net->xfrm.policy_count[dir]++;
112287 - atomic_inc(&net->xfrm.flow_cache_genid);
112288 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
112289
112290 /* After previous checking, family can either be AF_INET or AF_INET6 */
112291 if (policy->family == AF_INET)
112292 @@ -1749,7 +1749,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
112293
112294 xdst->num_pols = num_pols;
112295 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
112296 - xdst->policy_genid = atomic_read(&pols[0]->genid);
112297 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
112298
112299 return xdst;
112300 }
112301 @@ -2538,10 +2538,11 @@ void xfrm_garbage_collect(struct net *net)
112302 }
112303 EXPORT_SYMBOL(xfrm_garbage_collect);
112304
112305 -static void xfrm_garbage_collect_deferred(struct net *net)
112306 +void xfrm_garbage_collect_deferred(struct net *net)
112307 {
112308 flow_cache_flush_deferred(net);
112309 }
112310 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
112311
112312 static void xfrm_init_pmtu(struct dst_entry *dst)
112313 {
112314 @@ -2591,7 +2592,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
112315 if (xdst->xfrm_genid != dst->xfrm->genid)
112316 return 0;
112317 if (xdst->num_pols > 0 &&
112318 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
112319 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
112320 return 0;
112321
112322 mtu = dst_mtu(dst->child);
112323 @@ -2679,8 +2680,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
112324 dst_ops->link_failure = xfrm_link_failure;
112325 if (likely(dst_ops->neigh_lookup == NULL))
112326 dst_ops->neigh_lookup = xfrm_neigh_lookup;
112327 - if (likely(afinfo->garbage_collect == NULL))
112328 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
112329 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
112330 }
112331 spin_unlock(&xfrm_policy_afinfo_lock);
112332 @@ -2734,7 +2733,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
112333 dst_ops->check = NULL;
112334 dst_ops->negative_advice = NULL;
112335 dst_ops->link_failure = NULL;
112336 - afinfo->garbage_collect = NULL;
112337 }
112338 return err;
112339 }
112340 @@ -3119,7 +3117,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
112341 sizeof(pol->xfrm_vec[i].saddr));
112342 pol->xfrm_vec[i].encap_family = mp->new_family;
112343 /* flush bundles */
112344 - atomic_inc(&pol->genid);
112345 + atomic_inc_unchecked(&pol->genid);
112346 }
112347 }
112348
112349 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
112350 index 0ab5413..73dd2cf 100644
112351 --- a/net/xfrm/xfrm_state.c
112352 +++ b/net/xfrm/xfrm_state.c
112353 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
112354
112355 if (unlikely(afinfo == NULL))
112356 return -EAFNOSUPPORT;
112357 - typemap = afinfo->type_map;
112358 + typemap = (const struct xfrm_type **)afinfo->type_map;
112359 spin_lock_bh(&xfrm_type_lock);
112360
112361 - if (likely(typemap[type->proto] == NULL))
112362 + if (likely(typemap[type->proto] == NULL)) {
112363 + pax_open_kernel();
112364 typemap[type->proto] = type;
112365 - else
112366 + pax_close_kernel();
112367 + } else
112368 err = -EEXIST;
112369 spin_unlock_bh(&xfrm_type_lock);
112370 xfrm_state_put_afinfo(afinfo);
112371 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
112372
112373 if (unlikely(afinfo == NULL))
112374 return -EAFNOSUPPORT;
112375 - typemap = afinfo->type_map;
112376 + typemap = (const struct xfrm_type **)afinfo->type_map;
112377 spin_lock_bh(&xfrm_type_lock);
112378
112379 if (unlikely(typemap[type->proto] != type))
112380 err = -ENOENT;
112381 - else
112382 + else {
112383 + pax_open_kernel();
112384 typemap[type->proto] = NULL;
112385 + pax_close_kernel();
112386 + }
112387 spin_unlock_bh(&xfrm_type_lock);
112388 xfrm_state_put_afinfo(afinfo);
112389 return err;
112390 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
112391 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
112392 {
112393 struct xfrm_state_afinfo *afinfo;
112394 - const struct xfrm_type **typemap;
112395 const struct xfrm_type *type;
112396 int modload_attempted = 0;
112397
112398 @@ -218,9 +222,8 @@ retry:
112399 afinfo = xfrm_state_get_afinfo(family);
112400 if (unlikely(afinfo == NULL))
112401 return NULL;
112402 - typemap = afinfo->type_map;
112403
112404 - type = typemap[proto];
112405 + type = afinfo->type_map[proto];
112406 if (unlikely(type && !try_module_get(type->owner)))
112407 type = NULL;
112408 if (!type && !modload_attempted) {
112409 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
112410 return -EAFNOSUPPORT;
112411
112412 err = -EEXIST;
112413 - modemap = afinfo->mode_map;
112414 + modemap = (struct xfrm_mode **)afinfo->mode_map;
112415 spin_lock_bh(&xfrm_mode_lock);
112416 if (modemap[mode->encap])
112417 goto out;
112418 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
112419 if (!try_module_get(afinfo->owner))
112420 goto out;
112421
112422 - mode->afinfo = afinfo;
112423 + pax_open_kernel();
112424 + *(const void **)&mode->afinfo = afinfo;
112425 modemap[mode->encap] = mode;
112426 + pax_close_kernel();
112427 err = 0;
112428
112429 out:
112430 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
112431 return -EAFNOSUPPORT;
112432
112433 err = -ENOENT;
112434 - modemap = afinfo->mode_map;
112435 + modemap = (struct xfrm_mode **)afinfo->mode_map;
112436 spin_lock_bh(&xfrm_mode_lock);
112437 if (likely(modemap[mode->encap] == mode)) {
112438 + pax_open_kernel();
112439 modemap[mode->encap] = NULL;
112440 + pax_close_kernel();
112441 module_put(mode->afinfo->owner);
112442 err = 0;
112443 }
112444 @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
112445 u32 xfrm_get_acqseq(void)
112446 {
112447 u32 res;
112448 - static atomic_t acqseq;
112449 + static atomic_unchecked_t acqseq;
112450
112451 do {
112452 - res = atomic_inc_return(&acqseq);
112453 + res = atomic_inc_return_unchecked(&acqseq);
112454 } while (!res);
112455
112456 return res;
112457 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
112458 index 05a6e3d..6716ec9 100644
112459 --- a/net/xfrm/xfrm_sysctl.c
112460 +++ b/net/xfrm/xfrm_sysctl.c
112461 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
112462
112463 int __net_init xfrm_sysctl_init(struct net *net)
112464 {
112465 - struct ctl_table *table;
112466 + ctl_table_no_const *table;
112467
112468 __xfrm_sysctl_init(net);
112469
112470 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
112471 index bf3e677..c7d426e 100644
112472 --- a/scripts/Makefile.build
112473 +++ b/scripts/Makefile.build
112474 @@ -60,7 +60,7 @@ endif
112475 endif
112476
112477 # Do not include host rules unless needed
112478 -ifneq ($(hostprogs-y)$(hostprogs-m),)
112479 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
112480 include scripts/Makefile.host
112481 endif
112482
112483 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
112484 index 686cb0d..9d653bf 100644
112485 --- a/scripts/Makefile.clean
112486 +++ b/scripts/Makefile.clean
112487 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
112488 __clean-files := $(extra-y) $(always) \
112489 $(targets) $(clean-files) \
112490 $(host-progs) \
112491 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
112492 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
112493 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
112494
112495 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
112496
112497 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
112498 index 6689364..e56dc6a 100644
112499 --- a/scripts/Makefile.host
112500 +++ b/scripts/Makefile.host
112501 @@ -31,6 +31,8 @@
112502 # Note: Shared libraries consisting of C++ files are not supported
112503
112504 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
112505 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
112506 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
112507
112508 # C code
112509 # Executables compiled from a single .c file
112510 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
112511 # Shared libaries (only .c supported)
112512 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
112513 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
112514 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
112515 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
112516 # Remove .so files from "xxx-objs"
112517 host-cobjs := $(filter-out %.so,$(host-cobjs))
112518 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
112519
112520 -#Object (.o) files used by the shared libaries
112521 +# Object (.o) files used by the shared libaries
112522 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
112523 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
112524
112525 # output directory for programs/.o files
112526 # hostprogs-y := tools/build may have been specified. Retrieve directory
112527 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
112528 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
112529 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
112530 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
112531 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
112532 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
112533 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
112534 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
112535
112536 obj-dirs += $(host-objdirs)
112537 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
112538 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
112539 $(call if_changed_dep,host-cshobjs)
112540
112541 +# Compile .c file, create position independent .o file
112542 +# host-cxxshobjs -> .o
112543 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
112544 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
112545 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
112546 + $(call if_changed_dep,host-cxxshobjs)
112547 +
112548 # Link a shared library, based on position independent .o files
112549 # *.o -> .so shared library (host-cshlib)
112550 quiet_cmd_host-cshlib = HOSTLLD -shared $@
112551 @@ -165,5 +180,14 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
112552 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
112553 $(call if_changed,host-cshlib)
112554
112555 +# Link a shared library, based on position independent .o files
112556 +# *.o -> .so shared library (host-cxxshlib)
112557 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
112558 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
112559 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
112560 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
112561 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
112562 + $(call if_changed,host-cxxshlib)
112563 +
112564 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
112565 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
112566 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
112567 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
112568 index b304068..462d24e 100644
112569 --- a/scripts/basic/fixdep.c
112570 +++ b/scripts/basic/fixdep.c
112571 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
112572 /*
112573 * Lookup a value in the configuration string.
112574 */
112575 -static int is_defined_config(const char *name, int len, unsigned int hash)
112576 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
112577 {
112578 struct item *aux;
112579
112580 @@ -211,10 +211,10 @@ static void clear_config(void)
112581 /*
112582 * Record the use of a CONFIG_* word.
112583 */
112584 -static void use_config(const char *m, int slen)
112585 +static void use_config(const char *m, unsigned int slen)
112586 {
112587 unsigned int hash = strhash(m, slen);
112588 - int c, i;
112589 + unsigned int c, i;
112590
112591 if (is_defined_config(m, slen, hash))
112592 return;
112593 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
112594
112595 static void parse_config_file(const char *map, size_t len)
112596 {
112597 - const int *end = (const int *) (map + len);
112598 + const unsigned int *end = (const unsigned int *) (map + len);
112599 /* start at +1, so that p can never be < map */
112600 - const int *m = (const int *) map + 1;
112601 + const unsigned int *m = (const unsigned int *) map + 1;
112602 const char *p, *q;
112603
112604 for (; m < end; m++) {
112605 @@ -435,7 +435,7 @@ static void print_deps(void)
112606 static void traps(void)
112607 {
112608 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
112609 - int *p = (int *)test;
112610 + unsigned int *p = (unsigned int *)test;
112611
112612 if (*p != INT_CONF) {
112613 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
112614 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
112615 new file mode 100644
112616 index 0000000..3fd3699
112617 --- /dev/null
112618 +++ b/scripts/gcc-plugin.sh
112619 @@ -0,0 +1,43 @@
112620 +#!/bin/bash
112621 +srctree=$(dirname "$0")
112622 +gccplugins_dir=$($3 -print-file-name=plugin)
112623 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
112624 +#include "gcc-common.h"
112625 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
112626 +#warning $2 CXX
112627 +#else
112628 +#warning $1 CC
112629 +#endif
112630 +EOF
112631 +)
112632 +
112633 +if [ $? -ne 0 ]
112634 +then
112635 + exit 1
112636 +fi
112637 +
112638 +if [[ "$plugincc" =~ "$1 CC" ]]
112639 +then
112640 + echo "$1"
112641 + exit 0
112642 +fi
112643 +
112644 +if [[ "$plugincc" =~ "$2 CXX" ]]
112645 +then
112646 +plugincc=$($1 -c -x c++ -std=gnu++98 - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
112647 +#include "gcc-common.h"
112648 +class test {
112649 +public:
112650 + int test;
112651 +} test = {
112652 + .test = 1
112653 +};
112654 +EOF
112655 +)
112656 +if [ $? -eq 0 ]
112657 +then
112658 + echo "$2"
112659 + exit 0
112660 +fi
112661 +fi
112662 +exit 1
112663 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
112664 index 5de5660..d3deb89 100644
112665 --- a/scripts/headers_install.sh
112666 +++ b/scripts/headers_install.sh
112667 @@ -32,6 +32,7 @@ do
112668 FILE="$(basename "$i")"
112669 sed -r \
112670 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
112671 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
112672 -e 's/__attribute_const__([ \t]|$)/\1/g' \
112673 -e 's@^#include <linux/compiler.h>@@' \
112674 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
112675 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
112676 index 86a4fe7..99e91f9 100644
112677 --- a/scripts/link-vmlinux.sh
112678 +++ b/scripts/link-vmlinux.sh
112679 @@ -166,7 +166,7 @@ else
112680 fi;
112681
112682 # final build of init/
112683 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
112684 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
112685
112686 kallsymso=""
112687 kallsyms_vmlinux=""
112688 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
112689 index e614ef6..d9d2b01 100644
112690 --- a/scripts/mod/file2alias.c
112691 +++ b/scripts/mod/file2alias.c
112692 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
112693 unsigned long size, unsigned long id_size,
112694 void *symval)
112695 {
112696 - int i;
112697 + unsigned int i;
112698
112699 if (size % id_size || size < id_size) {
112700 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
112701 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
112702 /* USB is special because the bcdDevice can be matched against a numeric range */
112703 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
112704 static void do_usb_entry(void *symval,
112705 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
112706 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
112707 unsigned char range_lo, unsigned char range_hi,
112708 unsigned char max, struct module *mod)
112709 {
112710 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
112711 {
112712 unsigned int devlo, devhi;
112713 unsigned char chi, clo, max;
112714 - int ndigits;
112715 + unsigned int ndigits;
112716
112717 DEF_FIELD(symval, usb_device_id, match_flags);
112718 DEF_FIELD(symval, usb_device_id, idVendor);
112719 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
112720 for (i = 0; i < count; i++) {
112721 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
112722 char acpi_id[sizeof(*id)];
112723 - int j;
112724 + unsigned int j;
112725
112726 buf_printf(&mod->dev_table_buf,
112727 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
112728 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
112729
112730 for (j = 0; j < PNP_MAX_DEVICES; j++) {
112731 const char *id = (char *)(*devs)[j].id;
112732 - int i2, j2;
112733 + unsigned int i2, j2;
112734 int dup = 0;
112735
112736 if (!id[0])
112737 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
112738 /* add an individual alias for every device entry */
112739 if (!dup) {
112740 char acpi_id[PNP_ID_LEN];
112741 - int k;
112742 + unsigned int k;
112743
112744 buf_printf(&mod->dev_table_buf,
112745 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
112746 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
112747 static int do_dmi_entry(const char *filename, void *symval,
112748 char *alias)
112749 {
112750 - int i, j;
112751 + unsigned int i, j;
112752 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
112753 sprintf(alias, "dmi*");
112754
112755 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
112756 index 9d9c5b9..a3af177 100644
112757 --- a/scripts/mod/modpost.c
112758 +++ b/scripts/mod/modpost.c
112759 @@ -949,6 +949,7 @@ enum mismatch {
112760 ANY_INIT_TO_ANY_EXIT,
112761 ANY_EXIT_TO_ANY_INIT,
112762 EXPORT_TO_INIT_EXIT,
112763 + DATA_TO_TEXT
112764 };
112765
112766 struct sectioncheck {
112767 @@ -1035,6 +1036,12 @@ const struct sectioncheck sectioncheck[] = {
112768 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
112769 .mismatch = EXPORT_TO_INIT_EXIT,
112770 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
112771 +},
112772 +/* Do not reference code from writable data */
112773 +{
112774 + .fromsec = { DATA_SECTIONS, NULL },
112775 + .tosec = { TEXT_SECTIONS, NULL },
112776 + .mismatch = DATA_TO_TEXT
112777 }
112778 };
112779
112780 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
112781 continue;
112782 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
112783 continue;
112784 - if (sym->st_value == addr)
112785 - return sym;
112786 /* Find a symbol nearby - addr are maybe negative */
112787 d = sym->st_value - addr;
112788 + if (d == 0)
112789 + return sym;
112790 if (d < 0)
112791 d = addr - sym->st_value;
112792 if (d < distance) {
112793 @@ -1436,6 +1443,14 @@ static void report_sec_mismatch(const char *modname,
112794 tosym, prl_to, prl_to, tosym);
112795 free(prl_to);
112796 break;
112797 + case DATA_TO_TEXT:
112798 +#if 0
112799 + fprintf(stderr,
112800 + "The %s %s:%s references\n"
112801 + "the %s %s:%s%s\n",
112802 + from, fromsec, fromsym, to, tosec, tosym, to_p);
112803 +#endif
112804 + break;
112805 }
112806 fprintf(stderr, "\n");
112807 }
112808 @@ -1687,7 +1702,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
112809 static void check_sec_ref(struct module *mod, const char *modname,
112810 struct elf_info *elf)
112811 {
112812 - int i;
112813 + unsigned int i;
112814 Elf_Shdr *sechdrs = elf->sechdrs;
112815
112816 /* Walk through all sections */
112817 @@ -1819,7 +1834,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
112818 va_end(ap);
112819 }
112820
112821 -void buf_write(struct buffer *buf, const char *s, int len)
112822 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
112823 {
112824 if (buf->size - buf->pos < len) {
112825 buf->size += len + SZ;
112826 @@ -2038,7 +2053,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
112827 if (fstat(fileno(file), &st) < 0)
112828 goto close_write;
112829
112830 - if (st.st_size != b->pos)
112831 + if (st.st_size != (off_t)b->pos)
112832 goto close_write;
112833
112834 tmp = NOFAIL(malloc(b->pos));
112835 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
112836 index 168b43d..77914bf 100644
112837 --- a/scripts/mod/modpost.h
112838 +++ b/scripts/mod/modpost.h
112839 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
112840
112841 struct buffer {
112842 char *p;
112843 - int pos;
112844 - int size;
112845 + unsigned int pos;
112846 + unsigned int size;
112847 };
112848
112849 void __attribute__((format(printf, 2, 3)))
112850 buf_printf(struct buffer *buf, const char *fmt, ...);
112851
112852 void
112853 -buf_write(struct buffer *buf, const char *s, int len);
112854 +buf_write(struct buffer *buf, const char *s, unsigned int len);
112855
112856 struct module {
112857 struct module *next;
112858 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
112859 index 944418d..15291e4 100644
112860 --- a/scripts/mod/sumversion.c
112861 +++ b/scripts/mod/sumversion.c
112862 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
112863 goto out;
112864 }
112865
112866 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
112867 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
112868 warn("writing sum in %s failed: %s\n",
112869 filename, strerror(errno));
112870 goto out;
112871 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
112872 index 0865b3e..7235dd4 100644
112873 --- a/scripts/module-common.lds
112874 +++ b/scripts/module-common.lds
112875 @@ -6,6 +6,10 @@
112876 SECTIONS {
112877 /DISCARD/ : { *(.discard) }
112878
112879 + .rodata : {
112880 + *(.rodata) *(.rodata.*)
112881 + *(.data..read_only)
112882 + }
112883 __ksymtab : { *(SORT(___ksymtab+*)) }
112884 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
112885 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
112886 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
112887 index 35d5a58..9e04789 100644
112888 --- a/scripts/package/builddeb
112889 +++ b/scripts/package/builddeb
112890 @@ -295,6 +295,7 @@ fi
112891 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
112892 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
112893 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
112894 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
112895 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
112896 mkdir -p "$destdir"
112897 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
112898 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
112899 index 4718d78..9220d58 100644
112900 --- a/scripts/pnmtologo.c
112901 +++ b/scripts/pnmtologo.c
112902 @@ -244,14 +244,14 @@ static void write_header(void)
112903 fprintf(out, " * Linux logo %s\n", logoname);
112904 fputs(" */\n\n", out);
112905 fputs("#include <linux/linux_logo.h>\n\n", out);
112906 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
112907 + fprintf(out, "static unsigned char %s_data[] = {\n",
112908 logoname);
112909 }
112910
112911 static void write_footer(void)
112912 {
112913 fputs("\n};\n\n", out);
112914 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
112915 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
112916 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
112917 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
112918 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
112919 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
112920 fputs("\n};\n\n", out);
112921
112922 /* write logo clut */
112923 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
112924 + fprintf(out, "static unsigned char %s_clut[] = {\n",
112925 logoname);
112926 write_hex_cnt = 0;
112927 for (i = 0; i < logo_clutsize; i++) {
112928 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
112929 index 8fac3fd..32ff38d 100644
112930 --- a/scripts/sortextable.h
112931 +++ b/scripts/sortextable.h
112932 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
112933 const char *secstrtab;
112934 const char *strtab;
112935 char *extab_image;
112936 - int extab_index = 0;
112937 - int i;
112938 - int idx;
112939 + unsigned int extab_index = 0;
112940 + unsigned int i;
112941 + unsigned int idx;
112942 unsigned int num_sections;
112943 unsigned int secindex_strings;
112944
112945 diff --git a/security/Kconfig b/security/Kconfig
112946 index beb86b5..40b1edb 100644
112947 --- a/security/Kconfig
112948 +++ b/security/Kconfig
112949 @@ -4,6 +4,957 @@
112950
112951 menu "Security options"
112952
112953 +menu "Grsecurity"
112954 +
112955 + config ARCH_TRACK_EXEC_LIMIT
112956 + bool
112957 +
112958 + config PAX_KERNEXEC_PLUGIN
112959 + bool
112960 +
112961 + config PAX_PER_CPU_PGD
112962 + bool
112963 +
112964 + config TASK_SIZE_MAX_SHIFT
112965 + int
112966 + depends on X86_64
112967 + default 47 if !PAX_PER_CPU_PGD
112968 + default 42 if PAX_PER_CPU_PGD
112969 +
112970 + config PAX_ENABLE_PAE
112971 + bool
112972 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
112973 +
112974 + config PAX_USERCOPY_SLABS
112975 + bool
112976 +
112977 +config GRKERNSEC
112978 + bool "Grsecurity"
112979 + select CRYPTO
112980 + select CRYPTO_SHA256
112981 + select PROC_FS
112982 + select STOP_MACHINE
112983 + select TTY
112984 + select DEBUG_KERNEL
112985 + select DEBUG_LIST
112986 + help
112987 + If you say Y here, you will be able to configure many features
112988 + that will enhance the security of your system. It is highly
112989 + recommended that you say Y here and read through the help
112990 + for each option so that you fully understand the features and
112991 + can evaluate their usefulness for your machine.
112992 +
112993 +choice
112994 + prompt "Configuration Method"
112995 + depends on GRKERNSEC
112996 + default GRKERNSEC_CONFIG_CUSTOM
112997 + help
112998 +
112999 +config GRKERNSEC_CONFIG_AUTO
113000 + bool "Automatic"
113001 + help
113002 + If you choose this configuration method, you'll be able to answer a small
113003 + number of simple questions about how you plan to use this kernel.
113004 + The settings of grsecurity and PaX will be automatically configured for
113005 + the highest commonly-used settings within the provided constraints.
113006 +
113007 + If you require additional configuration, custom changes can still be made
113008 + from the "custom configuration" menu.
113009 +
113010 +config GRKERNSEC_CONFIG_CUSTOM
113011 + bool "Custom"
113012 + help
113013 + If you choose this configuration method, you'll be able to configure all
113014 + grsecurity and PaX settings manually. Via this method, no options are
113015 + automatically enabled.
113016 +
113017 +endchoice
113018 +
113019 +choice
113020 + prompt "Usage Type"
113021 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
113022 + default GRKERNSEC_CONFIG_SERVER
113023 + help
113024 +
113025 +config GRKERNSEC_CONFIG_SERVER
113026 + bool "Server"
113027 + help
113028 + Choose this option if you plan to use this kernel on a server.
113029 +
113030 +config GRKERNSEC_CONFIG_DESKTOP
113031 + bool "Desktop"
113032 + help
113033 + Choose this option if you plan to use this kernel on a desktop.
113034 +
113035 +endchoice
113036 +
113037 +choice
113038 + prompt "Virtualization Type"
113039 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
113040 + default GRKERNSEC_CONFIG_VIRT_NONE
113041 + help
113042 +
113043 +config GRKERNSEC_CONFIG_VIRT_NONE
113044 + bool "None"
113045 + help
113046 + Choose this option if this kernel will be run on bare metal.
113047 +
113048 +config GRKERNSEC_CONFIG_VIRT_GUEST
113049 + bool "Guest"
113050 + help
113051 + Choose this option if this kernel will be run as a VM guest.
113052 +
113053 +config GRKERNSEC_CONFIG_VIRT_HOST
113054 + bool "Host"
113055 + help
113056 + Choose this option if this kernel will be run as a VM host.
113057 +
113058 +endchoice
113059 +
113060 +choice
113061 + prompt "Virtualization Hardware"
113062 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
113063 + help
113064 +
113065 +config GRKERNSEC_CONFIG_VIRT_EPT
113066 + bool "EPT/RVI Processor Support"
113067 + depends on X86
113068 + help
113069 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
113070 + hardware virtualization. This allows for additional kernel hardening protections
113071 + to operate without additional performance impact.
113072 +
113073 + To see if your Intel processor supports EPT, see:
113074 + http://ark.intel.com/Products/VirtualizationTechnology
113075 + (Most Core i3/5/7 support EPT)
113076 +
113077 + To see if your AMD processor supports RVI, see:
113078 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
113079 +
113080 +config GRKERNSEC_CONFIG_VIRT_SOFT
113081 + bool "First-gen/No Hardware Virtualization"
113082 + help
113083 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
113084 + support hardware virtualization or doesn't support the EPT/RVI extensions.
113085 +
113086 +endchoice
113087 +
113088 +choice
113089 + prompt "Virtualization Software"
113090 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
113091 + help
113092 +
113093 +config GRKERNSEC_CONFIG_VIRT_XEN
113094 + bool "Xen"
113095 + help
113096 + Choose this option if this kernel is running as a Xen guest or host.
113097 +
113098 +config GRKERNSEC_CONFIG_VIRT_VMWARE
113099 + bool "VMWare"
113100 + help
113101 + Choose this option if this kernel is running as a VMWare guest or host.
113102 +
113103 +config GRKERNSEC_CONFIG_VIRT_KVM
113104 + bool "KVM"
113105 + help
113106 + Choose this option if this kernel is running as a KVM guest or host.
113107 +
113108 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
113109 + bool "VirtualBox"
113110 + help
113111 + Choose this option if this kernel is running as a VirtualBox guest or host.
113112 +
113113 +endchoice
113114 +
113115 +choice
113116 + prompt "Required Priorities"
113117 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
113118 + default GRKERNSEC_CONFIG_PRIORITY_PERF
113119 + help
113120 +
113121 +config GRKERNSEC_CONFIG_PRIORITY_PERF
113122 + bool "Performance"
113123 + help
113124 + Choose this option if performance is of highest priority for this deployment
113125 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
113126 + clearing of structures intended for userland, and freed memory sanitizing will
113127 + be disabled.
113128 +
113129 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
113130 + bool "Security"
113131 + help
113132 + Choose this option if security is of highest priority for this deployment of
113133 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
113134 + for userland, and freed memory sanitizing will be enabled for this kernel.
113135 + In a worst-case scenario, these features can introduce a 20% performance hit
113136 + (UDEREF on x64 contributing half of this hit).
113137 +
113138 +endchoice
113139 +
113140 +menu "Default Special Groups"
113141 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
113142 +
113143 +config GRKERNSEC_PROC_GID
113144 + int "GID exempted from /proc restrictions"
113145 + default 1001
113146 + help
113147 + Setting this GID determines which group will be exempted from
113148 + grsecurity's /proc restrictions, allowing users of the specified
113149 + group to view network statistics and the existence of other users'
113150 + processes on the system. This GID may also be chosen at boot time
113151 + via "grsec_proc_gid=" on the kernel commandline.
113152 +
113153 +config GRKERNSEC_TPE_UNTRUSTED_GID
113154 + int "GID for TPE-untrusted users"
113155 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
113156 + default 1005
113157 + help
113158 + Setting this GID determines which group untrusted users should
113159 + be added to. These users will be placed under grsecurity's Trusted Path
113160 + Execution mechanism, preventing them from executing their own binaries.
113161 + The users will only be able to execute binaries in directories owned and
113162 + writable only by the root user. If the sysctl option is enabled, a sysctl
113163 + option with name "tpe_gid" is created.
113164 +
113165 +config GRKERNSEC_TPE_TRUSTED_GID
113166 + int "GID for TPE-trusted users"
113167 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
113168 + default 1005
113169 + help
113170 + Setting this GID determines what group TPE restrictions will be
113171 + *disabled* for. If the sysctl option is enabled, a sysctl option
113172 + with name "tpe_gid" is created.
113173 +
113174 +config GRKERNSEC_SYMLINKOWN_GID
113175 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
113176 + depends on GRKERNSEC_CONFIG_SERVER
113177 + default 1006
113178 + help
113179 + Setting this GID determines what group kernel-enforced
113180 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
113181 + is enabled, a sysctl option with name "symlinkown_gid" is created.
113182 +
113183 +
113184 +endmenu
113185 +
113186 +menu "Customize Configuration"
113187 +depends on GRKERNSEC
113188 +
113189 +menu "PaX"
113190 +
113191 +config PAX
113192 + bool "Enable various PaX features"
113193 + default y if GRKERNSEC_CONFIG_AUTO
113194 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
113195 + help
113196 + This allows you to enable various PaX features. PaX adds
113197 + intrusion prevention mechanisms to the kernel that reduce
113198 + the risks posed by exploitable memory corruption bugs.
113199 +
113200 +menu "PaX Control"
113201 + depends on PAX
113202 +
113203 +config PAX_SOFTMODE
113204 + bool 'Support soft mode'
113205 + help
113206 + Enabling this option will allow you to run PaX in soft mode, that
113207 + is, PaX features will not be enforced by default, only on executables
113208 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
113209 + support as they are the only way to mark executables for soft mode use.
113210 +
113211 + Soft mode can be activated by using the "pax_softmode=1" kernel command
113212 + line option on boot. Furthermore you can control various PaX features
113213 + at runtime via the entries in /proc/sys/kernel/pax.
113214 +
113215 +config PAX_EI_PAX
113216 + bool 'Use legacy ELF header marking'
113217 + default y if GRKERNSEC_CONFIG_AUTO
113218 + help
113219 + Enabling this option will allow you to control PaX features on
113220 + a per executable basis via the 'chpax' utility available at
113221 + http://pax.grsecurity.net/. The control flags will be read from
113222 + an otherwise reserved part of the ELF header. This marking has
113223 + numerous drawbacks (no support for soft-mode, toolchain does not
113224 + know about the non-standard use of the ELF header) therefore it
113225 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
113226 + support.
113227 +
113228 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
113229 + support as well, they will override the legacy EI_PAX marks.
113230 +
113231 + If you enable none of the marking options then all applications
113232 + will run with PaX enabled on them by default.
113233 +
113234 +config PAX_PT_PAX_FLAGS
113235 + bool 'Use ELF program header marking'
113236 + default y if GRKERNSEC_CONFIG_AUTO
113237 + help
113238 + Enabling this option will allow you to control PaX features on
113239 + a per executable basis via the 'paxctl' utility available at
113240 + http://pax.grsecurity.net/. The control flags will be read from
113241 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
113242 + has the benefits of supporting both soft mode and being fully
113243 + integrated into the toolchain (the binutils patch is available
113244 + from http://pax.grsecurity.net).
113245 +
113246 + Note that if you enable the legacy EI_PAX marking support as well,
113247 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
113248 +
113249 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
113250 + must make sure that the marks are the same if a binary has both marks.
113251 +
113252 + If you enable none of the marking options then all applications
113253 + will run with PaX enabled on them by default.
113254 +
113255 +config PAX_XATTR_PAX_FLAGS
113256 + bool 'Use filesystem extended attributes marking'
113257 + default y if GRKERNSEC_CONFIG_AUTO
113258 + select CIFS_XATTR if CIFS
113259 + select F2FS_FS_XATTR if F2FS_FS
113260 + select EXT2_FS_XATTR if EXT2_FS
113261 + select EXT3_FS_XATTR if EXT3_FS
113262 + select JFFS2_FS_XATTR if JFFS2_FS
113263 + select REISERFS_FS_XATTR if REISERFS_FS
113264 + select SQUASHFS_XATTR if SQUASHFS
113265 + select TMPFS_XATTR if TMPFS
113266 + help
113267 + Enabling this option will allow you to control PaX features on
113268 + a per executable basis via the 'setfattr' utility. The control
113269 + flags will be read from the user.pax.flags extended attribute of
113270 + the file. This marking has the benefit of supporting binary-only
113271 + applications that self-check themselves (e.g., skype) and would
113272 + not tolerate chpax/paxctl changes. The main drawback is that
113273 + extended attributes are not supported by some filesystems (e.g.,
113274 + isofs, udf, vfat) so copying files through such filesystems will
113275 + lose the extended attributes and these PaX markings.
113276 +
113277 + Note that if you enable the legacy EI_PAX marking support as well,
113278 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
113279 +
113280 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
113281 + must make sure that the marks are the same if a binary has both marks.
113282 +
113283 + If you enable none of the marking options then all applications
113284 + will run with PaX enabled on them by default.
113285 +
113286 +choice
113287 + prompt 'MAC system integration'
113288 + default PAX_HAVE_ACL_FLAGS
113289 + help
113290 + Mandatory Access Control systems have the option of controlling
113291 + PaX flags on a per executable basis, choose the method supported
113292 + by your particular system.
113293 +
113294 + - "none": if your MAC system does not interact with PaX,
113295 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
113296 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
113297 +
113298 + NOTE: this option is for developers/integrators only.
113299 +
113300 + config PAX_NO_ACL_FLAGS
113301 + bool 'none'
113302 +
113303 + config PAX_HAVE_ACL_FLAGS
113304 + bool 'direct'
113305 +
113306 + config PAX_HOOK_ACL_FLAGS
113307 + bool 'hook'
113308 +endchoice
113309 +
113310 +endmenu
113311 +
113312 +menu "Non-executable pages"
113313 + depends on PAX
113314 +
113315 +config PAX_NOEXEC
113316 + bool "Enforce non-executable pages"
113317 + default y if GRKERNSEC_CONFIG_AUTO
113318 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
113319 + help
113320 + By design some architectures do not allow for protecting memory
113321 + pages against execution or even if they do, Linux does not make
113322 + use of this feature. In practice this means that if a page is
113323 + readable (such as the stack or heap) it is also executable.
113324 +
113325 + There is a well known exploit technique that makes use of this
113326 + fact and a common programming mistake where an attacker can
113327 + introduce code of his choice somewhere in the attacked program's
113328 + memory (typically the stack or the heap) and then execute it.
113329 +
113330 + If the attacked program was running with different (typically
113331 + higher) privileges than that of the attacker, then he can elevate
113332 + his own privilege level (e.g. get a root shell, write to files for
113333 + which he does not have write access to, etc).
113334 +
113335 + Enabling this option will let you choose from various features
113336 + that prevent the injection and execution of 'foreign' code in
113337 + a program.
113338 +
113339 + This will also break programs that rely on the old behaviour and
113340 + expect that dynamically allocated memory via the malloc() family
113341 + of functions is executable (which it is not). Notable examples
113342 + are the XFree86 4.x server, the java runtime and wine.
113343 +
113344 +config PAX_PAGEEXEC
113345 + bool "Paging based non-executable pages"
113346 + default y if GRKERNSEC_CONFIG_AUTO
113347 + depends on PAX_NOEXEC && (!X86_32 || M586 || M586TSC || M586MMX || M686 || MPENTIUMII || MPENTIUMIII || MPENTIUMM || MCORE2 || MATOM || MPENTIUM4 || MPSC || MK7 || MK8 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MVIAC3_2 || MVIAC7)
113348 + select ARCH_TRACK_EXEC_LIMIT if X86_32
113349 + help
113350 + This implementation is based on the paging feature of the CPU.
113351 + On i386 without hardware non-executable bit support there is a
113352 + variable but usually low performance impact, however on Intel's
113353 + P4 core based CPUs it is very high so you should not enable this
113354 + for kernels meant to be used on such CPUs.
113355 +
113356 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
113357 + with hardware non-executable bit support there is no performance
113358 + impact, on ppc the impact is negligible.
113359 +
113360 + Note that several architectures require various emulations due to
113361 + badly designed userland ABIs, this will cause a performance impact
113362 + but will disappear as soon as userland is fixed. For example, ppc
113363 + userland MUST have been built with secure-plt by a recent toolchain.
113364 +
113365 +config PAX_SEGMEXEC
113366 + bool "Segmentation based non-executable pages"
113367 + default y if GRKERNSEC_CONFIG_AUTO
113368 + depends on PAX_NOEXEC && X86_32
113369 + help
113370 + This implementation is based on the segmentation feature of the
113371 + CPU and has a very small performance impact, however applications
113372 + will be limited to a 1.5 GB address space instead of the normal
113373 + 3 GB.
113374 +
113375 +config PAX_EMUTRAMP
113376 + bool "Emulate trampolines"
113377 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
113378 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
113379 + help
113380 + There are some programs and libraries that for one reason or
113381 + another attempt to execute special small code snippets from
113382 + non-executable memory pages. Most notable examples are the
113383 + signal handler return code generated by the kernel itself and
113384 + the GCC trampolines.
113385 +
113386 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
113387 + such programs will no longer work under your kernel.
113388 +
113389 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
113390 + utilities to enable trampoline emulation for the affected programs
113391 + yet still have the protection provided by the non-executable pages.
113392 +
113393 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
113394 + your system will not even boot.
113395 +
113396 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
113397 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
113398 + for the affected files.
113399 +
113400 + NOTE: enabling this feature *may* open up a loophole in the
113401 + protection provided by non-executable pages that an attacker
113402 + could abuse. Therefore the best solution is to not have any
113403 + files on your system that would require this option. This can
113404 + be achieved by not using libc5 (which relies on the kernel
113405 + signal handler return code) and not using or rewriting programs
113406 + that make use of the nested function implementation of GCC.
113407 + Skilled users can just fix GCC itself so that it implements
113408 + nested function calls in a way that does not interfere with PaX.
113409 +
113410 +config PAX_EMUSIGRT
113411 + bool "Automatically emulate sigreturn trampolines"
113412 + depends on PAX_EMUTRAMP && PARISC
113413 + default y
113414 + help
113415 + Enabling this option will have the kernel automatically detect
113416 + and emulate signal return trampolines executing on the stack
113417 + that would otherwise lead to task termination.
113418 +
113419 + This solution is intended as a temporary one for users with
113420 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
113421 + Modula-3 runtime, etc) or executables linked to such, basically
113422 + everything that does not specify its own SA_RESTORER function in
113423 + normal executable memory like glibc 2.1+ does.
113424 +
113425 + On parisc you MUST enable this option, otherwise your system will
113426 + not even boot.
113427 +
113428 + NOTE: this feature cannot be disabled on a per executable basis
113429 + and since it *does* open up a loophole in the protection provided
113430 + by non-executable pages, the best solution is to not have any
113431 + files on your system that would require this option.
113432 +
113433 +config PAX_MPROTECT
113434 + bool "Restrict mprotect()"
113435 + default y if GRKERNSEC_CONFIG_AUTO
113436 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
113437 + help
113438 + Enabling this option will prevent programs from
113439 + - changing the executable status of memory pages that were
113440 + not originally created as executable,
113441 + - making read-only executable pages writable again,
113442 + - creating executable pages from anonymous memory,
113443 + - making read-only-after-relocations (RELRO) data pages writable again.
113444 +
113445 + You should say Y here to complete the protection provided by
113446 + the enforcement of non-executable pages.
113447 +
113448 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
113449 + this feature on a per file basis.
113450 +
113451 +config PAX_MPROTECT_COMPAT
113452 + bool "Use legacy/compat protection demoting (read help)"
113453 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
113454 + depends on PAX_MPROTECT
113455 + help
113456 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
113457 + by sending the proper error code to the application. For some broken
113458 + userland, this can cause problems with Python or other applications. The
113459 + current implementation however allows for applications like clamav to
113460 + detect if JIT compilation/execution is allowed and to fall back gracefully
113461 + to an interpreter-based mode if it does not. While we encourage everyone
113462 + to use the current implementation as-is and push upstream to fix broken
113463 + userland (note that the RWX logging option can assist with this), in some
113464 + environments this may not be possible. Having to disable MPROTECT
113465 + completely on certain binaries reduces the security benefit of PaX,
113466 + so this option is provided for those environments to revert to the old
113467 + behavior.
113468 +
113469 +config PAX_ELFRELOCS
113470 + bool "Allow ELF text relocations (read help)"
113471 + depends on PAX_MPROTECT
113472 + default n
113473 + help
113474 + Non-executable pages and mprotect() restrictions are effective
113475 + in preventing the introduction of new executable code into an
113476 + attacked task's address space. There remain only two venues
113477 + for this kind of attack: if the attacker can execute already
113478 + existing code in the attacked task then he can either have it
113479 + create and mmap() a file containing his code or have it mmap()
113480 + an already existing ELF library that does not have position
113481 + independent code in it and use mprotect() on it to make it
113482 + writable and copy his code there. While protecting against
113483 + the former approach is beyond PaX, the latter can be prevented
113484 + by having only PIC ELF libraries on one's system (which do not
113485 + need to relocate their code). If you are sure this is your case,
113486 + as is the case with all modern Linux distributions, then leave
113487 + this option disabled. You should say 'n' here.
113488 +
113489 +config PAX_ETEXECRELOCS
113490 + bool "Allow ELF ET_EXEC text relocations"
113491 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
113492 + select PAX_ELFRELOCS
113493 + default y
113494 + help
113495 + On some architectures there are incorrectly created applications
113496 + that require text relocations and would not work without enabling
113497 + this option. If you are an alpha, ia64 or parisc user, you should
113498 + enable this option and disable it once you have made sure that
113499 + none of your applications need it.
113500 +
113501 +config PAX_EMUPLT
113502 + bool "Automatically emulate ELF PLT"
113503 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
113504 + default y
113505 + help
113506 + Enabling this option will have the kernel automatically detect
113507 + and emulate the Procedure Linkage Table entries in ELF files.
113508 + On some architectures such entries are in writable memory, and
113509 + become non-executable leading to task termination. Therefore
113510 + it is mandatory that you enable this option on alpha, parisc,
113511 + sparc and sparc64, otherwise your system would not even boot.
113512 +
113513 + NOTE: this feature *does* open up a loophole in the protection
113514 + provided by the non-executable pages, therefore the proper
113515 + solution is to modify the toolchain to produce a PLT that does
113516 + not need to be writable.
113517 +
113518 +config PAX_DLRESOLVE
113519 + bool 'Emulate old glibc resolver stub'
113520 + depends on PAX_EMUPLT && SPARC
113521 + default n
113522 + help
113523 + This option is needed if userland has an old glibc (before 2.4)
113524 + that puts a 'save' instruction into the runtime generated resolver
113525 + stub that needs special emulation.
113526 +
113527 +config PAX_KERNEXEC
113528 + bool "Enforce non-executable kernel pages"
113529 + default y if GRKERNSEC_CONFIG_AUTO && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_GUEST) || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_KVM))
113530 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
113531 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
113532 + select PAX_KERNEXEC_PLUGIN if X86_64
113533 + help
113534 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
113535 + that is, enabling this option will make it harder to inject
113536 + and execute 'foreign' code in kernel memory itself.
113537 +
113538 +choice
113539 + prompt "Return Address Instrumentation Method"
113540 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
113541 + depends on PAX_KERNEXEC_PLUGIN
113542 + help
113543 + Select the method used to instrument function pointer dereferences.
113544 + Note that binary modules cannot be instrumented by this approach.
113545 +
113546 + Note that the implementation requires a gcc with plugin support,
113547 + i.e., gcc 4.5 or newer. You may need to install the supporting
113548 + headers explicitly in addition to the normal gcc package.
113549 +
113550 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
113551 + bool "bts"
113552 + help
113553 + This method is compatible with binary only modules but has
113554 + a higher runtime overhead.
113555 +
113556 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
113557 + bool "or"
113558 + depends on !PARAVIRT
113559 + help
113560 + This method is incompatible with binary only modules but has
113561 + a lower runtime overhead.
113562 +endchoice
113563 +
113564 +config PAX_KERNEXEC_PLUGIN_METHOD
113565 + string
113566 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
113567 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
113568 + default ""
113569 +
113570 +config PAX_KERNEXEC_MODULE_TEXT
113571 + int "Minimum amount of memory reserved for module code"
113572 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
113573 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
113574 + depends on PAX_KERNEXEC && X86_32
113575 + help
113576 + Due to implementation details the kernel must reserve a fixed
113577 + amount of memory for runtime allocated code (such as modules)
113578 + at compile time that cannot be changed at runtime. Here you
113579 + can specify the minimum amount in MB that will be reserved.
113580 + Due to the same implementation details this size will always
113581 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
113582 + the actually available memory for runtime allocated code will
113583 + usually be more than this minimum.
113584 +
113585 + The default 4 MB should be enough for most users but if you have
113586 + an excessive number of modules (e.g., most distribution configs
113587 + compile many drivers as modules) or use huge modules such as
113588 + nvidia's kernel driver, you will need to adjust this amount.
113589 + A good rule of thumb is to look at your currently loaded kernel
113590 + modules and add up their sizes.
113591 +
113592 +endmenu
113593 +
113594 +menu "Address Space Layout Randomization"
113595 + depends on PAX
113596 +
113597 +config PAX_ASLR
113598 + bool "Address Space Layout Randomization"
113599 + default y if GRKERNSEC_CONFIG_AUTO
113600 + help
113601 + Many if not most exploit techniques rely on the knowledge of
113602 + certain addresses in the attacked program. The following options
113603 + will allow the kernel to apply a certain amount of randomization
113604 + to specific parts of the program thereby forcing an attacker to
113605 + guess them in most cases. Any failed guess will most likely crash
113606 + the attacked program which allows the kernel to detect such attempts
113607 + and react on them. PaX itself provides no reaction mechanisms,
113608 + instead it is strongly encouraged that you make use of grsecurity's
113609 + (http://www.grsecurity.net/) built-in crash detection features or
113610 + develop one yourself.
113611 +
113612 + By saying Y here you can choose to randomize the following areas:
113613 + - top of the task's kernel stack
113614 + - top of the task's userland stack
113615 + - base address for mmap() requests that do not specify one
113616 + (this includes all libraries)
113617 + - base address of the main executable
113618 +
113619 + It is strongly recommended to say Y here as address space layout
113620 + randomization has negligible impact on performance yet it provides
113621 + a very effective protection.
113622 +
113623 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
113624 + this feature on a per file basis.
113625 +
113626 +config PAX_RANDKSTACK
113627 + bool "Randomize kernel stack base"
113628 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
113629 + depends on X86_TSC && X86
113630 + help
113631 + By saying Y here the kernel will randomize every task's kernel
113632 + stack on every system call. This will not only force an attacker
113633 + to guess it but also prevent him from making use of possible
113634 + leaked information about it.
113635 +
113636 + Since the kernel stack is a rather scarce resource, randomization
113637 + may cause unexpected stack overflows, therefore you should very
113638 + carefully test your system. Note that once enabled in the kernel
113639 + configuration, this feature cannot be disabled on a per file basis.
113640 +
113641 +config PAX_RANDUSTACK
113642 + bool
113643 +
113644 +config PAX_RANDMMAP
113645 + bool "Randomize user stack and mmap() bases"
113646 + default y if GRKERNSEC_CONFIG_AUTO
113647 + depends on PAX_ASLR
113648 + select PAX_RANDUSTACK
113649 + help
113650 + By saying Y here the kernel will randomize every task's userland
113651 + stack and use a randomized base address for mmap() requests that
113652 + do not specify one themselves.
113653 +
113654 + The stack randomization is done in two steps where the second
113655 + one may apply a big amount of shift to the top of the stack and
113656 + cause problems for programs that want to use lots of memory (more
113657 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
113658 +
113659 + As a result of mmap randomization all dynamically loaded libraries
113660 + will appear at random addresses and therefore be harder to exploit
113661 + by a technique where an attacker attempts to execute library code
113662 + for his purposes (e.g. spawn a shell from an exploited program that
113663 + is running at an elevated privilege level).
113664 +
113665 + Furthermore, if a program is relinked as a dynamic ELF file, its
113666 + base address will be randomized as well, completing the full
113667 + randomization of the address space layout. Attacking such programs
113668 + becomes a guess game. You can find an example of doing this at
113669 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
113670 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
113671 +
113672 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
113673 + feature on a per file basis.
113674 +
113675 +endmenu
113676 +
113677 +menu "Miscellaneous hardening features"
113678 +
113679 +config PAX_MEMORY_SANITIZE
113680 + bool "Sanitize all freed memory"
113681 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
113682 + help
113683 + By saying Y here the kernel will erase memory pages and slab objects
113684 + as soon as they are freed. This in turn reduces the lifetime of data
113685 + stored in them, making it less likely that sensitive information such
113686 + as passwords, cryptographic secrets, etc stay in memory for too long.
113687 +
113688 + This is especially useful for programs whose runtime is short, long
113689 + lived processes and the kernel itself benefit from this as long as
113690 + they ensure timely freeing of memory that may hold sensitive
113691 + information.
113692 +
113693 + A nice side effect of the sanitization of slab objects is the
113694 + reduction of possible info leaks caused by padding bytes within the
113695 + leaky structures. Use-after-free bugs for structures containing
113696 + pointers can also be detected as dereferencing the sanitized pointer
113697 + will generate an access violation.
113698 +
113699 + The tradeoff is performance impact, on a single CPU system kernel
113700 + compilation sees a 3% slowdown, other systems and workloads may vary
113701 + and you are advised to test this feature on your expected workload
113702 + before deploying it.
113703 +
113704 + To reduce the performance penalty by sanitizing pages only, albeit
113705 + limiting the effectiveness of this feature at the same time, slab
113706 + sanitization can be disabled with the kernel commandline parameter
113707 + "pax_sanitize_slab=0".
113708 +
113709 + Note that this feature does not protect data stored in live pages,
113710 + e.g., process memory swapped to disk may stay there for a long time.
113711 +
113712 +config PAX_MEMORY_STACKLEAK
113713 + bool "Sanitize kernel stack"
113714 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
113715 + depends on X86
113716 + help
113717 + By saying Y here the kernel will erase the kernel stack before it
113718 + returns from a system call. This in turn reduces the information
113719 + that a kernel stack leak bug can reveal.
113720 +
113721 + Note that such a bug can still leak information that was put on
113722 + the stack by the current system call (the one eventually triggering
113723 + the bug) but traces of earlier system calls on the kernel stack
113724 + cannot leak anymore.
113725 +
113726 + The tradeoff is performance impact: on a single CPU system kernel
113727 + compilation sees a 1% slowdown, other systems and workloads may vary
113728 + and you are advised to test this feature on your expected workload
113729 + before deploying it.
113730 +
113731 + Note that the full feature requires a gcc with plugin support,
113732 + i.e., gcc 4.5 or newer. You may need to install the supporting
113733 + headers explicitly in addition to the normal gcc package. Using
113734 + older gcc versions means that functions with large enough stack
113735 + frames may leave uninitialized memory behind that may be exposed
113736 + to a later syscall leaking the stack.
113737 +
113738 +config PAX_MEMORY_STRUCTLEAK
113739 + bool "Forcibly initialize local variables copied to userland"
113740 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
113741 + help
113742 + By saying Y here the kernel will zero initialize some local
113743 + variables that are going to be copied to userland. This in
113744 + turn prevents unintended information leakage from the kernel
113745 + stack should later code forget to explicitly set all parts of
113746 + the copied variable.
113747 +
113748 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
113749 + at a much smaller coverage.
113750 +
113751 + Note that the implementation requires a gcc with plugin support,
113752 + i.e., gcc 4.5 or newer. You may need to install the supporting
113753 + headers explicitly in addition to the normal gcc package.
113754 +
113755 +config PAX_MEMORY_UDEREF
113756 + bool "Prevent invalid userland pointer dereference"
113757 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
113758 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
113759 + select PAX_PER_CPU_PGD if X86_64
113760 + help
113761 + By saying Y here the kernel will be prevented from dereferencing
113762 + userland pointers in contexts where the kernel expects only kernel
113763 + pointers. This is both a useful runtime debugging feature and a
113764 + security measure that prevents exploiting a class of kernel bugs.
113765 +
113766 + The tradeoff is that some virtualization solutions may experience
113767 + a huge slowdown and therefore you should not enable this feature
113768 + for kernels meant to run in such environments. Whether a given VM
113769 + solution is affected or not is best determined by simply trying it
113770 + out, the performance impact will be obvious right on boot as this
113771 + mechanism engages from very early on. A good rule of thumb is that
113772 + VMs running on CPUs without hardware virtualization support (i.e.,
113773 + the majority of IA-32 CPUs) will likely experience the slowdown.
113774 +
113775 + On X86_64 the kernel will make use of PCID support when available
113776 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
113777 + or performance impact. Pass pax_weakuderef on the kernel command
113778 + line to choose the latter.
113779 +
113780 +config PAX_REFCOUNT
113781 + bool "Prevent various kernel object reference counter overflows"
113782 + default y if GRKERNSEC_CONFIG_AUTO
113783 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
113784 + help
113785 + By saying Y here the kernel will detect and prevent overflowing
113786 + various (but not all) kinds of object reference counters. Such
113787 + overflows can normally occur due to bugs only and are often, if
113788 + not always, exploitable.
113789 +
113790 + The tradeoff is that data structures protected by an overflowed
113791 + refcount will never be freed and therefore will leak memory. Note
113792 + that this leak also happens even without this protection but in
113793 + that case the overflow can eventually trigger the freeing of the
113794 + data structure while it is still being used elsewhere, resulting
113795 + in the exploitable situation that this feature prevents.
113796 +
113797 + Since this has a negligible performance impact, you should enable
113798 + this feature.
113799 +
113800 +config PAX_CONSTIFY_PLUGIN
113801 + bool "Automatically constify eligible structures"
113802 + default y
113803 + depends on !UML && PAX_KERNEXEC
113804 + help
113805 + By saying Y here the compiler will automatically constify a class
113806 + of types that contain only function pointers. This reduces the
113807 + kernel's attack surface and also produces a better memory layout.
113808 +
113809 + Note that the implementation requires a gcc with plugin support,
113810 + i.e., gcc 4.5 or newer. You may need to install the supporting
113811 + headers explicitly in addition to the normal gcc package.
113812 +
113813 + Note that if some code really has to modify constified variables
113814 + then the source code will have to be patched to allow it. Examples
113815 + can be found in PaX itself (the no_const attribute) and for some
113816 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
113817 +
113818 +config PAX_USERCOPY
113819 + bool "Harden heap object copies between kernel and userland"
113820 + default y if GRKERNSEC_CONFIG_AUTO
113821 + depends on ARM || IA64 || PPC || SPARC || X86
113822 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
113823 + select PAX_USERCOPY_SLABS
113824 + help
113825 + By saying Y here the kernel will enforce the size of heap objects
113826 + when they are copied in either direction between the kernel and
113827 + userland, even if only a part of the heap object is copied.
113828 +
113829 + Specifically, this checking prevents information leaking from the
113830 + kernel heap during kernel to userland copies (if the kernel heap
113831 + object is otherwise fully initialized) and prevents kernel heap
113832 + overflows during userland to kernel copies.
113833 +
113834 + Note that the current implementation provides the strictest bounds
113835 + checks for the SLUB allocator.
113836 +
113837 + Enabling this option also enables per-slab cache protection against
113838 + data in a given cache being copied into/out of via userland
113839 + accessors. Though the whitelist of regions will be reduced over
113840 + time, it notably protects important data structures like task structs.
113841 +
113842 + If frame pointers are enabled on x86, this option will also restrict
113843 + copies into and out of the kernel stack to local variables within a
113844 + single frame.
113845 +
113846 + Since this has a negligible performance impact, you should enable
113847 + this feature.
113848 +
113849 +config PAX_USERCOPY_DEBUG
113850 + bool
113851 + depends on X86 && PAX_USERCOPY
113852 + default n
113853 +
113854 +config PAX_SIZE_OVERFLOW
113855 + bool "Prevent various integer overflows in function size parameters"
113856 + default y if GRKERNSEC_CONFIG_AUTO
113857 + depends on X86
113858 + help
113859 + By saying Y here the kernel recomputes expressions of function
113860 + arguments marked by a size_overflow attribute with double integer
113861 + precision (DImode/TImode for 32/64 bit integer types).
113862 +
113863 + The recomputed argument is checked against TYPE_MAX and an event
113864 + is logged on overflow and the triggering process is killed.
113865 +
113866 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
113867 +
113868 + Note that the implementation requires a gcc with plugin support,
113869 + i.e., gcc 4.5 or newer. You may need to install the supporting
113870 + headers explicitly in addition to the normal gcc package.
113871 +
113872 +config PAX_LATENT_ENTROPY
113873 + bool "Generate some entropy during boot and runtime"
113874 + default y if GRKERNSEC_CONFIG_AUTO
113875 + help
113876 + By saying Y here the kernel will instrument some kernel code to
113877 + extract some entropy from both original and artificially created
113878 + program state. This will help especially embedded systems where
113879 + there is little 'natural' source of entropy normally. The cost
113880 + is some slowdown of the boot process and fork and irq processing.
113881 +
113882 + When pax_extra_latent_entropy is passed on the kernel command line,
113883 + entropy will be extracted from up to the first 4GB of RAM while the
113884 + runtime memory allocator is being initialized. This costs even more
113885 + slowdown of the boot process.
113886 +
113887 + Note that the implementation requires a gcc with plugin support,
113888 + i.e., gcc 4.5 or newer. You may need to install the supporting
113889 + headers explicitly in addition to the normal gcc package.
113890 +
113891 + Note that entropy extracted this way is not cryptographically
113892 + secure!
113893 +
113894 +endmenu
113895 +
113896 +endmenu
113897 +
113898 +source grsecurity/Kconfig
113899 +
113900 +endmenu
113901 +
113902 +endmenu
113903 +
113904 source security/keys/Kconfig
113905
113906 config SECURITY_DMESG_RESTRICT
113907 @@ -103,7 +1054,7 @@ config INTEL_TXT
113908 config LSM_MMAP_MIN_ADDR
113909 int "Low address space for LSM to protect from user allocation"
113910 depends on SECURITY && SECURITY_SELINUX
113911 - default 32768 if ARM || (ARM64 && COMPAT)
113912 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
113913 default 65536
113914 help
113915 This is the portion of low virtual memory which should be protected
113916 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
113917 index fdaa50c..2761dcb 100644
113918 --- a/security/apparmor/file.c
113919 +++ b/security/apparmor/file.c
113920 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
113921 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
113922 struct path *new_dir, struct dentry *new_dentry)
113923 {
113924 - struct path link = { new_dir->mnt, new_dentry };
113925 - struct path target = { new_dir->mnt, old_dentry };
113926 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
113927 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
113928 struct path_cond cond = {
113929 old_dentry->d_inode->i_uid,
113930 old_dentry->d_inode->i_mode
113931 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
113932 index 9981000..eb21356 100644
113933 --- a/security/apparmor/lsm.c
113934 +++ b/security/apparmor/lsm.c
113935 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
113936 struct dentry *dentry, u32 mask,
113937 struct path_cond *cond)
113938 {
113939 - struct path path = { dir->mnt, dentry };
113940 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
113941
113942 return common_perm(op, &path, mask, cond);
113943 }
113944 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
113945 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
113946 struct dentry *dentry, u32 mask)
113947 {
113948 - struct path path = { mnt, dentry };
113949 + struct path path = { .mnt = mnt, .dentry = dentry };
113950 struct path_cond cond = { dentry->d_inode->i_uid,
113951 dentry->d_inode->i_mode
113952 };
113953 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
113954
113955 profile = aa_current_profile();
113956 if (!unconfined(profile)) {
113957 - struct path old_path = { old_dir->mnt, old_dentry };
113958 - struct path new_path = { new_dir->mnt, new_dentry };
113959 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
113960 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
113961 struct path_cond cond = { old_dentry->d_inode->i_uid,
113962 old_dentry->d_inode->i_mode
113963 };
113964 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
113965 return error;
113966 }
113967
113968 -static struct security_operations apparmor_ops = {
113969 +static struct security_operations apparmor_ops __read_only = {
113970 .name = "apparmor",
113971
113972 .ptrace_access_check = apparmor_ptrace_access_check,
113973 diff --git a/security/commoncap.c b/security/commoncap.c
113974 index b9d613e..f68305c 100644
113975 --- a/security/commoncap.c
113976 +++ b/security/commoncap.c
113977 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
113978 return 0;
113979 }
113980
113981 +/* returns:
113982 + 1 for suid privilege
113983 + 2 for sgid privilege
113984 + 3 for fscap privilege
113985 +*/
113986 +int is_privileged_binary(const struct dentry *dentry)
113987 +{
113988 + struct cpu_vfs_cap_data capdata;
113989 + struct inode *inode = dentry->d_inode;
113990 +
113991 + if (!inode || S_ISDIR(inode->i_mode))
113992 + return 0;
113993 +
113994 + if (inode->i_mode & S_ISUID)
113995 + return 1;
113996 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
113997 + return 2;
113998 +
113999 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
114000 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
114001 + return 3;
114002 + }
114003 +
114004 + return 0;
114005 +}
114006 +
114007 /*
114008 * Attempt to get the on-exec apply capability sets for an executable file from
114009 * its xattrs and, if present, apply them to the proposed credentials being
114010 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
114011 const struct cred *cred = current_cred();
114012 kuid_t root_uid = make_kuid(cred->user_ns, 0);
114013
114014 + if (gr_acl_enable_at_secure())
114015 + return 1;
114016 +
114017 if (!uid_eq(cred->uid, root_uid)) {
114018 if (bprm->cap_effective)
114019 return 1;
114020 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
114021 index f79fa8b..6161868 100644
114022 --- a/security/integrity/ima/ima.h
114023 +++ b/security/integrity/ima/ima.h
114024 @@ -118,8 +118,8 @@ int ima_init_template(void);
114025 extern spinlock_t ima_queue_lock;
114026
114027 struct ima_h_table {
114028 - atomic_long_t len; /* number of stored measurements in the list */
114029 - atomic_long_t violations;
114030 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
114031 + atomic_long_unchecked_t violations;
114032 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
114033 };
114034 extern struct ima_h_table ima_htable;
114035 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
114036 index d9cd5ce..c5c29ac 100644
114037 --- a/security/integrity/ima/ima_api.c
114038 +++ b/security/integrity/ima/ima_api.c
114039 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
114040 int result;
114041
114042 /* can overflow, only indicator */
114043 - atomic_long_inc(&ima_htable.violations);
114044 + atomic_long_inc_unchecked(&ima_htable.violations);
114045
114046 result = ima_alloc_init_template(NULL, file, filename,
114047 NULL, 0, &entry);
114048 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
114049 index da92fcc..8a5d390 100644
114050 --- a/security/integrity/ima/ima_fs.c
114051 +++ b/security/integrity/ima/ima_fs.c
114052 @@ -28,12 +28,12 @@
114053 static int valid_policy = 1;
114054 #define TMPBUFLEN 12
114055 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
114056 - loff_t *ppos, atomic_long_t *val)
114057 + loff_t *ppos, atomic_long_unchecked_t *val)
114058 {
114059 char tmpbuf[TMPBUFLEN];
114060 ssize_t len;
114061
114062 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
114063 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
114064 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
114065 }
114066
114067 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
114068 index 552705d..9920f4fb 100644
114069 --- a/security/integrity/ima/ima_queue.c
114070 +++ b/security/integrity/ima/ima_queue.c
114071 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
114072 INIT_LIST_HEAD(&qe->later);
114073 list_add_tail_rcu(&qe->later, &ima_measurements);
114074
114075 - atomic_long_inc(&ima_htable.len);
114076 + atomic_long_inc_unchecked(&ima_htable.len);
114077 key = ima_hash_key(entry->digest);
114078 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
114079 return 0;
114080 diff --git a/security/keys/compat.c b/security/keys/compat.c
114081 index 3478965..ec7bb9e 100644
114082 --- a/security/keys/compat.c
114083 +++ b/security/keys/compat.c
114084 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
114085 if (ret == 0)
114086 goto no_payload_free;
114087
114088 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
114089 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
114090 err:
114091 if (iov != iovstack)
114092 kfree(iov);
114093 diff --git a/security/keys/internal.h b/security/keys/internal.h
114094 index 5f20da0..444ccf1 100644
114095 --- a/security/keys/internal.h
114096 +++ b/security/keys/internal.h
114097 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
114098 extern long keyctl_invalidate_key(key_serial_t);
114099
114100 extern long keyctl_instantiate_key_common(key_serial_t,
114101 - const struct iovec *,
114102 + const struct iovec __user *,
114103 unsigned, size_t, key_serial_t);
114104 #ifdef CONFIG_PERSISTENT_KEYRINGS
114105 extern long keyctl_get_persistent(uid_t, key_serial_t);
114106 diff --git a/security/keys/key.c b/security/keys/key.c
114107 index 2048a11..101df4c 100644
114108 --- a/security/keys/key.c
114109 +++ b/security/keys/key.c
114110 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
114111
114112 atomic_set(&key->usage, 1);
114113 init_rwsem(&key->sem);
114114 - lockdep_set_class(&key->sem, &type->lock_class);
114115 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
114116 key->index_key.type = type;
114117 key->user = user;
114118 key->quotalen = quotalen;
114119 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
114120 struct key_type *p;
114121 int ret;
114122
114123 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
114124 + pax_open_kernel();
114125 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
114126 + pax_close_kernel();
114127
114128 ret = -EEXIST;
114129 down_write(&key_types_sem);
114130 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
114131 }
114132
114133 /* store the type */
114134 - list_add(&ktype->link, &key_types_list);
114135 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
114136
114137 pr_notice("Key type %s registered\n", ktype->name);
114138 ret = 0;
114139 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
114140 void unregister_key_type(struct key_type *ktype)
114141 {
114142 down_write(&key_types_sem);
114143 - list_del_init(&ktype->link);
114144 + pax_list_del_init((struct list_head *)&ktype->link);
114145 downgrade_write(&key_types_sem);
114146 key_gc_keytype(ktype);
114147 pr_notice("Key type %s unregistered\n", ktype->name);
114148 @@ -1088,10 +1090,10 @@ void __init key_init(void)
114149 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
114150
114151 /* add the special key types */
114152 - list_add_tail(&key_type_keyring.link, &key_types_list);
114153 - list_add_tail(&key_type_dead.link, &key_types_list);
114154 - list_add_tail(&key_type_user.link, &key_types_list);
114155 - list_add_tail(&key_type_logon.link, &key_types_list);
114156 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
114157 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
114158 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
114159 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
114160
114161 /* record the root user tracking */
114162 rb_link_node(&root_key_user.node,
114163 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
114164 index cd5bd0c..acd0d5c 100644
114165 --- a/security/keys/keyctl.c
114166 +++ b/security/keys/keyctl.c
114167 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
114168 /*
114169 * Copy the iovec data from userspace
114170 */
114171 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
114172 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
114173 unsigned ioc)
114174 {
114175 for (; ioc > 0; ioc--) {
114176 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
114177 * If successful, 0 will be returned.
114178 */
114179 long keyctl_instantiate_key_common(key_serial_t id,
114180 - const struct iovec *payload_iov,
114181 + const struct iovec __user *payload_iov,
114182 unsigned ioc,
114183 size_t plen,
114184 key_serial_t ringid)
114185 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
114186 [0].iov_len = plen
114187 };
114188
114189 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
114190 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
114191 }
114192
114193 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
114194 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
114195 if (ret == 0)
114196 goto no_payload_free;
114197
114198 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
114199 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
114200 err:
114201 if (iov != iovstack)
114202 kfree(iov);
114203 diff --git a/security/min_addr.c b/security/min_addr.c
114204 index f728728..6457a0c 100644
114205 --- a/security/min_addr.c
114206 +++ b/security/min_addr.c
114207 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
114208 */
114209 static void update_mmap_min_addr(void)
114210 {
114211 +#ifndef SPARC
114212 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
114213 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
114214 mmap_min_addr = dac_mmap_min_addr;
114215 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
114216 #else
114217 mmap_min_addr = dac_mmap_min_addr;
114218 #endif
114219 +#endif
114220 }
114221
114222 /*
114223 diff --git a/security/security.c b/security/security.c
114224 index 31614e9..8b86b12 100644
114225 --- a/security/security.c
114226 +++ b/security/security.c
114227 @@ -33,8 +33,8 @@
114228 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
114229 CONFIG_DEFAULT_SECURITY;
114230
114231 -static struct security_operations *security_ops;
114232 -static struct security_operations default_security_ops = {
114233 +struct security_operations *security_ops __read_only;
114234 +struct security_operations default_security_ops __read_only = {
114235 .name = "default",
114236 };
114237
114238 @@ -73,11 +73,6 @@ int __init security_init(void)
114239 return 0;
114240 }
114241
114242 -void reset_security_ops(void)
114243 -{
114244 - security_ops = &default_security_ops;
114245 -}
114246 -
114247 /* Save user chosen LSM */
114248 static int __init choose_lsm(char *str)
114249 {
114250 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
114251 index a18f1fa..c9b9fc4 100644
114252 --- a/security/selinux/avc.c
114253 +++ b/security/selinux/avc.c
114254 @@ -59,7 +59,7 @@ struct avc_node {
114255 struct avc_cache {
114256 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
114257 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
114258 - atomic_t lru_hint; /* LRU hint for reclaim scan */
114259 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
114260 atomic_t active_nodes;
114261 u32 latest_notif; /* latest revocation notification */
114262 };
114263 @@ -167,7 +167,7 @@ void __init avc_init(void)
114264 spin_lock_init(&avc_cache.slots_lock[i]);
114265 }
114266 atomic_set(&avc_cache.active_nodes, 0);
114267 - atomic_set(&avc_cache.lru_hint, 0);
114268 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
114269
114270 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
114271 0, SLAB_PANIC, NULL);
114272 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
114273 spinlock_t *lock;
114274
114275 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
114276 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
114277 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
114278 head = &avc_cache.slots[hvalue];
114279 lock = &avc_cache.slots_lock[hvalue];
114280
114281 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
114282 index 83d06db..d4d6861 100644
114283 --- a/security/selinux/hooks.c
114284 +++ b/security/selinux/hooks.c
114285 @@ -95,8 +95,6 @@
114286 #include "audit.h"
114287 #include "avc_ss.h"
114288
114289 -extern struct security_operations *security_ops;
114290 -
114291 /* SECMARK reference count */
114292 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
114293
114294 @@ -5761,7 +5759,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
114295
114296 #endif
114297
114298 -static struct security_operations selinux_ops = {
114299 +static struct security_operations selinux_ops __read_only = {
114300 .name = "selinux",
114301
114302 .ptrace_access_check = selinux_ptrace_access_check,
114303 @@ -6114,6 +6112,9 @@ static void selinux_nf_ip_exit(void)
114304 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
114305 static int selinux_disabled;
114306
114307 +extern struct security_operations *security_ops;
114308 +extern struct security_operations default_security_ops;
114309 +
114310 int selinux_disable(void)
114311 {
114312 if (ss_initialized) {
114313 @@ -6131,7 +6132,9 @@ int selinux_disable(void)
114314 selinux_disabled = 1;
114315 selinux_enabled = 0;
114316
114317 - reset_security_ops();
114318 + pax_open_kernel();
114319 + security_ops = &default_security_ops;
114320 + pax_close_kernel();
114321
114322 /* Try to destroy the avc node cache */
114323 avc_disable();
114324 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
114325 index 1450f85..a91e0bc 100644
114326 --- a/security/selinux/include/xfrm.h
114327 +++ b/security/selinux/include/xfrm.h
114328 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
114329
114330 rtnl_lock();
114331 for_each_net(net) {
114332 - atomic_inc(&net->xfrm.flow_cache_genid);
114333 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
114334 rt_genid_bump_all(net);
114335 }
114336 rtnl_unlock();
114337 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
114338 index f2c3080..813c85e 100644
114339 --- a/security/smack/smack_lsm.c
114340 +++ b/security/smack/smack_lsm.c
114341 @@ -3849,7 +3849,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
114342 return 0;
114343 }
114344
114345 -struct security_operations smack_ops = {
114346 +struct security_operations smack_ops __read_only = {
114347 .name = "smack",
114348
114349 .ptrace_access_check = smack_ptrace_access_check,
114350 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
114351 index 4003907..13a2b55 100644
114352 --- a/security/tomoyo/file.c
114353 +++ b/security/tomoyo/file.c
114354 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
114355 {
114356 struct tomoyo_request_info r;
114357 struct tomoyo_obj_info obj = {
114358 - .path1 = *path,
114359 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
114360 };
114361 int error = -ENOMEM;
114362 struct tomoyo_path_info buf;
114363 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
114364 struct tomoyo_path_info buf;
114365 struct tomoyo_request_info r;
114366 struct tomoyo_obj_info obj = {
114367 - .path1 = *path,
114368 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
114369 };
114370 int idx;
114371
114372 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
114373 {
114374 struct tomoyo_request_info r;
114375 struct tomoyo_obj_info obj = {
114376 - .path1 = *path,
114377 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
114378 };
114379 int error;
114380 struct tomoyo_path_info buf;
114381 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
114382 {
114383 struct tomoyo_request_info r;
114384 struct tomoyo_obj_info obj = {
114385 - .path1 = *path,
114386 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
114387 };
114388 int error = -ENOMEM;
114389 struct tomoyo_path_info buf;
114390 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
114391 struct tomoyo_path_info buf2;
114392 struct tomoyo_request_info r;
114393 struct tomoyo_obj_info obj = {
114394 - .path1 = *path1,
114395 - .path2 = *path2,
114396 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
114397 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
114398 };
114399 int idx;
114400
114401 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
114402 index 390c646..f2f8db3 100644
114403 --- a/security/tomoyo/mount.c
114404 +++ b/security/tomoyo/mount.c
114405 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
114406 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
114407 need_dev = -1; /* dev_name is a directory */
114408 } else {
114409 + if (!capable(CAP_SYS_ADMIN)) {
114410 + error = -EPERM;
114411 + goto out;
114412 + }
114413 fstype = get_fs_type(type);
114414 if (!fstype) {
114415 error = -ENODEV;
114416 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
114417 index f0b756e..8aa497b 100644
114418 --- a/security/tomoyo/tomoyo.c
114419 +++ b/security/tomoyo/tomoyo.c
114420 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
114421 */
114422 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
114423 {
114424 - struct path path = { mnt, dentry };
114425 + struct path path = { .mnt = mnt, .dentry = dentry };
114426 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
114427 }
114428
114429 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
114430 */
114431 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
114432 {
114433 - struct path path = { parent->mnt, dentry };
114434 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
114435 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
114436 }
114437
114438 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
114439 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
114440 umode_t mode)
114441 {
114442 - struct path path = { parent->mnt, dentry };
114443 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
114444 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
114445 mode & S_IALLUGO);
114446 }
114447 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
114448 */
114449 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
114450 {
114451 - struct path path = { parent->mnt, dentry };
114452 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
114453 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
114454 }
114455
114456 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
114457 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
114458 const char *old_name)
114459 {
114460 - struct path path = { parent->mnt, dentry };
114461 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
114462 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
114463 }
114464
114465 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
114466 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
114467 umode_t mode, unsigned int dev)
114468 {
114469 - struct path path = { parent->mnt, dentry };
114470 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
114471 int type = TOMOYO_TYPE_CREATE;
114472 const unsigned int perm = mode & S_IALLUGO;
114473
114474 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
114475 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
114476 struct dentry *new_dentry)
114477 {
114478 - struct path path1 = { new_dir->mnt, old_dentry };
114479 - struct path path2 = { new_dir->mnt, new_dentry };
114480 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
114481 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
114482 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
114483 }
114484
114485 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
114486 struct path *new_parent,
114487 struct dentry *new_dentry)
114488 {
114489 - struct path path1 = { old_parent->mnt, old_dentry };
114490 - struct path path2 = { new_parent->mnt, new_dentry };
114491 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
114492 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
114493 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
114494 }
114495
114496 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
114497 */
114498 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
114499 {
114500 - struct path path = { mnt, mnt->mnt_root };
114501 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
114502 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
114503 }
114504
114505 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
114506 * tomoyo_security_ops is a "struct security_operations" which is used for
114507 * registering TOMOYO.
114508 */
114509 -static struct security_operations tomoyo_security_ops = {
114510 +static struct security_operations tomoyo_security_ops __read_only = {
114511 .name = "tomoyo",
114512 .cred_alloc_blank = tomoyo_cred_alloc_blank,
114513 .cred_prepare = tomoyo_cred_prepare,
114514 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
114515 index 20ef514..4182bed 100644
114516 --- a/security/yama/Kconfig
114517 +++ b/security/yama/Kconfig
114518 @@ -1,6 +1,6 @@
114519 config SECURITY_YAMA
114520 bool "Yama support"
114521 - depends on SECURITY
114522 + depends on SECURITY && !GRKERNSEC
114523 select SECURITYFS
114524 select SECURITY_PATH
114525 default n
114526 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
114527 index 13c88fbc..f8c115e 100644
114528 --- a/security/yama/yama_lsm.c
114529 +++ b/security/yama/yama_lsm.c
114530 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
114531 }
114532
114533 #ifndef CONFIG_SECURITY_YAMA_STACKED
114534 -static struct security_operations yama_ops = {
114535 +static struct security_operations yama_ops __read_only = {
114536 .name = "yama",
114537
114538 .ptrace_access_check = yama_ptrace_access_check,
114539 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
114540 #endif
114541
114542 #ifdef CONFIG_SYSCTL
114543 +static int zero __read_only;
114544 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
114545 +
114546 static int yama_dointvec_minmax(struct ctl_table *table, int write,
114547 void __user *buffer, size_t *lenp, loff_t *ppos)
114548 {
114549 - int rc;
114550 + ctl_table_no_const yama_table;
114551
114552 if (write && !capable(CAP_SYS_PTRACE))
114553 return -EPERM;
114554
114555 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
114556 - if (rc)
114557 - return rc;
114558 -
114559 + yama_table = *table;
114560 /* Lock the max value if it ever gets set. */
114561 - if (write && *(int *)table->data == *(int *)table->extra2)
114562 - table->extra1 = table->extra2;
114563 -
114564 - return rc;
114565 + if (ptrace_scope == max_scope)
114566 + yama_table.extra1 = &max_scope;
114567 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
114568 }
114569
114570 -static int zero;
114571 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
114572 -
114573 struct ctl_path yama_sysctl_path[] = {
114574 { .procname = "kernel", },
114575 { .procname = "yama", },
114576 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
114577 index 401107b..b9c47c6 100644
114578 --- a/sound/aoa/codecs/onyx.c
114579 +++ b/sound/aoa/codecs/onyx.c
114580 @@ -54,7 +54,7 @@ struct onyx {
114581 spdif_locked:1,
114582 analog_locked:1,
114583 original_mute:2;
114584 - int open_count;
114585 + local_t open_count;
114586 struct codec_info *codec_info;
114587
114588 /* mutex serializes concurrent access to the device
114589 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
114590 struct onyx *onyx = cii->codec_data;
114591
114592 mutex_lock(&onyx->mutex);
114593 - onyx->open_count++;
114594 + local_inc(&onyx->open_count);
114595 mutex_unlock(&onyx->mutex);
114596
114597 return 0;
114598 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
114599 struct onyx *onyx = cii->codec_data;
114600
114601 mutex_lock(&onyx->mutex);
114602 - onyx->open_count--;
114603 - if (!onyx->open_count)
114604 + if (local_dec_and_test(&onyx->open_count))
114605 onyx->spdif_locked = onyx->analog_locked = 0;
114606 mutex_unlock(&onyx->mutex);
114607
114608 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
114609 index ffd2025..df062c9 100644
114610 --- a/sound/aoa/codecs/onyx.h
114611 +++ b/sound/aoa/codecs/onyx.h
114612 @@ -11,6 +11,7 @@
114613 #include <linux/i2c.h>
114614 #include <asm/pmac_low_i2c.h>
114615 #include <asm/prom.h>
114616 +#include <asm/local.h>
114617
114618 /* PCM3052 register definitions */
114619
114620 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
114621 index ada69d7..5f65386 100644
114622 --- a/sound/core/oss/pcm_oss.c
114623 +++ b/sound/core/oss/pcm_oss.c
114624 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
114625 if (in_kernel) {
114626 mm_segment_t fs;
114627 fs = snd_enter_user();
114628 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
114629 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
114630 snd_leave_user(fs);
114631 } else {
114632 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
114633 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
114634 }
114635 if (ret != -EPIPE && ret != -ESTRPIPE)
114636 break;
114637 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
114638 if (in_kernel) {
114639 mm_segment_t fs;
114640 fs = snd_enter_user();
114641 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
114642 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
114643 snd_leave_user(fs);
114644 } else {
114645 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
114646 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
114647 }
114648 if (ret == -EPIPE) {
114649 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
114650 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
114651 struct snd_pcm_plugin_channel *channels;
114652 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
114653 if (!in_kernel) {
114654 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
114655 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
114656 return -EFAULT;
114657 buf = runtime->oss.buffer;
114658 }
114659 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
114660 }
114661 } else {
114662 tmp = snd_pcm_oss_write2(substream,
114663 - (const char __force *)buf,
114664 + (const char __force_kernel *)buf,
114665 runtime->oss.period_bytes, 0);
114666 if (tmp <= 0)
114667 goto err;
114668 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
114669 struct snd_pcm_runtime *runtime = substream->runtime;
114670 snd_pcm_sframes_t frames, frames1;
114671 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
114672 - char __user *final_dst = (char __force __user *)buf;
114673 + char __user *final_dst = (char __force_user *)buf;
114674 if (runtime->oss.plugin_first) {
114675 struct snd_pcm_plugin_channel *channels;
114676 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
114677 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
114678 xfer += tmp;
114679 runtime->oss.buffer_used -= tmp;
114680 } else {
114681 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
114682 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
114683 runtime->oss.period_bytes, 0);
114684 if (tmp <= 0)
114685 goto err;
114686 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
114687 size1);
114688 size1 /= runtime->channels; /* frames */
114689 fs = snd_enter_user();
114690 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
114691 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
114692 snd_leave_user(fs);
114693 }
114694 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
114695 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
114696 index af49721..e85058e 100644
114697 --- a/sound/core/pcm_compat.c
114698 +++ b/sound/core/pcm_compat.c
114699 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
114700 int err;
114701
114702 fs = snd_enter_user();
114703 - err = snd_pcm_delay(substream, &delay);
114704 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
114705 snd_leave_user(fs);
114706 if (err < 0)
114707 return err;
114708 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
114709 index b653ab0..a4738e3 100644
114710 --- a/sound/core/pcm_native.c
114711 +++ b/sound/core/pcm_native.c
114712 @@ -2812,11 +2812,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
114713 switch (substream->stream) {
114714 case SNDRV_PCM_STREAM_PLAYBACK:
114715 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
114716 - (void __user *)arg);
114717 + (void __force_user *)arg);
114718 break;
114719 case SNDRV_PCM_STREAM_CAPTURE:
114720 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
114721 - (void __user *)arg);
114722 + (void __force_user *)arg);
114723 break;
114724 default:
114725 result = -EINVAL;
114726 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
114727 index 16d4267..fe8b49b 100644
114728 --- a/sound/core/seq/oss/seq_oss.c
114729 +++ b/sound/core/seq/oss/seq_oss.c
114730 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
114731 {
114732 int rc;
114733 static struct snd_seq_dev_ops ops = {
114734 - snd_seq_oss_synth_register,
114735 - snd_seq_oss_synth_unregister,
114736 + .init_device = snd_seq_oss_synth_register,
114737 + .free_device = snd_seq_oss_synth_unregister,
114738 };
114739
114740 snd_seq_autoload_lock();
114741 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
114742 index 91a786a..4c07ed4 100644
114743 --- a/sound/core/seq/seq_device.c
114744 +++ b/sound/core/seq/seq_device.c
114745 @@ -64,7 +64,7 @@ struct ops_list {
114746 int argsize; /* argument size */
114747
114748 /* operators */
114749 - struct snd_seq_dev_ops ops;
114750 + struct snd_seq_dev_ops *ops;
114751
114752 /* registered devices */
114753 struct list_head dev_list; /* list of devices */
114754 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
114755
114756 mutex_lock(&ops->reg_mutex);
114757 /* copy driver operators */
114758 - ops->ops = *entry;
114759 + ops->ops = entry;
114760 ops->driver |= DRIVER_LOADED;
114761 ops->argsize = argsize;
114762
114763 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
114764 dev->name, ops->id, ops->argsize, dev->argsize);
114765 return -EINVAL;
114766 }
114767 - if (ops->ops.init_device(dev) >= 0) {
114768 + if (ops->ops->init_device(dev) >= 0) {
114769 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
114770 ops->num_init_devices++;
114771 } else {
114772 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
114773 dev->name, ops->id, ops->argsize, dev->argsize);
114774 return -EINVAL;
114775 }
114776 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
114777 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
114778 dev->status = SNDRV_SEQ_DEVICE_FREE;
114779 dev->driver_data = NULL;
114780 ops->num_init_devices--;
114781 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
114782 index a1fd77a..69cd659 100644
114783 --- a/sound/core/seq/seq_midi.c
114784 +++ b/sound/core/seq/seq_midi.c
114785 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
114786 static int __init alsa_seq_midi_init(void)
114787 {
114788 static struct snd_seq_dev_ops ops = {
114789 - snd_seq_midisynth_register_port,
114790 - snd_seq_midisynth_unregister_port,
114791 + .init_device = snd_seq_midisynth_register_port,
114792 + .free_device = snd_seq_midisynth_unregister_port,
114793 };
114794 memset(&synths, 0, sizeof(synths));
114795 snd_seq_autoload_lock();
114796 diff --git a/sound/core/sound.c b/sound/core/sound.c
114797 index 38ad1a0..5010a40 100644
114798 --- a/sound/core/sound.c
114799 +++ b/sound/core/sound.c
114800 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
114801 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
114802 default: return;
114803 }
114804 - request_module(str);
114805 + request_module("%s", str);
114806 }
114807
114808 #endif /* modular kernel */
114809 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
114810 index f5fd448..6ae276da 100644
114811 --- a/sound/drivers/mts64.c
114812 +++ b/sound/drivers/mts64.c
114813 @@ -29,6 +29,7 @@
114814 #include <sound/initval.h>
114815 #include <sound/rawmidi.h>
114816 #include <sound/control.h>
114817 +#include <asm/local.h>
114818
114819 #define CARD_NAME "Miditerminal 4140"
114820 #define DRIVER_NAME "MTS64"
114821 @@ -67,7 +68,7 @@ struct mts64 {
114822 struct pardevice *pardev;
114823 int pardev_claimed;
114824
114825 - int open_count;
114826 + local_t open_count;
114827 int current_midi_output_port;
114828 int current_midi_input_port;
114829 u8 mode[MTS64_NUM_INPUT_PORTS];
114830 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
114831 {
114832 struct mts64 *mts = substream->rmidi->private_data;
114833
114834 - if (mts->open_count == 0) {
114835 + if (local_read(&mts->open_count) == 0) {
114836 /* We don't need a spinlock here, because this is just called
114837 if the device has not been opened before.
114838 So there aren't any IRQs from the device */
114839 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
114840
114841 msleep(50);
114842 }
114843 - ++(mts->open_count);
114844 + local_inc(&mts->open_count);
114845
114846 return 0;
114847 }
114848 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
114849 struct mts64 *mts = substream->rmidi->private_data;
114850 unsigned long flags;
114851
114852 - --(mts->open_count);
114853 - if (mts->open_count == 0) {
114854 + if (local_dec_return(&mts->open_count) == 0) {
114855 /* We need the spinlock_irqsave here because we can still
114856 have IRQs at this point */
114857 spin_lock_irqsave(&mts->lock, flags);
114858 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
114859
114860 msleep(500);
114861
114862 - } else if (mts->open_count < 0)
114863 - mts->open_count = 0;
114864 + } else if (local_read(&mts->open_count) < 0)
114865 + local_set(&mts->open_count, 0);
114866
114867 return 0;
114868 }
114869 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
114870 index 6839953..7a0f4b9 100644
114871 --- a/sound/drivers/opl3/opl3_seq.c
114872 +++ b/sound/drivers/opl3/opl3_seq.c
114873 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
114874 {
114875 static struct snd_seq_dev_ops ops =
114876 {
114877 - snd_opl3_seq_new_device,
114878 - snd_opl3_seq_delete_device
114879 + .init_device = snd_opl3_seq_new_device,
114880 + .free_device = snd_opl3_seq_delete_device
114881 };
114882
114883 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
114884 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
114885 index b953fb4..1999c01 100644
114886 --- a/sound/drivers/opl4/opl4_lib.c
114887 +++ b/sound/drivers/opl4/opl4_lib.c
114888 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
114889 MODULE_DESCRIPTION("OPL4 driver");
114890 MODULE_LICENSE("GPL");
114891
114892 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
114893 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
114894 {
114895 int timeout = 10;
114896 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
114897 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
114898 index 9919769..d7de36c 100644
114899 --- a/sound/drivers/opl4/opl4_seq.c
114900 +++ b/sound/drivers/opl4/opl4_seq.c
114901 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
114902 static int __init alsa_opl4_synth_init(void)
114903 {
114904 static struct snd_seq_dev_ops ops = {
114905 - snd_opl4_seq_new_device,
114906 - snd_opl4_seq_delete_device
114907 + .init_device = snd_opl4_seq_new_device,
114908 + .free_device = snd_opl4_seq_delete_device
114909 };
114910
114911 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
114912 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
114913 index 78ccfa4..7a0857b 100644
114914 --- a/sound/drivers/portman2x4.c
114915 +++ b/sound/drivers/portman2x4.c
114916 @@ -48,6 +48,7 @@
114917 #include <sound/initval.h>
114918 #include <sound/rawmidi.h>
114919 #include <sound/control.h>
114920 +#include <asm/local.h>
114921
114922 #define CARD_NAME "Portman 2x4"
114923 #define DRIVER_NAME "portman"
114924 @@ -85,7 +86,7 @@ struct portman {
114925 struct pardevice *pardev;
114926 int pardev_claimed;
114927
114928 - int open_count;
114929 + local_t open_count;
114930 int mode[PORTMAN_NUM_INPUT_PORTS];
114931 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
114932 };
114933 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
114934 index f96bf4c..f3bd1e0 100644
114935 --- a/sound/firewire/amdtp.c
114936 +++ b/sound/firewire/amdtp.c
114937 @@ -512,7 +512,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
114938 ptr = s->pcm_buffer_pointer + frames;
114939 if (ptr >= pcm->runtime->buffer_size)
114940 ptr -= pcm->runtime->buffer_size;
114941 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
114942 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
114943
114944 s->pcm_period_pointer += frames;
114945 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
114946 @@ -952,7 +952,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
114947 */
114948 void amdtp_stream_update(struct amdtp_stream *s)
114949 {
114950 - ACCESS_ONCE(s->source_node_id_field) =
114951 + ACCESS_ONCE_RW(s->source_node_id_field) =
114952 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
114953 }
114954 EXPORT_SYMBOL(amdtp_stream_update);
114955 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
114956 index d8ee7b0..79dfa2a 100644
114957 --- a/sound/firewire/amdtp.h
114958 +++ b/sound/firewire/amdtp.h
114959 @@ -211,7 +211,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
114960 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
114961 struct snd_pcm_substream *pcm)
114962 {
114963 - ACCESS_ONCE(s->pcm) = pcm;
114964 + ACCESS_ONCE_RW(s->pcm) = pcm;
114965 }
114966
114967 /**
114968 @@ -229,7 +229,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
114969 struct snd_rawmidi_substream *midi)
114970 {
114971 if (port < s->midi_ports)
114972 - ACCESS_ONCE(s->midi[port]) = midi;
114973 + ACCESS_ONCE_RW(s->midi[port]) = midi;
114974 }
114975
114976 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
114977 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
114978 index 7ac9443..0ec6274 100644
114979 --- a/sound/firewire/isight.c
114980 +++ b/sound/firewire/isight.c
114981 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
114982 ptr += count;
114983 if (ptr >= runtime->buffer_size)
114984 ptr -= runtime->buffer_size;
114985 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
114986 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
114987
114988 isight->period_counter += count;
114989 if (isight->period_counter >= runtime->period_size) {
114990 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
114991 if (err < 0)
114992 return err;
114993
114994 - ACCESS_ONCE(isight->pcm_active) = true;
114995 + ACCESS_ONCE_RW(isight->pcm_active) = true;
114996
114997 return 0;
114998 }
114999 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
115000 {
115001 struct isight *isight = substream->private_data;
115002
115003 - ACCESS_ONCE(isight->pcm_active) = false;
115004 + ACCESS_ONCE_RW(isight->pcm_active) = false;
115005
115006 mutex_lock(&isight->mutex);
115007 isight_stop_streaming(isight);
115008 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
115009
115010 switch (cmd) {
115011 case SNDRV_PCM_TRIGGER_START:
115012 - ACCESS_ONCE(isight->pcm_running) = true;
115013 + ACCESS_ONCE_RW(isight->pcm_running) = true;
115014 break;
115015 case SNDRV_PCM_TRIGGER_STOP:
115016 - ACCESS_ONCE(isight->pcm_running) = false;
115017 + ACCESS_ONCE_RW(isight->pcm_running) = false;
115018 break;
115019 default:
115020 return -EINVAL;
115021 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
115022 index 2dba848..c682aef 100644
115023 --- a/sound/firewire/scs1x.c
115024 +++ b/sound/firewire/scs1x.c
115025 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
115026 {
115027 struct scs *scs = stream->rmidi->private_data;
115028
115029 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
115030 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
115031 if (up) {
115032 scs->output_idle = false;
115033 tasklet_schedule(&scs->tasklet);
115034 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
115035 {
115036 struct scs *scs = stream->rmidi->private_data;
115037
115038 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
115039 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
115040 }
115041
115042 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
115043 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
115044
115045 snd_card_disconnect(scs->card);
115046
115047 - ACCESS_ONCE(scs->output) = NULL;
115048 - ACCESS_ONCE(scs->input) = NULL;
115049 + ACCESS_ONCE_RW(scs->output) = NULL;
115050 + ACCESS_ONCE_RW(scs->input) = NULL;
115051
115052 wait_event(scs->idle_wait, scs->output_idle);
115053
115054 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
115055 index 4e3fcfb..ab45a9d 100644
115056 --- a/sound/isa/sb/emu8000_synth.c
115057 +++ b/sound/isa/sb/emu8000_synth.c
115058 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
115059 {
115060
115061 static struct snd_seq_dev_ops ops = {
115062 - snd_emu8000_new_device,
115063 - snd_emu8000_delete_device,
115064 + .init_device = snd_emu8000_new_device,
115065 + .free_device = snd_emu8000_delete_device,
115066 };
115067 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
115068 sizeof(struct snd_emu8000*));
115069 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
115070 index 048439a..3be9f6f 100644
115071 --- a/sound/oss/sb_audio.c
115072 +++ b/sound/oss/sb_audio.c
115073 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
115074 buf16 = (signed short *)(localbuf + localoffs);
115075 while (c)
115076 {
115077 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
115078 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
115079 if (copy_from_user(lbuf8,
115080 userbuf+useroffs + p,
115081 locallen))
115082 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
115083 index a33e8ce..2262303 100644
115084 --- a/sound/oss/swarm_cs4297a.c
115085 +++ b/sound/oss/swarm_cs4297a.c
115086 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
115087 {
115088 struct cs4297a_state *s;
115089 u32 pwr, id;
115090 - mm_segment_t fs;
115091 int rval;
115092 u64 cfg;
115093 int mdio_val;
115094 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
115095 if (!rval) {
115096 char *sb1250_duart_present;
115097
115098 +#if 0
115099 + mm_segment_t fs;
115100 fs = get_fs();
115101 set_fs(KERNEL_DS);
115102 -#if 0
115103 val = SOUND_MASK_LINE;
115104 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
115105 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
115106 val = initvol[i].vol;
115107 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
115108 }
115109 + set_fs(fs);
115110 // cs4297a_write_ac97(s, 0x18, 0x0808);
115111 #else
115112 // cs4297a_write_ac97(s, 0x5e, 0x180);
115113 cs4297a_write_ac97(s, 0x02, 0x0808);
115114 cs4297a_write_ac97(s, 0x18, 0x0808);
115115 #endif
115116 - set_fs(fs);
115117
115118 list_add(&s->list, &cs4297a_devs);
115119
115120 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
115121 index 4c41c90..37f3631 100644
115122 --- a/sound/pci/emu10k1/emu10k1_synth.c
115123 +++ b/sound/pci/emu10k1/emu10k1_synth.c
115124 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
115125 {
115126
115127 static struct snd_seq_dev_ops ops = {
115128 - snd_emu10k1_synth_new_device,
115129 - snd_emu10k1_synth_delete_device,
115130 + .init_device = snd_emu10k1_synth_new_device,
115131 + .free_device = snd_emu10k1_synth_delete_device,
115132 };
115133 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
115134 sizeof(struct snd_emu10k1_synth_arg));
115135 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
115136 index 4c20277..91abdce 100644
115137 --- a/sound/pci/hda/hda_codec.c
115138 +++ b/sound/pci/hda/hda_codec.c
115139 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
115140 mutex_unlock(&preset_mutex);
115141
115142 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
115143 - char name[32];
115144 if (!mod_requested)
115145 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
115146 - codec->vendor_id);
115147 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
115148 else
115149 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
115150 - (codec->vendor_id >> 16) & 0xffff);
115151 - request_module(name);
115152 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
115153 mod_requested++;
115154 goto again;
115155 }
115156 @@ -2777,7 +2773,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
115157 /* FIXME: set_fs() hack for obtaining user-space TLV data */
115158 mm_segment_t fs = get_fs();
115159 set_fs(get_ds());
115160 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
115161 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
115162 tlv = _tlv;
115163 set_fs(fs);
115164 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
115165 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
115166 index 4631a23..001ae57 100644
115167 --- a/sound/pci/ymfpci/ymfpci.h
115168 +++ b/sound/pci/ymfpci/ymfpci.h
115169 @@ -358,7 +358,7 @@ struct snd_ymfpci {
115170 spinlock_t reg_lock;
115171 spinlock_t voice_lock;
115172 wait_queue_head_t interrupt_sleep;
115173 - atomic_t interrupt_sleep_count;
115174 + atomic_unchecked_t interrupt_sleep_count;
115175 struct snd_info_entry *proc_entry;
115176 const struct firmware *dsp_microcode;
115177 const struct firmware *controller_microcode;
115178 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
115179 index 81c916a..516f0bf 100644
115180 --- a/sound/pci/ymfpci/ymfpci_main.c
115181 +++ b/sound/pci/ymfpci/ymfpci_main.c
115182 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
115183 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
115184 break;
115185 }
115186 - if (atomic_read(&chip->interrupt_sleep_count)) {
115187 - atomic_set(&chip->interrupt_sleep_count, 0);
115188 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
115189 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
115190 wake_up(&chip->interrupt_sleep);
115191 }
115192 __end:
115193 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
115194 continue;
115195 init_waitqueue_entry(&wait, current);
115196 add_wait_queue(&chip->interrupt_sleep, &wait);
115197 - atomic_inc(&chip->interrupt_sleep_count);
115198 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
115199 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
115200 remove_wait_queue(&chip->interrupt_sleep, &wait);
115201 }
115202 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
115203 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
115204 spin_unlock(&chip->reg_lock);
115205
115206 - if (atomic_read(&chip->interrupt_sleep_count)) {
115207 - atomic_set(&chip->interrupt_sleep_count, 0);
115208 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
115209 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
115210 wake_up(&chip->interrupt_sleep);
115211 }
115212 }
115213 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
115214 spin_lock_init(&chip->reg_lock);
115215 spin_lock_init(&chip->voice_lock);
115216 init_waitqueue_head(&chip->interrupt_sleep);
115217 - atomic_set(&chip->interrupt_sleep_count, 0);
115218 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
115219 chip->card = card;
115220 chip->pci = pci;
115221 chip->irq = -1;
115222 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
115223 index b87d7d8..0ccaac3 100644
115224 --- a/sound/soc/soc-core.c
115225 +++ b/sound/soc/soc-core.c
115226 @@ -2279,8 +2279,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
115227 if (ret)
115228 return ret;
115229
115230 - ops->warm_reset = snd_soc_ac97_warm_reset;
115231 - ops->reset = snd_soc_ac97_reset;
115232 + pax_open_kernel();
115233 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
115234 + *(void **)&ops->reset = snd_soc_ac97_reset;
115235 + pax_close_kernel();
115236
115237 snd_ac97_rst_cfg = cfg;
115238 return 0;
115239 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
115240 index 7778b8e..3d619fc 100644
115241 --- a/sound/synth/emux/emux_seq.c
115242 +++ b/sound/synth/emux/emux_seq.c
115243 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
115244 * MIDI emulation operators
115245 */
115246 static struct snd_midi_op emux_ops = {
115247 - snd_emux_note_on,
115248 - snd_emux_note_off,
115249 - snd_emux_key_press,
115250 - snd_emux_terminate_note,
115251 - snd_emux_control,
115252 - snd_emux_nrpn,
115253 - snd_emux_sysex,
115254 + .note_on = snd_emux_note_on,
115255 + .note_off = snd_emux_note_off,
115256 + .key_press = snd_emux_key_press,
115257 + .note_terminate = snd_emux_terminate_note,
115258 + .control = snd_emux_control,
115259 + .nrpn = snd_emux_nrpn,
115260 + .sysex = snd_emux_sysex,
115261 };
115262
115263
115264 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
115265 new file mode 100644
115266 index 0000000..de92ed9
115267 --- /dev/null
115268 +++ b/tools/gcc/.gitignore
115269 @@ -0,0 +1 @@
115270 +randomize_layout_seed.h
115271 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
115272 new file mode 100644
115273 index 0000000..7b8921f
115274 --- /dev/null
115275 +++ b/tools/gcc/Makefile
115276 @@ -0,0 +1,52 @@
115277 +#CC := gcc
115278 +#PLUGIN_SOURCE_FILES := pax_plugin.c
115279 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
115280 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
115281 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
115282 +
115283 +ifeq ($(PLUGINCC),$(HOSTCC))
115284 +HOSTLIBS := hostlibs
115285 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
115286 +export HOST_EXTRACFLAGS
115287 +else
115288 +HOSTLIBS := hostcxxlibs
115289 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
115290 +export HOST_EXTRACXXFLAGS
115291 +endif
115292 +
115293 +export GCCPLUGINS_DIR HOSTLIBS
115294 +
115295 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
115296 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
115297 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
115298 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
115299 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
115300 +$(HOSTLIBS)-y += colorize_plugin.so
115301 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
115302 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
115303 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
115304 +
115305 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
115306 +subdir- += size_overflow_plugin
115307 +
115308 +always := $($(HOSTLIBS)-y)
115309 +
115310 +constify_plugin-objs := constify_plugin.o
115311 +stackleak_plugin-objs := stackleak_plugin.o
115312 +kallocstat_plugin-objs := kallocstat_plugin.o
115313 +kernexec_plugin-objs := kernexec_plugin.o
115314 +checker_plugin-objs := checker_plugin.o
115315 +colorize_plugin-objs := colorize_plugin.o
115316 +latent_entropy_plugin-objs := latent_entropy_plugin.o
115317 +structleak_plugin-objs := structleak_plugin.o
115318 +randomize_layout_plugin-objs := randomize_layout_plugin.o
115319 +
115320 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
115321 +
115322 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
115323 + cmd_create_randomize_layout_seed = \
115324 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
115325 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
115326 + $(call if_changed,create_randomize_layout_seed)
115327 +
115328 +targets += randomize_layout_seed.h randomize_layout_hash.h
115329 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
115330 new file mode 100644
115331 index 0000000..5452feea
115332 --- /dev/null
115333 +++ b/tools/gcc/checker_plugin.c
115334 @@ -0,0 +1,150 @@
115335 +/*
115336 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
115337 + * Licensed under the GPL v2
115338 + *
115339 + * Note: the choice of the license means that the compilation process is
115340 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
115341 + * but for the kernel it doesn't matter since it doesn't link against
115342 + * any of the gcc libraries
115343 + *
115344 + * gcc plugin to implement various sparse (source code checker) features
115345 + *
115346 + * TODO:
115347 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
115348 + *
115349 + * BUGS:
115350 + * - none known
115351 + */
115352 +
115353 +#include "gcc-common.h"
115354 +
115355 +extern void c_register_addr_space (const char *str, addr_space_t as);
115356 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
115357 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
115358 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
115359 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
115360 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
115361 +
115362 +int plugin_is_GPL_compatible;
115363 +
115364 +static struct plugin_info checker_plugin_info = {
115365 + .version = "201304082245",
115366 + .help = NULL,
115367 +};
115368 +
115369 +#define ADDR_SPACE_KERNEL 0
115370 +#define ADDR_SPACE_FORCE_KERNEL 1
115371 +#define ADDR_SPACE_USER 2
115372 +#define ADDR_SPACE_FORCE_USER 3
115373 +#define ADDR_SPACE_IOMEM 0
115374 +#define ADDR_SPACE_FORCE_IOMEM 0
115375 +#define ADDR_SPACE_PERCPU 0
115376 +#define ADDR_SPACE_FORCE_PERCPU 0
115377 +#define ADDR_SPACE_RCU 0
115378 +#define ADDR_SPACE_FORCE_RCU 0
115379 +
115380 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
115381 +{
115382 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
115383 +}
115384 +
115385 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
115386 +{
115387 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
115388 +}
115389 +
115390 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
115391 +{
115392 + return default_addr_space_valid_pointer_mode(mode, as);
115393 +}
115394 +
115395 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
115396 +{
115397 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
115398 +}
115399 +
115400 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
115401 +{
115402 + return default_addr_space_legitimize_address(x, oldx, mode, as);
115403 +}
115404 +
115405 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
115406 +{
115407 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
115408 + return true;
115409 +
115410 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
115411 + return true;
115412 +
115413 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
115414 + return true;
115415 +
115416 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
115417 + return true;
115418 +
115419 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
115420 + return true;
115421 +
115422 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
115423 + return true;
115424 +
115425 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
115426 + return true;
115427 +
115428 + return subset == superset;
115429 +}
115430 +
115431 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
115432 +{
115433 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
115434 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
115435 +
115436 + return op;
115437 +}
115438 +
115439 +static void register_checker_address_spaces(void *event_data, void *data)
115440 +{
115441 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
115442 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
115443 + c_register_addr_space("__user", ADDR_SPACE_USER);
115444 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
115445 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
115446 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
115447 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
115448 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
115449 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
115450 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
115451 +
115452 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
115453 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
115454 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
115455 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
115456 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
115457 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
115458 + targetm.addr_space.convert = checker_addr_space_convert;
115459 +}
115460 +
115461 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
115462 +{
115463 + const char * const plugin_name = plugin_info->base_name;
115464 + const int argc = plugin_info->argc;
115465 + const struct plugin_argument * const argv = plugin_info->argv;
115466 + int i;
115467 +
115468 + if (!plugin_default_version_check(version, &gcc_version)) {
115469 + error(G_("incompatible gcc/plugin versions"));
115470 + return 1;
115471 + }
115472 +
115473 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
115474 +
115475 + for (i = 0; i < argc; ++i)
115476 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
115477 +
115478 + if (TARGET_64BIT == 0)
115479 + return 0;
115480 +
115481 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
115482 +
115483 + return 0;
115484 +}
115485 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
115486 new file mode 100644
115487 index 0000000..54461af
115488 --- /dev/null
115489 +++ b/tools/gcc/colorize_plugin.c
115490 @@ -0,0 +1,210 @@
115491 +/*
115492 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
115493 + * Licensed under the GPL v2
115494 + *
115495 + * Note: the choice of the license means that the compilation process is
115496 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
115497 + * but for the kernel it doesn't matter since it doesn't link against
115498 + * any of the gcc libraries
115499 + *
115500 + * gcc plugin to colorize diagnostic output
115501 + *
115502 + */
115503 +
115504 +#include "gcc-common.h"
115505 +
115506 +int plugin_is_GPL_compatible;
115507 +
115508 +static struct plugin_info colorize_plugin_info = {
115509 + .version = "201404202350",
115510 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
115511 +};
115512 +
115513 +#define GREEN "\033[32m\033[K"
115514 +#define LIGHTGREEN "\033[1;32m\033[K"
115515 +#define YELLOW "\033[33m\033[K"
115516 +#define LIGHTYELLOW "\033[1;33m\033[K"
115517 +#define RED "\033[31m\033[K"
115518 +#define LIGHTRED "\033[1;31m\033[K"
115519 +#define BLUE "\033[34m\033[K"
115520 +#define LIGHTBLUE "\033[1;34m\033[K"
115521 +#define BRIGHT "\033[1;m\033[K"
115522 +#define NORMAL "\033[m\033[K"
115523 +
115524 +static diagnostic_starter_fn old_starter;
115525 +static diagnostic_finalizer_fn old_finalizer;
115526 +
115527 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
115528 +{
115529 + const char *color;
115530 + char *newprefix;
115531 +
115532 + switch (diagnostic->kind) {
115533 + case DK_NOTE:
115534 + color = LIGHTBLUE;
115535 + break;
115536 +
115537 + case DK_PEDWARN:
115538 + case DK_WARNING:
115539 + color = LIGHTYELLOW;
115540 + break;
115541 +
115542 + case DK_ERROR:
115543 + case DK_FATAL:
115544 + case DK_ICE:
115545 + case DK_PERMERROR:
115546 + case DK_SORRY:
115547 + color = LIGHTRED;
115548 + break;
115549 +
115550 + default:
115551 + color = NORMAL;
115552 + }
115553 +
115554 + old_starter(context, diagnostic);
115555 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
115556 + return;
115557 + pp_destroy_prefix(context->printer);
115558 + pp_set_prefix(context->printer, newprefix);
115559 +}
115560 +
115561 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
115562 +{
115563 + old_finalizer(context, diagnostic);
115564 +}
115565 +
115566 +static void colorize_arm(void)
115567 +{
115568 + old_starter = diagnostic_starter(global_dc);
115569 + old_finalizer = diagnostic_finalizer(global_dc);
115570 +
115571 + diagnostic_starter(global_dc) = start_colorize;
115572 + diagnostic_finalizer(global_dc) = finalize_colorize;
115573 +}
115574 +
115575 +static unsigned int execute_colorize_rearm(void)
115576 +{
115577 + if (diagnostic_starter(global_dc) == start_colorize)
115578 + return 0;
115579 +
115580 + colorize_arm();
115581 + return 0;
115582 +}
115583 +
115584 +#if BUILDING_GCC_VERSION >= 4009
115585 +static const struct pass_data colorize_rearm_pass_data = {
115586 +#else
115587 +struct simple_ipa_opt_pass colorize_rearm_pass = {
115588 + .pass = {
115589 +#endif
115590 + .type = SIMPLE_IPA_PASS,
115591 + .name = "colorize_rearm",
115592 +#if BUILDING_GCC_VERSION >= 4008
115593 + .optinfo_flags = OPTGROUP_NONE,
115594 +#endif
115595 +#if BUILDING_GCC_VERSION >= 4009
115596 + .has_gate = false,
115597 + .has_execute = true,
115598 +#else
115599 + .gate = NULL,
115600 + .execute = execute_colorize_rearm,
115601 + .sub = NULL,
115602 + .next = NULL,
115603 + .static_pass_number = 0,
115604 +#endif
115605 + .tv_id = TV_NONE,
115606 + .properties_required = 0,
115607 + .properties_provided = 0,
115608 + .properties_destroyed = 0,
115609 + .todo_flags_start = 0,
115610 + .todo_flags_finish = 0
115611 +#if BUILDING_GCC_VERSION < 4009
115612 + }
115613 +#endif
115614 +};
115615 +
115616 +#if BUILDING_GCC_VERSION >= 4009
115617 +namespace {
115618 +class colorize_rearm_pass : public simple_ipa_opt_pass {
115619 +public:
115620 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
115621 + unsigned int execute() { return execute_colorize_rearm(); }
115622 +};
115623 +}
115624 +
115625 +static opt_pass *make_colorize_rearm_pass(void)
115626 +{
115627 + return new colorize_rearm_pass();
115628 +}
115629 +#else
115630 +static struct opt_pass *make_colorize_rearm_pass(void)
115631 +{
115632 + return &colorize_rearm_pass.pass;
115633 +}
115634 +#endif
115635 +
115636 +static void colorize_start_unit(void *gcc_data, void *user_data)
115637 +{
115638 + colorize_arm();
115639 +}
115640 +
115641 +static bool should_colorize(void)
115642 +{
115643 +#if BUILDING_GCC_VERSION >= 4009
115644 + return false;
115645 +#else
115646 + char const *t = getenv("TERM");
115647 +
115648 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
115649 +#endif
115650 +}
115651 +
115652 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
115653 +{
115654 + const char * const plugin_name = plugin_info->base_name;
115655 + const int argc = plugin_info->argc;
115656 + const struct plugin_argument * const argv = plugin_info->argv;
115657 + int i;
115658 + struct register_pass_info colorize_rearm_pass_info;
115659 + bool colorize;
115660 +
115661 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
115662 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
115663 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
115664 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
115665 +
115666 + if (!plugin_default_version_check(version, &gcc_version)) {
115667 + error(G_("incompatible gcc/plugin versions"));
115668 + return 1;
115669 + }
115670 +
115671 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
115672 +
115673 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
115674 +
115675 + for (i = 0; i < argc; ++i) {
115676 + if (!strcmp(argv[i].key, "color")) {
115677 + if (!argv[i].value) {
115678 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
115679 + continue;
115680 + }
115681 + if (!strcmp(argv[i].value, "always"))
115682 + colorize = true;
115683 + else if (!strcmp(argv[i].value, "never"))
115684 + colorize = false;
115685 + else if (!strcmp(argv[i].value, "auto"))
115686 + colorize = should_colorize();
115687 + else
115688 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
115689 + continue;
115690 + }
115691 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
115692 + }
115693 +
115694 + if (colorize) {
115695 + // TODO: parse GCC_COLORS as used by gcc 4.9+
115696 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
115697 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
115698 + }
115699 + return 0;
115700 +}
115701 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
115702 new file mode 100644
115703 index 0000000..82bc5a8
115704 --- /dev/null
115705 +++ b/tools/gcc/constify_plugin.c
115706 @@ -0,0 +1,557 @@
115707 +/*
115708 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
115709 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
115710 + * Licensed under the GPL v2, or (at your option) v3
115711 + *
115712 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
115713 + *
115714 + * Homepage:
115715 + * http://www.grsecurity.net/~ephox/const_plugin/
115716 + *
115717 + * Usage:
115718 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
115719 + * $ gcc -fplugin=constify_plugin.so test.c -O2
115720 + */
115721 +
115722 +#include "gcc-common.h"
115723 +
115724 +// unused C type flag in all versions 4.5-4.9
115725 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
115726 +
115727 +int plugin_is_GPL_compatible;
115728 +
115729 +static struct plugin_info const_plugin_info = {
115730 + .version = "201401270210",
115731 + .help = "no-constify\tturn off constification\n",
115732 +};
115733 +
115734 +typedef struct {
115735 + bool has_fptr_field;
115736 + bool has_writable_field;
115737 + bool has_do_const_field;
115738 + bool has_no_const_field;
115739 +} constify_info;
115740 +
115741 +static const_tree get_field_type(const_tree field)
115742 +{
115743 + return strip_array_types(TREE_TYPE(field));
115744 +}
115745 +
115746 +static bool is_fptr(const_tree field)
115747 +{
115748 + const_tree ptr = get_field_type(field);
115749 +
115750 + if (TREE_CODE(ptr) != POINTER_TYPE)
115751 + return false;
115752 +
115753 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
115754 +}
115755 +
115756 +/*
115757 + * determine whether the given structure type meets the requirements for automatic constification,
115758 + * including the constification attributes on nested structure types
115759 + */
115760 +static void constifiable(const_tree node, constify_info *cinfo)
115761 +{
115762 + const_tree field;
115763 +
115764 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
115765 +
115766 + // e.g., pointer to structure fields while still constructing the structure type
115767 + if (TYPE_FIELDS(node) == NULL_TREE)
115768 + return;
115769 +
115770 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
115771 + const_tree type = get_field_type(field);
115772 + enum tree_code code = TREE_CODE(type);
115773 +
115774 + if (node == type)
115775 + continue;
115776 +
115777 + if (is_fptr(field))
115778 + cinfo->has_fptr_field = true;
115779 + else if (!TREE_READONLY(field))
115780 + cinfo->has_writable_field = true;
115781 +
115782 + if (code == RECORD_TYPE || code == UNION_TYPE) {
115783 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
115784 + cinfo->has_do_const_field = true;
115785 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
115786 + cinfo->has_no_const_field = true;
115787 + else
115788 + constifiable(type, cinfo);
115789 + }
115790 + }
115791 +}
115792 +
115793 +static bool constified(const_tree node)
115794 +{
115795 + constify_info cinfo = {
115796 + .has_fptr_field = false,
115797 + .has_writable_field = false,
115798 + .has_do_const_field = false,
115799 + .has_no_const_field = false
115800 + };
115801 +
115802 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
115803 +
115804 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
115805 +// gcc_assert(!TYPE_READONLY(node));
115806 + return false;
115807 + }
115808 +
115809 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
115810 + gcc_assert(TYPE_READONLY(node));
115811 + return true;
115812 + }
115813 +
115814 + constifiable(node, &cinfo);
115815 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
115816 + return false;
115817 +
115818 + return TYPE_READONLY(node);
115819 +}
115820 +
115821 +static void deconstify_tree(tree node);
115822 +
115823 +static void deconstify_type(tree type)
115824 +{
115825 + tree field;
115826 +
115827 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
115828 +
115829 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
115830 + const_tree fieldtype = get_field_type(field);
115831 +
115832 + // special case handling of simple ptr-to-same-array-type members
115833 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
115834 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
115835 +
115836 + if (TREE_TYPE(TREE_TYPE(field)) == type)
115837 + continue;
115838 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
115839 + continue;
115840 + if (!constified(ptrtype))
115841 + continue;
115842 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
115843 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
115844 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
115845 + }
115846 + continue;
115847 + }
115848 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
115849 + continue;
115850 + if (!constified(fieldtype))
115851 + continue;
115852 +
115853 + deconstify_tree(field);
115854 + TREE_READONLY(field) = 0;
115855 + }
115856 + TYPE_READONLY(type) = 0;
115857 + C_TYPE_FIELDS_READONLY(type) = 0;
115858 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
115859 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
115860 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
115861 + }
115862 +}
115863 +
115864 +static void deconstify_tree(tree node)
115865 +{
115866 + tree old_type, new_type, field;
115867 +
115868 + old_type = TREE_TYPE(node);
115869 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
115870 + node = TREE_TYPE(node) = copy_node(old_type);
115871 + old_type = TREE_TYPE(old_type);
115872 + }
115873 +
115874 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
115875 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
115876 +
115877 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
115878 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
115879 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
115880 + DECL_FIELD_CONTEXT(field) = new_type;
115881 +
115882 + deconstify_type(new_type);
115883 +
115884 + TREE_TYPE(node) = new_type;
115885 +}
115886 +
115887 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
115888 +{
115889 + tree type;
115890 + constify_info cinfo = {
115891 + .has_fptr_field = false,
115892 + .has_writable_field = false,
115893 + .has_do_const_field = false,
115894 + .has_no_const_field = false
115895 + };
115896 +
115897 + *no_add_attrs = true;
115898 + if (TREE_CODE(*node) == FUNCTION_DECL) {
115899 + error("%qE attribute does not apply to functions (%qF)", name, *node);
115900 + return NULL_TREE;
115901 + }
115902 +
115903 + if (TREE_CODE(*node) == PARM_DECL) {
115904 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
115905 + return NULL_TREE;
115906 + }
115907 +
115908 + if (TREE_CODE(*node) == VAR_DECL) {
115909 + error("%qE attribute does not apply to variables (%qD)", name, *node);
115910 + return NULL_TREE;
115911 + }
115912 +
115913 + if (TYPE_P(*node)) {
115914 + type = *node;
115915 + } else {
115916 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
115917 + type = TREE_TYPE(*node);
115918 + }
115919 +
115920 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
115921 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
115922 + return NULL_TREE;
115923 + }
115924 +
115925 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
115926 + error("%qE attribute is already applied to the type %qT", name, type);
115927 + return NULL_TREE;
115928 + }
115929 +
115930 + if (TYPE_P(*node)) {
115931 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
115932 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
115933 + else
115934 + *no_add_attrs = false;
115935 + return NULL_TREE;
115936 + }
115937 +
115938 + constifiable(type, &cinfo);
115939 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
115940 + deconstify_tree(*node);
115941 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
115942 + return NULL_TREE;
115943 + }
115944 +
115945 + error("%qE attribute used on type %qT that is not constified", name, type);
115946 + return NULL_TREE;
115947 +}
115948 +
115949 +static void constify_type(tree type)
115950 +{
115951 + TYPE_READONLY(type) = 1;
115952 + C_TYPE_FIELDS_READONLY(type) = 1;
115953 + TYPE_CONSTIFY_VISITED(type) = 1;
115954 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
115955 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
115956 +}
115957 +
115958 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
115959 +{
115960 + *no_add_attrs = true;
115961 + if (!TYPE_P(*node)) {
115962 + error("%qE attribute applies to types only (%qD)", name, *node);
115963 + return NULL_TREE;
115964 + }
115965 +
115966 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
115967 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
115968 + return NULL_TREE;
115969 + }
115970 +
115971 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
115972 + error("%qE attribute used on %qT is already applied to the type", name, *node);
115973 + return NULL_TREE;
115974 + }
115975 +
115976 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
115977 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
115978 + return NULL_TREE;
115979 + }
115980 +
115981 + *no_add_attrs = false;
115982 + return NULL_TREE;
115983 +}
115984 +
115985 +static struct attribute_spec no_const_attr = {
115986 + .name = "no_const",
115987 + .min_length = 0,
115988 + .max_length = 0,
115989 + .decl_required = false,
115990 + .type_required = false,
115991 + .function_type_required = false,
115992 + .handler = handle_no_const_attribute,
115993 +#if BUILDING_GCC_VERSION >= 4007
115994 + .affects_type_identity = true
115995 +#endif
115996 +};
115997 +
115998 +static struct attribute_spec do_const_attr = {
115999 + .name = "do_const",
116000 + .min_length = 0,
116001 + .max_length = 0,
116002 + .decl_required = false,
116003 + .type_required = false,
116004 + .function_type_required = false,
116005 + .handler = handle_do_const_attribute,
116006 +#if BUILDING_GCC_VERSION >= 4007
116007 + .affects_type_identity = true
116008 +#endif
116009 +};
116010 +
116011 +static void register_attributes(void *event_data, void *data)
116012 +{
116013 + register_attribute(&no_const_attr);
116014 + register_attribute(&do_const_attr);
116015 +}
116016 +
116017 +static void finish_type(void *event_data, void *data)
116018 +{
116019 + tree type = (tree)event_data;
116020 + constify_info cinfo = {
116021 + .has_fptr_field = false,
116022 + .has_writable_field = false,
116023 + .has_do_const_field = false,
116024 + .has_no_const_field = false
116025 + };
116026 +
116027 + if (type == NULL_TREE || type == error_mark_node)
116028 + return;
116029 +
116030 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
116031 + return;
116032 +
116033 + constifiable(type, &cinfo);
116034 +
116035 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
116036 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
116037 + deconstify_type(type);
116038 + TYPE_CONSTIFY_VISITED(type) = 1;
116039 + } else
116040 + error("'no_const' attribute used on type %qT that is not constified", type);
116041 + return;
116042 + }
116043 +
116044 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
116045 + if (!cinfo.has_writable_field) {
116046 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
116047 + return;
116048 + }
116049 + constify_type(type);
116050 + return;
116051 + }
116052 +
116053 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
116054 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
116055 + error("'do_const' attribute used on type %qT that is constified", type);
116056 + return;
116057 + }
116058 + constify_type(type);
116059 + return;
116060 + }
116061 +
116062 + deconstify_type(type);
116063 + TYPE_CONSTIFY_VISITED(type) = 1;
116064 +}
116065 +
116066 +static void check_global_variables(void *event_data, void *data)
116067 +{
116068 +#if BUILDING_GCC_VERSION >= 4009
116069 + varpool_node *node;
116070 +#else
116071 + struct varpool_node *node;
116072 +#endif
116073 +
116074 + FOR_EACH_VARIABLE(node) {
116075 + tree var = NODE_DECL(node);
116076 + tree type = TREE_TYPE(var);
116077 +
116078 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
116079 + continue;
116080 +
116081 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
116082 + continue;
116083 +
116084 + if (!TYPE_CONSTIFY_VISITED(type))
116085 + continue;
116086 +
116087 + if (DECL_EXTERNAL(var))
116088 + continue;
116089 +
116090 + if (DECL_INITIAL(var))
116091 + continue;
116092 +
116093 + // this works around a gcc bug/feature where uninitialized globals
116094 + // are moved into the .bss section regardless of any constification
116095 + DECL_INITIAL(var) = build_constructor(type, NULL);
116096 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
116097 + }
116098 +}
116099 +
116100 +static unsigned int check_local_variables(void)
116101 +{
116102 + unsigned int ret = 0;
116103 + tree var;
116104 +
116105 + unsigned int i;
116106 +
116107 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
116108 + tree type = TREE_TYPE(var);
116109 +
116110 + gcc_assert(DECL_P(var));
116111 + if (is_global_var(var))
116112 + continue;
116113 +
116114 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
116115 + continue;
116116 +
116117 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
116118 + continue;
116119 +
116120 + if (!TYPE_CONSTIFY_VISITED(type))
116121 + continue;
116122 +
116123 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
116124 + ret = 1;
116125 + }
116126 + return ret;
116127 +}
116128 +
116129 +#if BUILDING_GCC_VERSION >= 4009
116130 +static const struct pass_data check_local_variables_pass_data = {
116131 +#else
116132 +static struct gimple_opt_pass check_local_variables_pass = {
116133 + .pass = {
116134 +#endif
116135 + .type = GIMPLE_PASS,
116136 + .name = "check_local_variables",
116137 +#if BUILDING_GCC_VERSION >= 4008
116138 + .optinfo_flags = OPTGROUP_NONE,
116139 +#endif
116140 +#if BUILDING_GCC_VERSION >= 4009
116141 + .has_gate = false,
116142 + .has_execute = true,
116143 +#else
116144 + .gate = NULL,
116145 + .execute = check_local_variables,
116146 + .sub = NULL,
116147 + .next = NULL,
116148 + .static_pass_number = 0,
116149 +#endif
116150 + .tv_id = TV_NONE,
116151 + .properties_required = 0,
116152 + .properties_provided = 0,
116153 + .properties_destroyed = 0,
116154 + .todo_flags_start = 0,
116155 + .todo_flags_finish = 0
116156 +#if BUILDING_GCC_VERSION < 4009
116157 + }
116158 +#endif
116159 +};
116160 +
116161 +#if BUILDING_GCC_VERSION >= 4009
116162 +namespace {
116163 +class check_local_variables_pass : public gimple_opt_pass {
116164 +public:
116165 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
116166 + unsigned int execute() { return check_local_variables(); }
116167 +};
116168 +}
116169 +
116170 +static opt_pass *make_check_local_variables_pass(void)
116171 +{
116172 + return new check_local_variables_pass();
116173 +}
116174 +#else
116175 +static struct opt_pass *make_check_local_variables_pass(void)
116176 +{
116177 + return &check_local_variables_pass.pass;
116178 +}
116179 +#endif
116180 +
116181 +static struct {
116182 + const char *name;
116183 + const char *asm_op;
116184 +} sections[] = {
116185 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
116186 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
116187 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
116188 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
116189 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
116190 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
116191 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
116192 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
116193 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
116194 +};
116195 +
116196 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
116197 +
116198 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
116199 +{
116200 + size_t i;
116201 +
116202 + for (i = 0; i < ARRAY_SIZE(sections); i++)
116203 + if (!strcmp(sections[i].name, name))
116204 + return 0;
116205 + return old_section_type_flags(decl, name, reloc);
116206 +}
116207 +
116208 +static void constify_start_unit(void *gcc_data, void *user_data)
116209 +{
116210 +// size_t i;
116211 +
116212 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
116213 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
116214 +// sections[i].section = get_section(sections[i].name, 0, NULL);
116215 +
116216 + old_section_type_flags = targetm.section_type_flags;
116217 + targetm.section_type_flags = constify_section_type_flags;
116218 +}
116219 +
116220 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
116221 +{
116222 + const char * const plugin_name = plugin_info->base_name;
116223 + const int argc = plugin_info->argc;
116224 + const struct plugin_argument * const argv = plugin_info->argv;
116225 + int i;
116226 + bool constify = true;
116227 +
116228 + struct register_pass_info check_local_variables_pass_info;
116229 +
116230 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
116231 + check_local_variables_pass_info.reference_pass_name = "ssa";
116232 + check_local_variables_pass_info.ref_pass_instance_number = 1;
116233 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116234 +
116235 + if (!plugin_default_version_check(version, &gcc_version)) {
116236 + error(G_("incompatible gcc/plugin versions"));
116237 + return 1;
116238 + }
116239 +
116240 + for (i = 0; i < argc; ++i) {
116241 + if (!(strcmp(argv[i].key, "no-constify"))) {
116242 + constify = false;
116243 + continue;
116244 + }
116245 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
116246 + }
116247 +
116248 + if (strcmp(lang_hooks.name, "GNU C")) {
116249 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
116250 + constify = false;
116251 + }
116252 +
116253 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
116254 + if (constify) {
116255 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
116256 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
116257 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
116258 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
116259 + }
116260 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
116261 +
116262 + return 0;
116263 +}
116264 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
116265 new file mode 100644
116266 index 0000000..e90c205
116267 --- /dev/null
116268 +++ b/tools/gcc/gcc-common.h
116269 @@ -0,0 +1,295 @@
116270 +#ifndef GCC_COMMON_H_INCLUDED
116271 +#define GCC_COMMON_H_INCLUDED
116272 +
116273 +#include "plugin.h"
116274 +#include "bversion.h"
116275 +#include "plugin-version.h"
116276 +#include "config.h"
116277 +#include "system.h"
116278 +#include "coretypes.h"
116279 +#include "tm.h"
116280 +#include "line-map.h"
116281 +#include "input.h"
116282 +#include "tree.h"
116283 +
116284 +#include "tree-inline.h"
116285 +#include "version.h"
116286 +#include "rtl.h"
116287 +#include "tm_p.h"
116288 +#include "flags.h"
116289 +//#include "insn-attr.h"
116290 +//#include "insn-config.h"
116291 +//#include "insn-flags.h"
116292 +#include "hard-reg-set.h"
116293 +//#include "recog.h"
116294 +#include "output.h"
116295 +#include "except.h"
116296 +#include "function.h"
116297 +#include "toplev.h"
116298 +//#include "expr.h"
116299 +#include "basic-block.h"
116300 +#include "intl.h"
116301 +#include "ggc.h"
116302 +//#include "regs.h"
116303 +#include "timevar.h"
116304 +
116305 +#include "params.h"
116306 +#include "pointer-set.h"
116307 +#include "emit-rtl.h"
116308 +//#include "reload.h"
116309 +//#include "ira.h"
116310 +//#include "dwarf2asm.h"
116311 +#include "debug.h"
116312 +#include "target.h"
116313 +#include "langhooks.h"
116314 +#include "cfgloop.h"
116315 +//#include "hosthooks.h"
116316 +#include "cgraph.h"
116317 +#include "opts.h"
116318 +//#include "coverage.h"
116319 +//#include "value-prof.h"
116320 +
116321 +#if BUILDING_GCC_VERSION >= 4007
116322 +#include "tree-pretty-print.h"
116323 +#include "gimple-pretty-print.h"
116324 +#include "c-tree.h"
116325 +//#include "alloc-pool.h"
116326 +#endif
116327 +
116328 +#if BUILDING_GCC_VERSION <= 4008
116329 +#include "tree-flow.h"
116330 +#else
116331 +#include "tree-cfgcleanup.h"
116332 +#endif
116333 +
116334 +#include "diagnostic.h"
116335 +//#include "tree-diagnostic.h"
116336 +#include "tree-dump.h"
116337 +#include "tree-pass.h"
116338 +//#include "df.h"
116339 +#include "predict.h"
116340 +#include "ipa-utils.h"
116341 +
116342 +#if BUILDING_GCC_VERSION >= 4009
116343 +#include "varasm.h"
116344 +#include "stor-layout.h"
116345 +#include "internal-fn.h"
116346 +#include "gimple-expr.h"
116347 +//#include "diagnostic-color.h"
116348 +#include "context.h"
116349 +#include "tree-ssa-alias.h"
116350 +#include "stringpool.h"
116351 +#include "tree-ssanames.h"
116352 +#include "print-tree.h"
116353 +#include "tree-eh.h"
116354 +#include "stmt.h"
116355 +#endif
116356 +
116357 +#include "gimple.h"
116358 +
116359 +#if BUILDING_GCC_VERSION >= 4009
116360 +#include "tree-ssa-operands.h"
116361 +#include "tree-phinodes.h"
116362 +#include "tree-cfg.h"
116363 +#include "gimple-iterator.h"
116364 +#include "gimple-ssa.h"
116365 +#include "ssa-iterators.h"
116366 +#endif
116367 +
116368 +//#include "lto/lto.h"
116369 +//#include "data-streamer.h"
116370 +//#include "lto-compress.h"
116371 +
116372 +//#include "expr.h" where are you...
116373 +extern rtx emit_move_insn(rtx x, rtx y);
116374 +
116375 +// missing from basic_block.h...
116376 +extern void debug_dominance_info(enum cdi_direction dir);
116377 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
116378 +
116379 +#define __unused __attribute__((__unused__))
116380 +
116381 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
116382 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
116383 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
116384 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
116385 +
116386 +#if BUILDING_GCC_VERSION == 4005
116387 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
116388 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
116389 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
116390 +#define TODO_rebuild_cgraph_edges 0
116391 +
116392 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
116393 +{
116394 + tree fndecl;
116395 +
116396 + if (!is_gimple_call(stmt))
116397 + return false;
116398 + fndecl = gimple_call_fndecl(stmt);
116399 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
116400 + return false;
116401 +// print_node(stderr, "pax", fndecl, 4);
116402 + return DECL_FUNCTION_CODE(fndecl) == code;
116403 +}
116404 +
116405 +static inline bool is_simple_builtin(tree decl)
116406 +{
116407 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
116408 + return false;
116409 +
116410 + switch (DECL_FUNCTION_CODE(decl)) {
116411 + /* Builtins that expand to constants. */
116412 + case BUILT_IN_CONSTANT_P:
116413 + case BUILT_IN_EXPECT:
116414 + case BUILT_IN_OBJECT_SIZE:
116415 + case BUILT_IN_UNREACHABLE:
116416 + /* Simple register moves or loads from stack. */
116417 + case BUILT_IN_RETURN_ADDRESS:
116418 + case BUILT_IN_EXTRACT_RETURN_ADDR:
116419 + case BUILT_IN_FROB_RETURN_ADDR:
116420 + case BUILT_IN_RETURN:
116421 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
116422 + case BUILT_IN_FRAME_ADDRESS:
116423 + case BUILT_IN_VA_END:
116424 + case BUILT_IN_STACK_SAVE:
116425 + case BUILT_IN_STACK_RESTORE:
116426 + /* Exception state returns or moves registers around. */
116427 + case BUILT_IN_EH_FILTER:
116428 + case BUILT_IN_EH_POINTER:
116429 + case BUILT_IN_EH_COPY_VALUES:
116430 + return true;
116431 +
116432 + default:
116433 + return false;
116434 + }
116435 +}
116436 +#endif
116437 +
116438 +#if BUILDING_GCC_VERSION <= 4006
116439 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
116440 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
116441 +
116442 +// should come from c-tree.h if only it were installed for gcc 4.5...
116443 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
116444 +
116445 +#define get_random_seed(noinit) ({ \
116446 + unsigned HOST_WIDE_INT seed; \
116447 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
116448 + seed * seed; })
116449 +
116450 +static inline bool gimple_clobber_p(gimple s)
116451 +{
116452 + return false;
116453 +}
116454 +
116455 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
116456 +{
116457 + return implicit_built_in_decls[fncode];
116458 +}
116459 +
116460 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
116461 +{
116462 + struct cgraph_node *node = cgraph_get_node(decl);
116463 +
116464 + return node ? node : cgraph_node(decl);
116465 +}
116466 +
116467 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
116468 +{
116469 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
116470 +}
116471 +
116472 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
116473 +{
116474 + struct cgraph_node *node;
116475 +
116476 + for (node = cgraph_nodes; node; node = node->next)
116477 + if (cgraph_function_with_gimple_body_p(node))
116478 + return node;
116479 + return NULL;
116480 +}
116481 +
116482 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
116483 +{
116484 + for (node = node->next; node; node = node->next)
116485 + if (cgraph_function_with_gimple_body_p(node))
116486 + return node;
116487 + return NULL;
116488 +}
116489 +
116490 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
116491 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
116492 + (node) = cgraph_next_function_with_gimple_body(node))
116493 +#endif
116494 +
116495 +#if BUILDING_GCC_VERSION == 4006
116496 +extern void debug_gimple_stmt(gimple);
116497 +extern void debug_gimple_seq(gimple_seq);
116498 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
116499 +extern void print_gimple_stmt(FILE *, gimple, int, int);
116500 +extern void print_gimple_expr(FILE *, gimple, int, int);
116501 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
116502 +#endif
116503 +
116504 +#if BUILDING_GCC_VERSION <= 4007
116505 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
116506 +#define PROP_loops 0
116507 +
116508 +static inline int bb_loop_depth(const_basic_block bb)
116509 +{
116510 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
116511 +}
116512 +
116513 +static inline bool gimple_store_p(gimple gs)
116514 +{
116515 + tree lhs = gimple_get_lhs(gs);
116516 + return lhs && !is_gimple_reg(lhs);
116517 +}
116518 +#endif
116519 +
116520 +#if BUILDING_GCC_VERSION >= 4007
116521 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
116522 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
116523 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
116524 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
116525 +#endif
116526 +
116527 +#if BUILDING_GCC_VERSION <= 4008
116528 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
116529 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
116530 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
116531 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
116532 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
116533 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
116534 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
116535 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
116536 +
116537 +static inline const char *get_tree_code_name(enum tree_code code)
116538 +{
116539 + gcc_assert(code < MAX_TREE_CODES);
116540 + return tree_code_name[code];
116541 +}
116542 +
116543 +#define ipa_remove_stmt_references(cnode, stmt)
116544 +#endif
116545 +
116546 +#if BUILDING_GCC_VERSION == 4008
116547 +#define NODE_DECL(node) node->symbol.decl
116548 +#else
116549 +#define NODE_DECL(node) node->decl
116550 +#endif
116551 +
116552 +#if BUILDING_GCC_VERSION >= 4008
116553 +#define add_referenced_var(var)
116554 +#define mark_sym_for_renaming(var)
116555 +#define varpool_mark_needed_node(node)
116556 +#define TODO_dump_func 0
116557 +#define TODO_dump_cgraph 0
116558 +#endif
116559 +
116560 +#if BUILDING_GCC_VERSION >= 4009
116561 +#define TODO_ggc_collect 0
116562 +#endif
116563 +
116564 +#endif
116565 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
116566 new file mode 100644
116567 index 0000000..7514850
116568 --- /dev/null
116569 +++ b/tools/gcc/gen-random-seed.sh
116570 @@ -0,0 +1,8 @@
116571 +#!/bin/sh
116572 +
116573 +if [ ! -f "$1" ]; then
116574 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
116575 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
116576 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
116577 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
116578 +fi
116579 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
116580 new file mode 100644
116581 index 0000000..d81c094
116582 --- /dev/null
116583 +++ b/tools/gcc/kallocstat_plugin.c
116584 @@ -0,0 +1,183 @@
116585 +/*
116586 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
116587 + * Licensed under the GPL v2
116588 + *
116589 + * Note: the choice of the license means that the compilation process is
116590 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
116591 + * but for the kernel it doesn't matter since it doesn't link against
116592 + * any of the gcc libraries
116593 + *
116594 + * gcc plugin to find the distribution of k*alloc sizes
116595 + *
116596 + * TODO:
116597 + *
116598 + * BUGS:
116599 + * - none known
116600 + */
116601 +
116602 +#include "gcc-common.h"
116603 +
116604 +int plugin_is_GPL_compatible;
116605 +
116606 +static struct plugin_info kallocstat_plugin_info = {
116607 + .version = "201401260140",
116608 + .help = NULL
116609 +};
116610 +
116611 +static const char * const kalloc_functions[] = {
116612 + "__kmalloc",
116613 + "kmalloc",
116614 + "kmalloc_large",
116615 + "kmalloc_node",
116616 + "kmalloc_order",
116617 + "kmalloc_order_trace",
116618 + "kmalloc_slab",
116619 + "kzalloc",
116620 + "kzalloc_node",
116621 +};
116622 +
116623 +static bool is_kalloc(const char *fnname)
116624 +{
116625 + size_t i;
116626 +
116627 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
116628 + if (!strcmp(fnname, kalloc_functions[i]))
116629 + return true;
116630 + return false;
116631 +}
116632 +
116633 +static unsigned int execute_kallocstat(void)
116634 +{
116635 + basic_block bb;
116636 +
116637 + // 1. loop through BBs and GIMPLE statements
116638 + FOR_EACH_BB_FN(bb, cfun) {
116639 + gimple_stmt_iterator gsi;
116640 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116641 + // gimple match:
116642 + tree fndecl, size;
116643 + gimple stmt;
116644 + const char *fnname;
116645 +
116646 + // is it a call
116647 + stmt = gsi_stmt(gsi);
116648 + if (!is_gimple_call(stmt))
116649 + continue;
116650 + fndecl = gimple_call_fndecl(stmt);
116651 + if (fndecl == NULL_TREE)
116652 + continue;
116653 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
116654 + continue;
116655 +
116656 + // is it a call to k*alloc
116657 + fnname = DECL_NAME_POINTER(fndecl);
116658 + if (!is_kalloc(fnname))
116659 + continue;
116660 +
116661 + // is the size arg const or the result of a simple const assignment
116662 + size = gimple_call_arg(stmt, 0);
116663 + while (true) {
116664 + expanded_location xloc;
116665 + size_t size_val;
116666 +
116667 + if (TREE_CONSTANT(size)) {
116668 + xloc = expand_location(gimple_location(stmt));
116669 + if (!xloc.file)
116670 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
116671 + size_val = TREE_INT_CST_LOW(size);
116672 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
116673 + break;
116674 + }
116675 +
116676 + if (TREE_CODE(size) != SSA_NAME)
116677 + break;
116678 + stmt = SSA_NAME_DEF_STMT(size);
116679 +//debug_gimple_stmt(stmt);
116680 +//debug_tree(size);
116681 + if (!stmt || !is_gimple_assign(stmt))
116682 + break;
116683 + if (gimple_num_ops(stmt) != 2)
116684 + break;
116685 + size = gimple_assign_rhs1(stmt);
116686 + }
116687 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
116688 +//debug_tree(gimple_call_fn(call_stmt));
116689 +//print_node(stderr, "pax", fndecl, 4);
116690 + }
116691 + }
116692 +
116693 + return 0;
116694 +}
116695 +
116696 +#if BUILDING_GCC_VERSION >= 4009
116697 +static const struct pass_data kallocstat_pass_data = {
116698 +#else
116699 +static struct gimple_opt_pass kallocstat_pass = {
116700 + .pass = {
116701 +#endif
116702 + .type = GIMPLE_PASS,
116703 + .name = "kallocstat",
116704 +#if BUILDING_GCC_VERSION >= 4008
116705 + .optinfo_flags = OPTGROUP_NONE,
116706 +#endif
116707 +#if BUILDING_GCC_VERSION >= 4009
116708 + .has_gate = false,
116709 + .has_execute = true,
116710 +#else
116711 + .gate = NULL,
116712 + .execute = execute_kallocstat,
116713 + .sub = NULL,
116714 + .next = NULL,
116715 + .static_pass_number = 0,
116716 +#endif
116717 + .tv_id = TV_NONE,
116718 + .properties_required = 0,
116719 + .properties_provided = 0,
116720 + .properties_destroyed = 0,
116721 + .todo_flags_start = 0,
116722 + .todo_flags_finish = 0
116723 +#if BUILDING_GCC_VERSION < 4009
116724 + }
116725 +#endif
116726 +};
116727 +
116728 +#if BUILDING_GCC_VERSION >= 4009
116729 +namespace {
116730 +class kallocstat_pass : public gimple_opt_pass {
116731 +public:
116732 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
116733 + unsigned int execute() { return execute_kallocstat(); }
116734 +};
116735 +}
116736 +
116737 +static opt_pass *make_kallocstat_pass(void)
116738 +{
116739 + return new kallocstat_pass();
116740 +}
116741 +#else
116742 +static struct opt_pass *make_kallocstat_pass(void)
116743 +{
116744 + return &kallocstat_pass.pass;
116745 +}
116746 +#endif
116747 +
116748 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
116749 +{
116750 + const char * const plugin_name = plugin_info->base_name;
116751 + struct register_pass_info kallocstat_pass_info;
116752 +
116753 + kallocstat_pass_info.pass = make_kallocstat_pass();
116754 + kallocstat_pass_info.reference_pass_name = "ssa";
116755 + kallocstat_pass_info.ref_pass_instance_number = 1;
116756 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
116757 +
116758 + if (!plugin_default_version_check(version, &gcc_version)) {
116759 + error(G_("incompatible gcc/plugin versions"));
116760 + return 1;
116761 + }
116762 +
116763 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
116764 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
116765 +
116766 + return 0;
116767 +}
116768 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
116769 new file mode 100644
116770 index 0000000..89f256d
116771 --- /dev/null
116772 +++ b/tools/gcc/kernexec_plugin.c
116773 @@ -0,0 +1,522 @@
116774 +/*
116775 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
116776 + * Licensed under the GPL v2
116777 + *
116778 + * Note: the choice of the license means that the compilation process is
116779 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
116780 + * but for the kernel it doesn't matter since it doesn't link against
116781 + * any of the gcc libraries
116782 + *
116783 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
116784 + *
116785 + * TODO:
116786 + *
116787 + * BUGS:
116788 + * - none known
116789 + */
116790 +
116791 +#include "gcc-common.h"
116792 +
116793 +int plugin_is_GPL_compatible;
116794 +
116795 +static struct plugin_info kernexec_plugin_info = {
116796 + .version = "201401260140",
116797 + .help = "method=[bts|or]\tinstrumentation method\n"
116798 +};
116799 +
116800 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
116801 +static void (*kernexec_instrument_retaddr)(rtx);
116802 +
116803 +/*
116804 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
116805 + */
116806 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
116807 +{
116808 + gimple asm_movabs_stmt;
116809 +
116810 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
116811 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
116812 + gimple_asm_set_volatile(asm_movabs_stmt, true);
116813 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
116814 + update_stmt(asm_movabs_stmt);
116815 +}
116816 +
116817 +/*
116818 + * find all asm() stmts that clobber r12 and add a reload of r12
116819 + */
116820 +static unsigned int execute_kernexec_reload(void)
116821 +{
116822 + basic_block bb;
116823 +
116824 + // 1. loop through BBs and GIMPLE statements
116825 + FOR_EACH_BB_FN(bb, cfun) {
116826 + gimple_stmt_iterator gsi;
116827 +
116828 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116829 + // gimple match: __asm__ ("" : : : "r12");
116830 + gimple asm_stmt;
116831 + size_t nclobbers;
116832 +
116833 + // is it an asm ...
116834 + asm_stmt = gsi_stmt(gsi);
116835 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
116836 + continue;
116837 +
116838 + // ... clobbering r12
116839 + nclobbers = gimple_asm_nclobbers(asm_stmt);
116840 + while (nclobbers--) {
116841 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
116842 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
116843 + continue;
116844 + kernexec_reload_fptr_mask(&gsi);
116845 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
116846 + break;
116847 + }
116848 + }
116849 + }
116850 +
116851 + return 0;
116852 +}
116853 +
116854 +/*
116855 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
116856 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
116857 + */
116858 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
116859 +{
116860 + gimple assign_intptr, assign_new_fptr, call_stmt;
116861 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
116862 +
116863 + call_stmt = gsi_stmt(*gsi);
116864 + old_fptr = gimple_call_fn(call_stmt);
116865 +
116866 + // create temporary unsigned long variable used for bitops and cast fptr to it
116867 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
116868 + add_referenced_var(intptr);
116869 + intptr = make_ssa_name(intptr, NULL);
116870 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
116871 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
116872 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
116873 + update_stmt(assign_intptr);
116874 +
116875 + // apply logical or to temporary unsigned long and bitmask
116876 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
116877 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
116878 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
116879 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
116880 + assign_intptr = gimple_build_assign(intptr, orptr);
116881 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
116882 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
116883 + update_stmt(assign_intptr);
116884 +
116885 + // cast temporary unsigned long back to a temporary fptr variable
116886 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
116887 + add_referenced_var(new_fptr);
116888 + new_fptr = make_ssa_name(new_fptr, NULL);
116889 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
116890 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
116891 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
116892 + update_stmt(assign_new_fptr);
116893 +
116894 + // replace call stmt fn with the new fptr
116895 + gimple_call_set_fn(call_stmt, new_fptr);
116896 + update_stmt(call_stmt);
116897 +}
116898 +
116899 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
116900 +{
116901 + gimple asm_or_stmt, call_stmt;
116902 + tree old_fptr, new_fptr, input, output;
116903 +#if BUILDING_GCC_VERSION <= 4007
116904 + VEC(tree, gc) *inputs = NULL;
116905 + VEC(tree, gc) *outputs = NULL;
116906 +#else
116907 + vec<tree, va_gc> *inputs = NULL;
116908 + vec<tree, va_gc> *outputs = NULL;
116909 +#endif
116910 +
116911 + call_stmt = gsi_stmt(*gsi);
116912 + old_fptr = gimple_call_fn(call_stmt);
116913 +
116914 + // create temporary fptr variable
116915 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
116916 + add_referenced_var(new_fptr);
116917 + new_fptr = make_ssa_name(new_fptr, NULL);
116918 +
116919 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
116920 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
116921 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
116922 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
116923 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
116924 +#if BUILDING_GCC_VERSION <= 4007
116925 + VEC_safe_push(tree, gc, inputs, input);
116926 + VEC_safe_push(tree, gc, outputs, output);
116927 +#else
116928 + vec_safe_push(inputs, input);
116929 + vec_safe_push(outputs, output);
116930 +#endif
116931 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
116932 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
116933 + gimple_asm_set_volatile(asm_or_stmt, true);
116934 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
116935 + update_stmt(asm_or_stmt);
116936 +
116937 + // replace call stmt fn with the new fptr
116938 + gimple_call_set_fn(call_stmt, new_fptr);
116939 + update_stmt(call_stmt);
116940 +}
116941 +
116942 +/*
116943 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
116944 + */
116945 +static unsigned int execute_kernexec_fptr(void)
116946 +{
116947 + basic_block bb;
116948 +
116949 + // 1. loop through BBs and GIMPLE statements
116950 + FOR_EACH_BB_FN(bb, cfun) {
116951 + gimple_stmt_iterator gsi;
116952 +
116953 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116954 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
116955 + tree fn;
116956 + gimple call_stmt;
116957 +
116958 + // is it a call ...
116959 + call_stmt = gsi_stmt(gsi);
116960 + if (!is_gimple_call(call_stmt))
116961 + continue;
116962 + fn = gimple_call_fn(call_stmt);
116963 + if (TREE_CODE(fn) == ADDR_EXPR)
116964 + continue;
116965 + if (TREE_CODE(fn) != SSA_NAME)
116966 + gcc_unreachable();
116967 +
116968 + // ... through a function pointer
116969 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
116970 + fn = SSA_NAME_VAR(fn);
116971 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
116972 + debug_tree(fn);
116973 + gcc_unreachable();
116974 + }
116975 + }
116976 + fn = TREE_TYPE(fn);
116977 + if (TREE_CODE(fn) != POINTER_TYPE)
116978 + continue;
116979 + fn = TREE_TYPE(fn);
116980 + if (TREE_CODE(fn) != FUNCTION_TYPE)
116981 + continue;
116982 +
116983 + kernexec_instrument_fptr(&gsi);
116984 +
116985 +//debug_tree(gimple_call_fn(call_stmt));
116986 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
116987 + }
116988 + }
116989 +
116990 + return 0;
116991 +}
116992 +
116993 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
116994 +static void kernexec_instrument_retaddr_bts(rtx insn)
116995 +{
116996 + rtx btsq;
116997 + rtvec argvec, constraintvec, labelvec;
116998 + int line;
116999 +
117000 + // create asm volatile("btsq $63,(%%rsp)":::)
117001 + argvec = rtvec_alloc(0);
117002 + constraintvec = rtvec_alloc(0);
117003 + labelvec = rtvec_alloc(0);
117004 + line = expand_location(RTL_LOCATION(insn)).line;
117005 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
117006 + MEM_VOLATILE_P(btsq) = 1;
117007 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
117008 + emit_insn_before(btsq, insn);
117009 +}
117010 +
117011 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
117012 +static void kernexec_instrument_retaddr_or(rtx insn)
117013 +{
117014 + rtx orq;
117015 + rtvec argvec, constraintvec, labelvec;
117016 + int line;
117017 +
117018 + // create asm volatile("orq %%r12,(%%rsp)":::)
117019 + argvec = rtvec_alloc(0);
117020 + constraintvec = rtvec_alloc(0);
117021 + labelvec = rtvec_alloc(0);
117022 + line = expand_location(RTL_LOCATION(insn)).line;
117023 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
117024 + MEM_VOLATILE_P(orq) = 1;
117025 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
117026 + emit_insn_before(orq, insn);
117027 +}
117028 +
117029 +/*
117030 + * find all asm level function returns and forcibly set the highest bit of the return address
117031 + */
117032 +static unsigned int execute_kernexec_retaddr(void)
117033 +{
117034 + rtx insn;
117035 +
117036 +// if (stack_realign_drap)
117037 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
117038 +
117039 + // 1. find function returns
117040 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
117041 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
117042 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
117043 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
117044 + rtx body;
117045 +
117046 + // is it a retn
117047 + if (!JUMP_P(insn))
117048 + continue;
117049 + body = PATTERN(insn);
117050 + if (GET_CODE(body) == PARALLEL)
117051 + body = XVECEXP(body, 0, 0);
117052 + if (!ANY_RETURN_P(body))
117053 + continue;
117054 + kernexec_instrument_retaddr(insn);
117055 + }
117056 +
117057 +// print_simple_rtl(stderr, get_insns());
117058 +// print_rtl(stderr, get_insns());
117059 +
117060 + return 0;
117061 +}
117062 +
117063 +static bool kernexec_cmodel_check(void)
117064 +{
117065 + tree section;
117066 +
117067 + if (ix86_cmodel != CM_KERNEL)
117068 + return false;
117069 +
117070 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
117071 + if (!section || !TREE_VALUE(section))
117072 + return true;
117073 +
117074 + section = TREE_VALUE(TREE_VALUE(section));
117075 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
117076 + return true;
117077 +
117078 + return false;
117079 +}
117080 +
117081 +#if BUILDING_GCC_VERSION >= 4009
117082 +static const struct pass_data kernexec_reload_pass_data = {
117083 +#else
117084 +static struct gimple_opt_pass kernexec_reload_pass = {
117085 + .pass = {
117086 +#endif
117087 + .type = GIMPLE_PASS,
117088 + .name = "kernexec_reload",
117089 +#if BUILDING_GCC_VERSION >= 4008
117090 + .optinfo_flags = OPTGROUP_NONE,
117091 +#endif
117092 +#if BUILDING_GCC_VERSION >= 4009
117093 + .has_gate = true,
117094 + .has_execute = true,
117095 +#else
117096 + .gate = kernexec_cmodel_check,
117097 + .execute = execute_kernexec_reload,
117098 + .sub = NULL,
117099 + .next = NULL,
117100 + .static_pass_number = 0,
117101 +#endif
117102 + .tv_id = TV_NONE,
117103 + .properties_required = 0,
117104 + .properties_provided = 0,
117105 + .properties_destroyed = 0,
117106 + .todo_flags_start = 0,
117107 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
117108 +#if BUILDING_GCC_VERSION < 4009
117109 + }
117110 +#endif
117111 +};
117112 +
117113 +#if BUILDING_GCC_VERSION >= 4009
117114 +static const struct pass_data kernexec_fptr_pass_data = {
117115 +#else
117116 +static struct gimple_opt_pass kernexec_fptr_pass = {
117117 + .pass = {
117118 +#endif
117119 + .type = GIMPLE_PASS,
117120 + .name = "kernexec_fptr",
117121 +#if BUILDING_GCC_VERSION >= 4008
117122 + .optinfo_flags = OPTGROUP_NONE,
117123 +#endif
117124 +#if BUILDING_GCC_VERSION >= 4009
117125 + .has_gate = true,
117126 + .has_execute = true,
117127 +#else
117128 + .gate = kernexec_cmodel_check,
117129 + .execute = execute_kernexec_fptr,
117130 + .sub = NULL,
117131 + .next = NULL,
117132 + .static_pass_number = 0,
117133 +#endif
117134 + .tv_id = TV_NONE,
117135 + .properties_required = 0,
117136 + .properties_provided = 0,
117137 + .properties_destroyed = 0,
117138 + .todo_flags_start = 0,
117139 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
117140 +#if BUILDING_GCC_VERSION < 4009
117141 + }
117142 +#endif
117143 +};
117144 +
117145 +#if BUILDING_GCC_VERSION >= 4009
117146 +static const struct pass_data kernexec_retaddr_pass_data = {
117147 +#else
117148 +static struct rtl_opt_pass kernexec_retaddr_pass = {
117149 + .pass = {
117150 +#endif
117151 + .type = RTL_PASS,
117152 + .name = "kernexec_retaddr",
117153 +#if BUILDING_GCC_VERSION >= 4008
117154 + .optinfo_flags = OPTGROUP_NONE,
117155 +#endif
117156 +#if BUILDING_GCC_VERSION >= 4009
117157 + .has_gate = true,
117158 + .has_execute = true,
117159 +#else
117160 + .gate = kernexec_cmodel_check,
117161 + .execute = execute_kernexec_retaddr,
117162 + .sub = NULL,
117163 + .next = NULL,
117164 + .static_pass_number = 0,
117165 +#endif
117166 + .tv_id = TV_NONE,
117167 + .properties_required = 0,
117168 + .properties_provided = 0,
117169 + .properties_destroyed = 0,
117170 + .todo_flags_start = 0,
117171 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
117172 +#if BUILDING_GCC_VERSION < 4009
117173 + }
117174 +#endif
117175 +};
117176 +
117177 +#if BUILDING_GCC_VERSION >= 4009
117178 +namespace {
117179 +class kernexec_reload_pass : public gimple_opt_pass {
117180 +public:
117181 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
117182 + bool gate() { return kernexec_cmodel_check(); }
117183 + unsigned int execute() { return execute_kernexec_reload(); }
117184 +};
117185 +
117186 +class kernexec_fptr_pass : public gimple_opt_pass {
117187 +public:
117188 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
117189 + bool gate() { return kernexec_cmodel_check(); }
117190 + unsigned int execute() { return execute_kernexec_fptr(); }
117191 +};
117192 +
117193 +class kernexec_retaddr_pass : public rtl_opt_pass {
117194 +public:
117195 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
117196 + bool gate() { return kernexec_cmodel_check(); }
117197 + unsigned int execute() { return execute_kernexec_retaddr(); }
117198 +};
117199 +}
117200 +
117201 +static opt_pass *make_kernexec_reload_pass(void)
117202 +{
117203 + return new kernexec_reload_pass();
117204 +}
117205 +
117206 +static opt_pass *make_kernexec_fptr_pass(void)
117207 +{
117208 + return new kernexec_fptr_pass();
117209 +}
117210 +
117211 +static opt_pass *make_kernexec_retaddr_pass(void)
117212 +{
117213 + return new kernexec_retaddr_pass();
117214 +}
117215 +#else
117216 +static struct opt_pass *make_kernexec_reload_pass(void)
117217 +{
117218 + return &kernexec_reload_pass.pass;
117219 +}
117220 +
117221 +static struct opt_pass *make_kernexec_fptr_pass(void)
117222 +{
117223 + return &kernexec_fptr_pass.pass;
117224 +}
117225 +
117226 +static struct opt_pass *make_kernexec_retaddr_pass(void)
117227 +{
117228 + return &kernexec_retaddr_pass.pass;
117229 +}
117230 +#endif
117231 +
117232 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117233 +{
117234 + const char * const plugin_name = plugin_info->base_name;
117235 + const int argc = plugin_info->argc;
117236 + const struct plugin_argument * const argv = plugin_info->argv;
117237 + int i;
117238 + struct register_pass_info kernexec_reload_pass_info;
117239 + struct register_pass_info kernexec_fptr_pass_info;
117240 + struct register_pass_info kernexec_retaddr_pass_info;
117241 +
117242 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
117243 + kernexec_reload_pass_info.reference_pass_name = "ssa";
117244 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
117245 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
117246 +
117247 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
117248 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
117249 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
117250 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
117251 +
117252 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
117253 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
117254 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
117255 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
117256 +
117257 + if (!plugin_default_version_check(version, &gcc_version)) {
117258 + error(G_("incompatible gcc/plugin versions"));
117259 + return 1;
117260 + }
117261 +
117262 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
117263 +
117264 + if (TARGET_64BIT == 0)
117265 + return 0;
117266 +
117267 + for (i = 0; i < argc; ++i) {
117268 + if (!strcmp(argv[i].key, "method")) {
117269 + if (!argv[i].value) {
117270 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117271 + continue;
117272 + }
117273 + if (!strcmp(argv[i].value, "bts")) {
117274 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
117275 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
117276 + } else if (!strcmp(argv[i].value, "or")) {
117277 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
117278 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
117279 + fix_register("r12", 1, 1);
117280 + } else
117281 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
117282 + continue;
117283 + }
117284 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117285 + }
117286 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
117287 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
117288 +
117289 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
117290 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
117291 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
117292 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
117293 +
117294 + return 0;
117295 +}
117296 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
117297 new file mode 100644
117298 index 0000000..39d7cc7
117299 --- /dev/null
117300 +++ b/tools/gcc/latent_entropy_plugin.c
117301 @@ -0,0 +1,462 @@
117302 +/*
117303 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
117304 + * Licensed under the GPL v2
117305 + *
117306 + * Note: the choice of the license means that the compilation process is
117307 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
117308 + * but for the kernel it doesn't matter since it doesn't link against
117309 + * any of the gcc libraries
117310 + *
117311 + * gcc plugin to help generate a little bit of entropy from program state,
117312 + * used throughout the uptime of the kernel
117313 + *
117314 + * TODO:
117315 + * - add ipa pass to identify not explicitly marked candidate functions
117316 + * - mix in more program state (function arguments/return values, loop variables, etc)
117317 + * - more instrumentation control via attribute parameters
117318 + *
117319 + * BUGS:
117320 + * - LTO needs -flto-partition=none for now
117321 + */
117322 +
117323 +#include "gcc-common.h"
117324 +
117325 +int plugin_is_GPL_compatible;
117326 +
117327 +static tree latent_entropy_decl;
117328 +
117329 +static struct plugin_info latent_entropy_plugin_info = {
117330 + .version = "201403280150",
117331 + .help = NULL
117332 +};
117333 +
117334 +static unsigned HOST_WIDE_INT seed;
117335 +static unsigned HOST_WIDE_INT get_random_const(void)
117336 +{
117337 + unsigned int i;
117338 + unsigned HOST_WIDE_INT ret = 0;
117339 +
117340 + for (i = 0; i < 8 * sizeof ret; i++) {
117341 + ret = (ret << 1) | (seed & 1);
117342 + seed >>= 1;
117343 + if (ret & 1)
117344 + seed ^= 0xD800000000000000ULL;
117345 + }
117346 +
117347 + return ret;
117348 +}
117349 +
117350 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
117351 +{
117352 + tree type;
117353 + unsigned long long mask;
117354 +#if BUILDING_GCC_VERSION <= 4007
117355 + VEC(constructor_elt, gc) *vals;
117356 +#else
117357 + vec<constructor_elt, va_gc> *vals;
117358 +#endif
117359 +
117360 + switch (TREE_CODE(*node)) {
117361 + default:
117362 + *no_add_attrs = true;
117363 + error("%qE attribute only applies to functions and variables", name);
117364 + break;
117365 +
117366 + case VAR_DECL:
117367 + if (DECL_INITIAL(*node)) {
117368 + *no_add_attrs = true;
117369 + error("variable %qD with %qE attribute must not be initialized", *node, name);
117370 + break;
117371 + }
117372 +
117373 + if (!TREE_STATIC(*node)) {
117374 + *no_add_attrs = true;
117375 + error("variable %qD with %qE attribute must not be local", *node, name);
117376 + break;
117377 + }
117378 +
117379 + type = TREE_TYPE(*node);
117380 + switch (TREE_CODE(type)) {
117381 + default:
117382 + *no_add_attrs = true;
117383 + error("variable %qD with %qE attribute must be an integer or a fixed length integer array type or a fixed sized structure with integer fields", *node, name);
117384 + break;
117385 +
117386 + case RECORD_TYPE: {
117387 + tree field;
117388 + unsigned int nelt = 0;
117389 +
117390 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
117391 + tree fieldtype;
117392 +
117393 + fieldtype = TREE_TYPE(field);
117394 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
117395 + *no_add_attrs = true;
117396 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
117397 + break;
117398 + }
117399 + }
117400 +
117401 + if (field)
117402 + break;
117403 +
117404 +#if BUILDING_GCC_VERSION <= 4007
117405 + vals = VEC_alloc(constructor_elt, gc, nelt);
117406 +#else
117407 + vec_alloc(vals, nelt);
117408 +#endif
117409 +
117410 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
117411 + tree fieldtype;
117412 +
117413 + fieldtype = TREE_TYPE(field);
117414 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
117415 + mask = 2 * (mask - 1) + 1;
117416 +
117417 + if (TYPE_UNSIGNED(fieldtype))
117418 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
117419 + else
117420 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
117421 + }
117422 +
117423 + DECL_INITIAL(*node) = build_constructor(type, vals);
117424 +//debug_tree(DECL_INITIAL(*node));
117425 + break;
117426 + }
117427 +
117428 + case INTEGER_TYPE:
117429 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
117430 + mask = 2 * (mask - 1) + 1;
117431 +
117432 + if (TYPE_UNSIGNED(type))
117433 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
117434 + else
117435 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
117436 + break;
117437 +
117438 + case ARRAY_TYPE: {
117439 + tree elt_type, array_size, elt_size;
117440 + unsigned int i, nelt;
117441 +
117442 + elt_type = TREE_TYPE(type);
117443 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
117444 + array_size = TYPE_SIZE_UNIT(type);
117445 +
117446 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
117447 + *no_add_attrs = true;
117448 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
117449 + break;
117450 + }
117451 +
117452 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
117453 +#if BUILDING_GCC_VERSION <= 4007
117454 + vals = VEC_alloc(constructor_elt, gc, nelt);
117455 +#else
117456 + vec_alloc(vals, nelt);
117457 +#endif
117458 +
117459 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
117460 + mask = 2 * (mask - 1) + 1;
117461 +
117462 + for (i = 0; i < nelt; i++)
117463 + if (TYPE_UNSIGNED(elt_type))
117464 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
117465 + else
117466 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
117467 +
117468 + DECL_INITIAL(*node) = build_constructor(type, vals);
117469 +//debug_tree(DECL_INITIAL(*node));
117470 + break;
117471 + }
117472 + }
117473 + break;
117474 +
117475 + case FUNCTION_DECL:
117476 + break;
117477 + }
117478 +
117479 + return NULL_TREE;
117480 +}
117481 +
117482 +static struct attribute_spec latent_entropy_attr = {
117483 + .name = "latent_entropy",
117484 + .min_length = 0,
117485 + .max_length = 0,
117486 + .decl_required = true,
117487 + .type_required = false,
117488 + .function_type_required = false,
117489 + .handler = handle_latent_entropy_attribute,
117490 +#if BUILDING_GCC_VERSION >= 4007
117491 + .affects_type_identity = false
117492 +#endif
117493 +};
117494 +
117495 +static void register_attributes(void *event_data, void *data)
117496 +{
117497 + register_attribute(&latent_entropy_attr);
117498 +}
117499 +
117500 +static bool gate_latent_entropy(void)
117501 +{
117502 + // don't bother with noreturn functions for now
117503 + if (TREE_THIS_VOLATILE(current_function_decl))
117504 + return false;
117505 +
117506 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
117507 +}
117508 +
117509 +static enum tree_code get_op(tree *rhs)
117510 +{
117511 + static enum tree_code op;
117512 + unsigned HOST_WIDE_INT random_const;
117513 +
117514 + random_const = get_random_const();
117515 +
117516 + switch (op) {
117517 + case BIT_XOR_EXPR:
117518 + op = PLUS_EXPR;
117519 + break;
117520 +
117521 + case PLUS_EXPR:
117522 + if (rhs) {
117523 + op = LROTATE_EXPR;
117524 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
117525 + break;
117526 + }
117527 +
117528 + case LROTATE_EXPR:
117529 + default:
117530 + op = BIT_XOR_EXPR;
117531 + break;
117532 + }
117533 + if (rhs)
117534 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
117535 + return op;
117536 +}
117537 +
117538 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
117539 +{
117540 + gimple_stmt_iterator gsi;
117541 + gimple assign;
117542 + tree addxorrol, rhs;
117543 + enum tree_code op;
117544 +
117545 + op = get_op(&rhs);
117546 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
117547 + assign = gimple_build_assign(local_entropy, addxorrol);
117548 + gsi = gsi_after_labels(bb);
117549 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
117550 + update_stmt(assign);
117551 +//debug_bb(bb);
117552 +}
117553 +
117554 +static void perturb_latent_entropy(basic_block bb, tree rhs)
117555 +{
117556 + gimple_stmt_iterator gsi;
117557 + gimple assign;
117558 + tree addxorrol, temp;
117559 +
117560 + // 1. create temporary copy of latent_entropy
117561 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
117562 + add_referenced_var(temp);
117563 +
117564 + // 2. read...
117565 + temp = make_ssa_name(temp, NULL);
117566 + assign = gimple_build_assign(temp, latent_entropy_decl);
117567 + SSA_NAME_DEF_STMT(temp) = assign;
117568 + add_referenced_var(latent_entropy_decl);
117569 + gsi = gsi_after_labels(bb);
117570 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
117571 + update_stmt(assign);
117572 +
117573 + // 3. ...modify...
117574 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
117575 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
117576 + assign = gimple_build_assign(temp, addxorrol);
117577 + SSA_NAME_DEF_STMT(temp) = assign;
117578 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
117579 + update_stmt(assign);
117580 +
117581 + // 4. ...write latent_entropy
117582 + assign = gimple_build_assign(latent_entropy_decl, temp);
117583 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
117584 + update_stmt(assign);
117585 +}
117586 +
117587 +static unsigned int execute_latent_entropy(void)
117588 +{
117589 + basic_block bb;
117590 + gimple assign;
117591 + gimple_stmt_iterator gsi;
117592 + tree local_entropy;
117593 +
117594 + if (!latent_entropy_decl) {
117595 +#if BUILDING_GCC_VERSION >= 4009
117596 + varpool_node *node;
117597 +#else
117598 + struct varpool_node *node;
117599 +#endif
117600 +
117601 + FOR_EACH_VARIABLE(node) {
117602 + tree var = NODE_DECL(node);
117603 +
117604 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
117605 + continue;
117606 + latent_entropy_decl = var;
117607 +// debug_tree(var);
117608 + break;
117609 + }
117610 + if (!latent_entropy_decl) {
117611 +// debug_tree(current_function_decl);
117612 + return 0;
117613 + }
117614 + }
117615 +
117616 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
117617 +
117618 + // 1. create local entropy variable
117619 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
117620 + add_referenced_var(local_entropy);
117621 + mark_sym_for_renaming(local_entropy);
117622 +
117623 + // 2. initialize local entropy variable
117624 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
117625 + if (dom_info_available_p(CDI_DOMINATORS))
117626 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
117627 + gsi = gsi_start_bb(bb);
117628 +
117629 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
117630 +// gimple_set_location(assign, loc);
117631 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
117632 + update_stmt(assign);
117633 +//debug_bb(bb);
117634 + gcc_assert(single_succ_p(bb));
117635 + bb = single_succ(bb);
117636 +
117637 + // 3. instrument each BB with an operation on the local entropy variable
117638 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
117639 + perturb_local_entropy(bb, local_entropy);
117640 +//debug_bb(bb);
117641 + bb = bb->next_bb;
117642 + };
117643 +
117644 + // 4. mix local entropy into the global entropy variable
117645 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
117646 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
117647 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
117648 + return 0;
117649 +}
117650 +
117651 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
117652 +{
117653 + tree latent_entropy_type;
117654 +
117655 + seed = get_random_seed(false);
117656 +
117657 + if (in_lto_p)
117658 + return;
117659 +
117660 + // extern volatile u64 latent_entropy
117661 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
117662 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
117663 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
117664 +
117665 + TREE_STATIC(latent_entropy_decl) = 1;
117666 + TREE_PUBLIC(latent_entropy_decl) = 1;
117667 + TREE_USED(latent_entropy_decl) = 1;
117668 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
117669 + DECL_EXTERNAL(latent_entropy_decl) = 1;
117670 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
117671 + lang_hooks.decls.pushdecl(latent_entropy_decl);
117672 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
117673 +// varpool_finalize_decl(latent_entropy_decl);
117674 +// varpool_mark_needed_node(latent_entropy_decl);
117675 +}
117676 +
117677 +#if BUILDING_GCC_VERSION >= 4009
117678 +static const struct pass_data latent_entropy_pass_data = {
117679 +#else
117680 +static struct gimple_opt_pass latent_entropy_pass = {
117681 + .pass = {
117682 +#endif
117683 + .type = GIMPLE_PASS,
117684 + .name = "latent_entropy",
117685 +#if BUILDING_GCC_VERSION >= 4008
117686 + .optinfo_flags = OPTGROUP_NONE,
117687 +#endif
117688 +#if BUILDING_GCC_VERSION >= 4009
117689 + .has_gate = true,
117690 + .has_execute = true,
117691 +#else
117692 + .gate = gate_latent_entropy,
117693 + .execute = execute_latent_entropy,
117694 + .sub = NULL,
117695 + .next = NULL,
117696 + .static_pass_number = 0,
117697 +#endif
117698 + .tv_id = TV_NONE,
117699 + .properties_required = PROP_gimple_leh | PROP_cfg,
117700 + .properties_provided = 0,
117701 + .properties_destroyed = 0,
117702 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
117703 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
117704 +#if BUILDING_GCC_VERSION < 4009
117705 + }
117706 +#endif
117707 +};
117708 +
117709 +#if BUILDING_GCC_VERSION >= 4009
117710 +namespace {
117711 +class latent_entropy_pass : public gimple_opt_pass {
117712 +public:
117713 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
117714 + bool gate() { return gate_latent_entropy(); }
117715 + unsigned int execute() { return execute_latent_entropy(); }
117716 +};
117717 +}
117718 +
117719 +static opt_pass *make_latent_entropy_pass(void)
117720 +{
117721 + return new latent_entropy_pass();
117722 +}
117723 +#else
117724 +static struct opt_pass *make_latent_entropy_pass(void)
117725 +{
117726 + return &latent_entropy_pass.pass;
117727 +}
117728 +#endif
117729 +
117730 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117731 +{
117732 + const char * const plugin_name = plugin_info->base_name;
117733 + struct register_pass_info latent_entropy_pass_info;
117734 +
117735 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
117736 + latent_entropy_pass_info.reference_pass_name = "optimized";
117737 + latent_entropy_pass_info.ref_pass_instance_number = 1;
117738 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
117739 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
117740 + {
117741 + .base = &latent_entropy_decl,
117742 + .nelt = 1,
117743 + .stride = sizeof(latent_entropy_decl),
117744 + .cb = &gt_ggc_mx_tree_node,
117745 + .pchw = &gt_pch_nx_tree_node
117746 + },
117747 + LAST_GGC_ROOT_TAB
117748 + };
117749 +
117750 + if (!plugin_default_version_check(version, &gcc_version)) {
117751 + error(G_("incompatible gcc/plugin versions"));
117752 + return 1;
117753 + }
117754 +
117755 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
117756 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
117757 + if (!in_lto_p)
117758 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
117759 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
117760 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
117761 +
117762 + return 0;
117763 +}
117764 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
117765 new file mode 100644
117766 index 0000000..a5cb46b
117767 --- /dev/null
117768 +++ b/tools/gcc/randomize_layout_plugin.c
117769 @@ -0,0 +1,915 @@
117770 +/*
117771 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
117772 + * and PaX Team <pageexec@freemail.hu>
117773 + * Licensed under the GPL v2
117774 + *
117775 + * Usage:
117776 + * $ # for 4.5/4.6/C based 4.7
117777 + * $ gcc -I`gcc -print-file-name=plugin`/include -I`gcc -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -o randomize_layout_plugin.so randomize_layout_plugin.c
117778 + * $ # for C++ based 4.7/4.8+
117779 + * $ g++ -I`g++ -print-file-name=plugin`/include -I`g++ -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -o randomize_layout_plugin.so randomize_layout_plugin.c
117780 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
117781 + */
117782 +
117783 +#include "gcc-common.h"
117784 +#include "randomize_layout_seed.h"
117785 +
117786 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
117787 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
117788 +#endif
117789 +
117790 +#define ORIG_TYPE_NAME(node) \
117791 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
117792 +
117793 +int plugin_is_GPL_compatible;
117794 +
117795 +static int performance_mode;
117796 +
117797 +static struct plugin_info randomize_layout_plugin_info = {
117798 + .version = "201402201816",
117799 + .help = "disable\t\t\tdo not activate plugin\n"
117800 + "performance-mode\tenable cacheline-aware layout randomization\n"
117801 +};
117802 +
117803 +/* from old Linux dcache.h */
117804 +static inline unsigned long
117805 +partial_name_hash(unsigned long c, unsigned long prevhash)
117806 +{
117807 + return (prevhash + (c << 4) + (c >> 4)) * 11;
117808 +}
117809 +static inline unsigned int
117810 +name_hash(const unsigned char *name)
117811 +{
117812 + unsigned long hash = 0;
117813 + unsigned int len = strlen((const char *)name);
117814 + while (len--)
117815 + hash = partial_name_hash(*name++, hash);
117816 + return (unsigned int)hash;
117817 +}
117818 +
117819 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
117820 +{
117821 + tree type;
117822 +
117823 + *no_add_attrs = true;
117824 + if (TREE_CODE(*node) == FUNCTION_DECL) {
117825 + error("%qE attribute does not apply to functions (%qF)", name, *node);
117826 + return NULL_TREE;
117827 + }
117828 +
117829 + if (TREE_CODE(*node) == PARM_DECL) {
117830 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
117831 + return NULL_TREE;
117832 + }
117833 +
117834 + if (TREE_CODE(*node) == VAR_DECL) {
117835 + error("%qE attribute does not apply to variables (%qD)", name, *node);
117836 + return NULL_TREE;
117837 + }
117838 +
117839 + if (TYPE_P(*node)) {
117840 + type = *node;
117841 + } else {
117842 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
117843 + type = TREE_TYPE(*node);
117844 + }
117845 +
117846 + if (TREE_CODE(type) != RECORD_TYPE) {
117847 + error("%qE attribute used on %qT applies to struct types only", name, type);
117848 + return NULL_TREE;
117849 + }
117850 +
117851 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
117852 + error("%qE attribute is already applied to the type %qT", name, type);
117853 + return NULL_TREE;
117854 + }
117855 +
117856 + *no_add_attrs = false;
117857 +
117858 + return NULL_TREE;
117859 +}
117860 +
117861 +/* set on complete types that we don't need to inspect further at all */
117862 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
117863 +{
117864 + *no_add_attrs = false;
117865 + return NULL_TREE;
117866 +}
117867 +
117868 +/*
117869 + * set on types that we've performed a shuffle on, to prevent re-shuffling
117870 + * this does not preclude us from inspecting its fields for potential shuffles
117871 + */
117872 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
117873 +{
117874 + *no_add_attrs = false;
117875 + return NULL_TREE;
117876 +}
117877 +
117878 +/*
117879 + * 64bit variant of Bob Jenkins' public domain PRNG
117880 + * 256 bits of internal state
117881 + */
117882 +
117883 +typedef unsigned long long u64;
117884 +
117885 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
117886 +
117887 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
117888 +static u64 ranval(ranctx *x) {
117889 + u64 e = x->a - rot(x->b, 7);
117890 + x->a = x->b ^ rot(x->c, 13);
117891 + x->b = x->c + rot(x->d, 37);
117892 + x->c = x->d + e;
117893 + x->d = e + x->a;
117894 + return x->d;
117895 +}
117896 +
117897 +static void raninit(ranctx *x, u64 *seed) {
117898 + int i;
117899 +
117900 + x->a = seed[0];
117901 + x->b = seed[1];
117902 + x->c = seed[2];
117903 + x->d = seed[3];
117904 +
117905 + for (i=0; i < 30; ++i)
117906 + (void)ranval(x);
117907 +}
117908 +
117909 +static u64 shuffle_seed[4];
117910 +
117911 +struct partition_group {
117912 + tree tree_start;
117913 + unsigned long start;
117914 + unsigned long length;
117915 +};
117916 +
117917 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
117918 +{
117919 + unsigned long i;
117920 + unsigned long accum_size = 0;
117921 + unsigned long accum_length = 0;
117922 + unsigned long group_idx = 0;
117923 +
117924 + gcc_assert(length < INT_MAX);
117925 +
117926 + memset(size_groups, 0, sizeof(struct partition_group) * length);
117927 +
117928 + for (i = 0; i < length; i++) {
117929 + if (size_groups[group_idx].tree_start == NULL_TREE) {
117930 + size_groups[group_idx].tree_start = fields[i];
117931 + size_groups[group_idx].start = i;
117932 + accum_length = 0;
117933 + accum_size = 0;
117934 + }
117935 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
117936 + accum_length++;
117937 + if (accum_size >= 64) {
117938 + size_groups[group_idx].length = accum_length;
117939 + accum_length = 0;
117940 + group_idx++;
117941 + }
117942 + }
117943 +
117944 + if (size_groups[group_idx].tree_start != NULL_TREE &&
117945 + !size_groups[group_idx].length) {
117946 + size_groups[group_idx].length = accum_length;
117947 + group_idx++;
117948 + }
117949 +
117950 + *num_groups = group_idx;
117951 +}
117952 +
117953 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
117954 +{
117955 + unsigned long i, x;
117956 + struct partition_group size_group[length];
117957 + unsigned long num_groups = 0;
117958 + unsigned long randnum;
117959 +
117960 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
117961 + for (i = num_groups - 1; i > 0; i--) {
117962 + struct partition_group tmp;
117963 + randnum = ranval(prng_state) % (i + 1);
117964 + tmp = size_group[i];
117965 + size_group[i] = size_group[randnum];
117966 + size_group[randnum] = tmp;
117967 + }
117968 +
117969 + for (x = 0; x < num_groups; x++) {
117970 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
117971 + tree tmp;
117972 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
117973 + continue;
117974 + randnum = ranval(prng_state) % (i + 1);
117975 + // we could handle this case differently if desired
117976 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
117977 + continue;
117978 + tmp = newtree[i];
117979 + newtree[i] = newtree[randnum];
117980 + newtree[randnum] = tmp;
117981 + }
117982 + }
117983 +}
117984 +
117985 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
117986 +{
117987 + unsigned long i, randnum;
117988 +
117989 + for (i = length - 1; i > 0; i--) {
117990 + tree tmp;
117991 + randnum = ranval(prng_state) % (i + 1);
117992 + tmp = newtree[i];
117993 + newtree[i] = newtree[randnum];
117994 + newtree[randnum] = tmp;
117995 + }
117996 +}
117997 +
117998 +/* modern in-place Fisher-Yates shuffle */
117999 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
118000 +{
118001 + unsigned long i;
118002 + u64 seed[4];
118003 + ranctx prng_state;
118004 + const unsigned char *structname;
118005 +
118006 + if (length == 0)
118007 + return;
118008 +
118009 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
118010 +
118011 + structname = ORIG_TYPE_NAME(type);
118012 +
118013 +#ifdef __DEBUG_PLUGIN
118014 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
118015 +#ifdef __DEBUG_VERBOSE
118016 + debug_tree((tree)type);
118017 +#endif
118018 +#endif
118019 +
118020 + for (i = 0; i < 4; i++) {
118021 + seed[i] = shuffle_seed[i];
118022 + seed[i] ^= name_hash(structname);
118023 + }
118024 +
118025 + raninit(&prng_state, (u64 *)&seed);
118026 +
118027 + if (performance_mode)
118028 + performance_shuffle(newtree, length, &prng_state);
118029 + else
118030 + full_shuffle(newtree, length, &prng_state);
118031 +}
118032 +
118033 +static bool is_flexible_array(const_tree field)
118034 +{
118035 + const_tree fieldtype;
118036 + const_tree typesize;
118037 + const_tree elemtype;
118038 + const_tree elemsize;
118039 +
118040 + fieldtype = TREE_TYPE(field);
118041 + typesize = TYPE_SIZE(fieldtype);
118042 +
118043 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
118044 + return false;
118045 +
118046 + elemtype = TREE_TYPE(fieldtype);
118047 + elemsize = TYPE_SIZE(elemtype);
118048 +
118049 + /* size of type is represented in bits */
118050 +
118051 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
118052 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
118053 + return true;
118054 +
118055 + if (typesize != NULL_TREE &&
118056 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
118057 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
118058 + return true;
118059 +
118060 + return false;
118061 +}
118062 +
118063 +static int relayout_struct(tree type)
118064 +{
118065 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
118066 + unsigned long shuffle_length = num_fields;
118067 + tree field;
118068 + tree newtree[num_fields];
118069 + unsigned long i;
118070 + tree list;
118071 + tree variant;
118072 + expanded_location xloc;
118073 +
118074 + if (TYPE_FIELDS(type) == NULL_TREE)
118075 + return 0;
118076 +
118077 + if (num_fields < 2)
118078 + return 0;
118079 +
118080 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
118081 +
118082 + gcc_assert(num_fields < INT_MAX);
118083 +
118084 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
118085 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
118086 + return 0;
118087 +
118088 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
118089 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
118090 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
118091 + return 0;
118092 +
118093 + /* throw out any structs in uapi */
118094 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
118095 +
118096 + if (strstr(xloc.file, "/uapi/"))
118097 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
118098 +
118099 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
118100 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
118101 + newtree[i] = field;
118102 + }
118103 +
118104 + /*
118105 + * enforce that we don't randomize the layout of the last
118106 + * element of a struct if it's a 0 or 1-length array
118107 + * or a proper flexible array
118108 + */
118109 + if (is_flexible_array(newtree[num_fields - 1]))
118110 + shuffle_length--;
118111 +
118112 + shuffle(type, (tree *)newtree, shuffle_length);
118113 +
118114 + /*
118115 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
118116 + * as gcc provides no other way to detect such code
118117 + */
118118 + list = make_node(FIELD_DECL);
118119 + TREE_CHAIN(list) = newtree[0];
118120 + TREE_TYPE(list) = void_type_node;
118121 + DECL_SIZE(list) = bitsize_zero_node;
118122 + DECL_NONADDRESSABLE_P(list) = 1;
118123 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
118124 + DECL_SIZE_UNIT(list) = size_zero_node;
118125 + DECL_FIELD_OFFSET(list) = size_zero_node;
118126 + // to satisfy the constify plugin
118127 + TREE_READONLY(list) = 1;
118128 +
118129 + for (i = 0; i < num_fields - 1; i++)
118130 + TREE_CHAIN(newtree[i]) = newtree[i+1];
118131 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
118132 +
118133 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
118134 + TYPE_FIELDS(variant) = list;
118135 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
118136 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
118137 + // force a re-layout
118138 + TYPE_SIZE(variant) = NULL_TREE;
118139 + layout_type(variant);
118140 + }
118141 +
118142 + return 1;
118143 +}
118144 +
118145 +/* from constify plugin */
118146 +static const_tree get_field_type(const_tree field)
118147 +{
118148 + return strip_array_types(TREE_TYPE(field));
118149 +}
118150 +
118151 +/* from constify plugin */
118152 +static bool is_fptr(const_tree fieldtype)
118153 +{
118154 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
118155 + return false;
118156 +
118157 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
118158 +}
118159 +
118160 +/* derived from constify plugin */
118161 +static int is_pure_ops_struct(const_tree node)
118162 +{
118163 + const_tree field;
118164 +
118165 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
118166 +
118167 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
118168 + const_tree fieldtype = get_field_type(field);
118169 + enum tree_code code = TREE_CODE(fieldtype);
118170 +
118171 + if (node == fieldtype)
118172 + continue;
118173 +
118174 + if (!is_fptr(fieldtype))
118175 + return 0;
118176 +
118177 + if (code != RECORD_TYPE && code != UNION_TYPE)
118178 + continue;
118179 +
118180 + if (!is_pure_ops_struct(fieldtype))
118181 + return 0;
118182 + }
118183 +
118184 + return 1;
118185 +}
118186 +
118187 +static void randomize_type(tree type)
118188 +{
118189 + tree variant;
118190 +
118191 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
118192 +
118193 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
118194 + return;
118195 +
118196 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
118197 + relayout_struct(type);
118198 +
118199 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
118200 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
118201 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
118202 + }
118203 +#ifdef __DEBUG_PLUGIN
118204 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
118205 +#ifdef __DEBUG_VERBOSE
118206 + debug_tree(type);
118207 +#endif
118208 +#endif
118209 +}
118210 +
118211 +static void randomize_layout_finish_decl(void *event_data, void *data)
118212 +{
118213 + tree decl = (tree)event_data;
118214 + tree type;
118215 +
118216 + if (decl == NULL_TREE || decl == error_mark_node)
118217 + return;
118218 +
118219 + type = TREE_TYPE(decl);
118220 +
118221 + if (TREE_CODE(decl) != VAR_DECL)
118222 + return;
118223 +
118224 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
118225 + return;
118226 +
118227 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
118228 + return;
118229 +
118230 + relayout_decl(decl);
118231 +}
118232 +
118233 +static void finish_type(void *event_data, void *data)
118234 +{
118235 + tree type = (tree)event_data;
118236 +
118237 + if (type == NULL_TREE || type == error_mark_node)
118238 + return;
118239 +
118240 + if (TREE_CODE(type) != RECORD_TYPE)
118241 + return;
118242 +
118243 + if (TYPE_FIELDS(type) == NULL_TREE)
118244 + return;
118245 +
118246 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
118247 + return;
118248 +
118249 +#ifdef __DEBUG_PLUGIN
118250 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
118251 +#endif
118252 +#ifdef __DEBUG_VERBOSE
118253 + debug_tree(type);
118254 +#endif
118255 + randomize_type(type);
118256 +
118257 + return;
118258 +}
118259 +
118260 +static struct attribute_spec randomize_layout_attr = {
118261 + .name = "randomize_layout",
118262 + // related to args
118263 + .min_length = 0,
118264 + .max_length = 0,
118265 + .decl_required = false,
118266 + // need type declaration
118267 + .type_required = true,
118268 + .function_type_required = false,
118269 + .handler = handle_randomize_layout_attr,
118270 +#if BUILDING_GCC_VERSION >= 4007
118271 + .affects_type_identity = true
118272 +#endif
118273 +};
118274 +
118275 +static struct attribute_spec no_randomize_layout_attr = {
118276 + .name = "no_randomize_layout",
118277 + // related to args
118278 + .min_length = 0,
118279 + .max_length = 0,
118280 + .decl_required = false,
118281 + // need type declaration
118282 + .type_required = true,
118283 + .function_type_required = false,
118284 + .handler = handle_randomize_layout_attr,
118285 +#if BUILDING_GCC_VERSION >= 4007
118286 + .affects_type_identity = true
118287 +#endif
118288 +};
118289 +
118290 +static struct attribute_spec randomize_considered_attr = {
118291 + .name = "randomize_considered",
118292 + // related to args
118293 + .min_length = 0,
118294 + .max_length = 0,
118295 + .decl_required = false,
118296 + // need type declaration
118297 + .type_required = true,
118298 + .function_type_required = false,
118299 + .handler = handle_randomize_considered_attr,
118300 +#if BUILDING_GCC_VERSION >= 4007
118301 + .affects_type_identity = false
118302 +#endif
118303 +};
118304 +
118305 +static struct attribute_spec randomize_performed_attr = {
118306 + .name = "randomize_performed",
118307 + // related to args
118308 + .min_length = 0,
118309 + .max_length = 0,
118310 + .decl_required = false,
118311 + // need type declaration
118312 + .type_required = true,
118313 + .function_type_required = false,
118314 + .handler = handle_randomize_performed_attr,
118315 +#if BUILDING_GCC_VERSION >= 4007
118316 + .affects_type_identity = false
118317 +#endif
118318 +};
118319 +
118320 +static void register_attributes(void *event_data, void *data)
118321 +{
118322 + register_attribute(&randomize_layout_attr);
118323 + register_attribute(&no_randomize_layout_attr);
118324 + register_attribute(&randomize_considered_attr);
118325 + register_attribute(&randomize_performed_attr);
118326 +}
118327 +
118328 +static void check_bad_casts_in_constructor(tree var, tree init)
118329 +{
118330 + unsigned HOST_WIDE_INT idx;
118331 + tree field, val;
118332 + tree field_type, val_type;
118333 +
118334 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
118335 + if (TREE_CODE(val) == CONSTRUCTOR) {
118336 + check_bad_casts_in_constructor(var, val);
118337 + continue;
118338 + }
118339 +
118340 + /* pipacs' plugin creates franken-arrays that differ from those produced by
118341 + normal code which all have valid 'field' trees. work around this */
118342 + if (field == NULL_TREE)
118343 + continue;
118344 + field_type = TREE_TYPE(field);
118345 + val_type = TREE_TYPE(val);
118346 +
118347 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
118348 + continue;
118349 +
118350 + if (field_type == val_type)
118351 + continue;
118352 +
118353 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
118354 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
118355 +
118356 + if (field_type == void_type_node)
118357 + continue;
118358 + if (field_type == val_type)
118359 + continue;
118360 + if (TREE_CODE(val_type) != RECORD_TYPE)
118361 + continue;
118362 +
118363 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
118364 + continue;
118365 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
118366 + }
118367 +}
118368 +
118369 +/* derived from the constify plugin */
118370 +static void check_global_variables(void *event_data, void *data)
118371 +{
118372 + struct varpool_node *node;
118373 + tree init;
118374 +
118375 + FOR_EACH_VARIABLE(node) {
118376 + tree var = NODE_DECL(node);
118377 + init = DECL_INITIAL(var);
118378 + if (init == NULL_TREE)
118379 + continue;
118380 +
118381 + if (TREE_CODE(init) != CONSTRUCTOR)
118382 + continue;
118383 +
118384 + check_bad_casts_in_constructor(var, init);
118385 + }
118386 +}
118387 +
118388 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
118389 +{
118390 + basic_block dom;
118391 + gimple dom_stmt;
118392 + gimple call_stmt;
118393 + const_tree dom_lhs;
118394 + const_tree poss_is_err_cond;
118395 + const_tree poss_is_err_func;
118396 + const_tree is_err_arg;
118397 +
118398 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
118399 + if (!dom)
118400 + return false;
118401 +
118402 + dom_stmt = last_stmt(dom);
118403 + if (!dom_stmt)
118404 + return false;
118405 +
118406 + if (gimple_code(dom_stmt) != GIMPLE_COND)
118407 + return false;
118408 +
118409 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
118410 + return false;
118411 +
118412 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
118413 + return false;
118414 +
118415 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
118416 +
118417 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
118418 + return false;
118419 +
118420 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
118421 +
118422 + if (gimple_code(call_stmt) != GIMPLE_CALL)
118423 + return false;
118424 +
118425 + dom_lhs = gimple_get_lhs(call_stmt);
118426 + poss_is_err_func = gimple_call_fndecl(call_stmt);
118427 + if (!poss_is_err_func)
118428 + return false;
118429 + if (dom_lhs != poss_is_err_cond)
118430 + return false;
118431 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
118432 + return false;
118433 +
118434 + is_err_arg = gimple_call_arg(call_stmt, 0);
118435 + if (!is_err_arg)
118436 + return false;
118437 +
118438 + if (is_err_arg != rhs)
118439 + return false;
118440 +
118441 + return true;
118442 +}
118443 +
118444 +static void handle_local_var_initializers(void)
118445 +{
118446 + tree var;
118447 + unsigned int i;
118448 +
118449 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
118450 + tree init = DECL_INITIAL(var);
118451 + if (!init)
118452 + continue;
118453 + if (TREE_CODE(init) != CONSTRUCTOR)
118454 + continue;
118455 + check_bad_casts_in_constructor(var, init);
118456 + }
118457 +}
118458 +
118459 +/*
118460 + * iterate over all statements to find "bad" casts:
118461 + * those where the address of the start of a structure is cast
118462 + * to a pointer of a structure of a different type, or a
118463 + * structure pointer type is cast to a different structure pointer type
118464 + */
118465 +static unsigned int find_bad_casts(void)
118466 +{
118467 + basic_block bb;
118468 +
118469 + handle_local_var_initializers();
118470 +
118471 + FOR_ALL_BB_FN(bb, cfun) {
118472 + gimple_stmt_iterator gsi;
118473 +
118474 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118475 + gimple stmt;
118476 + const_tree lhs;
118477 + const_tree lhs_type;
118478 + const_tree rhs1;
118479 + const_tree rhs_type;
118480 + const_tree ptr_lhs_type;
118481 + const_tree ptr_rhs_type;
118482 + const_tree op0;
118483 + const_tree op0_type;
118484 + enum tree_code rhs_code;
118485 +
118486 + stmt = gsi_stmt(gsi);
118487 +
118488 +#ifdef __DEBUG_PLUGIN
118489 +#ifdef __DEBUG_VERBOSE
118490 + debug_gimple_stmt(stmt);
118491 + debug_tree(gimple_get_lhs(stmt));
118492 +#endif
118493 +#endif
118494 +
118495 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
118496 + continue;
118497 +
118498 +#ifdef __DEBUG_PLUGIN
118499 +#ifdef __DEBUG_VERBOSE
118500 + debug_tree(gimple_assign_rhs1(stmt));
118501 +#endif
118502 +#endif
118503 +
118504 + rhs_code = gimple_assign_rhs_code(stmt);
118505 +
118506 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
118507 + continue;
118508 +
118509 + lhs = gimple_get_lhs(stmt);
118510 + lhs_type = TREE_TYPE(lhs);
118511 + rhs1 = gimple_assign_rhs1(stmt);
118512 + rhs_type = TREE_TYPE(rhs1);
118513 +
118514 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
118515 + TREE_CODE(lhs_type) != POINTER_TYPE)
118516 + continue;
118517 +
118518 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
118519 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
118520 +
118521 + if (ptr_rhs_type == void_type_node)
118522 + continue;
118523 +
118524 + if (ptr_lhs_type == void_type_node)
118525 + continue;
118526 +
118527 + if (dominated_by_is_err(rhs1, bb))
118528 + continue;
118529 +
118530 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
118531 +#ifndef __DEBUG_PLUGIN
118532 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
118533 +#endif
118534 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
118535 + continue;
118536 + }
118537 +
118538 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
118539 + continue;
118540 +
118541 + if (rhs_code == ADDR_EXPR) {
118542 + op0 = TREE_OPERAND(rhs1, 0);
118543 +
118544 + if (op0 == NULL_TREE)
118545 + continue;
118546 +
118547 + if (TREE_CODE(op0) != VAR_DECL)
118548 + continue;
118549 +
118550 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
118551 + if (op0_type == ptr_lhs_type)
118552 + continue;
118553 +
118554 +#ifndef __DEBUG_PLUGIN
118555 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
118556 +#endif
118557 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
118558 + } else {
118559 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
118560 + /* skip bogus type casts introduced by container_of */
118561 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
118562 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
118563 + continue;
118564 +#ifndef __DEBUG_PLUGIN
118565 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
118566 +#endif
118567 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
118568 + }
118569 +
118570 + }
118571 + }
118572 + return 0;
118573 +}
118574 +
118575 +#if BUILDING_GCC_VERSION >= 4009
118576 +static const struct pass_data randomize_layout_bad_cast_data = {
118577 +#else
118578 +static struct gimple_opt_pass randomize_layout_bad_cast = {
118579 + .pass = {
118580 +#endif
118581 + .type = GIMPLE_PASS,
118582 + .name = "randomize_layout_bad_cast",
118583 +#if BUILDING_GCC_VERSION >= 4008
118584 + .optinfo_flags = OPTGROUP_NONE,
118585 +#endif
118586 +#if BUILDING_GCC_VERSION >= 4009
118587 + .has_gate = false,
118588 + .has_execute = true,
118589 +#else
118590 + .gate = NULL,
118591 + .execute = find_bad_casts,
118592 + .sub = NULL,
118593 + .next = NULL,
118594 + .static_pass_number = 0,
118595 +#endif
118596 + .tv_id = TV_NONE,
118597 + .properties_required = PROP_cfg,
118598 + .properties_provided = 0,
118599 + .properties_destroyed = 0,
118600 + .todo_flags_start = 0,
118601 + .todo_flags_finish = TODO_dump_func
118602 +#if BUILDING_GCC_VERSION < 4009
118603 + }
118604 +#endif
118605 +};
118606 +
118607 +#if BUILDING_GCC_VERSION >= 4009
118608 +namespace {
118609 +class randomize_layout_bad_cast : public gimple_opt_pass {
118610 +public:
118611 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
118612 + unsigned int execute() { return find_bad_casts(); }
118613 +};
118614 +}
118615 +#endif
118616 +
118617 +static struct opt_pass *make_randomize_layout_bad_cast(void)
118618 +{
118619 +#if BUILDING_GCC_VERSION >= 4009
118620 + return new randomize_layout_bad_cast();
118621 +#else
118622 + return &randomize_layout_bad_cast.pass;
118623 +#endif
118624 +}
118625 +
118626 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118627 +{
118628 + int i;
118629 + const char * const plugin_name = plugin_info->base_name;
118630 + const int argc = plugin_info->argc;
118631 + const struct plugin_argument * const argv = plugin_info->argv;
118632 + bool enable = true;
118633 + int obtained_seed = 0;
118634 + struct register_pass_info randomize_layout_bad_cast_info;
118635 +
118636 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
118637 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
118638 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
118639 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
118640 +
118641 + if (!plugin_default_version_check(version, &gcc_version)) {
118642 + error(G_("incompatible gcc/plugin versions"));
118643 + return 1;
118644 + }
118645 +
118646 + if (strcmp(lang_hooks.name, "GNU C")) {
118647 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
118648 + enable = false;
118649 + }
118650 +
118651 + for (i = 0; i < argc; ++i) {
118652 + if (!strcmp(argv[i].key, "disable")) {
118653 + enable = false;
118654 + continue;
118655 + }
118656 + if (!strcmp(argv[i].key, "performance-mode")) {
118657 + performance_mode = 1;
118658 + continue;
118659 + }
118660 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118661 + }
118662 +
118663 + if (strlen(randstruct_seed) != 64) {
118664 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
118665 + return 1;
118666 + }
118667 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
118668 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
118669 + if (obtained_seed != 4) {
118670 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
118671 + return 1;
118672 + }
118673 +
118674 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
118675 + if (enable) {
118676 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
118677 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
118678 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
118679 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
118680 + }
118681 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
118682 +
118683 + return 0;
118684 +}
118685 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
118686 new file mode 100644
118687 index 0000000..1f0214f
118688 --- /dev/null
118689 +++ b/tools/gcc/size_overflow_plugin/.gitignore
118690 @@ -0,0 +1,3 @@
118691 +randomize_layout_seed.h
118692 +size_overflow_hash.h
118693 +size_overflow_hash_aux.h
118694 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
118695 new file mode 100644
118696 index 0000000..1ae2ed5
118697 --- /dev/null
118698 +++ b/tools/gcc/size_overflow_plugin/Makefile
118699 @@ -0,0 +1,20 @@
118700 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
118701 +always := $($(HOSTLIBS)-y)
118702 +
118703 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
118704 +
118705 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
118706 +
118707 +quiet_cmd_build_size_overflow_hash = GENHASH $@
118708 + cmd_build_size_overflow_hash = \
118709 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
118710 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
118711 + $(call if_changed,build_size_overflow_hash)
118712 +
118713 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
118714 + cmd_build_size_overflow_hash_aux = \
118715 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
118716 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
118717 + $(call if_changed,build_size_overflow_hash_aux)
118718 +
118719 +targets += size_overflow_hash.h size_overflow_hash_aux.h
118720 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
118721 new file mode 100644
118722 index 0000000..12b1e3b
118723 --- /dev/null
118724 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
118725 @@ -0,0 +1,102 @@
118726 +#!/bin/bash
118727 +
118728 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
118729 +
118730 +header1="size_overflow_hash.h"
118731 +database="size_overflow_hash.data"
118732 +n=65536
118733 +hashtable_name="size_overflow_hash"
118734 +
118735 +usage() {
118736 +cat <<EOF
118737 +usage: $0 options
118738 +OPTIONS:
118739 + -h|--help help
118740 + -o header file
118741 + -d database file
118742 + -n hash array size
118743 + -s name of the hash table
118744 +EOF
118745 + return 0
118746 +}
118747 +
118748 +while true
118749 +do
118750 + case "$1" in
118751 + -h|--help) usage && exit 0;;
118752 + -n) n=$2; shift 2;;
118753 + -o) header1="$2"; shift 2;;
118754 + -d) database="$2"; shift 2;;
118755 + -s) hashtable_name="$2"; shift 2;;
118756 + --) shift 1; break ;;
118757 + *) break ;;
118758 + esac
118759 +done
118760 +
118761 +create_defines() {
118762 + for i in `seq 0 31`
118763 + do
118764 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
118765 + done
118766 + echo >> "$header1"
118767 +}
118768 +
118769 +create_structs() {
118770 + rm -f "$header1"
118771 +
118772 + create_defines
118773 +
118774 + cat "$database" | while read data
118775 + do
118776 + data_array=($data)
118777 + struct_hash_name="${data_array[0]}"
118778 + funcn="${data_array[1]}"
118779 + params="${data_array[2]}"
118780 + next="${data_array[4]}"
118781 +
118782 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
118783 +
118784 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
118785 + echo -en "\t.param\t= " >> "$header1"
118786 + line=
118787 + for param_num in ${params//-/ };
118788 + do
118789 + line="${line}PARAM"$param_num"|"
118790 + done
118791 +
118792 + echo -e "${line%?},\n};\n" >> "$header1"
118793 + done
118794 +}
118795 +
118796 +create_headers() {
118797 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
118798 +}
118799 +
118800 +create_array_elements() {
118801 + index=0
118802 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
118803 + do
118804 + data_array=($data)
118805 + i="${data_array[3]}"
118806 + hash="${data_array[0]}"
118807 + while [[ $index -lt $i ]]
118808 + do
118809 + echo -e "\t["$index"]\t= NULL," >> "$header1"
118810 + index=$(($index + 1))
118811 + done
118812 + index=$(($index + 1))
118813 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
118814 + done
118815 + echo '};' >> $header1
118816 +}
118817 +
118818 +size_overflow_plugin_dir=`dirname $header1`
118819 +if [ "$size_overflow_plugin_dir" != '.' ]; then
118820 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
118821 +fi
118822 +
118823 +create_structs
118824 +create_headers
118825 +create_array_elements
118826 +
118827 +exit 0
118828 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
118829 new file mode 100644
118830 index 0000000..c43901f
118831 --- /dev/null
118832 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
118833 @@ -0,0 +1,748 @@
118834 +/*
118835 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
118836 + * Licensed under the GPL v2, or (at your option) v3
118837 + *
118838 + * Homepage:
118839 + * http://www.grsecurity.net/~ephox/overflow_plugin/
118840 + *
118841 + * Documentation:
118842 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
118843 + *
118844 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
118845 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
118846 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
118847 + *
118848 + * Usage:
118849 + * $ make
118850 + * $ make run
118851 + */
118852 +
118853 +#include "gcc-common.h"
118854 +#include "size_overflow.h"
118855 +
118856 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
118857 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
118858 +
118859 +// data for the size_overflow asm stmt
118860 +struct asm_data {
118861 + gimple def_stmt;
118862 + tree input;
118863 + tree output;
118864 +};
118865 +
118866 +#if BUILDING_GCC_VERSION <= 4007
118867 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
118868 +#else
118869 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
118870 +#endif
118871 +{
118872 + tree list;
118873 +#if BUILDING_GCC_VERSION <= 4007
118874 + VEC(tree, gc) *vec_list = NULL;
118875 +#else
118876 + vec<tree, va_gc> *vec_list = NULL;
118877 +#endif
118878 +
118879 + list = build_tree_list(NULL_TREE, string);
118880 + list = chainon(NULL_TREE, build_tree_list(list, io));
118881 +#if BUILDING_GCC_VERSION <= 4007
118882 + VEC_safe_push(tree, gc, vec_list, list);
118883 +#else
118884 + vec_safe_push(vec_list, list);
118885 +#endif
118886 + return vec_list;
118887 +}
118888 +
118889 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
118890 +{
118891 + gimple asm_stmt;
118892 + gimple_stmt_iterator gsi;
118893 +#if BUILDING_GCC_VERSION <= 4007
118894 + VEC(tree, gc) *input, *output = NULL;
118895 +#else
118896 + vec<tree, va_gc> *input, *output = NULL;
118897 +#endif
118898 +
118899 + input = create_asm_io_list(str_input, asm_data->input);
118900 +
118901 + if (asm_data->output)
118902 + output = create_asm_io_list(str_output, asm_data->output);
118903 +
118904 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
118905 + gsi = gsi_for_stmt(asm_data->def_stmt);
118906 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
118907 +
118908 + if (asm_data->output)
118909 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
118910 +}
118911 +
118912 +static void replace_call_lhs(const struct asm_data *asm_data)
118913 +{
118914 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
118915 + update_stmt(asm_data->def_stmt);
118916 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
118917 +}
118918 +
118919 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
118920 +{
118921 + enum mark cur_fndecl_attr;
118922 + gimple phi = get_def_stmt(result);
118923 + unsigned int i, n = gimple_phi_num_args(phi);
118924 +
118925 + pointer_set_insert(visited, phi);
118926 + for (i = 0; i < n; i++) {
118927 + tree arg = gimple_phi_arg_def(phi, i);
118928 +
118929 + cur_fndecl_attr = search_intentional(visited, arg);
118930 + if (cur_fndecl_attr != MARK_NO)
118931 + return cur_fndecl_attr;
118932 + }
118933 + return MARK_NO;
118934 +}
118935 +
118936 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
118937 +{
118938 + enum mark cur_fndecl_attr;
118939 + const_tree rhs1, rhs2;
118940 + gimple def_stmt = get_def_stmt(lhs);
118941 +
118942 + rhs1 = gimple_assign_rhs1(def_stmt);
118943 + rhs2 = gimple_assign_rhs2(def_stmt);
118944 +
118945 + cur_fndecl_attr = search_intentional(visited, rhs1);
118946 + if (cur_fndecl_attr != MARK_NO)
118947 + return cur_fndecl_attr;
118948 + return search_intentional(visited, rhs2);
118949 +}
118950 +
118951 +// Look up the intentional_overflow attribute on the caller and the callee functions.
118952 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
118953 +{
118954 + const_gimple def_stmt;
118955 +
118956 + if (TREE_CODE(lhs) != SSA_NAME)
118957 + return get_intentional_attr_type(lhs);
118958 +
118959 + def_stmt = get_def_stmt(lhs);
118960 + if (!def_stmt)
118961 + return MARK_NO;
118962 +
118963 + if (pointer_set_contains(visited, def_stmt))
118964 + return MARK_NO;
118965 +
118966 + switch (gimple_code(def_stmt)) {
118967 + case GIMPLE_NOP:
118968 + return search_intentional(visited, SSA_NAME_VAR(lhs));
118969 + case GIMPLE_ASM:
118970 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
118971 + return MARK_TURN_OFF;
118972 + return MARK_NO;
118973 + case GIMPLE_CALL:
118974 + return MARK_NO;
118975 + case GIMPLE_PHI:
118976 + return search_intentional_phi(visited, lhs);
118977 + case GIMPLE_ASSIGN:
118978 + switch (gimple_num_ops(def_stmt)) {
118979 + case 2:
118980 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
118981 + case 3:
118982 + return search_intentional_binary(visited, lhs);
118983 + }
118984 + case GIMPLE_RETURN:
118985 + return MARK_NO;
118986 + default:
118987 + debug_gimple_stmt((gimple)def_stmt);
118988 + error("%s: unknown gimple code", __func__);
118989 + gcc_unreachable();
118990 + }
118991 +}
118992 +
118993 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
118994 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
118995 +{
118996 + const_tree fndecl;
118997 + struct pointer_set_t *visited;
118998 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
118999 +
119000 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
119001 + if (is_end_intentional_intentional_attr(fndecl, argnum))
119002 + decl_attr = MARK_NOT_INTENTIONAL;
119003 + else if (is_yes_intentional_attr(fndecl, argnum))
119004 + decl_attr = MARK_YES;
119005 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
119006 + return MARK_TURN_OFF;
119007 + }
119008 +
119009 + visited = pointer_set_create();
119010 + cur_fndecl_attr = search_intentional(visited, arg);
119011 + pointer_set_destroy(visited);
119012 +
119013 + switch (cur_fndecl_attr) {
119014 + case MARK_NO:
119015 + case MARK_TURN_OFF:
119016 + return cur_fndecl_attr;
119017 + default:
119018 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
119019 + return MARK_YES;
119020 + }
119021 +}
119022 +
119023 +static void check_missing_size_overflow_attribute(tree var)
119024 +{
119025 + tree orig_fndecl;
119026 + unsigned int num;
119027 +
119028 + if (is_a_return_check(var))
119029 + orig_fndecl = DECL_ORIGIN(var);
119030 + else
119031 + orig_fndecl = DECL_ORIGIN(current_function_decl);
119032 +
119033 + num = get_function_num(var, orig_fndecl);
119034 + if (num == CANNOT_FIND_ARG)
119035 + return;
119036 +
119037 + is_missing_function(orig_fndecl, num);
119038 +}
119039 +
119040 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
119041 +{
119042 + gimple phi = get_def_stmt(result);
119043 + unsigned int i, n = gimple_phi_num_args(phi);
119044 +
119045 + pointer_set_insert(visited, phi);
119046 + for (i = 0; i < n; i++) {
119047 + tree arg = gimple_phi_arg_def(phi, i);
119048 +
119049 + search_size_overflow_attribute(visited, arg);
119050 + }
119051 +}
119052 +
119053 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
119054 +{
119055 + const_gimple def_stmt = get_def_stmt(lhs);
119056 + tree rhs1, rhs2;
119057 +
119058 + rhs1 = gimple_assign_rhs1(def_stmt);
119059 + rhs2 = gimple_assign_rhs2(def_stmt);
119060 +
119061 + search_size_overflow_attribute(visited, rhs1);
119062 + search_size_overflow_attribute(visited, rhs2);
119063 +}
119064 +
119065 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
119066 +{
119067 + const_gimple def_stmt;
119068 +
119069 + if (TREE_CODE(lhs) == PARM_DECL) {
119070 + check_missing_size_overflow_attribute(lhs);
119071 + return;
119072 + }
119073 +
119074 + def_stmt = get_def_stmt(lhs);
119075 + if (!def_stmt)
119076 + return;
119077 +
119078 + if (pointer_set_insert(visited, def_stmt))
119079 + return;
119080 +
119081 + switch (gimple_code(def_stmt)) {
119082 + case GIMPLE_NOP:
119083 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
119084 + case GIMPLE_ASM:
119085 + return;
119086 + case GIMPLE_CALL: {
119087 + tree fndecl = gimple_call_fndecl(def_stmt);
119088 +
119089 + if (fndecl == NULL_TREE)
119090 + return;
119091 + check_missing_size_overflow_attribute(fndecl);
119092 + return;
119093 + }
119094 + case GIMPLE_PHI:
119095 + return search_size_overflow_attribute_phi(visited, lhs);
119096 + case GIMPLE_ASSIGN:
119097 + switch (gimple_num_ops(def_stmt)) {
119098 + case 2:
119099 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
119100 + case 3:
119101 + return search_size_overflow_attribute_binary(visited, lhs);
119102 + }
119103 + default:
119104 + debug_gimple_stmt((gimple)def_stmt);
119105 + error("%s: unknown gimple code", __func__);
119106 + gcc_unreachable();
119107 + }
119108 +}
119109 +
119110 +// Search missing entries in the hash table (invoked from the gimple pass)
119111 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
119112 +{
119113 + tree fndecl = NULL_TREE;
119114 + tree lhs;
119115 + struct pointer_set_t *visited;
119116 +
119117 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
119118 + return;
119119 +
119120 + if (num == 0) {
119121 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
119122 + lhs = gimple_return_retval(stmt);
119123 + } else {
119124 + gcc_assert(is_gimple_call(stmt));
119125 + lhs = gimple_call_arg(stmt, num - 1);
119126 + fndecl = gimple_call_fndecl(stmt);
119127 + }
119128 +
119129 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
119130 + return;
119131 +
119132 + visited = pointer_set_create();
119133 + search_size_overflow_attribute(visited, lhs);
119134 + pointer_set_destroy(visited);
119135 +}
119136 +
119137 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
119138 +{
119139 + gimple_stmt_iterator gsi;
119140 + gimple assign;
119141 +
119142 + assign = gimple_build_assign(asm_data->input, asm_data->output);
119143 + gsi = gsi_for_stmt(stmt);
119144 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
119145 + asm_data->def_stmt = assign;
119146 +
119147 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
119148 + asm_data->output = make_ssa_name(asm_data->output, stmt);
119149 + if (gimple_code(stmt) == GIMPLE_RETURN)
119150 + gimple_return_set_retval(stmt, asm_data->output);
119151 + else
119152 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
119153 + update_stmt(stmt);
119154 +}
119155 +
119156 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
119157 +{
119158 + const char *fn_name;
119159 + char *asm_comment;
119160 + unsigned int len;
119161 +
119162 + if (argnum == 0)
119163 + fn_name = DECL_NAME_POINTER(current_function_decl);
119164 + else
119165 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
119166 +
119167 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
119168 + gcc_assert(len > 0);
119169 +
119170 + return asm_comment;
119171 +}
119172 +
119173 +static const char *convert_mark_to_str(enum mark mark)
119174 +{
119175 + switch (mark) {
119176 + case MARK_NO:
119177 + return OK_ASM_STR;
119178 + case MARK_YES:
119179 + case MARK_NOT_INTENTIONAL:
119180 + return YES_ASM_STR;
119181 + case MARK_TURN_OFF:
119182 + return TURN_OFF_ASM_STR;
119183 + }
119184 +
119185 + gcc_unreachable();
119186 +}
119187 +
119188 +/* Create the input of the size_overflow asm stmt.
119189 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
119190 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
119191 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
119192 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
119193 + */
119194 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
119195 +{
119196 + if (!asm_data->def_stmt) {
119197 + asm_data->input = NULL_TREE;
119198 + return;
119199 + }
119200 +
119201 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
119202 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
119203 +
119204 + switch (gimple_code(asm_data->def_stmt)) {
119205 + case GIMPLE_ASSIGN:
119206 + case GIMPLE_CALL:
119207 + replace_call_lhs(asm_data);
119208 + break;
119209 + case GIMPLE_PHI:
119210 + create_output_from_phi(stmt, argnum, asm_data);
119211 + break;
119212 + case GIMPLE_NOP: {
119213 + enum mark mark;
119214 + const char *mark_str;
119215 + char *asm_comment;
119216 +
119217 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
119218 +
119219 + asm_data->input = asm_data->output;
119220 + asm_data->output = NULL;
119221 + asm_data->def_stmt = stmt;
119222 +
119223 + mark_str = convert_mark_to_str(mark);
119224 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
119225 +
119226 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
119227 + free(asm_comment);
119228 + asm_data->input = NULL_TREE;
119229 + break;
119230 + }
119231 + case GIMPLE_ASM:
119232 + if (is_size_overflow_asm(asm_data->def_stmt)) {
119233 + asm_data->input = NULL_TREE;
119234 + break;
119235 + }
119236 + default:
119237 + debug_gimple_stmt(asm_data->def_stmt);
119238 + gcc_unreachable();
119239 + }
119240 +}
119241 +
119242 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
119243 + * is of the right kind create the appropriate size_overflow asm stmts:
119244 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
119245 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
119246 + */
119247 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
119248 +{
119249 + struct asm_data asm_data;
119250 + const char *mark_str;
119251 + char *asm_comment;
119252 + enum mark mark;
119253 +
119254 + if (is_gimple_constant(output_node))
119255 + return;
119256 +
119257 + asm_data.output = output_node;
119258 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
119259 + if (mark != MARK_TURN_OFF)
119260 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
119261 +
119262 + asm_data.def_stmt = get_def_stmt(asm_data.output);
119263 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
119264 + return;
119265 +
119266 + create_asm_input(stmt, argnum, &asm_data);
119267 + if (asm_data.input == NULL_TREE)
119268 + return;
119269 +
119270 + mark_str = convert_mark_to_str(mark);
119271 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
119272 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
119273 + free(asm_comment);
119274 +}
119275 +
119276 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
119277 +static bool create_mark_asm(gimple stmt, enum mark mark)
119278 +{
119279 + struct asm_data asm_data;
119280 + const char *asm_str;
119281 +
119282 + switch (mark) {
119283 + case MARK_TURN_OFF:
119284 + asm_str = TURN_OFF_ASM_STR;
119285 + break;
119286 + case MARK_NOT_INTENTIONAL:
119287 + case MARK_YES:
119288 + asm_str = YES_ASM_STR;
119289 + break;
119290 + default:
119291 + gcc_unreachable();
119292 + }
119293 +
119294 + asm_data.def_stmt = stmt;
119295 + asm_data.output = gimple_call_lhs(stmt);
119296 +
119297 + if (asm_data.output == NULL_TREE) {
119298 + asm_data.input = gimple_call_arg(stmt, 0);
119299 + if (is_gimple_constant(asm_data.input))
119300 + return false;
119301 + asm_data.output = NULL;
119302 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
119303 + return true;
119304 + }
119305 +
119306 + create_asm_input(stmt, 0, &asm_data);
119307 + gcc_assert(asm_data.input != NULL_TREE);
119308 +
119309 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
119310 + return true;
119311 +}
119312 +
119313 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
119314 +{
119315 + gimple def_stmt;
119316 +
119317 + def_stmt = get_def_stmt(lhs);
119318 + if (!def_stmt)
119319 + return;
119320 +
119321 + if (pointer_set_insert(visited, def_stmt))
119322 + return;
119323 +
119324 + switch (gimple_code(def_stmt)) {
119325 + case GIMPLE_NOP:
119326 + case GIMPLE_ASM:
119327 + case GIMPLE_CALL:
119328 + break;
119329 + case GIMPLE_PHI: {
119330 + unsigned int i, n = gimple_phi_num_args(def_stmt);
119331 +
119332 + pointer_set_insert(visited, def_stmt);
119333 +
119334 + for (i = 0; i < n; i++) {
119335 + tree arg = gimple_phi_arg_def(def_stmt, i);
119336 +
119337 + walk_use_def_ptr(visited, arg);
119338 + }
119339 + }
119340 + case GIMPLE_ASSIGN:
119341 + switch (gimple_num_ops(def_stmt)) {
119342 + case 2:
119343 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
119344 + return;
119345 + case 3:
119346 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
119347 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
119348 + return;
119349 + default:
119350 + return;
119351 + }
119352 + default:
119353 + debug_gimple_stmt((gimple)def_stmt);
119354 + error("%s: unknown gimple code", __func__);
119355 + gcc_unreachable();
119356 + }
119357 +}
119358 +
119359 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
119360 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
119361 +{
119362 + struct pointer_set_t *visited;
119363 +
119364 + visited = pointer_set_create();
119365 + walk_use_def_ptr(visited, arg);
119366 + pointer_set_destroy(visited);
119367 +}
119368 +
119369 +// Determine the return value and insert the asm stmt to mark the return stmt.
119370 +static void insert_asm_ret(gimple stmt)
119371 +{
119372 + tree ret;
119373 +
119374 + ret = gimple_return_retval(stmt);
119375 + create_size_overflow_asm(stmt, ret, 0);
119376 +}
119377 +
119378 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
119379 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
119380 +{
119381 + tree arg;
119382 + unsigned int argnum;
119383 +
119384 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
119385 + gcc_assert(argnum != 0);
119386 + if (argnum == CANNOT_FIND_ARG)
119387 + return;
119388 +
119389 + arg = gimple_call_arg(stmt, argnum - 1);
119390 + gcc_assert(arg != NULL_TREE);
119391 +
119392 + // skip all ptr - ptr expressions
119393 + insert_mark_not_intentional_asm_at_ptr(arg);
119394 +
119395 + create_size_overflow_asm(stmt, arg, argnum);
119396 +}
119397 +
119398 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
119399 +static void set_argnum_attribute(const_tree attr, bool *argnums)
119400 +{
119401 + unsigned int argnum;
119402 + tree attr_value;
119403 +
119404 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
119405 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
119406 + argnums[argnum] = true;
119407 + }
119408 +}
119409 +
119410 +// If a function arg or the return value is in the hash table then set its index in the array.
119411 +static void set_argnum_hash(tree fndecl, bool *argnums)
119412 +{
119413 + unsigned int num;
119414 + const struct size_overflow_hash *hash;
119415 +
119416 + hash = get_function_hash(DECL_ORIGIN(fndecl));
119417 + if (!hash)
119418 + return;
119419 +
119420 + for (num = 0; num <= MAX_PARAM; num++) {
119421 + if (!(hash->param & (1U << num)))
119422 + continue;
119423 +
119424 + argnums[num] = true;
119425 + }
119426 +}
119427 +
119428 +static bool is_all_the_argnums_empty(bool *argnums)
119429 +{
119430 + unsigned int i;
119431 +
119432 + for (i = 0; i <= MAX_PARAM; i++)
119433 + if (argnums[i])
119434 + return false;
119435 + return true;
119436 +}
119437 +
119438 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
119439 +static void search_interesting_args(tree fndecl, bool *argnums)
119440 +{
119441 + const_tree attr;
119442 +
119443 + set_argnum_hash(fndecl, argnums);
119444 + if (!is_all_the_argnums_empty(argnums))
119445 + return;
119446 +
119447 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
119448 + if (attr && TREE_VALUE(attr))
119449 + set_argnum_attribute(attr, argnums);
119450 +}
119451 +
119452 +/*
119453 + * Look up the intentional_overflow attribute that turns off ipa based duplication
119454 + * on the callee function.
119455 + */
119456 +static bool is_mark_turn_off_attribute(gimple stmt)
119457 +{
119458 + enum mark mark;
119459 + const_tree fndecl = gimple_call_fndecl(stmt);
119460 +
119461 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
119462 + if (mark == MARK_TURN_OFF)
119463 + return true;
119464 + return false;
119465 +}
119466 +
119467 +// If the argument(s) of the callee function is/are in the hash table or are marked by an attribute then mark the call stmt with an asm stmt
119468 +static void handle_interesting_function(gimple stmt)
119469 +{
119470 + unsigned int argnum;
119471 + tree fndecl;
119472 + bool orig_argnums[MAX_PARAM + 1] = {false};
119473 +
119474 + if (gimple_call_num_args(stmt) == 0)
119475 + return;
119476 + fndecl = gimple_call_fndecl(stmt);
119477 + if (fndecl == NULL_TREE)
119478 + return;
119479 + fndecl = DECL_ORIGIN(fndecl);
119480 +
119481 + if (is_mark_turn_off_attribute(stmt)) {
119482 + create_mark_asm(stmt, MARK_TURN_OFF);
119483 + return;
119484 + }
119485 +
119486 + search_interesting_args(fndecl, orig_argnums);
119487 +
119488 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
119489 + if (orig_argnums[argnum])
119490 + insert_asm_arg(stmt, argnum);
119491 +}
119492 +
119493 +// If the return value of the caller function is in hash table (its index is 0) then mark the return stmt with an asm stmt
119494 +static void handle_interesting_ret(gimple stmt)
119495 +{
119496 + bool orig_argnums[MAX_PARAM + 1] = {false};
119497 +
119498 + search_interesting_args(current_function_decl, orig_argnums);
119499 +
119500 + if (orig_argnums[0])
119501 + insert_asm_ret(stmt);
119502 +}
119503 +
119504 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
119505 +static unsigned int search_interesting_functions(void)
119506 +{
119507 + basic_block bb;
119508 +
119509 + FOR_ALL_BB_FN(bb, cfun) {
119510 + gimple_stmt_iterator gsi;
119511 +
119512 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
119513 + gimple stmt = gsi_stmt(gsi);
119514 +
119515 + if (is_size_overflow_asm(stmt))
119516 + continue;
119517 +
119518 + if (is_gimple_call(stmt))
119519 + handle_interesting_function(stmt);
119520 + else if (gimple_code(stmt) == GIMPLE_RETURN)
119521 + handle_interesting_ret(stmt);
119522 + }
119523 + }
119524 + return 0;
119525 +}
119526 +
119527 +/*
119528 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
119529 + * this pass inserts asm stmts to mark the interesting args
119530 + * that the ipa pass will detect and insert the size overflow checks for.
119531 + */
119532 +#if BUILDING_GCC_VERSION >= 4009
119533 +static const struct pass_data insert_size_overflow_asm_pass_data = {
119534 +#else
119535 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
119536 + .pass = {
119537 +#endif
119538 + .type = GIMPLE_PASS,
119539 + .name = "insert_size_overflow_asm",
119540 +#if BUILDING_GCC_VERSION >= 4008
119541 + .optinfo_flags = OPTGROUP_NONE,
119542 +#endif
119543 +#if BUILDING_GCC_VERSION >= 4009
119544 + .has_gate = false,
119545 + .has_execute = true,
119546 +#else
119547 + .gate = NULL,
119548 + .execute = search_interesting_functions,
119549 + .sub = NULL,
119550 + .next = NULL,
119551 + .static_pass_number = 0,
119552 +#endif
119553 + .tv_id = TV_NONE,
119554 + .properties_required = PROP_cfg,
119555 + .properties_provided = 0,
119556 + .properties_destroyed = 0,
119557 + .todo_flags_start = 0,
119558 + .todo_flags_finish = TODO_dump_func | TODO_verify_ssa | TODO_verify_stmts | TODO_remove_unused_locals | TODO_update_ssa_no_phi | TODO_cleanup_cfg | TODO_ggc_collect | TODO_verify_flow
119559 +#if BUILDING_GCC_VERSION < 4009
119560 + }
119561 +#endif
119562 +};
119563 +
119564 +#if BUILDING_GCC_VERSION >= 4009
119565 +namespace {
119566 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
119567 +public:
119568 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
119569 + unsigned int execute() { return search_interesting_functions(); }
119570 +};
119571 +}
119572 +#endif
119573 +
119574 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
119575 +{
119576 +#if BUILDING_GCC_VERSION >= 4009
119577 + return new insert_size_overflow_asm_pass();
119578 +#else
119579 + return &insert_size_overflow_asm_pass.pass;
119580 +#endif
119581 +}
119582 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
119583 new file mode 100644
119584 index 0000000..73f0a12
119585 --- /dev/null
119586 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
119587 @@ -0,0 +1,943 @@
119588 +/*
119589 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
119590 + * Licensed under the GPL v2, or (at your option) v3
119591 + *
119592 + * Homepage:
119593 + * http://www.grsecurity.net/~ephox/overflow_plugin/
119594 + *
119595 + * Documentation:
119596 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
119597 + *
119598 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
119599 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
119600 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
119601 + *
119602 + * Usage:
119603 + * $ make
119604 + * $ make run
119605 + */
119606 +
119607 +#include "gcc-common.h"
119608 +#include "size_overflow.h"
119609 +
119610 +#define MIN_CHECK true
119611 +#define MAX_CHECK false
119612 +
119613 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
119614 +{
119615 + const_tree type;
119616 + tree new_type;
119617 +
119618 + gcc_assert(node != NULL_TREE);
119619 +
119620 + type = TREE_TYPE(node);
119621 +
119622 + if (pointer_set_contains(visited->my_stmts, stmt))
119623 + return TREE_TYPE(node);
119624 +
119625 + switch (TYPE_MODE(type)) {
119626 + case QImode:
119627 + new_type = size_overflow_type_HI;
119628 + break;
119629 + case HImode:
119630 + new_type = size_overflow_type_SI;
119631 + break;
119632 + case SImode:
119633 + new_type = size_overflow_type_DI;
119634 + break;
119635 + case DImode:
119636 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
119637 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
119638 + else
119639 + new_type = size_overflow_type_TI;
119640 + break;
119641 + case TImode:
119642 + gcc_assert(!TYPE_UNSIGNED(type));
119643 + new_type = size_overflow_type_TI;
119644 + break;
119645 + default:
119646 + debug_tree((tree)node);
119647 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
119648 + gcc_unreachable();
119649 + }
119650 +
119651 + if (TYPE_QUALS(type) != 0)
119652 + return build_qualified_type(new_type, TYPE_QUALS(type));
119653 + return new_type;
119654 +}
119655 +
119656 +static tree get_lhs(const_gimple stmt)
119657 +{
119658 + switch (gimple_code(stmt)) {
119659 + case GIMPLE_ASSIGN:
119660 + case GIMPLE_CALL:
119661 + return gimple_get_lhs(stmt);
119662 + case GIMPLE_PHI:
119663 + return gimple_phi_result(stmt);
119664 + default:
119665 + return NULL_TREE;
119666 + }
119667 +}
119668 +
119669 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
119670 +{
119671 + gimple_stmt_iterator gsi;
119672 + tree lhs;
119673 + gimple new_stmt;
119674 +
119675 + if (rhs == NULL_TREE)
119676 + return NULL_TREE;
119677 +
119678 + gsi = gsi_for_stmt(stmt);
119679 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
119680 + pointer_set_insert(visited->my_stmts, new_stmt);
119681 +
119682 + lhs = get_lhs(new_stmt);
119683 + gcc_assert(lhs != NULL_TREE);
119684 + return lhs;
119685 +}
119686 +
119687 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
119688 +{
119689 + tree lhs, dst_type;
119690 + gimple_stmt_iterator gsi;
119691 +
119692 + if (rhs1 == NULL_TREE) {
119693 + debug_gimple_stmt(oldstmt);
119694 + error("%s: rhs1 is NULL_TREE", __func__);
119695 + gcc_unreachable();
119696 + }
119697 +
119698 + switch (gimple_code(oldstmt)) {
119699 + case GIMPLE_ASM:
119700 + lhs = rhs1;
119701 + break;
119702 + case GIMPLE_CALL:
119703 + case GIMPLE_ASSIGN:
119704 + lhs = gimple_get_lhs(oldstmt);
119705 + break;
119706 + default:
119707 + debug_gimple_stmt(oldstmt);
119708 + gcc_unreachable();
119709 + }
119710 +
119711 + gsi = gsi_for_stmt(oldstmt);
119712 + pointer_set_insert(visited->stmts, oldstmt);
119713 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
119714 + basic_block next_bb, cur_bb;
119715 + const_edge e;
119716 +
119717 + gcc_assert(before == false);
119718 + gcc_assert(stmt_can_throw_internal(oldstmt));
119719 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
119720 + gcc_assert(!gsi_end_p(gsi));
119721 +
119722 + cur_bb = gimple_bb(oldstmt);
119723 + next_bb = cur_bb->next_bb;
119724 + e = find_edge(cur_bb, next_bb);
119725 + gcc_assert(e != NULL);
119726 + gcc_assert(e->flags & EDGE_FALLTHRU);
119727 +
119728 + gsi = gsi_after_labels(next_bb);
119729 + gcc_assert(!gsi_end_p(gsi));
119730 +
119731 + before = true;
119732 + oldstmt = gsi_stmt(gsi);
119733 + }
119734 +
119735 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
119736 +
119737 + if (is_gimple_constant(rhs1))
119738 + return cast_a_tree(dst_type, rhs1);
119739 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
119740 +}
119741 +
119742 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
119743 +{
119744 + gimple stmt;
119745 + gimple_stmt_iterator gsi;
119746 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
119747 +
119748 + if (pointer_set_contains(visited->my_stmts, oldstmt))
119749 + return lhs;
119750 +
119751 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
119752 + rhs1 = gimple_assign_rhs1(oldstmt);
119753 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
119754 + }
119755 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
119756 + rhs2 = gimple_assign_rhs2(oldstmt);
119757 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
119758 + }
119759 +
119760 + stmt = gimple_copy(oldstmt);
119761 + gimple_set_location(stmt, gimple_location(oldstmt));
119762 + pointer_set_insert(visited->my_stmts, stmt);
119763 +
119764 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
119765 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
119766 +
119767 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
119768 +
119769 + new_var = create_new_var(size_overflow_type);
119770 + new_var = make_ssa_name(new_var, stmt);
119771 + gimple_assign_set_lhs(stmt, new_var);
119772 +
119773 + if (rhs1 != NULL_TREE)
119774 + gimple_assign_set_rhs1(stmt, rhs1);
119775 +
119776 + if (rhs2 != NULL_TREE)
119777 + gimple_assign_set_rhs2(stmt, rhs2);
119778 +#if BUILDING_GCC_VERSION >= 4006
119779 + if (rhs3 != NULL_TREE)
119780 + gimple_assign_set_rhs3(stmt, rhs3);
119781 +#endif
119782 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
119783 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
119784 +
119785 + gsi = gsi_for_stmt(oldstmt);
119786 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
119787 + update_stmt(stmt);
119788 + pointer_set_insert(visited->stmts, oldstmt);
119789 + return gimple_assign_lhs(stmt);
119790 +}
119791 +
119792 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
119793 +{
119794 + gimple assign;
119795 + gimple_stmt_iterator gsi;
119796 + basic_block first_bb;
119797 +
119798 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
119799 +
119800 + if (bb->index == 0) {
119801 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
119802 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
119803 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
119804 + bb = first_bb;
119805 + }
119806 +
119807 + gsi = gsi_after_labels(bb);
119808 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
119809 + pointer_set_insert(visited->my_stmts, assign);
119810 +
119811 + return gimple_assign_lhs(assign);
119812 +}
119813 +
119814 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
119815 +{
119816 + gimple_stmt_iterator gsi;
119817 + gimple assign, def_stmt = get_def_stmt(new_arg);
119818 +
119819 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
119820 + gsi = gsi_after_labels(gimple_bb(def_stmt));
119821 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
119822 + } else {
119823 + gsi = gsi_for_stmt(def_stmt);
119824 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
119825 + }
119826 +
119827 + pointer_set_insert(visited->my_stmts, assign);
119828 + return gimple_assign_lhs(assign);
119829 +}
119830 +
119831 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
119832 +{
119833 + basic_block bb;
119834 + gimple_stmt_iterator gsi;
119835 + const_gimple def_stmt;
119836 + gimple assign;
119837 +
119838 + def_stmt = get_def_stmt(arg);
119839 + bb = gimple_bb(def_stmt);
119840 + gcc_assert(bb->index != 0);
119841 + gsi = gsi_after_labels(bb);
119842 +
119843 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
119844 + pointer_set_insert(visited->my_stmts, assign);
119845 + return gimple_assign_lhs(assign);
119846 +}
119847 +
119848 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
119849 +{
119850 + tree size_overflow_type;
119851 + tree arg;
119852 + const_gimple def_stmt;
119853 +
119854 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
119855 + return new_arg;
119856 +
119857 + arg = gimple_phi_arg_def(oldstmt, i);
119858 + def_stmt = get_def_stmt(arg);
119859 + gcc_assert(def_stmt != NULL);
119860 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
119861 +
119862 + switch (gimple_code(def_stmt)) {
119863 + case GIMPLE_PHI:
119864 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
119865 + case GIMPLE_NOP: {
119866 + basic_block bb;
119867 +
119868 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
119869 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
119870 + }
119871 + case GIMPLE_ASM: {
119872 + gimple_stmt_iterator gsi;
119873 + gimple assign, stmt = get_def_stmt(arg);
119874 +
119875 + gsi = gsi_for_stmt(stmt);
119876 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
119877 + pointer_set_insert(visited->my_stmts, assign);
119878 + return gimple_assign_lhs(assign);
119879 + }
119880 + default:
119881 + gcc_assert(new_arg != NULL_TREE);
119882 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
119883 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
119884 + }
119885 +}
119886 +
119887 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
119888 +{
119889 + basic_block bb;
119890 + gimple phi;
119891 + gimple_seq seq;
119892 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
119893 +
119894 + bb = gsi_bb(gsi);
119895 +
119896 + if (result == NULL_TREE) {
119897 + tree old_result = gimple_phi_result(oldstmt);
119898 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
119899 +
119900 + result = create_new_var(size_overflow_type);
119901 + }
119902 +
119903 + phi = create_phi_node(result, bb);
119904 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
119905 + seq = phi_nodes(bb);
119906 + gsi = gsi_last(seq);
119907 + gsi_remove(&gsi, false);
119908 +
119909 + gsi = gsi_for_stmt(oldstmt);
119910 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
119911 + gimple_set_bb(phi, bb);
119912 + return phi;
119913 +}
119914 +
119915 +#if BUILDING_GCC_VERSION <= 4007
119916 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
119917 +#else
119918 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
119919 +#endif
119920 +{
119921 + gimple new_phi;
119922 + unsigned int i;
119923 + tree arg, result;
119924 + location_t loc = gimple_location(oldstmt);
119925 +
119926 +#if BUILDING_GCC_VERSION <= 4007
119927 + gcc_assert(!VEC_empty(tree, *args));
119928 +#else
119929 + gcc_assert(!args->is_empty());
119930 +#endif
119931 +
119932 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
119933 + result = gimple_phi_result(new_phi);
119934 + ssa_name_var = SSA_NAME_VAR(result);
119935 +
119936 +#if BUILDING_GCC_VERSION <= 4007
119937 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
119938 +#else
119939 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
119940 +#endif
119941 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
119942 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
119943 + }
119944 +
119945 +#if BUILDING_GCC_VERSION <= 4007
119946 + VEC_free(tree, heap, *args);
119947 +#else
119948 + vec_free(args);
119949 +#endif
119950 + update_stmt(new_phi);
119951 + pointer_set_insert(visited->my_stmts, new_phi);
119952 + return result;
119953 +}
119954 +
119955 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
119956 +{
119957 + tree ssa_name_var = NULL_TREE;
119958 +#if BUILDING_GCC_VERSION <= 4007
119959 + VEC(tree, heap) *args = NULL;
119960 +#else
119961 + vec<tree, va_heap, vl_embed> *args = NULL;
119962 +#endif
119963 + gimple oldstmt = get_def_stmt(orig_result);
119964 + unsigned int i, len = gimple_phi_num_args(oldstmt);
119965 +
119966 + pointer_set_insert(visited->stmts, oldstmt);
119967 + for (i = 0; i < len; i++) {
119968 + tree arg, new_arg;
119969 +
119970 + arg = gimple_phi_arg_def(oldstmt, i);
119971 + new_arg = expand(visited, caller_node, arg);
119972 +
119973 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
119974 + ssa_name_var = SSA_NAME_VAR(new_arg);
119975 +
119976 + if (is_gimple_constant(arg)) {
119977 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
119978 +
119979 + new_arg = cast_a_tree(size_overflow_type, arg);
119980 + }
119981 +
119982 +#if BUILDING_GCC_VERSION <= 4007
119983 + VEC_safe_push(tree, heap, args, new_arg);
119984 +#else
119985 + vec_safe_push(args, new_arg);
119986 +#endif
119987 + }
119988 +
119989 +#if BUILDING_GCC_VERSION <= 4007
119990 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
119991 +#else
119992 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
119993 +#endif
119994 +}
119995 +
119996 +static tree create_cast_assign(struct visited *visited, gimple stmt)
119997 +{
119998 + tree rhs1 = gimple_assign_rhs1(stmt);
119999 + tree lhs = gimple_assign_lhs(stmt);
120000 + const_tree rhs1_type = TREE_TYPE(rhs1);
120001 + const_tree lhs_type = TREE_TYPE(lhs);
120002 +
120003 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
120004 + return create_assign(visited, stmt, lhs, AFTER_STMT);
120005 +
120006 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
120007 +}
120008 +
120009 +static bool skip_lhs_cast_check(const_gimple stmt)
120010 +{
120011 + const_tree rhs = gimple_assign_rhs1(stmt);
120012 + const_gimple def_stmt = get_def_stmt(rhs);
120013 +
120014 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
120015 + if (gimple_code(def_stmt) == GIMPLE_ASM)
120016 + return true;
120017 +
120018 + if (is_const_plus_unsigned_signed_truncation(rhs))
120019 + return true;
120020 +
120021 + return false;
120022 +}
120023 +
120024 +static tree create_string_param(tree string)
120025 +{
120026 + tree i_type, a_type;
120027 + const int length = TREE_STRING_LENGTH(string);
120028 +
120029 + gcc_assert(length > 0);
120030 +
120031 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
120032 + a_type = build_array_type(char_type_node, i_type);
120033 +
120034 + TREE_TYPE(string) = a_type;
120035 + TREE_CONSTANT(string) = 1;
120036 + TREE_READONLY(string) = 1;
120037 +
120038 + return build1(ADDR_EXPR, ptr_type_node, string);
120039 +}
120040 +
120041 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
120042 +{
120043 + gimple cond_stmt;
120044 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
120045 +
120046 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
120047 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
120048 + update_stmt(cond_stmt);
120049 +}
120050 +
120051 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
120052 +{
120053 + gimple func_stmt;
120054 + const_gimple def_stmt;
120055 + const_tree loc_line;
120056 + tree loc_file, ssa_name, current_func;
120057 + expanded_location xloc;
120058 + char *ssa_name_buf;
120059 + int len;
120060 + struct cgraph_edge *edge;
120061 + struct cgraph_node *callee_node;
120062 + int frequency;
120063 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
120064 +
120065 + def_stmt = get_def_stmt(arg);
120066 + xloc = expand_location(gimple_location(def_stmt));
120067 +
120068 + if (!gimple_has_location(def_stmt)) {
120069 + xloc = expand_location(gimple_location(stmt));
120070 + if (!gimple_has_location(stmt))
120071 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
120072 + }
120073 +
120074 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
120075 +
120076 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
120077 + loc_file = create_string_param(loc_file);
120078 +
120079 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
120080 + current_func = create_string_param(current_func);
120081 +
120082 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
120083 + call_count++;
120084 + len = asprintf(&ssa_name_buf, "%s_%u %s, count: %u\n", DECL_NAME_POINTER(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max", call_count);
120085 + gcc_assert(len > 0);
120086 + ssa_name = build_string(len + 1, ssa_name_buf);
120087 + free(ssa_name_buf);
120088 + ssa_name = create_string_param(ssa_name);
120089 +
120090 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
120091 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
120092 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
120093 +
120094 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
120095 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
120096 +
120097 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
120098 + gcc_assert(edge != NULL);
120099 +}
120100 +
120101 +static void insert_check_size_overflow(struct cgraph_node *caller_node, gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
120102 +{
120103 + basic_block cond_bb, join_bb, bb_true;
120104 + edge e;
120105 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
120106 +
120107 + cond_bb = gimple_bb(stmt);
120108 + if (before)
120109 + gsi_prev(&gsi);
120110 + if (gsi_end_p(gsi))
120111 + e = split_block_after_labels(cond_bb);
120112 + else
120113 + e = split_block(cond_bb, gsi_stmt(gsi));
120114 + cond_bb = e->src;
120115 + join_bb = e->dest;
120116 + e->flags = EDGE_FALSE_VALUE;
120117 + e->probability = REG_BR_PROB_BASE;
120118 +
120119 + bb_true = create_empty_bb(cond_bb);
120120 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
120121 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
120122 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
120123 +
120124 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
120125 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
120126 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
120127 +
120128 + if (current_loops != NULL) {
120129 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
120130 + add_bb_to_loop(bb_true, cond_bb->loop_father);
120131 + }
120132 +
120133 + insert_cond(cond_bb, arg, cond_code, type_value);
120134 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
120135 +
120136 +// print_the_code_insertions(stmt);
120137 +}
120138 +
120139 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
120140 +{
120141 + const_tree rhs_type = TREE_TYPE(rhs);
120142 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
120143 +
120144 + gcc_assert(rhs_type != NULL_TREE);
120145 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
120146 + return;
120147 +
120148 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
120149 +
120150 + if (is_const_plus_unsigned_signed_truncation(rhs))
120151 + return;
120152 +
120153 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
120154 + // typemax (-1) < typemin (0)
120155 + if (TREE_OVERFLOW(type_max))
120156 + return;
120157 +
120158 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
120159 +
120160 + cast_rhs_type = TREE_TYPE(cast_rhs);
120161 + type_max_type = TREE_TYPE(type_max);
120162 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
120163 +
120164 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
120165 +
120166 + // special case: get_size_overflow_type(), 32, u64->s
120167 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
120168 + return;
120169 +
120170 + type_min_type = TREE_TYPE(type_min);
120171 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
120172 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
120173 +}
120174 +
120175 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
120176 +{
120177 + bool cast_lhs, cast_rhs;
120178 + tree lhs = gimple_assign_lhs(stmt);
120179 + tree rhs = gimple_assign_rhs1(stmt);
120180 + const_tree lhs_type = TREE_TYPE(lhs);
120181 + const_tree rhs_type = TREE_TYPE(rhs);
120182 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
120183 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
120184 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
120185 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
120186 +
120187 + static bool check_lhs[3][4] = {
120188 + // ss su us uu
120189 + { false, true, true, false }, // lhs > rhs
120190 + { false, false, false, false }, // lhs = rhs
120191 + { true, true, true, true }, // lhs < rhs
120192 + };
120193 +
120194 + static bool check_rhs[3][4] = {
120195 + // ss su us uu
120196 + { true, false, true, true }, // lhs > rhs
120197 + { true, false, true, true }, // lhs = rhs
120198 + { true, false, true, true }, // lhs < rhs
120199 + };
120200 +
120201 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
120202 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
120203 + return create_assign(visited, stmt, lhs, AFTER_STMT);
120204 +
120205 + if (lhs_size > rhs_size) {
120206 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
120207 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
120208 + } else if (lhs_size == rhs_size) {
120209 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
120210 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
120211 + } else {
120212 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
120213 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
120214 + }
120215 +
120216 + if (!cast_lhs && !cast_rhs)
120217 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
120218 +
120219 + if (cast_lhs && !skip_lhs_cast_check(stmt))
120220 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
120221 +
120222 + if (cast_rhs)
120223 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
120224 +
120225 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
120226 +}
120227 +
120228 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
120229 +{
120230 + enum tree_code rhs_code;
120231 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
120232 +
120233 + if (pointer_set_contains(visited->my_stmts, stmt))
120234 + return lhs;
120235 +
120236 + rhs1 = gimple_assign_rhs1(stmt);
120237 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
120238 + return create_assign(visited, stmt, lhs, AFTER_STMT);
120239 +
120240 + new_rhs1 = expand(visited, caller_node, rhs1);
120241 +
120242 + if (new_rhs1 == NULL_TREE)
120243 + return create_cast_assign(visited, stmt);
120244 +
120245 + if (pointer_set_contains(visited->no_cast_check, stmt))
120246 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
120247 +
120248 + rhs_code = gimple_assign_rhs_code(stmt);
120249 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
120250 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
120251 +
120252 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
120253 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
120254 + return create_assign(visited, stmt, lhs, AFTER_STMT);
120255 + }
120256 +
120257 + if (!gimple_assign_cast_p(stmt))
120258 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
120259 +
120260 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
120261 +}
120262 +
120263 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
120264 +{
120265 + tree rhs1, lhs = gimple_assign_lhs(stmt);
120266 + gimple def_stmt = get_def_stmt(lhs);
120267 +
120268 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
120269 + rhs1 = gimple_assign_rhs1(def_stmt);
120270 +
120271 + if (is_gimple_constant(rhs1))
120272 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
120273 +
120274 + switch (TREE_CODE(rhs1)) {
120275 + case SSA_NAME: {
120276 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
120277 +
120278 + if (gimple_assign_cast_p(stmt))
120279 + unsigned_signed_cast_intentional_overflow(visited, stmt);
120280 + return ret;
120281 + }
120282 + case ARRAY_REF:
120283 + case BIT_FIELD_REF:
120284 + case ADDR_EXPR:
120285 + case COMPONENT_REF:
120286 + case INDIRECT_REF:
120287 +#if BUILDING_GCC_VERSION >= 4006
120288 + case MEM_REF:
120289 +#endif
120290 + case TARGET_MEM_REF:
120291 + case VIEW_CONVERT_EXPR:
120292 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
120293 + case PARM_DECL:
120294 + case VAR_DECL:
120295 + return create_assign(visited, stmt, lhs, AFTER_STMT);
120296 +
120297 + default:
120298 + debug_gimple_stmt(def_stmt);
120299 + debug_tree(rhs1);
120300 + gcc_unreachable();
120301 + }
120302 +}
120303 +
120304 +static void __unused print_the_code_insertions(const_gimple stmt)
120305 +{
120306 + location_t loc = gimple_location(stmt);
120307 +
120308 + inform(loc, "Integer size_overflow check applied here.");
120309 +}
120310 +
120311 +static bool is_from_cast(const_tree node)
120312 +{
120313 + gimple def_stmt = get_def_stmt(node);
120314 +
120315 + if (!def_stmt)
120316 + return false;
120317 +
120318 + if (gimple_assign_cast_p(def_stmt))
120319 + return true;
120320 +
120321 + return false;
120322 +}
120323 +
120324 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
120325 +static bool is_a_ptr_minus(gimple stmt)
120326 +{
120327 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
120328 +
120329 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
120330 + return false;
120331 +
120332 + rhs1 = gimple_assign_rhs1(stmt);
120333 + if (!is_from_cast(rhs1))
120334 + return false;
120335 +
120336 + rhs2 = gimple_assign_rhs2(stmt);
120337 + if (!is_from_cast(rhs2))
120338 + return false;
120339 +
120340 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
120341 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
120342 +
120343 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
120344 + return false;
120345 +
120346 + return true;
120347 +}
120348 +
120349 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
120350 +{
120351 + enum intentional_overflow_type res;
120352 + tree rhs1, rhs2, new_lhs;
120353 + gimple def_stmt = get_def_stmt(lhs);
120354 + tree new_rhs1 = NULL_TREE;
120355 + tree new_rhs2 = NULL_TREE;
120356 +
120357 + if (is_a_ptr_minus(def_stmt))
120358 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
120359 +
120360 + rhs1 = gimple_assign_rhs1(def_stmt);
120361 + rhs2 = gimple_assign_rhs2(def_stmt);
120362 +
120363 + /* no DImode/TImode division in the 32/64 bit kernel */
120364 + switch (gimple_assign_rhs_code(def_stmt)) {
120365 + case RDIV_EXPR:
120366 + case TRUNC_DIV_EXPR:
120367 + case CEIL_DIV_EXPR:
120368 + case FLOOR_DIV_EXPR:
120369 + case ROUND_DIV_EXPR:
120370 + case TRUNC_MOD_EXPR:
120371 + case CEIL_MOD_EXPR:
120372 + case FLOOR_MOD_EXPR:
120373 + case ROUND_MOD_EXPR:
120374 + case EXACT_DIV_EXPR:
120375 + case POINTER_PLUS_EXPR:
120376 + case BIT_AND_EXPR:
120377 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
120378 + default:
120379 + break;
120380 + }
120381 +
120382 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
120383 + if (new_lhs != NULL_TREE)
120384 + return new_lhs;
120385 +
120386 + if (TREE_CODE(rhs1) == SSA_NAME)
120387 + new_rhs1 = expand(visited, caller_node, rhs1);
120388 + if (TREE_CODE(rhs2) == SSA_NAME)
120389 + new_rhs2 = expand(visited, caller_node, rhs2);
120390 +
120391 + res = add_mul_intentional_overflow(def_stmt);
120392 + if (res != NO_INTENTIONAL_OVERFLOW) {
120393 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
120394 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
120395 + return new_lhs;
120396 + }
120397 +
120398 + if (skip_expr_on_double_type(def_stmt)) {
120399 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
120400 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
120401 + return new_lhs;
120402 + }
120403 +
120404 + if (is_a_neg_overflow(def_stmt, rhs2))
120405 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
120406 + if (is_a_neg_overflow(def_stmt, rhs1))
120407 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
120408 +
120409 +
120410 + if (is_a_constant_overflow(def_stmt, rhs2))
120411 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
120412 + if (is_a_constant_overflow(def_stmt, rhs1))
120413 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
120414 +
120415 + // the const is between 0 and (signed) MAX
120416 + if (is_gimple_constant(rhs1))
120417 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
120418 + if (is_gimple_constant(rhs2))
120419 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
120420 +
120421 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
120422 +}
120423 +
120424 +#if BUILDING_GCC_VERSION >= 4006
120425 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
120426 +{
120427 + if (is_gimple_constant(rhs))
120428 + return cast_a_tree(size_overflow_type, rhs);
120429 + if (TREE_CODE(rhs) != SSA_NAME)
120430 + return NULL_TREE;
120431 + return expand(visited, caller_node, rhs);
120432 +}
120433 +
120434 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
120435 +{
120436 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
120437 + gimple def_stmt = get_def_stmt(lhs);
120438 +
120439 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
120440 +
120441 + rhs1 = gimple_assign_rhs1(def_stmt);
120442 + rhs2 = gimple_assign_rhs2(def_stmt);
120443 + rhs3 = gimple_assign_rhs3(def_stmt);
120444 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
120445 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
120446 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
120447 +
120448 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
120449 +}
120450 +#endif
120451 +
120452 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
120453 +{
120454 + gimple_stmt_iterator gsi;
120455 + gimple next_stmt = NULL;
120456 +
120457 + gsi = gsi_for_stmt(stmt);
120458 +
120459 + do {
120460 + gsi_next(&gsi);
120461 + next_stmt = gsi_stmt(gsi);
120462 +
120463 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
120464 + return NULL_TREE;
120465 +
120466 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
120467 + break;
120468 +
120469 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
120470 + } while (!gsi_end_p(gsi));
120471 +
120472 + gcc_assert(next_stmt);
120473 + return get_lhs(next_stmt);
120474 +}
120475 +
120476 +static tree expand_visited(struct visited *visited, gimple def_stmt)
120477 +{
120478 + gimple_stmt_iterator gsi;
120479 + enum gimple_code code = gimple_code(def_stmt);
120480 +
120481 + if (code == GIMPLE_ASM)
120482 + return NULL_TREE;
120483 +
120484 + gsi = gsi_for_stmt(def_stmt);
120485 + gsi_next(&gsi);
120486 +
120487 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
120488 + return NULL_TREE;
120489 + return get_my_stmt_lhs(visited, def_stmt);
120490 +}
120491 +
120492 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
120493 +{
120494 + gimple def_stmt;
120495 +
120496 + def_stmt = get_def_stmt(lhs);
120497 +
120498 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
120499 + return NULL_TREE;
120500 +
120501 + if (pointer_set_contains(visited->my_stmts, def_stmt))
120502 + return lhs;
120503 +
120504 + if (pointer_set_contains(visited->stmts, def_stmt))
120505 + return expand_visited(visited, def_stmt);
120506 +
120507 + switch (gimple_code(def_stmt)) {
120508 + case GIMPLE_PHI:
120509 + return handle_phi(visited, caller_node, lhs);
120510 + case GIMPLE_CALL:
120511 + case GIMPLE_ASM:
120512 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
120513 + case GIMPLE_ASSIGN:
120514 + switch (gimple_num_ops(def_stmt)) {
120515 + case 2:
120516 + return handle_unary_ops(visited, caller_node, def_stmt);
120517 + case 3:
120518 + return handle_binary_ops(visited, caller_node, lhs);
120519 +#if BUILDING_GCC_VERSION >= 4006
120520 + case 4:
120521 + return handle_ternary_ops(visited, caller_node, lhs);
120522 +#endif
120523 + }
120524 + default:
120525 + debug_gimple_stmt(def_stmt);
120526 + error("%s: unknown gimple code", __func__);
120527 + gcc_unreachable();
120528 + }
120529 +}
120530 +
120531 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
120532 new file mode 100644
120533 index 0000000..df50164
120534 --- /dev/null
120535 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
120536 @@ -0,0 +1,1141 @@
120537 +/*
120538 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
120539 + * Licensed under the GPL v2, or (at your option) v3
120540 + *
120541 + * Homepage:
120542 + * http://www.grsecurity.net/~ephox/overflow_plugin/
120543 + *
120544 + * Documentation:
120545 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
120546 + *
120547 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
120548 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
120549 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
120550 + *
120551 + * Usage:
120552 + * $ make
120553 + * $ make run
120554 + */
120555 +
120556 +#include "gcc-common.h"
120557 +#include "size_overflow.h"
120558 +
120559 +#define VEC_LEN 128
120560 +#define RET_CHECK NULL_TREE
120561 +#define WRONG_NODE 32
120562 +#define NOT_INTENTIONAL_ASM NULL
120563 +
120564 +unsigned int call_count;
120565 +
120566 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
120567 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
120568 +
120569 +struct visited_fns {
120570 + struct visited_fns *next;
120571 + const_tree fndecl;
120572 + unsigned int num;
120573 + const_gimple first_stmt;
120574 +};
120575 +
120576 +struct next_cgraph_node {
120577 + struct next_cgraph_node *next;
120578 + struct cgraph_node *current_function;
120579 + tree callee_fndecl;
120580 + unsigned int num;
120581 +};
120582 +
120583 +// Don't want to duplicate entries in next_cgraph_node
120584 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
120585 +{
120586 + const_tree new_callee_fndecl;
120587 + struct next_cgraph_node *cur_node;
120588 +
120589 + if (fndecl == RET_CHECK)
120590 + new_callee_fndecl = NODE_DECL(node);
120591 + else
120592 + new_callee_fndecl = fndecl;
120593 +
120594 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
120595 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
120596 + continue;
120597 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
120598 + continue;
120599 + if (num == cur_node->num)
120600 + return true;
120601 + }
120602 + return false;
120603 +}
120604 +
120605 +/* Add a next_cgraph_node into the list for handle_function().
120606 + * handle_function() iterates over all the next cgraph nodes and
120607 + * starts the overflow check insertion process.
120608 + */
120609 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
120610 +{
120611 + struct next_cgraph_node *new_node;
120612 +
120613 + if (is_in_next_cgraph_node(head, node, fndecl, num))
120614 + return head;
120615 +
120616 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
120617 + new_node->current_function = node;
120618 + new_node->next = NULL;
120619 + new_node->num = num;
120620 + if (fndecl == RET_CHECK)
120621 + new_node->callee_fndecl = NODE_DECL(node);
120622 + else
120623 + new_node->callee_fndecl = fndecl;
120624 +
120625 + if (!head)
120626 + return new_node;
120627 +
120628 + new_node->next = head;
120629 + return new_node;
120630 +}
120631 +
120632 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
120633 +{
120634 + struct cgraph_edge *e;
120635 +
120636 + if (num == 0)
120637 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
120638 +
120639 + for (e = node->callers; e; e = e->next_caller) {
120640 + tree fndecl = gimple_call_fndecl(e->call_stmt);
120641 +
120642 + gcc_assert(fndecl != NULL_TREE);
120643 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
120644 + }
120645 +
120646 + return head;
120647 +}
120648 +
120649 +struct missing_functions {
120650 + struct missing_functions *next;
120651 + const_tree node;
120652 + tree fndecl;
120653 +};
120654 +
120655 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
120656 +{
120657 + struct missing_functions *new_function;
120658 +
120659 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
120660 + new_function->node = node;
120661 + new_function->next = NULL;
120662 +
120663 + if (TREE_CODE(node) == FUNCTION_DECL)
120664 + new_function->fndecl = node;
120665 + else
120666 + new_function->fndecl = current_function_decl;
120667 + gcc_assert(new_function->fndecl);
120668 +
120669 + if (!missing_fn_head)
120670 + return new_function;
120671 +
120672 + new_function->next = missing_fn_head;
120673 + return new_function;
120674 +}
120675 +
120676 +/* If the function is missing from the hash table and it is a static function
120677 + * then create a next_cgraph_node from it for handle_function()
120678 + */
120679 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
120680 +{
120681 + unsigned int num;
120682 + const_tree orig_fndecl;
120683 + struct cgraph_node *next_node = NULL;
120684 +
120685 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
120686 +
120687 + num = get_function_num(missing_fn_head->node, orig_fndecl);
120688 + if (num == CANNOT_FIND_ARG)
120689 + return cnodes;
120690 +
120691 + if (!is_missing_function(orig_fndecl, num))
120692 + return cnodes;
120693 +
120694 + next_node = cgraph_get_node(missing_fn_head->fndecl);
120695 + if (next_node && next_node->local.local)
120696 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
120697 + return cnodes;
120698 +}
120699 +
120700 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
120701 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
120702 + */
120703 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
120704 +{
120705 + unsigned int i;
120706 + tree node;
120707 + struct missing_functions *cur, *missing_fn_head = NULL;
120708 +
120709 +#if BUILDING_GCC_VERSION <= 4007
120710 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
120711 +#else
120712 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
120713 +#endif
120714 + switch (TREE_CODE(node)) {
120715 + case PARM_DECL:
120716 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
120717 + break;
120718 + case FUNCTION_DECL:
120719 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
120720 + break;
120721 + default:
120722 + break;
120723 + }
120724 + }
120725 +
120726 + while (missing_fn_head) {
120727 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
120728 +
120729 + cur = missing_fn_head->next;
120730 + free(missing_fn_head);
120731 + missing_fn_head = cur;
120732 + }
120733 +
120734 + return cnodes;
120735 +}
120736 +
120737 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
120738 +{
120739 + gimple phi = get_def_stmt(result);
120740 + unsigned int i, n = gimple_phi_num_args(phi);
120741 +
120742 + pointer_set_insert(visited, phi);
120743 + for (i = 0; i < n; i++) {
120744 + const_tree arg = gimple_phi_arg_def(phi, i);
120745 +
120746 + set_conditions(visited, interesting_conditions, arg);
120747 + }
120748 +}
120749 +
120750 +enum conditions {
120751 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
120752 +};
120753 +
120754 +// Search for constants, cast assignments and binary/ternary assignments
120755 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
120756 +{
120757 + gimple def_stmt = get_def_stmt(lhs);
120758 +
120759 + if (is_gimple_constant(lhs)) {
120760 + interesting_conditions[FROM_CONST] = true;
120761 + return;
120762 + }
120763 +
120764 + if (!def_stmt)
120765 + return;
120766 +
120767 + if (pointer_set_contains(visited, def_stmt))
120768 + return;
120769 +
120770 + switch (gimple_code(def_stmt)) {
120771 + case GIMPLE_CALL:
120772 + if (lhs == gimple_call_lhs(def_stmt))
120773 + interesting_conditions[RET] = true;
120774 + return;
120775 + case GIMPLE_NOP:
120776 + case GIMPLE_ASM:
120777 + return;
120778 + case GIMPLE_PHI:
120779 + interesting_conditions[PHI] = true;
120780 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
120781 + case GIMPLE_ASSIGN:
120782 + if (gimple_num_ops(def_stmt) == 2) {
120783 + const_tree rhs = gimple_assign_rhs1(def_stmt);
120784 +
120785 + if (gimple_assign_cast_p(def_stmt))
120786 + interesting_conditions[CAST] = true;
120787 +
120788 + return set_conditions(visited, interesting_conditions, rhs);
120789 + } else {
120790 + interesting_conditions[NOT_UNARY] = true;
120791 + return;
120792 + }
120793 + default:
120794 + debug_gimple_stmt(def_stmt);
120795 + gcc_unreachable();
120796 + }
120797 +}
120798 +
120799 +// determine whether duplication will be necessary or not.
120800 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
120801 +{
120802 + struct pointer_set_t *visited;
120803 +
120804 + if (gimple_assign_cast_p(cur_node->first_stmt))
120805 + interesting_conditions[CAST] = true;
120806 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
120807 + interesting_conditions[NOT_UNARY] = true;
120808 +
120809 + visited = pointer_set_create();
120810 + set_conditions(visited, interesting_conditions, cur_node->node);
120811 + pointer_set_destroy(visited);
120812 +}
120813 +
120814 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
120815 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
120816 +{
120817 + gimple assign;
120818 + gimple_stmt_iterator gsi;
120819 +
120820 + // already removed
120821 + if (gimple_bb(asm_stmt) == NULL)
120822 + return;
120823 + gsi = gsi_for_stmt(asm_stmt);
120824 +
120825 + assign = gimple_build_assign(lhs, rhs);
120826 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
120827 + SSA_NAME_DEF_STMT(lhs) = assign;
120828 +
120829 + gsi_remove(&gsi, true);
120830 +}
120831 +
120832 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
120833 + * stmt is a return otherwise it is the callee function.
120834 + */
120835 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
120836 +{
120837 + const_tree fndecl;
120838 +
120839 + if (argnum == 0)
120840 + fndecl = current_function_decl;
120841 + else
120842 + fndecl = gimple_call_fndecl(stmt);
120843 +
120844 + if (fndecl == NULL_TREE)
120845 + return NULL_TREE;
120846 +
120847 + return DECL_ORIGIN(fndecl);
120848 +}
120849 +
120850 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
120851 +static bool skip_asm(const_tree arg)
120852 +{
120853 + gimple def_stmt = get_def_stmt(arg);
120854 +
120855 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
120856 + return false;
120857 +
120858 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
120859 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
120860 +}
120861 +
120862 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
120863 +{
120864 + gimple phi = get_def_stmt(result);
120865 + unsigned int i, n = gimple_phi_num_args(phi);
120866 +
120867 + pointer_set_insert(visited, phi);
120868 + for (i = 0; i < n; i++) {
120869 + tree arg = gimple_phi_arg_def(phi, i);
120870 +
120871 + walk_use_def(visited, cur_node, arg);
120872 + }
120873 +}
120874 +
120875 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
120876 +{
120877 + gimple def_stmt = get_def_stmt(lhs);
120878 + tree rhs1, rhs2;
120879 +
120880 + rhs1 = gimple_assign_rhs1(def_stmt);
120881 + rhs2 = gimple_assign_rhs2(def_stmt);
120882 +
120883 + walk_use_def(visited, cur_node, rhs1);
120884 + walk_use_def(visited, cur_node, rhs2);
120885 +}
120886 +
120887 +static void insert_last_node(struct interesting_node *cur_node, tree node)
120888 +{
120889 + unsigned int i;
120890 + tree element;
120891 + enum tree_code code;
120892 +
120893 + gcc_assert(node != NULL_TREE);
120894 +
120895 + if (is_gimple_constant(node))
120896 + return;
120897 +
120898 + code = TREE_CODE(node);
120899 + if (code == VAR_DECL) {
120900 + node = DECL_ORIGIN(node);
120901 + code = TREE_CODE(node);
120902 + }
120903 +
120904 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
120905 + return;
120906 +
120907 +#if BUILDING_GCC_VERSION <= 4007
120908 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
120909 +#else
120910 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
120911 +#endif
120912 + if (operand_equal_p(node, element, 0))
120913 + return;
120914 + }
120915 +
120916 +#if BUILDING_GCC_VERSION <= 4007
120917 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
120918 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
120919 +#else
120920 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
120921 + vec_safe_push(cur_node->last_nodes, node);
120922 +#endif
120923 +}
120924 +
120925 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
120926 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
120927 +{
120928 + if (!is_size_overflow_asm(stmt))
120929 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
120930 +}
120931 +
120932 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
120933 + * and component refs (for checking the intentional_overflow attribute).
120934 + */
120935 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
120936 +{
120937 + const_gimple def_stmt;
120938 +
120939 + if (TREE_CODE(lhs) != SSA_NAME) {
120940 + insert_last_node(cur_node, lhs);
120941 + return;
120942 + }
120943 +
120944 + def_stmt = get_def_stmt(lhs);
120945 + if (!def_stmt)
120946 + return;
120947 +
120948 + if (pointer_set_insert(visited, def_stmt))
120949 + return;
120950 +
120951 + switch (gimple_code(def_stmt)) {
120952 + case GIMPLE_NOP:
120953 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
120954 + case GIMPLE_ASM:
120955 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
120956 + case GIMPLE_CALL: {
120957 + tree fndecl = gimple_call_fndecl(def_stmt);
120958 +
120959 + if (fndecl == NULL_TREE)
120960 + return;
120961 + insert_last_node(cur_node, fndecl);
120962 + return;
120963 + }
120964 + case GIMPLE_PHI:
120965 + return walk_use_def_phi(visited, cur_node, lhs);
120966 + case GIMPLE_ASSIGN:
120967 + switch (gimple_num_ops(def_stmt)) {
120968 + case 2:
120969 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
120970 + case 3:
120971 + return walk_use_def_binary(visited, cur_node, lhs);
120972 + }
120973 + default:
120974 + debug_gimple_stmt((gimple)def_stmt);
120975 + error("%s: unknown gimple code", __func__);
120976 + gcc_unreachable();
120977 + }
120978 +}
120979 +
120980 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
120981 +static void set_last_nodes(struct interesting_node *cur_node)
120982 +{
120983 + struct pointer_set_t *visited;
120984 +
120985 + visited = pointer_set_create();
120986 + walk_use_def(visited, cur_node, cur_node->node);
120987 + pointer_set_destroy(visited);
120988 +}
120989 +
120990 +enum precond {
120991 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
120992 +};
120993 +
120994 +/* If there is a mark_turn_off intentional attribute on the caller or the callee then there is no duplication and missing size_overflow attribute check anywhere.
120995 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
120996 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
120997 + * It skips the possible error codes too.
120998 + */
120999 +static enum precond check_preconditions(struct interesting_node *cur_node)
121000 +{
121001 + bool interesting_conditions[5] = {false, false, false, false, false};
121002 +
121003 + set_last_nodes(cur_node);
121004 +
121005 + check_intentional_attribute_ipa(cur_node);
121006 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
121007 + return NO_ATTRIBUTE_SEARCH;
121008 +
121009 + search_interesting_conditions(cur_node, interesting_conditions);
121010 +
121011 + // error code: a phi, unary assign (not cast) and returns only
121012 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
121013 + return NO_ATTRIBUTE_SEARCH;
121014 +
121015 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
121016 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
121017 + return NO_ATTRIBUTE_SEARCH;
121018 +
121019 + // unnecessary overflow check
121020 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
121021 + return NO_CHECK_INSERT;
121022 +
121023 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
121024 + return NO_CHECK_INSERT;
121025 +
121026 + return NONE;
121027 +}
121028 +
121029 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
121030 +{
121031 + const_gimple assign;
121032 + tree orig_type = TREE_TYPE(orig_node);
121033 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
121034 +
121035 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
121036 + return gimple_assign_lhs(assign);
121037 +}
121038 +
121039 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
121040 +{
121041 + void (*set_rhs)(gimple, tree);
121042 + gimple stmt = cur_node->first_stmt;
121043 + const_tree orig_node = cur_node->node;
121044 +
121045 + switch (gimple_code(stmt)) {
121046 + case GIMPLE_RETURN:
121047 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
121048 + break;
121049 + case GIMPLE_CALL:
121050 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
121051 + break;
121052 + case GIMPLE_ASSIGN:
121053 + switch (cur_node->num) {
121054 + case 1:
121055 + set_rhs = &gimple_assign_set_rhs1;
121056 + break;
121057 + case 2:
121058 + set_rhs = &gimple_assign_set_rhs2;
121059 + break;
121060 +#if BUILDING_GCC_VERSION >= 4006
121061 + case 3:
121062 + set_rhs = &gimple_assign_set_rhs3;
121063 + break;
121064 +#endif
121065 + default:
121066 + gcc_unreachable();
121067 + }
121068 +
121069 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
121070 + break;
121071 + default:
121072 + debug_gimple_stmt(stmt);
121073 + gcc_unreachable();
121074 + }
121075 +
121076 + update_stmt(stmt);
121077 +}
121078 +
121079 +static struct visited *create_visited(void)
121080 +{
121081 + struct visited *new_node;
121082 +
121083 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
121084 + new_node->stmts = pointer_set_create();
121085 + new_node->my_stmts = pointer_set_create();
121086 + new_node->skip_expr_casts = pointer_set_create();
121087 + new_node->no_cast_check = pointer_set_create();
121088 + return new_node;
121089 +}
121090 +
121091 +static void free_visited(struct visited *visited)
121092 +{
121093 + pointer_set_destroy(visited->stmts);
121094 + pointer_set_destroy(visited->my_stmts);
121095 + pointer_set_destroy(visited->skip_expr_casts);
121096 + pointer_set_destroy(visited->no_cast_check);
121097 +
121098 + free(visited);
121099 +}
121100 +
121101 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
121102 + * it decides whether the duplication is necessary or not and it searches for missing size_overflow attributes. After expand() it changes the orig node to the duplicated node
121103 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
121104 + */
121105 +static struct next_cgraph_node *handle_interesting_stmt(struct visited *visited, struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
121106 +{
121107 + enum precond ret;
121108 + tree new_node, orig_node = cur_node->node;
121109 +
121110 + ret = check_preconditions(cur_node);
121111 + if (ret == NO_ATTRIBUTE_SEARCH)
121112 + return cnodes;
121113 +
121114 + cnodes = search_overflow_attribute(cnodes, cur_node);
121115 +
121116 + if (ret == NO_CHECK_INSERT)
121117 + return cnodes;
121118 +
121119 + new_node = expand(visited, caller_node, orig_node);
121120 + if (new_node == NULL_TREE)
121121 + return cnodes;
121122 +
121123 + change_orig_node(visited, cur_node, new_node);
121124 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
121125 +
121126 + return cnodes;
121127 +}
121128 +
121129 +// Check visited_fns interesting nodes.
121130 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
121131 +{
121132 + struct interesting_node *cur;
121133 +
121134 + for (cur = head; cur; cur = cur->next) {
121135 + if (!operand_equal_p(node, cur->node, 0))
121136 + continue;
121137 + if (num != cur->num)
121138 + continue;
121139 + if (first_stmt == cur->first_stmt)
121140 + return true;
121141 + }
121142 + return false;
121143 +}
121144 +
121145 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
121146 + first_stmt: it is the call or assignment or ret stmt, change_orig_node() will change the original node (retval, or function arg) in this
121147 + last_nodes: they are the last stmts in the recursion (they haven't a def_stmt). They are useful in the missing size_overflow attribute check and
121148 + the intentional_overflow attribute check. They are collected by set_last_nodes().
121149 + num: arg count of a call stmt or 0 when it is a ret
121150 + node: the recursion starts from here, it is a call arg or a return value
121151 + fndecl: the fndecl of the interesting node when the node is an arg. it is the fndecl of the callee function otherwise it is the fndecl of the caller (current_function_fndecl) function.
121152 + intentional_attr_decl: intentional_overflow attribute of the callee function
121153 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
121154 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
121155 + */
121156 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
121157 +{
121158 + struct interesting_node *new_node;
121159 + tree fndecl;
121160 + enum gimple_code code;
121161 +
121162 + gcc_assert(node != NULL_TREE);
121163 + code = gimple_code(first_stmt);
121164 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
121165 +
121166 + if (num == CANNOT_FIND_ARG)
121167 + return head;
121168 +
121169 + if (skip_types(node))
121170 + return head;
121171 +
121172 + if (skip_asm(node))
121173 + return head;
121174 +
121175 + if (is_gimple_call(first_stmt))
121176 + fndecl = gimple_call_fndecl(first_stmt);
121177 + else
121178 + fndecl = current_function_decl;
121179 +
121180 + if (fndecl == NULL_TREE)
121181 + return head;
121182 +
121183 + if (is_in_interesting_node(head, first_stmt, node, num))
121184 + return head;
121185 +
121186 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
121187 +
121188 + new_node->next = NULL;
121189 + new_node->first_stmt = first_stmt;
121190 +#if BUILDING_GCC_VERSION <= 4007
121191 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
121192 +#else
121193 + vec_alloc(new_node->last_nodes, VEC_LEN);
121194 +#endif
121195 + new_node->num = num;
121196 + new_node->node = node;
121197 + new_node->fndecl = fndecl;
121198 + new_node->intentional_attr_decl = MARK_NO;
121199 + new_node->intentional_attr_cur_fndecl = MARK_NO;
121200 + new_node->intentional_mark_from_gimple = asm_stmt;
121201 +
121202 + if (!head)
121203 + return new_node;
121204 +
121205 + new_node->next = head;
121206 + return new_node;
121207 +}
121208 +
121209 +/* Check the ret stmts in the functions on the next cgraph node list (these functions will be in the hash table and they are reachable from ipa).
121210 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
121211 + */
121212 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
121213 +{
121214 + struct next_cgraph_node *cur_node;
121215 + tree ret = gimple_return_retval(stmt);
121216 +
121217 + if (ret == NULL_TREE)
121218 + return head;
121219 +
121220 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
121221 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
121222 + continue;
121223 + if (cur_node->num == 0)
121224 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
121225 + }
121226 +
121227 + return head;
121228 +}
121229 +
121230 +/* Check the call stmts in the functions on the next cgraph node list (these functions will be in the hash table and they are reachable from ipa).
121231 + * If the call stmt is in the next cgraph node list then it's an interesting call.
121232 + */
121233 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
121234 +{
121235 + unsigned int argnum;
121236 + tree arg;
121237 + const_tree fndecl;
121238 + struct next_cgraph_node *cur_node;
121239 +
121240 + fndecl = gimple_call_fndecl(stmt);
121241 + if (fndecl == NULL_TREE)
121242 + return head;
121243 +
121244 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
121245 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
121246 + continue;
121247 + argnum = get_correct_arg_count(cur_node->num, fndecl);
121248 + gcc_assert(argnum != CANNOT_FIND_ARG);
121249 + if (argnum == 0)
121250 + continue;
121251 +
121252 + arg = gimple_call_arg(stmt, argnum - 1);
121253 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
121254 + }
121255 +
121256 + return head;
121257 +}
121258 +
121259 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
121260 +{
121261 + if (!operand_equal_p(orig_node, node, 0))
121262 + return WRONG_NODE;
121263 + if (skip_types(node))
121264 + return WRONG_NODE;
121265 + return ret_count;
121266 +}
121267 +
121268 +// Get the index of the rhs node in an assignment
121269 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
121270 +{
121271 + const_tree rhs1, rhs2;
121272 + unsigned int ret;
121273 +
121274 + gcc_assert(stmt);
121275 + gcc_assert(is_gimple_assign(stmt));
121276 +
121277 + rhs1 = gimple_assign_rhs1(stmt);
121278 + gcc_assert(rhs1 != NULL_TREE);
121279 +
121280 + switch (gimple_num_ops(stmt)) {
121281 + case 2:
121282 + return check_ops(node, rhs1, 1);
121283 + case 3:
121284 + ret = check_ops(node, rhs1, 1);
121285 + if (ret != WRONG_NODE)
121286 + return ret;
121287 +
121288 + rhs2 = gimple_assign_rhs2(stmt);
121289 + gcc_assert(rhs2 != NULL_TREE);
121290 + return check_ops(node, rhs2, 2);
121291 + default:
121292 + gcc_unreachable();
121293 + }
121294 +}
121295 +
121296 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
121297 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
121298 +{
121299 + unsigned int i;
121300 +
121301 + if (gimple_call_fndecl(stmt) == NULL_TREE)
121302 + return CANNOT_FIND_ARG;
121303 +
121304 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
121305 + tree node;
121306 +
121307 + node = gimple_call_arg(stmt, i);
121308 + if (!operand_equal_p(arg, node, 0))
121309 + continue;
121310 + if (!skip_types(node))
121311 + return i + 1;
121312 + }
121313 +
121314 + return CANNOT_FIND_ARG;
121315 +}
121316 +
121317 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
121318 + * any of return, call or assignment stmts (because of inlining).
121319 + */
121320 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
121321 +{
121322 + use_operand_p use_p;
121323 + imm_use_iterator imm_iter;
121324 + unsigned int argnum;
121325 +
121326 + gcc_assert(TREE_CODE(node) == SSA_NAME);
121327 +
121328 + if (pointer_set_insert(visited, node))
121329 + return head;
121330 +
121331 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
121332 + gimple stmt = USE_STMT(use_p);
121333 +
121334 + if (stmt == NULL)
121335 + return head;
121336 + if (is_gimple_debug(stmt))
121337 + continue;
121338 +
121339 + switch (gimple_code(stmt)) {
121340 + case GIMPLE_CALL:
121341 + argnum = find_arg_number_gimple(node, stmt);
121342 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
121343 + break;
121344 + case GIMPLE_RETURN:
121345 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
121346 + break;
121347 + case GIMPLE_ASSIGN:
121348 + argnum = get_assign_ops_count(stmt, node);
121349 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
121350 + break;
121351 + case GIMPLE_PHI: {
121352 + tree result = gimple_phi_result(stmt);
121353 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
121354 + break;
121355 + }
121356 + case GIMPLE_ASM:
121357 + if (gimple_asm_noutputs(stmt) != 0)
121358 + break;
121359 + if (!is_size_overflow_asm(stmt))
121360 + break;
121361 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
121362 + break;
121363 + case GIMPLE_COND:
121364 + case GIMPLE_SWITCH:
121365 + break;
121366 + default:
121367 + debug_gimple_stmt(stmt);
121368 + gcc_unreachable();
121369 + break;
121370 + }
121371 + }
121372 + return head;
121373 +}
121374 +
121375 +static void remove_size_overflow_asm(gimple stmt)
121376 +{
121377 + gimple_stmt_iterator gsi;
121378 + tree input, output;
121379 +
121380 + if (!is_size_overflow_asm(stmt))
121381 + return;
121382 +
121383 + if (gimple_asm_noutputs(stmt) == 0) {
121384 + gsi = gsi_for_stmt(stmt);
121385 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
121386 + gsi_remove(&gsi, true);
121387 + return;
121388 + }
121389 +
121390 + input = gimple_asm_input_op(stmt, 0);
121391 + output = gimple_asm_output_op(stmt, 0);
121392 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
121393 +}
121394 +
121395 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
121396 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
121397 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
121398 + */
121399 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
121400 +{
121401 + const_tree output;
121402 + struct pointer_set_t *visited;
121403 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
121404 +
121405 + if (!is_size_overflow_asm(stmt))
121406 + return head;
121407 +
121408 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
121409 + intentional_asm = stmt;
121410 +
121411 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
121412 +
121413 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
121414 + return head;
121415 +
121416 + if (gimple_asm_noutputs(stmt) == 0) {
121417 + const_tree input;
121418 +
121419 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
121420 + return head;
121421 +
121422 + input = gimple_asm_input_op(stmt, 0);
121423 + remove_size_overflow_asm(stmt);
121424 + if (is_gimple_constant(TREE_VALUE(input)))
121425 + return head;
121426 + visited = pointer_set_create();
121427 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
121428 + pointer_set_destroy(visited);
121429 + return head;
121430 + }
121431 +
121432 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
121433 + remove_size_overflow_asm(stmt);
121434 +
121435 + visited = pointer_set_create();
121436 + output = gimple_asm_output_op(stmt, 0);
121437 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
121438 + pointer_set_destroy(visited);
121439 + return head;
121440 +}
121441 +
121442 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
121443 + * or a call stmt or a return stmt and store them in the interesting_node list
121444 + */
121445 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
121446 +{
121447 + basic_block bb;
121448 + struct interesting_node *head = NULL;
121449 +
121450 + FOR_ALL_BB_FN(bb, cfun) {
121451 + gimple_stmt_iterator gsi;
121452 +
121453 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
121454 + enum gimple_code code;
121455 + gimple stmt = gsi_stmt(gsi);
121456 +
121457 + code = gimple_code(stmt);
121458 +
121459 + if (code == GIMPLE_ASM)
121460 + head = handle_stmt_by_size_overflow_asm(stmt, head);
121461 +
121462 + if (!next_node)
121463 + continue;
121464 + if (code == GIMPLE_CALL)
121465 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
121466 + if (code == GIMPLE_RETURN)
121467 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
121468 + }
121469 + }
121470 + return head;
121471 +}
121472 +
121473 +static void free_interesting_node(struct interesting_node *head)
121474 +{
121475 + struct interesting_node *cur;
121476 +
121477 + while (head) {
121478 + cur = head->next;
121479 +#if BUILDING_GCC_VERSION <= 4007
121480 + VEC_free(tree, gc, head->last_nodes);
121481 +#else
121482 + vec_free(head->last_nodes);
121483 +#endif
121484 + free(head);
121485 + head = cur;
121486 + }
121487 +}
121488 +
121489 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
121490 +{
121491 + struct visited_fns *new_visited_fns;
121492 +
121493 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
121494 + new_visited_fns->fndecl = cur_node->fndecl;
121495 + new_visited_fns->num = cur_node->num;
121496 + new_visited_fns->first_stmt = cur_node->first_stmt;
121497 + new_visited_fns->next = NULL;
121498 +
121499 + if (!head)
121500 + return new_visited_fns;
121501 +
121502 + new_visited_fns->next = head;
121503 + return new_visited_fns;
121504 +}
121505 +
121506 +/* Check whether the function was already visited_fns. If the fndecl, the arg count of the fndecl and the first_stmt (call or return) are same then
121507 + * it is a visited_fns function.
121508 + */
121509 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
121510 +{
121511 + struct visited_fns *cur;
121512 +
121513 + if (!head)
121514 + return false;
121515 +
121516 + for (cur = head; cur; cur = cur->next) {
121517 + if (cur_node->first_stmt != cur->first_stmt)
121518 + continue;
121519 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
121520 + continue;
121521 + if (cur_node->num == cur->num)
121522 + return true;
121523 + }
121524 + return false;
121525 +}
121526 +
121527 +static void free_next_cgraph_node(struct next_cgraph_node *head)
121528 +{
121529 + struct next_cgraph_node *cur;
121530 +
121531 + while (head) {
121532 + cur = head->next;
121533 + free(head);
121534 + head = cur;
121535 + }
121536 +}
121537 +
121538 +static void remove_all_size_overflow_asm(void)
121539 +{
121540 + basic_block bb;
121541 +
121542 + FOR_ALL_BB_FN(bb, cfun) {
121543 + gimple_stmt_iterator si;
121544 +
121545 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
121546 + remove_size_overflow_asm(gsi_stmt(si));
121547 + }
121548 +}
121549 +
121550 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
121551 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
121552 + * the newly collected interesting functions (they are interesting if there is control flow between
121553 + * the interesting stmts and them).
121554 + */
121555 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
121556 +{
121557 + struct visited *visited;
121558 + struct interesting_node *head, *cur_node;
121559 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
121560 +
121561 + set_current_function_decl(NODE_DECL(node));
121562 + call_count = 0;
121563 +
121564 + head = collect_interesting_stmts(next_node);
121565 +
121566 + visited = create_visited();
121567 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
121568 + if (is_visited_fns_function(visited_fns, cur_node))
121569 + continue;
121570 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
121571 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
121572 + }
121573 +
121574 + free_visited(visited);
121575 + free_interesting_node(head);
121576 + remove_all_size_overflow_asm();
121577 + unset_current_function_decl();
121578 +
121579 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
121580 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
121581 +
121582 + free_next_cgraph_node(cnodes_head);
121583 + return visited_fns;
121584 +}
121585 +
121586 +static void free_visited_fns(struct visited_fns *head)
121587 +{
121588 + struct visited_fns *cur;
121589 +
121590 + while (head) {
121591 + cur = head->next;
121592 + free(head);
121593 + head = cur;
121594 + }
121595 +}
121596 +
121597 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
121598 +unsigned int search_function(void)
121599 +{
121600 + struct cgraph_node *node;
121601 + struct visited_fns *visited_fns = NULL;
121602 +
121603 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
121604 + gcc_assert(cgraph_function_flags_ready);
121605 +#if BUILDING_GCC_VERSION <= 4007
121606 + gcc_assert(node->reachable);
121607 +#endif
121608 +
121609 + visited_fns = handle_function(node, NULL, visited_fns);
121610 + }
121611 +
121612 + free_visited_fns(visited_fns);
121613 + return 0;
121614 +}
121615 +
121616 +#if BUILDING_GCC_VERSION >= 4009
121617 +static const struct pass_data insert_size_overflow_check_data = {
121618 +#else
121619 +static struct ipa_opt_pass_d insert_size_overflow_check = {
121620 + .pass = {
121621 +#endif
121622 + .type = SIMPLE_IPA_PASS,
121623 + .name = "size_overflow",
121624 +#if BUILDING_GCC_VERSION >= 4008
121625 + .optinfo_flags = OPTGROUP_NONE,
121626 +#endif
121627 +#if BUILDING_GCC_VERSION >= 4009
121628 + .has_gate = false,
121629 + .has_execute = true,
121630 +#else
121631 + .gate = NULL,
121632 + .execute = search_function,
121633 + .sub = NULL,
121634 + .next = NULL,
121635 + .static_pass_number = 0,
121636 +#endif
121637 + .tv_id = TV_NONE,
121638 + .properties_required = 0,
121639 + .properties_provided = 0,
121640 + .properties_destroyed = 0,
121641 + .todo_flags_start = 0,
121642 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_remove_unused_locals | TODO_ggc_collect | TODO_verify_flow | TODO_dump_cgraph | TODO_dump_func | TODO_update_ssa_no_phi,
121643 +#if BUILDING_GCC_VERSION < 4009
121644 + },
121645 + .generate_summary = NULL,
121646 + .write_summary = NULL,
121647 + .read_summary = NULL,
121648 +#if BUILDING_GCC_VERSION >= 4006
121649 + .write_optimization_summary = NULL,
121650 + .read_optimization_summary = NULL,
121651 +#endif
121652 + .stmt_fixup = NULL,
121653 + .function_transform_todo_flags_start = 0,
121654 + .function_transform = NULL,
121655 + .variable_transform = NULL,
121656 +#endif
121657 +};
121658 +
121659 +#if BUILDING_GCC_VERSION >= 4009
121660 +namespace {
121661 +class insert_size_overflow_check : public ipa_opt_pass_d {
121662 +public:
121663 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
121664 + unsigned int execute() { return search_function(); }
121665 +};
121666 +}
121667 +#endif
121668 +
121669 +struct opt_pass *make_insert_size_overflow_check(void)
121670 +{
121671 +#if BUILDING_GCC_VERSION >= 4009
121672 + return new insert_size_overflow_check();
121673 +#else
121674 + return &insert_size_overflow_check.pass;
121675 +#endif
121676 +}
121677 +
121678 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
121679 new file mode 100644
121680 index 0000000..d71d72a
121681 --- /dev/null
121682 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
121683 @@ -0,0 +1,736 @@
121684 +/*
121685 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
121686 + * Licensed under the GPL v2, or (at your option) v3
121687 + *
121688 + * Homepage:
121689 + * http://www.grsecurity.net/~ephox/overflow_plugin/
121690 + *
121691 + * Documentation:
121692 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
121693 + *
121694 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
121695 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
121696 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
121697 + *
121698 + * Usage:
121699 + * $ make
121700 + * $ make run
121701 + */
121702 +
121703 +#include "gcc-common.h"
121704 +#include "size_overflow.h"
121705 +
121706 +/* Get the param of the intentional_overflow attribute.
121707 + * * 0: MARK_NOT_INTENTIONAL
121708 + * * 1..MAX_PARAM: MARK_YES
121709 + * * -1: MARK_TURN_OFF
121710 + */
121711 +static tree get_attribute_param(const_tree decl)
121712 +{
121713 + const_tree attr;
121714 +
121715 + if (decl == NULL_TREE)
121716 + return NULL_TREE;
121717 +
121718 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
121719 + if (!attr || !TREE_VALUE(attr))
121720 + return NULL_TREE;
121721 +
121722 + return TREE_VALUE(attr);
121723 +}
121724 +
121725 +// MARK_TURN_OFF
121726 +bool is_turn_off_intentional_attr(const_tree decl)
121727 +{
121728 + const_tree param_head;
121729 +
121730 + param_head = get_attribute_param(decl);
121731 + if (param_head == NULL_TREE)
121732 + return false;
121733 +
121734 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
121735 + return true;
121736 + return false;
121737 +}
121738 +
121739 +// MARK_NOT_INTENTIONAL
121740 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
121741 +{
121742 + const_tree param_head;
121743 +
121744 + if (argnum == 0)
121745 + return false;
121746 +
121747 + param_head = get_attribute_param(decl);
121748 + if (param_head == NULL_TREE)
121749 + return false;
121750 +
121751 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
121752 + return true;
121753 + return false;
121754 +}
121755 +
121756 +// MARK_YES
121757 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
121758 +{
121759 + tree param, param_head;
121760 +
121761 + if (argnum == 0)
121762 + return false;
121763 +
121764 + param_head = get_attribute_param(decl);
121765 + for (param = param_head; param; param = TREE_CHAIN(param))
121766 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
121767 + return true;
121768 + return false;
121769 +}
121770 +
121771 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
121772 +{
121773 + location_t loc;
121774 +
121775 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
121776 + return;
121777 +
121778 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
121779 + return;
121780 +
121781 + loc = DECL_SOURCE_LOCATION(decl);
121782 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
121783 +}
121784 +
121785 +// Get the field decl of a component ref for intentional_overflow checking
121786 +static const_tree search_field_decl(const_tree comp_ref)
121787 +{
121788 + const_tree field = NULL_TREE;
121789 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
121790 +
121791 + for (i = 0; i < len; i++) {
121792 + field = TREE_OPERAND(comp_ref, i);
121793 + if (TREE_CODE(field) == FIELD_DECL)
121794 + break;
121795 + }
121796 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
121797 + return field;
121798 +}
121799 +
121800 +/* Get the type of the intentional_overflow attribute of a node
121801 + * * MARK_TURN_OFF
121802 + * * MARK_YES
121803 + * * MARK_NO
121804 + * * MARK_NOT_INTENTIONAL
121805 + */
121806 +enum mark get_intentional_attr_type(const_tree node)
121807 +{
121808 + const_tree cur_decl;
121809 +
121810 + if (node == NULL_TREE)
121811 + return MARK_NO;
121812 +
121813 + switch (TREE_CODE(node)) {
121814 + case COMPONENT_REF:
121815 + cur_decl = search_field_decl(node);
121816 + if (is_turn_off_intentional_attr(cur_decl))
121817 + return MARK_TURN_OFF;
121818 + if (is_end_intentional_intentional_attr(cur_decl, 1))
121819 + return MARK_YES;
121820 + break;
121821 + case PARM_DECL: {
121822 + unsigned int argnum;
121823 +
121824 + cur_decl = DECL_ORIGIN(current_function_decl);
121825 + argnum = find_arg_number_tree(node, cur_decl);
121826 + if (argnum == CANNOT_FIND_ARG)
121827 + return MARK_NO;
121828 + if (is_yes_intentional_attr(cur_decl, argnum))
121829 + return MARK_YES;
121830 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
121831 + return MARK_NOT_INTENTIONAL;
121832 + break;
121833 + }
121834 + case FUNCTION_DECL:
121835 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
121836 + return MARK_TURN_OFF;
121837 + break;
121838 + default:
121839 + break;
121840 + }
121841 + return MARK_NO;
121842 +}
121843 +
121844 +// Search for the intentional_overflow attribute on the last nodes
121845 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
121846 +{
121847 + unsigned int i;
121848 + tree last_node;
121849 + enum mark mark = MARK_NO;
121850 +
121851 +#if BUILDING_GCC_VERSION <= 4007
121852 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
121853 +#else
121854 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
121855 +#endif
121856 + mark = get_intentional_attr_type(last_node);
121857 + if (mark != MARK_NO)
121858 + break;
121859 + }
121860 + return mark;
121861 +}
121862 +
121863 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
121864 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
121865 + */
121866 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
121867 +{
121868 + if (!cur_node->intentional_mark_from_gimple)
121869 + return false;
121870 +
121871 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
121872 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
121873 + else
121874 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
121875 +
121876 + // skip param decls
121877 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
121878 + return true;
121879 + return true;
121880 +}
121881 +
121882 +/* Search intentional_overflow attribute on caller and on callee too.
121883 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
121884 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
121885 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
121886 +*/
121887 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
121888 +{
121889 + const_tree fndecl;
121890 +
121891 + if (is_intentional_attribute_from_gimple(cur_node))
121892 + return;
121893 +
121894 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
121895 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
121896 + return;
121897 + }
121898 +
121899 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
121900 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
121901 + return;
121902 + }
121903 +
121904 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
121905 + return;
121906 +
121907 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
121908 + if (is_turn_off_intentional_attr(fndecl)) {
121909 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
121910 + return;
121911 + }
121912 +
121913 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
121914 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
121915 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
121916 + cur_node->intentional_attr_decl = MARK_YES;
121917 +
121918 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
121919 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
121920 +}
121921 +
121922 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
121923 +{
121924 + const_tree rhs1, lhs, rhs1_type, lhs_type;
121925 + enum machine_mode lhs_mode, rhs_mode;
121926 + gimple def_stmt = get_def_stmt(no_const_rhs);
121927 +
121928 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
121929 + return false;
121930 +
121931 + rhs1 = gimple_assign_rhs1(def_stmt);
121932 + lhs = gimple_assign_lhs(def_stmt);
121933 + rhs1_type = TREE_TYPE(rhs1);
121934 + lhs_type = TREE_TYPE(lhs);
121935 + rhs_mode = TYPE_MODE(rhs1_type);
121936 + lhs_mode = TYPE_MODE(lhs_type);
121937 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
121938 + return false;
121939 +
121940 + return true;
121941 +}
121942 +
121943 +static unsigned int uses_num(tree node)
121944 +{
121945 + imm_use_iterator imm_iter;
121946 + use_operand_p use_p;
121947 + unsigned int num = 0;
121948 +
121949 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
121950 + gimple use_stmt = USE_STMT(use_p);
121951 +
121952 + if (use_stmt == NULL)
121953 + return num;
121954 + if (is_gimple_debug(use_stmt))
121955 + continue;
121956 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
121957 + continue;
121958 + num++;
121959 + }
121960 + return num;
121961 +}
121962 +
121963 +static bool no_uses(tree node)
121964 +{
121965 + return !uses_num(node);
121966 +}
121967 +
121968 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
121969 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
121970 +{
121971 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
121972 + gimple def_stmt = get_def_stmt(lhs);
121973 +
121974 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
121975 + return false;
121976 +
121977 + rhs1 = gimple_assign_rhs1(def_stmt);
121978 + rhs_type = TREE_TYPE(rhs1);
121979 + lhs_type = TREE_TYPE(lhs);
121980 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
121981 + return false;
121982 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
121983 + return false;
121984 +
121985 + def_stmt = get_def_stmt(rhs1);
121986 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
121987 + return false;
121988 +
121989 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
121990 + return false;
121991 +
121992 + rhs1 = gimple_assign_rhs1(def_stmt);
121993 + rhs2 = gimple_assign_rhs2(def_stmt);
121994 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
121995 + return false;
121996 +
121997 + if (is_gimple_constant(rhs2))
121998 + not_const_rhs = rhs1;
121999 + else
122000 + not_const_rhs = rhs2;
122001 +
122002 + return no_uses(not_const_rhs);
122003 +}
122004 +
122005 +static bool is_lt_signed_type_max(const_tree rhs)
122006 +{
122007 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
122008 +
122009 + if (!TYPE_UNSIGNED(type))
122010 + return true;
122011 +
122012 + switch (TYPE_MODE(type)) {
122013 + case QImode:
122014 + new_type = intQI_type_node;
122015 + break;
122016 + case HImode:
122017 + new_type = intHI_type_node;
122018 + break;
122019 + case SImode:
122020 + new_type = intSI_type_node;
122021 + break;
122022 + case DImode:
122023 + new_type = intDI_type_node;
122024 + break;
122025 + default:
122026 + debug_tree((tree)type);
122027 + gcc_unreachable();
122028 + }
122029 +
122030 + type_max = TYPE_MAX_VALUE(new_type);
122031 + if (!tree_int_cst_lt(type_max, rhs))
122032 + return true;
122033 +
122034 + return false;
122035 +}
122036 +
122037 +static bool is_gt_zero(const_tree rhs)
122038 +{
122039 + const_tree type = TREE_TYPE(rhs);
122040 +
122041 + if (TYPE_UNSIGNED(type))
122042 + return true;
122043 +
122044 + if (!tree_int_cst_lt(rhs, integer_zero_node))
122045 + return true;
122046 +
122047 + return false;
122048 +}
122049 +
122050 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
122051 +{
122052 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
122053 + return false;
122054 + if (!is_gimple_constant(rhs))
122055 + return false;
122056 +
122057 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
122058 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
122059 + return false;
122060 +
122061 + return true;
122062 +}
122063 +
122064 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
122065 +{
122066 + gimple assign;
122067 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
122068 + tree origtype = TREE_TYPE(orig_rhs);
122069 +
122070 + gcc_assert(is_gimple_assign(stmt));
122071 +
122072 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
122073 + pointer_set_insert(visited->my_stmts, assign);
122074 + return gimple_assign_lhs(assign);
122075 +}
122076 +
122077 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
122078 +{
122079 + tree new_rhs, orig_rhs;
122080 + void (*gimple_assign_set_rhs)(gimple, tree);
122081 + tree rhs1 = gimple_assign_rhs1(stmt);
122082 + tree rhs2 = gimple_assign_rhs2(stmt);
122083 + tree lhs = gimple_assign_lhs(stmt);
122084 +
122085 + if (!check_overflow)
122086 + return create_assign(visited, stmt, lhs, AFTER_STMT);
122087 +
122088 + if (change_rhs == NULL_TREE)
122089 + return create_assign(visited, stmt, lhs, AFTER_STMT);
122090 +
122091 + if (new_rhs2 == NULL_TREE) {
122092 + orig_rhs = rhs1;
122093 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
122094 + } else {
122095 + orig_rhs = rhs2;
122096 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
122097 + }
122098 +
122099 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
122100 +
122101 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
122102 + gimple_assign_set_rhs(stmt, new_rhs);
122103 + update_stmt(stmt);
122104 +
122105 + return create_assign(visited, stmt, lhs, AFTER_STMT);
122106 +}
122107 +
122108 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
122109 +{
122110 + gimple rhs1_def_stmt, rhs2_def_stmt;
122111 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
122112 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
122113 + const_tree rhs1 = gimple_assign_rhs1(stmt);
122114 + const_tree rhs2 = gimple_assign_rhs2(stmt);
122115 +
122116 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
122117 + return false;
122118 +
122119 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
122120 +
122121 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
122122 + return false;
122123 +
122124 + rhs1_def_stmt = get_def_stmt(rhs1);
122125 + rhs2_def_stmt = get_def_stmt(rhs2);
122126 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
122127 + return false;
122128 +
122129 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
122130 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
122131 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
122132 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
122133 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
122134 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
122135 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
122136 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
122137 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
122138 + return false;
122139 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
122140 + return false;
122141 +
122142 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
122143 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
122144 + return true;
122145 +}
122146 +
122147 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
122148 +{
122149 + gimple assign;
122150 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
122151 + tree type = TREE_TYPE(rhs1);
122152 + tree lhs = create_new_var(type);
122153 +
122154 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
122155 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
122156 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
122157 +
122158 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
122159 + update_stmt(assign);
122160 + pointer_set_insert(visited->my_stmts, assign);
122161 + return assign;
122162 +}
122163 +
122164 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
122165 +{
122166 + gimple_stmt_iterator gsi;
122167 + gimple cast_stmt;
122168 + tree type = TREE_TYPE(node);
122169 +
122170 + if (types_compatible_p(type, intTI_type_node))
122171 + return node;
122172 +
122173 + gsi = gsi_for_stmt(stmt);
122174 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
122175 + pointer_set_insert(visited->my_stmts, cast_stmt);
122176 + return gimple_assign_lhs(cast_stmt);
122177 +}
122178 +
122179 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
122180 +{
122181 + tree rhs1, def_stmt_rhs1;
122182 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
122183 +
122184 + def_stmt = get_def_stmt(var);
122185 + if (!gimple_assign_cast_p(def_stmt))
122186 + return NULL_TREE;
122187 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
122188 +
122189 + rhs1 = gimple_assign_rhs1(def_stmt);
122190 + rhs1_def_stmt = get_def_stmt(rhs1);
122191 + if (!gimple_assign_cast_p(rhs1_def_stmt))
122192 + return rhs1;
122193 +
122194 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
122195 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
122196 +
122197 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
122198 + case GIMPLE_CALL:
122199 + case GIMPLE_NOP:
122200 + case GIMPLE_ASM:
122201 + case GIMPLE_PHI:
122202 + return def_stmt_rhs1;
122203 + case GIMPLE_ASSIGN:
122204 + return rhs1;
122205 + default:
122206 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
122207 + gcc_unreachable();
122208 + }
122209 +}
122210 +
122211 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
122212 +{
122213 + tree new_rhs1, new_rhs2;
122214 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
122215 + gimple assign, stmt = get_def_stmt(lhs);
122216 + tree rhs1 = gimple_assign_rhs1(stmt);
122217 + tree rhs2 = gimple_assign_rhs2(stmt);
122218 +
122219 + if (!is_subtraction_special(visited, stmt))
122220 + return NULL_TREE;
122221 +
122222 + new_rhs1 = expand(visited, caller_node, rhs1);
122223 + new_rhs2 = expand(visited, caller_node, rhs2);
122224 +
122225 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
122226 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
122227 +
122228 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
122229 + return NULL_TREE;
122230 +
122231 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
122232 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
122233 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
122234 + }
122235 +
122236 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
122237 + new_lhs = gimple_assign_lhs(assign);
122238 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
122239 +
122240 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
122241 +}
122242 +
122243 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
122244 +{
122245 + const_gimple def_stmt;
122246 +
122247 + if (TREE_CODE(rhs) != SSA_NAME)
122248 + return false;
122249 +
122250 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
122251 + return false;
122252 +
122253 + def_stmt = get_def_stmt(rhs);
122254 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
122255 + return false;
122256 +
122257 + return true;
122258 +}
122259 +
122260 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
122261 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
122262 + * fffffff * 16 > signed max -> truncate
122263 + */
122264 +static bool look_for_mult_and_add(const_gimple stmt)
122265 +{
122266 + const_tree res;
122267 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
122268 + const_gimple def_stmt;
122269 +
122270 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
122271 + return false;
122272 + if (!is_gimple_assign(stmt))
122273 + return false;
122274 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
122275 + return false;
122276 +
122277 + rhs1 = gimple_assign_rhs1(stmt);
122278 + rhs2 = gimple_assign_rhs2(stmt);
122279 + if (is_gimple_constant(rhs1)) {
122280 + const_rhs = rhs1;
122281 + def_stmt = get_def_stmt(rhs2);
122282 + } else if (is_gimple_constant(rhs2)) {
122283 + const_rhs = rhs2;
122284 + def_stmt = get_def_stmt(rhs1);
122285 + } else
122286 + return false;
122287 +
122288 + if (!is_gimple_assign(def_stmt))
122289 + return false;
122290 +
122291 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
122292 + return false;
122293 +
122294 + def_rhs1 = gimple_assign_rhs1(def_stmt);
122295 + def_rhs2 = gimple_assign_rhs2(def_stmt);
122296 + if (is_gimple_constant(def_rhs1))
122297 + def_const_rhs = def_rhs1;
122298 + else if (is_gimple_constant(def_rhs2))
122299 + def_const_rhs = def_rhs2;
122300 + else
122301 + return false;
122302 +
122303 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
122304 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
122305 + return false;
122306 + return true;
122307 +}
122308 +
122309 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
122310 +{
122311 + const_gimple def_stmt_1, def_stmt_2;
122312 + const_tree rhs1, rhs2;
122313 + bool add_mul_rhs1, add_mul_rhs2;
122314 +
122315 + rhs1 = gimple_assign_rhs1(stmt);
122316 + def_stmt_1 = get_def_stmt(rhs1);
122317 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
122318 +
122319 + rhs2 = gimple_assign_rhs2(stmt);
122320 + def_stmt_2 = get_def_stmt(rhs2);
122321 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
122322 +
122323 + if (add_mul_rhs1)
122324 + return RHS1_INTENTIONAL_OVERFLOW;
122325 + if (add_mul_rhs2)
122326 + return RHS2_INTENTIONAL_OVERFLOW;
122327 + return NO_INTENTIONAL_OVERFLOW;
122328 +}
122329 +
122330 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
122331 +{
122332 + gimple my_stmt;
122333 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
122334 +
122335 + gsi_next(&gsi);
122336 + my_stmt = gsi_stmt(gsi);
122337 +
122338 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
122339 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
122340 +
122341 + return my_stmt;
122342 +}
122343 +
122344 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
122345 + * unsigned type cast to signed type, unsigned type: no more uses
122346 + * e.g., lib/vsprintf.c:simple_strtol()
122347 + * _10 = (unsigned long int) _9
122348 + * _11 = -_10;
122349 + * _12 = (long int) _11; (_11_ no more uses)
122350 + */
122351 +static bool is_call_or_cast(gimple stmt)
122352 +{
122353 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
122354 +}
122355 +
122356 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
122357 +{
122358 + const_tree rhs;
122359 + gimple def_stmt;
122360 +
122361 + if (node == NULL_TREE)
122362 + return true;
122363 + if (is_gimple_constant(node))
122364 + return true;
122365 +
122366 + def_stmt = get_def_stmt(node);
122367 + if (!def_stmt)
122368 + return false;
122369 +
122370 + if (is_call_or_cast(def_stmt))
122371 + return true;
122372 +
122373 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
122374 + return false;
122375 + rhs = gimple_assign_rhs1(def_stmt);
122376 + def_stmt = get_def_stmt(rhs);
122377 + if (!def_stmt)
122378 + return false;
122379 + return is_call_or_cast(def_stmt);
122380 +}
122381 +
122382 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
122383 +{
122384 + unsigned int use_num;
122385 + gimple so_stmt;
122386 + const_gimple def_stmt;
122387 + const_tree rhs1, rhs2;
122388 + tree rhs = gimple_assign_rhs1(stmt);
122389 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
122390 + const_tree rhs_type = TREE_TYPE(rhs);
122391 +
122392 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
122393 + return;
122394 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
122395 + return;
122396 + use_num = uses_num(rhs);
122397 + if (use_num != 1)
122398 + return;
122399 +
122400 + def_stmt = get_def_stmt(rhs);
122401 + if (!def_stmt)
122402 + return;
122403 + if (!is_gimple_assign(def_stmt))
122404 + return;
122405 +
122406 + rhs1 = gimple_assign_rhs1(def_stmt);
122407 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
122408 + return;
122409 +
122410 + rhs2 = gimple_assign_rhs2(def_stmt);
122411 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
122412 + return;
122413 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
122414 + return;
122415 +
122416 + so_stmt = get_dup_stmt(visited, stmt);
122417 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
122418 +}
122419 +
122420 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
122421 new file mode 100644
122422 index 0000000..4bddad2
122423 --- /dev/null
122424 +++ b/tools/gcc/size_overflow_plugin/misc.c
122425 @@ -0,0 +1,203 @@
122426 +/*
122427 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
122428 + * Licensed under the GPL v2, or (at your option) v3
122429 + *
122430 + * Homepage:
122431 + * http://www.grsecurity.net/~ephox/overflow_plugin/
122432 + *
122433 + * Documentation:
122434 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
122435 + *
122436 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
122437 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
122438 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
122439 + *
122440 + * Usage:
122441 + * $ make
122442 + * $ make run
122443 + */
122444 +
122445 +#include "gcc-common.h"
122446 +#include "size_overflow.h"
122447 +
122448 +void set_current_function_decl(tree fndecl)
122449 +{
122450 + gcc_assert(fndecl != NULL_TREE);
122451 +
122452 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
122453 + calculate_dominance_info(CDI_DOMINATORS);
122454 + current_function_decl = fndecl;
122455 +}
122456 +
122457 +void unset_current_function_decl(void)
122458 +{
122459 + free_dominance_info(CDI_DOMINATORS);
122460 + pop_cfun();
122461 + current_function_decl = NULL_TREE;
122462 +}
122463 +
122464 +static bool is_bool(const_tree node)
122465 +{
122466 + const_tree type;
122467 +
122468 + if (node == NULL_TREE)
122469 + return false;
122470 +
122471 + type = TREE_TYPE(node);
122472 + if (!INTEGRAL_TYPE_P(type))
122473 + return false;
122474 + if (TREE_CODE(type) == BOOLEAN_TYPE)
122475 + return true;
122476 + if (TYPE_PRECISION(type) == 1)
122477 + return true;
122478 + return false;
122479 +}
122480 +
122481 +bool skip_types(const_tree var)
122482 +{
122483 + tree type;
122484 + enum tree_code code;
122485 +
122486 + if (is_gimple_constant(var))
122487 + return true;
122488 +
122489 + switch (TREE_CODE(var)) {
122490 + case ADDR_EXPR:
122491 +#if BUILDING_GCC_VERSION >= 4006
122492 + case MEM_REF:
122493 +#endif
122494 + case ARRAY_REF:
122495 + case BIT_FIELD_REF:
122496 + case INDIRECT_REF:
122497 + case TARGET_MEM_REF:
122498 + case COMPONENT_REF:
122499 + case VAR_DECL:
122500 + case VIEW_CONVERT_EXPR:
122501 + return true;
122502 + default:
122503 + break;
122504 + }
122505 +
122506 + code = TREE_CODE(var);
122507 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
122508 +
122509 + type = TREE_TYPE(var);
122510 + switch (TREE_CODE(type)) {
122511 + case INTEGER_TYPE:
122512 + case ENUMERAL_TYPE:
122513 + return false;
122514 + case BOOLEAN_TYPE:
122515 + return is_bool(var);
122516 + default:
122517 + return true;
122518 + }
122519 +}
122520 +
122521 +gimple get_def_stmt(const_tree node)
122522 +{
122523 + gcc_assert(node != NULL_TREE);
122524 +
122525 + if (skip_types(node))
122526 + return NULL;
122527 +
122528 + if (TREE_CODE(node) != SSA_NAME)
122529 + return NULL;
122530 + return SSA_NAME_DEF_STMT(node);
122531 +}
122532 +
122533 +tree create_new_var(tree type)
122534 +{
122535 + tree new_var = create_tmp_var(type, "cicus");
122536 +
122537 + add_referenced_var(new_var);
122538 + return new_var;
122539 +}
122540 +
122541 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
122542 +{
122543 + const_gimple def_stmt = get_def_stmt(rhs);
122544 +
122545 + if (force)
122546 + return false;
122547 +
122548 + if (is_gimple_constant(rhs))
122549 + return false;
122550 +
122551 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
122552 + return false;
122553 +
122554 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
122555 + return false;
122556 +
122557 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
122558 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
122559 + return false;
122560 +
122561 + return true;
122562 +}
122563 +
122564 +tree cast_a_tree(tree type, tree var)
122565 +{
122566 + gcc_assert(type != NULL_TREE);
122567 + gcc_assert(var != NULL_TREE);
122568 + gcc_assert(fold_convertible_p(type, var));
122569 +
122570 + return fold_convert(type, var);
122571 +}
122572 +
122573 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
122574 +{
122575 + gimple assign, def_stmt;
122576 +
122577 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
122578 + gcc_assert(!is_gimple_constant(rhs));
122579 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
122580 + gcc_unreachable();
122581 +
122582 + def_stmt = get_def_stmt(rhs);
122583 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
122584 + return def_stmt;
122585 +
122586 + if (lhs == CREATE_NEW_VAR)
122587 + lhs = create_new_var(dst_type);
122588 +
122589 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
122590 +
122591 + if (!gsi_end_p(*gsi)) {
122592 + location_t loc = gimple_location(gsi_stmt(*gsi));
122593 + gimple_set_location(assign, loc);
122594 + }
122595 +
122596 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
122597 +
122598 + if (before)
122599 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
122600 + else
122601 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
122602 + update_stmt(assign);
122603 + return assign;
122604 +}
122605 +
122606 +bool is_size_overflow_type(const_tree var)
122607 +{
122608 + const char *name;
122609 + const_tree type_name, type;
122610 +
122611 + if (var == NULL_TREE)
122612 + return false;
122613 +
122614 + type = TREE_TYPE(var);
122615 + type_name = TYPE_NAME(type);
122616 + if (type_name == NULL_TREE)
122617 + return false;
122618 +
122619 + if (DECL_P(type_name))
122620 + name = DECL_NAME_POINTER(type_name);
122621 + else
122622 + name = IDENTIFIER_POINTER(type_name);
122623 +
122624 + if (!strncmp(name, "size_overflow_type", 18))
122625 + return true;
122626 + return false;
122627 +}
122628 +
122629 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
122630 new file mode 100644
122631 index 0000000..7c9e6d1
122632 --- /dev/null
122633 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
122634 @@ -0,0 +1,138 @@
122635 +/*
122636 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
122637 + * Licensed under the GPL v2, or (at your option) v3
122638 + *
122639 + * Homepage:
122640 + * http://www.grsecurity.net/~ephox/overflow_plugin/
122641 + *
122642 + * Documentation:
122643 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
122644 + *
122645 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
122646 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
122647 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
122648 + *
122649 + * Usage:
122650 + * $ make
122651 + * $ make run
122652 + */
122653 +
122654 +#include "gcc-common.h"
122655 +#include "size_overflow.h"
122656 +
122657 +bool skip_expr_on_double_type(const_gimple stmt)
122658 +{
122659 + enum tree_code code = gimple_assign_rhs_code(stmt);
122660 +
122661 + switch (code) {
122662 + case RSHIFT_EXPR:
122663 + case TRUNC_DIV_EXPR:
122664 + case CEIL_DIV_EXPR:
122665 + case FLOOR_DIV_EXPR:
122666 + case ROUND_DIV_EXPR:
122667 + case EXACT_DIV_EXPR:
122668 + case RDIV_EXPR:
122669 + case TRUNC_MOD_EXPR:
122670 + case CEIL_MOD_EXPR:
122671 + case FLOOR_MOD_EXPR:
122672 + case ROUND_MOD_EXPR:
122673 + return true;
122674 + default:
122675 + return false;
122676 + }
122677 +}
122678 +
122679 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
122680 +{
122681 + const_tree orig_rhs1;
122682 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
122683 + gimple down_cast, up_cast;
122684 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
122685 +
122686 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
122687 + down_lhs = gimple_assign_lhs(down_cast);
122688 +
122689 + gsi = gsi_for_stmt(use_stmt);
122690 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
122691 + new_lhs = gimple_assign_lhs(up_cast);
122692 +
122693 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
122694 + if (operand_equal_p(orig_rhs1, rhs, 0))
122695 + gimple_assign_set_rhs1(use_stmt, new_lhs);
122696 + else
122697 + gimple_assign_set_rhs2(use_stmt, new_lhs);
122698 + update_stmt(use_stmt);
122699 +
122700 + pointer_set_insert(visited->my_stmts, up_cast);
122701 + pointer_set_insert(visited->my_stmts, down_cast);
122702 + pointer_set_insert(visited->skip_expr_casts, up_cast);
122703 + pointer_set_insert(visited->skip_expr_casts, down_cast);
122704 +}
122705 +
122706 +static tree get_proper_unsigned_half_type(const_tree node)
122707 +{
122708 + tree new_type, type;
122709 +
122710 + gcc_assert(is_size_overflow_type(node));
122711 +
122712 + type = TREE_TYPE(node);
122713 + switch (TYPE_MODE(type)) {
122714 + case HImode:
122715 + new_type = unsigned_intQI_type_node;
122716 + break;
122717 + case SImode:
122718 + new_type = unsigned_intHI_type_node;
122719 + break;
122720 + case DImode:
122721 + new_type = unsigned_intSI_type_node;
122722 + break;
122723 + case TImode:
122724 + new_type = unsigned_intDI_type_node;
122725 + break;
122726 + default:
122727 + gcc_unreachable();
122728 + }
122729 +
122730 + if (TYPE_QUALS(type) != 0)
122731 + return build_qualified_type(new_type, TYPE_QUALS(type));
122732 + return new_type;
122733 +}
122734 +
122735 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
122736 +{
122737 + tree type;
122738 +
122739 + if (rhs == NULL_TREE)
122740 + return;
122741 + if (!is_size_overflow_type(rhs))
122742 + return;
122743 +
122744 + type = get_proper_unsigned_half_type(rhs);
122745 + if (is_gimple_constant(rhs))
122746 + return;
122747 + create_up_and_down_cast(visited, stmt, type, rhs);
122748 +}
122749 +
122750 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
122751 +{
122752 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
122753 + return;
122754 + gcc_assert(is_size_overflow_type(rhs));
122755 + insert_cast_rhs(visited, stmt, rhs);
122756 +}
122757 +
122758 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
122759 +{
122760 + tree rhs1, rhs2;
122761 +
122762 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
122763 + rhs1 = gimple_assign_rhs1(stmt);
122764 + insert_cast(visited, stmt, rhs1);
122765 + }
122766 +
122767 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
122768 + rhs2 = gimple_assign_rhs2(stmt);
122769 + insert_cast(visited, stmt, rhs2);
122770 + }
122771 +}
122772 +
122773 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
122774 new file mode 100644
122775 index 0000000..e5b4e50
122776 --- /dev/null
122777 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
122778 @@ -0,0 +1,127 @@
122779 +#ifndef SIZE_OVERFLOW_H
122780 +#define SIZE_OVERFLOW_H
122781 +
122782 +#define CREATE_NEW_VAR NULL_TREE
122783 +#define CANNOT_FIND_ARG 32
122784 +#define MAX_PARAM 31
122785 +#define BEFORE_STMT true
122786 +#define AFTER_STMT false
122787 +
122788 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
122789 +#define YES_ASM_STR "# size_overflow MARK_YES "
122790 +#define OK_ASM_STR "# size_overflow "
122791 +
122792 +enum mark {
122793 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
122794 +};
122795 +
122796 +enum intentional_overflow_type {
122797 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
122798 +};
122799 +
122800 +struct visited {
122801 + struct pointer_set_t *stmts;
122802 + struct pointer_set_t *my_stmts;
122803 + struct pointer_set_t *skip_expr_casts;
122804 + struct pointer_set_t *no_cast_check;
122805 +};
122806 +
122807 +// size_overflow_plugin.c
122808 +extern tree report_size_overflow_decl;
122809 +extern tree size_overflow_type_HI;
122810 +extern tree size_overflow_type_SI;
122811 +extern tree size_overflow_type_DI;
122812 +extern tree size_overflow_type_TI;
122813 +
122814 +
122815 +// size_overflow_plugin_hash.c
122816 +struct size_overflow_hash {
122817 + const struct size_overflow_hash * const next;
122818 + const char * const name;
122819 + const unsigned int param;
122820 +};
122821 +
122822 +struct interesting_node {
122823 + struct interesting_node *next;
122824 + gimple first_stmt;
122825 + const_tree fndecl;
122826 + tree node;
122827 +#if BUILDING_GCC_VERSION <= 4007
122828 + VEC(tree, gc) *last_nodes;
122829 +#else
122830 + vec<tree, va_gc> *last_nodes;
122831 +#endif
122832 + unsigned int num;
122833 + enum mark intentional_attr_decl;
122834 + enum mark intentional_attr_cur_fndecl;
122835 + gimple intentional_mark_from_gimple;
122836 +};
122837 +
122838 +extern bool is_size_overflow_asm(const_gimple stmt);
122839 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
122840 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
122841 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
122842 +extern bool is_a_return_check(const_tree node);
122843 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
122844 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
122845 +
122846 +
122847 +// size_overflow_debug.c
122848 +extern struct opt_pass *make_dump_pass(void);
122849 +
122850 +
122851 +// intentional_overflow.c
122852 +extern enum mark get_intentional_attr_type(const_tree node);
122853 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
122854 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
122855 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
122856 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
122857 +extern bool is_turn_off_intentional_attr(const_tree decl);
122858 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
122859 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
122860 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
122861 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
122862 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
122863 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
122864 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
122865 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
122866 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
122867 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
122868 +
122869 +
122870 +// insert_size_overflow_check_ipa.c
122871 +extern unsigned int search_function(void);
122872 +extern unsigned int call_count;
122873 +extern struct opt_pass *make_insert_size_overflow_check(void);
122874 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
122875 +
122876 +
122877 +// insert_size_overflow_asm.c
122878 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
122879 +
122880 +
122881 +// misc.c
122882 +extern void set_current_function_decl(tree fndecl);
122883 +extern void unset_current_function_decl(void);
122884 +extern gimple get_def_stmt(const_tree node);
122885 +extern tree create_new_var(tree type);
122886 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
122887 +extern bool skip_types(const_tree var);
122888 +extern tree cast_a_tree(tree type, tree var);
122889 +extern bool is_size_overflow_type(const_tree var);
122890 +
122891 +
122892 +// insert_size_overflow_check_core.c
122893 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
122894 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
122895 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
122896 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
122897 +
122898 +
122899 +// remove_unnecessary_dup.c
122900 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
122901 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
122902 +extern bool skip_expr_on_double_type(const_gimple stmt);
122903 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
122904 +
122905 +#endif
122906 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
122907 new file mode 100644
122908 index 0000000..4378111
122909 --- /dev/null
122910 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
122911 @@ -0,0 +1,116 @@
122912 +/*
122913 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
122914 + * Licensed under the GPL v2, or (at your option) v3
122915 + *
122916 + * Homepage:
122917 + * http://www.grsecurity.net/~ephox/overflow_plugin/
122918 + *
122919 + * Documentation:
122920 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
122921 + *
122922 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
122923 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
122924 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
122925 + *
122926 + * Usage:
122927 + * $ make
122928 + * $ make run
122929 + */
122930 +
122931 +#include "gcc-common.h"
122932 +
122933 +static unsigned int dump_functions(void)
122934 +{
122935 + struct cgraph_node *node;
122936 +
122937 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
122938 + basic_block bb;
122939 +
122940 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
122941 + current_function_decl = NODE_DECL(node);
122942 +
122943 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
122944 +
122945 + FOR_ALL_BB_FN(bb, cfun) {
122946 + gimple_stmt_iterator si;
122947 +
122948 + fprintf(stderr, "<bb %u>:\n", bb->index);
122949 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
122950 + debug_gimple_stmt(gsi_stmt(si));
122951 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
122952 + debug_gimple_stmt(gsi_stmt(si));
122953 + fprintf(stderr, "\n");
122954 + }
122955 +
122956 + fprintf(stderr, "-------------------------------------------------------------------------\n");
122957 +
122958 + pop_cfun();
122959 + current_function_decl = NULL_TREE;
122960 + }
122961 +
122962 + fprintf(stderr, "###############################################################################\n");
122963 +
122964 + return 0;
122965 +}
122966 +
122967 +#if BUILDING_GCC_VERSION >= 4009
122968 +static const struct pass_data dump_pass_data = {
122969 +#else
122970 +static struct ipa_opt_pass_d dump_pass = {
122971 + .pass = {
122972 +#endif
122973 + .type = SIMPLE_IPA_PASS,
122974 + .name = "dump",
122975 +#if BUILDING_GCC_VERSION >= 4008
122976 + .optinfo_flags = OPTGROUP_NONE,
122977 +#endif
122978 +#if BUILDING_GCC_VERSION >= 4009
122979 + .has_gate = false,
122980 + .has_execute = true,
122981 +#else
122982 + .gate = NULL,
122983 + .execute = dump_functions,
122984 + .sub = NULL,
122985 + .next = NULL,
122986 + .static_pass_number = 0,
122987 +#endif
122988 + .tv_id = TV_NONE,
122989 + .properties_required = 0,
122990 + .properties_provided = 0,
122991 + .properties_destroyed = 0,
122992 + .todo_flags_start = 0,
122993 + .todo_flags_finish = 0,
122994 +#if BUILDING_GCC_VERSION < 4009
122995 + },
122996 + .generate_summary = NULL,
122997 + .write_summary = NULL,
122998 + .read_summary = NULL,
122999 +#if BUILDING_GCC_VERSION >= 4006
123000 + .write_optimization_summary = NULL,
123001 + .read_optimization_summary = NULL,
123002 +#endif
123003 + .stmt_fixup = NULL,
123004 + .function_transform_todo_flags_start = 0,
123005 + .function_transform = NULL,
123006 + .variable_transform = NULL,
123007 +#endif
123008 +};
123009 +
123010 +#if BUILDING_GCC_VERSION >= 4009
123011 +namespace {
123012 +class dump_pass : public ipa_opt_pass_d {
123013 +public:
123014 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
123015 + unsigned int execute() { return dump_functions(); }
123016 +};
123017 +}
123018 +#endif
123019 +
123020 +struct opt_pass *make_dump_pass(void)
123021 +{
123022 +#if BUILDING_GCC_VERSION >= 4009
123023 + return new dump_pass();
123024 +#else
123025 + return &dump_pass.pass;
123026 +#endif
123027 +}
123028 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
123029 new file mode 100644
123030 index 0000000..37dbdb1
123031 --- /dev/null
123032 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
123033 @@ -0,0 +1,5511 @@
123034 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
123035 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
123036 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
123037 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
123038 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
123039 +padzero_55 padzero 1 55 &sel_read_policyvers_55
123040 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
123041 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
123042 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
123043 +load_msg_95 load_msg 2 95 NULL
123044 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
123045 +init_q_132 init_q 4 132 NULL
123046 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
123047 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
123048 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL nohasharray
123049 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 &tracing_trace_options_write_153
123050 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
123051 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
123052 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
123053 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
123054 +br_port_info_size_268 br_port_info_size 0 268 NULL
123055 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
123056 +SYSC_connect_304 SYSC_connect 3 304 NULL
123057 +syslog_print_307 syslog_print 2 307 NULL
123058 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
123059 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
123060 +aio_read_events_ring_410 aio_read_events_ring 3 410 NULL
123061 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
123062 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
123063 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
123064 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
123065 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
123066 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
123067 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
123068 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
123069 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
123070 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
123071 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
123072 +dev_hard_header_565 dev_hard_header 0 565 NULL nohasharray
123073 +start_isoc_chain_565 start_isoc_chain 2 565 &dev_hard_header_565
123074 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
123075 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
123076 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
123077 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
123078 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
123079 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
123080 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
123081 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
123082 +unlink_queued_645 unlink_queued 4 645 NULL
123083 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
123084 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
123085 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
123086 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
123087 +dvb_video_write_754 dvb_video_write 3 754 NULL
123088 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
123089 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
123090 +if_writecmd_815 if_writecmd 2 815 NULL
123091 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
123092 +error_state_read_859 error_state_read 6 859 NULL
123093 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
123094 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
123095 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
123096 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
123097 +__nodes_weight_956 __nodes_weight 0 956 NULL
123098 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
123099 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
123100 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
123101 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
123102 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
123103 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
123104 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
123105 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
123106 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
123107 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
123108 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
123109 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
123110 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
123111 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
123112 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
123113 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
123114 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
123115 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
123116 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
123117 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
123118 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
123119 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
123120 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
123121 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
123122 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
123123 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
123124 +ffs_1322 ffs 0 1322 NULL
123125 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
123126 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
123127 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
123128 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
123129 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
123130 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
123131 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
123132 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
123133 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
123134 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
123135 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
123136 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
123137 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
123138 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
123139 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
123140 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
123141 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
123142 +fpregs_set_1497 fpregs_set 4 1497 NULL
123143 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
123144 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
123145 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
123146 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
123147 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
123148 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
123149 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
123150 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
123151 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
123152 +rmap_add_1677 rmap_add 3 1677 NULL
123153 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
123154 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
123155 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
123156 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
123157 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
123158 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
123159 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
123160 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
123161 +cosa_write_1774 cosa_write 3 1774 NULL
123162 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
123163 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2 1815 NULL
123164 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
123165 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
123166 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
123167 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
123168 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
123169 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
123170 +bdev_erase_1933 bdev_erase 3 1933 NULL
123171 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
123172 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
123173 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
123174 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
123175 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
123176 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
123177 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
123178 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
123179 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
123180 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
123181 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
123182 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
123183 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
123184 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
123185 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
123186 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
123187 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
123188 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
123189 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
123190 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
123191 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
123192 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
123193 +enable_read_2117 enable_read 3 2117 NULL
123194 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
123195 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
123196 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
123197 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
123198 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
123199 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
123200 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
123201 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
123202 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
123203 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
123204 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
123205 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
123206 +do_update_counters_2259 do_update_counters 4 2259 NULL
123207 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
123208 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
123209 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
123210 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
123211 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
123212 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
123213 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
123214 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
123215 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
123216 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
123217 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
123218 +rose_recvmsg_2368 rose_recvmsg 4 2368 NULL nohasharray
123219 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 &rose_recvmsg_2368
123220 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
123221 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
123222 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
123223 +raid1_size_2419 raid1_size 0-2 2419 NULL
123224 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
123225 +wiphy_new_2482 wiphy_new 2 2482 NULL
123226 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
123227 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
123228 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
123229 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
123230 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
123231 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
123232 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
123233 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
123234 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
123235 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
123236 +slot_bytes_2609 slot_bytes 0 2609 NULL
123237 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
123238 +switch_status_2629 switch_status 5 2629 NULL
123239 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
123240 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
123241 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
123242 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
123243 +oti6858_write_2692 oti6858_write 4 2692 NULL
123244 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
123245 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
123246 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
123247 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
123248 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
123249 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
123250 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
123251 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
123252 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
123253 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
123254 +sock_create_2838 sock_create 0 2838 NULL
123255 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
123256 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
123257 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
123258 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
123259 +nla_padlen_2883 nla_padlen 1 2883 NULL
123260 +cmm_write_2896 cmm_write 3 2896 NULL
123261 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
123262 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
123263 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
123264 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
123265 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
123266 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
123267 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
123268 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
123269 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
123270 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
123271 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
123272 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
123273 +depth_write_3021 depth_write 3 3021 NULL
123274 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
123275 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
123276 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
123277 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
123278 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
123279 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
123280 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
123281 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
123282 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
123283 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
123284 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL nohasharray
123285 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 &dac960_user_command_proc_write_3071
123286 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
123287 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
123288 +rb_alloc_3102 rb_alloc 1 3102 NULL
123289 +simple_write_to_buffer_3122 simple_write_to_buffer 2-5 3122 NULL
123290 +print_time_3132 print_time 0 3132 NULL
123291 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
123292 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
123293 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
123294 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
123295 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
123296 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
123297 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
123298 +alloc_context_3194 alloc_context 1 3194 NULL
123299 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
123300 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
123301 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
123302 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
123303 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
123304 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
123305 +key_key_read_3241 key_key_read 3 3241 NULL
123306 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
123307 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
123308 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
123309 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
123310 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
123311 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
123312 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
123313 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
123314 +scnprintf_3360 scnprintf 0-2 3360 NULL
123315 +sr_read_3366 sr_read 3 3366 NULL
123316 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
123317 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
123318 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
123319 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
123320 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
123321 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
123322 +softsynth_write_3455 softsynth_write 3 3455 NULL
123323 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
123324 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
123325 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
123326 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
123327 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
123328 +SyS_readv_3539 SyS_readv 3 3539 NULL
123329 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
123330 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
123331 +evtchn_read_3569 evtchn_read 3 3569 NULL
123332 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
123333 +vc_resize_3585 vc_resize 3-2 3585 NULL
123334 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
123335 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
123336 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
123337 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
123338 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
123339 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
123340 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
123341 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
123342 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
123343 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
123344 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
123345 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
123346 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
123347 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
123348 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
123349 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
123350 +get_fd_set_3866 get_fd_set 1 3866 NULL
123351 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
123352 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
123353 +nvram_write_3894 nvram_write 3 3894 NULL
123354 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
123355 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
123356 +vcs_write_3910 vcs_write 3 3910 NULL
123357 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
123358 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
123359 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
123360 +do_add_counters_3992 do_add_counters 3 3992 NULL
123361 +userspace_status_4004 userspace_status 4 4004 NULL
123362 +mei_write_4005 mei_write 3 4005 NULL nohasharray
123363 +xfs_check_block_4005 xfs_check_block 4 4005 &mei_write_4005
123364 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
123365 +blk_end_request_4024 blk_end_request 3 4024 NULL
123366 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
123367 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
123368 +read_file_queues_4078 read_file_queues 3 4078 NULL
123369 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
123370 +tm6000_read_4151 tm6000_read 3 4151 NULL
123371 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
123372 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
123373 +get_alua_req_4166 get_alua_req 3 4166 NULL
123374 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
123375 +read_file_bool_4180 read_file_bool 3 4180 NULL
123376 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
123377 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
123378 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
123379 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
123380 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
123381 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
123382 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
123383 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
123384 +count_strings_4315 count_strings 0 4315 NULL
123385 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
123386 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
123387 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
123388 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL
123389 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
123390 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
123391 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
123392 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
123393 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
123394 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
123395 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
123396 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 0-5 4481 NULL
123397 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
123398 +set_link_security_4502 set_link_security 4 4502 NULL
123399 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
123400 +tty_register_device_4544 tty_register_device 2 4544 NULL
123401 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
123402 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
123403 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
123404 +bch_alloc_4593 bch_alloc 1 4593 NULL
123405 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
123406 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
123407 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
123408 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
123409 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
123410 +kone_receive_4690 kone_receive 4 4690 NULL
123411 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
123412 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
123413 +show_header_4722 show_header 3 4722 NULL nohasharray
123414 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 &show_header_4722
123415 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
123416 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
123417 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
123418 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
123419 +create_subvol_4791 create_subvol 4 4791 NULL
123420 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
123421 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
123422 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
123423 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
123424 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
123425 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
123426 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
123427 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
123428 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
123429 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
123430 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
123431 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
123432 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
123433 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
123434 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
123435 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
123436 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 2-3 5066 NULL
123437 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
123438 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
123439 +kfifo_copy_from_user_5091 kfifo_copy_from_user 4-3-0 5091 NULL nohasharray
123440 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
123441 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
123442 +sound_write_5102 sound_write 3 5102 NULL
123443 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
123444 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
123445 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
123446 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
123447 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
123448 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
123449 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
123450 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
123451 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
123452 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
123453 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
123454 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
123455 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
123456 +cq_free_res_5355 cq_free_res 5 5355 NULL
123457 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
123458 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
123459 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
123460 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
123461 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
123462 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
123463 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
123464 +tty_write_5494 tty_write 3 5494 NULL
123465 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 NULL nohasharray
123466 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 &ieee80211_if_fmt_last_beacon_5498
123467 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
123468 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
123469 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
123470 +le_readq_5557 le_readq 0 5557 NULL
123471 +inw_5558 inw 0 5558 NULL
123472 +bioset_create_5580 bioset_create 1 5580 NULL
123473 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
123474 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
123475 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
123476 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
123477 +get_arg_5694 get_arg 3 5694 NULL
123478 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
123479 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
123480 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
123481 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
123482 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
123483 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
123484 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
123485 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
123486 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
123487 +setup_req_5848 setup_req 3 5848 NULL
123488 +ria_page_count_5849 ria_page_count 0 5849 NULL
123489 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
123490 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
123491 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
123492 +port_show_regs_5904 port_show_regs 3 5904 NULL
123493 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
123494 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
123495 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
123496 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
123497 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
123498 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
123499 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
123500 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
123501 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
123502 +alloc_msg_6072 alloc_msg 1 6072 NULL
123503 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
123504 +force_static_address_read_6110 force_static_address_read 3 6110 NULL nohasharray
123505 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 &force_static_address_read_6110
123506 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
123507 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
123508 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
123509 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
123510 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
123511 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
123512 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
123513 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
123514 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
123515 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
123516 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
123517 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
123518 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
123519 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
123520 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
123521 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
123522 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
123523 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
123524 +serial_port_in_6291 serial_port_in 0 6291 NULL
123525 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
123526 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
123527 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
123528 +SyS_mincore_6329 SyS_mincore 1-2 6329 &hfa384x_inw_6329
123529 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
123530 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
123531 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
123532 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
123533 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
123534 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
123535 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
123536 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
123537 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
123538 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
123539 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
123540 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
123541 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
123542 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
123543 +mei_read_6507 mei_read 3 6507 NULL
123544 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
123545 +wdm_read_6549 wdm_read 3 6549 NULL
123546 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
123547 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
123548 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
123549 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
123550 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
123551 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
123552 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
123553 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
123554 +mpeg_read_6708 mpeg_read 3 6708 NULL
123555 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
123556 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
123557 +video_proc_write_6724 video_proc_write 3 6724 NULL
123558 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
123559 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
123560 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
123561 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
123562 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
123563 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
123564 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
123565 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
123566 +calc_pages_for_6838 calc_pages_for 0-2-1 6838 NULL
123567 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
123568 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
123569 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
123570 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
123571 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
123572 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
123573 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
123574 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
123575 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
123576 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
123577 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
123578 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
123579 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
123580 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
123581 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
123582 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
123583 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
123584 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
123585 +request_key_async_6990 request_key_async 4 6990 NULL
123586 +tpl_write_6998 tpl_write 3 6998 NULL
123587 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
123588 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
123589 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
123590 +wimax_msg_7030 wimax_msg 4 7030 NULL
123591 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
123592 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
123593 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
123594 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
123595 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
123596 +event_enable_read_7074 event_enable_read 3 7074 NULL
123597 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
123598 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
123599 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
123600 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
123601 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
123602 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
123603 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
123604 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
123605 +mgmt_control_7349 mgmt_control 3 7349 NULL
123606 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
123607 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
123608 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
123609 +hweight_long_7388 hweight_long 0 7388 NULL
123610 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
123611 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
123612 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
123613 +readb_7401 readb 0 7401 NULL
123614 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
123615 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
123616 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
123617 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
123618 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
123619 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
123620 +garp_request_join_7471 garp_request_join 4 7471 NULL
123621 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
123622 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
123623 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
123624 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
123625 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
123626 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
123627 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
123628 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
123629 +groups_alloc_7614 groups_alloc 1 7614 NULL
123630 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
123631 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
123632 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
123633 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
123634 +dev_write_7708 dev_write 3 7708 NULL
123635 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
123636 +ubi_io_read_vid_hdr_7766 ubi_io_read_vid_hdr 0 7766 NULL
123637 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
123638 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
123639 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
123640 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
123641 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
123642 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
123643 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
123644 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
123645 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
123646 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
123647 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
123648 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
123649 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
123650 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
123651 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
123652 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
123653 +vcs_read_8017 vcs_read 3 8017 NULL
123654 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
123655 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
123656 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
123657 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
123658 +venus_lookup_8121 venus_lookup 4 8121 NULL
123659 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
123660 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
123661 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
123662 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
123663 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
123664 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
123665 +play_iframe_8219 play_iframe 3 8219 NULL
123666 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
123667 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
123668 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
123669 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
123670 +init_cdev_8274 init_cdev 1 8274 NULL
123671 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
123672 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
123673 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
123674 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
123675 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
123676 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
123677 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
123678 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
123679 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
123680 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
123681 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
123682 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
123683 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
123684 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
123685 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
123686 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
123687 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
123688 +dev_config_8506 dev_config 3 8506 NULL
123689 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
123690 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
123691 +user_on_off_8552 user_on_off 2 8552 NULL
123692 +profile_remove_8556 profile_remove 3 8556 NULL
123693 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
123694 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
123695 +tower_write_8580 tower_write 3 8580 NULL
123696 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
123697 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
123698 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
123699 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
123700 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
123701 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
123702 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
123703 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
123704 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
123705 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
123706 +arcfb_write_8702 arcfb_write 3 8702 NULL
123707 +i_size_read_8703 i_size_read 0 8703 NULL
123708 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
123709 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
123710 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
123711 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
123712 +compound_order_8750 compound_order 0 8750 NULL
123713 +yurex_write_8761 yurex_write 3 8761 NULL
123714 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
123715 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
123716 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
123717 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
123718 +__bitmap_weight_8796 __bitmap_weight 0 8796 NULL
123719 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
123720 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
123721 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
123722 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
123723 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
123724 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
123725 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
123726 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
123727 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
123728 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
123729 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
123730 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
123731 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL nohasharray
123732 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 &tracing_max_lat_read_8890
123733 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
123734 +write_file_ani_8918 write_file_ani 3 8918 NULL
123735 +layout_commit_8926 layout_commit 3 8926 NULL
123736 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
123737 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
123738 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
123739 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
123740 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
123741 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
123742 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
123743 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
123744 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
123745 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
123746 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
123747 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
123748 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
123749 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
123750 +nla_put_9042 nla_put 3 9042 NULL
123751 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 4-3-0 9050 NULL
123752 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
123753 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
123754 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
123755 +create_queues_9088 create_queues 2-3 9088 NULL
123756 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
123757 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
123758 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
123759 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
123760 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
123761 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
123762 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
123763 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
123764 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
123765 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
123766 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
123767 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
123768 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
123769 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
123770 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
123771 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
123772 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
123773 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
123774 +flakey_status_9274 flakey_status 5 9274 NULL
123775 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
123776 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
123777 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
123778 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
123779 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
123780 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
123781 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
123782 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
123783 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
123784 +read_9397 read 3 9397 NULL
123785 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
123786 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
123787 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
123788 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
123789 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
123790 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
123791 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
123792 +crypt_status_9492 crypt_status 5 9492 NULL
123793 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
123794 +lp_write_9511 lp_write 3 9511 NULL
123795 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
123796 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
123797 +read_file_dma_9530 read_file_dma 3 9530 NULL
123798 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
123799 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
123800 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
123801 +fw_node_create_9559 fw_node_create 2 9559 NULL
123802 +kobj_map_9566 kobj_map 2-3 9566 NULL
123803 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
123804 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
123805 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
123806 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
123807 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
123808 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
123809 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
123810 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
123811 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
123812 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
123813 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
123814 +dns_query_9676 dns_query 3 9676 NULL
123815 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
123816 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
123817 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
123818 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
123819 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
123820 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
123821 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
123822 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
123823 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
123824 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
123825 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
123826 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
123827 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
123828 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
123829 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
123830 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
123831 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
123832 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
123833 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
123834 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
123835 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
123836 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
123837 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
123838 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
123839 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
123840 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
123841 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
123842 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
123843 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
123844 +read_file_misc_9948 read_file_misc 3 9948 NULL
123845 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
123846 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
123847 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
123848 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
123849 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
123850 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
123851 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
123852 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
123853 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
123854 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
123855 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
123856 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
123857 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
123858 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
123859 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
123860 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
123861 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
123862 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
123863 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
123864 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
123865 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
123866 +ubi_leb_change_10289 ubi_leb_change 0 10289 NULL
123867 +read_emulate_10310 read_emulate 2-4 10310 NULL
123868 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
123869 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
123870 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
123871 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
123872 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
123873 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
123874 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
123875 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
123876 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
123877 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
123878 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
123879 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
123880 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
123881 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
123882 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
123883 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
123884 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
123885 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
123886 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
123887 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
123888 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
123889 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
123890 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
123891 +otp_read_10594 otp_read 2-4-5 10594 NULL
123892 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
123893 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
123894 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
123895 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL nohasharray
123896 +ubi_io_write_vid_hdr_10660 ubi_io_write_vid_hdr 0 10660 &nfs_idmap_lookup_id_10660
123897 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
123898 +parport_write_10669 parport_write 0 10669 NULL
123899 +edge_write_10692 edge_write 4 10692 NULL
123900 +ubi_wl_get_peb_10699 ubi_wl_get_peb 0 10699 NULL
123901 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
123902 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
123903 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
123904 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
123905 +spi_sync_10731 spi_sync 0 10731 NULL
123906 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
123907 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
123908 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
123909 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
123910 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
123911 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
123912 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
123913 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
123914 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
123915 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
123916 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
123917 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
123918 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
123919 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
123920 +get_scq_10897 get_scq 2 10897 NULL
123921 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
123922 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
123923 +__copy_from_user_10918 __copy_from_user 3-0 10918 NULL
123924 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
123925 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
123926 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
123927 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
123928 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
123929 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
123930 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
123931 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
123932 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
123933 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
123934 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
123935 +count_argc_11083 count_argc 0 11083 NULL
123936 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
123937 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
123938 +page_offset_11120 page_offset 0 11120 NULL
123939 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
123940 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
123941 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
123942 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
123943 +of_irq_count_11253 of_irq_count 0 11253 NULL
123944 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
123945 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
123946 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
123947 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
123948 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
123949 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
123950 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
123951 +construct_key_11329 construct_key 3 11329 NULL nohasharray
123952 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
123953 +next_segment_11330 next_segment 0-2-1 11330 NULL
123954 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
123955 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
123956 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
123957 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
123958 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
123959 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
123960 +nft_value_dump_11381 nft_value_dump 3 11381 NULL nohasharray
123961 +tcf_register_action_11381 tcf_register_action 2 11381 &nft_value_dump_11381
123962 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
123963 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
123964 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
123965 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
123966 +str_to_user_11411 str_to_user 2 11411 NULL
123967 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
123968 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
123969 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
123970 +trace_options_read_11419 trace_options_read 3 11419 NULL
123971 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
123972 +bttv_read_11432 bttv_read 3 11432 NULL
123973 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
123974 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
123975 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
123976 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
123977 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
123978 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
123979 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
123980 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
123981 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
123982 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
123983 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
123984 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
123985 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
123986 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
123987 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
123988 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
123989 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
123990 +slab_ksize_11664 slab_ksize 0 11664 NULL
123991 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
123992 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
123993 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
123994 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
123995 +split_11691 split 2 11691 NULL
123996 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
123997 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
123998 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
123999 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
124000 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
124001 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
124002 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
124003 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
124004 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
124005 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
124006 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
124007 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
124008 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
124009 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
124010 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
124011 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
124012 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
124013 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
124014 +ti_write_11916 ti_write 4 11916 NULL
124015 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
124016 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
124017 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
124018 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
124019 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
124020 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
124021 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
124022 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
124023 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
124024 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
124025 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
124026 +set_powered_12129 set_powered 4 12129 NULL
124027 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
124028 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
124029 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
124030 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
124031 +get_idx_gc_leb_12148 get_idx_gc_leb 0 12148 NULL
124032 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
124033 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
124034 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
124035 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
124036 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
124037 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
124038 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
124039 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
124040 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
124041 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
124042 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
124043 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
124044 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
124045 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
124046 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
124047 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
124048 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
124049 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
124050 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
124051 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
124052 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
124053 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
124054 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
124055 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
124056 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 NULL nohasharray
124057 +write_file_dump_12391 write_file_dump 3 12391 &btrfs_file_extent_ram_bytes_12391
124058 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
124059 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
124060 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
124061 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
124062 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
124063 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
124064 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
124065 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
124066 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
124067 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
124068 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
124069 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
124070 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
124071 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
124072 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
124073 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
124074 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
124075 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
124076 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
124077 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 NULL nohasharray
124078 +sel_read_class_12669 sel_read_class 3 12669 &sparse_mem_maps_populate_node_12669
124079 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
124080 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
124081 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
124082 +ivtv_write_12721 ivtv_write 3 12721 NULL
124083 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
124084 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
124085 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
124086 +listxattr_12769 listxattr 3 12769 NULL
124087 +sctp_ssnmap_init_12772 sctp_ssnmap_init 3-2 12772 NULL
124088 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
124089 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
124090 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
124091 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
124092 +spidev_sync_12842 spidev_sync 0 12842 NULL
124093 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
124094 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
124095 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
124096 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
124097 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
124098 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
124099 +bm_status_write_12964 bm_status_write 3 12964 NULL
124100 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
124101 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
124102 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
124103 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
124104 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
124105 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
124106 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
124107 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
124108 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
124109 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
124110 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
124111 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
124112 +blk_update_request_13146 blk_update_request 3 13146 NULL
124113 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
124114 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
124115 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
124116 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
124117 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
124118 +comedi_read_13199 comedi_read 3 13199 NULL
124119 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
124120 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
124121 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
124122 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
124123 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
124124 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
124125 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
124126 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
124127 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
124128 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
124129 +il4965_stats_flag_13281 il4965_stats_flag 3-0 13281 NULL
124130 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
124131 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
124132 +sd_major_13294 sd_major 0-1 13294 NULL
124133 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
124134 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
124135 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
124136 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
124137 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
124138 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
124139 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
124140 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
124141 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
124142 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
124143 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
124144 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
124145 +data_read_13494 data_read 3 13494 NULL nohasharray
124146 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
124147 +core_status_13515 core_status 4 13515 NULL
124148 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
124149 +bm_init_13529 bm_init 2 13529 NULL
124150 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
124151 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
124152 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
124153 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
124154 +cache_write_13589 cache_write 3 13589 NULL
124155 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
124156 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
124157 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
124158 +packet_snd_13634 packet_snd 3 13634 NULL
124159 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
124160 +cache_downcall_13666 cache_downcall 3 13666 NULL
124161 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
124162 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
124163 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
124164 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
124165 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
124166 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
124167 +random_read_13815 random_read 3 13815 NULL
124168 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
124169 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
124170 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
124171 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
124172 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
124173 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
124174 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
124175 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
124176 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
124177 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
124178 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
124179 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
124180 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
124181 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
124182 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
124183 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
124184 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
124185 +qcam_read_13977 qcam_read 3 13977 NULL
124186 +dsp_read_13980 dsp_read 2 13980 NULL
124187 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
124188 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
124189 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
124190 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
124191 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
124192 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
124193 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
124194 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
124195 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
124196 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
124197 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
124198 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
124199 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
124200 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
124201 +em_canid_change_14150 em_canid_change 3 14150 NULL
124202 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
124203 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
124204 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
124205 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
124206 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
124207 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
124208 +alloc_async_14208 alloc_async 1 14208 NULL
124209 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
124210 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
124211 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
124212 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
124213 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
124214 +rr_status_14293 rr_status 5 14293 NULL
124215 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
124216 +oo_objects_14319 oo_objects 0 14319 NULL
124217 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
124218 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
124219 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
124220 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
124221 +lowpan_read_14369 lowpan_read 3 14369 NULL
124222 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
124223 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
124224 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
124225 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
124226 +block_size_14443 block_size 0 14443 NULL
124227 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
124228 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
124229 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
124230 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
124231 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
124232 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
124233 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
124234 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
124235 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
124236 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
124237 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
124238 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
124239 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
124240 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
124241 +dbJoin_14644 dbJoin 0 14644 NULL
124242 +profile_replace_14652 profile_replace 3 14652 NULL
124243 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
124244 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
124245 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
124246 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
124247 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
124248 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
124249 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
124250 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
124251 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
124252 +vfd_write_14717 vfd_write 3 14717 NULL
124253 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
124254 +raid1_resize_14740 raid1_resize 2 14740 NULL
124255 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
124256 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
124257 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
124258 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
124259 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
124260 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
124261 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
124262 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
124263 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
124264 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
124265 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
124266 +lcd_write_14857 lcd_write 3 14857 NULL
124267 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
124268 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
124269 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
124270 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
124271 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
124272 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
124273 +queue_cnt_14951 queue_cnt 0 14951 NULL
124274 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
124275 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
124276 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
124277 +setkey_14987 setkey 3 14987 NULL nohasharray
124278 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
124279 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
124280 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
124281 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
124282 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
124283 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
124284 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
124285 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
124286 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
124287 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
124288 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
124289 +start_port_15124 start_port 0 15124 NULL
124290 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
124291 +self_check_not_bad_15175 self_check_not_bad 0 15175 NULL
124292 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
124293 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
124294 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
124295 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
124296 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
124297 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
124298 +simple_strtol_15273 simple_strtol 0 15273 NULL
124299 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
124300 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
124301 +ioread16_15342 ioread16 0 15342 NULL
124302 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
124303 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
124304 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
124305 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
124306 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
124307 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
124308 +get_modalias_15406 get_modalias 2 15406 NULL
124309 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
124310 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 0-2 15438 NULL
124311 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
124312 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
124313 +insert_old_idx_znode_15500 insert_old_idx_znode 0 15500 NULL
124314 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
124315 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
124316 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
124317 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
124318 +persistent_status_15574 persistent_status 4 15574 NULL
124319 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
124320 +vme_user_write_15587 vme_user_write 3 15587 NULL
124321 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
124322 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
124323 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
124324 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
124325 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
124326 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
124327 +fs_path_add_15648 fs_path_add 3 15648 NULL
124328 +xsd_read_15653 xsd_read 3 15653 NULL
124329 +unix_bind_15668 unix_bind 3 15668 NULL
124330 +SyS_connect_15674 SyS_connect 3 15674 NULL nohasharray
124331 +dm_read_15674 dm_read 3 15674 &SyS_connect_15674
124332 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
124333 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
124334 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
124335 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
124336 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
124337 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
124338 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
124339 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
124340 +table_size_15851 table_size 0-1-2 15851 NULL
124341 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
124342 +media_entity_init_15870 media_entity_init 2-4 15870 NULL nohasharray
124343 +ubi_io_write_15870 ubi_io_write 0 15870 &media_entity_init_15870
124344 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
124345 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
124346 +power_read_15939 power_read 3 15939 NULL
124347 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
124348 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
124349 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
124350 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
124351 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
124352 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
124353 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
124354 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
124355 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
124356 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
124357 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
124358 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
124359 +fsm_init_16134 fsm_init 2 16134 NULL
124360 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
124361 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
124362 +mapping_level_16188 mapping_level 0-2 16188 NULL
124363 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
124364 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
124365 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
124366 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
124367 +create_table_16213 create_table 2 16213 NULL
124368 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
124369 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
124370 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
124371 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
124372 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
124373 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
124374 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
124375 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
124376 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
124377 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
124378 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
124379 +account_16283 account 0-4-2 16283 NULL nohasharray
124380 +mirror_status_16283 mirror_status 5 16283 &account_16283
124381 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
124382 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
124383 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
124384 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
124385 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
124386 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
124387 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
124388 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
124389 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
124390 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
124391 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
124392 +cmdline_store_16442 cmdline_store 4 16442 NULL
124393 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
124394 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
124395 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
124396 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
124397 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
124398 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
124399 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
124400 +raid10_resize_16537 raid10_resize 2 16537 NULL
124401 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
124402 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
124403 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
124404 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
124405 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
124406 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
124407 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
124408 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
124409 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
124410 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
124411 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
124412 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
124413 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
124414 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
124415 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
124416 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
124417 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
124418 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
124419 +st_write_16874 st_write 3 16874 NULL
124420 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
124421 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
124422 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
124423 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
124424 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
124425 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
124426 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
124427 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
124428 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
124429 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
124430 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
124431 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
124432 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
124433 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
124434 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
124435 +entry_length_17093 entry_length 0 17093 NULL
124436 +write_mem_17114 write_mem 3 17114 NULL
124437 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
124438 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
124439 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
124440 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
124441 +sep_read_17161 sep_read 3 17161 NULL
124442 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
124443 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
124444 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
124445 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
124446 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
124447 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
124448 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
124449 +sync_request_17208 sync_request 2 17208 NULL
124450 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
124451 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
124452 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
124453 +alloc_ep_17269 alloc_ep 1 17269 NULL
124454 +pg_read_17276 pg_read 3 17276 NULL
124455 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
124456 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
124457 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
124458 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
124459 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
124460 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
124461 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
124462 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
124463 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
124464 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
124465 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
124466 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
124467 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
124468 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
124469 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
124470 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
124471 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
124472 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
124473 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
124474 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
124475 +qp_free_res_17541 qp_free_res 5 17541 NULL
124476 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
124477 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
124478 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
124479 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
124480 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
124481 +osst_execute_17607 osst_execute 7-6 17607 NULL
124482 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
124483 +dma_map_page_17628 dma_map_page 0 17628 NULL
124484 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
124485 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
124486 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL nohasharray
124487 +ubi_io_read_data_17662 ubi_io_read_data 0 17662 &packet_setsockopt_17662
124488 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
124489 +venus_rename_17707 venus_rename 4-5 17707 NULL
124490 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
124491 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
124492 +ubifs_leb_change_17789 ubifs_leb_change 0 17789 NULL
124493 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
124494 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
124495 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
124496 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
124497 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
124498 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
124499 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
124500 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
124501 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
124502 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
124503 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
124504 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
124505 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
124506 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
124507 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
124508 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
124509 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
124510 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
124511 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
124512 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
124513 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
124514 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
124515 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
124516 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
124517 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
124518 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
124519 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
124520 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
124521 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
124522 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
124523 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
124524 +fpregs_get_18066 fpregs_get 4 18066 NULL
124525 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
124526 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
124527 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
124528 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
124529 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
124530 +svc_getnl_18120 svc_getnl 0 18120 NULL
124531 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
124532 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
124533 +is_idx_node_in_use_18165 is_idx_node_in_use 0 18165 NULL
124534 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
124535 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
124536 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
124537 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
124538 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
124539 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
124540 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
124541 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
124542 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
124543 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
124544 +find_dirty_idx_leb_18280 find_dirty_idx_leb 0 18280 NULL
124545 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
124546 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
124547 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
124548 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
124549 +um_idi_write_18293 um_idi_write 3 18293 NULL
124550 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
124551 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
124552 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
124553 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
124554 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
124555 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
124556 +copy_page_to_iter_18345 copy_page_to_iter 3-0 18345 NULL
124557 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
124558 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
124559 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
124560 +ep_io_18367 ep_io 0 18367 NULL
124561 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
124562 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
124563 +ci_role_write_18388 ci_role_write 3 18388 NULL
124564 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
124565 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
124566 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
124567 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
124568 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
124569 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
124570 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL
124571 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
124572 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
124573 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
124574 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
124575 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
124576 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
124577 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
124578 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
124579 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
124580 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
124581 +debug_output_18575 debug_output 3 18575 NULL
124582 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL
124583 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
124584 +from_buffer_18625 from_buffer 3 18625 NULL
124585 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
124586 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
124587 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
124588 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
124589 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
124590 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
124591 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
124592 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
124593 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
124594 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
124595 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
124596 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
124597 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
124598 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
124599 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
124600 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
124601 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
124602 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
124603 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
124604 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
124605 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
124606 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
124607 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
124608 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
124609 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
124610 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
124611 +find_dirtiest_idx_leb_19001 find_dirtiest_idx_leb 0 19001 NULL
124612 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
124613 +huge_page_size_19008 huge_page_size 0 19008 NULL
124614 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
124615 +revalidate_19043 revalidate 2 19043 NULL
124616 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
124617 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
124618 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
124619 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
124620 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
124621 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
124622 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
124623 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
124624 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
124625 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
124626 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
124627 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
124628 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
124629 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
124630 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
124631 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
124632 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
124633 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
124634 +ucma_query_19260 ucma_query 4 19260 NULL
124635 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
124636 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
124637 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
124638 +qc_capture_19298 qc_capture 3 19298 NULL
124639 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 3-4 19303 NULL
124640 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
124641 +debug_read_19322 debug_read 3 19322 NULL
124642 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
124643 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
124644 +closure_sub_19359 closure_sub 2 19359 NULL
124645 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
124646 +read_zero_19366 read_zero 3 19366 NULL
124647 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
124648 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
124649 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
124650 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
124651 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
124652 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
124653 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
124654 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
124655 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
124656 +sky2_read16_19475 sky2_read16 0 19475 NULL
124657 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
124658 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
124659 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
124660 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
124661 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
124662 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
124663 +nfsd_read_19568 nfsd_read 5 19568 NULL
124664 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
124665 +bm_status_read_19583 bm_status_read 3 19583 NULL
124666 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
124667 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
124668 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
124669 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
124670 +read_reg_19723 read_reg 0 19723 NULL
124671 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
124672 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
124673 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
124674 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
124675 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
124676 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
124677 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
124678 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
124679 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
124680 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
124681 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
124682 +__nla_put_19857 __nla_put 3 19857 NULL
124683 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
124684 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
124685 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
124686 +mangle_name_19923 mangle_name 0 19923 NULL
124687 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
124688 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
124689 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
124690 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
124691 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
124692 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
124693 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
124694 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
124695 +event_trigger_write_20009 event_trigger_write 3 20009 NULL nohasharray
124696 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 &event_trigger_write_20009
124697 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
124698 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
124699 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
124700 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4-0 20067 NULL
124701 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
124702 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
124703 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
124704 +team_options_register_20091 team_options_register 3 20091 NULL
124705 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
124706 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
124707 +self_check_vid_hdr_20131 self_check_vid_hdr 0 20131 NULL
124708 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
124709 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
124710 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
124711 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
124712 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
124713 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
124714 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
124715 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
124716 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
124717 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
124718 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
124719 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
124720 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
124721 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
124722 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
124723 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
124724 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
124725 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
124726 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
124727 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
124728 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
124729 +read_buf_20469 read_buf 2 20469 NULL
124730 +bio_trim_20472 bio_trim 2 20472 NULL
124731 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
124732 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
124733 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
124734 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
124735 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
124736 +venus_create_20555 venus_create 4 20555 NULL
124737 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
124738 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
124739 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
124740 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
124741 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
124742 +lirc_write_20604 lirc_write 3 20604 NULL
124743 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
124744 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
124745 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
124746 +kfifo_copy_to_user_20646 kfifo_copy_to_user 4-3 20646 NULL
124747 +cpulist_scnprintf_20648 cpulist_scnprintf 2 20648 NULL
124748 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
124749 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
124750 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
124751 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
124752 +cpumask_size_20683 cpumask_size 0 20683 NULL
124753 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
124754 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
124755 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
124756 +__maestro_read_20700 __maestro_read 0 20700 NULL
124757 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
124758 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
124759 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
124760 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
124761 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
124762 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
124763 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
124764 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
124765 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
124766 +ubi_io_read_20767 ubi_io_read 0 20767 NULL
124767 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
124768 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
124769 +lowpan_write_20800 lowpan_write 3 20800 NULL
124770 +strndup_user_20819 strndup_user 2 20819 NULL
124771 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
124772 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
124773 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
124774 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
124775 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
124776 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
124777 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
124778 +srq_free_res_20868 srq_free_res 5 20868 NULL
124779 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
124780 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
124781 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
124782 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
124783 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
124784 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
124785 +htable_bits_20933 htable_bits 0 20933 NULL
124786 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
124787 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
124788 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
124789 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
124790 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
124791 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
124792 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
124793 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
124794 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
124795 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
124796 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
124797 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
124798 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
124799 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
124800 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
124801 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
124802 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
124803 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
124804 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
124805 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
124806 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
124807 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
124808 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
124809 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
124810 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
124811 +input_ff_create_21240 input_ff_create 2 21240 NULL
124812 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
124813 +fru_length_21257 fru_length 0 21257 NULL
124814 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
124815 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
124816 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
124817 +add_res_range_21310 add_res_range 4 21310 NULL
124818 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
124819 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
124820 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
124821 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
124822 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
124823 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
124824 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
124825 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
124826 +insert_ptr_21386 insert_ptr 6 21386 NULL
124827 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
124828 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
124829 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
124830 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
124831 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
124832 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
124833 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
124834 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
124835 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
124836 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
124837 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
124838 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
124839 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
124840 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
124841 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
124842 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
124843 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
124844 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
124845 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
124846 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
124847 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
124848 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
124849 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
124850 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
124851 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
124852 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
124853 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
124854 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
124855 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
124856 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
124857 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
124858 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
124859 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
124860 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
124861 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
124862 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
124863 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
124864 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
124865 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
124866 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
124867 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
124868 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
124869 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3-0 22001 NULL nohasharray
124870 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 &compat_rw_copy_check_uvector_22001
124871 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
124872 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
124873 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
124874 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
124875 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
124876 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
124877 +mem_rw_22085 mem_rw 3 22085 NULL
124878 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
124879 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
124880 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
124881 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
124882 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
124883 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
124884 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
124885 +mem_write_22232 mem_write 3 22232 NULL
124886 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
124887 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
124888 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
124889 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
124890 +add_res_tree_22263 add_res_tree 7 22263 NULL
124891 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
124892 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
124893 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
124894 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
124895 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
124896 +atomic_read_22342 atomic_read 0 22342 NULL
124897 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
124898 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
124899 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
124900 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
124901 +zoran_write_22404 zoran_write 3 22404 NULL
124902 +queue_reply_22416 queue_reply 3 22416 NULL
124903 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
124904 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
124905 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
124906 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
124907 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
124908 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
124909 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
124910 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
124911 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
124912 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
124913 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
124914 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
124915 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
124916 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
124917 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
124918 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL nohasharray
124919 +fill_gap_22681 fill_gap 0 22681 &l2tp_ip_recvmsg_22681
124920 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
124921 +reg_umr_22686 reg_umr 5 22686 NULL
124922 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
124923 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
124924 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
124925 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
124926 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
124927 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
124928 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
124929 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
124930 +print_frame_22769 print_frame 0 22769 NULL
124931 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
124932 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
124933 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
124934 +create_attr_set_22861 create_attr_set 1 22861 NULL
124935 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
124936 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
124937 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
124938 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
124939 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 NULL nohasharray
124940 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 &policy_emit_config_values_22900
124941 +__set_xattr_22923 __set_xattr 0 22923 NULL
124942 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
124943 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
124944 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
124945 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
124946 +vme_get_size_22964 vme_get_size 0 22964 NULL
124947 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
124948 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
124949 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
124950 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
124951 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
124952 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
124953 +st_status_23032 st_status 5 23032 NULL
124954 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
124955 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 NULL nohasharray
124956 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 &unix_seqpacket_recvmsg_23062
124957 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
124958 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
124959 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
124960 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
124961 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
124962 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
124963 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
124964 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
124965 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
124966 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
124967 +__clear_user_23118 __clear_user 0-2 23118 NULL
124968 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
124969 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
124970 +read_file_ani_23161 read_file_ani 3 23161 NULL
124971 +usblp_write_23178 usblp_write 3 23178 NULL
124972 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
124973 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
124974 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
124975 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
124976 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
124977 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
124978 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
124979 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
124980 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
124981 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
124982 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
124983 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
124984 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
124985 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
124986 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
124987 +page_readlink_23346 page_readlink 3 23346 NULL
124988 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
124989 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
124990 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
124991 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
124992 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
124993 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
124994 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
124995 +linear_conf_23485 linear_conf 2 23485 NULL
124996 +event_filter_read_23494 event_filter_read 3 23494 NULL
124997 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
124998 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
124999 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
125000 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
125001 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
125002 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
125003 +dbg_leb_change_23555 dbg_leb_change 0 23555 NULL
125004 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
125005 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
125006 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
125007 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
125008 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
125009 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
125010 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
125011 +sInW_23663 sInW 0 23663 NULL
125012 +SyS_connect_23669 SyS_connect 3 23669 NULL
125013 +cx18_read_23699 cx18_read 3 23699 NULL
125014 +at_get_23708 at_get 0 23708 NULL
125015 +get_conn_info_23723 get_conn_info 4 23723 NULL
125016 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
125017 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
125018 +__build_packet_message_23778 __build_packet_message 10-4 23778 NULL
125019 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
125020 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
125021 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
125022 +map_write_23795 map_write 3 23795 NULL
125023 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
125024 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
125025 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
125026 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
125027 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
125028 +p54_init_common_23850 p54_init_common 1 23850 NULL
125029 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
125030 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
125031 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
125032 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
125033 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
125034 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
125035 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
125036 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
125037 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
125038 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
125039 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
125040 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
125041 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
125042 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
125043 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
125044 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
125045 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
125046 +give_pages_24021 give_pages 3 24021 NULL
125047 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
125048 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
125049 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
125050 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
125051 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
125052 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
125053 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
125054 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
125055 +lov_brw_24122 lov_brw 4 24122 NULL
125056 +mpu401_read_24126 mpu401_read 3 24126 NULL
125057 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
125058 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
125059 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
125060 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
125061 +adu_read_24177 adu_read 3 24177 NULL
125062 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
125063 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
125064 +tcpprobe_sprint_24222 tcpprobe_sprint 2-0 24222 NULL
125065 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
125066 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
125067 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
125068 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
125069 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
125070 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
125071 +thin_status_24278 thin_status 5 24278 NULL
125072 +msg_size_24288 msg_size 0 24288 NULL
125073 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
125074 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
125075 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
125076 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
125077 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
125078 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
125079 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
125080 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
125081 +igetword_24373 igetword 0 24373 NULL
125082 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
125083 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
125084 +getxattr_24398 getxattr 4 24398 NULL nohasharray
125085 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
125086 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
125087 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
125088 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
125089 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
125090 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
125091 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
125092 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
125093 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
125094 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
125095 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
125096 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
125097 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
125098 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
125099 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
125100 +pd_video_read_24510 pd_video_read 3 24510 NULL
125101 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
125102 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
125103 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
125104 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
125105 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
125106 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
125107 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
125108 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
125109 +SyS_poll_24620 SyS_poll 2 24620 NULL
125110 +context_alloc_24645 context_alloc 3 24645 NULL
125111 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
125112 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
125113 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
125114 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
125115 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
125116 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
125117 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
125118 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
125119 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
125120 +cache_read_24790 cache_read 3 24790 NULL
125121 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
125122 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
125123 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
125124 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
125125 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
125126 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
125127 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
125128 +queues_read_24877 queues_read 3 24877 NULL
125129 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
125130 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
125131 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
125132 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
125133 +ocfs2_fiemap_24949 ocfs2_fiemap 3-4 24949 NULL
125134 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
125135 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
125136 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
125137 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
125138 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
125139 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
125140 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
125141 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
125142 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
125143 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
125144 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
125145 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
125146 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
125147 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
125148 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
125149 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
125150 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
125151 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
125152 +stripe_status_25259 stripe_status 5 25259 NULL
125153 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
125154 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
125155 +vfs_writev_25278 vfs_writev 3 25278 NULL
125156 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
125157 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
125158 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
125159 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
125160 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
125161 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
125162 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
125163 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
125164 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
125165 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
125166 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
125167 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
125168 +sb_permission_25523 sb_permission 0 25523 NULL
125169 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
125170 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
125171 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
125172 +ht_print_chan_25556 ht_print_chan 3-4-0 25556 NULL
125173 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
125174 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
125175 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
125176 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
125177 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
125178 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
125179 +__direct_map_25647 __direct_map 6-5 25647 NULL
125180 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
125181 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
125182 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
125183 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
125184 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
125185 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
125186 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
125187 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
125188 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
125189 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
125190 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
125191 +sg_read_25799 sg_read 3 25799 NULL
125192 +system_enable_read_25815 system_enable_read 3 25815 NULL
125193 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
125194 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
125195 +parport_read_25855 parport_read 0 25855 NULL
125196 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
125197 +key_attr_size_25865 key_attr_size 0 25865 NULL
125198 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
125199 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
125200 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
125201 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
125202 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
125203 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
125204 +rcname_read_25919 rcname_read 3 25919 NULL
125205 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
125206 +key_flags_read_25931 key_flags_read 3 25931 NULL
125207 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
125208 +flush_25957 flush 2 25957 NULL
125209 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
125210 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
125211 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
125212 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
125213 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
125214 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
125215 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
125216 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
125217 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
125218 +read_sb_page_26119 read_sb_page 5 26119 NULL
125219 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
125220 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
125221 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
125222 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
125223 +disk_devt_26180 disk_devt 0 26180 NULL
125224 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
125225 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
125226 +mce_write_26201 mce_write 3 26201 NULL
125227 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
125228 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
125229 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
125230 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
125231 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
125232 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
125233 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
125234 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
125235 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
125236 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
125237 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
125238 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
125239 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
125240 +ntty_write_26404 ntty_write 3 26404 NULL
125241 +firmware_store_26408 firmware_store 4 26408 NULL
125242 +tower_read_26461 tower_read 3 26461 NULL nohasharray
125243 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
125244 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
125245 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
125246 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
125247 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
125248 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
125249 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
125250 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
125251 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
125252 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
125253 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
125254 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
125255 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
125256 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
125257 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
125258 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
125259 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
125260 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
125261 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
125262 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
125263 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
125264 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
125265 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
125266 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
125267 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
125268 +smk_write_load_26829 smk_write_load 3 26829 NULL
125269 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
125270 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
125271 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
125272 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
125273 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
125274 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
125275 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
125276 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
125277 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
125278 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
125279 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
125280 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
125281 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
125282 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
125283 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
125284 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
125285 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
125286 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
125287 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
125288 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
125289 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
125290 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
125291 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
125292 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
125293 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
125294 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
125295 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
125296 +pms_capture_27142 pms_capture 4 27142 NULL
125297 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
125298 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
125299 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
125300 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
125301 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
125302 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
125303 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
125304 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
125305 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
125306 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
125307 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
125308 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
125309 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
125310 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
125311 +seq_read_27411 seq_read 3 27411 NULL
125312 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
125313 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
125314 +cypress_write_27423 cypress_write 4 27423 NULL
125315 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
125316 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
125317 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
125318 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
125319 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
125320 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
125321 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
125322 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
125323 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
125324 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
125325 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
125326 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
125327 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
125328 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL nohasharray
125329 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642 nohasharray
125330 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 &nl80211_send_connect_result_27642
125331 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
125332 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
125333 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
125334 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
125335 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
125336 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
125337 +evm_write_key_27715 evm_write_key 3 27715 NULL
125338 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
125339 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
125340 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
125341 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
125342 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
125343 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
125344 +SyS_readv_27804 SyS_readv 3 27804 NULL
125345 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
125346 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
125347 +read_profile_27859 read_profile 3 27859 NULL
125348 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
125349 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
125350 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
125351 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
125352 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL nohasharray
125353 +bio_next_split_27961 bio_next_split 2 27961 &tracing_clock_write_27961
125354 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
125355 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
125356 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
125357 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
125358 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
125359 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
125360 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
125361 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
125362 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
125363 +pool_status_28055 pool_status 5 28055 NULL
125364 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
125365 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
125366 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
125367 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
125368 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
125369 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
125370 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
125371 +video_read_28148 video_read 3 28148 NULL
125372 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
125373 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
125374 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
125375 +counter_free_res_28187 counter_free_res 5 28187 NULL
125376 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
125377 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
125378 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
125379 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
125380 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
125381 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
125382 +usemap_size_28281 usemap_size 0 28281 NULL
125383 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
125384 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
125385 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
125386 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
125387 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
125388 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
125389 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
125390 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
125391 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
125392 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
125393 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
125394 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
125395 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
125396 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
125397 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
125398 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
125399 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
125400 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
125401 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
125402 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
125403 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
125404 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
125405 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
125406 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
125407 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
125408 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
125409 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
125410 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
125411 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
125412 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
125413 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
125414 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
125415 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
125416 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
125417 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 3-5 28622 NULL
125418 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
125419 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
125420 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
125421 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
125422 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
125423 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
125424 +spi_execute_28736 spi_execute 5 28736 NULL
125425 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
125426 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
125427 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
125428 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
125429 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
125430 +sel_write_member_28800 sel_write_member 3 28800 NULL
125431 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
125432 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
125433 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
125434 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
125435 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
125436 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
125437 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
125438 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
125439 +push_rx_28939 push_rx 3 28939 NULL
125440 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
125441 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
125442 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
125443 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
125444 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
125445 +bin_uuid_28999 bin_uuid 3 28999 NULL
125446 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
125447 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
125448 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
125449 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
125450 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
125451 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
125452 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
125453 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
125454 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
125455 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
125456 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
125457 +snprintf_29125 snprintf 0 29125 NULL
125458 +iov_shorten_29130 iov_shorten 0 29130 NULL
125459 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
125460 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
125461 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
125462 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
125463 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
125464 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
125465 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
125466 +recover_peb_29238 recover_peb 0 29238 NULL
125467 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
125468 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
125469 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
125470 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
125471 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
125472 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
125473 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
125474 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
125475 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
125476 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
125477 +tun_put_user_29337 tun_put_user 5 29337 NULL
125478 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
125479 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
125480 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
125481 +mempool_create_29437 mempool_create 1 29437 NULL
125482 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
125483 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
125484 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
125485 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
125486 +do_register_entry_29478 do_register_entry 4 29478 NULL
125487 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
125488 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
125489 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
125490 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
125491 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
125492 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
125493 +ftrace_write_29551 ftrace_write 3 29551 NULL
125494 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
125495 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
125496 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
125497 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
125498 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
125499 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
125500 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
125501 +slots_per_page_29601 slots_per_page 0 29601 NULL
125502 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
125503 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
125504 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
125505 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
125506 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
125507 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
125508 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
125509 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
125510 +probes_write_29711 probes_write 3 29711 NULL
125511 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
125512 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
125513 +std_nic_write_29752 std_nic_write 3 29752 NULL
125514 +static_key_count_29771 static_key_count 0 29771 NULL
125515 +dbAlloc_29794 dbAlloc 0 29794 NULL
125516 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
125517 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
125518 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
125519 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
125520 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
125521 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
125522 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
125523 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
125524 +write_file_queue_29922 write_file_queue 3 29922 NULL
125525 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
125526 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
125527 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
125528 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
125529 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
125530 +drp_wmove_30043 drp_wmove 4 30043 NULL
125531 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
125532 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
125533 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
125534 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
125535 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
125536 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
125537 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
125538 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
125539 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
125540 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
125541 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
125542 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
125543 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
125544 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
125545 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
125546 +compat_readv_30273 compat_readv 3 30273 NULL
125547 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
125548 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
125549 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
125550 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
125551 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
125552 +resource_from_user_30341 resource_from_user 3 30341 NULL
125553 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
125554 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
125555 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
125556 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
125557 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
125558 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
125559 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
125560 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
125561 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
125562 +enable_write_30456 enable_write 3 30456 NULL
125563 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
125564 +urandom_read_30462 urandom_read 3 30462 NULL
125565 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
125566 +adu_write_30487 adu_write 3 30487 NULL
125567 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
125568 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
125569 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
125570 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
125571 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
125572 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
125573 +set_le_30581 set_le 4 30581 NULL
125574 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
125575 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
125576 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
125577 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
125578 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
125579 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
125580 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
125581 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
125582 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
125583 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
125584 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
125585 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
125586 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
125587 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 3-4 30727 NULL
125588 +snapshot_status_30744 snapshot_status 5 30744 NULL
125589 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
125590 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
125591 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
125592 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
125593 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
125594 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
125595 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
125596 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
125597 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
125598 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
125599 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
125600 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
125601 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
125602 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
125603 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
125604 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
125605 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
125606 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
125607 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
125608 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
125609 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
125610 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
125611 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
125612 +depth_read_31112 depth_read 3 31112 NULL
125613 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
125614 +size_inside_page_31141 size_inside_page 0 31141 NULL
125615 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
125616 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
125617 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
125618 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
125619 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
125620 +__read_reg_31216 __read_reg 0 31216 NULL
125621 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
125622 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
125623 +cyy_readb_31240 cyy_readb 0 31240 NULL
125624 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
125625 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
125626 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
125627 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
125628 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
125629 +command_file_write_31318 command_file_write 3 31318 NULL
125630 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
125631 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
125632 +outlen_write_31358 outlen_write 3 31358 NULL
125633 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
125634 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
125635 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
125636 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
125637 +inb_31388 inb 0 31388 NULL
125638 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
125639 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
125640 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
125641 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
125642 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
125643 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
125644 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
125645 +alg_setkey_31485 alg_setkey 3 31485 NULL
125646 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
125647 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
125648 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
125649 +hidraw_write_31536 hidraw_write 3 31536 NULL
125650 +usbvision_read_31555 usbvision_read 3 31555 NULL
125651 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
125652 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
125653 +osst_write_31581 osst_write 3 31581 NULL
125654 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
125655 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
125656 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
125657 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
125658 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
125659 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
125660 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
125661 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
125662 +__lgread_31668 __lgread 4 31668 NULL
125663 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
125664 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
125665 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
125666 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
125667 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
125668 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
125669 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
125670 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
125671 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
125672 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
125673 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
125674 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
125675 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
125676 +get_count_order_31800 get_count_order 0 31800 NULL
125677 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
125678 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
125679 +data_write_31805 data_write 3 31805 NULL
125680 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
125681 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
125682 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
125683 +clone_bio_31854 clone_bio 4-3 31854 NULL
125684 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
125685 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
125686 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
125687 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
125688 +xattr_permission_31907 xattr_permission 0 31907 NULL
125689 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
125690 +new_dir_31919 new_dir 3 31919 NULL
125691 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
125692 +era_status_31934 era_status 5 31934 NULL
125693 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
125694 +read_mem_31942 read_mem 3 31942 NULL
125695 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
125696 +vb2_write_31948 vb2_write 3 31948 NULL
125697 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
125698 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
125699 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
125700 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
125701 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
125702 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
125703 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
125704 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
125705 +calc_hmac_32010 calc_hmac 3 32010 NULL
125706 +aead_len_32021 aead_len 0 32021 NULL
125707 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
125708 +stk_read_32038 stk_read 3 32038 NULL
125709 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
125710 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
125711 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
125712 +bio_alloc_32095 bio_alloc 2 32095 NULL
125713 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
125714 +disk_status_32120 disk_status 4 32120 NULL
125715 +venus_link_32165 venus_link 5 32165 NULL
125716 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
125717 +do_writepages_32173 do_writepages 0 32173 NULL
125718 +del_ptr_32197 del_ptr 4 32197 NULL
125719 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
125720 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
125721 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
125722 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
125723 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
125724 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
125725 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
125726 +SyS_select_32319 SyS_select 1 32319 NULL
125727 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
125728 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
125729 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
125730 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
125731 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
125732 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
125733 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
125734 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
125735 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
125736 +cache_status_32462 cache_status 5 32462 NULL
125737 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
125738 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
125739 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
125740 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
125741 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
125742 +disconnect_32521 disconnect 4 32521 NULL
125743 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
125744 +ilo_read_32531 ilo_read 3 32531 NULL
125745 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
125746 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
125747 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
125748 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
125749 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
125750 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
125751 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
125752 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
125753 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
125754 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
125755 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
125756 +kvmalloc_32646 kvmalloc 1 32646 NULL
125757 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
125758 +generic_readlink_32654 generic_readlink 3 32654 NULL
125759 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
125760 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
125761 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
125762 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
125763 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
125764 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
125765 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
125766 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
125767 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
125768 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
125769 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
125770 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
125771 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
125772 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
125773 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
125774 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
125775 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
125776 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
125777 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
125778 +compat_filldir_32999 compat_filldir 3 32999 NULL
125779 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
125780 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
125781 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
125782 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
125783 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
125784 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
125785 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
125786 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
125787 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
125788 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
125789 +alloc_tio_33077 alloc_tio 3 33077 NULL
125790 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
125791 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
125792 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
125793 +SyS_poll_33152 SyS_poll 2 33152 NULL
125794 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
125795 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
125796 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
125797 +pp_read_33210 pp_read 3 33210 NULL
125798 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
125799 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
125800 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
125801 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
125802 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
125803 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
125804 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
125805 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
125806 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
125807 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
125808 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
125809 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
125810 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
125811 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
125812 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 2-3 33394 NULL
125813 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
125814 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
125815 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
125816 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
125817 +message_stats_list_33440 message_stats_list 5 33440 NULL
125818 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
125819 +create_entry_33479 create_entry 2 33479 NULL
125820 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
125821 +res_counter_read_33499 res_counter_read 4 33499 NULL
125822 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
125823 +fb_read_33506 fb_read 3 33506 NULL
125824 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
125825 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
125826 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
125827 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
125828 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
125829 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
125830 +count_subheaders_33591 count_subheaders 0 33591 NULL
125831 +scsi_execute_33596 scsi_execute 5 33596 NULL
125832 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
125833 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
125834 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
125835 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
125836 +stride_page_count_33641 stride_page_count 2 33641 NULL
125837 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
125838 +inw_p_33668 inw_p 0 33668 NULL
125839 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
125840 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
125841 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
125842 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
125843 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
125844 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
125845 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
125846 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
125847 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
125848 +hashtab_create_33769 hashtab_create 3 33769 NULL
125849 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
125850 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
125851 +filter_write_33819 filter_write 3 33819 NULL
125852 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
125853 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
125854 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
125855 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
125856 +get_user_pages_33908 get_user_pages 0 33908 NULL
125857 +sg_nents_33909 sg_nents 0 33909 NULL
125858 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
125859 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
125860 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
125861 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
125862 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
125863 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
125864 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
125865 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
125866 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
125867 +ppp_write_34034 ppp_write 3 34034 NULL
125868 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
125869 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
125870 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
125871 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
125872 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
125873 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
125874 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
125875 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
125876 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
125877 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
125878 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
125879 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
125880 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
125881 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
125882 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
125883 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
125884 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
125885 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
125886 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
125887 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
125888 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
125889 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 NULL nohasharray
125890 +ea_read_34378 ea_read 0 34378 &_iwl_dbgfs_low_latency_write_34378
125891 +fuse_send_read_34379 fuse_send_read 4-0 34379 NULL
125892 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
125893 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
125894 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
125895 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
125896 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
125897 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
125898 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
125899 +security_socket_create_34439 security_socket_create 0 34439 NULL
125900 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
125901 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
125902 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
125903 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
125904 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
125905 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
125906 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
125907 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
125908 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL nohasharray
125909 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 &tracing_stats_read_34537
125910 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
125911 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
125912 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL nohasharray
125913 +self_check_peb_ec_hdr_34564 self_check_peb_ec_hdr 0 34564 &alloc_ieee80211_rsl_34564
125914 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
125915 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
125916 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
125917 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
125918 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
125919 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
125920 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
125921 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL nohasharray
125922 +mtd_write_34609 mtd_write 0 34609 &__jffs2_ref_totlen_34609
125923 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
125924 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
125925 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
125926 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
125927 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
125928 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
125929 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
125930 +port_print_34704 port_print 3 34704 NULL
125931 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
125932 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
125933 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
125934 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
125935 +bootmode_store_34762 bootmode_store 4 34762 NULL
125936 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
125937 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
125938 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
125939 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
125940 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
125941 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
125942 +file_page_index_34820 file_page_index 0-2 34820 NULL
125943 +bio_segments_34832 bio_segments 0 34832 NULL
125944 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
125945 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
125946 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
125947 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
125948 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
125949 +msg_print_text_34889 msg_print_text 0 34889 NULL
125950 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
125951 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
125952 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
125953 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
125954 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
125955 +do_add_page_to_bio_34974 do_add_page_to_bio 10-2 34974 NULL
125956 +schedule_erase_34996 schedule_erase 0 34996 NULL
125957 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
125958 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
125959 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
125960 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
125961 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
125962 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
125963 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
125964 +capi_write_35104 capi_write 3 35104 NULL nohasharray
125965 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
125966 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
125967 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
125968 +message_stats_print_35158 message_stats_print 6 35158 NULL
125969 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
125970 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
125971 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
125972 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
125973 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
125974 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
125975 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
125976 +set_fd_set_35249 set_fd_set 1 35249 NULL
125977 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
125978 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
125979 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
125980 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
125981 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
125982 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
125983 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
125984 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
125985 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
125986 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
125987 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
125988 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
125989 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
125990 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
125991 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
125992 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
125993 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
125994 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
125995 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
125996 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
125997 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
125998 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
125999 +async_setkey_35521 async_setkey 3 35521 NULL
126000 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
126001 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
126002 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
126003 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
126004 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
126005 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
126006 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
126007 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
126008 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
126009 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
126010 +kernel_readv_35617 kernel_readv 3 35617 NULL
126011 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
126012 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
126013 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
126014 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
126015 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
126016 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
126017 +md_super_write_35703 md_super_write 4 35703 NULL
126018 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
126019 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
126020 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
126021 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
126022 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
126023 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
126024 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
126025 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
126026 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
126027 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
126028 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
126029 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
126030 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
126031 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
126032 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
126033 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
126034 +acl_alloc_35979 acl_alloc 1 35979 NULL
126035 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
126036 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
126037 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
126038 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
126039 +ubi_eba_write_leb_36029 ubi_eba_write_leb 0 36029 NULL
126040 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
126041 +account_shadowed_36048 account_shadowed 2 36048 NULL
126042 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
126043 +write_emulate_36065 write_emulate 2-4 36065 NULL
126044 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
126045 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
126046 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
126047 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
126048 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
126049 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
126050 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
126051 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
126052 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
126053 +twl_set_36154 twl_set 2 36154 NULL
126054 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
126055 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
126056 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
126057 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
126058 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
126059 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
126060 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
126061 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
126062 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
126063 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
126064 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
126065 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
126066 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
126067 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
126068 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
126069 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
126070 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 NULL nohasharray
126071 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 &__compat_sys_pwritev64_36328
126072 +lc_create_36332 lc_create 4 36332 NULL
126073 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
126074 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
126075 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
126076 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
126077 +to_sector_36361 to_sector 0-1 36361 NULL
126078 +tunables_read_36385 tunables_read 3 36385 NULL
126079 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
126080 +sierra_write_36402 sierra_write 4 36402 NULL
126081 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
126082 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
126083 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
126084 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
126085 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
126086 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL
126087 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
126088 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
126089 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
126090 +get_param_l_36518 get_param_l 0 36518 NULL
126091 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
126092 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
126093 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
126094 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
126095 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
126096 +__erst_read_36579 __erst_read 0 36579 NULL
126097 +put_cmsg_36589 put_cmsg 4 36589 NULL
126098 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
126099 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
126100 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
126101 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
126102 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
126103 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
126104 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
126105 +xillybus_read_36678 xillybus_read 3 36678 NULL
126106 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
126107 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
126108 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
126109 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
126110 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
126111 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
126112 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
126113 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
126114 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
126115 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
126116 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
126117 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
126118 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
126119 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
126120 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
126121 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
126122 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
126123 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
126124 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
126125 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
126126 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
126127 +setxattr_37006 setxattr 4 37006 NULL
126128 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
126129 +command_file_read_37038 command_file_read 3 37038 NULL
126130 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
126131 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
126132 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
126133 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
126134 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
126135 +parse_command_37079 parse_command 2 37079 NULL
126136 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
126137 +tun_get_user_37094 tun_get_user 5 37094 NULL
126138 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
126139 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
126140 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
126141 +msg_word_37164 msg_word 0 37164 NULL
126142 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
126143 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
126144 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
126145 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
126146 +__do_replace_37227 __do_replace 5 37227 NULL
126147 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
126148 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 NULL nohasharray
126149 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 &__btrfs_inc_extent_ref_37238
126150 +prot_queue_del_37258 prot_queue_del 0 37258 NULL
126151 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
126152 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
126153 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
126154 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
126155 +tipc_send_37315 tipc_send 3 37315 NULL
126156 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
126157 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
126158 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
126159 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
126160 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
126161 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL nohasharray
126162 +find_next_bit_37422 find_next_bit 0 37422 &acpi_os_allocate_zeroed_37422
126163 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
126164 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 7-9-0 37433 NULL
126165 +fru_alloc_37442 fru_alloc 1 37442 NULL
126166 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
126167 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
126168 +get_est_timing_37484 get_est_timing 0 37484 NULL
126169 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
126170 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
126171 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
126172 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
126173 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
126174 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
126175 +hdr_size_37536 hdr_size 0 37536 NULL
126176 +extent_map_end_37550 extent_map_end 0 37550 NULL
126177 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
126178 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
126179 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
126180 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
126181 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
126182 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
126183 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
126184 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
126185 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
126186 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
126187 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
126188 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
126189 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
126190 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
126191 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
126192 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
126193 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
126194 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
126195 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
126196 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
126197 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
126198 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
126199 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
126200 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
126201 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
126202 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
126203 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
126204 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
126205 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
126206 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
126207 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
126208 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
126209 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
126210 +write_file_bool_37957 write_file_bool 3 37957 NULL
126211 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
126212 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
126213 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
126214 +vfs_readv_38011 vfs_readv 3 38011 NULL
126215 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
126216 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
126217 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
126218 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
126219 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
126220 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
126221 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
126222 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
126223 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
126224 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
126225 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
126226 +ep0_read_38095 ep0_read 3 38095 NULL
126227 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
126228 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
126229 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
126230 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
126231 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
126232 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
126233 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
126234 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
126235 +cdev_add_38176 cdev_add 2-3 38176 NULL
126236 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
126237 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
126238 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
126239 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
126240 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
126241 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
126242 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
126243 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 NULL nohasharray
126244 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 &xfs_bmdr_to_bmbt_38275
126245 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
126246 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
126247 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
126248 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
126249 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
126250 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
126251 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
126252 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
126253 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
126254 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
126255 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
126256 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
126257 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
126258 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
126259 +dev_names_read_38509 dev_names_read 3 38509 NULL
126260 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
126261 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
126262 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
126263 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
126264 +kuc_len_38557 kuc_len 0-1 38557 NULL
126265 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
126266 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
126267 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
126268 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 3-5 38567 NULL
126269 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
126270 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
126271 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
126272 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
126273 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
126274 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
126275 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
126276 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
126277 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
126278 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
126279 +validate_vid_hdr_38699 validate_vid_hdr 0 38699 NULL
126280 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
126281 +udf_readpages_38761 udf_readpages 4 38761 NULL
126282 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
126283 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
126284 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
126285 +err_decode_38804 err_decode 2 38804 NULL
126286 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
126287 +direct_entry_38836 direct_entry 3 38836 NULL
126288 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
126289 +interfaces_38859 interfaces 2 38859 NULL
126290 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
126291 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
126292 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
126293 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 NULL nohasharray
126294 +usb_maxpacket_38977 usb_maxpacket 0 38977 &C_SYSC_preadv64_38977
126295 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
126296 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
126297 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
126298 +get_nodes_39012 get_nodes 3 39012 NULL
126299 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
126300 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
126301 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
126302 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
126303 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
126304 +leb_write_lock_39111 leb_write_lock 0 39111 NULL
126305 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
126306 +ea_foreach_39133 ea_foreach 0 39133 NULL
126307 +generic_permission_39150 generic_permission 0 39150 NULL
126308 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
126309 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
126310 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
126311 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
126312 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
126313 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
126314 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
126315 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
126316 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
126317 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
126318 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
126319 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
126320 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
126321 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
126322 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
126323 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
126324 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
126325 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
126326 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
126327 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
126328 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
126329 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
126330 +__send_to_port_39386 __send_to_port 3 39386 NULL
126331 +user_power_read_39414 user_power_read 3 39414 NULL
126332 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
126333 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
126334 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
126335 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
126336 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
126337 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
126338 +int_proc_write_39542 int_proc_write 3 39542 NULL
126339 +ext4_alloc_file_blocks_39551 ext4_alloc_file_blocks 3 39551 NULL
126340 +pp_write_39554 pp_write 3 39554 NULL
126341 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
126342 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
126343 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
126344 +ext_depth_39607 ext_depth 0 39607 NULL
126345 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
126346 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
126347 +sdio_readb_39618 sdio_readb 0 39618 NULL
126348 +set_dev_class_39645 set_dev_class 4 39645 NULL
126349 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
126350 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
126351 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
126352 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
126353 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
126354 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
126355 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
126356 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
126357 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
126358 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
126359 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
126360 +pkt_add_39897 pkt_add 3 39897 NULL
126361 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
126362 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
126363 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
126364 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
126365 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
126366 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
126367 +__spi_async_39932 __spi_async 0 39932 NULL
126368 +__get_order_39935 __get_order 0 39935 NULL
126369 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
126370 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
126371 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
126372 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
126373 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
126374 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
126375 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
126376 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
126377 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
126378 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
126379 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
126380 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
126381 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
126382 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
126383 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
126384 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
126385 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
126386 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
126387 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
126388 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
126389 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
126390 +pt_write_40159 pt_write 3 40159 NULL
126391 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
126392 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
126393 +allocate_probes_40204 allocate_probes 1 40204 NULL
126394 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
126395 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
126396 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
126397 +osst_read_40237 osst_read 3 40237 NULL
126398 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
126399 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
126400 +of_get_child_count_40254 of_get_child_count 0 40254 NULL
126401 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
126402 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
126403 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
126404 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
126405 +SyS_bind_40303 SyS_bind 3 40303 NULL
126406 +ubi_io_write_data_40305 ubi_io_write_data 0 40305 NULL
126407 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
126408 +mmio_read_40348 mmio_read 4 40348 NULL
126409 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
126410 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 2-3 40365 NULL
126411 +get_chars_40373 get_chars 3 40373 NULL
126412 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
126413 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
126414 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
126415 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
126416 +SyS_writev_40467 SyS_writev 3 40467 NULL
126417 +SyS_select_40473 SyS_select 1 40473 NULL
126418 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
126419 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
126420 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
126421 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
126422 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
126423 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
126424 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
126425 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
126426 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
126427 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
126428 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
126429 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
126430 +fops_read_40672 fops_read 3 40672 NULL
126431 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
126432 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
126433 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
126434 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
126435 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
126436 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
126437 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
126438 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
126439 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
126440 +card_send_command_40757 card_send_command 3 40757 NULL
126441 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
126442 +pg_write_40766 pg_write 3 40766 NULL
126443 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
126444 +show_list_40775 show_list 3-0 40775 NULL
126445 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
126446 +bitmap_weight_40791 bitmap_weight 0 40791 NULL
126447 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
126448 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
126449 +add_action_40811 add_action 4 40811 NULL
126450 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
126451 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
126452 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
126453 +read_file_queue_40895 read_file_queue 3 40895 NULL
126454 +waiters_read_40902 waiters_read 3 40902 NULL
126455 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
126456 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
126457 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
126458 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
126459 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
126460 +insert_old_idx_40987 insert_old_idx 0 40987 NULL
126461 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
126462 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
126463 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
126464 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
126465 +mtd_block_isbad_41015 mtd_block_isbad 0 41015 NULL
126466 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
126467 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
126468 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
126469 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
126470 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
126471 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
126472 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
126473 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
126474 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
126475 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
126476 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
126477 +dma_attach_41094 dma_attach 5-6 41094 NULL
126478 +provide_user_output_41105 provide_user_output 3 41105 NULL
126479 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
126480 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
126481 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
126482 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
126483 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
126484 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
126485 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
126486 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
126487 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
126488 +erst_read_41260 erst_read 0 41260 NULL
126489 +alloc_context_41283 alloc_context 1 41283 NULL
126490 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
126491 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
126492 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
126493 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
126494 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
126495 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
126496 +kmp_init_41373 kmp_init 2 41373 NULL
126497 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
126498 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
126499 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
126500 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
126501 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
126502 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
126503 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
126504 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
126505 +se_io_cb_41461 se_io_cb 3 41461 NULL
126506 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
126507 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
126508 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
126509 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
126510 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
126511 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
126512 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
126513 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
126514 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
126515 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
126516 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
126517 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 NULL nohasharray
126518 +nr_status_frames_41559 nr_status_frames 0-1 41559 &si476x_radio_fops_read_41559
126519 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
126520 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
126521 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
126522 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
126523 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 NULL nohasharray
126524 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 &usb_endpoint_maxp_41613
126525 +a2mp_send_41615 a2mp_send 4 41615 NULL
126526 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
126527 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
126528 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
126529 +get_std_timing_41654 get_std_timing 0 41654 NULL
126530 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
126531 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
126532 +fillonedir_41746 fillonedir 3 41746 NULL
126533 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
126534 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
126535 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
126536 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
126537 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
126538 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
126539 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
126540 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
126541 +pci_map_single_41869 pci_map_single 0 41869 NULL
126542 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
126543 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
126544 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
126545 +read_gssp_41947 read_gssp 3 41947 NULL
126546 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
126547 +portnames_read_41958 portnames_read 3 41958 NULL
126548 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 0 41959 NULL
126549 +dst_mtu_41969 dst_mtu 0 41969 NULL
126550 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
126551 +ubi_io_is_bad_41983 ubi_io_is_bad 0 41983 NULL
126552 +pool_allocate_42012 pool_allocate 3 42012 NULL
126553 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
126554 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
126555 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
126556 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
126557 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
126558 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
126559 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
126560 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
126561 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
126562 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
126563 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
126564 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
126565 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
126566 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
126567 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
126568 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
126569 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
126570 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
126571 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
126572 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL nohasharray
126573 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 &pla_ocp_read_42235
126574 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
126575 +find_last_bit_42260 find_last_bit 0 42260 NULL
126576 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
126577 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
126578 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
126579 +__cpus_weight_42299 __cpus_weight 0 42299 NULL
126580 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
126581 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
126582 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
126583 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
126584 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
126585 +tcp_sync_mss_42330 tcp_sync_mss 0-2 42330 NULL
126586 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
126587 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
126588 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
126589 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
126590 +krng_get_random_42420 krng_get_random 3 42420 NULL
126591 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
126592 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
126593 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
126594 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
126595 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
126596 +kuc_free_42455 kuc_free 2 42455 NULL
126597 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
126598 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
126599 +bypass_write_42498 bypass_write 3 42498 NULL
126600 +SyS_mincore_42511 SyS_mincore 2-1 42511 NULL
126601 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
126602 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
126603 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
126604 +self_check_ec_hdr_42528 self_check_ec_hdr 0 42528 NULL
126605 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
126606 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
126607 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
126608 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
126609 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
126610 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
126611 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
126612 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
126613 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
126614 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
126615 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
126616 +vb2_read_42703 vb2_read 3 42703 NULL
126617 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
126618 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
126619 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
126620 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
126621 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
126622 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
126623 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
126624 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
126625 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
126626 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
126627 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
126628 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
126629 +set_arg_42824 set_arg 3 42824 NULL
126630 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
126631 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
126632 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
126633 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
126634 +hd_end_request_42904 hd_end_request 2 42904 NULL
126635 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
126636 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
126637 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
126638 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
126639 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
126640 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
126641 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
126642 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
126643 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
126644 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
126645 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
126646 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
126647 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
126648 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
126649 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
126650 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
126651 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
126652 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
126653 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
126654 +uio_write_43202 uio_write 3 43202 NULL
126655 +iso_callback_43208 iso_callback 3 43208 NULL
126656 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
126657 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
126658 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
126659 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
126660 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
126661 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
126662 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
126663 +evtchn_write_43278 evtchn_write 3 43278 NULL
126664 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
126665 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
126666 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
126667 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
126668 +xenfb_write_43412 xenfb_write 3 43412 NULL
126669 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
126670 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
126671 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
126672 +usb_string_43443 usb_string 0 43443 NULL nohasharray
126673 +usemap_size_43443 usemap_size 0-1-2 43443 &usb_string_43443
126674 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
126675 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
126676 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
126677 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
126678 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
126679 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
126680 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
126681 +read_events_43534 read_events 3 43534 NULL
126682 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
126683 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
126684 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
126685 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
126686 +proc_read_43614 proc_read 3 43614 NULL
126687 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
126688 +random_write_43656 random_write 3 43656 NULL
126689 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
126690 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
126691 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
126692 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
126693 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
126694 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
126695 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
126696 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
126697 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
126698 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
126699 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
126700 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
126701 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
126702 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
126703 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
126704 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
126705 +read_flush_43851 read_flush 3 43851 NULL
126706 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
126707 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
126708 +SendString_43928 SendString 3 43928 NULL
126709 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
126710 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
126711 +nla_reserve_43984 nla_reserve 3 43984 NULL
126712 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
126713 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
126714 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992 nohasharray
126715 +scsi_command_size_43992 scsi_command_size 0 43992 &bcm_recvmsg_43992
126716 +emit_flags_44006 emit_flags 4-3 44006 NULL
126717 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
126718 +fru_strlen_44046 fru_strlen 0 44046 NULL
126719 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
126720 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
126721 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
126722 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
126723 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
126724 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
126725 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
126726 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
126727 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
126728 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
126729 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
126730 +ubifs_find_dirty_idx_leb_44169 ubifs_find_dirty_idx_leb 0 44169 NULL
126731 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
126732 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
126733 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
126734 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
126735 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
126736 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
126737 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
126738 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
126739 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
126740 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
126741 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
126742 +rs_init_44327 rs_init 1 44327 NULL
126743 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
126744 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
126745 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
126746 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
126747 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
126748 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
126749 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
126750 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
126751 +write_file_debug_44476 write_file_debug 3 44476 NULL
126752 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
126753 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
126754 +bio_advance_44496 bio_advance 2 44496 NULL
126755 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
126756 +ac_register_board_44504 ac_register_board 3 44504 NULL
126757 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
126758 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
126759 +spidev_write_44510 spidev_write 3 44510 NULL
126760 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
126761 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
126762 +comm_write_44537 comm_write 3 44537 NULL
126763 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
126764 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
126765 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
126766 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
126767 +mpi_resize_44674 mpi_resize 2 44674 NULL
126768 +ts_read_44687 ts_read 3 44687 NULL
126769 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
126770 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
126771 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
126772 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
126773 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
126774 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
126775 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
126776 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
126777 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
126778 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
126779 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
126780 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
126781 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
126782 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
126783 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
126784 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
126785 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
126786 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
126787 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
126788 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
126789 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
126790 +sisusb_write_44834 sisusb_write 3 44834 NULL
126791 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
126792 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
126793 +copydesc_user_44855 copydesc_user 3 44855 NULL
126794 +set_advertising_44870 set_advertising 4 44870 NULL
126795 +init_rs_44873 init_rs 1 44873 NULL
126796 +skb_availroom_44883 skb_availroom 0 44883 NULL
126797 +do_tty_write_44896 do_tty_write 5 44896 NULL
126798 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
126799 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
126800 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
126801 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
126802 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
126803 +sel_write_user_45060 sel_write_user 3 45060 NULL
126804 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
126805 +snd_card_new_45104 snd_card_new 5 45104 NULL
126806 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
126807 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
126808 +usbdev_read_45114 usbdev_read 3 45114 NULL
126809 +send_to_tty_45141 send_to_tty 3 45141 NULL
126810 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
126811 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
126812 +device_write_45156 device_write 3 45156 NULL nohasharray
126813 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
126814 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
126815 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
126816 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 NULL nohasharray
126817 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 &sctp_pack_cookie_45190
126818 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
126819 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
126820 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
126821 +event_enable_write_45238 event_enable_write 3 45238 NULL
126822 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
126823 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
126824 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
126825 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
126826 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
126827 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
126828 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
126829 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
126830 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
126831 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
126832 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
126833 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
126834 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
126835 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
126836 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
126837 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
126838 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
126839 +copy_macs_45534 copy_macs 4 45534 NULL
126840 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
126841 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
126842 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
126843 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
126844 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
126845 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
126846 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
126847 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
126848 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
126849 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
126850 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
126851 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
126852 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
126853 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
126854 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
126855 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
126856 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
126857 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
126858 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
126859 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
126860 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
126861 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
126862 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
126863 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
126864 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
126865 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
126866 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
126867 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
126868 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
126869 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
126870 +isdn_write_45863 isdn_write 3 45863 NULL
126871 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
126872 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
126873 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
126874 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
126875 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
126876 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
126877 +alloc_mr_45935 alloc_mr 1 45935 NULL
126878 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
126879 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
126880 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
126881 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
126882 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
126883 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
126884 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
126885 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
126886 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
126887 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
126888 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
126889 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
126890 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
126891 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
126892 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
126893 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
126894 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
126895 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
126896 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
126897 +fq_resize_46195 fq_resize 2 46195 NULL
126898 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
126899 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
126900 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
126901 +dsp_write_46218 dsp_write 2 46218 NULL
126902 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
126903 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
126904 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
126905 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
126906 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
126907 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 NULL nohasharray
126908 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 &compat_SyS_readv_46328
126909 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
126910 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
126911 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
126912 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
126913 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
126914 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
126915 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
126916 +filldir64_46469 filldir64 3 46469 NULL
126917 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
126918 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
126919 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
126920 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
126921 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
126922 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
126923 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
126924 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
126925 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
126926 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
126927 +il3945_stats_flag_46606 il3945_stats_flag 3-0 46606 NULL
126928 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
126929 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
126930 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
126931 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
126932 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
126933 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
126934 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
126935 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
126936 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
126937 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
126938 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
126939 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
126940 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
126941 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
126942 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
126943 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
126944 +spi_async_46857 spi_async 0 46857 NULL
126945 +vsnprintf_46863 vsnprintf 0 46863 NULL
126946 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
126947 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
126948 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
126949 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
126950 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
126951 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
126952 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
126953 +fb_write_46924 fb_write 3 46924 NULL
126954 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
126955 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
126956 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
126957 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
126958 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
126959 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
126960 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
126961 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
126962 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
126963 +fs_path_len_47060 fs_path_len 0 47060 NULL
126964 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
126965 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
126966 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
126967 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
126968 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
126969 +mousedev_read_47123 mousedev_read 3 47123 NULL
126970 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
126971 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
126972 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
126973 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
126974 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
126975 +options_write_47243 options_write 3 47243 NULL
126976 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
126977 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
126978 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
126979 +vsnprintf_47291 vsnprintf 0 47291 NULL
126980 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
126981 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
126982 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
126983 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
126984 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
126985 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
126986 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
126987 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
126988 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
126989 +nametbl_list_47391 nametbl_list 2 47391 NULL
126990 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
126991 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
126992 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
126993 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
126994 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
126995 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
126996 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
126997 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
126998 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
126999 +newpart_47485 newpart 6-4 47485 NULL
127000 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
127001 +core_sys_select_47494 core_sys_select 1 47494 NULL
127002 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
127003 +unlink_simple_47506 unlink_simple 3 47506 NULL
127004 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
127005 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
127006 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
127007 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
127008 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
127009 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
127010 +read_ldt_47570 read_ldt 2 47570 NULL
127011 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
127012 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
127013 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
127014 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
127015 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
127016 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
127017 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
127018 +get_size_47644 get_size 1-2 47644 NULL
127019 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
127020 +save_microcode_47717 save_microcode 3 47717 NULL
127021 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
127022 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
127023 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
127024 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
127025 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
127026 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
127027 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
127028 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
127029 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
127030 +lov_packmd_47810 lov_packmd 0 47810 NULL
127031 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
127032 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
127033 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
127034 +vhci_read_47878 vhci_read 3 47878 NULL
127035 +ubi_wl_put_peb_47886 ubi_wl_put_peb 0 47886 NULL
127036 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
127037 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
127038 +comedi_write_47926 comedi_write 3 47926 NULL
127039 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
127040 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
127041 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
127042 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
127043 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
127044 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
127045 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
127046 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
127047 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
127048 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
127049 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
127050 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
127051 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
127052 +disc_write_48070 disc_write 3 48070 NULL
127053 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
127054 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
127055 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
127056 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
127057 +set_discoverable_48141 set_discoverable 4 48141 NULL
127058 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
127059 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
127060 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
127061 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
127062 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
127063 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
127064 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
127065 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
127066 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
127067 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
127068 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
127069 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
127070 +read_file_recv_48232 read_file_recv 3 48232 NULL
127071 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
127072 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
127073 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
127074 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
127075 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
127076 +trace_options_write_48275 trace_options_write 3 48275 NULL
127077 +send_set_info_48288 send_set_info 7 48288 NULL
127078 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
127079 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
127080 +hash_setkey_48310 hash_setkey 3 48310 NULL
127081 +skb_add_data_48363 skb_add_data 3 48363 NULL
127082 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
127083 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
127084 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
127085 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
127086 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
127087 +print_filtered_48442 print_filtered 2-0 48442 NULL
127088 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
127089 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
127090 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
127091 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
127092 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
127093 +send_control_msg_48498 send_control_msg 6 48498 NULL
127094 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
127095 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
127096 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
127097 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
127098 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
127099 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
127100 +llog_data_len_48607 llog_data_len 1 48607 NULL
127101 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
127102 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
127103 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
127104 +mtd_read_48655 mtd_read 0 48655 NULL
127105 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
127106 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
127107 +ubi_eba_unmap_leb_48671 ubi_eba_unmap_leb 0 48671 NULL
127108 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
127109 +altera_drscan_48698 altera_drscan 2 48698 NULL
127110 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
127111 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
127112 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
127113 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
127114 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
127115 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
127116 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
127117 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
127118 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
127119 +azx_get_position_48841 azx_get_position 0 48841 NULL
127120 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
127121 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
127122 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
127123 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
127124 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
127125 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
127126 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
127127 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
127128 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
127129 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
127130 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
127131 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
127132 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
127133 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
127134 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
127135 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
127136 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
127137 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
127138 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
127139 +transient_status_49027 transient_status 4 49027 NULL
127140 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
127141 +scsi_register_49094 scsi_register 2 49094 NULL
127142 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
127143 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
127144 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
127145 +pt_read_49136 pt_read 3 49136 NULL
127146 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
127147 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
127148 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
127149 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
127150 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
127151 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
127152 +print_queue_49191 print_queue 4-0 49191 NULL
127153 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
127154 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
127155 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
127156 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
127157 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
127158 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
127159 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
127160 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
127161 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
127162 +uio_read_49300 uio_read 3 49300 NULL
127163 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
127164 +SYSC_mincore_49319 SYSC_mincore 1-2 49319 NULL
127165 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
127166 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
127167 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
127168 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
127169 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
127170 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
127171 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
127172 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
127173 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
127174 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
127175 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
127176 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
127177 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
127178 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
127179 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
127180 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
127181 +smk_write_access_49561 smk_write_access 3 49561 NULL
127182 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
127183 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
127184 +tap_write_49595 tap_write 3 49595 NULL
127185 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
127186 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
127187 +heap_init_49617 heap_init 2 49617 NULL
127188 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
127189 +port_fops_read_49626 port_fops_read 3 49626 NULL
127190 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
127191 +__swab32p_49657 __swab32p 0 49657 NULL
127192 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
127193 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
127194 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
127195 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
127196 +write_pool_49718 write_pool 3 49718 NULL
127197 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
127198 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
127199 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
127200 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
127201 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
127202 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
127203 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
127204 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
127205 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
127206 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
127207 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 6-3-0 49829 NULL
127208 +add_uuid_49831 add_uuid 4 49831 NULL
127209 +twl4030_write_49846 twl4030_write 2 49846 NULL
127210 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
127211 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
127212 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
127213 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
127214 +osc_brw_49896 osc_brw 4 49896 NULL
127215 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
127216 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
127217 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
127218 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
127219 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
127220 +isdn_read_50021 isdn_read 3 50021 NULL
127221 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
127222 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
127223 +ioread8_50049 ioread8 0 50049 NULL
127224 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
127225 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
127226 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
127227 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
127228 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
127229 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
127230 +read_file_slot_50111 read_file_slot 3 50111 NULL
127231 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
127232 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
127233 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
127234 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
127235 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
127236 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
127237 +odev_update_50169 odev_update 2 50169 NULL
127238 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 NULL nohasharray
127239 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 &ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172
127240 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
127241 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
127242 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
127243 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
127244 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
127245 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
127246 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
127247 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
127248 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
127249 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
127250 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
127251 +do_launder_page_50329 do_launder_page 0 50329 NULL
127252 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
127253 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
127254 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
127255 +tpm_read_50344 tpm_read 3 50344 NULL
127256 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
127257 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
127258 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
127259 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
127260 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
127261 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
127262 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
127263 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
127264 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
127265 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
127266 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
127267 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
127268 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
127269 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
127270 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
127271 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
127272 +self_check_peb_vid_hdr_50563 self_check_peb_vid_hdr 0 50563 NULL
127273 +fat_readpages_50582 fat_readpages 4 50582 NULL
127274 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
127275 +xillybus_write_50605 xillybus_write 3 50605 NULL
127276 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
127277 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
127278 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
127279 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
127280 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
127281 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
127282 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
127283 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
127284 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
127285 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
127286 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
127287 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
127288 +tpm_write_50798 tpm_write 3 50798 NULL
127289 +tun_do_read_50800 tun_do_read 4 50800 NULL
127290 +write_flush_50803 write_flush 3 50803 NULL
127291 +dvb_play_50814 dvb_play 3 50814 NULL
127292 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
127293 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
127294 +SetArea_50835 SetArea 4 50835 NULL
127295 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
127296 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
127297 +self_check_write_50856 self_check_write 0 50856 NULL
127298 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
127299 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
127300 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
127301 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
127302 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
127303 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
127304 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
127305 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
127306 +show_device_status_50947 show_device_status 0 50947 NULL
127307 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
127308 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
127309 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
127310 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
127311 +iwl_statistics_flag_50981 iwl_statistics_flag 3-0 50981 NULL
127312 +timeout_write_50991 timeout_write 3 50991 NULL
127313 +proc_write_51003 proc_write 3 51003 NULL
127314 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
127315 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
127316 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
127317 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
127318 +dump_midi_51040 dump_midi 3 51040 NULL
127319 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
127320 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
127321 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
127322 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
127323 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
127324 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
127325 +ti_recv_51110 ti_recv 3 51110 NULL
127326 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
127327 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
127328 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
127329 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
127330 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
127331 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
127332 +drm_property_create_51239 drm_property_create 4 51239 NULL
127333 +st_read_51251 st_read 3 51251 NULL
127334 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
127335 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
127336 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
127337 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
127338 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
127339 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
127340 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
127341 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
127342 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
127343 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
127344 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
127345 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
127346 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
127347 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
127348 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
127349 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
127350 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
127351 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
127352 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
127353 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
127354 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
127355 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
127356 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
127357 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
127358 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
127359 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
127360 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
127361 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
127362 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
127363 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
127364 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
127365 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
127366 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
127367 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
127368 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
127369 +sel_write_access_51704 sel_write_access 3 51704 NULL
127370 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
127371 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
127372 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
127373 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
127374 +cm4040_read_51732 cm4040_read 3 51732 NULL
127375 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
127376 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
127377 +if_write_51756 if_write 3 51756 NULL
127378 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
127379 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
127380 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
127381 +ioread32_51847 ioread32 0 51847 NULL nohasharray
127382 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
127383 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
127384 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
127385 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
127386 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
127387 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
127388 +user_read_51881 user_read 3 51881 NULL
127389 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
127390 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
127391 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
127392 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
127393 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
127394 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
127395 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
127396 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
127397 +get_zone_51981 get_zone 0-1 51981 NULL
127398 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
127399 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
127400 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
127401 +rdmalt_52022 rdmalt 0 52022 NULL
127402 +override_release_52032 override_release 2 52032 NULL
127403 +end_port_52042 end_port 0 52042 NULL
127404 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
127405 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
127406 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
127407 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
127408 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
127409 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
127410 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
127411 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
127412 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
127413 +retry_count_read_52129 retry_count_read 3 52129 NULL
127414 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
127415 +sub_alloc_52140 sub_alloc 0 52140 NULL
127416 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
127417 +htable_size_52148 htable_size 0-1 52148 NULL
127418 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
127419 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
127420 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
127421 +print_prefix_52176 print_prefix 0 52176 NULL
127422 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
127423 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
127424 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
127425 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
127426 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
127427 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
127428 +shrink_slab_52261 shrink_slab 2 52261 NULL
127429 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
127430 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
127431 +read_file_reset_52310 read_file_reset 3 52310 NULL
127432 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
127433 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
127434 +hwflags_read_52318 hwflags_read 3 52318 NULL
127435 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
127436 +hur_len_52339 hur_len 0 52339 NULL
127437 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
127438 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
127439 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
127440 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
127441 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
127442 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
127443 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
127444 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
127445 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
127446 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
127447 +delay_status_52431 delay_status 5 52431 NULL
127448 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
127449 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
127450 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
127451 +bt_alloc_52457 bt_alloc 2 52457 NULL
127452 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
127453 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
127454 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
127455 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
127456 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
127457 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
127458 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
127459 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
127460 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
127461 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
127462 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
127463 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
127464 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
127465 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
127466 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
127467 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
127468 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
127469 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
127470 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
127471 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
127472 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
127473 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
127474 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
127475 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
127476 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
127477 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
127478 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
127479 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
127480 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
127481 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
127482 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
127483 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
127484 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
127485 +twlreg_write_52880 twlreg_write 3 52880 NULL
127486 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
127487 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
127488 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
127489 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
127490 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
127491 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
127492 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
127493 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
127494 +num_node_state_52989 num_node_state 0 52989 NULL
127495 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
127496 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
127497 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
127498 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
127499 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
127500 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
127501 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
127502 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
127503 +verity_status_53120 verity_status 5 53120 NULL
127504 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
127505 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
127506 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
127507 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
127508 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
127509 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
127510 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
127511 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
127512 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
127513 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
127514 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
127515 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
127516 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
127517 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
127518 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
127519 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
127520 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
127521 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
127522 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
127523 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
127524 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
127525 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
127526 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
127527 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
127528 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
127529 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
127530 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
127531 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
127532 +check_acl_53512 check_acl 0 53512 NULL nohasharray
127533 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
127534 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
127535 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
127536 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
127537 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
127538 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
127539 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
127540 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
127541 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
127542 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
127543 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
127544 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
127545 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
127546 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
127547 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
127548 +wdm_write_53735 wdm_write 3 53735 NULL
127549 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
127550 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
127551 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
127552 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
127553 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
127554 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
127555 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
127556 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
127557 +setup_data_read_53822 setup_data_read 3 53822 NULL
127558 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
127559 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
127560 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
127561 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
127562 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
127563 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
127564 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
127565 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
127566 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
127567 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
127568 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
127569 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
127570 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
127571 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
127572 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
127573 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
127574 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
127575 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
127576 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
127577 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
127578 +strn_len_54122 strn_len 0 54122 NULL
127579 +isku_receive_54130 isku_receive 4 54130 NULL
127580 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
127581 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
127582 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
127583 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
127584 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
127585 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
127586 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
127587 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
127588 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
127589 +reada_add_block_54247 reada_add_block 2 54247 NULL
127590 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
127591 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
127592 +audio_write_54261 audio_write 4 54261 NULL nohasharray
127593 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
127594 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
127595 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
127596 +sizeof_long_54276 sizeof_long 0 54276 NULL
127597 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
127598 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
127599 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
127600 +sprintf_54306 sprintf 0 54306 NULL
127601 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
127602 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
127603 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
127604 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
127605 +readlink_copy_54366 readlink_copy 2 54366 NULL
127606 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
127607 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
127608 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
127609 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
127610 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
127611 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
127612 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
127613 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
127614 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
127615 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
127616 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
127617 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
127618 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
127619 +viacam_read_54526 viacam_read 3 54526 NULL
127620 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
127621 +setsockopt_54539 setsockopt 5 54539 NULL
127622 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
127623 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
127624 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
127625 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
127626 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
127627 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
127628 +port_fops_write_54627 port_fops_write 3 54627 NULL
127629 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
127630 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
127631 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
127632 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
127633 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
127634 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
127635 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
127636 +evm_read_key_54674 evm_read_key 3 54674 NULL
127637 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
127638 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
127639 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
127640 +kzalloc_54740 kzalloc 1 54740 NULL
127641 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
127642 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
127643 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
127644 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
127645 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
127646 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
127647 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
127648 +nfsd_write_54809 nfsd_write 6 54809 NULL
127649 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
127650 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
127651 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
127652 +kvzalloc_54815 kvzalloc 1 54815 &aes_decrypt_fail_read_54815
127653 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
127654 +write_rio_54837 write_rio 3 54837 NULL
127655 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
127656 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
127657 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
127658 +printer_read_54851 printer_read 3 54851 NULL
127659 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
127660 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
127661 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
127662 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
127663 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
127664 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
127665 +add_port_54941 add_port 2 54941 NULL
127666 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
127667 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
127668 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
127669 +c4_add_card_54968 c4_add_card 3 54968 NULL
127670 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
127671 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
127672 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
127673 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
127674 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
127675 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
127676 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
127677 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
127678 +filldir_55137 filldir 3 55137 NULL
127679 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
127680 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
127681 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
127682 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
127683 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
127684 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
127685 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
127686 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
127687 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
127688 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
127689 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
127690 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
127691 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
127692 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
127693 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
127694 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
127695 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
127696 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
127697 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 NULL nohasharray
127698 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 &compat_SyS_process_vm_readv_55305
127699 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
127700 +vme_user_read_55338 vme_user_read 3 55338 NULL
127701 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL nohasharray
127702 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 &sctp_datamsg_from_user_55342
127703 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
127704 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
127705 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
127706 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
127707 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
127708 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
127709 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
127710 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
127711 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
127712 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
127713 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
127714 +ea_get_55522 ea_get 3-0 55522 NULL
127715 +buffer_size_55534 buffer_size 0 55534 NULL
127716 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
127717 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
127718 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
127719 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
127720 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
127721 +add_partition_55588 add_partition 2 55588 NULL
127722 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
127723 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
127724 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
127725 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
127726 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
127727 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
127728 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
127729 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
127730 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
127731 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
127732 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
127733 +get_info_55681 get_info 3 55681 NULL
127734 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
127735 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
127736 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
127737 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
127738 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
127739 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
127740 +set_local_name_55757 set_local_name 4 55757 NULL
127741 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
127742 +strlen_55778 strlen 0 55778 NULL nohasharray
127743 +is_idx_node_in_tnc_55778 is_idx_node_in_tnc 0 55778 &strlen_55778
127744 +set_spte_55783 set_spte 4-5 55783 NULL
127745 +conf_read_55786 conf_read 3 55786 NULL nohasharray
127746 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
127747 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
127748 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
127749 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
127750 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
127751 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
127752 +hsc_write_55875 hsc_write 3 55875 NULL
127753 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
127754 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
127755 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
127756 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
127757 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
127758 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
127759 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
127760 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2 55957 NULL
127761 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
127762 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
127763 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
127764 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
127765 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
127766 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
127767 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
127768 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
127769 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
127770 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
127771 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
127772 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
127773 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
127774 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
127775 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
127776 +fd_copyin_56247 fd_copyin 3 56247 NULL
127777 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
127778 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
127779 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
127780 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
127781 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
127782 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
127783 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
127784 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
127785 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
127786 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
127787 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
127788 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
127789 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
127790 +dev_read_56369 dev_read 3 56369 NULL
127791 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
127792 +write_gssp_56404 write_gssp 3 56404 NULL
127793 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
127794 +store_msg_56417 store_msg 3 56417 NULL
127795 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
127796 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
127797 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
127798 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
127799 +fl_create_56435 fl_create 5 56435 NULL
127800 +gnttab_map_56439 gnttab_map 2 56439 NULL
127801 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
127802 +set_connectable_56458 set_connectable 4 56458 NULL
127803 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
127804 +putused_user_56467 putused_user 3 56467 NULL
127805 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
127806 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
127807 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
127808 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
127809 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
127810 +init_map_ip_56508 init_map_ip 5 56508 NULL
127811 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
127812 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
127813 +ip_options_get_56538 ip_options_get 4 56538 NULL
127814 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
127815 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
127816 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
127817 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
127818 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
127819 +event_filter_write_56609 event_filter_write 3 56609 NULL
127820 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
127821 +gather_array_56641 gather_array 3 56641 NULL
127822 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
127823 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
127824 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
127825 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
127826 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
127827 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
127828 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
127829 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
127830 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
127831 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
127832 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
127833 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
127834 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
127835 +do_syslog_56807 do_syslog 3 56807 NULL
127836 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
127837 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
127838 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
127839 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
127840 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
127841 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
127842 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
127843 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL nohasharray
127844 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 &batadv_tt_update_changes_56895
127845 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
127846 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
127847 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
127848 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
127849 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
127850 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
127851 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
127852 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
127853 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL
127854 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
127855 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
127856 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
127857 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
127858 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
127859 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
127860 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
127861 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
127862 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
127863 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
127864 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
127865 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
127866 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
127867 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
127868 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
127869 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
127870 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
127871 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
127872 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
127873 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
127874 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
127875 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
127876 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
127877 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
127878 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
127879 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
127880 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
127881 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
127882 +write_file_regval_57313 write_file_regval 3 57313 NULL
127883 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
127884 +usblp_read_57342 usblp_read 3 57342 NULL
127885 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
127886 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
127887 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
127888 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
127889 +read_file_blob_57406 read_file_blob 3 57406 NULL
127890 +enclosure_register_57412 enclosure_register 3 57412 NULL
127891 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
127892 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
127893 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
127894 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
127895 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
127896 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
127897 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
127898 +skb_headlen_57501 skb_headlen 0 57501 NULL
127899 +copy_in_user_57502 copy_in_user 3 57502 NULL
127900 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
127901 +init_tag_map_57515 init_tag_map 3 57515 NULL
127902 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
127903 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
127904 +cmm_read_57520 cmm_read 3 57520 NULL
127905 +inode_permission_57531 inode_permission 0 57531 NULL
127906 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
127907 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
127908 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
127909 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
127910 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
127911 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
127912 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
127913 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
127914 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
127915 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
127916 +mem_read_57631 mem_read 3 57631 NULL
127917 +r3964_write_57662 r3964_write 4 57662 NULL
127918 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
127919 +__lgwrite_57669 __lgwrite 4 57669 NULL
127920 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
127921 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
127922 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
127923 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
127924 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
127925 +ld2_57794 ld2 0 57794 NULL
127926 +ivtv_read_57796 ivtv_read 3 57796 NULL
127927 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
127928 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
127929 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
127930 +flash_read_57843 flash_read 3 57843 NULL
127931 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
127932 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
127933 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
127934 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
127935 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
127936 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
127937 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
127938 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
127939 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
127940 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
127941 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
127942 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
127943 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
127944 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
127945 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
127946 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
127947 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
127948 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
127949 +mce_async_out_58056 mce_async_out 3 58056 NULL
127950 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
127951 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
127952 +cm4040_write_58079 cm4040_write 3 58079 NULL
127953 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
127954 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
127955 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
127956 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
127957 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
127958 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
127959 +read_file_debug_58256 read_file_debug 3 58256 NULL
127960 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
127961 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
127962 +profile_load_58267 profile_load 3 58267 NULL
127963 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
127964 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
127965 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
127966 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
127967 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
127968 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
127969 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
127970 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
127971 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
127972 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
127973 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
127974 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
127975 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
127976 +capabilities_read_58457 capabilities_read 3 58457 NULL
127977 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
127978 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
127979 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
127980 +nv_rd08_58472 nv_rd08 0 58472 NULL
127981 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
127982 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
127983 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
127984 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
127985 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
127986 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
127987 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
127988 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
127989 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
127990 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
127991 +xip_file_read_58592 xip_file_read 3 58592 NULL
127992 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
127993 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
127994 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
127995 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
127996 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
127997 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
127998 +find_zero_58685 find_zero 0-1 58685 NULL
127999 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
128000 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
128001 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
128002 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
128003 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
128004 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
128005 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
128006 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
128007 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
128008 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
128009 +ep_read_58813 ep_read 3 58813 NULL
128010 +command_write_58841 command_write 3 58841 NULL
128011 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
128012 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
128013 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
128014 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
128015 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
128016 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
128017 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
128018 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
128019 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
128020 +init_list_set_59005 init_list_set 3 59005 NULL
128021 +ep_write_59008 ep_write 3 59008 NULL
128022 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
128023 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
128024 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
128025 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
128026 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
128027 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
128028 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
128029 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 5-4-0 59122 NULL nohasharray
128030 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
128031 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
128032 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
128033 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
128034 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
128035 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
128036 +ksize_59176 ksize 0 59176 NULL
128037 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
128038 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
128039 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
128040 +dt3155_read_59226 dt3155_read 3 59226 NULL
128041 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-2-1 59229 NULL
128042 +nla_len_59258 nla_len 0 59258 NULL
128043 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
128044 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
128045 +fd_copyout_59323 fd_copyout 3 59323 NULL
128046 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
128047 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
128048 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
128049 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
128050 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
128051 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
128052 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
128053 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
128054 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
128055 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
128056 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
128057 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
128058 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
128059 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
128060 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
128061 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
128062 +tunables_write_59563 tunables_write 3 59563 NULL
128063 +bio_split_59564 bio_split 2 59564 NULL
128064 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
128065 +memdup_user_59590 memdup_user 2 59590 NULL
128066 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
128067 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
128068 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
128069 +mtrr_write_59622 mtrr_write 3 59622 NULL
128070 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
128071 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
128072 +hidraw_read_59650 hidraw_read 3 59650 NULL
128073 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
128074 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
128075 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
128076 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
128077 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
128078 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
128079 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
128080 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
128081 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
128082 +strnlen_59746 strnlen 0 59746 NULL
128083 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
128084 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
128085 +venus_remove_59781 venus_remove 4 59781 NULL
128086 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
128087 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
128088 +ipw_write_59807 ipw_write 3 59807 NULL
128089 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
128090 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
128091 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
128092 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
128093 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
128094 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
128095 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
128096 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
128097 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
128098 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
128099 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
128100 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
128101 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
128102 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
128103 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
128104 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
128105 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
128106 +copy_items_60009 copy_items 7 60009 NULL
128107 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
128108 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
128109 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
128110 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
128111 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
128112 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
128113 +vcs_size_60050 vcs_size 0 60050 NULL
128114 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
128115 +compat_writev_60063 compat_writev 3 60063 NULL
128116 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
128117 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
128118 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
128119 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
128120 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
128121 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
128122 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
128123 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
128124 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
128125 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
128126 +init_state_60165 init_state 2 60165 NULL
128127 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
128128 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
128129 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
128130 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
128131 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
128132 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
128133 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
128134 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
128135 +printer_write_60276 printer_write 3 60276 NULL
128136 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
128137 +getDataLength_60301 getDataLength 0 60301 NULL
128138 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
128139 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
128140 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
128141 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
128142 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 0 60379 NULL
128143 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
128144 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
128145 +driver_names_read_60399 driver_names_read 3 60399 NULL
128146 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
128147 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
128148 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
128149 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
128150 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
128151 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
128152 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
128153 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
128154 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
128155 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
128156 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
128157 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
128158 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
128159 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
128160 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
128161 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
128162 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
128163 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
128164 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
128165 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
128166 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
128167 +raid_status_60755 raid_status 5 60755 NULL
128168 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
128169 +opticon_write_60775 opticon_write 4 60775 NULL
128170 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
128171 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
128172 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
128173 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
128174 +generic_writepages_60871 generic_writepages 0 60871 NULL
128175 +ubifs_read_one_lp_60882 ubifs_read_one_lp 0 60882 NULL
128176 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
128177 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
128178 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
128179 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
128180 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
128181 +pti_char_write_60960 pti_char_write 3 60960 NULL
128182 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
128183 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
128184 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
128185 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
128186 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
128187 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
128188 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
128189 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
128190 +symtab_init_61050 symtab_init 2 61050 NULL
128191 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
128192 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 2-0 61062 NULL
128193 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
128194 +get_derived_key_61100 get_derived_key 4 61100 NULL
128195 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
128196 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
128197 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
128198 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
128199 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
128200 +pair_device_61175 pair_device 4 61175 NULL nohasharray
128201 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
128202 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
128203 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
128204 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
128205 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
128206 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
128207 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
128208 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270
128209 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
128210 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
128211 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
128212 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
128213 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
128214 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
128215 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
128216 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 4-6 61340 NULL
128217 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
128218 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
128219 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
128220 +system_enable_write_61396 system_enable_write 3 61396 NULL
128221 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
128222 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
128223 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
128224 +erst_errno_61526 erst_errno 0 61526 NULL
128225 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
128226 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
128227 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
128228 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
128229 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
128230 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
128231 +seq_open_private_61589 seq_open_private 3 61589 NULL
128232 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-2-1 61591 NULL
128233 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
128234 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
128235 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
128236 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
128237 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
128238 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
128239 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
128240 +resize_stripes_61650 resize_stripes 2 61650 NULL
128241 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
128242 +insert_one_name_61668 insert_one_name 7 61668 NULL
128243 +lock_loop_61681 lock_loop 1 61681 NULL
128244 +filter_read_61692 filter_read 3 61692 NULL
128245 +iov_length_61716 iov_length 0 61716 NULL
128246 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
128247 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
128248 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
128249 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
128250 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
128251 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
128252 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
128253 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
128254 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
128255 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
128256 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
128257 +get_fw_name_61874 get_fw_name 3 61874 NULL
128258 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
128259 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
128260 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
128261 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
128262 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
128263 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
128264 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
128265 +fix_read_error_61965 fix_read_error 4 61965 NULL
128266 +cow_file_range_61979 cow_file_range 3 61979 NULL
128267 +dequeue_event_62000 dequeue_event 3 62000 NULL
128268 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
128269 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
128270 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
128271 +SYSC_select_62024 SYSC_select 1 62024 NULL
128272 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
128273 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
128274 +do_pselect_62061 do_pselect 1 62061 NULL
128275 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
128276 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
128277 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
128278 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
128279 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
128280 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
128281 +ql_status_62135 ql_status 5 62135 NULL
128282 +video_usercopy_62151 video_usercopy 2 62151 NULL
128283 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
128284 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
128285 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
128286 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
128287 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
128288 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
128289 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
128290 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
128291 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
128292 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
128293 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
128294 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
128295 +subseq_list_62332 subseq_list 3-0 62332 NULL
128296 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
128297 +flash_write_62354 flash_write 3 62354 NULL
128298 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
128299 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
128300 +altera_irscan_62396 altera_irscan 2 62396 NULL
128301 +set_ssp_62411 set_ssp 4 62411 NULL
128302 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
128303 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
128304 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
128305 +debugfs_read_62535 debugfs_read 3 62535 NULL
128306 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
128307 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
128308 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
128309 +get_subdir_62581 get_subdir 3 62581 NULL
128310 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
128311 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
128312 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
128313 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
128314 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
128315 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
128316 +rdm_62719 rdm 0 62719 NULL
128317 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
128318 +key_replays_read_62746 key_replays_read 3 62746 NULL
128319 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
128320 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
128321 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
128322 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 3-0 62770 NULL nohasharray
128323 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
128324 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
128325 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
128326 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
128327 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
128328 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
128329 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
128330 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
128331 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
128332 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
128333 +aoechr_write_62883 aoechr_write 3 62883 NULL
128334 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
128335 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
128336 +getdqbuf_62908 getdqbuf 1 62908 NULL
128337 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
128338 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
128339 +hwdep_read_62992 hwdep_read 3 62992 NULL
128340 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
128341 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
128342 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
128343 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
128344 +unlink1_63059 unlink1 3 63059 NULL
128345 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
128346 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
128347 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
128348 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
128349 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
128350 +ubifs_change_one_lp_63157 ubifs_change_one_lp 0 63157 NULL
128351 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
128352 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
128353 +vme_master_read_63221 vme_master_read 0 63221 NULL
128354 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
128355 +ptp_read_63251 ptp_read 4 63251 NULL
128356 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
128357 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
128358 +raid5_resize_63306 raid5_resize 2 63306 NULL
128359 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
128360 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
128361 +proc_info_read_63344 proc_info_read 3 63344 NULL
128362 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
128363 +idmouse_read_63374 idmouse_read 3 63374 NULL
128364 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
128365 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
128366 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
128367 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
128368 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
128369 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
128370 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
128371 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
128372 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
128373 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
128374 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
128375 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
128376 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
128377 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
128378 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
128379 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
128380 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
128381 +write_debug_level_63613 write_debug_level 3 63613 NULL
128382 +__spi_validate_63618 __spi_validate 0 63618 NULL
128383 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
128384 +hid_report_len_63637 hid_report_len 0 63637 NULL
128385 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
128386 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
128387 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
128388 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
128389 +vbi_read_63673 vbi_read 3 63673 NULL
128390 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
128391 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
128392 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
128393 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
128394 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
128395 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
128396 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
128397 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
128398 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
128399 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
128400 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL
128401 +sel_write_load_63830 sel_write_load 3 63830 NULL
128402 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
128403 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
128404 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
128405 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
128406 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
128407 +__team_options_register_63941 __team_options_register 3 63941 NULL
128408 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
128409 +set_bredr_63975 set_bredr 4 63975 NULL
128410 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
128411 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
128412 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
128413 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
128414 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
128415 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
128416 +__sock_create_64069 __sock_create 0 64069 NULL
128417 +get_u8_64076 get_u8 0 64076 NULL
128418 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
128419 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
128420 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
128421 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
128422 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
128423 +to_bytes_64103 to_bytes 0-1 64103 NULL
128424 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
128425 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
128426 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
128427 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
128428 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
128429 +init_bch_64130 init_bch 1-2 64130 NULL
128430 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
128431 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
128432 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
128433 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
128434 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
128435 +read_pulse_64227 read_pulse 0-3 64227 NULL
128436 +ea_len_64229 ea_len 0 64229 NULL
128437 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
128438 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
128439 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
128440 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
128441 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
128442 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
128443 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
128444 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
128445 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
128446 +ts_write_64336 ts_write 3 64336 NULL
128447 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
128448 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
128449 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
128450 +reg_create_64372 reg_create 5 64372 NULL
128451 +ilo_write_64378 ilo_write 3 64378 NULL
128452 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
128453 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
128454 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
128455 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
128456 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
128457 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
128458 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
128459 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
128460 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
128461 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
128462 +single_open_size_64483 single_open_size 4 64483 NULL
128463 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
128464 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
128465 +remove_uuid_64505 remove_uuid 4 64505 NULL
128466 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
128467 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
128468 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
128469 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
128470 +SyS_bind_64544 SyS_bind 3 64544 NULL
128471 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
128472 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
128473 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
128474 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
128475 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
128476 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
128477 +do_erase_64574 do_erase 4 64574 NULL
128478 +fanotify_write_64623 fanotify_write 3 64623 NULL
128479 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
128480 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
128481 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL nohasharray
128482 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 &tlbflush_read_file_64661
128483 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
128484 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
128485 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
128486 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
128487 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
128488 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
128489 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
128490 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
128491 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
128492 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
128493 +hwdep_write_64776 hwdep_write 3 64776 NULL
128494 +message_for_md_64777 message_for_md 5 64777 NULL
128495 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
128496 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
128497 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
128498 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
128499 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
128500 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
128501 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
128502 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
128503 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
128504 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
128505 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
128506 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
128507 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
128508 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
128509 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
128510 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
128511 +insert_dent_65034 insert_dent 7 65034 NULL
128512 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
128513 +make_idx_node_65068 make_idx_node 0 65068 NULL
128514 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
128515 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
128516 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
128517 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
128518 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
128519 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
128520 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
128521 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
128522 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
128523 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
128524 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
128525 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
128526 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
128527 +get_var_len_65304 get_var_len 0 65304 NULL
128528 +unpack_array_65318 unpack_array 0 65318 NULL
128529 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
128530 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
128531 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
128532 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
128533 +SyS_writev_65372 SyS_writev 3 65372 NULL
128534 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
128535 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
128536 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
128537 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
128538 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
128539 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
128540 +clear_user_65470 clear_user 2 65470 NULL
128541 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
128542 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
128543 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
128544 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
128545 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
128546 new file mode 100644
128547 index 0000000..560cd7b
128548 --- /dev/null
128549 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
128550 @@ -0,0 +1,92 @@
128551 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
128552 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
128553 +mappedread_2627 mappedread 2 2627 NULL
128554 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
128555 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
128556 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
128557 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
128558 +dmu_write_6048 dmu_write 4-3 6048 NULL
128559 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
128560 +update_pages_6225 update_pages 2-3 6225 NULL
128561 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
128562 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
128563 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
128564 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
128565 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
128566 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
128567 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
128568 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
128569 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
128570 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
128571 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
128572 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
128573 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
128574 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
128575 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
128576 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
128577 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
128578 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
128579 +uiocopy_18680 uiocopy 2 18680 NULL
128580 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
128581 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
128582 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
128583 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
128584 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
128585 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
128586 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
128587 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
128588 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
128589 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
128590 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
128591 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
128592 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
128593 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
128594 +splat_write_30943 splat_write 3 30943 NULL
128595 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
128596 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
128597 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
128598 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
128599 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
128600 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
128601 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
128602 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
128603 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
128604 +copyinstr_36980 copyinstr 3 36980 NULL
128605 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
128606 +splat_read_38116 splat_read 3 38116 NULL
128607 +sa_setup_38756 sa_setup 4 38756 NULL
128608 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
128609 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
128610 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
128611 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
128612 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
128613 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
128614 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
128615 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
128616 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
128617 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
128618 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
128619 +kcopy_write_43683 kcopy_write 3 43683 NULL
128620 +uiomove_44355 uiomove 2 44355 NULL
128621 +dmu_read_44418 dmu_read 4-3 44418 NULL
128622 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
128623 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
128624 +copyin_45945 copyin 3 45945 NULL
128625 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
128626 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
128627 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
128628 +spa_history_write_49650 spa_history_write 3 49650 NULL
128629 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
128630 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
128631 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
128632 +copyout_51409 copyout 3 51409 NULL
128633 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
128634 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
128635 +get_nvlist_56685 get_nvlist 2 56685 NULL
128636 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
128637 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
128638 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
128639 +zpios_write_61823 zpios_write 3 61823 NULL
128640 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
128641 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
128642 +zpios_read_64734 zpios_read 3 64734 NULL
128643 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
128644 new file mode 100644
128645 index 0000000..95f7abd
128646 --- /dev/null
128647 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
128648 @@ -0,0 +1,259 @@
128649 +/*
128650 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
128651 + * Licensed under the GPL v2, or (at your option) v3
128652 + *
128653 + * Homepage:
128654 + * http://www.grsecurity.net/~ephox/overflow_plugin/
128655 + *
128656 + * Documentation:
128657 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
128658 + *
128659 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
128660 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
128661 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
128662 + *
128663 + * Usage:
128664 + * $ make
128665 + * $ make run
128666 + */
128667 +
128668 +#include "gcc-common.h"
128669 +#include "size_overflow.h"
128670 +
128671 +int plugin_is_GPL_compatible;
128672 +
128673 +tree report_size_overflow_decl;
128674 +
128675 +tree size_overflow_type_HI;
128676 +tree size_overflow_type_SI;
128677 +tree size_overflow_type_DI;
128678 +tree size_overflow_type_TI;
128679 +
128680 +static struct plugin_info size_overflow_plugin_info = {
128681 + .version = "20140725",
128682 + .help = "no-size-overflow\tturn off size overflow checking\n",
128683 +};
128684 +
128685 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
128686 +{
128687 + unsigned int arg_count;
128688 + enum tree_code code = TREE_CODE(*node);
128689 +
128690 + switch (code) {
128691 + case FUNCTION_DECL:
128692 + arg_count = type_num_arguments(TREE_TYPE(*node));
128693 + break;
128694 + case FUNCTION_TYPE:
128695 + case METHOD_TYPE:
128696 + arg_count = type_num_arguments(*node);
128697 + break;
128698 + default:
128699 + *no_add_attrs = true;
128700 + error("%s: %qE attribute only applies to functions", __func__, name);
128701 + return NULL_TREE;
128702 + }
128703 +
128704 + for (; args; args = TREE_CHAIN(args)) {
128705 + tree position = TREE_VALUE(args);
128706 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
128707 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
128708 + *no_add_attrs = true;
128709 + }
128710 + }
128711 + return NULL_TREE;
128712 +}
128713 +
128714 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
128715 +{
128716 + unsigned int arg_count;
128717 + enum tree_code code = TREE_CODE(*node);
128718 +
128719 + switch (code) {
128720 + case FUNCTION_DECL:
128721 + arg_count = type_num_arguments(TREE_TYPE(*node));
128722 + break;
128723 + case FUNCTION_TYPE:
128724 + case METHOD_TYPE:
128725 + arg_count = type_num_arguments(*node);
128726 + break;
128727 + case FIELD_DECL:
128728 + return NULL_TREE;
128729 + default:
128730 + *no_add_attrs = true;
128731 + error("%qE attribute only applies to functions", name);
128732 + return NULL_TREE;
128733 + }
128734 +
128735 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
128736 + return NULL_TREE;
128737 +
128738 + for (; args; args = TREE_CHAIN(args)) {
128739 + tree position = TREE_VALUE(args);
128740 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
128741 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
128742 + *no_add_attrs = true;
128743 + }
128744 + }
128745 + return NULL_TREE;
128746 +}
128747 +
128748 +static struct attribute_spec size_overflow_attr = {
128749 + .name = "size_overflow",
128750 + .min_length = 1,
128751 + .max_length = -1,
128752 + .decl_required = true,
128753 + .type_required = false,
128754 + .function_type_required = false,
128755 + .handler = handle_size_overflow_attribute,
128756 +#if BUILDING_GCC_VERSION >= 4007
128757 + .affects_type_identity = false
128758 +#endif
128759 +};
128760 +
128761 +static struct attribute_spec intentional_overflow_attr = {
128762 + .name = "intentional_overflow",
128763 + .min_length = 1,
128764 + .max_length = -1,
128765 + .decl_required = true,
128766 + .type_required = false,
128767 + .function_type_required = false,
128768 + .handler = handle_intentional_overflow_attribute,
128769 +#if BUILDING_GCC_VERSION >= 4007
128770 + .affects_type_identity = false
128771 +#endif
128772 +};
128773 +
128774 +static void register_attributes(void __unused *event_data, void __unused *data)
128775 +{
128776 + register_attribute(&size_overflow_attr);
128777 + register_attribute(&intentional_overflow_attr);
128778 +}
128779 +
128780 +static tree create_typedef(tree type, const char* ident)
128781 +{
128782 + tree new_type, decl;
128783 +
128784 + new_type = build_variant_type_copy(type);
128785 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
128786 + DECL_ORIGINAL_TYPE(decl) = type;
128787 + TYPE_NAME(new_type) = decl;
128788 + return new_type;
128789 +}
128790 +
128791 +// Create the noreturn report_size_overflow() function decl.
128792 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
128793 +{
128794 + tree const_char_ptr_type_node;
128795 + tree fntype;
128796 +
128797 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
128798 +
128799 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
128800 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
128801 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
128802 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
128803 +
128804 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
128805 + fntype = build_function_type_list(void_type_node,
128806 + const_char_ptr_type_node,
128807 + unsigned_type_node,
128808 + const_char_ptr_type_node,
128809 + const_char_ptr_type_node,
128810 + NULL_TREE);
128811 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
128812 +
128813 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
128814 + TREE_PUBLIC(report_size_overflow_decl) = 1;
128815 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
128816 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
128817 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
128818 +}
128819 +
128820 +
128821 +extern struct gimple_opt_pass pass_dce;
128822 +
128823 +static struct opt_pass *make_dce_pass(void)
128824 +{
128825 +#if BUILDING_GCC_VERSION >= 4009
128826 + return make_pass_dce(g);
128827 +#else
128828 + return &pass_dce.pass;
128829 +#endif
128830 +}
128831 +
128832 +
128833 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
128834 +{
128835 + int i;
128836 + const char * const plugin_name = plugin_info->base_name;
128837 + const int argc = plugin_info->argc;
128838 + const struct plugin_argument * const argv = plugin_info->argv;
128839 + bool enable = true;
128840 + struct register_pass_info insert_size_overflow_asm_pass_info;
128841 + struct register_pass_info __unused dump_before_pass_info;
128842 + struct register_pass_info __unused dump_after_pass_info;
128843 + struct register_pass_info insert_size_overflow_check_info;
128844 + struct register_pass_info dce_pass_info;
128845 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
128846 + {
128847 + .base = &report_size_overflow_decl,
128848 + .nelt = 1,
128849 + .stride = sizeof(report_size_overflow_decl),
128850 + .cb = &gt_ggc_mx_tree_node,
128851 + .pchw = &gt_pch_nx_tree_node
128852 + },
128853 + LAST_GGC_ROOT_TAB
128854 + };
128855 +
128856 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
128857 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
128858 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
128859 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
128860 +
128861 + dump_before_pass_info.pass = make_dump_pass();
128862 + dump_before_pass_info.reference_pass_name = "increase_alignment";
128863 + dump_before_pass_info.ref_pass_instance_number = 1;
128864 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
128865 +
128866 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
128867 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
128868 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
128869 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
128870 +
128871 + dump_after_pass_info.pass = make_dump_pass();
128872 + dump_after_pass_info.reference_pass_name = "increase_alignment";
128873 + dump_after_pass_info.ref_pass_instance_number = 1;
128874 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
128875 +
128876 + dce_pass_info.pass = make_dce_pass();
128877 + dce_pass_info.reference_pass_name = "vrp";
128878 + dce_pass_info.ref_pass_instance_number = 1;
128879 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
128880 +
128881 + if (!plugin_default_version_check(version, &gcc_version)) {
128882 + error(G_("incompatible gcc/plugin versions"));
128883 + return 1;
128884 + }
128885 +
128886 + for (i = 0; i < argc; ++i) {
128887 + if (!strcmp(argv[i].key, "no-size-overflow")) {
128888 + enable = false;
128889 + continue;
128890 + }
128891 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
128892 + }
128893 +
128894 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
128895 + if (enable) {
128896 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
128897 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
128898 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
128899 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
128900 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
128901 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
128902 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
128903 + }
128904 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
128905 +
128906 + return 0;
128907 +}
128908 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
128909 new file mode 100644
128910 index 0000000..0888f6c
128911 --- /dev/null
128912 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
128913 @@ -0,0 +1,364 @@
128914 +/*
128915 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
128916 + * Licensed under the GPL v2, or (at your option) v3
128917 + *
128918 + * Homepage:
128919 + * http://www.grsecurity.net/~ephox/overflow_plugin/
128920 + *
128921 + * Documentation:
128922 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
128923 + *
128924 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
128925 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
128926 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
128927 + *
128928 + * Usage:
128929 + * $ make
128930 + * $ make run
128931 + */
128932 +
128933 +#include "gcc-common.h"
128934 +#include "size_overflow.h"
128935 +
128936 +#include "size_overflow_hash.h"
128937 +#include "size_overflow_hash_aux.h"
128938 +
128939 +#define CODES_LIMIT 32
128940 +
128941 +static unsigned char get_tree_code(const_tree type)
128942 +{
128943 + switch (TREE_CODE(type)) {
128944 + case ARRAY_TYPE:
128945 + return 0;
128946 + case BOOLEAN_TYPE:
128947 + return 1;
128948 + case ENUMERAL_TYPE:
128949 + return 2;
128950 + case FUNCTION_TYPE:
128951 + return 3;
128952 + case INTEGER_TYPE:
128953 + return 4;
128954 + case POINTER_TYPE:
128955 + return 5;
128956 + case RECORD_TYPE:
128957 + return 6;
128958 + case UNION_TYPE:
128959 + return 7;
128960 + case VOID_TYPE:
128961 + return 8;
128962 + case REAL_TYPE:
128963 + return 9;
128964 + case VECTOR_TYPE:
128965 + return 10;
128966 + case REFERENCE_TYPE:
128967 + return 11;
128968 + case OFFSET_TYPE:
128969 + return 12;
128970 + case COMPLEX_TYPE:
128971 + return 13;
128972 + default:
128973 + debug_tree((tree)type);
128974 + gcc_unreachable();
128975 + }
128976 +}
128977 +
128978 +struct function_hash {
128979 + size_t tree_codes_len;
128980 + unsigned char tree_codes[CODES_LIMIT];
128981 + const_tree fndecl;
128982 + unsigned int hash;
128983 +};
128984 +
128985 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
128986 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
128987 +{
128988 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
128989 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
128990 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
128991 +
128992 + unsigned int m = 0x57559429;
128993 + unsigned int n = 0x5052acdb;
128994 + const unsigned int *key4 = (const unsigned int *)key;
128995 + unsigned int h = len;
128996 + unsigned int k = len + seed + n;
128997 + unsigned long long p;
128998 +
128999 + while (len >= 8) {
129000 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
129001 + len -= 8;
129002 + }
129003 + if (len >= 4) {
129004 + cwmixb(key4[0]) key4 += 1;
129005 + len -= 4;
129006 + }
129007 + if (len)
129008 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
129009 + cwmixb(h ^ (k + n));
129010 + return k ^ h;
129011 +
129012 +#undef cwfold
129013 +#undef cwmixa
129014 +#undef cwmixb
129015 +}
129016 +
129017 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
129018 +{
129019 + unsigned int fn, codes, seed = 0;
129020 +
129021 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
129022 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
129023 +
129024 + fn_hash_data->hash = fn ^ codes;
129025 +}
129026 +
129027 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
129028 +{
129029 + gcc_assert(type != NULL_TREE);
129030 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
129031 +
129032 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
129033 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
129034 + fn_hash_data->tree_codes_len++;
129035 + type = TREE_TYPE(type);
129036 + }
129037 +}
129038 +
129039 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
129040 +{
129041 + const_tree result;
129042 +
129043 + gcc_assert(node != NULL_TREE);
129044 +
129045 + if (DECL_P(node)) {
129046 + result = DECL_RESULT(node);
129047 + if (result != NULL_TREE)
129048 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
129049 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
129050 + }
129051 +
129052 + gcc_assert(TYPE_P(node));
129053 +
129054 + if (TREE_CODE(node) == FUNCTION_TYPE)
129055 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
129056 +
129057 + return set_node_codes(node, fn_hash_data);
129058 +}
129059 +
129060 +static void set_function_codes(struct function_hash *fn_hash_data)
129061 +{
129062 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
129063 + enum tree_code code = TREE_CODE(type);
129064 +
129065 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
129066 +
129067 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
129068 +
129069 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
129070 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
129071 +}
129072 +
129073 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
129074 +{
129075 + while (entry) {
129076 + if (!strcmp(entry->name, func_name))
129077 + return entry;
129078 + entry = entry->next;
129079 + }
129080 + return NULL;
129081 +}
129082 +
129083 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
129084 +{
129085 + const struct size_overflow_hash *entry;
129086 + struct function_hash fn_hash_data;
129087 + const char *func_name;
129088 +
129089 + // skip builtins __builtin_constant_p
129090 + if (DECL_BUILT_IN(fndecl))
129091 + return NULL;
129092 +
129093 + fn_hash_data.fndecl = fndecl;
129094 + fn_hash_data.tree_codes_len = 0;
129095 +
129096 + set_function_codes(&fn_hash_data);
129097 + gcc_assert(fn_hash_data.tree_codes_len != 0);
129098 +
129099 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
129100 + set_hash(func_name, &fn_hash_data);
129101 +
129102 + entry = size_overflow_hash[fn_hash_data.hash];
129103 + entry = get_proper_hash_chain(entry, func_name);
129104 + if (entry)
129105 + return entry;
129106 + entry = size_overflow_hash_aux[fn_hash_data.hash];
129107 + return get_proper_hash_chain(entry, func_name);
129108 +}
129109 +
129110 +static void print_missing_msg(const_tree func, unsigned int argnum)
129111 +{
129112 + location_t loc;
129113 + const char *curfunc;
129114 + struct function_hash fn_hash_data;
129115 +
129116 + fn_hash_data.fndecl = DECL_ORIGIN(func);
129117 + fn_hash_data.tree_codes_len = 0;
129118 +
129119 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
129120 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
129121 +
129122 + set_function_codes(&fn_hash_data);
129123 + set_hash(curfunc, &fn_hash_data);
129124 +
129125 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
129126 +}
129127 +
129128 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
129129 +{
129130 + tree var;
129131 + unsigned int argnum = 1;
129132 +
129133 + if (TREE_CODE(arg) == SSA_NAME)
129134 + arg = SSA_NAME_VAR(arg);
129135 +
129136 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
129137 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
129138 + continue;
129139 + if (!skip_types(var))
129140 + return argnum;
129141 + }
129142 +
129143 + return CANNOT_FIND_ARG;
129144 +}
129145 +
129146 +static const char *get_asm_string(const_gimple stmt)
129147 +{
129148 + if (!stmt)
129149 + return NULL;
129150 + if (gimple_code(stmt) != GIMPLE_ASM)
129151 + return NULL;
129152 +
129153 + return gimple_asm_string(stmt);
129154 +}
129155 +
129156 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
129157 +{
129158 + const char *str;
129159 +
129160 + str = get_asm_string(stmt);
129161 + if (!str)
129162 + return false;
129163 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
129164 +}
129165 +
129166 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
129167 +{
129168 + const char *str;
129169 +
129170 + str = get_asm_string(stmt);
129171 + if (!str)
129172 + return false;
129173 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
129174 +}
129175 +
129176 +bool is_size_overflow_asm(const_gimple stmt)
129177 +{
129178 + const char *str;
129179 +
129180 + str = get_asm_string(stmt);
129181 + if (!str)
129182 + return false;
129183 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
129184 +}
129185 +
129186 +bool is_a_return_check(const_tree node)
129187 +{
129188 + if (TREE_CODE(node) == FUNCTION_DECL)
129189 + return true;
129190 +
129191 + gcc_assert(TREE_CODE(node) == PARM_DECL);
129192 + return false;
129193 +}
129194 +
129195 +// Get the argnum of a function decl, if node is a return then the argnum is 0
129196 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
129197 +{
129198 + if (is_a_return_check(node))
129199 + return 0;
129200 + else
129201 + return find_arg_number_tree(node, orig_fndecl);
129202 +}
129203 +
129204 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
129205 +{
129206 + const struct size_overflow_hash *hash;
129207 + unsigned int new_argnum;
129208 + tree arg;
129209 + const_tree origarg;
129210 +
129211 + if (argnum == 0)
129212 + return argnum;
129213 +
129214 + hash = get_function_hash(fndecl);
129215 + if (hash && hash->param & (1U << argnum))
129216 + return argnum;
129217 +
129218 + if (DECL_EXTERNAL(fndecl))
129219 + return argnum;
129220 +
129221 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
129222 + argnum--;
129223 + while (origarg && argnum) {
129224 + origarg = TREE_CHAIN(origarg);
129225 + argnum--;
129226 + }
129227 + gcc_assert(argnum == 0);
129228 + gcc_assert(origarg != NULL_TREE);
129229 +
129230 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
129231 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
129232 + return new_argnum;
129233 +
129234 + return CANNOT_FIND_ARG;
129235 +}
129236 +
129237 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
129238 +{
129239 + const struct size_overflow_hash *hash;
129240 +
129241 + hash = get_function_hash(fndecl);
129242 + if (hash && (hash->param & (1U << num)))
129243 + return true;
129244 + return false;
129245 +}
129246 +
129247 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
129248 + * If the function is missing everywhere then print the missing message into stderr.
129249 + */
129250 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
129251 +{
129252 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
129253 +#if BUILDING_GCC_VERSION >= 4008
129254 + case BUILT_IN_BSWAP16:
129255 +#endif
129256 + case BUILT_IN_BSWAP32:
129257 + case BUILT_IN_BSWAP64:
129258 + case BUILT_IN_EXPECT:
129259 + case BUILT_IN_MEMCMP:
129260 + return false;
129261 + default:
129262 + break;
129263 + }
129264 +
129265 + // skip test.c
129266 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
129267 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
129268 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
129269 + }
129270 +
129271 + if (is_in_hash_table(orig_fndecl, num))
129272 + return false;
129273 +
129274 + print_missing_msg(orig_fndecl, num);
129275 + return true;
129276 +}
129277 +
129278 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
129279 new file mode 100644
129280 index 0000000..924652b
129281 --- /dev/null
129282 +++ b/tools/gcc/stackleak_plugin.c
129283 @@ -0,0 +1,395 @@
129284 +/*
129285 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
129286 + * Licensed under the GPL v2
129287 + *
129288 + * Note: the choice of the license means that the compilation process is
129289 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
129290 + * but for the kernel it doesn't matter since it doesn't link against
129291 + * any of the gcc libraries
129292 + *
129293 + * gcc plugin to help implement various PaX features
129294 + *
129295 + * - track lowest stack pointer
129296 + *
129297 + * TODO:
129298 + * - initialize all local variables
129299 + *
129300 + * BUGS:
129301 + * - none known
129302 + */
129303 +
129304 +#include "gcc-common.h"
129305 +
129306 +int plugin_is_GPL_compatible;
129307 +
129308 +static int track_frame_size = -1;
129309 +static const char track_function[] = "pax_track_stack";
129310 +static const char check_function[] = "pax_check_alloca";
129311 +static tree track_function_decl, check_function_decl;
129312 +static bool init_locals;
129313 +
129314 +static struct plugin_info stackleak_plugin_info = {
129315 + .version = "201408011900",
129316 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
129317 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
129318 +};
129319 +
129320 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
129321 +{
129322 + gimple check_alloca;
129323 + tree alloca_size;
129324 +
129325 + // insert call to void pax_check_alloca(unsigned long size)
129326 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
129327 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
129328 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
129329 +}
129330 +
129331 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
129332 +{
129333 + gimple track_stack;
129334 +
129335 + // insert call to void pax_track_stack(void)
129336 + track_stack = gimple_build_call(track_function_decl, 0);
129337 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
129338 +}
129339 +
129340 +static bool is_alloca(gimple stmt)
129341 +{
129342 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
129343 + return true;
129344 +
129345 +#if BUILDING_GCC_VERSION >= 4007
129346 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
129347 + return true;
129348 +#endif
129349 +
129350 + return false;
129351 +}
129352 +
129353 +static unsigned int execute_stackleak_tree_instrument(void)
129354 +{
129355 + basic_block bb, entry_bb;
129356 + bool prologue_instrumented = false, is_leaf = true;
129357 +
129358 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
129359 +
129360 + // 1. loop through BBs and GIMPLE statements
129361 + FOR_EACH_BB_FN(bb, cfun) {
129362 + gimple_stmt_iterator gsi;
129363 +
129364 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
129365 + gimple stmt;
129366 +
129367 + stmt = gsi_stmt(gsi);
129368 +
129369 + if (is_gimple_call(stmt))
129370 + is_leaf = false;
129371 +
129372 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
129373 + if (!is_alloca(stmt))
129374 + continue;
129375 +
129376 + // 2. insert stack overflow check before each __builtin_alloca call
129377 + stackleak_check_alloca(&gsi);
129378 +
129379 + // 3. insert track call after each __builtin_alloca call
129380 + stackleak_add_instrumentation(&gsi);
129381 + if (bb == entry_bb)
129382 + prologue_instrumented = true;
129383 + }
129384 + }
129385 +
129386 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
129387 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
129388 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
129389 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
129390 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
129391 + return 0;
129392 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
129393 + return 0;
129394 +
129395 + // 4. insert track call at the beginning
129396 + if (!prologue_instrumented) {
129397 + gimple_stmt_iterator gsi;
129398 +
129399 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
129400 + if (dom_info_available_p(CDI_DOMINATORS))
129401 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
129402 + gsi = gsi_start_bb(bb);
129403 + stackleak_add_instrumentation(&gsi);
129404 + }
129405 +
129406 + return 0;
129407 +}
129408 +
129409 +static unsigned int execute_stackleak_final(void)
129410 +{
129411 + rtx insn, next;
129412 +
129413 + if (cfun->calls_alloca)
129414 + return 0;
129415 +
129416 + // keep calls only if function frame is big enough
129417 + if (get_frame_size() >= track_frame_size)
129418 + return 0;
129419 +
129420 + // 1. find pax_track_stack calls
129421 + for (insn = get_insns(); insn; insn = next) {
129422 + // rtl match: (call_insn 8 7 9 3 (call (mem (symbol_ref ("pax_track_stack") [flags 0x41] <function_decl 0xb7470e80 pax_track_stack>) [0 S1 A8]) (4)) -1 (nil) (nil))
129423 + rtx body;
129424 +
129425 + next = NEXT_INSN(insn);
129426 + if (!CALL_P(insn))
129427 + continue;
129428 + body = PATTERN(insn);
129429 + if (GET_CODE(body) != CALL)
129430 + continue;
129431 + body = XEXP(body, 0);
129432 + if (GET_CODE(body) != MEM)
129433 + continue;
129434 + body = XEXP(body, 0);
129435 + if (GET_CODE(body) != SYMBOL_REF)
129436 + continue;
129437 +// if (strcmp(XSTR(body, 0), track_function))
129438 + if (SYMBOL_REF_DECL(body) != track_function_decl)
129439 + continue;
129440 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
129441 + // 2. delete call
129442 + delete_insn_and_edges(insn);
129443 +#if BUILDING_GCC_VERSION >= 4007
129444 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
129445 + insn = next;
129446 + next = NEXT_INSN(insn);
129447 + delete_insn_and_edges(insn);
129448 + }
129449 +#endif
129450 + }
129451 +
129452 +// print_simple_rtl(stderr, get_insns());
129453 +// print_rtl(stderr, get_insns());
129454 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
129455 +
129456 + return 0;
129457 +}
129458 +
129459 +static bool gate_stackleak_track_stack(void)
129460 +{
129461 + tree section;
129462 +
129463 + if (ix86_cmodel != CM_KERNEL)
129464 + return false;
129465 +
129466 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
129467 + if (section && TREE_VALUE(section)) {
129468 + section = TREE_VALUE(TREE_VALUE(section));
129469 +
129470 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
129471 + return false;
129472 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
129473 + return false;
129474 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
129475 + return false;
129476 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
129477 + return false;
129478 + }
129479 +
129480 + return track_frame_size >= 0;
129481 +}
129482 +
129483 +static void stackleak_start_unit(void *gcc_data, void *user_data)
129484 +{
129485 + tree fntype;
129486 +
129487 + // void pax_track_stack(void)
129488 + fntype = build_function_type_list(void_type_node, NULL_TREE);
129489 + track_function_decl = build_fn_decl(track_function, fntype);
129490 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
129491 + TREE_PUBLIC(track_function_decl) = 1;
129492 + DECL_EXTERNAL(track_function_decl) = 1;
129493 + DECL_ARTIFICIAL(track_function_decl) = 1;
129494 +
129495 + // void pax_check_alloca(unsigned long)
129496 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
129497 + check_function_decl = build_fn_decl(check_function, fntype);
129498 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
129499 + TREE_PUBLIC(check_function_decl) = 1;
129500 + DECL_EXTERNAL(check_function_decl) = 1;
129501 + DECL_ARTIFICIAL(check_function_decl) = 1;
129502 +}
129503 +
129504 +#if BUILDING_GCC_VERSION >= 4009
129505 +static const struct pass_data stackleak_tree_instrument_pass_data = {
129506 +#else
129507 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
129508 + .pass = {
129509 +#endif
129510 + .type = GIMPLE_PASS,
129511 + .name = "stackleak_tree_instrument",
129512 +#if BUILDING_GCC_VERSION >= 4008
129513 + .optinfo_flags = OPTGROUP_NONE,
129514 +#endif
129515 +#if BUILDING_GCC_VERSION >= 4009
129516 + .has_gate = true,
129517 + .has_execute = true,
129518 +#else
129519 + .gate = gate_stackleak_track_stack,
129520 + .execute = execute_stackleak_tree_instrument,
129521 + .sub = NULL,
129522 + .next = NULL,
129523 + .static_pass_number = 0,
129524 +#endif
129525 + .tv_id = TV_NONE,
129526 + .properties_required = PROP_gimple_leh | PROP_cfg,
129527 + .properties_provided = 0,
129528 + .properties_destroyed = 0,
129529 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
129530 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
129531 +#if BUILDING_GCC_VERSION < 4009
129532 + }
129533 +#endif
129534 +};
129535 +
129536 +#if BUILDING_GCC_VERSION >= 4009
129537 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
129538 +#else
129539 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
129540 + .pass = {
129541 +#endif
129542 + .type = RTL_PASS,
129543 + .name = "stackleak_final",
129544 +#if BUILDING_GCC_VERSION >= 4008
129545 + .optinfo_flags = OPTGROUP_NONE,
129546 +#endif
129547 +#if BUILDING_GCC_VERSION >= 4009
129548 + .has_gate = true,
129549 + .has_execute = true,
129550 +#else
129551 + .gate = gate_stackleak_track_stack,
129552 + .execute = execute_stackleak_final,
129553 + .sub = NULL,
129554 + .next = NULL,
129555 + .static_pass_number = 0,
129556 +#endif
129557 + .tv_id = TV_NONE,
129558 + .properties_required = 0,
129559 + .properties_provided = 0,
129560 + .properties_destroyed = 0,
129561 + .todo_flags_start = 0,
129562 + .todo_flags_finish = TODO_dump_func
129563 +#if BUILDING_GCC_VERSION < 4009
129564 + }
129565 +#endif
129566 +};
129567 +
129568 +#if BUILDING_GCC_VERSION >= 4009
129569 +namespace {
129570 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
129571 +public:
129572 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
129573 + bool gate() { return gate_stackleak_track_stack(); }
129574 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
129575 +};
129576 +
129577 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
129578 +public:
129579 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
129580 + bool gate() { return gate_stackleak_track_stack(); }
129581 + unsigned int execute() { return execute_stackleak_final(); }
129582 +};
129583 +}
129584 +
129585 +static opt_pass *make_stackleak_tree_instrument_pass(void)
129586 +{
129587 + return new stackleak_tree_instrument_pass();
129588 +}
129589 +
129590 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
129591 +{
129592 + return new stackleak_final_rtl_opt_pass();
129593 +}
129594 +#else
129595 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
129596 +{
129597 + return &stackleak_tree_instrument_pass.pass;
129598 +}
129599 +
129600 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
129601 +{
129602 + return &stackleak_final_rtl_opt_pass.pass;
129603 +}
129604 +#endif
129605 +
129606 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
129607 +{
129608 + const char * const plugin_name = plugin_info->base_name;
129609 + const int argc = plugin_info->argc;
129610 + const struct plugin_argument * const argv = plugin_info->argv;
129611 + int i;
129612 + struct register_pass_info stackleak_tree_instrument_pass_info;
129613 + struct register_pass_info stackleak_final_pass_info;
129614 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
129615 + {
129616 + .base = &track_function_decl,
129617 + .nelt = 1,
129618 + .stride = sizeof(track_function_decl),
129619 + .cb = &gt_ggc_mx_tree_node,
129620 + .pchw = &gt_pch_nx_tree_node
129621 + },
129622 + {
129623 + .base = &check_function_decl,
129624 + .nelt = 1,
129625 + .stride = sizeof(check_function_decl),
129626 + .cb = &gt_ggc_mx_tree_node,
129627 + .pchw = &gt_pch_nx_tree_node
129628 + },
129629 + LAST_GGC_ROOT_TAB
129630 + };
129631 +
129632 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
129633 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
129634 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
129635 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
129636 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
129637 +
129638 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
129639 + stackleak_final_pass_info.reference_pass_name = "final";
129640 + stackleak_final_pass_info.ref_pass_instance_number = 1;
129641 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
129642 +
129643 + if (!plugin_default_version_check(version, &gcc_version)) {
129644 + error(G_("incompatible gcc/plugin versions"));
129645 + return 1;
129646 + }
129647 +
129648 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
129649 +
129650 + for (i = 0; i < argc; ++i) {
129651 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
129652 + if (!argv[i].value) {
129653 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
129654 + continue;
129655 + }
129656 + track_frame_size = atoi(argv[i].value);
129657 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
129658 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
129659 + continue;
129660 + }
129661 + if (!strcmp(argv[i].key, "initialize-locals")) {
129662 + if (argv[i].value) {
129663 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
129664 + continue;
129665 + }
129666 + init_locals = true;
129667 + continue;
129668 + }
129669 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
129670 + }
129671 +
129672 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
129673 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
129674 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
129675 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
129676 +
129677 + return 0;
129678 +}
129679 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
129680 new file mode 100644
129681 index 0000000..4ee2231
129682 --- /dev/null
129683 +++ b/tools/gcc/structleak_plugin.c
129684 @@ -0,0 +1,274 @@
129685 +/*
129686 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
129687 + * Licensed under the GPL v2
129688 + *
129689 + * Note: the choice of the license means that the compilation process is
129690 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
129691 + * but for the kernel it doesn't matter since it doesn't link against
129692 + * any of the gcc libraries
129693 + *
129694 + * gcc plugin to forcibly initialize certain local variables that could
129695 + * otherwise leak kernel stack to userland if they aren't properly initialized
129696 + * by later code
129697 + *
129698 + * Homepage: http://pax.grsecurity.net/
129699 + *
129700 + * Usage:
129701 + * $ # for 4.5/4.6/C based 4.7
129702 + * $ gcc -I`gcc -print-file-name=plugin`/include -I`gcc -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -o structleak_plugin.so structleak_plugin.c
129703 + * $ # for C++ based 4.7/4.8+
129704 + * $ g++ -I`g++ -print-file-name=plugin`/include -I`g++ -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -o structleak_plugin.so structleak_plugin.c
129705 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
129706 + *
129707 + * TODO: eliminate redundant initializers
129708 + * increase type coverage
129709 + */
129710 +
129711 +#include "gcc-common.h"
129712 +
129713 +// unused C type flag in all versions 4.5-4.9
129714 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
129715 +
129716 +int plugin_is_GPL_compatible;
129717 +
129718 +static struct plugin_info structleak_plugin_info = {
129719 + .version = "201401260140",
129720 + .help = "disable\tdo not activate plugin\n",
129721 +};
129722 +
129723 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
129724 +{
129725 + *no_add_attrs = true;
129726 +
129727 + // check for types? for now accept everything linux has to offer
129728 + if (TREE_CODE(*node) != FIELD_DECL)
129729 + return NULL_TREE;
129730 +
129731 + *no_add_attrs = false;
129732 + return NULL_TREE;
129733 +}
129734 +
129735 +static struct attribute_spec user_attr = {
129736 + .name = "user",
129737 + .min_length = 0,
129738 + .max_length = 0,
129739 + .decl_required = false,
129740 + .type_required = false,
129741 + .function_type_required = false,
129742 + .handler = handle_user_attribute,
129743 +#if BUILDING_GCC_VERSION >= 4007
129744 + .affects_type_identity = true
129745 +#endif
129746 +};
129747 +
129748 +static void register_attributes(void *event_data, void *data)
129749 +{
129750 + register_attribute(&user_attr);
129751 +// register_attribute(&force_attr);
129752 +}
129753 +
129754 +static tree get_field_type(tree field)
129755 +{
129756 + return strip_array_types(TREE_TYPE(field));
129757 +}
129758 +
129759 +static bool is_userspace_type(tree type)
129760 +{
129761 + tree field;
129762 +
129763 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
129764 + tree fieldtype = get_field_type(field);
129765 + enum tree_code code = TREE_CODE(fieldtype);
129766 +
129767 + if (code == RECORD_TYPE || code == UNION_TYPE)
129768 + if (is_userspace_type(fieldtype))
129769 + return true;
129770 +
129771 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
129772 + return true;
129773 + }
129774 + return false;
129775 +}
129776 +
129777 +static void finish_type(void *event_data, void *data)
129778 +{
129779 + tree type = (tree)event_data;
129780 +
129781 + if (TYPE_USERSPACE(type))
129782 + return;
129783 +
129784 + if (is_userspace_type(type))
129785 + TYPE_USERSPACE(type) = 1;
129786 +}
129787 +
129788 +static void initialize(tree var)
129789 +{
129790 + basic_block bb;
129791 + gimple_stmt_iterator gsi;
129792 + tree initializer;
129793 + gimple init_stmt;
129794 +
129795 + // this is the original entry bb before the forced split
129796 + // TODO: check further BBs in case more splits occured before us
129797 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
129798 +
129799 + // first check if the variable is already initialized, warn otherwise
129800 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
129801 + gimple stmt = gsi_stmt(gsi);
129802 + tree rhs1;
129803 +
129804 + // we're looking for an assignment of a single rhs...
129805 + if (!gimple_assign_single_p(stmt))
129806 + continue;
129807 + rhs1 = gimple_assign_rhs1(stmt);
129808 +#if BUILDING_GCC_VERSION >= 4007
129809 + // ... of a non-clobbering expression...
129810 + if (TREE_CLOBBER_P(rhs1))
129811 + continue;
129812 +#endif
129813 + // ... to our variable...
129814 + if (gimple_get_lhs(stmt) != var)
129815 + continue;
129816 + // if it's an initializer then we're good
129817 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
129818 + return;
129819 + }
129820 +
129821 + // these aren't the 0days you're looking for
129822 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
129823 +
129824 + // build the initializer expression
129825 + initializer = build_constructor(TREE_TYPE(var), NULL);
129826 +
129827 + // build the initializer stmt
129828 + init_stmt = gimple_build_assign(var, initializer);
129829 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
129830 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
129831 + update_stmt(init_stmt);
129832 +}
129833 +
129834 +static unsigned int handle_function(void)
129835 +{
129836 + basic_block bb;
129837 + unsigned int ret = 0;
129838 + tree var;
129839 + unsigned int i;
129840 +
129841 + // split the first bb where we can put the forced initializers
129842 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
129843 + if (dom_info_available_p(CDI_DOMINATORS))
129844 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
129845 +
129846 + // enumarate all local variables and forcibly initialize our targets
129847 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
129848 + tree type = TREE_TYPE(var);
129849 +
129850 + gcc_assert(DECL_P(var));
129851 + if (!auto_var_in_fn_p(var, current_function_decl))
129852 + continue;
129853 +
129854 + // only care about structure types
129855 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
129856 + continue;
129857 +
129858 + // if the type is of interest, examine the variable
129859 + if (TYPE_USERSPACE(type))
129860 + initialize(var);
129861 + }
129862 +
129863 + return ret;
129864 +}
129865 +
129866 +#if BUILDING_GCC_VERSION >= 4009
129867 +static const struct pass_data structleak_pass_data = {
129868 +#else
129869 +static struct gimple_opt_pass structleak_pass = {
129870 + .pass = {
129871 +#endif
129872 + .type = GIMPLE_PASS,
129873 + .name = "structleak",
129874 +#if BUILDING_GCC_VERSION >= 4008
129875 + .optinfo_flags = OPTGROUP_NONE,
129876 +#endif
129877 +#if BUILDING_GCC_VERSION >= 4009
129878 + .has_gate = false,
129879 + .has_execute = true,
129880 +#else
129881 + .gate = NULL,
129882 + .execute = handle_function,
129883 + .sub = NULL,
129884 + .next = NULL,
129885 + .static_pass_number = 0,
129886 +#endif
129887 + .tv_id = TV_NONE,
129888 + .properties_required = PROP_cfg,
129889 + .properties_provided = 0,
129890 + .properties_destroyed = 0,
129891 + .todo_flags_start = 0,
129892 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa | TODO_ggc_collect | TODO_verify_flow
129893 +#if BUILDING_GCC_VERSION < 4009
129894 + }
129895 +#endif
129896 +};
129897 +
129898 +#if BUILDING_GCC_VERSION >= 4009
129899 +namespace {
129900 +class structleak_pass : public gimple_opt_pass {
129901 +public:
129902 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
129903 + unsigned int execute() { return handle_function(); }
129904 +};
129905 +}
129906 +
129907 +static opt_pass *make_structleak_pass(void)
129908 +{
129909 + return new structleak_pass();
129910 +}
129911 +#else
129912 +static struct opt_pass *make_structleak_pass(void)
129913 +{
129914 + return &structleak_pass.pass;
129915 +}
129916 +#endif
129917 +
129918 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
129919 +{
129920 + int i;
129921 + const char * const plugin_name = plugin_info->base_name;
129922 + const int argc = plugin_info->argc;
129923 + const struct plugin_argument * const argv = plugin_info->argv;
129924 + bool enable = true;
129925 + struct register_pass_info structleak_pass_info;
129926 +
129927 + structleak_pass_info.pass = make_structleak_pass();
129928 + structleak_pass_info.reference_pass_name = "ssa";
129929 + structleak_pass_info.ref_pass_instance_number = 1;
129930 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
129931 +
129932 + if (!plugin_default_version_check(version, &gcc_version)) {
129933 + error(G_("incompatible gcc/plugin versions"));
129934 + return 1;
129935 + }
129936 +
129937 + if (strcmp(lang_hooks.name, "GNU C")) {
129938 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
129939 + enable = false;
129940 + }
129941 +
129942 + for (i = 0; i < argc; ++i) {
129943 + if (!strcmp(argv[i].key, "disable")) {
129944 + enable = false;
129945 + continue;
129946 + }
129947 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
129948 + }
129949 +
129950 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
129951 + if (enable) {
129952 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
129953 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
129954 + }
129955 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
129956 +
129957 + return 0;
129958 +}
129959 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
129960 index 88461f0..6fb70a0 100644
129961 --- a/tools/include/linux/compiler.h
129962 +++ b/tools/include/linux/compiler.h
129963 @@ -35,6 +35,14 @@
129964 # define unlikely(x) __builtin_expect(!!(x), 0)
129965 #endif
129966
129967 +#ifndef __size_overflow
129968 +# define __size_overflow(...)
129969 +#endif
129970 +
129971 +#ifndef __intentional_overflow
129972 +# define __intentional_overflow(...)
129973 +#endif
129974 +
129975 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
129976
129977 #endif /* _TOOLS_LINUX_COMPILER_H */
129978 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
129979 index ce00f7e..0aca5e4 100644
129980 --- a/tools/lib/api/Makefile
129981 +++ b/tools/lib/api/Makefile
129982 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
129983
129984 LIBFILE = libapikfs.a
129985
129986 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
129987 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
129988 EXTLIBS = -lelf -lpthread -lrt -lm
129989 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
129990 ALL_LDFLAGS = $(LDFLAGS)
129991 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
129992 index 6789d788..4afd019e 100644
129993 --- a/tools/perf/util/include/asm/alternative-asm.h
129994 +++ b/tools/perf/util/include/asm/alternative-asm.h
129995 @@ -5,4 +5,7 @@
129996
129997 #define altinstruction_entry #
129998
129999 + .macro pax_force_retaddr rip=0, reload=0
130000 + .endm
130001 +
130002 #endif
130003 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
130004 index 0a578fe..b81f62d 100644
130005 --- a/tools/virtio/linux/uaccess.h
130006 +++ b/tools/virtio/linux/uaccess.h
130007 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
130008 ({ \
130009 typeof(ptr) __pu_ptr = (ptr); \
130010 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
130011 - ACCESS_ONCE(*(__pu_ptr)) = x; \
130012 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
130013 0; \
130014 })
130015
130016 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
130017 index 4b6c01b..16eb755 100644
130018 --- a/virt/kvm/kvm_main.c
130019 +++ b/virt/kvm/kvm_main.c
130020 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
130021
130022 static cpumask_var_t cpus_hardware_enabled;
130023 static int kvm_usage_count = 0;
130024 -static atomic_t hardware_enable_failed;
130025 +static atomic_unchecked_t hardware_enable_failed;
130026
130027 struct kmem_cache *kvm_vcpu_cache;
130028 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
130029
130030 -static __read_mostly struct preempt_ops kvm_preempt_ops;
130031 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
130032 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
130033 +static struct preempt_ops kvm_preempt_ops = {
130034 + .sched_in = kvm_sched_in,
130035 + .sched_out = kvm_sched_out,
130036 +};
130037
130038 struct dentry *kvm_debugfs_dir;
130039
130040 @@ -761,7 +766,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
130041 /* We can read the guest memory with __xxx_user() later on. */
130042 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
130043 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
130044 - !access_ok(VERIFY_WRITE,
130045 + !access_ok_noprefault(VERIFY_WRITE,
130046 (void __user *)(unsigned long)mem->userspace_addr,
130047 mem->memory_size)))
130048 goto out;
130049 @@ -1618,9 +1623,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
130050
130051 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
130052 {
130053 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
130054 + int r;
130055 + unsigned long addr;
130056
130057 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
130058 + addr = gfn_to_hva(kvm, gfn);
130059 + if (kvm_is_error_hva(addr))
130060 + return -EFAULT;
130061 + r = __clear_user((void __user *)addr + offset, len);
130062 + if (r)
130063 + return -EFAULT;
130064 + mark_page_dirty(kvm, gfn);
130065 + return 0;
130066 }
130067 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
130068
130069 @@ -1870,7 +1883,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
130070 return 0;
130071 }
130072
130073 -static struct file_operations kvm_vcpu_fops = {
130074 +static file_operations_no_const kvm_vcpu_fops __read_only = {
130075 .release = kvm_vcpu_release,
130076 .unlocked_ioctl = kvm_vcpu_ioctl,
130077 #ifdef CONFIG_COMPAT
130078 @@ -2540,7 +2553,7 @@ out:
130079 }
130080 #endif
130081
130082 -static struct file_operations kvm_vm_fops = {
130083 +static file_operations_no_const kvm_vm_fops __read_only = {
130084 .release = kvm_vm_release,
130085 .unlocked_ioctl = kvm_vm_ioctl,
130086 #ifdef CONFIG_COMPAT
130087 @@ -2640,7 +2653,7 @@ out:
130088 return r;
130089 }
130090
130091 -static struct file_operations kvm_chardev_ops = {
130092 +static file_operations_no_const kvm_chardev_ops __read_only = {
130093 .unlocked_ioctl = kvm_dev_ioctl,
130094 .compat_ioctl = kvm_dev_ioctl,
130095 .llseek = noop_llseek,
130096 @@ -2666,7 +2679,7 @@ static void hardware_enable_nolock(void *junk)
130097
130098 if (r) {
130099 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
130100 - atomic_inc(&hardware_enable_failed);
130101 + atomic_inc_unchecked(&hardware_enable_failed);
130102 printk(KERN_INFO "kvm: enabling virtualization on "
130103 "CPU%d failed\n", cpu);
130104 }
130105 @@ -2722,10 +2735,10 @@ static int hardware_enable_all(void)
130106
130107 kvm_usage_count++;
130108 if (kvm_usage_count == 1) {
130109 - atomic_set(&hardware_enable_failed, 0);
130110 + atomic_set_unchecked(&hardware_enable_failed, 0);
130111 on_each_cpu(hardware_enable_nolock, NULL, 1);
130112
130113 - if (atomic_read(&hardware_enable_failed)) {
130114 + if (atomic_read_unchecked(&hardware_enable_failed)) {
130115 hardware_disable_all_nolock();
130116 r = -EBUSY;
130117 }
130118 @@ -3130,7 +3143,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
130119 kvm_arch_vcpu_put(vcpu);
130120 }
130121
130122 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
130123 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
130124 struct module *module)
130125 {
130126 int r;
130127 @@ -3177,7 +3190,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
130128 if (!vcpu_align)
130129 vcpu_align = __alignof__(struct kvm_vcpu);
130130 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
130131 - 0, NULL);
130132 + SLAB_USERCOPY, NULL);
130133 if (!kvm_vcpu_cache) {
130134 r = -ENOMEM;
130135 goto out_free_3;
130136 @@ -3187,9 +3200,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
130137 if (r)
130138 goto out_free;
130139
130140 + pax_open_kernel();
130141 kvm_chardev_ops.owner = module;
130142 kvm_vm_fops.owner = module;
130143 kvm_vcpu_fops.owner = module;
130144 + pax_close_kernel();
130145
130146 r = misc_register(&kvm_dev);
130147 if (r) {
130148 @@ -3199,9 +3214,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
130149
130150 register_syscore_ops(&kvm_syscore_ops);
130151
130152 - kvm_preempt_ops.sched_in = kvm_sched_in;
130153 - kvm_preempt_ops.sched_out = kvm_sched_out;
130154 -
130155 r = kvm_init_debug();
130156 if (r) {
130157 printk(KERN_ERR "kvm: create debugfs files failed\n");